Skip to content

Commit def26a4

Browse files
committed
[cortex-m] Add .faststack section
1 parent 09ef00e commit def26a4

File tree

8 files changed

+41
-30
lines changed

8 files changed

+41
-30
lines changed

src/modm/architecture/utils.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
/// @note This memory location may not be DMA-able!
8282
#define modm_fastdata
8383

84+
/// Places an array into the fastest accessible memory *with* DMA access:
85+
/// data cache, core coupled memory or SRAM as fallback.
86+
/// @note This memory location is DMA-able, but uninitialized!
87+
#define modm_faststack
88+
8489
/// This branch is more likely to execute.
8590
#define modm_likely(x) (x)
8691

@@ -144,10 +149,12 @@
144149
# define modm_fastcode
145150
# define modm_ramcode
146151
# define modm_fastdata
152+
# define modm_faststack
147153
#else
148154
# define modm_fastcode modm_section(".fastcode")
149155
# define modm_ramcode modm_fastcode
150156
# define modm_fastdata modm_section(".fastdata")
157+
# define modm_faststack modm_section(".faststack")
151158
#endif
152159

153160
#ifdef __cplusplus

src/modm/platform/core/cortex/linker.macros

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE;
119119
{{ linkerscript_extern_zero | indent(8, first=True) }}
120120
%% endif
121121
__table_zero_extern_end = .;
122+
122123
__table_copy_extern_start = .;
123124
%% if linkerscript_extern_copy
124125
{{ linkerscript_extern_copy | indent(8, first=True) }}
@@ -139,17 +140,7 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE;
139140
} >{{memory}}
140141
%% endmacro
141142

142-
%% macro section(memory, name, table_copy, sections=[])
143-
%% do table_copy.append(name)
144-
.{{name}} :
145-
{
146-
. = ALIGN(4);
147-
__{{name}}_load = LOADADDR(.{{name}});
148-
__{{name}}_start = .;
149-
*(.{{name}} .{{name}}.*)
150-
. = ALIGN(4);
151-
__{{name}}_end = .;
152-
} >{{memory}}
143+
%% macro section_load(memory, table_copy, sections)
153144
%% do table_copy.extend(sections)
154145
%% for section in sections
155146
%#
@@ -192,7 +183,7 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE;
192183
%% for region in cont_region.contains
193184
/* Sections in {{ region.name|upper }} */
194185
%% if region.index
195-
{{ section(cont_region.cont_name|upper + " AT >FLASH", "data_"+region.name, table_copy) }}
186+
{{ section_load(cont_region.cont_name|upper + " AT >FLASH", table_copy, sections=["data_"+region.name]) }}
196187
%% do table_zero.append("bss_"+region.name)
197188
%% endif
198189
{{ section_heap(region.name|upper, "heap_"+region.name, cont_region.cont_name|upper,
@@ -281,7 +272,7 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE;
281272
%% endmacro
282273

283274

284-
%% macro section_ram(memory, rom, table_copy, table_zero, sections_data=[], sections_bss=[])
275+
%% macro section_ram(memory, rom, table_copy, table_zero, sections_data=[], sections_bss=[], sections_noinit=[])
285276
/* Read-write sections in {{memory}} */
286277
%% do table_copy.append("data")
287278
.data :
@@ -312,27 +303,30 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE;
312303
__bss_start = . ;
313304
*(.bss .bss.* .gnu.linkonce.b.*)
314305
. = ALIGN(4);
315-
__bss_end = .;
316-
} >{{memory}}
317-
%% do table_zero.extend(sections_bss)
318306
%% for section in sections_bss
307+
} >{{memory}}
319308
%#
320309
.{{section}} (NOLOAD) :
321310
{
322311
__{{section}}_start = . ;
323312
*(.{{section}} .{{section}}.*)
324313
. = ALIGN(4);
325314
__{{section}}_end = .;
326-
} >{{memory}}
327315
%% endfor
316+
__bss_end = .;
317+
} >{{memory}}
328318
%#
329-
.noinit (NOLOAD) :
319+
%% do sections_noinit.insert(0, "noinit")
320+
%% for section in sections_noinit
321+
%#
322+
.{{section}} (NOLOAD) :
330323
{
331-
__noinit_start = .;
332-
*(.noinit .noinit.*)
324+
__{{section}}_start = . ;
325+
*(.{{section}} .{{section}}.*)
333326
. = ALIGN(4);
334-
__noinit_end = .;
327+
__{{section}}_end = .;
335328
} >{{memory}}
329+
%% endfor
336330
%% endmacro
337331

