Hi all,
I have been testing to write a bootloader, and all seems fine.
ChibiOS starts up after the bootloader calls the binary, initialization works, HAL init goes fine and LEDs go on.
However, whenever I call a chThdSleep, I get an _unhandled_exception and it seems to happen on the return to _idle_thread.
Has anyone run into a similar issue before? The interesting part is that this only happens when going through the bootloader.
So my question is, is there something that ChibiOS does not reset at startup? Something in the NVIC perhaps?
_unhandled_exception when running a chThdSleep (running chibi from a bootloader)
- wurstnase
- Posts: 121
- Joined: Tue Oct 17, 2017 2:24 pm
- Has thanked: 43 times
- Been thanked: 30 times
- Contact:
Re: _unhandled_exception when running a chThdSleep (running chibi from a bootloader)
I had some issues when jumping from os-less chibi bootloader to a none chibios application.
Finally I reset also CONTROL and PRIMASK register and going an extra round with a NVIC_SystemReset().
I write a magic code into a backup register (e.g. BKP->DR42 = 0x4242). If this key exist after bootup, I don't start any xxxInit() and jump directly to my application.
In total something like:
Finally I reset also CONTROL and PRIMASK register and going an extra round with a NVIC_SystemReset().
I write a magic code into a backup register (e.g. BKP->DR42 = 0x4242). If this key exist after bootup, I don't start any xxxInit() and jump directly to my application.
In total something like:
Code: Select all
if (BKP->DR42 == 0x4242) {
BKP->DR42 = 0x0;
typedef void (*pFunction)(void);
pFunction Jump_To_Application; uint32_t JumpAddress;
JumpAddress = *(__IO uint32_t *)(APP_ADDRESS + 4);
Jump_To_Application = (pFunction)JumpAddress;
/* Clear pending interrupts just to be on the safe side */
SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk;
/* Disable the SysTick */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/* Disable all interrupts */
for(uint8_t i=0; i<8; i++)
NVIC->ICER[i] = NVIC->IABR[i];
SCB->VTOR = APP_ADDRESS;
__set_CONTROL(0);
__set_PRIMASK(0);
__DSB();
__set_MSP(*(__IO uint32_t *)APP_ADDRESS);
Jump_To_Application();
}
\o/ Nico
- Korken
- Posts: 270
- Joined: Wed Apr 02, 2014 4:09 pm
- Location: Luleå, Sweden
- Has thanked: 5 times
- Been thanked: 6 times
- Contact:
Re: _unhandled_exception when running a chThdSleep (running chibi from a bootloader)
Hi, thanks for the tips!
I'm doing exactly the same, inside the bootloader I am also using a "magic value" (in RAM though) to read after a soft reset, only to set addresses and VTOR and then jump to my ChibiOS code.
Just to be safe I checked with the debugger that all registers are correctly set and at their reset values.
It is very strange issue for me, especially that it only happens during chThdSleepXXX functions.
I'm doing exactly the same, inside the bootloader I am also using a "magic value" (in RAM though) to read after a soft reset, only to set addresses and VTOR and then jump to my ChibiOS code.
Just to be safe I checked with the debugger that all registers are correctly set and at their reset values.
It is very strange issue for me, especially that it only happens during chThdSleepXXX functions.
- Korken
- Posts: 270
- Joined: Wed Apr 02, 2014 4:09 pm
- Location: Luleå, Sweden
- Has thanked: 5 times
- Been thanked: 6 times
- Contact:
Re: _unhandled_exception when running a chThdSleep (running chibi from a bootloader)
Finally figured it out
I read the ARM docs wrong about the alignment of the vector table (round up to power of 2 of your table size).
I read it as it always need to be 64 words.
With the alignment fixed, everything is working, thanks for the tips!
I read the ARM docs wrong about the alignment of the vector table (round up to power of 2 of your table size).
I read it as it always need to be 64 words.
With the alignment fixed, everything is working, thanks for the tips!
- wurstnase
- Posts: 121
- Joined: Tue Oct 17, 2017 2:24 pm
- Has thanked: 43 times
- Been thanked: 30 times
- Contact:
Re: _unhandled_exception when running a chThdSleep (running chibi from a bootloader)
Can you please explain what you've done before and what you changed afterwards?
\o/ Nico
- Korken
- Posts: 270
- Joined: Wed Apr 02, 2014 4:09 pm
- Location: Luleå, Sweden
- Has thanked: 5 times
- Been thanked: 6 times
- Contact:
Re: _unhandled_exception when running a chThdSleep (running chibi from a bootloader)
Sure!
Before I had 128 byte alignment of the vector table, after I have 1024 byte alignment.
Nothing more was needed
Before I had 128 byte alignment of the vector table, after I have 1024 byte alignment.
Nothing more was needed
Who is online
Users browsing this forum: No registered users and 13 guests