FreeRTOS and Bootloader

Started by "Alvarez, Daniel" September 21, 2009
Hello:

I'm using an USB Bootloader and want to run a FreeRTOS application which
works standalone (with no bootloader in flash).
However, if I burn the bootloader onto my LPC2148 and then load the FreeRTOS
app (linked in the starting address 0x2000) it will eventually provoke a
Data Abort exception.

I tried to trace it with the JTAG but I think that I might be breaking the
normal behaviour because of the manual step by step debugging. Sometimes my
first FreeRTOS task starts running and sometimes it doesn't.

The Data Abort exception is usually raised when stepping into
vPortStartFirstTask. And in this code to be more precise:

LDR R0,[PC,#0x0168]
LDR R0,[R0]
LDR R14,[R0]
LDR R0,[PC,#0x0158]
LDMIA R14!,{R1}
STR R1,[R0]
LDMIA R14!,{R0}
MSR SPSR_cxsf,R0
LDMIA R14,{R0-R14}^
NOP
LDR R14,[R14,#0x003C] <--------- Here R14 equals
0xaaaaaaaa AND raises a Data Abort
SUBS PC,R14,#0x00000004

When this same application is run without a bootloader, it works perfectly.
Thank you so much in advance,

Daniel


An Engineer's Guide to the LPC2100 Series




> The Data Abort exception is usually raised when stepping into
> vPortStartFirstTask. And in this code to be more precise:
>
> LDR R0,[PC,#0x0168]
> LDR R0,[R0]
> LDR R14,[R0]
> LDR R0,[PC,#0x0158]
> LDMIA R14!,{R1}
> STR R1,[R0]
> LDMIA R14!,{R0}
> MSR SPSR_cxsf,R0
> LDMIA R14,{R0-R14}^
> NOP
> LDR R14,[R14,#0x003C] <--------- Here R14 equals
> 0xaaaaaaaa AND raises a Data Abort

This is nearly always a symptom of the CPU being in the wrong mode. The CPU
must be in Supervisor mode when vPortStartScheduler() is called, check
whether this is the case when loading through the bootloader.

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T as meeting the requirements for safety related systems.

Hello,

Thank you much for your quick response Richard.
You are right, my processor is in User mode ... the bootloader switches into
User mode before jumping to the FreeRTOS app and when the initialization
code of this app tries to switch and setup stacks for all the modes, it has
no effect and remains in User mode all the time causing this abort.

I can't see why the initialization code is not working. Do I have to avoid
the bootloader code from exiting SVC mode?

Regards,
Daniel


I just found out something else.

Sometimes my first FreeRTOS task starts running and sometimes it doesn't.
>

When the processor is in SVC mode, my task starts running - but just for a
little while - and then it doesn't raise a Dabt exception but if I stop the
program with the debugger I'll find it stuck at:

0x00000044 EAFFFFFE B 0x00000044

Regards,
Daniel


Sorry for posting 3 times in a row ...

0x00000044 EAFFFFFE B 0x00000044
>

This is the SWI_Handler installed by my bootloader and when the processor is
in Supervisor mode before starting the FreeRTOS scheduler and everything
appears to be ready for working, the yield function is not hitting the SWI
handler installed by my own startup code but the one installed by the
bootloader. Should I remap these vectors? Anyways the problem of not
switching properly from the app startup code is not solved yet.

Thank you so much and sorry again for this sort of spam.
Kind regards,
Daniel


Hi Daniel,
It seems that the bootloader you're using doesn't have a propper
redirection
for the SWI handler (0x44 it's an usual address for the loop: B loop at
a fake swi handler),
the one we use at Espardino (I know you were playing with the board) has a
redirection
fro 0x00002008 to 0x00000008 address, that's the reason it works on
Espardino boards.

You have 2 solutions:

1) Fix handlers on your bootloader to redirect (instruction penalty
for added jump).

2) Remap your interrupt vectors to RAM (use the MEMMAP register) ->
you will have
to fix some space in your linkerscript for your vectors.

2009/9/21 Alvarez, Daniel

> Sorry for posting 3 times in a row ...
>
> 0x00000044 EAFFFFFE B 0x00000044
> > This is the SWI_Handler installed by my bootloader and when the processor
> is
> in Supervisor mode before starting the FreeRTOS scheduler and everything
> appears to be ready for working, the yield function is not hitting the SWI
> handler installed by my own startup code but the one installed by the
> bootloader. Should I remap these vectors? Anyways the problem of not
> switching properly from the app startup code is not solved yet.
>
> Thank you so much and sorry again for this sort of spam.
> Kind regards,
>
> Daniel
>
>
>
>
>

--
Miguel Angel Ajo Pelayo
http://www.nbee.es
+34 91 120 1798
+34 636 52 25 69
skype: ajoajoajo


2009/9/22 Miguel Angel

>
> fro 0x00002008 to 0x00000008 address, that's the reason it works on
> Espardino boards.
I meant from 0x00000008 to 0x00002008 :-)
--
Miguel Angel Ajo Pelayo
http://www.nbee.es
+34 91 120 1798
+34 636 52 25 69
skype: ajoajoajo


Great :)

Thank you so much for the answers. I will go on playing around with
Espardino, Miguel, it's got a useful amount of source code available.

Cheers,
Daniel


And fix the NXP's bootloader for your designs :)

2009/9/22 Alvarez, Daniel

> Great :)
>
> Thank you so much for the answers. I will go on playing around with
> Espardino, Miguel, it's got a useful amount of source code available.
>
> Cheers,
>
> Daniel
>
>
>
>
>

--
Miguel Angel Ajo Pelayo
http://www.nbee.es
+34 91 120 1798
+34 636 52 25 69
skype: ajoajoajo