2024-12-16 12:01 PM
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!
2024-12-16 12:11 PM - edited 2024-12-16 12:24 PM
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.
2024-12-16 12:14 PM - edited 2024-12-16 12:14 PM
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.