Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CANopenNode_STM32/CO_driver_STM32.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,24 @@ HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef* hfdcan, uint32_t RxFifo1ITs) {
}
}

/**
* \brief Error status callback
* \param[in] hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
* the configuration information for the specified FDCAN.
* \param[in] ErrorStatusITs indicates which Error Status interrupts are signaled.
* This parameter can be any combination of @arg FDCAN_Error_Status_Interrupts.
*
* Implements manual FDCAN Bus-Off recovery as described in
* https://community.st.com/stm32-mcus-60/how-to-recover-from-bus-off-state-with-fdcan-on-stm32-mcus-158678.
*/
void
HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef* hfdcan, uint32_t ErrorStatusITs) {
if ((ErrorStatusITs & FDCAN_IT_BUS_OFF) != 0) // If Bus-Off error occurred
{
CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT); // Clear INIT bit to recover from Bus-Off
}
}
Comment on lines +636 to +641

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this suggestion make sense @MaJerle ? This is not what STM32 article recommends

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, I'd rather use that we use the HAL_FDCAN_procotolStatus (or something like that) function to read all the statuses and if we have busoff, we start init.

I use a function like this:

/**
 * \brief           Check for BUS-OFF and reinitialize the init
 * 
 *                  IP will then wait for recessive bits before resuming the operation
 * 
 * \param           hfdcan 
 */
static void
prv_fdcan_bus_off_check_reset(FDCAN_HandleTypeDef* hfdcan) {
    FDCAN_ProtocolStatusTypeDef protocolStatus = {0};

    HAL_FDCAN_GetProtocolStatus(hfdcan, &protocolStatus);
    if (protocolStatus.BusOff) {
        CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
    }
}

And I call it on:

  • HAL_FDCAN_ErrorCallback()
  • HAL_FDCAN_ErrorStatusCallback()
  • Each time I try to send the packet

In practice, I'll do some reworking today of the drivers, so if @HamedJafarzadeh can agree to merge this today, it will be good.


/**
* \brief TX buffer has been well transmitted callback
* \param[in] hfdcan: pointer to an FDCAN_HandleTypeDef structure that contains
Expand Down