Discussion Forum

HardFault_Hander before os_sys_init

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
M D
Posted
15-Mar-2010 09:36 GMT
Toolset
ARM
New! HardFault_Hander before os_sys_init

Hi all,

I'm using Keil RV4.10 on MCBSTM32 demo board (STM32F103RB) with STM32F10x_StdPeriph_Lib_V3.1.2 and Keil RTX kernel.

My application is relocated at 0x8002800 (bootloader and configuration data are placed before).

My main just setup the clock, peripherals, interrupts, etc ... and call

os_sys_init


All seems to be ok.

Recently I had to add in infinite cicle for debug/test purposes just after clocks and irq setup, like this:

int main(void)
{
    MicroController.Setup(); //setup clock, preiphs, irq,...

    while(1) {
        IWDG_ReloadCounter(); //DEBUG
    }

    os_sys_init(FirstTask);
}

then something strange happens... during the while(1) loop the application goes into HardFault_Handler, and the debugger shows me the following call stack:

HardFault_Handler()
rt_put_rdy_first()
rt_systick()
HAL_CM3()
rt_systick()

Could this be related to the RTX kernel ?

What's happening ? Am I not allowed to do whatever I want before calling

os_sys_init

??

Read-Only
Author
Jed C
Posted
15-Mar-2010 20:49 GMT
Toolset
ARM
New! RE: HardFault_Hander before os_sys_init

These links may provide you with the info you need to answer your question....

What happens within startup code:
http://www.embedded.com/design/200900043

RTX startup:
http://www.keil.com/support/man/docs/rlarm/rlarm_ar_hints_cortex.htm

-OR-

http://www.keil.com/support/man/docs/rlarm/rlarm_ar_hints_arm.htm

Read-Only
Author
M D
Posted
17-Mar-2010 14:23 GMT
Toolset
ARM
New! RE: HardFault_Hander before os_sys_init

Jed C,

thanks for the links, but they didn't help.
I do have a large-enough main stack, my code is all privileged, and all my setup activities uses global or setup-local variables, so the stack is clean after hw initialization.
Furthermore, there are no problems if I don't put an endless loop before the os_sys_init call, and the loop itself consumes very little stack...
So it seems a matter of ''how long'' I indulge in the main before calling os_sys_init...
From the call stack seems that the os is trying to schedule, but ther's nothing to schedule yet... hence the hardfault...

Any more specific hint ?

Read-Only
Author
Robert McNamara
Posted
17-Mar-2010 20:26 GMT
Toolset
ARM
New! RE: HardFault_Hander before os_sys_init

My guess is somehow the system_tick timer is getting initialized BEFORE the OS has been initialized. Try not initializing the system_tick timer (RTX does initialize this timer)

Read-Only
Author
M D
Posted
18-Mar-2010 09:33 GMT
Toolset
ARM
New! RE: HardFault_Hander before os_sys_init

Hi Robert,

you're right, that was my guess too.
I found that systick is configured and used by our bootloader.
There is no library function to turn it off, so I simply add

SysTick->CTRL &= ~1

as the first main instruction.
Problem solved, I'll put this instruction at the end of our bootloader process for next revision.
Thanks.

Next Thread | Thread List | Previous Thread Start a Thread | Settings