Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

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.
Reason:
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).

Clemens

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?

Regards.

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 */
Reset_Handler,
....

[...]

void Reset_Handler(void)
{
SystemInit_ExtMemCtl();

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

/* Initialize data and bss */
__Init_Data();

/* Call the application's entry point.*/
main();
}

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

BTW: Thank's for the great OS!

Clemens


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


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner