I am trying to call HAL_UART_Transmit() from my custom SA145.c file, which causes the error: identifier huart1 us undefined. huart1 is declared as extern in main.c. How to call HAL_UART_Transmit() from the file other than main.c
Asked
Active
Viewed 1,078 times
1 Answers
0
error: identifier huart1 us undefined.
huart1 is declared as extern in main.c.
Something needs to be declared as extern
in a file where it is, to use an everyday word, "borrowed".
But it needs to actually exist (ie, not be extern
) is some file. Otherwise the linker will find only attempts to use it, but will never actually find an "it" to use.
At the same time, you may not really want to be calling the basic serial function from a lot of places, but may rather want to wrap it in something appropriate to why you are calling it, eg, to send data to a peripheral, or to create a debug printout, etc. Then you can keep the argument in just one file and not need to share it.

Chris Stratton
- 39,853
- 6
- 84
- 117
-
It is declared as an extern in SA145.h file. It complies fine throws linking error as below. HAL headers included in SA145.h **.\test_sample.axf: Error: L6218E: Undefined symbol huart1 (referred from SA145.o)** I want to send the data to peripheral. – nvm Aug 05 '20 at 02:42
-
Sorry, I wasn't focusing on the fact that this is as link error. See edits – Chris Stratton Aug 05 '20 at 03:27