diff --git a/.changesets/flash-fix-minor.md b/.changesets/flash-fix-minor.md new file mode 100644 index 000000000..6a96b2888 --- /dev/null +++ b/.changesets/flash-fix-minor.md @@ -0,0 +1,2 @@ +release: patch +summary: add a FLASH_ST in .ld to keep the flash information that is not code diff --git a/Inc/HALAL/HardFault/HardfaultTrace.h b/Inc/HALAL/HardFault/HardfaultTrace.h index a81348b1d..5fe2d7c40 100644 --- a/Inc/HALAL/HardFault/HardfaultTrace.h +++ b/Inc/HALAL/HardFault/HardfaultTrace.h @@ -1,12 +1,22 @@ #ifndef __HARD_FAULT_TRACE - #define __HARD_FAULT_TRACE #include +#include #include "stm32h7xx_ll_gpio_wrapper.h" #include "stm32h7xx_ll_bus_wrapper.h" #include "stm32h7xx_ll_tim_wrapper.h" -#define METADATA_FLASH_ADDR (0x080DFD00) // Metadata pool flash address -#define HF_FLASH_ADDR (0x080C0000U) // Hard_fault_flash address + +#ifdef __cplusplus +extern "C" { +#endif +extern uint32_t _metadata; +extern uint32_t _hf_log; +#ifdef __cplusplus +} +#endif + +#define METADATA_FLASH_ADDR ((uint32_t) & _metadata) // Metadata pool flash address +#define HF_FLASH_ADDR ((uint32_t) & _hf_log) // Hard_fault_flash address #define HF_FLAG_VALUE (0xFF00FF00U) // Flag to know if already is written information in the flash #define METADATA_FLASH_SIZE (0X100U) #define HARD_FAULT_FLASH_SIZE (0X200U) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index 24c8c7a55..1b68aee53 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -236,6 +236,7 @@ template struct Board { #ifdef HAL_IWDG_MODULE_ENABLED Watchdog::check_reset_flag(); + Hard_fault_check(); #endif HAL_Init(); HALconfig::system_clock(); diff --git a/STM32H723ZGTX_FLASH.ld b/STM32H723ZGTX_FLASH.ld index 73c7f2126..5e9e3f041 100644 --- a/STM32H723ZGTX_FLASH.ld +++ b/STM32H723ZGTX_FLASH.ld @@ -46,7 +46,9 @@ MEMORY { ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K-128K + FLASH_ST (rx) : ORIGIN = 0x080C0000, LENGTH = 128K + FLASH_BT (rx) : ORIGIN = 0x080E0000, LENGTH = 128K RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 320K RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 32K RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 16K @@ -189,28 +191,28 @@ SECTIONS _edata = .; /* define a global symbol at data end */ } >DTCMRAM AT> FLASH /* - this needs to be the last thing in FLASH - because the preceeding sections are appended after the one preceeding them - this is, if this were the first thing in FLASH - the sections below it would try to be placed afterwards - thus overflowing the FLASH + .hard_fault_log has to be the first thing in the FLASH_ST */ - .hardfault_log 0x080C0000 : + .hardfault_log : { - KEEP(*(.hardfault_log)) - . = . + 0x200; - } >FLASH + . = ALIGN(4); + hf_log = .; + KEEP(*(.hardfault_log)); + . += 0x200; + } >FLASH_ST + + . = ALIGN(4); .metadata_pool : { - . = ABSOLUTE(0x080DFD00); . = ALIGN(4); metadata = .; KEEP(*(.metadata_pool)) . += 0x100; - } >FLASH - + } >FLASH_ST + PROVIDE(_metadata = metadata); + PROVIDE(_hf_log = hf_log); /* Uninitialized data section */ . = ALIGN(4); .bss (NOLOAD) : diff --git a/STM32H723ZGTX_RAM.ld b/STM32H723ZGTX_RAM.ld index 9cc0683a4..8611972c3 100644 --- a/STM32H723ZGTX_RAM.ld +++ b/STM32H723ZGTX_RAM.ld @@ -41,7 +41,9 @@ /* Entry Point */ ENTRY(Reset_Handler) + /* Highest address of the user mode stack */ +_sstack = ORIGIN(DTCMRAM); _estack = ORIGIN(DTCMRAM) + LENGTH(DTCMRAM); /* end of RAM */ /* Generate a link error if heap and stack don't fit into RAM */ _Min_Heap_Size = 0x200 ; /* required amount of heap */ @@ -52,7 +54,9 @@ MEMORY { ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K - 128K + FLASH_ST (rx) : ORIGIN = 0x080C0000, LENGTH = 128K + FLASH_BT (rx) : ORIGIN = 0x080E0000, LENGTH = 128K RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 320K RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 32K RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 16K @@ -89,6 +93,8 @@ SECTIONS .text : { . = ALIGN(4); + _stext = .; + *(.text) /* .text sections (code) */ *(.text*) /* .text* sections (code) */ *(.glue_7) /* glue arm to thumb code */ @@ -111,6 +117,14 @@ SECTIONS . = ALIGN(4); } >RAM_D1 + .hardfault_stack (NOLOAD) : /*Stack memory to avoid memfault inside hardfault handler*/ + { + . = ALIGN(8); + _hf_stack_start = .; + . += 0x400; /* 1 KB */ + _hf_stack_end = .; + } >DTCMRAM + .ARM.extab (READONLY): { *(.ARM.extab* .gnu.linkonce.armextab.*) } >RAM_D1 .ARM (READONLY): { __exidx_start = .; @@ -183,6 +197,17 @@ SECTIONS _edata = .; /* define a global symbol at data end */ } >DTCMRAM + /* + .hard_fault_log has to be the first thing in the FLASH_ST + */ + + .hardfault_stack (NOLOAD) : /*Stack memory to avoid memfault inside hardfault handler*/ + { + . = ALIGN(8); + _hf_stack_start = .; + . += 0x400; /* 1 KB */ + _hf_stack_end = .; + } >DTCMRAM /* Uninitialized data section */ . = ALIGN(4); .bss : diff --git a/Src/HALAL/HardFault/HardfaultTrace.c b/Src/HALAL/HardFault/HardfaultTrace.c index 64dd3f6fb..0aa1d7c18 100644 --- a/Src/HALAL/HardFault/HardfaultTrace.c +++ b/Src/HALAL/HardFault/HardfaultTrace.c @@ -18,6 +18,7 @@ extern GPIO_TypeDef* ports_hard_fault[]; extern uint16_t pins_hard_fault[]; extern uint8_t hard_fault_leds_count; +extern uint32_t _hf_log; static void LED_Blink(); static void LED_init(void);