cancel
Showing results for 
Search instead for 
Did you mean: 

FDCAN problems on STM32G4

RickN
Associate

 

I am developing a new project for the STM32G474 processor using the STM32G474E-EVAL1 board but am having a problem with FDCAN. I have two issues:

1. I configure FDCAN and use the function HAL_FDCAN_AddMessageToTxFifoQ but the queue quickly fills up and no CAN transmission takes place. I have verified the physical connection and cable termination.

2. I set up a receive filter to accept all incoming messages and send them to RX FIFO 0, and I activate notifications with HAL_FDCAN_ActivateNotification using the argument FDCAN_IT_RX_FIFO0_NEW_MESSAGE, but I never get a CAN interrupt when messages are sent from the host. I am using a CAN analyzer to verify that the messages are sent.

I am using Normal mode CAN at 125Kbps.

Here is the STM32CubeMX generated code and the filter I set up:

/**
* @brief FDCAN1 Initialization Function
* @PAram None
* @retval None
*/
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.ClockDivider = FDCAN_CLOCK_DIV20;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = DISABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 160;
hfdcan1.Init.NominalSyncJumpWidth = 10;
hfdcan1.Init.NominalTimeSeg1 = 2;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 16;
hfdcan1.Init.DataTimeSeg1 = 23;
hfdcan1.Init.DataTimeSeg2 = 16;
hfdcan1.Init.StdFiltersNbr = 1;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FDCAN1_Init 2 */

// Set up filters
FDCAN_FilterTypeDef sFilterConfig;
sFilterConfig.IdType = FDCAN_STANDARD_ID; // vs. Extended ID
sFilterConfig.FilterIndex = 0; // the number of the filter we are using
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; // what should be done for a match with the filter
sFilterConfig.FilterID1 = 0; // filter
sFilterConfig.FilterID2 = 0; // mask: 0=>accept all messages
if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
{
// Filter configuration error
Error_Handler();
}
/* Configure global filter (what to do with messages not matching above filter - is this nec?) */
if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT,
FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
{
Error_Handler();
}

/* USER CODE END FDCAN1_Init 2 */

}

subsequently call the following functions:

void canfestival_CAN_Initialize(CO_Data* can_handle)
{
// Set up the transmit header
TxHeader.IdType = FDCAN_STANDARD_ID;
TxHeader.TxFrameType = FDCAN_DATA_FRAME;
TxHeader.DataLength = FDCAN_DLC_BYTES_8;
TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE; // Error State Indicator for Tx errors
TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
TxHeader.MessageMarker = 0;

// Start CAN timer for use by CANfestival
if (HAL_TIM_Base_Start_IT(&hCAN_FESTIVAL_TIMER) != HAL_OK)
{
Error_Handler();
}

// Start FDCAN module
if (HAL_FDCAN_Start(&hFDCAN_MODULE) != HAL_OK)
{
Error_Handler();
}

// Set up to interrupt when a new message arrives in the RX Fifo 0
if (HAL_FDCAN_ActivateNotification(&hFDCAN_MODULE, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
{
Error_Handler();
}
}

Issue 1: I use the function HAL_FDCAN_AddMessageToTxFifoQ but the queue quickly fills up and no CAN transmission takes place.

void canxmit_Task(void)
{
Message message;
osStatus_t status;

while(true)
{
// Check to see if the Tx FIFO is full.
if ((hFDCAN_MODULE.Instance->TXFQS & FDCAN_TXFQS_TFQF) != 0)
{
break; // Tx FIFO is full.
}

// Check for any messages in the RTOS queue.
status = osMessageQueueGet(CanXmitQueueHandle, &message, NULL, 0);
if (status == osErrorTimeout)
{
break; // No new messages to send.
}
if (status != osOK)
{
Error_Handler();
}

// Copy message from data structure used by CANfestival into that required for HAL.
TxHeader.Identifier = message.cob_id;
TxHeader.TxFrameType = (message.rtr != 0) ? FDCAN_REMOTE_FRAME : FDCAN_DATA_FRAME;
TxHeader.DataLength = message.len;
for (uint32_t i = 0; i < message.len; i++)
{
TxData[i] = message.data[i];
}

// Add message to CAN Fifo queue for transmission.
if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData) != HAL_OK)
{
Error_Handler();
}
}
}

From debug, I see that HAL_FDCAN_AddMessageTxFifoQ is called 3 times and after this the FDCAN_TXFQS_TFQF bit is permanently set. I don’t see any output on the CAN bus.

Issue 2: I never get a CAN interrupt when messages are sent from the host

Even with host transmitting CAN data, the function: void FDCAN1_IT0_IRQHandler(void) is never called.

 

1 ACCEPTED SOLUTION

Accepted Solutions
KDJEM.1
ST Employee

Hello @RickN ,

The FDCAN2 TX is initially disconnected in MB1397-G474EMC-B04 Board revision, SB5 is open by default,

Could you please solder the SB5 location on the board.

Please tell me know if the problem is solved.

When your question is answered, please close this topic by choosing "Accept as Solution". This will help other users find that answer faster.

Kaouthar

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

3 REPLIES 3
KDJEM.1
ST Employee

Hello @RickN and welcome to the community 🙂,

Which revision STM32G474E-EVAL1 are you using? MB1397-G474EMC-B04 or MB1397-G474E-B04?

Did you already test the FDCAN_Com_IT example provided in STM32CubeG4 firmware?

Thanks and best regards,

Kaouthar

 

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.

RickN
Associate

I accidentally marked this as a solution but I am still having problems. I have two STM32G474E-EVAL1 boards which are the MB1397-G474EMC-B04 revision of the boards. I tried running the FDCAN_Com_IT example on both boards but none of the LEDs lit on either board when I pressed the user buttons, and the program eventually got an error on the call to HAL_FDCAN_AddMessageToTxFifoQ. I also tried running the FDCAN_Classic_Frame_Networking example with the CAN bus connecting the boards together and got similar results.

KDJEM.1
ST Employee

Hello @RickN ,

The FDCAN2 TX is initially disconnected in MB1397-G474EMC-B04 Board revision, SB5 is open by default,

Could you please solder the SB5 location on the board.

Please tell me know if the problem is solved.

When your question is answered, please close this topic by choosing "Accept as Solution". This will help other users find that answer faster.

Kaouthar

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.