2024-02-13 06:06 AM - edited 2024-02-13 11:11 AM
Hi there,
I am using two STM32H723ZGT communicating via FDCAN2 instance (FDCAN, no bit rate switch, 12500 bit/s). Both controller use the same FDCAN initialization code, but different filter IDs.
As shown below, the message is transfered on receiver CAN_Rx (upper trace) and acknowledged on sender CAN_Rx (lower trace), but neither the HAL_FDCAN_RxFifo0Callback() nor HAL_FDCAN_RxFifo1Callback() is triggered. When the receiver is shut down, the ackowledge disapears, so the message seems stuck in the the CAN peripherial.
CAN instance 1 (CAN2.0) is used for communication with other periperhial devices an works as expected.
What am I missing?
Thanks in advance!
CAN2 initialization FDCAN for both controller
/* USER CODE END FDCAN2_Init 1 */
hfdcan2.Instance = FDCAN2;
hfdcan2.Init.FrameFormat = FDCAN_FRAME_FD_NO_BRS;
hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan2.Init.AutoRetransmission = DISABLE;
hfdcan2.Init.TransmitPause = DISABLE;
hfdcan2.Init.ProtocolException = ENABLE;
hfdcan2.Init.NominalPrescaler = 32;
hfdcan2.Init.NominalSyncJumpWidth = 5;
hfdcan2.Init.NominalTimeSeg1 = 32;
hfdcan2.Init.NominalTimeSeg2 = 7;
hfdcan2.Init.DataPrescaler = 1;
hfdcan2.Init.DataSyncJumpWidth = 16;
hfdcan2.Init.DataTimeSeg1 = 20;
hfdcan2.Init.DataTimeSeg2 = 16;
hfdcan2.Init.MessageRAMOffset = 196;
hfdcan2.Init.StdFiltersNbr = 1;
hfdcan2.Init.ExtFiltersNbr = 1;
hfdcan2.Init.RxFifo0ElmtsNbr = 16;
hfdcan2.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_64;
hfdcan2.Init.RxFifo1ElmtsNbr = 16;
hfdcan2.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_64;
hfdcan2.Init.RxBuffersNbr = 0;
hfdcan2.Init.RxBufferSize = FDCAN_DATA_BYTES_64;
hfdcan2.Init.TxEventsNbr = 0;
hfdcan2.Init.TxBuffersNbr = 0;
hfdcan2.Init.TxFifoQueueElmtsNbr = 16;
hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
hfdcan2.Init.TxElmtSize = FDCAN_DATA_BYTES_64;
if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FDCAN2_Init 2 */
CAN2 Filter configuration
uint8_t CAN_ConfigCAN02Filter(uint8_t own_address)
{
//
uint8_t result = 0;
FDCAN_FilterTypeDef canFilterConfig = { 0 };
uint8_t filterindex = 0;
//
canFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
//
canFilterConfig.IdType = FDCAN_EXTENDED_ID;
//
canFilterConfig.FilterType = FDCAN_FILTER_MASK;
//
canFilterConfig.FilterID1 = own_address; // canIdentifier
canFilterConfig.FilterID2 = 0; // mask: 0 => accept all messages
//
canFilterConfig.RxBufferIndex = 0; // set to 0 if using FIFO
// canFilterConfig.IsCalibrationMsg = 0;
//
canFilterConfig.FilterIndex = filterindex;
// configure the FDCAN reception filter
result += HAL_FDCAN_ConfigFilter(&hfdcan2, &canFilterConfig);
//
filterindex += 2;
// enable Rx interrupts
result += HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
result += HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0);
// enable Tx interrupts
result += HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_TX_COMPLETE, FDCAN_TX_BUFFER0);
result += HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_TX_FIFO_EMPTY, 0);
// configure global filter to reject all non-matching frames
HAL_FDCAN_ConfigGlobalFilter(&hfdcan2,
FDCAN_REJECT,
FDCAN_REJECT,
FDCAN_REJECT_REMOTE,
FDCAN_REJECT_REMOTE);
//
return result;
}
CAN1 initialization CAN2.0
/* USER CODE END FDCAN1_Init 1 */
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = DISABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = ENABLE;
hfdcan1.Init.NominalPrescaler = 40;
hfdcan1.Init.NominalSyncJumpWidth = 5;
hfdcan1.Init.NominalTimeSeg1 = 10;
hfdcan1.Init.NominalTimeSeg2 = 9;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 16;
hfdcan1.Init.DataTimeSeg1 = 20;
hfdcan1.Init.DataTimeSeg2 = 16;
hfdcan1.Init.MessageRAMOffset = 0;
hfdcan1.Init.StdFiltersNbr = 1;
hfdcan1.Init.ExtFiltersNbr = 1;
hfdcan1.Init.RxFifo0ElmtsNbr = 16;
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 = 32;
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 */
2024-02-16 05:46 PM
I don't see HAL_FDCAN_Start?
2024-02-19 08:03 AM - edited 2024-02-19 08:04 AM
Hello,
I'm wondering why you are not using the same config for FDCAN1 and FDCAN2 since you're in classical CAN config: bitrate config (TSEGs and prescalers), FIFO configs etc ..
If you change the config of FDCAN2 to be in frame classic with:
hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
and data sizes for Rx buffers / fifos:
FDCAN_DATA_BYTES_8; instead of FDCAN_DATA_BYTES_64;
and
hfdcan2.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
2024-02-20 11:24 PM
Hi Karl,
HAL_FDCAN_Start(&hfdcan2) is called right after CAN_ConfigCAN02FilterByAddress().
If wouldn't had been called no acknowledge bit would be visible.
Cheers.
2024-02-20 11:39 PM - edited 2024-02-21 12:14 AM
Hi SofLit,
I am using two CAN channels.
Channel 1 H723 A to L432 C
Channel2 H723 A to H723 B
Channel 1 is FDCAN1 in classic format to communicate with a STM32L432 supporting only CAN2.0 (classic) at 20kbit/s.
Channel 2 is FDCAN2 in FDCAN format to communicate with another STM32H723 supporting FDCAN at 12.5kbit/s.
I want to use both channels simultaneously (A - C and A - B) and take advantage of the higher data size of FDCAN, my understanding is that all 3 FDCAN instances are fully independend.
Changing FDCAN2 to classic as recommended shows the same behaviour at receiver B, just an CAN acknowledge no interrupt at the register:
Cheers.
2024-02-21 12:31 AM - edited 2024-02-21 12:32 AM
Hello,
On H723 you can use FDCAN1, FDCAN2 and FDCAN3 in parallel. But the issue is not clear to me.
On which instance you faced the issue?
Could you please share the three projects related to H723A, H723B and L432C?
2024-02-21 12:41 AM
Another question: which HW you're using? ST boards (all the nodes A, B and C) or your own HW? if the latter provide more details for ex schematics.
2024-02-21 04:06 AM - edited 2024-02-21 06:29 AM
Hi SofLit,
I use my own hardware for both H723 and L432
H723A FDCAN1 to L432C CAN using CAN driver sn65hvd230d (ca. 50cm between drivers) at 20kBit/s
so this is OK.
H723A FDCAN2 to H723B FDCAN2 using CAN and no CAN driver but cross over RxCAN and TxCAN lines (ca. 10cm at 20kBit/s
canFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
canFilterConfig.IdType = FDCAN_EXTENDED_ID;
canFilterConfig.FilterType = FDCAN_FILTER_MASK;
1. receive H723B FAIL
canFilterConfig.FilterID1 = own_address; // canIdentifier
canFilterConfig.FilterID2 = 0x1FFFFFFF; // mask: 0 => accept all messages
HAL_FDCAN_ConfigGlobalFilter(&hfdcan2,
FDCAN_REJECT,
FDCAN_REJECT,
FDCAN_FILTER_REMOTE,
FDCAN_FILTER_REMOTE);
2. receive H723B FAIL
canFilterConfig.FilterID1 = own_address; // canIdentifier
canFilterConfig.FilterID2 = 0; // mask: 0 => accept all messages
HAL_FDCAN_ConfigGlobalFilter(&hfdcan2,
FDCAN_REJECT,
FDCAN_REJECT,
FDCAN_FILTER_REMOTE,
FDCAN_FILTER_REMOTE);
3. receive H723B OK
canFilterConfig.FilterID1 = own_address; // canIdentifier
canFilterConfig.FilterID2 = 0x1FFFFFFF; // mask: 0 => accept all messages
HAL_FDCAN_ConfigGlobalFilter(&hfdcan2,
FDCAN_ACCEPT_IN_RX_FIFO1,
FDCAN_ACCEPT_IN_RX_FIFO1,
FDCAN_FILTER_REMOTE,
FDCAN_FILTER_REMOTE);
4. receive H723B OK
canFilterConfig.FilterID1 = own_address; // canIdentifier
canFilterConfig.FilterID2 = 0; // mask: 0 => accept all messages
HAL_FDCAN_ConfigGlobalFilter(&hfdcan2,
FDCAN_ACCEPT_IN_RX_FIFO1,
FDCAN_ACCEPT_IN_RX_FIFO1,
FDCAN_FILTER_REMOTE,
FDCAN_FILTER_REMOTE);
Not calling HAL_FDCAN_ConfigGlobalFilter() at all will lead to no received message.
In my understanding 1. and 2. should receive too. I seems like either the FilterID2 is set false, or that FDCAN_REJECT recjects always, despite any FilterID2 setting.
Cheers!
2024-02-21 05:51 AM
H723A FDCAN2 to H723B FDCAN2 using CAN and no CAN driver but cross over RxCAN and TxCAN lines (ca. 10cm at 20kBit/s
What do you mean by "no CAN driver but cross over RxCAN and TxCAN lines"?
Did you connect H723A Rx to H723B Tx and vice versa ??
2024-02-21 06:28 AM - edited 2024-02-21 06:32 AM
Yes I connected H723A Rx to H723B Tx and vice versa.
It works a shown in case 3. receive H723B OK and case 4. receiveH723B OK there are only 2 members on the bus. Send A /send B are never overlapping since send B is a reply to send A.
To me it seems FilterID2 and the global filter are causing the problem.