Skip to main content
Visitor II
April 14, 2021
Solved

Hello, I am trying to set up a FDCAN communication (STD Id) at a baud rate of 250 kbit/s in STM32G473RBT . The Tx part seems to work perfectly but I have a problem at the level of the reception.

  • April 14, 2021
  • 2 replies
  • 9175 views

I try to just toggle a led for each received frame (STD ID).

With a logic analyser I checked the Rx pin on the Rx MCU and the frames arrive well. Hence my feeling that the problem lies at the level of the callback function where the MCU never go.

Thank you in advance for the help you will be able to give me.

    This topic has been closed for replies.
    Best answer by SKacp.1

    Hi,

    You have problem with file "startup_stm32g473rbtx.s". I attached new file for Your project. Please replace only this file.

    Best Regards,

    Slawek

    2 replies

    Visitor II
    April 14, 2021

    Hi,

    If You want to have communication 250 kb/s please change in the init section from hfdcan1.Init.NominalPrescaler = 1 to hfdcan1.Init.NominalPrescaler = 4.

    Do no not change hfdcan1.Init.ClockDivider. This is divider main clock fequency for FDCAN. If You change this divider You must also change the parameters NominalTimeSeg1 and NominalTimeSeg2.

    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_DIV1;
     hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
     hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
     hfdcan1.Init.AutoRetransmission = ENABLE;
     hfdcan1.Init.TransmitPause = ENABLE;
     hfdcan1.Init.ProtocolException = DISABLE;
     hfdcan1.Init.NominalPrescaler = 4;
     hfdcan1.Init.NominalSyncJumpWidth = 16;
     hfdcan1.Init.NominalTimeSeg1 = 63;
     hfdcan1.Init.NominalTimeSeg2 = 16;
     hfdcan1.Init.DataPrescaler = 1;
     hfdcan1.Init.DataSyncJumpWidth = 4;
     hfdcan1.Init.DataTimeSeg1 = 5;
     hfdcan1.Init.DataTimeSeg2 = 4;
     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 */
     
    	FDCAN_FilterTypeDef sFilterConfig;
     
    	sFilterConfig.IdType = FDCAN_STANDARD_ID;
    	sFilterConfig.FilterIndex = 0;
    	sFilterConfig.FilterType = FDCAN_FILTER_MASK;
    	sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
    	sFilterConfig.FilterID1 = 0x321;
    	sFilterConfig.FilterID2 = 0x7FF;
     
    	if(HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
    	{
    		Error_Handler();
    	}
     
    	if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
    	{
    		Error_Handler();
    	}
     
    	if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
    	{
    		Error_Handler();
    	}
     
    	if(HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
    	{
    		Error_Handler();
    	}
     
    	TxHeader.Identifier = 0x123;
    	TxHeader.IdType = FDCAN_STANDARD_ID;
    	TxHeader.TxFrameType = FDCAN_DATA_FRAME;
    	TxHeader.DataLength = FDCAN_DLC_BYTES_8;
    	TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
    	TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
    	TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
    	TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
    	TxHeader.MessageMarker = 0;
     
     
     /* USER CODE END FDCAN1_Init 2 */
     
    }

    Best Regards,

    Slawek

    Best Regards

    Visitor II
    April 15, 2021

    thank you for your reply but i don't have any problem with the baud rate because i word with 20mhz the clock of FD CAN.i get exactly 250 250 kb/s  with the hfdcan1.Init.NominalPrescaler = 1. the problem that i send message from ixxat and there is no receive callback :/. the interruption of FD CAN dosen't work .do you know the reason of that problem !! thank you

    Visitor II
    April 15, 2021

    Hi,

    How You check that You do not have receive callback from ixxat?

    Please also check settings of Your "sFilterConfig".

    Best Regards,

    Slawek

    Visitor II
    April 15, 2021

    hi;

    the same problem HardFault_Handler :\

    Visitor II
    April 15, 2021

    Hi,

    Please send me Your project.

    Which version STM32CubeIDE You use?

    Best Regards,

    Slawek

    Visitor II
    April 15, 2021

    hello;

    i use the version 1.6.1 of STM32CubeIDE .

    https://drive.google.com/drive/folders/1dFU3DTQlKSMKYTDDUaQHnbL_vToalO9Q?usp=sharing

    Best Regards,

    nasri