Browse Source

stm32: In link script, define start of stack separately from heap end.

Previously the end of the heap was the start (lowest address) of the stack.
With the changes in this commit these addresses are now independent,
allowing a board to place the heap and stack in separate locations.
pull/4845/head
Chris Mason 6 years ago
committed by Damien George
parent
commit
14cf91f704
  1. 8
      ports/stm32/boards/PYBD_SF2/f722_qspi.ld
  2. 8
      ports/stm32/boards/PYBD_SF6/f767.ld
  3. 6
      ports/stm32/boards/STM32F769DISC/f769_qspi.ld
  4. 8
      ports/stm32/boards/stm32f091xc.ld
  5. 10
      ports/stm32/boards/stm32f401xd.ld
  6. 8
      ports/stm32/boards/stm32f401xe.ld
  7. 8
      ports/stm32/boards/stm32f405.ld
  8. 8
      ports/stm32/boards/stm32f411.ld
  9. 8
      ports/stm32/boards/stm32f413xg.ld
  10. 8
      ports/stm32/boards/stm32f413xh.ld
  11. 8
      ports/stm32/boards/stm32f429.ld
  12. 6
      ports/stm32/boards/stm32f439.ld
  13. 8
      ports/stm32/boards/stm32f722.ld
  14. 10
      ports/stm32/boards/stm32f746.ld
  15. 8
      ports/stm32/boards/stm32f767.ld
  16. 8
      ports/stm32/boards/stm32f769.ld
  17. 8
      ports/stm32/boards/stm32h743.ld
  18. 8
      ports/stm32/boards/stm32l432.ld
  19. 8
      ports/stm32/boards/stm32l476xe.ld
  20. 8
      ports/stm32/boards/stm32l476xg.ld
  21. 8
      ports/stm32/boards/stm32l496xg.ld
  22. 1
      ports/stm32/gccollect.h
  23. 2
      ports/stm32/main.c
  24. 1
      ports/stm32/modmachine.c
  25. 4
      ports/stm32/pybthread.c
  26. 2
      ports/stm32/stm32_it.c

8
ports/stm32/boards/PYBD_SF2/f722_qspi.ld

@ -29,16 +29,16 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K;
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = _ram_end - 16K; /* 16k stack */
_heap_end = _sstack;
ENTRY(Reset_Handler)

8
ports/stm32/boards/PYBD_SF6/f767.ld

@ -28,16 +28,16 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 24K;
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = _ram_end - 24K; /* 24k stack */
_heap_end = _sstack;
ENTRY(Reset_Handler)

6
ports/stm32/boards/STM32F769DISC/f769_qspi.ld

@ -27,14 +27,16 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 32K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20078000; /* tunable */
_heap_end = _sstack;
ENTRY(Reset_Handler)

8
ports/stm32/boards/stm32f091xc.ld

@ -14,13 +14,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 6K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20006800; /* room for a 6k stack */
_heap_end = _sstack;

10
ports/stm32/boards/stm32f401xd.ld

@ -14,15 +14,15 @@ MEMORY
/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
_minimum_heap_size = 16K; /* tunable */
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K;
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20014000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f401xe.ld

@ -16,13 +16,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20014000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f405.ld

@ -17,13 +17,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2001c000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f411.ld

@ -16,13 +16,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2001c000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f413xg.ld

@ -19,13 +19,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = _ram_end - 16K; /* 240K, tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f413xh.ld

@ -19,13 +19,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = _ram_end - 16K; /* 240K, tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f429.ld

@ -17,13 +17,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2002c000; /* tunable */
_heap_end = _sstack;

6
ports/stm32/boards/stm32f439.ld

@ -18,11 +18,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* top end of the stack */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2002c000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f722.ld

@ -15,13 +15,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 32K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20038000; /* tunable */
_heap_end = _sstack;

10
ports/stm32/boards/stm32f746.ld

@ -1,5 +1,5 @@
/*
GNU linker script for STM32F405
GNU linker script for STM32F746
*/
/* Specify the memory areas */
@ -17,13 +17,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2004c000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f767.ld

@ -18,13 +18,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 32K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20078000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32f769.ld

@ -17,13 +17,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 32K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20078000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32h743.ld

@ -17,13 +17,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define tho top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2407C000; /* tunable */
_heap_end = _sstack;

8
ports/stm32/boards/stm32l432.ld

@ -15,13 +15,13 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define the top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 6K; /* tunable */
/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2000A800; /* room for a 6k stack */
_heap_end = _sstack;

