From eaaebf3291a12ff65ca5c7f16e0d486fbde10efa Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 Sep 2014 10:59:05 +0100 Subject: 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). --- stmhal/main.c | 6 +++--- stmhal/stm32f405.ld | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'stmhal') 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); -- cgit v1.2.3