Skip to main content
YFric
Associate II
October 22, 2018
Question

Why don't I have HAL_CAN_Transmit in the generated CubeMX code?

  • October 22, 2018
  • 5 replies
  • 3615 views

I setup a project in CubeMX (STM32F302C6), activated CAN (and other peripherals) and did everything. I generated the code and opened it in eclipse. However, in the HAL_CAN library the functions like HAL_CAN_Transmit are missing. I have these control functions:

/* Control functions **********************************************************/
HAL_StatusTypeDef HAL_CAN_Start(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_Stop(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_RequestSleep(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan);
uint32_t HAL_CAN_IsSleepActive(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_AddTxMessage(CAN_HandleTypeDef *hcan, CAN_TxHeaderTypeDef *pHeader, uint8_t aData[], uint32_t *pTxMailbox);
HAL_StatusTypeDef HAL_CAN_AbortTxRequest(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes);
uint32_t HAL_CAN_GetTxMailboxesFreeLevel(CAN_HandleTypeDef *hcan);
uint32_t HAL_CAN_IsTxMessagePending(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes);
uint32_t HAL_CAN_GetTxTimestamp(CAN_HandleTypeDef *hcan, uint32_t TxMailbox);
HAL_StatusTypeDef HAL_CAN_GetRxMessage(CAN_HandleTypeDef *hcan, uint32_t RxFifo, CAN_RxHeaderTypeDef *pHeader, uint8_t aData[]);
uint32_t HAL_CAN_GetRxFifoFillLevel(CAN_HandleTypeDef *hcan, uint32_t RxFifo);

But these are not even described in the documentation (https://www.st.com/content/ccc/resource/technical/document/programming_manual/6c/3a/cb/e7/e4/ea/44/9b/DM00046982.pdf/files/DM00046982.pdf/jcr:content/translations/en.DM00046982.pdf )

Probably I am missing some settings in CubeMX but I can't find them...

This topic has been closed for replies.

5 replies

Technical Moderator
October 23, 2018

Hello @YFric​ ,

With the new HAL CAN driver, the function HAL_CAN_Transmit() is replaced by HAL_CAN_AddTxMessage() to place Txrequest, then HAL_CAN_GetTxMailboxesFreeLevel() for polling until completion.

As the HAL CAN driver has been redesigned with new API, please find below a short migration guide:

  • Fields of CAN_InitTypeDef structure are renamed: SJW to SyncJumpWidth, BS1 to TimeSeg1, BS2 to TimeSeg2, ABOM to AutoBusOff, AWUM to AutoWakeUp, NART to AutoRetransmission (inversed), RFLM to ReceiveFifoLocked and TXFP to TransmitFifoPriority
  • HAL_CAN_Init() is split into both HAL_CAN_Init() and HAL_CAN_Start()
  • HAL_CAN_Transmit() is replaced by HAL_CAN_AddTxMessage() to place Tx request, then HAL_CAN_GetTxMailboxesFreeLevel() for polling until completion
  • HAL_CAN_Transmit_IT() is replaced by HAL_CAN_ActivateNotification() to enable transmission with interrupt mode, then HAL_CAN_AddTxMessage() to place Tx request
  • HAL_CAN_Receive() is replaced by HAL_CAN_GetRxFifoFillLevel() for polling until reception, then HAL_CAN_GetRxMessage() to get Rx message
  • HAL_CAN_Receive_IT() is replaced by HAL_CAN_ActivateNotification() to enable reception with interrupt mode, then HAL_CAN_GetRxMessage() in the receive callback to get Rx message
  • HAL_CAN_Sleep() is renamed to HAL_CAN_RequestSleep()
  • HAL_CAN_TxCpltCallback() is split into HAL_CAN_TxMailbox0CompleteCallback(), HAL_CAN_TxMailbox1CompleteCallback() and HAL_CAN_TxMailbox2CompleteCallback()
  • HAL_CAN_RxCpltCallback() is split into HAL_CAN_RxFifo0MsgPendingCallback() and HAL_CAN_RxFifo1MsgPendingCallback()

Please refer to the attached document for more details about the new HAL CAN driver and migration guide.

Kind Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
TFabi
Visitor II
February 26, 2019

Hello Imen,

a small bug page 17 :

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan)

{

HAL_CAN_GetRxMessage(&hcan1 => hcan ,CAN_RX_FIFO0,&RxHeader,RxData);

HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_2);

}

regards

Hidekazu
Associate
November 3, 2018

I don't have an answer to contribute but have a further question since I had the same question as the original poster. Is there a more-up-to-date documentation somewhere I can read so we don't need to constantly search the web for information? It's been very frustrating trying to get CAN to work on the STM32F4 because the documentation is outdated :( I appreciate any help!

YFric
YFricAuthor
Associate II
November 3, 2018

@Imen DAHMEN​ Thank you, this helped indeed a lot!

@Hidekazu​ I haven't found anything except the manual linked above, it is indeed frustrating at times...

Andrei Chichak
Lead
February 4, 2020

Is there a possibility of coercing someone into converting this random powerpoint into a proper app note describing the CAN system API?

Please?

Andrei

PSchi.5
Associate
May 27, 2022

@Imen DAHMEN​  Sorry to necropost, but is there any update on this? It's pretty ridiculous that such a basic feature as transmitting a canbus message has documentation that is actively wrong - and for this to be the case for at least 3 years!