cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7A3 - FDCAN Callback not called after reconfiguration of CAN-Bus

GS1
Senior III

In my project I use FDCAN1 and FDCAN2 for communication.

At startup of the system CAN1 ist used to send out messages with 500 kBit - CAN2 is used to receive data at 1 MBit and this works.

Now the user can reconfigure the CAN busses e.g. as follows:

Receive data on both CANs at 500 kBit.

After the FDCAN Busses are reconfigured to match this option, messages are only received for FDCAN2 in the callback routine.

(Of course Interrupt is enabled for FDCAN1_IT0)

I then activate FIFO0 Callbacks for all Standard IDs as follows (without filterering):

HAL_FDCAN_ConfigGlobalFilter(phCan, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_ACCEPT_IN_RX_FIFO1, FDCAN_REJECT, FDCAN_REJECT);

HAL_FDCAN_ActivateNotification(phCan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0);

-> HAL_FDCAN_RxFifo0Callback then will be called only for CAN2.

Using the debugger I saw in the FDCAN1 registers that messages are received, Fifo0 is full and messages are lost.

I added a read funtion so that also CAN1 messages are read in the callback routine (using HAL_FDCAN_GetRxMessage) and then data messages are actually available and can be read!

What might be the reason, that the callback doesn't work for CAN1 ? Any Idea?  

Any help is very much appreciated!

BR GS

1 REPLY 1
sqwerize
Associate II

Hi, did u fix it? I have STM32H750XBHX with same problem... 
I also have a callback for CAN1 but it is not called at all. I have an interrupt set up in NVIC....
I checked via FreeRTOS if receiving works and here surprise, receiving and sending frames from task level works very well....

 

 

sqwerize_0-1713395262036.pngsqwerize_1-1713395281643.pngsqwerize_2-1713395310474.png

 

static void MX_FDCAN1_Init(void)

{

 

/* USER CODE BEGIN FDCAN1_Init 0 */

 

/* USER CODE END FDCAN1_Init 0 */

 

/* USER CODE BEGIN FDCAN1_Init 1 */

 

/* USER CODE END FDCAN1_Init 1 */

hfdcan1.Instance = FDCAN1;

hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

hfdcan1.Init.AutoRetransmission = ENABLE;

hfdcan1.Init.TransmitPause = DISABLE;

hfdcan1.Init.ProtocolException = DISABLE;

hfdcan1.Init.NominalPrescaler = 15;

hfdcan1.Init.NominalSyncJumpWidth = 3;

hfdcan1.Init.NominalTimeSeg1 = 13;

hfdcan1.Init.NominalTimeSeg2 = 2;

hfdcan1.Init.DataPrescaler = 25;

hfdcan1.Init.DataSyncJumpWidth = 1;

hfdcan1.Init.DataTimeSeg1 = 2;

hfdcan1.Init.DataTimeSeg2 = 1;

hfdcan1.Init.MessageRAMOffset = 0;

hfdcan1.Init.StdFiltersNbr = 1;

hfdcan1.Init.ExtFiltersNbr = 0;

hfdcan1.Init.RxFifo0ElmtsNbr = 0;

hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;

hfdcan1.Init.RxFifo1ElmtsNbr = 0;

hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

hfdcan1.Init.RxBuffersNbr = 0;

hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;

hfdcan1.Init.TxEventsNbr = 0;

hfdcan1.Init.TxBuffersNbr = 0;

hfdcan1.Init.TxFifoQueueElmtsNbr = 1;

hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN FDCAN1_Init 2 */

 

FDCAN_FilterTypeDef sFilterConfig;

 

/* Konfiguracja filtru do akceptowania wszystkich ramek ze standardowymi ID */

sFilterConfig.IdType = FDCAN_STANDARD_ID; // Lub FDCAN_EXTENDED_ID dla długich identyfikatorów

sFilterConfig.FilterIndex = 0; // Pierwszy filtr

sFilterConfig.FilterType = FDCAN_FILTER_MASK; // Filtr maskowy

sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; // Przekierowanie akceptowanych ramek do FIFO 0

sFilterConfig.FilterID1 = 0x000; // ID do akceptacji

sFilterConfig.FilterID2 = 0x000; // Maska filtru: 0x000 oznacza akceptowanie wszystkich ID

sFilterConfig.RxBufferIndex = 0;

 

 

if(HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)

{

Error_Handler();

}

 

if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)

{

Error_Handler();

}

 

if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)

{

Error_Handler();

}

 

if(HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)

{

Error_Handler();

}

 

TxHeader.Identifier = 0x123;

TxHeader.IdType = FDCAN_STANDARD_ID;

TxHeader.TxFrameType = FDCAN_DATA_FRAME;

TxHeader.DataLength = FDCAN_DLC_BYTES_8;

TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;

TxHeader.BitRateSwitch = FDCAN_BRS_OFF;

TxHeader.FDFormat = FDCAN_CLASSIC_CAN;

TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

TxHeader.MessageMarker = 0;

 

/* USER CODE END FDCAN1_Init 2 */

 

}

void HAL_FDCAN_RxFifo0MsgPendingCallback(FDCAN_HandleTypeDef *hfdcan)

{

LED1_ON();

if(hfdcan->Instance == FDCAN1)

{

FDCAN_RxHeaderTypeDef RxHeader;

uint8_t RxData[8];

 

// Pobierz ramkę

if(HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData) == HAL_OK)

{

 

}

}

}