338332

src/modm/platform/core/cortex/ram.ld.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ SECTIONS
2828

2929
{{ linker.section_ram(cont_ram_regions[0].cont_name|upper, "FLASH", table_copy, table_zero,
3030
sections_data=["fastdata", "fastcode", "data_" + cont_ram_regions[0].contains[0].name],
31-
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name]) }}
31+
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name],
32+
sections_noinit=["faststack"]) }}
3233

3334
{{ linker.all_heap_sections(table_copy, table_zero, table_heap) }}
3435

src/modm/platform/core/sam/module.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Currently only one basic linkerscript is supported.
1919
│ +HEAP_RAM │
2020
│ .noinit_ram │
2121
│ .noinit │
22+
│ .faststack │
2223
│ .bss_ram │
2324
│ .bss │
2425
│ .data_ram │

src/modm/platform/core/stm32/dccm.ld.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ SECTIONS
2828

2929
{{ linker.section_ram(cont_ram_regions[0].cont_name|upper, "FLASH", table_copy, table_zero,
3030
sections_data=["fastcode", "data_" + cont_ram_regions[0].contains[0].name],
31-
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name]) }}
31+
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name],
32+
sections_noinit=["faststack"]) }}
3233

3334
{{ linker.all_heap_sections(table_copy, table_zero, table_heap) }}
3435

3536
%% if "backup" in regions
3637
/* Sections in memory region BACKUP */
37-
{{ linker.section("BACKUP AT >FLASH", "data_backup", table_copy) }}
38+
{{ linker.section_load("BACKUP AT >FLASH", table_copy, sections=["data_backup"]) }}
3839

3940
{{ linker.section_heap("BACKUP", "heap_backup", sections=["bss_backup", "noinit_backup"]) }}
4041
%% do table_heap.append({"name": "heap_backup", "prop": "0x4009"})
4142
%% do table_zero.append("bss_backup")
4243
%% endif
4344

4445
/* Sections in memory region CCM */
45-
{{ linker.section("CCM AT >FLASH", "fastdata", table_copy, sections=["data_ccm"]) }}
46+
{{ linker.section_load("CCM AT >FLASH", table_copy, sections=["fastdata", "data_ccm"]) }}
4647

4748
{{ linker.section_heap("CCM", "heap_ccm", sections=["bss_ccm", "noinit_ccm"]) }}
4849
%% do table_heap.append({"name": "heap_ccm", "prop": "0x2002"})

src/modm/platform/core/stm32/iccm.ld.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ SECTIONS
1919

2020
{{ linker.section_ram(cont_ram_regions[0].cont_name|upper, "FLASH", table_copy, table_zero,
2121
sections_data=["data_" + cont_ram_regions[0].contains[0].name],
22-
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name]) }}
22+
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name],
23+
sections_noinit=["faststack"]) }}
2324

2425
{{ linker.all_heap_sections(table_copy, table_zero, table_heap) }}
2526
%% if with_crashcatcher
@@ -34,7 +35,7 @@ SECTIONS
3435
%% endif
3536

3637
/* Sections in memory region CCM */
37-
{{ linker.section("CCM AT >FLASH", "fastcode", table_copy, sections=["fastdata", "data_ccm"]) }}
38+
{{ linker.section_load("CCM AT >FLASH", table_copy, sections=["fastcode", "fastdata", "data_ccm"]) }}
3839

3940
{{ linker.section_heap("CCM", "heap_ccm", sections=["bss_ccm", "noinit_ccm"]) }}
4041
%% do table_heap.append({"name": "heap_ccm", "prop": "0x2006"})

src/modm/platform/core/stm32/idtcm.ld.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SECTIONS
2020
%% endif
2121

2222
/* Sections in memory region ITCM */
23-
{{ linker.section("ITCM AT >FLASH", "fastcode", table_copy, sections=["data_itcm"]) }}
23+
{{ linker.section_load("ITCM AT >FLASH", table_copy, sections=["fastcode", "data_itcm"]) }}
2424

2525
{{ linker.section_heap("ITCM", "heap_itcm", sections=["noinit_itcm"]) }}
2626
%% do table_heap.append({"name": "heap_itcm", "prop": "0x201f"})
@@ -29,7 +29,8 @@ SECTIONS
2929

3030
{{ linker.section_ram(cont_ram_regions[0].cont_name|upper, "FLASH", table_copy, table_zero,
3131
sections_data=["fastdata", "data_" + cont_ram_regions[0].contains[0].name],
32-
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name]) }}
32+
sections_bss=["bss_" + cont_ram_regions[0].contains[0].name],
33+
sections_noinit=["faststack"]) }}
3334

3435
{{ linker.all_heap_sections(table_copy, table_zero, table_heap) }}
3536
%% if with_crashcatcher
@@ -41,7 +42,7 @@ SECTIONS
4142

4243
%% if "backup" in regions
4344
/* Sections in memory region BACKUP */
44-
{{ linker.section("BACKUP AT >FLASH", "data_backup", table_copy) }}
45+
{{ linker.section_load("BACKUP AT >FLASH", table_copy, sections=["data_backup"]) }}
4546

4647
{{ linker.section_heap("BACKUP", "heap_backup", sections=["bss_backup", "noinit_backup"]) }}
4748
%% do table_heap.append({"name": "heap_backup", "prop": "0x4009"})

src/modm/platform/core/stm32/module.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ SRAMs explicitly to free up the space in the lower sections.
5959
│ +HEAP_SRAM1 │
6060
│ .noinit_sram1 │
6161
│ .noinit │
62+
│ .faststack │
6263
│ .bss_sram1 │
6364
│ .bss │
6465
│ .data_sram1 │
@@ -128,6 +129,7 @@ Therefore the main stack is placed into SRAM, even though it is slower than CCM.
128129
│ +HEAP_SRAM1 │
129130
│ .noinit_sram1 │
130131
│ .noinit │
132+
│ .faststack │
131133
│ .bss_sram1 │
132134
│ .bss │
133135
│ .data_sram1 │
@@ -199,6 +201,7 @@ not DMA-able.
199201
│ +HEAP_SRAM1 │
200202
│ .noinit_sram1 │
201203
│ .noinit │
204+
│ .faststack │
202205
│ .bss_sram1 │
203206
│ .bss │
204207
│ .data_sram1 │
@@ -277,6 +280,7 @@ overflow into the SRAM1/2 sections.
277280
│ +HEAP_DTCM │
278281
│ .noinit_dtcm │
279282
│ .noinit │
283+
│ .faststack │
280284
D-Code │ .bss_dtcm │
281285
only │ .bss │
282286
access │ .data_dtcm │
@@ -383,6 +387,7 @@ placed into the 128kB DTCM, but cannot overflow into D1_SRAM section.
383387
│ +HEAP_DTCM │
384388
│ .noinit_dtcm │
385389
│ .noinit │
390+
│ .faststack │
386391
D-Code │ .bss_dtcm │
387392
only │ .data_dtcm │
388393
access │ .data │

0 commit comments

Comments
 (0)