2024-07-22 01:12 AM - last edited on 2024-07-22 01:49 AM by SofLit
Hello,
I am trying to use FDCAN but for some reason interrupt is not triggering. Im using PEAK CAN to send and recieve messages. With osciloscope I can see the data being transfared to the STM board but the interrupt doesn't trigger. The speed I want is 125 kbit/s . I've done this with the CAN before but with FDCAN just cant seem to figure it out.
I have enabled FDCAN1 interupt 0 in the NVIC with priority 5.
Any idea what should I check? I have a feeling that it might be the filter settings that are wrong but Im just not sure.
I've tried sending data to 0x11 and 0x22 but nothing happens.
Filter and fdcan setup:
/* USER CODE END FDCAN1_Init 1 */
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
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 = 12;
hfdcan1.Init.NominalSyncJumpWidth = 1;
hfdcan1.Init.NominalTimeSeg1 = 13;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataPrescaler = 24;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 13;
hfdcan1.Init.DataTimeSeg2 = 2;
hfdcan1.Init.StdFiltersNbr = 1;
hfdcan1.Init.ExtFiltersNbr = 1;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FDCAN1_Init 2 */
//FDCAN1 FILTER
FDCAN_FilterTypeDef sFilterConfig;
sFilterConfig.IdType = FDCAN_STANDARD_ID; // Use standard IDs
sFilterConfig.FilterIndex = 0; // Filter index 0
sFilterConfig.FilterType = FDCAN_FILTER_DUAL; // Use range filter
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; // Route accepted messages to RX FIFO 0
sFilterConfig.FilterID1 = 0x11; // Start of ID range
sFilterConfig.FilterID2 = 0x22; // End of ID range (standard ID max is 0x7FF)
if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
{
/* Filter configuration Error */
Error_Handler();
}
FDCAN defines:
// Configure TX Header for FDCAN1
TxHeader1.Identifier = 0x11;
TxHeader1.IdType = FDCAN_STANDARD_ID;
TxHeader1.TxFrameType = FDCAN_DATA_FRAME;
TxHeader1.DataLength = FDCAN_DLC_BYTES_12;
TxHeader1.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
TxHeader1.BitRateSwitch = FDCAN_BRS_OFF;
TxHeader1.FDFormat = FDCAN_FD_CAN;
TxHeader1.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
TxHeader1.MessageMarker = 0;
Callback function:
// FDCAN1 Callback
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
{
/* Retreive Rx messages from RX FIFO0 */
if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader1, RxData1) != HAL_OK)
{
/* Reception Error */
Error_Handler();
}
if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
{
/* Notification Error */
Error_Handler();
}
}
}
Solved! Go to Solution.
2024-07-22 06:52 AM - edited 2024-07-22 06:54 AM
Ah! you are running TouchGFX!
I suggest you to create a very simple project with a very basic CAN communication in Loopback mode: without any middleware: FreeRTOS, TouchGFX etc .. So I will look at it after. Just an example like we provide in STM32Cube examples: https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects/STM32H743I-EVAL/Examples/FDCAN/FDCAN_Loopback
2024-07-22 11:58 PM - edited 2024-07-23 01:29 AM
Yes, sorry for not mentioning earlier. I have created a new project, where I'm trying to use only FDCAN. I have the same issue as before. Also no data transmission is being detected with osciloscope.
EDIT: interrupt is not being called therefore rx callback is not executed. I tried adding TxFifoCallback, which is also not being called.
Since it's not sending data, the FIFO gets full and enters erro handle state.
2024-07-23 09:39 AM
Hello,
You can't use CAN pins that are already connected to something to the HW. They need to be free. In your case for example and according to the schematics: PD0 and PD1 are used by the VCP (Virtual Comport). PD0 and PD1 need to be free.
Need also to set the IO speed to at least High speed.
2024-07-24 12:14 AM - edited 2024-07-26 03:21 AM
First, thank you for taking your time to help me.
However, when I turn on FDCAN1 the default pins selected are PB8 and PD1. And no conflicts are detected by the .ioc file, that's why I didnt check it out. I changed them to PB8 and PB9 but those seem to be connected to camera connector (I dont have camera connected). The issue presists. TxBuffer is getting filled while RxBuffer doesnt recieve anything (interrupt not triggering, messages not being sent).
EDIT: I have also unsoldered R52 and R56 so PD0 and PD1 are not connected to VCP anymore, issue still presists.
EDIT_2: I have realized that PD0 and PD1 are arduino connector pin names and are not actually connected to FDCAN but to UART. Anyhow, even now that I use osciloscope on the correct pins still nothing to meassure, since that didn't fix loopback.
EDIT_3: I have found out that in the HAL_FDCAN_Start when INIT bit of FDCAN should be cleared CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT); , It doesnt actually clear it. But it does clear CCE, in the user manual it says that INIT bit can be reset at any time
2024-08-14 07:00 AM
So the solution was that when running sys tick with TIM 6 you have to change priority from 15 (default) to something lower otherwise it wont work... Also ControllersTech example tutorial and also older version of STM32 examples are not mentioning GLOBAL FILTER, which you also have to use.