MAGIC value for powerReason should be stored in RTC backup on Horus (#7096)

- Allows the radio main application to start correctly when coming from an app in RAM
- Refactoring of the `UNEXPECTED_SHUTDOWN()` process
- Saves the RTC battery as BACKUP RAM is not needed on normal shutdown
- On PWR OFF on an ALERT, the radio won't show the next alert before shutting down
- Bootloader flashable through the SD Manager
This commit is contained in:
Bertrand Songis
2019-11-21 11:50:33 +01:00
committed by GitHub
parent 103534bdcf
commit 4cdd17f0d7
41 changed files with 235 additions and 190 deletions
@@ -8,6 +8,8 @@ if(CPU_TYPE_FULL STREQUAL STM32F429xI)
../f4/system_stm32f4xx.c
../../../../../targets/${TARGET_DIR}/startup_stm32f42_43xxx.s
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rtc.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_pwr.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.c
@@ -25,6 +27,8 @@ elseif(CPU_TYPE_FULL STREQUAL STM32F407xE)
../f4/system_stm32f4xx.c
../../../../../targets/${TARGET_DIR}/startup_stm32f40_41xxx.s
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rtc.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_pwr.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.c
@@ -99,20 +103,16 @@ if(PCB STREQUAL X7 OR PCB STREQUAL XLITE OR PCB STREQUAL XLITES)
)
endif()
if(NOT (PCB STREQUAL X10 OR PCB STREQUAL X12S))
set(BOOTLOADER_SRC
${BOOTLOADER_SRC}
../../../../../targets/${TARGET_DIR}/i2c_driver.cpp
)
remove_definitions(-DDEBUG)
else()
if(PCB STREQUAL X10 OR PCB STREQUAL X12S)
set(BOOTLOADER_SRC
${BOOTLOADER_SRC}
../../../../../targets/${TARGET_DIR}/sdram_driver.c
../../../../../targets/common/arm/stm32/sdio_sd.c
../../../../../targets/common/arm/stm32/rtc_driver.cpp
../../../../../targets/${TARGET_DIR}/haptic_driver.cpp
../../../../../gui/${GUI_DIR}/bitmapbuffer.cpp
../../../../../gui/${GUI_DIR}/rle.cpp
../../../../../syscalls.c
)
@@ -123,12 +123,20 @@ else()
../../../../../serial.cpp
)
endif()
else()
set(BOOTLOADER_SRC
${BOOTLOADER_SRC}
../../../../../targets/${TARGET_DIR}/i2c_driver.cpp
)
remove_definitions(-DDEBUG)
endif()
remove_definitions(-DDISK_CACHE)
remove_definitions(-DLUA)
remove_definitions(-DCLI)
remove_definitions(-DUSB_SERIAL)
remove_definitions(-DWATCHDOG)
add_definitions(-DBOOT)
set(CMAKE_EXE_LINKER_FLAGS "-mcpu=${MCU} -mthumb -nostartfiles -lm -T${RADIO_SRC_DIRECTORY}/targets/${TARGET_DIR}/stm32_ramboot.ld -Wl,-Map=bootloader.map,--cref,--no-warn-mismatch,--gc-sections")
@@ -195,7 +195,7 @@ int main()
FRESULT fr;
uint32_t nameCount = 0;
wdt_reset();
WDG_RESET();
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph |
LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph |
@@ -215,7 +215,7 @@ int main()
#if defined(PCBHORUS)
// wait a bit for the inputs to stabilize...
for (uint32_t i = 0; i < 50000; i++) {
wdt_reset();
WDG_RESET();
}
#endif
@@ -265,12 +265,12 @@ int main()
#if defined(PWR_BUTTON_PRESS)
// wait until power button is released
while (pwrPressed()) {
wdt_reset();
WDG_RESET();
}
#endif
for (;;) {
wdt_reset();
WDG_RESET();
if (tenms) {
tenms = 0;
@@ -506,16 +506,12 @@ int main()
lcdRefresh();
lcdRefreshWait();
#if !defined(EEPROM)
// Use jump on radios with emergency mode
// to avoid triggering it with a soft reset
// Jump to proper application address
jumpTo(APP_START_ADDRESS);
#else
// Use software reset everywhere else
NVIC_SystemReset();
#if defined(RTC_BACKUP_RAM)
rtcInit();
RTC->BKP0R = SOFTRESET_REQUEST;
#endif
NVIC_SystemReset();
}
}
@@ -523,5 +519,5 @@ int main()
}
#if defined(PCBHORUS)
void *__dso_handle = 0;
void *__dso_handle = nullptr;
#endif