8
ports/stm32/boards/stm32l476xe.ld

@ -18,10 +18,10 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define the top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_fs_cache_start = ORIGIN(FS_CACHE);
@ -29,7 +29,7 @@ _ram_fs_cache_end = ORIGIN(FS_CACHE) + LENGTH(FS_CACHE);
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20014000; /* tunable */
_heap_end = _sstack;
_flash_fs_start = ORIGIN(FLASH_FS);
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);

8
ports/stm32/boards/stm32l476xg.ld

@ -18,10 +18,10 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define the top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);
_sstack = _estack - 16K; /* tunable */
/* RAM extents for the garbage collector */
_ram_fs_cache_start = ORIGIN(FS_CACHE);
@ -29,7 +29,7 @@ _ram_fs_cache_end = ORIGIN(FS_CACHE) + LENGTH(FS_CACHE);
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20014000; /* tunable */
_heap_end = _sstack;
_flash_fs_start = ORIGIN(FLASH_FS);
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);

8
ports/stm32/boards/stm32l496xg.ld

@ -18,10 +18,10 @@ MEMORY
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
/* Define the top end of the stack. The stack is full descending so begins just
above last byte of RAM. Note that EABI requires the stack to be 8-byte
aligned for a call. */
/* Define the stack. The stack is full descending so begins just above last byte
of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM) + LENGTH(SRAM2);
_sstack = _estack - 206K; /* tunable */
/* RAM extents for the garbage collector */
_ram_fs_cache_start = ORIGIN(FS_CACHE);
@ -29,7 +29,7 @@ _ram_fs_cache_end = ORIGIN(FS_CACHE) + LENGTH(FS_CACHE);
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM) + LENGTH(SRAM2);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2001C000; /* tunable */
_heap_end = _sstack;
_flash_fs_start = ORIGIN(FLASH_FS);
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);

1
ports/stm32/gccollect.h

@ -37,6 +37,7 @@ extern uint32_t _sbss;
extern uint32_t _ebss;
extern uint32_t _heap_start;
extern uint32_t _heap_end;
extern uint32_t _sstack;
extern uint32_t _estack;
extern uint32_t _ram_end;

2
ports/stm32/main.c

@ -536,7 +536,7 @@ soft_reset:
// to recover from limit hit. (Limit is measured in bytes.)
// Note: stack control relies on main thread being initialised above
mp_stack_set_top(&_estack);
mp_stack_set_limit((char*)&_estack - (char*)&_heap_end - 1024);
mp_stack_set_limit((char*)&_estack - (char*)&_sstack - 1024);
// GC init
gc_init(MICROPY_HEAP_START, MICROPY_HEAP_END);

1
ports/stm32/modmachine.c

@ -174,6 +174,7 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
printf("_edata=%p\n", &_edata);
printf("_sbss=%p\n", &_sbss);
printf("_ebss=%p\n", &_ebss);
printf("_sstack=%p\n", &_sstack);
printf("_estack=%p\n", &_estack);
printf("_ram_start=%p\n", &_ram_start);
printf("_heap_start=%p\n", &_heap_start);

4
ports/stm32/pybthread.c

@ -70,8 +70,8 @@ void pyb_thread_init(pyb_thread_t *thread) {
thread->sp = NULL; // will be set when this thread switches out
thread->local_state = 0; // will be set by mp_thread_init
thread->arg = NULL;
thread->stack = &_heap_end;
thread->stack_len = ((uint32_t)&_estack - (uint32_t)&_heap_end) / sizeof(uint32_t);
thread->stack = &_sstack;
thread->stack_len = ((uint32_t)&_estack - (uint32_t)&_sstack) / sizeof(uint32_t);
thread->all_next = NULL;
thread->run_prev = thread;
thread->run_next = thread;

2
ports/stm32/stm32_it.c

@ -181,7 +181,7 @@ void HardFault_C_Handler(ExceptionRegisters_t *regs) {
if ((void*)&_ram_start <= (void*)regs && (void*)regs < (void*)&_ram_end) {
mp_hal_stdout_tx_str("Stack:\r\n");
uint32_t *stack_top = &_estack;
if ((void*)regs < (void*)&_heap_end) {
if ((void*)regs < (void*)&_sstack) {
// stack not in static stack area so limit the amount we print
stack_top = (uint32_t*)regs + 32;
}

Loading…
Cancel
Save