Skip to main content
Associate II
January 12, 2024
Question

HAL_FDCAN_ERROR_NOT_INITIALIZED Error

  • January 12, 2024
  • 2 replies
  • 1947 views

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_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = DISABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 8;
hfdcan1.Init.NominalSyncJumpWidth = 1;
hfdcan1.Init.NominalTimeSeg1 = 14;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 1;
hfdcan1.Init.DataTimeSeg2 = 1;
hfdcan1.Init.MessageRAMOffset = 0;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.RxFifo0ElmtsNbr = 0;
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 = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_QUEUE_OPERATION;
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FDCAN1_Init 2 */

/* USER CODE END FDCAN1_Init 2 */

}
///////////////////////////////////////////////////////

void FDCAN_config(void)
{
FDCAN_FilterTypeDef sFilterConfig;
FDCAN_TxHeaderTypeDef TxHeader;
 
sFilterConfig.IdType = FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
sFilterConfig.FilterID1 = 0x000;
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();
}
}
///////////////////////////////////////////////////////
void Send_FDCAN_TX(uint8_t* TxData)
{
FDCAN_TxHeaderTypeDef TxHeader;
FDCAN_HandleTypeDef hfdcan1;
 
/* Configure transmission parameters */
TxHeader.Identifier = 0x222; /* Set the ID of the received frame message */
TxHeader.IdType = FDCAN_STANDARD_ID; /* Standard ID */
TxHeader.TxFrameType = FDCAN_DATA_FRAME; /* Data frame */
TxHeader.DataLength = FDCAN_DLC_BYTES_16; /* Length of the transmitted data */
TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE; /* Set the error state indicator */
TxHeader.BitRateSwitch = FDCAN_BRS_ON; /* Enable bit rate switching for flexible data-rate (FD) CAN */
TxHeader.FDFormat = FDCAN_FD_CAN; /* FD-CAN format */
TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS; /* Control for sending events to the TX Event FIFO, not stored */
TxHeader.MessageMarker = 0; /* Used to identify message status copied to the TX EVENT FIFO, ranging from 0 to 0xFF */
 
///////////////////////////////////////////////////////
if(HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData) != HAL_OK) // this  is ERROR
{
 
}
else
;
}

/* Update error code */
hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;

return HAL_ERROR;


I'm trying to do FDCan communication, but the moment I use that function,
I think communication was not possible due to that error. If there is anything strange in my settings or code, please correct it and respond.

@stm32h723User #STM32_Nucleo #H723zg



    2 replies

    Rim LANDOLSI
    ST Employee
    January 12, 2024

    Hello @younginpark  and welcome to the community,

     

    I will look into this issue and get back to you as soon as possible.

     

    Thanks,

    Rim.

    Associate II
    January 15, 2024

    When will I get an answer?

    Rim LANDOLSI
    ST Employee
    January 15, 2024

    Hello @younginpark ,

     

    Could you provide a minimal project and the STM32CubeIDE version used as I couldn't reproduce the problem?

     

     

    Associate II
    January 16, 2024

    Is this possible?