Here is my main function in application:
Code: Select all
int main() {
halInit();
chSysInit();
while (true) {
chThdSleepMilliseconds(500);
//for (volatile size_t i=0; i<5000000; ++i) {} // Uncomment this and comment previous line and everything works
palTogglePad(GPIOC, GPIOC_LED1);
}
return 0;
}
What happens is that I got unhandled exception when calling chThdSleepMilliseconds. BTW there is hardfault handler defined and I am sure that it works.
Firmware update is performed over CAN bus. This is how I exit the bootloader:
Code: Select all
canStop(&CAND1);
chSysDisable();
stStopAlarm();
// Disable all NVIC interrupts
for (size_t i=0; i<sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); ++i) {
NVIC->ICER[i] = 0xFFFFFFFF;
}
SCB->ICSR |= SCB_ICSR_PENDSVCLR_Msk;
SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;
// Clear all NVIC pending interrupts
for (size_t i=0; i< sizeof(NVIC->ICPR) / sizeof(NVIC->ICPR[0]); ++i) {
NVIC->ICPR[i] = 0xFFFFFFFF;
}
// Clear all interrupt priorities
for (size_t i=0; i<sizeof(NVIC->IP) / sizeof(NVIC->IP[0]); ++i) {
NVIC->IP[i] = 0;
}
jump_to_firmware(APP_START_ADDRESS);
Jump to firmware method:
Code: Select all
inline
void __attribute__((noreturn)) jump_to_firmware(uint32_t address) {
// Set new vector table
SCB->VTOR = address;
uint32_t *addr_ptr = (uint32_t *) address;
// Set main stack pointer
__set_MSP((uint32_t) addr_ptr[0]);
// Jump to application
typedef void (*func_ptr)(void);
((func_ptr) addr_ptr[1])();
for(;;) {}
}
Linker script is defined as follows. One script which defines regions:
Code: Select all
MEMORY
{
bootloader : org = 0x08000000, len = 48K
app : org = 0x0800C000, len = 976K
flash2 : org = 0x00000000, len = 0
flash3 : org = 0x00000000, len = 0
flash4 : org = 0x00000000, len = 0
flash5 : org = 0x00000000, len = 0
flash6 : org = 0x00000000, len = 0
flash7 : org = 0x00000000, len = 0
ram0 : org = 0x20000000, len = 128k /* SRAM1 + SRAM2 */
ram1 : org = 0x20000000, len = 112k /* SRAM1 */
ram2 : org = 0x2001C000, len = 16k /* SRAM2 */
ram3 : org = 0x00000000, len = 0
ram4 : org = 0x10000000, len = 64k /* CCM SRAM */
ram5 : org = 0x40024000, len = 4k /* BCKP SRAM */
ram6 : org = 0x00000000, len = 0
ram7 : org = 0x00000000, len = 0
}
And it is included by 2 other scripts which just define aliases required for ChibiOS linker to work.
Main and process stack sizes are both set to 2KB. Stack pointers are initialized correctly. Application has STM32_NO_INIT defined, since both targets shares same initialization code. All debugging checks are enabled.
Looking over registers values in debugger I could not find anything useful. Any thought?
Thanks!