Skip to content

Fix issue Bad flash memory Usage#612

Open
oganigl wants to merge 7 commits intodevelopmentfrom
fix_issue598
Open

Fix issue Bad flash memory Usage#612
oganigl wants to merge 7 commits intodevelopmentfrom
fix_issue598

Conversation

@oganigl
Copy link
Copy Markdown
Contributor

@oganigl oganigl commented Mar 22, 2026

Created a flash size in sector 6 to keep other things differents than code, right now only metadata and Hardfault_log

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 22, 2026

ST-LIB Release Plan

  • Current version: 5.0.0
  • Pending changesets: 4
  • Highest requested bump: minor
  • Next version if merged now: 5.1.0

Pending changes

  • minor Refactor the ADC stack around DMA-backed acquisition using new MPU (.changesets/adc-dma-minor.md)
  • patch add a FLASH_ST in .ld to keep the flash information that is not code (.changesets/flash-fix-minor.md)
  • patch Fix incorrect GPIO alternate-function availability bitmaps (.changesets/gpio-af-bitmaps-patch.md)
  • none Introduce semver tooling and release automation infrastructure (.changesets/revive-releases-bootstrap.md)

@oganigl oganigl requested review from Cantonplas and FoniksFox March 22, 2026 20:42
Cantonplas
Cantonplas previously approved these changes Mar 22, 2026
Copy link
Copy Markdown
Contributor

@Cantonplas Cantonplas left a comment

Choose a reason for hiding this comment

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

LGTM

FoniksFox
FoniksFox previously approved these changes Mar 30, 2026
Copy link
Copy Markdown
Contributor

@FoniksFox FoniksFox left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Reserves dedicated flash sectors for non-code data (HardFault log + metadata) and switches HardFault/metadata addressing from hard-coded constants to linker-provided symbols.

Changes:

  • Split internal flash into FLASH (code) plus FLASH_ST/FLASH_BT reserved regions in both linker scripts.
  • Place .hardfault_log and .metadata_pool into FLASH_ST and expose their addresses via linker symbols consumed by HardfaultTrace.h.
  • Invoke Hard_fault_check() during board initialization and apply a small ADC constructor formatting change.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
STM32H723ZGTX_RAM.ld Adjusts flash region layout; adds HardFault stack section (currently duplicated)
STM32H723ZGTX_FLASH.ld Moves hardfault log + metadata pool into FLASH_ST and exports linker symbols
Src/HALAL/HardFault/HardfaultTrace.c Adds linker symbol extern for HardFault log address
Inc/HALAL/HardFault/HardfaultTrace.h Replaces fixed flash addresses with linker-symbol-based addresses
Inc/ST-LIB.hpp Calls Hard_fault_check() during init when IWDG is enabled
Inc/HALAL/Services/ADC/ADC.hpp Constructor formatting (single-line delegating ctor)
.changesets/flash-fix-minor.md Adds patch changeset entry for the flash layout change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

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 +200 to +210
/*
.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
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.
Comment on lines +120 to +127
.hardfault_stack (NOLOAD) : /*Stack memory to avoid memfault inside hardfault handler*/
{
. = ALIGN(8);
_hf_stack_start = .;
. += 0x400; /* 1 KB */
_hf_stack_end = .;
} >DTCMRAM

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.
Comment on lines +197 to +213
.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
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants