Skip to content

Commit

Permalink
add stack and heap size as parameters to mcu-gen (#419)
Browse files Browse the repository at this point in the history
* add stack and heap size to linker script template

* Add heap and stack parameter to mcu-gen

* Set the default stack and heap size to 0x800

* Add parameter to all the linker scripts

---------

Co-authored-by: luigi.giuffrida <[email protected]>
  • Loading branch information
LuigiGiuffrida98 and LuigiGiuffrida98 authored Oct 25, 2023
1 parent df569a8 commit 86b72f5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions mcu_cfg.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
lenght: whatisleft, #keyword used to calculate the size as: ram.length - code.lenght
}
},
stack_size: 0x800,
heap_size: 0x800,
}

debug: {
Expand Down
4 changes: 2 additions & 2 deletions sw/linker/link.ld.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ SECTIONS
PROVIDE(__boot_address = 0x180);
/* stack and heap related settings */
__stack_size = DEFINED(__stack_size) ? __stack_size : 0x800;
__stack_size = DEFINED(__stack_size) ? __stack_size : 0x${stack_size};
PROVIDE(__stack_size = __stack_size);
__heap_size = DEFINED(__heap_size) ? __heap_size : 0x800;
__heap_size = DEFINED(__heap_size) ? __heap_size : 0x${heap_size};

/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x10000)); . = SEGMENT_START("text-segment", 0x10000) + SIZEOF_HEADERS;
Expand Down
4 changes: 2 additions & 2 deletions sw/linker/link_flash_exec.ld.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ SECTIONS {
PROVIDE(__boot_address = 0x40000180);
/* stack and heap related settings */
__stack_size = DEFINED(__stack_size) ? __stack_size : 0x1000;
__stack_size = DEFINED(__stack_size) ? __stack_size : 0x${stack_size};
PROVIDE(__stack_size = __stack_size);
__heap_size = DEFINED(__heap_size) ? __heap_size : 0x1000;
__heap_size = DEFINED(__heap_size) ? __heap_size : 0x${heap_size};

/* interrupt vectors */
.vectors (ORIGIN(FLASH)):
Expand Down
4 changes: 2 additions & 2 deletions sw/linker/link_flash_load.ld.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ SECTIONS {
PROVIDE(__boot_address = 0x180);
/* stack and heap related settings */
__stack_size = DEFINED(__stack_size) ? __stack_size : 0x1000;
__stack_size = DEFINED(__stack_size) ? __stack_size : 0x${stack_size};
PROVIDE(__stack_size = __stack_size);
__heap_size = DEFINED(__heap_size) ? __heap_size : 0x1000;
__heap_size = DEFINED(__heap_size) ? __heap_size : 0x${heap_size};

/* interrupt vectors */
.vectors (ORIGIN(RAM)):
Expand Down
9 changes: 9 additions & 0 deletions util/mcu_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,15 @@ def len_extracted_peripherals(peripherals):
linker_onchip_il_start_address = str('{:08X}'.format(int(linker_onchip_data_start_address,16) + int(linker_onchip_data_size_address,16)))
linker_onchip_il_size_address = str('{:08X}'.format(ram_numbanks_il*32*1024))

stack_size = string2int(obj['linker_script']['stack_size'])
heap_size = string2int(obj['linker_script']['heap_size'])

if ((int(linker_onchip_data_size_address,16) + int(linker_onchip_code_size_address,16)) > int(ram_size_address,16)):
exit("The code and data section must fit in the RAM size, instead they takes " + str(linker_onchip_data_size_address + linker_onchip_code_size_address))

if ((int(stack_size,16) + int(heap_size,16)) > int(ram_size_address,16)):
exit("The stack and heap section must fit in the RAM size, instead they takes " + str(stack_size + heap_size))


plic_used_n_interrupts = len(obj['interrupts']['list'])
plit_n_interrupts = obj['interrupts']['number']
Expand Down Expand Up @@ -847,6 +854,8 @@ def len_extracted_peripherals(peripherals):
"linker_onchip_data_size_address" : linker_onchip_data_size_address,
"linker_onchip_il_start_address" : linker_onchip_il_start_address,
"linker_onchip_il_size_address" : linker_onchip_il_size_address,
"stack_size" : stack_size,
"heap_size" : heap_size,
"plic_used_n_interrupts" : plic_used_n_interrupts,
"plit_n_interrupts" : plit_n_interrupts,
"interrupts" : interrupts,
Expand Down

1 comment on commit 86b72f5

@danivz
Copy link
Contributor

@danivz danivz commented on 86b72f5 Oct 30, 2023

Choose a reason for hiding this comment

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

stack_size and heap_size must also be added in mcu_cfg_minimal.hjson.

Please sign in to comment.