Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Hint: STM32 HD stack problem

Posted by Clemens Gerlach on June 16, 2009
Hi All,

I just searched a while so I share it here before someone else is wasting time...

I am using a STM32 High-Density device with FreeRTOS and the ST FWlib 3.0 and had system crashes.
The supplied startup code in the FWlib sets the stack pointer in the vector table (1st entry) to the fixed address 0x20000400. After initializing the external memory interface (if any) it sets the MSP register to the desired value (_estack defined in the linker script).
Normaly this should be ok but FreeRTOS resets the stack pointer (MSP) to the value stored in the vector table (when staring the first thread). This is ok and saves stack space.

The too ideas are nice but do not play together very well...

My solution was to edit the startup code (in $(FWLIB)/CMSIS/Core/CM3/startup) to place &_estack into the vector table (I am not using external RAM).


RE: Hint: STM32 HD stack problem

Posted by Richard on June 16, 2009
Hmm, interesting. All CM3 devices are supposed to have the stack location in the first position within the vector table, FreeRTOS locates the vector table through the system control registers, and resets the stack back to its start position. Are you saying the STM32 startup code defines a different stack in the linker script to that pointed to by the vector table? I will need to look at that in more detail - thanks for the heads up. What is at 0x20000400?

This must be resurged in the linker script?


RE: Hint: STM32 HD stack problem

Posted by Clemens Gerlach on June 16, 2009
Hi Richard,

the problem only occurs with the STM32 startup code for the high-density
devices. Since firmware lib 3.0.0 they are included. I think their intention
for using this scheme was to provide a stack for the startup code (RAM
starts at 0x20000000), setup the external memory controller and then move
the stack to the end of the ram (which may be inside the external memory).

I think FreeRTOS behavior is correct. It just collides with the (example)
routines from ST. But if someone (for whatever reason) wants to put the stack
into external RAM FreeRTOS' way of resetting the stack may be a problem.

From $(fwlib)/Libraries/CMSIS/Core/CM3/startup/gcc/startup_stm32f10x_hd.c:

#define Initial_spTop 0x20000400 <- this is in internal ram (cg)


__attribute__ ((section(".isr_vector")))
void (* const g_pfnVectors[])(void) =
(void *)Initial_spTop, /* The initial stack pointer */


void Reset_Handler(void)

/* restore original stack pointer */
asm(" LDR r0, =_estack"); <- _estack defined by linker script
asm(" MSR msp, r0");

/* Initialize data and bss */

/* Call the application's entry point.*/

Maybe FreeRTOS' stack reset behavior sould be documented in the port
information. Also the use of the dual stack pointers is not mentioned

BTW: Thank's for the great OS!


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists