Skip to content

Commit 64314c7

Browse files
committed
stm32h7: Allow static placement in SRAM2 and SRAM4
Add SRAM2 and SRAM4 MEMORY regions with .sram2/.sram4 output sections so code can place buffers there via __attribute__((section(".sram2"))) or .sram4. The runtime heap setup now starts above any statically allocated content via the _esram2/_esram4 linker symbols, mirroring how the regular heap starts above _ebss. The SRAM4 region length excludes the 512-byte crashlog buffer at the top of SRAM4 so it can never be allocated over. The shared region/section definitions live in stm32h7_sram.ld and are included by both stm32h7.ld and stm32h7_bootloader.ld.
1 parent f217d88 commit 64314c7

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/platform/stm32h7/stm32h7.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ stm32h7_init(void)
114114
// SRAM2
115115
mpu_add_region((void *)0x30004000, 14,
116116
MPU_NORMAL_NON_SHARED_NON_CACHED | MPU_AP_RW | MPU_XN);
117-
heap_add_mem(0x30004000, 0x30008000,
117+
extern uint8_t _esram2[];
118+
heap_add_mem((long)_esram2, 0x30008000,
118119
MEM_TYPE_DMA | MEM_TYPE_NO_CACHE, 30);
119120

120121
// SRAM4
121122
mpu_add_region((void *)0x38000000, 14,
122123
MPU_NORMAL_NON_SHARED_NON_CACHED | MPU_AP_RW | MPU_XN);
123-
heap_add_mem(0x38000000, CRASHLOG_ADDR,
124+
extern uint8_t _esram4[];
125+
heap_add_mem((long)_esram4, CRASHLOG_ADDR,
124126
MEM_TYPE_DMA | MEM_TYPE_NO_CACHE, 40);
125127
break;
126128
}

src/platform/stm32h7/stm32h7.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ MEMORY {
44
RAM (xrw): ORIGIN = 0x20000400, LENGTH = 128K
55
}
66

7+
INCLUDE platform/stm32h7/stm32h7_sram.ld
78
INCLUDE cpu/cortexm/cortexm.ld

src/platform/stm32h7/stm32h7_bootloader.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ SECTIONS {
1717
} >BOOT
1818
}
1919

20+
INCLUDE platform/stm32h7/stm32h7_sram.ld
2021
INCLUDE cpu/cortexm/cortexm.ld
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SRAM2 and SRAM4 regions shared by the application and bootloader
2+
* linker scripts. Placement in these regions is opt-in via the .sram2
3+
* and .sram4 input sections. _esram2 / _esram4 mark the end of any
4+
* statically allocated content so the heap can be added above it.
5+
*
6+
* The last 512 bytes of SRAM4 are reserved for the crashlog buffer
7+
* (see CRASHLOG_ADDR in stm32h7.c) and excluded from the region.
8+
*/
9+
10+
MEMORY {
11+
SRAM2 (xrw): ORIGIN = 0x30004000, LENGTH = 16K
12+
SRAM4 (xrw): ORIGIN = 0x38000000, LENGTH = 16K - 512
13+
}
14+
15+
SECTIONS {
16+
.sram2 (NOLOAD) : {
17+
. = ALIGN(4);
18+
_ssram2 = .;
19+
KEEP(*(.sram2))
20+
KEEP(*(.sram2.*))
21+
. = ALIGN(4);
22+
_esram2 = .;
23+
} >SRAM2
24+
25+
.sram4 (NOLOAD) : {
26+
. = ALIGN(4);
27+
_ssram4 = .;
28+
KEEP(*(.sram4))
29+
KEEP(*(.sram4.*))
30+
. = ALIGN(4);
31+
_esram4 = .;
32+
} >SRAM4
33+
}

0 commit comments

Comments
 (0)