cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H750-DK FD CAN packet reception is not working in normal mode

Kasun Dinesh
Associate III

HI all,

I am developing a CAN FD application using STM32H750-DK. Packet reception to FIFO is working in External Loopback mode and packet transmission works as well. But once I change the mode to Normal, packet reception (FIFO interrupt) dosent fire If i send a packet to the DK and (receiving does not work). It seems its not ack the receiving packets. This is the code I m using.

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.FrameFormat = FDCAN_FRAME_FD_BRS;
  hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
  hfdcan1.Init.AutoRetransmission = DISABLE;
  hfdcan1.Init.TransmitPause = DISABLE;
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 1;
  hfdcan1.Init.NominalSyncJumpWidth = 8;
  hfdcan1.Init.NominalTimeSeg1 = 0x1f;
  hfdcan1.Init.NominalTimeSeg2 = 8;
  hfdcan1.Init.DataPrescaler = 1;
  hfdcan1.Init.DataSyncJumpWidth = 8;
  hfdcan1.Init.DataTimeSeg1 = 0x1f;
  hfdcan1.Init.DataTimeSeg2 = 8;
  hfdcan1.Init.MessageRAMOffset = 0;
  hfdcan1.Init.StdFiltersNbr = 0;
  hfdcan1.Init.ExtFiltersNbr = 1;
  hfdcan1.Init.RxFifo0ElmtsNbr = 1;
  hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_64;
  hfdcan1.Init.RxFifo1ElmtsNbr = 0;
  hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_64;
  hfdcan1.Init.RxBuffersNbr = 0;
  hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_64;
  hfdcan1.Init.TxEventsNbr = 0;
  hfdcan1.Init.TxBuffersNbr = 0;
  hfdcan1.Init.TxFifoQueueElmtsNbr = 1;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_12;
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN FDCAN1_Init 2 */
 
	/* Configure extended ID reception filter to Rx FIFO 1 */
	sFilterConfig.IdType = FDCAN_EXTENDED_ID;
	sFilterConfig.FilterIndex = 0;
	sFilterConfig.FilterType = FDCAN_FILTER_MASK;
	sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
	sFilterConfig.FilterID1 = 0x2011FFF;
	sFilterConfig.FilterID2 = 0xFFFFFFF;
	if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
	{
		Error_Handler();
	}
 
	if (HAL_FDCAN_DisableEdgeFiltering(&hfdcan1) != HAL_OK)
	{
		Error_Handler();
	}
 
 
	if (HAL_FDCAN_ConfigInterruptLines(&hfdcan1, 0xFFFFFFFF, FDCAN_INTERRUPT_LINE0) != HAL_OK)
	{
		  Error_Handler();
	}
 
	if(HAL_FDCAN_ActivateNotification(&hfdcan1,FDCAN_IT_RX_FIFO0_NEW_MESSAGE,0) != HAL_OK)
	{
	  Error_Handler();
	}
 
	if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
	{
		Error_Handler();
	}
 
	if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
	{
	  Error_Handler();
	}
 
    /* Add second message to Tx FIFO */
    TxHeader.Identifier = 0x2011FFF;
    TxHeader.IdType = FDCAN_EXTENDED_ID;
    TxHeader.TxFrameType = FDCAN_DATA_FRAME;
    TxHeader.DataLength = FDCAN_DLC_BYTES_12;
    TxHeader.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
    TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
    TxHeader.FDFormat = FDCAN_FD_CAN;
    TxHeader.TxEventFifoControl = FDCAN_STORE_TX_EVENTS;
    TxHeader.MessageMarker = 0xDD;
 
    while(1)
    {
		if(HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData2) != HAL_OK)
		{
		  Error_Handler();
		}
		HAL_Delay(1000);
    }
 
  /* USER CODE END FDCAN1_Init 2 */
 
}
 
 
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
	FDCAN_RxHeaderTypeDef   RxHeader;
 
	if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
	{
		/* Retrieve Rx messages from RX FIFO0 */
		if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
		{
		Error_Handler();
		}
 
		/* Display LEDx */
		if ((RxHeader.Identifier == 0x321) && (RxHeader.IdType == FDCAN_STANDARD_ID) && (RxHeader.DataLength == FDCAN_DLC_BYTES_2))
		{
		  //LED_Display(RxData[0]);
		  //ubKeyNumber = RxData[0];
		}
	}
 
	if(HAL_FDCAN_ActivateNotification(&hfdcan1,FDCAN_IT_RX_FIFO0_NEW_MESSAGE,0) != HAL_OK)
	{
	  Error_Handler();
	}
}

Can some one help me to figure out the issue. Thanks

2 REPLIES 2

Do you have two units communicating with each other?

What if you accept all packets, which do you see then?

The Extended ID is 29-bits as I recall, not 28

Unlikely to see any Standard ID packets in the callback if you're not filtering for them.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Kasun Dinesh
Associate III

HI Clive,

Thanks for your reply.

Do you have two units communicating with each other?

  • Yes. The 2nd device i used has a working CAN interface. It receives the packets I am sending via STM32F750-DK

What if you accept all packets, which do you see then?

  • I tried that by setting sFilterConfig.FilterID2 = 0x0000000; I can see it execute HAL_FDCAN_RxFifo0Callback in external loopback or loopback mode. But I dont get that event in normal mode. What i saw is STM does not acknowledge the receiving packet. Because the other device continually transmit the same packet.

Any idea why its not acknowledging?