2023-12-04 09:08 PM
Hi, I have converted an CubeIDE project to CPP so I can get a GLCD library working, the Adafruit GFX library, for my STM32F407-Discovery board. This required I rename some files from .C to .CPP. It all worked fine. Now I want to get the CAN interface working and when I call "MX_CAN1_Init()", I get the following error.
"main.cpp:672: undefined reference to `HAL_CAN_Init"
I admit I'm a complete novice to this type of C and CPP hybrid, and I hope someone has a solution that will fix this.
I think an "extern "C"" statement would fix it, but no luck, and I'm not even sure I'm using this statement in the source correctly. Can someone help out here?
Thanks.
kvresto.
BTW: I had the same type of error within the "stm32f4xx_it.c" file, It complained about no reference to "HAL_CAN_IRQHandler(&hcan1)" this was for the CAN interrupt, but when I renamed it with the .CPP extension that went away.
Solved! Go to Solution.
2023-12-05 09:47 PM
Hi, just an update, seems I solved the problem. Initially this project was created about 4 years ago with CUBEMX and without the CAN interface. I added the interface copying all of the files and functions from a previous project.
So, I went back and created a new project, this time adding the CAN interface, and it worked. I'm sure someone with experience in how CUBEMX creates the IDE project might add some comment.
Anyway, happy days.
Thanks
2023-12-04 09:22 PM
2023-12-04 09:40 PM
Thanks STTwo-32, this post didn't work in this case.
2023-12-04 09:45 PM - last edited on 2024-11-13 02:33 AM by SofLit
I should also add the error is within a function, please see my code.
static void MX_CAN1_Init(void)
{
/* USER CODE BEGIN CAN1_Init 0 */
/* USER CODE END CAN1_Init 0 */
/* USER CODE BEGIN CAN1_Init 1 */
/* USER CODE END CAN1_Init 1 */
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 4;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_12TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_8TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if(HAL_CAN_Init(&hcan1) != HAL_OK) <-------------- HERE!
{
Error_Handler();
}
/* USER CODE BEGIN CAN1_Init 2 */
/* USER CODE END CAN1_Init 2 */
}
2023-12-05 09:47 PM
Hi, just an update, seems I solved the problem. Initially this project was created about 4 years ago with CUBEMX and without the CAN interface. I added the interface copying all of the files and functions from a previous project.
So, I went back and created a new project, this time adding the CAN interface, and it worked. I'm sure someone with experience in how CUBEMX creates the IDE project might add some comment.
Anyway, happy days.
Thanks