2020-09-24 12:19 AM
Hello,
I'm using a STM32CubeIDE.
A lot of the in the main.c file is auto generated.
For example:
UART Handlers, DMA Handlers etc.
I also have a header file where I wrote a lot of user custom functions inside a file named: custom.h
The functions in this header file make use of the auto generated variables from main.c
What's the best way to make the auto generated variables from main.c visible to the functions at custom.h ?
2020-09-24 06:15 AM
One way is to include their definitions as extern in main.h and #include it.
For example, if "uint32_t variable" is in main.c, put this in main.h:
extern uint32_t variable;
You could also just put this statement in custom.h on its own.
2020-09-24 09:49 AM
Thanks,
The variables whose scope I want to extend are autogenerated by the IDE.
Let's see if I understand your suggestions:
2020-09-24 10:18 AM
Put prototypes with extern into the .H file, put the actual definitions in ONE .C file.
If you put the definitions in the .H file, and include it in multiple other source files you'll get "multiple definition" errors.
This is C, standard rules/methods apply.
2020-09-24 10:57 AM
But I don't want to modify the auto-generated code...
2020-09-24 11:02 AM
2020-09-24 02:19 PM
I don't understand you suggestion. The variables are already declared in the auto-generated code section. Do you suggest I declare the same ones again using "extern" in the user sections ??