diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-09-23 10:59:05 +0100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-09-23 10:59:05 +0100 |
| commit | eaaebf3291a12ff65ca5c7f16e0d486fbde10efa (patch) | |
| tree | cbfa01bb3b66abb38f367d09754724f19cc64137 /stmhal | |
| parent | 2c180f7ccc456e1768fd1cb9a86399808672a237 (diff) | |
stmhal: Initialise stack pointer correctly.
Stack is full descending and must be 8-byte aligned. It must start off
pointing to just above the last byte of RAM.
Previously, stack started pointed to last byte of RAM (eg 0x2001ffff)
and so was not 8-byte aligned. This caused a bug in combination with
alloca.
This patch also updates some debug printing code.
Addresses issue #872 (among many other undiscovered issues).
Diffstat (limited to 'stmhal')
| -rw-r--r-- | stmhal/main.c | 6 | ||||
| -rw-r--r-- | stmhal/stm32f405.ld | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/stmhal/main.c b/stmhal/main.c index 6aa7b082d..05b097b7b 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -174,9 +174,9 @@ static const char fresh_readme_txt[] = int main(void) { // TODO disable JTAG - // Stack limit should be less than real stack size, so we - // had chance to recover from limit hit. - mp_stack_set_limit(&_ram_end - &_heap_end - 512); + // Stack limit should be less than real stack size, so we have a chance + // to recover from limit hit. (Limit is measured in bytes.) + mp_stack_set_limit((char*)&_ram_end - (char*)&_heap_end - 1024); /* STM32F4xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches diff --git a/stmhal/stm32f405.ld b/stmhal/stm32f405.ld index 9d9d4d508..5af1d3299 100644 --- a/stmhal/stm32f405.ld +++ b/stmhal/stm32f405.ld @@ -16,10 +16,10 @@ MEMORY _minimum_stack_size = 2K; _minimum_heap_size = 16K; -/* top end of the stack */ - -/*_stack_end = ORIGIN(RAM) + LENGTH(RAM);*/ -_estack = ORIGIN(RAM) + LENGTH(RAM) - 1; +/* 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. */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* RAM extents for the garbage collector */ _ram_end = ORIGIN(RAM) + LENGTH(RAM); |
