cancel
Showing results for 
Search instead for 
Did you mean: 

Undefined reference to HAL_UART_Init

arduo
Senior

Anyone knows how to fix undefined reference to HAL_UART_Init,HAL_UART_receive

I included all necessary files for this but somehow it doesn't find any reference

#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_conf.h"
#include "usb_device.h"
#include "usbd_comp_if.h"
#include "usbd_comp.h"
#include "usb_device.h"
#include "stm32f4xx_hal_usart.h"
#include "stm32f4xx_hal_uart.h"
#include <stm32f4xx_hal_uart.c>
#include "usbd_comp_if.h"
#include "usbd_comp.h"
#include "main.h"
#include <stm32f4xx_hal.h>
#include <stm32_hal_legacy.h>
 
extern HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);

11 REPLIES 11
AvaTar
Lead

A common convention in C coding is to NEVER EVER # include *.c files, i.e. sources.

Apart from that, check where the missing function is implemented, and if the regarding source file is built with the project. In this case, supposedly stm32f4xx_hal_uart.c.

Including said source file would effectively create a second implementation, resulting in duplicate linker symbols.

You don't use C++, do you ?

Pavel A.
Evangelist III

Including the C file is probably a desperate attempt to get the function defined 🙂

The unresolved reference likely occurs because HAL_UART_MODULE_ENABLED not defined:

https://github.com/pavel-a/stm32f4_libs/blob/c4560650ddaea6ee33de171027d801a31109565a/STM32Cube_FW_F4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c#L165

This normally should be defined in your stm32f4xx_hal_conf.h.

It is created and updated by CubeMX. If you added the UART outside of the Cube, add also #define HAL_UART_MODULE_ENABLED in the .h

-- pa

no i use c

i removed the double implementation it still throws an error

Hi 😁

I defined it thanks for the hint but it still isn't defined

Piranha
Chief II

Look from where comes the error - compiler or linker. Undefined reference is a linker error and means that compiled function can't be found in object files. In this case it means that stm32f4xx_hal_uart.c is not compiled and linked.

AvaTar
Lead

Post the exact error message from your toolchain, not just short excerpts.

And don't forget preceeding errors, if any.

As a general rule, always start fixing with the first compiler error. Small syntactical errors can cause a torrent of aftereffects.

Do a file search in *.c files for the HAL_UART_Init label.

One of the files should supposedly be part of your project.

If so, check for surrounding # if / # ifdef labels, that possible keep your compiler from seeing it.

Know your tools.

ST does this differently, you include one top level include file, and it then pulls the stm32f4xx_hal_conf.h where you've marked the specific modules you want to include. And then you add the .C files from the library into the project.

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

thanks I fixed it that way.

Now i got my composite device working any idea why i can't connect to USB Serial Device COM Port?

0690X000006DRGmQAO.jpg