FDCAN with custom bootloader
Hello everyone!
Background
We are working on STM32G474VET6 based custom board for some specific motor control application. Project demands to have a custom bootloader on FD-CAN with 500kbit/s arbitration baudrate and data rate with 2Mbit/s with BRS option turned ON. Bootloader is done and working fine.
Board has a support for three CAN buses, therefore using FDCAN1, FDCAN2 and FDCAN3 periphery. All CAN buses has the same bus configuration and are not inter-connected.
Everything works perfectly with running only application on uC. As soon as we add bootloader that runs on FDCAN1, that same application (adjusted to be bootloadable ofcourse - offseted in flash, vector table adjusted) that was running all three CANs, now hangs if any message is received/transmitted on eihter FDCAN2 or FDCAN3. If there is no traffic on FDCAN2 or FDCAN3 everything is working as expected. Beside CAN periphery we're running also ADC1&2 with injected and regular channels, triggered by center aligned PWM timers, UART for debug purposes,...
Anyway application boots completely normal and works OK until we receive something on FDCAN2 or 3, then things fall apart. Mind that FDCAN2&3 works perfecly without bootloader. So I'm susspecting something around that transition from bootloader to application.
FDCAN Driver
FDCAN drivers source file are append to post. There it is visible how they are configured and used.
Transition from bootloader to application
Before entering application, bootloader de-init and resets all periphery that is using. FDCAN periphery is de-initialized, therefore when application boots it should find FDCAN clean as in standalone application.
De-init routine before entering application:
// De-Initialize cryptographic library
if ( CMOX_INIT_SUCCESS != cmox_finalize( NULL ))
{
status = eBOOT_ERROR;
}
// De-init gpio
gpio_deinit();
// De-init CAN
can_deinit( eCAN_MASTER );
// De-init clocks
HAL_RCC_DeInit();
// De-init HAL
HAL_DeInit();
// Disable systick
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
Problem with FDCAN on application with bootloader support
- Receiving/Transmitting something on FDCAN2 triggers FDCAN1_IT1_IRQHandler
- Receiving/Transmitting something on FDCAN3 end-up in Default Handler
Questions
- Why do we end up in FDCAN1_IT1_IRQHandler, when EINT1 bit inside FDCAN1 ILE register is cleared?
- Why does traffic on FDCAN2 triggers FDCAN1 interrupt in the first place?
- Ending in Default Handler probably means that some interrupts are not handled. Can you recommend me how to figure up which interrupt is not being handled? Again standalone application works perfectly!
- Can there be something that bootloader should do before entering application, regarding FDCAN periphery?
- Is there any officail ST recommendation how to de-init FDCAN, before entering application?
Any recomendations are highly welcome. We're eager to hear your suggestions/answers!
BR, Žiga
