ChibiOS crashes when my firmware is not at beginning of flash memory

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby Laurent » Thu Mar 30, 2017 2:13 pm

Ok. Thanks a lot for your help Giovanni :)

mobyfab
Posts: 483
Joined: Sat Nov 19, 2011 6:47 pm
Location: Le Mans, France
Has thanked: 21 times
Been thanked: 30 times

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby mobyfab » Thu Mar 30, 2017 5:30 pm

Laurent wrote:So flash sector 0 can never contain pure data? That's annoying.

You need to have a vectors table at address zero containing at least the reset address and the MSP initial value.

Sorry but I know very little about vectors table, how would I do that?


It depends on the boot pins, but most of the times no, you need the vector table at adress 0. (address 0 is mapped to flash at 0x08000000 by default)
Just put your data at the end of flash.

It probably works with the debugger since it jumps to where you flash the code.

Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby Laurent » Mon Apr 03, 2017 10:00 am

As I said, I need the small sectors so I can't put the data at the end (16 KB sectors vs 128 KB sectors make a huge difference for me).

I added the MSP initial value and reset handler address -- the same values that ChibiOS uses -- at the beginning of sector 0 (at address 0x80000000), and everything worked as exptected. This is not a perfect solution since these values depend on the linker script of the firmware, and thus may break if I make modifications to it, but I guess this is the only way to make it work. The good news is that it only requires 8 bytes in sector 0, the 16376 remaining bytes can still be used for pure data.

Thanks everyone, and especially Giovanni :)

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby Giovanni » Mon Apr 03, 2017 12:29 pm

You are welcome, I just did what I usually do with my students :) (go read the documentation), ask RoccoMarco about this lol.

I can only recommend, before changing defaults of a complex systems, to ask beforehand about the possible consequences, just reporting a crash afterwards is not very helpful. I have to make assumptions/guesses, see bootloader etc.

Giovanni

mobyfab
Posts: 483
Joined: Sat Nov 19, 2011 6:47 pm
Location: Le Mans, France
Has thanked: 21 times
Been thanked: 30 times

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby mobyfab » Fri Apr 07, 2017 11:27 am

Just be careful to rewrite the vectors table after you erase the page, or use another one.

You can also change the linker script to handle updating it but you will loose the data you stored after each update.

There's no perfect solution here. ;)

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby rew » Sat Apr 08, 2017 6:01 pm

I think you'll crash if you get an interrupt while the page is blanked. You need to disable interrupt while erasing and refilling the page. (the interrupt will hang on the flash access, but resume before you're done writing all the vectors).

The problem that remains is that power might fail after (or even during) erasing and before reprogramming the vectors. Then your CPU might not boot at all anymore. IMHO, I think you should just use the first page for vectors/boot code only.

kalpesh
Posts: 19
Joined: Mon Dec 09, 2019 11:53 am

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby kalpesh » Tue Mar 03, 2020 6:09 am

Hi Sir,

Currently my chibios code is starting from sector 0(0x08000000). But I want my code to start from sector 5 (0x08020000).

I have changed the following info in my STM32f407xg.ld file

flash0 : org = 0x08020000, len = 512k /* flash0 : org = 0x08000000, len = 1M */

After compiling my code I flashed it in sector 5. But the code is not getting started.

I have my bootloader code at sector 0(0x08000000),which contains a vector offset that points to sector 5.

Do I need to make some other changes in chibios code. I am using STM32F407 controller.

Thanks
Kalpesh

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby Giovanni » Tue Mar 03, 2020 6:26 am

You need to jump at the address contained at offset +4 in the vectors table you placed at 0x08020000.

From what you wrote I understood you are jumping at the vectors table.

Giovanni

kalpesh
Posts: 19
Joined: Mon Dec 09, 2019 11:53 am

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby kalpesh » Tue Mar 03, 2020 7:12 am

Giovanni wrote:You need to jump at the address contained at offset +4 in the vectors table you placed at 0x08020000.

From what you wrote I understood you are jumping at the vectors table.

Giovanni
kalpesh wrote:
Hi ,

I am actually jumpimg to address contained at offset +4 only.
JumpAddress = (__IO uint32_t) (ApplicationAddress + 4);

My bootloader is able to read the data of sector 5 address. But the code present in sector 5 is not getting started.
My bootloader code contains read and Jump functions.

After compiling my chibios code my ch.map file flash0 points to sector 5 address with the required size.

ch.map file:

Name Origin Length Attributes
flash0 0x08020000 0x00080000



Thanks
Kalpesh

kalpesh
Posts: 19
Joined: Mon Dec 09, 2019 11:53 am

Re: ChibiOS crashes when my firmware is not at beginning of flash memory

Postby kalpesh » Tue Mar 03, 2020 8:29 am

Hi,

In chibios is it neessary to set the following macro.

#define CORTEX_VTOR_INIT 0x00020000 /* For Sector5 */

This macro is not present in my chibios code . Is there any alternate macro for this.

My bootloader code is able to start a sample Led application code(HAL) , but not he chibios code.

Thanks


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 13 guests