cancel
Showing results for 
Search instead for 
Did you mean: 

Generated private variables in main.c

neel1311
Visitor

In the generated code in main.c file, there are variables that are declared as "private variables" by the software, such as "ADC_HandleTypeDef hadc1"; "TIM_HandleTypeDef htim1". Since these variables are declared only in main.c and not in main.h, does that mean that the use of these variables in other modules is not encouraged? 
If I need to use them in other modules, can I declare these variable as extern in main.h or is there a better way to handle this?

Thank you in advance!

2 REPLIES 2
Karl Yamashita
Lead III

You can use them as extern. If the variables are not meant to be used outside of the file then it would be declared static.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

You typically don't define variables in .H files, you provide prototypes, extern for those you wish to pull into multiple source files, so as not to get "multiple definition" errors.

You can define and share these in ONE .C file, or make them static to hide them from the global name-space.

Often you'd want to share peripheral instances with stm32xyz_it.c so you could keep all the IRQHandler over there, but HAL/CUBE generally just does what it wants.

 

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