Skip to content

stm32h7: Fix Protected user SRAM placement and attributes. - #19983

Merged
xiaoxiang781216 merged 2 commits into
apache:masterfrom
13022591351:fix/stm32h7-protected-memory
Aug 28, 2026
Merged

stm32h7: Fix Protected user SRAM placement and attributes.#19983
xiaoxiang781216 merged 2 commits into
apache:masterfrom
13022591351:fix/stm32h7-protected-memory

Conversation

@13022591351

@13022591351 13022591351 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Make STM32H7 Protected user heap placement consistently use SRAM_END,
    which represents the primary SRAM selected for the active M7/M4 chip
    configuration.
  • Remove the fixed SRAM123_END placement that is inconsistent with heap
    sizing and is undefined for dual-core M7 and M4 configurations.
  • Map Protected user data and heap SRAM as Normal, cacheable, and
    non-shareable so LDREX/STREX synchronization uses the CPU-local exclusive
    monitor on STM32H7.
  • Keep dual-core RPTUN SRAM unaffected: its shared region is mapped separately
    with explicit shareable attributes.

Impact

  • New feature: NO. This fixes STM32H7 Protected memory placement and MPU
    attributes.
  • User adaptation: NO.
  • Build process: NO.
  • Hardware: YES. Only STM32H7 Protected builds are affected. Flat builds
    are unchanged. Dual-core shared RPTUN SRAM keeps its existing mapping.
  • Documentation: Public API documentation is not affected; source comments
    document the mapping and dual-core exception.
  • Security: NO reduction in privilege separation. User access permissions
    remain P:RW/U:RW; only the SRAM memory attributes change.
  • Compatibility: The Protected user heap now resides in the SRAM region
    selected by the board/chip configuration instead of a fixed D2 boundary.

Testing

Build host:

  • Linux 6.8.0-60-generic, x86_64
  • GNU Arm Embedded Toolchain 10.3.1 20210824

Target:

Build output:

Protected kernel:
  kflash  877528 B / 896 KB (95.64%)
  ksram    54320 B / 128 KB (41.44%)

Protected user:
  uflash  751000 B / 1 MB   (71.62%)
  usram     8192 B / 384 KB (2.08%)

Runtime stress results:

Protected libc user WQ: 15.6540 / 15.6540 / 15.6540 s
Protected kernel WQ:    30.1490 / 30.1480 / 30.1480 s

Steady current memory after initial run:
  Kmem used/free: 10104 / 243848 B
  Umem used/free:  9232 / 416752 B

The tests repeatedly exercised pthread creation, mutex/semaphore atomics,
multi-worker queues, synchronous cancellation, and queue teardown. All runs
completed without assertion, fault, residual worker, or cumulative Kmem/Umem
growth. The board cold-booted into NSH and remained stable.

Validation:

tools/checkpatch.sh -m -g upstream/master..fix/stm32h7-protected-memory: pass
tools/checkpatch.sh -g upstream/master..fix/stm32h7-protected-memory: pass
git diff --check upstream/master..fix/stm32h7-protected-memory: pass

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to the contributing guidelines and coding standard.
  • My PR is still work in progress.
  • My PR is ready for review and can be safely merged.

@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Size: S The size of the change in this PR is small labels Aug 27, 2026
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

ci was fixed, please rebase your change to the last master. @13022591351

up_allocate_heap() calculates the available user heap from SRAM_END but
previously placed the aligned region relative to SRAM123_END.  That mixes
the selected primary SRAM with a fixed D2 SRAM boundary and leaves
SRAM123_END undefined for dual-core M7 and M4 configurations.

Place the user heap relative to SRAM_END so its size, MPU alignment, and
location all refer to the SRAM region selected by the chip configuration.

Tested by building and booting a Protected image on an STM32H7 PX4 FMUv6C.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
The generic ARMv7-M user SRAM helper marks memory shareable.  STM32H7
Protected user data and heaps can reside in cacheable AXI or D2 SRAM, where
userspace synchronization needs LDREX/STREX to use the CPU-local exclusive
monitor.

Map protected user SRAM as Normal, cacheable, and non-shareable.  Dual-core
RPTUN SRAM remains unaffected because it is mapped separately with explicit
shareable attributes.

Tested by booting a Protected image and running user and kernel work-queue
stress tests on an STM32H7 PX4 FMUv6C.

Assisted-by: Codex:GPT-5
Signed-off-by: DuoYuWang <thirteenking.wang@gmail.com>
@13022591351
13022591351 force-pushed the fix/stm32h7-protected-memory branch from 0ad0903 to a475478 Compare August 27, 2026 11:10
@13022591351

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216 Rebased onto the latest master (c6b349b023). The two patches are unchanged according to git range-diff, and tools/checkpatch.sh -g upstream/master..HEAD passes. The new CI run has started. Thanks.

@xiaoxiang781216
xiaoxiang781216 merged commit 519c9a4 into apache:master Aug 28, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants