diff --git a/src/main/drivers/system.c b/src/main/drivers/system.c index e3bcdd766c..f3aa27a35a 100644 --- a/src/main/drivers/system.c +++ b/src/main/drivers/system.c @@ -102,28 +102,25 @@ void systemResetToBootloader(void) typedef void resetHandler_t(void); typedef struct isrVector_s { - __I uint32_t stackEnd; + uint32_t stackEnd; resetHandler_t *resetHandler; } isrVector_t; -#pragma GCC push_options -#pragma GCC optimize ("O0") + void checkForBootLoaderRequest(void) { uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON); if (bootloaderRequest != RESET_BOOTLOADER_REQUEST_ROM) { - return; - } + return; + } persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE); - extern isrVector_t system_isr_vector_table_base; - - __set_MSP(system_isr_vector_table_base.stackEnd); - system_isr_vector_table_base.resetHandler(); + volatile isrVector_t *bootloaderVector = (isrVector_t *)systemBootloaderAddress(); + __set_MSP(bootloaderVector->stackEnd); + bootloaderVector->resetHandler(); while (1); } -#pragma GCC pop_options // SysTick diff --git a/src/main/drivers/system.h b/src/main/drivers/system.h index 4931c0d599..87cc140690 100644 --- a/src/main/drivers/system.h +++ b/src/main/drivers/system.h @@ -39,6 +39,7 @@ void failureMode(failureMode_e mode); // bootloader/IAP void systemReset(void); void systemResetToBootloader(void); +uint32_t systemBootloaderAddress(void); bool isMPUSoftReset(void); void cycleCounterInit(void); void checkForBootLoaderRequest(void); diff --git a/src/main/drivers/system_stm32f30x.c b/src/main/drivers/system_stm32f30x.c index e8d9d1c651..0719e576c1 100644 --- a/src/main/drivers/system_stm32f30x.c +++ b/src/main/drivers/system_stm32f30x.c @@ -61,6 +61,11 @@ bool isMPUSoftReset(void) return false; } +uint32_t systemBootloaderAddress(void) +{ + return 0x1FFFD800; +} + static void systemTimekeepingSetup(void) { RCC_ClocksTypeDef clocks; diff --git a/src/main/drivers/system_stm32f4xx.c b/src/main/drivers/system_stm32f4xx.c index b2adb289cf..aa98183484 100644 --- a/src/main/drivers/system_stm32f4xx.c +++ b/src/main/drivers/system_stm32f4xx.c @@ -138,6 +138,11 @@ bool isMPUSoftReset(void) return false; } +uint32_t systemBootloaderAddress(void) +{ + return 0x1FFF0000; +} + void systemClockSetup(uint8_t cpuUnderclock) { (void)cpuUnderclock; diff --git a/src/main/drivers/system_stm32f7xx.c b/src/main/drivers/system_stm32f7xx.c index 92f417bea0..9c39be23e8 100644 --- a/src/main/drivers/system_stm32f7xx.c +++ b/src/main/drivers/system_stm32f7xx.c @@ -61,6 +61,11 @@ bool isMPUSoftReset(void) return false; } +uint32_t systemBootloaderAddress(void) +{ + return 0x1FF00000; +} + void systemClockSetup(uint8_t cpuUnderclock) { (void)cpuUnderclock; diff --git a/src/main/target/link/stm32_flash.ld b/src/main/target/link/stm32_flash.ld index 08af3aee4c..83f6aeb32c 100644 --- a/src/main/target/link/stm32_flash.ld +++ b/src/main/target/link/stm32_flash.ld @@ -30,15 +30,6 @@ SECTIONS . = ALIGN(4); } >FLASH - /* System memory (read-only bootloader) interrupt vector */ - .system_isr_vector (NOLOAD) : - { - . = ALIGN(4); - PROVIDE (system_isr_vector_table_base = .); - KEEP(*(.system_isr_vector)) /* Bootloader code */ - . = ALIGN(4); - } >SYSTEM_MEMORY - /* The program code and other data goes into FLASH */ .text : { diff --git a/src/main/target/link/stm32_flash_f303_128k.ld b/src/main/target/link/stm32_flash_f303_128k.ld index 320148bc5b..4274fb4a45 100644 --- a/src/main/target/link/stm32_flash_f303_128k.ld +++ b/src/main/target/link/stm32_flash_f303_128k.ld @@ -19,8 +19,6 @@ MEMORY FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 126K FLASH_CONFIG (r) : ORIGIN = 0x0801F800, LENGTH = 2K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFFD800, LENGTH = 8K - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 40K CCM (xrw) : ORIGIN = 0x10000000, LENGTH = 8K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K diff --git a/src/main/target/link/stm32_flash_f303_256k.ld b/src/main/target/link/stm32_flash_f303_256k.ld index d3e49fe479..1917843495 100644 --- a/src/main/target/link/stm32_flash_f303_256k.ld +++ b/src/main/target/link/stm32_flash_f303_256k.ld @@ -19,8 +19,6 @@ MEMORY FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 250K FLASH_CONFIG (r) : ORIGIN = 0x0803E800, LENGTH = 6K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFFD800, LENGTH = 8K - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 40K CCM (xrw) : ORIGIN = 0x10000000, LENGTH = 8K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K diff --git a/src/main/target/link/stm32_flash_f405.ld b/src/main/target/link/stm32_flash_f405.ld index 4e009241d9..66721aee5f 100644 --- a/src/main/target/link/stm32_flash_f405.ld +++ b/src/main/target/link/stm32_flash_f405.ld @@ -28,8 +28,6 @@ MEMORY FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 896K FLASH_CONFIG (r) : ORIGIN = 0x080E0000, LENGTH = 128K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFF0000, LENGTH = 29K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K BACKUP_SRAM (rwx) : ORIGIN = 0x40024000, LENGTH = 4K diff --git a/src/main/target/link/stm32_flash_f405_opbl.ld b/src/main/target/link/stm32_flash_f405_opbl.ld index 8ba55f94f1..d12578f7db 100644 --- a/src/main/target/link/stm32_flash_f405_opbl.ld +++ b/src/main/target/link/stm32_flash_f405_opbl.ld @@ -29,8 +29,6 @@ MEMORY FLASH (rx) : ORIGIN = 0x08004000, LENGTH = 880K FLASH_CONFIG (r): ORIGIN = 0x080E0000, LENGTH = 128K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFF0000, LENGTH = 29K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K @@ -39,4 +37,4 @@ MEMORY REGION_ALIAS("STACKRAM", CCM) REGION_ALIAS("FASTRAM", CCM) -INCLUDE "stm32_flash.ld" +INCLUDE "stm32_flash.ld" \ No newline at end of file diff --git a/src/main/target/link/stm32_flash_f411.ld b/src/main/target/link/stm32_flash_f411.ld index a4ed5003a4..0326840b34 100644 --- a/src/main/target/link/stm32_flash_f411.ld +++ b/src/main/target/link/stm32_flash_f411.ld @@ -30,8 +30,6 @@ MEMORY FLASH_CONFIG (r) : ORIGIN = 0x08004000, LENGTH = 16K FLASH1 (rx) : ORIGIN = 0x08008000, LENGTH = 480K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFF0000, LENGTH = 29K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K } diff --git a/src/main/target/link/stm32_flash_f411_opbl.ld b/src/main/target/link/stm32_flash_f411_opbl.ld index b32fef22dc..af264a87e1 100644 --- a/src/main/target/link/stm32_flash_f411_opbl.ld +++ b/src/main/target/link/stm32_flash_f411_opbl.ld @@ -29,8 +29,6 @@ MEMORY FLASH (rx) : ORIGIN = 0x08004000, LENGTH = 368K FLASH_CONFIG (r) : ORIGIN = 0x08060000, LENGTH = 128K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFF0000, LENGTH = 29K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K CCM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K @@ -39,4 +37,4 @@ MEMORY REGION_ALIAS("STACKRAM", CCM) REGION_ALIAS("FASTRAM", CCM) -INCLUDE "stm32_flash.ld" +INCLUDE "stm32_flash.ld" \ No newline at end of file diff --git a/src/main/target/link/stm32_flash_f427.ld b/src/main/target/link/stm32_flash_f427.ld index 96a0dc0969..8c080f38e7 100755 --- a/src/main/target/link/stm32_flash_f427.ld +++ b/src/main/target/link/stm32_flash_f427.ld @@ -48,8 +48,6 @@ MEMORY FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 896K FLASH_CONFIG (r) : ORIGIN = 0x080E0000, LENGTH = 128K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFF0000, LENGTH = 29K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K diff --git a/src/main/target/link/stm32_flash_f446.ld b/src/main/target/link/stm32_flash_f446.ld index a4ed5003a4..1128fa3506 100644 --- a/src/main/target/link/stm32_flash_f446.ld +++ b/src/main/target/link/stm32_flash_f446.ld @@ -30,8 +30,6 @@ MEMORY FLASH_CONFIG (r) : ORIGIN = 0x08004000, LENGTH = 16K FLASH1 (rx) : ORIGIN = 0x08008000, LENGTH = 480K - SYSTEM_MEMORY (rx): ORIGIN = 0x1FFF0000, LENGTH = 29K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K } @@ -39,4 +37,4 @@ MEMORY REGION_ALIAS("STACKRAM", RAM) REGION_ALIAS("FASTRAM", RAM) -INCLUDE "stm32_flash_split.ld" +INCLUDE "stm32_flash_split.ld" \ No newline at end of file diff --git a/src/main/target/link/stm32_flash_f722.ld b/src/main/target/link/stm32_flash_f722.ld index 457c02a330..296708678d 100644 --- a/src/main/target/link/stm32_flash_f722.ld +++ b/src/main/target/link/stm32_flash_f722.ld @@ -37,8 +37,6 @@ MEMORY FLASH_CONFIG (r) : ORIGIN = 0x08004000, LENGTH = 16K FLASH1 (rx) : ORIGIN = 0x08008000, LENGTH = 480K - SYSTEM_MEMORY (rx) : ORIGIN = 0x1FF00000, LENGTH = 59K - TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 192K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K diff --git a/src/main/target/link/stm32_flash_f745.ld b/src/main/target/link/stm32_flash_f745.ld index 2dc5eb8acb..a83374e4e4 100644 --- a/src/main/target/link/stm32_flash_f745.ld +++ b/src/main/target/link/stm32_flash_f745.ld @@ -37,8 +37,6 @@ MEMORY FLASH_CONFIG (r) : ORIGIN = 0x08008000, LENGTH = 32K FLASH1 (rx) : ORIGIN = 0x08010000, LENGTH = 960K - SYSTEM_MEMORY (rx) : ORIGIN = 0x1FF00000, LENGTH = 60K - TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 256K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K diff --git a/src/main/target/link/stm32_flash_f746.ld b/src/main/target/link/stm32_flash_f746.ld index b80cdef7e2..0c9041676f 100644 --- a/src/main/target/link/stm32_flash_f746.ld +++ b/src/main/target/link/stm32_flash_f746.ld @@ -36,8 +36,6 @@ MEMORY FLASH_CONFIG (r) : ORIGIN = 0x08008000, LENGTH = 32K FLASH1 (rx) : ORIGIN = 0x08010000, LENGTH = 960K - SYSTEM_MEMORY (rx) : ORIGIN = 0x1FF00000, LENGTH = 60K - TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 256K MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K diff --git a/src/main/target/link/stm32_flash_f765.ld b/src/main/target/link/stm32_flash_f765.ld index eaf3209d45..86e394c673 100644 --- a/src/main/target/link/stm32_flash_f765.ld +++ b/src/main/target/link/stm32_flash_f765.ld @@ -38,8 +38,6 @@ MEMORY AXIM_FLASH_CFG (r) : ORIGIN = 0x08008000, LENGTH = 32K AXIM_FLASH1 (rx) : ORIGIN = 0x08010000, LENGTH = 1984K - SYSTEM_MEMORY (rx) : ORIGIN = 0x1FF00000, LENGTH = 59K - DTCM_RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K SRAM1 (rwx) : ORIGIN = 0x20020000, LENGTH = 368K SRAM2 (rwx) : ORIGIN = 0x2007C000, LENGTH = 16K @@ -54,4 +52,4 @@ REGION_ALIAS("STACKRAM", DTCM_RAM) REGION_ALIAS("FASTRAM", DTCM_RAM) REGION_ALIAS("RAM", SRAM1) -INCLUDE "stm32_flash_f7_split.ld" +INCLUDE "stm32_flash_f7_split.ld" \ No newline at end of file diff --git a/src/main/target/link/stm32_flash_f7_split.ld b/src/main/target/link/stm32_flash_f7_split.ld index b3ea8ede93..42d8f0205c 100644 --- a/src/main/target/link/stm32_flash_f7_split.ld +++ b/src/main/target/link/stm32_flash_f7_split.ld @@ -67,15 +67,6 @@ SECTIONS __exidx_end = .; } >FLASH - /* System memory (read-only bootloader) interrupt vector */ - .system_isr_vector (NOLOAD) : - { - . = ALIGN(4); - PROVIDE (system_isr_vector_table_base = .); - KEEP(*(.system_isr_vector)) /* Bootloader code */ - . = ALIGN(4); - } >SYSTEM_MEMORY - .busdev_registry : { PROVIDE_HIDDEN (__busdev_registry_start = .); diff --git a/src/main/target/link/stm32_flash_split.ld b/src/main/target/link/stm32_flash_split.ld index 082909493d..d0f746d1da 100644 --- a/src/main/target/link/stm32_flash_split.ld +++ b/src/main/target/link/stm32_flash_split.ld @@ -30,15 +30,6 @@ SECTIONS . = ALIGN(4); } >FLASH - /* System memory (read-only bootloader) interrupt vector */ - .system_isr_vector (NOLOAD) : - { - . = ALIGN(4); - PROVIDE (system_isr_vector_table_base = .); - KEEP(*(.system_isr_vector)) /* Bootloader code */ - . = ALIGN(4); - } >SYSTEM_MEMORY - /* The program code and other data goes into FLASH */ .text : {