cancel
Showing results for 
Search instead for 
Did you mean: 

stm32u5 HAL_FDCAN_AddMessageToTxFifoQ is always full after error

lll
Associate II

Hello

I have a code use CAN on a stm32U585 he work fine if the CAN bus have not disturbance

But if i have to many disturbance for exemple if i make a short circuit bethen CANH and CANL when i remove the short circuit the CAN no restart to send data. I need stop and restart CAN  

HAL_FDCAN_Stop(&hfdcan1);
HAL_FDCAN_Start(&hfdcan1);

After the disturbance, the return value of HAL_FDCAN_GetState() and HAL_FDCAN_GetError() remains unchanged.

 

How can I immediately know when there is a problem with CAN

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

Hello,


@lll wrote:

if i make a short circuit bethen CANH and CANL when i remove the short circuit the CAN no restart to send data.


That's normal. The node is in Bus-off state and there is no automatic Bus-off recovery by hardware with FDCAN. You need to do it by software.

To implement the Bus-Off recovery by software you need to:

  1. Enable the FDCAN NVIC interrupt line, either manually or using the STM32CubeMX interface.
  2. Activate the Bus-Off notification interrupt with the following code: 
    HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_BUS_OFF, 0);​
  3. implement the error status callback to handle the Bus-Off event:
    void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
    {
        FDCAN_ProtocolStatusTypeDef protocol_status;
        HAL_FDCAN_GetProtocolStatus(hfdcan, &protocol_status);
    
        if (protocol_status.BusOff != 0)  // If Bus-Off error occurred
        {
            CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);  // Clear INIT bit to recover from Bus-Off
        }
    }
    ​

Hope that answers your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
lll
Associate II

correction: HAL_FDCAN_GetTxFifoFreeLevel is always full after error 

mƎALLEm
ST Employee

Hello,


@lll wrote:

if i make a short circuit bethen CANH and CANL when i remove the short circuit the CAN no restart to send data.


That's normal. The node is in Bus-off state and there is no automatic Bus-off recovery by hardware with FDCAN. You need to do it by software.

To implement the Bus-Off recovery by software you need to:

  1. Enable the FDCAN NVIC interrupt line, either manually or using the STM32CubeMX interface.
  2. Activate the Bus-Off notification interrupt with the following code: 
    HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_BUS_OFF, 0);​
  3. implement the error status callback to handle the Bus-Off event:
    void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
    {
        FDCAN_ProtocolStatusTypeDef protocol_status;
        HAL_FDCAN_GetProtocolStatus(hfdcan, &protocol_status);
    
        if (protocol_status.BusOff != 0)  // If Bus-Off error occurred
        {
            CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);  // Clear INIT bit to recover from Bus-Off
        }
    }
    ​

Hope that answers your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.