2021-03-05 01:00 AM
Dear ST Community,
I am trying to use the FDCAN peripheral of the G431KB STMicroelectronics Microcontroller.
It is a project requirement that the FDCAN is used in CAN 2.0 mode (FDCAN_CLASSIC_CAN). FDCAN is backwards-compatible so thus far there's no issues.
I am having difficulties setting up the FDCAN in the required setting in the STM32CubeIDE program.
The `HAL_FDCAN_Start()` function returns `HAL_OK` .
The `HAL_FDCAN_AddMessageToTxFifoQ()` function, however, returns the `HAL_FDCAN_ERROR_FIFO_FULL` error code.
I initialize the FDCAN as usual:
can_filterConfig.IdType = FDCAN_STANDARD_ID;
can_filterConfig.FilterIndex = 0;
can_filterConfig.FilterType = FDCAN_FILTER_MASK;
can_filterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
can_filterConfig.FilterID1 = 0x000;
can_filterConfig.FilterID2 = 0x000;
if( HAL_OK != HAL_FDCAN_ConfigFilter(&hfdcan1, &can_filterConfig) )
{
/* Filter configuration Error */
Error_Handler();
}
/* Activate the usage of interrupts */
if( HAL_OK != HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_TX_FIFO_EMPTY, FDCAN_TX_BUFFER0 | FDCAN_TX_BUFFER1 | FDCAN_TX_BUFFER2) )
{
/* Filter configuration Error */
Error_Handler();
}
/* Start the peripheral */
if( HAL_OK != HAL_FDCAN_Start(&hfdcan1) )
{
/* Filter configuration Error */
Error_Handler();
}
In the interrupt service routine of the GPIOs (`HAL_GPIO_EXTI_Callback()`) I call a function that sends the CAN messages.
can_txHeader.Identifier = 0x007;
can_txHeader.IdType = FDCAN_STANDARD_ID; /* 11 bit */
can_txHeader.TxFrameType = FDCAN_DATA_FRAME;
can_txHeader.DataLength = FDCAN_DLC_BYTES_4;
can_txHeader.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
can_txHeader.BitRateSwitch = FDCAN_BRS_OFF;
can_txHeader.FDFormat = FDCAN_CLASSIC_CAN; /* Not CAN-FD */
can_txHeader.TxEventFifoControl = FDCAN_STORE_TX_EVENTS;
can_txHeader.MessageMarker = 0x00;
if(HAL_OK != HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &can_txHeader, txData))
{
i8_error = 1;
}
return i8_error;
Because of the above mentioned `HAL_FDCAN_ERROR_FIFO_FULL` error code, the variable `i8_error` returns `1`.
Am I doing something wrong during the CAN-setup?
What could be the cause of the `HAL_FDCAN_ERROR_FIFO_FULL` error?
I do understand what it means for the FIFO to be full.
So I suppose what I am asking is - how can I empty the FIFO? Doesn't the CAN peripheral take care of sending the messages on the FIFO in the background?
I have tried debugging with no avail thus far.
If you can provide me with some program examples or sources of information, I would be very grateful!
Any help is highly appreciated. Should more information be required, I am able to provide more.
Kind regards,
Mihail
2021-03-05 01:43 AM
Hi,
Please see this post: https://community.st.com/s/question/0D53W0000080SyvSAE/get-no-coomunication-via-fdcan1-on-stm32g431rb-nucleo-board
Best regards,
Slawek