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




Loading

STM32 Primer HardFault (Help!)

Posted by https://www.google.com/accounts on March 28, 2010
Hi All

I'm trying to get stm std peripheral lib V3.2.0 working with FreeRTOS 6.0.4. on stm primer1 GCC.
It crashes in here:
void vPortStartFirstTask( void )
{
__asm volatile(
" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
" ldr r0, [r0] \n"
" ldr r0, [r0] \n"
" msr msp, r0\n" /* Set the msp back to the start of the stack. */
" svc 0\n" /* System call to start first task. */
);
}

Everything works ok in demo project relying on old V0.2 lib.

RE: STM32 Primer HardFault (Help!)

Posted by Richard on March 28, 2010
I'll ask the obvious question first - do you have the correct SVC handler installed? vPortSVCHandler should be in the 9th position of the vector table.

The next less obvious one is, where is the stack? When the Cortex M3 boots it looks at the first interrupt vector to find where the stack is located. When FreeRTOS starts the kernel finds the vector table to in turn find the stack so the stack pointer can be set back to the beginning of the stack region (this is what the code in your post is doing). Some STM32 projects (not provided by me) have two stack regions, first one that is in internal RAM and located using the vector table, then another in external RAM (which I don't think the Primer has). If it switches to use the external RAM stack before FreeRTOS starts then the kernel will set the stack pointer back to the start of the wrong stack [I have no idea why you would want the stack in external RAM, but will ask ST next time I talk to them].

Regards.

RE: STM32 Primer HardFault (Help!)

Posted by https://www.google.com/accounts on March 29, 2010
Lol - handlers were missing - indeed!!! Thanks.

To All - who is facing new Std lib (3.0 and up) from STM:

You will need to add 3 handlers into stm32f10x_it.c:

void SysTick_Handler(void)
{
xPortSysTickHandler();
}
void PendSV_Handler( void ) __attribute__ (( naked ));
void PendSV_Handler(void)
{
//xPortPendSVHandler();

__asm volatile
(
"mrs r0, psp\n"
"\n"
"ldrr3, pxCurrentTCBConst\n" /* Get the location of the current TCB. */
"ldrr2, [r3]\n"
"\n"
"stmdb r0!, {r4-r11}\n" /* Save the remaining registers. */
"str r0, [r2]\n" /* Save the new top of stack into the first member of the TCB. */
"\n"
"stmdb sp!, {r3, r14}\n"
"mov r0, %0\n"
"msr basepri, r0\n"
"bl vTaskSwitchContext\n"
"mov r0, #0\n"
"msr basepri, r0\n"
"ldmia sp!, {r3, r14}\n"
"\n"/* Restore the context, including the critical nesting count. */
"ldr r1, [r3]\n"
"ldr r0, [r1]\n" /* The first item in pxCurrentTCB is the task top of stack. */
"ldmia r0!, {r4-r11}\n" /* Pop the registers. */
"msr psp, r0\n"
"bx r14\n"
"\n"
".align 2\n"
"pxCurrentTCBConst: .word pxCurrentTCB\n"
::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)
);

}
void SVC_Handler( void ) __attribute__ (( naked ));

void SVC_Handler(void)
{
//vPortSVCHandler();

__asm volatile (
"ldrr3, pxCurrentTCBConst2\n" /* Restore the context. */
"ldr r1, [r3]\n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
"ldr r0, [r1]\n" /* The first item in pxCurrentTCB is the task top of stack. */
"ldmia r0!, {r4-r11}\n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
"msr psp, r0\n" /* Restore the task stack pointer. */
"mov r0, #0 \n"
"msrbasepri, r0\n"
"orr r14, #0xd\n"
"bx r14\n"
"\n"
".align 2\n"
"pxCurrentTCBConst2: .word pxCurrentTCB\n"
);

}



P.S. richardbarry. I had to copy 'asm' context handlers from port.s since new LIB format initializes all interrupt handlers in the standard startup .s file to 0. Unless you declare handler with the same name. Not sure if that is the way to do this.


[ 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