cancel
Showing results for 
Search instead for 
Did you mean: 

H723 FDCAN1 and FDCAN2

PGrif.2
Associate III

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.

FDCAN messageFDCAN message

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 */

 

 

 

 

17 REPLIES 17
Karl Yamashita
Lead II

I don't see HAL_FDCAN_Start?

SofLit
ST Employee

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;

 

 

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.

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.

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:

FDCAN 2 classicFDCAN 2 classic

FDCAN2 interrupt registerFDCAN2 interrupt register

FDCAN2 classic settingsFDCAN2 classic settings 

 

 Cheers.

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?

 

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.
SofLit
ST Employee

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. 

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.

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

  • send H723A OK
  • receive L432C OK
  • send L432C OK
  • receive H723A OK

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

  • send H723A OK (CAN bus mode external loopback)
  • receive settings are always CAN bus mode bus monitoring and

 

 

canFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
canFilterConfig.IdType = FDCAN_EXTENDED_ID;
canFilterConfig.FilterType = FDCAN_FILTER_MASK;

 

 

1. receive H723B FAIL

  • FilterID2 matches the only incomming CAN ID (0x1FFFFFFF matches all 29Bit)
  • gobal reject all non matching CAN IDs
  • should be receiving since FIlterID2 matches the send ID and the global filter rejects all other CAN IDs (no others are send, so nothing left to reject)

 

 

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

  • FilterID2 match all CAN IDs
  • gobal reject all non matching CAN IDs
  • should be receiving since the FilterID matches all CAN IDs and the global filter rejects all other CAN IDs (no others are send, so nothing left to reject)

 

 

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

  • FilterID2 matches the only incomming CAN ID (0x1FFFFFFF matches all 29Bit)
  • gobal accept all non matching CAN IDs
  • receives since all IDs are allowed by global filter

 

 

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

  • FilterID2 matches the all incomming CAN IDs
  • gobal accept all non matching CAN IDs
  • receives since all ID are allowed by FilterID2 and by global filter

 

 

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!

 

 

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 ??

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.

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.