refactor: bootloader & cmake cleanup (#5232)
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_timer.h"
|
||||
#endif
|
||||
|
||||
@@ -45,19 +46,7 @@
|
||||
#include "thirdparty/Segger_RTT/RTT/SEGGER_RTT.h"
|
||||
#endif
|
||||
|
||||
#if defined(PCBXLITE)
|
||||
#define BOOTLOADER_KEYS 0x0F
|
||||
#elif defined(RADIO_MT12)
|
||||
#define BOOTLOADER_KEYS 0x06
|
||||
#else
|
||||
#define BOOTLOADER_KEYS 0x42
|
||||
#endif
|
||||
|
||||
#if defined(RADIO_FAMILY_T20)
|
||||
#define SECONDARY_BOOTLOADER_KEYS 0x1200
|
||||
#endif
|
||||
|
||||
#define APP_START_ADDRESS (uint32_t)(FIRMWARE_ADDRESS + BOOTLOADER_SIZE)
|
||||
#define APP_START_ADDRESS (uint32_t)(FIRMWARE_ADDRESS + BOOTLOADER_SIZE)
|
||||
|
||||
#if defined(EEPROM) || defined(SPI_FLASH)
|
||||
#define MAIN_MENU_LEN 3
|
||||
@@ -70,16 +59,6 @@
|
||||
#define SEL_CLEAR_FLASH_STORAGE_MENU_LEN 2
|
||||
#endif
|
||||
|
||||
typedef void (*voidFunction)(void);
|
||||
|
||||
#define jumpTo(addr) do { \
|
||||
SCB->VTOR = addr; \
|
||||
__set_MSP(*(__IO uint32_t*)addr); \
|
||||
uint32_t jumpAddress = *(uint32_t*)(addr + 4); \
|
||||
voidFunction jumpFn = (voidFunction)jumpAddress; \
|
||||
jumpFn(); \
|
||||
} while(0)
|
||||
|
||||
#if !defined(SIMU)
|
||||
// Bootloader marker:
|
||||
// -> used to detect valid bootloader files
|
||||
@@ -180,6 +159,7 @@ int menuFlashFile(uint32_t index, event_t event)
|
||||
|
||||
void flashWriteBlock()
|
||||
{
|
||||
// TODO: use some board provided driver instead
|
||||
uint32_t blockOffset = 0;
|
||||
#if !defined(SIMU)
|
||||
while (BlockCount) {
|
||||
@@ -205,18 +185,26 @@ void writeEepromBlock()
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU)
|
||||
|
||||
typedef void (*fctptr_t)(void);
|
||||
|
||||
static __attribute__((noreturn)) void jumpTo(uint32_t addr)
|
||||
{
|
||||
__disable_irq();
|
||||
__set_MSP(*(uint32_t*)addr);
|
||||
fctptr_t reset_handler = (fctptr_t)*(uint32_t*)(addr + 4);
|
||||
reset_handler();
|
||||
while(1){}
|
||||
}
|
||||
|
||||
// Optional board hook
|
||||
__weak void boardBLInit() {}
|
||||
__weak bool boardBLStartCondition() { return false; }
|
||||
__weak void boardBLPreJump() {}
|
||||
|
||||
void bootloaderInitApp()
|
||||
{
|
||||
LL_AHB1_GRP1_EnableClock(LCD_RCC_AHB1Periph);
|
||||
#if defined(LCD_RCC_APB2Periph)
|
||||
LL_APB2_GRP1_EnableClock(LCD_RCC_APB2Periph);
|
||||
#endif
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
|
||||
|
||||
#if defined(HAVE_BOARD_BOOTLOADER_INIT)
|
||||
boardBootloaderInit();
|
||||
#endif
|
||||
boardBLInit();
|
||||
|
||||
#if defined(DEBUG_SEGGER_RTT)
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
|
||||
@@ -232,22 +220,13 @@ void bootloaderInitApp()
|
||||
}
|
||||
}
|
||||
|
||||
#if (defined(RADIO_T8) || defined(RADIO_COMMANDO8)) && !defined(RADIOMASTER_RELEASE)
|
||||
// Bind button not pressed
|
||||
if ((~(KEYS_GPIO_REG_BIND->IDR) & KEYS_GPIO_PIN_BIND) == false) {
|
||||
#else
|
||||
// LHR & RHL trims not pressed simultanously
|
||||
#if defined(SECONDARY_BOOTLOADER_KEYS)
|
||||
if (readTrims() != BOOTLOADER_KEYS && readTrims() != SECONDARY_BOOTLOADER_KEYS) {
|
||||
#else
|
||||
if (readTrims() != BOOTLOADER_KEYS) {
|
||||
#endif
|
||||
#endif
|
||||
// TODO: deInit before restarting
|
||||
if (!boardBLStartCondition()) {
|
||||
// Start main application
|
||||
boardBLPreJump();
|
||||
jumpTo(APP_START_ADDRESS);
|
||||
}
|
||||
|
||||
// TODO: move all this into board specifics
|
||||
pwrOn();
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION) && !defined(USE_HATS_AS_KEYS)
|
||||
@@ -264,8 +243,10 @@ void bootloaderInitApp()
|
||||
|
||||
TRACE("\nBootloader started :)");
|
||||
|
||||
// TODO: move BT & EEPROM into board specifics
|
||||
#if defined(BLUETOOTH)
|
||||
// we shutdown the bluetooth module now to be sure it will be detected on firmware start
|
||||
// we shutdown the bluetooth module now to be sure it will be detected on
|
||||
// firmware start
|
||||
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE, false);
|
||||
#endif
|
||||
|
||||
@@ -592,4 +573,3 @@ int bootloaderMain()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user