From 16a7f0498dc9626c6fc7ff2b53f4c7bb1ac6c8f4 Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 13 Mar 2023 07:13:01 +0100 Subject: [PATCH] feat: Check MCU type at start (#3272) * Check MCU type * MCU check * MCU check * chore: Change capitalisation --- radio/src/gui/common/stdlcd/radio_version.cpp | 5 +--- radio/src/opentx.cpp | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/radio/src/gui/common/stdlcd/radio_version.cpp b/radio/src/gui/common/stdlcd/radio_version.cpp index f3761abf1..844d5c2b9 100644 --- a/radio/src/gui/common/stdlcd/radio_version.cpp +++ b/radio/src/gui/common/stdlcd/radio_version.cpp @@ -270,10 +270,7 @@ void menuRadioVersion(event_t event) coord_t y = MENU_HEADER_HEIGHT + 2; lcdDrawText(FW, y, vers_stamp, SMLSIZE); - y += 5 * (FH - 1); - - - y += 2; + y += 5 * (FH - 1) + 2; #if defined(PCBTARANIS) lcdDrawText(INDENT_WIDTH, y, BUTTON(TR_FIRMWARE_OPTIONS), menuVerticalPosition == ITEM_RADIO_FIRMWARE_OPTIONS ? INVERS : 0); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 2547587d7..e8bc92a63 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -140,6 +140,27 @@ static void readKeysAndTrims() } } +void checkValidMCU(void) +{ + // Checks the radio MCU type matches intended firmware type + uint32_t idcode = DBGMCU->IDCODE & 0xFFF; + +#if defined(STM32F205xx) + #define TARGET_IDCODE 0x411 +#elif defined(STM32F407xx) + #define TARGET_IDCODE 0x413 +#elif defined(STM32F429xx) + #define TARGET_IDCODE 0x419 +#else + // Ensure new radio get registered :) + #define TARGET_IDCODE 0x0 +#endif + + if(idcode != TARGET_IDCODE) { + runFatalErrorScreen("Wrong MCU"); + } +} + void per10ms() { g_tmr10ms++; @@ -1668,6 +1689,8 @@ int main() boardInit(); pulsesInit(); + checkValidMCU(); + #if defined(PCBHORUS) if (!IS_FIRMWARE_COMPATIBLE_WITH_BOARD()) { runFatalErrorScreen(STR_WRONG_PCBREV);