Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changesets/flash-fix-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: patch
summary: add a FLASH_ST in .ld to keep the flash information that is not code
16 changes: 13 additions & 3 deletions Inc/HALAL/HardFault/HardfaultTrace.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#ifndef __HARD_FAULT_TRACE

#define __HARD_FAULT_TRACE
#include <string.h>
#include <stdint.h>
#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)
Expand Down
10 changes: 1 addition & 9 deletions Inc/HALAL/Services/ADC/ADC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,7 @@ struct ADCDomain {
ClockPrescaler prescaler = ClockPrescaler::DIV1,
uint32_t sample_rate_hz = 0
)
: ADC(
pin,
resolution,
sample_time,
prescaler,
sample_rate_hz,
peripheral,
channel
) {}
: ADC(pin, resolution, sample_time, prescaler, sample_rate_hz, peripheral, channel) {}

template <class Ctx> consteval std::size_t inscribe(Ctx& ctx) const {
const auto gpio_idx = gpio.inscribe(ctx);
Expand Down
1 change: 1 addition & 0 deletions Inc/ST-LIB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ template <auto&... devs> struct Board {

#ifdef HAL_IWDG_MODULE_ENABLED
Watchdog::check_reset_flag();
Hard_fault_check();
#endif
HAL_Init();
HALconfig::system_clock();
Expand Down
28 changes: 15 additions & 13 deletions STM32H723ZGTX_FLASH.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment on lines +197 to +213
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.hardfault_log and .metadata_pool reserve flash space by advancing . (0x200 / 0x100), which means the built image will contain data for those addresses. If these regions are intended to persist runtime-written logs/metadata across firmware reflashes, consider marking the sections NOLOAD and/or ensuring the flashing process does not program/erase FLASH_ST, otherwise flashing the firmware will overwrite any stored log/metadata.

Copilot uses AI. Check for mistakes.
PROVIDE(_metadata = metadata);
PROVIDE(_hf_log = hf_log);
/* Uninitialized data section */
. = ALIGN(4);
.bss (NOLOAD) :
Expand Down
27 changes: 26 additions & 1 deletion STM32H723ZGTX_RAM.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
Expand Down Expand Up @@ -89,6 +93,8 @@ SECTIONS
.text :
{
. = ALIGN(4);
_stext = .;

*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
Expand All @@ -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

Comment on lines +120 to +127
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.hardfault_stack output section is defined twice in this linker script (and _hf_stack_start/_hf_stack_end are assigned twice). This will either reserve the stack region twice or overwrite the symbol values, making the memory layout ambiguous. Keep a single .hardfault_stack definition and define the symbols only once.

Suggested change
.hardfault_stack (NOLOAD) : /*Stack memory to avoid memfault inside hardfault handler*/
{
. = ALIGN(8);
_hf_stack_start = .;
. += 0x400; /* 1 KB */
_hf_stack_end = .;
} >DTCMRAM

Copilot uses AI. Check for mistakes.
Comment on lines +120 to +127
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new .hardfault_stack reserved region and symbols (_hf_stack_start/_hf_stack_end) are not referenced anywhere in the repo (no code/asm uses them), so this change currently just consumes 1KB of DTCMRAM without affecting HardFault behavior. Either wire these symbols into the HardFault handler to actually switch to the dedicated stack, or remove the reserved section to avoid wasting memory.

Suggested change
.hardfault_stack (NOLOAD) : /*Stack memory to avoid memfault inside hardfault handler*/
{
. = ALIGN(8);
_hf_stack_start = .;
. += 0x400; /* 1 KB */
_hf_stack_end = .;
} >DTCMRAM

Copilot uses AI. Check for mistakes.
.ARM.extab (READONLY): { *(.ARM.extab* .gnu.linkonce.armextab.*) } >RAM_D1
.ARM (READONLY): {
__exidx_start = .;
Expand Down Expand Up @@ -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
Comment on lines +200 to +210
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HardfaultTrace.h now depends on linker-provided symbols _hf_log and _metadata, but this RAM linker script does not define .hardfault_log / .metadata_pool sections nor PROVIDE(_hf_log=...) / PROVIDE(_metadata=...). Builds that use STM32H723ZGTX_RAM.ld and link HardfaultTrace.c will fail with undefined symbols (or point at the wrong address). Add equivalent FLASH_ST sections + PROVIDE symbols here, or conditionally compile out HardFault/metadata flash usage for the RAM build.

Copilot uses AI. Check for mistakes.
/* Uninitialized data section */
. = ALIGN(4);
.bss :
Expand Down
1 change: 1 addition & 0 deletions Src/HALAL/HardFault/HardfaultTrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading