FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [October 2010 Threads] STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 Hello everyone. I am using STM32F103VB uP with CodeSourcery GCC compiler. I have following problem. I've developed bootloader, which is loaded at the beginning of flash (0x08000000) . This bootloader uses a SD card with FAT file system, and check if some file with new firmware exists on SD card, and then loads it to flash at address 0x08008000 and call new application using such asm code:
.thumb_func CallApplication: // Set the vector table address to the beginning of the application. ldr r0, =APP_VEC_TAB_OFFSET ldr r1, =(SCB_BASE + 8) str r0, [r1]
// Load the initial LR as it should be after the reset. movs lr, #0xffffffff
// Load the stack pointer from the application's vector table. ldr r0, =DEF_APP_ADDRESS ldr r1, [r0] msr msp, r1
// Load the initial PC from the application's vector table and branch to // the application's entry point. ldr r0, [r0, #4] bx r0
Where DEF_APP_ADDRESS is 0x08000000. When I load in such way application that is not using FreeRTOSeverything is fine. Application is loading and than running correctly, but doing the same with application based on FreeRTOS i get the HardFault Exception before calling the main in section LoopFillZerobss of startup file: Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */ movsr1, #0 bLoopCopyDataInit
CopyDataInit: ldrr3, =_sidata ldrr3, [r3, r1] strr3, [r0, r1] addsr1, r1, #4 LoopCopyDataInit: ldrr0, =_sdata ldrr3, =_edata addsr2, r0, r1 cmpr2, r3 bccCopyDataInit ldrr2, =_sbss bLoopFillZerobss /* Zero fill the bss segment. */ FillZerobss: movsr3, #0 strr3, [r2], #4 LoopFillZerobss: ldrr3, = _ebss cmpr2, r3 bccFillZerobss /* Call the clock system intitialization function.*/ bl SystemInit /* Call the application's entry point.*/ blmain bxlr .sizeReset_Handler, .-Reset_Handler
Of course i change in the linker script line: FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K to: FLASH (rx) : ORIGIN = 0x08008000, LENGTH = (128K - 0x8000) and in function void vSetupHardware(void) I changed line: NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 ); to: NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x8000 ); I don't know where to find problem.
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 I forgot to add that application, which i tried to load an then execute using bootloader works perfectly in normal situation: - in linker script is FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K - in function vSetupHardware: NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 );
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Dave on October 28, 2010 Without having fully inspected your code, is it possible that your problem is something to do with the code that starts the scheduler loading the stack location from the interrupt table (in port.c) 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. */ ); }
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 I checked this, but this function is called in vTaskStartScheduler(), but I dont even reach the main() function. Application with FreeRTOS crash with HardFault exception in startup file in this section: /* Zero fill the bss segment. */ FillZerobss: movs r3, #0 str r3, [r2], #4 LoopFillZerobss: ldr r3, = _ebss cmp r2, r3 bcc FillZerobss This section is also present in application without FreeRTOS (what is obvious), but in application without FreeRTOS everything works fine.
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 I was wrong and you were like always. The problem is in vPortStartFirstTask function. So i have to change something in this function. I will try and let you know when i solved the problem.
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 So the problem is with line: " msr msp, r0 \n" When i debug code and put breakpoint on line: " ldr r0, [r0] \n" The value of R0 register is 0x20005000 so its correct for my processor. Maybe the the core of stm32 processor is in wrong state and cannot execute msr command. How can I check current state and how can I change it? To execute command MSR i have to be in Thread mode with privileged state?
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Dave on October 28, 2010 Can you just inspect the status register to see which mode you are in?
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 The CPSR register is uequal to 0x61000020
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Dave on October 28, 2010 ...have you interpreted what that means with respect to modes and stacks. You are going to have to look it up in the manual if your debugger is not giving you the information.
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 I discover that in function vPortStartFirstTask processor is in Thread Priviliged mode and I dont know what is causing HardFault on " msr msp, r0 \n" Its unbelieveable.
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 28, 2010 Ok, again my fault. Initialization of MSP is done correctly. Problem is with line "svc 0 \n" . Its quite strange because this code works properlyy when program starts from 0x08000000. In startup file i have something like this: .extern xPortPendSVHandler .extern xPortSysTickHandler .extern vPortSVCHandler . . . . . . g_pfnVectors: .word_estack .wordReset_Handler .wordNMI_Handler .wordHardFault_Handler .wordMemManage_Handler .wordBusFault_Handler .wordUsageFault_Handler .word0 .word0 .word0 .word0 /*.wordSVC_Handler */ .word vPortSVCHandler .wordDebugMon_Handler .word0 /*.wordPendSV_Handler */ .word xPortPendSVHandler /*.wordSysTick_Handler */ ... rest of handlers ...
where
RE: STM32 + GCC + Bootloader + FreeRTOSPosted by Sebastian K on October 29, 2010 Ok i solved problem. The problem was, that in bootloader i used Systick Timer and before calling application i didnt disable this timer. Now I disable SysTick timer in bootloader, and loaded and calles FreeRTOS application runs properly.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|