Skip to content

Commit b9a48ef

Browse files
oganiglFoniksFoxjorgesg82
authored
Fix issue Bad flash memory Usage (#612)
* Created a flash size in sector 6 to keep other things differents than code, right now only metadata and Hardfault_log * add changeset * add indentation * added also in Ram.ld * add clang format --------- Co-authored-by: Boris Mladenov Beslimov <borisbeslimov@gmail.com> Co-authored-by: Jorge Sáez <125664643+jorgesg82@users.noreply.github.com>
1 parent b23c767 commit b9a48ef

File tree

6 files changed

+58
-17
lines changed

6 files changed

+58
-17
lines changed

.changesets/flash-fix-minor.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
release: patch
2+
summary: add a FLASH_ST in .ld to keep the flash information that is not code

Inc/HALAL/HardFault/HardfaultTrace.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
#ifndef __HARD_FAULT_TRACE
2-
32
#define __HARD_FAULT_TRACE
43
#include <string.h>
4+
#include <stdint.h>
55
#include "stm32h7xx_ll_gpio_wrapper.h"
66
#include "stm32h7xx_ll_bus_wrapper.h"
77
#include "stm32h7xx_ll_tim_wrapper.h"
8-
#define METADATA_FLASH_ADDR (0x080DFD00) // Metadata pool flash address
9-
#define HF_FLASH_ADDR (0x080C0000U) // Hard_fault_flash address
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
extern uint32_t _metadata;
13+
extern uint32_t _hf_log;
14+
#ifdef __cplusplus
15+
}
16+
#endif
17+
18+
#define METADATA_FLASH_ADDR ((uint32_t) & _metadata) // Metadata pool flash address
19+
#define HF_FLASH_ADDR ((uint32_t) & _hf_log) // Hard_fault_flash address
1020
#define HF_FLAG_VALUE (0xFF00FF00U) // Flag to know if already is written information in the flash
1121
#define METADATA_FLASH_SIZE (0X100U)
1222
#define HARD_FAULT_FLASH_SIZE (0X200U)

Inc/ST-LIB.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ template <auto&... devs> struct Board {
260260

261261
#ifdef HAL_IWDG_MODULE_ENABLED
262262
Watchdog::check_reset_flag();
263+
Hard_fault_check();
263264
#endif
264265
HAL_Init();
265266
HALconfig::system_clock();

STM32H723ZGTX_FLASH.ld

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ MEMORY
4646
{
4747
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
4848
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
49-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K
49+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K-128K
50+
FLASH_ST (rx) : ORIGIN = 0x080C0000, LENGTH = 128K
51+
FLASH_BT (rx) : ORIGIN = 0x080E0000, LENGTH = 128K
5052
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 320K
5153
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 32K
5254
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 16K
@@ -189,28 +191,28 @@ SECTIONS
189191
_edata = .; /* define a global symbol at data end */
190192
} >DTCMRAM AT> FLASH
191193
/*
192-
this needs to be the last thing in FLASH
193-
because the preceeding sections are appended after the one preceeding them
194-
this is, if this were the first thing in FLASH
195-
the sections below it would try to be placed afterwards
196-
thus overflowing the FLASH
194+
.hard_fault_log has to be the first thing in the FLASH_ST
197195
*/
198196

199-
.hardfault_log 0x080C0000 :
197+
.hardfault_log :
200198
{
201-
KEEP(*(.hardfault_log))
202-
. = . + 0x200;
203-
} >FLASH
199+
. = ALIGN(4);
200+
hf_log = .;
201+
KEEP(*(.hardfault_log));
202+
. += 0x200;
203+
} >FLASH_ST
204+
205+
. = ALIGN(4);
204206

205207
.metadata_pool :
206208
{
207-
. = ABSOLUTE(0x080DFD00);
208209
. = ALIGN(4);
209210
metadata = .;
210211
KEEP(*(.metadata_pool))
211212
. += 0x100;
212-
} >FLASH
213-
213+
} >FLASH_ST
214+
PROVIDE(_metadata = metadata);
215+
PROVIDE(_hf_log = hf_log);
214216
/* Uninitialized data section */
215217
. = ALIGN(4);
216218
.bss (NOLOAD) :

STM32H723ZGTX_RAM.ld

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
/* Entry Point */
4242
ENTRY(Reset_Handler)
4343

44+
4445
/* Highest address of the user mode stack */
46+
_sstack = ORIGIN(DTCMRAM);
4547
_estack = ORIGIN(DTCMRAM) + LENGTH(DTCMRAM); /* end of RAM */
4648
/* Generate a link error if heap and stack don't fit into RAM */
4749
_Min_Heap_Size = 0x200 ; /* required amount of heap */
@@ -52,7 +54,9 @@ MEMORY
5254
{
5355
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
5456
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
55-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K
57+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K-128K - 128K
58+
FLASH_ST (rx) : ORIGIN = 0x080C0000, LENGTH = 128K
59+
FLASH_BT (rx) : ORIGIN = 0x080E0000, LENGTH = 128K
5660
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 320K
5761
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 32K
5862
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 16K
@@ -89,6 +93,8 @@ SECTIONS
8993
.text :
9094
{
9195
. = ALIGN(4);
96+
_stext = .;
97+
9298
*(.text) /* .text sections (code) */
9399
*(.text*) /* .text* sections (code) */
94100
*(.glue_7) /* glue arm to thumb code */
@@ -111,6 +117,14 @@ SECTIONS
111117
. = ALIGN(4);
112118
} >RAM_D1
113119

120+
.hardfault_stack (NOLOAD) : /*Stack memory to avoid memfault inside hardfault handler*/
121+
{
122+
. = ALIGN(8);
123+
_hf_stack_start = .;
124+
. += 0x400; /* 1 KB */
125+
_hf_stack_end = .;
126+
} >DTCMRAM
127+
114128
.ARM.extab (READONLY): { *(.ARM.extab* .gnu.linkonce.armextab.*) } >RAM_D1
115129
.ARM (READONLY): {
116130
__exidx_start = .;
@@ -183,6 +197,17 @@ SECTIONS
183197
_edata = .; /* define a global symbol at data end */
184198
} >DTCMRAM
185199

200+
/*
201+
.hard_fault_log has to be the first thing in the FLASH_ST
202+
*/
203+
204+
.hardfault_stack (NOLOAD) : /*Stack memory to avoid memfault inside hardfault handler*/
205+
{
206+
. = ALIGN(8);
207+
_hf_stack_start = .;
208+
. += 0x400; /* 1 KB */
209+
_hf_stack_end = .;
210+
} >DTCMRAM
186211
/* Uninitialized data section */
187212
. = ALIGN(4);
188213
.bss :

Src/HALAL/HardFault/HardfaultTrace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
extern GPIO_TypeDef* ports_hard_fault[];
1919
extern uint16_t pins_hard_fault[];
2020
extern uint8_t hard_fault_leds_count;
21+
extern uint32_t _hf_log;
2122

2223
static void LED_Blink();
2324
static void LED_init(void);

0 commit comments

Comments
 (0)