Implement manual bus off recovery - #129
Conversation
|
For me it looks ok. |
There was a problem hiding this comment.
🟡 Changes recommended
The new callback should ensure Bus-Off is currently asserted (not just “status changed”) before clearing CCCR.INIT, to avoid unintended behavior and improve robustness.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an FDCAN HAL error-status callback to perform manual Bus-Off recovery on STM32 targets, addressing the inability to recover from Bus-Off automatically as discussed in issue #128.
Changes:
- Implement
HAL_FDCAN_ErrorStatusCallbackto clearFDCAN_CCCR_INITwhen Bus-Off is signaled. - Add brief inline documentation pointing to ST’s recommended recovery approach.
File summaries
| File | Description |
|---|---|
| CANopenNode_STM32/CO_driver_STM32.c | Adds an FDCAN error-status callback intended to manually recover from Bus-Off. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
Does this suggestion make sense @MaJerle ? This is not what STM32 article recommends
There was a problem hiding this comment.
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.
Fix for issue 128 #128 (comment)
Implement manual bus off recovery according to https://community.st.com/stm32-mcus-60/how-to-recover-from-bus-off-state-with-fdcan-on-stm32-mcus-158678