AnsweredAssumed Answered

General questions on STM32 programming paradigms

Question asked by pod.hate on Nov 12, 2011
Latest reply on Nov 12, 2011 by Clive One

I could not find any good document on internet about STM32 programming. Unfortunately, STM's own documents do not explain anything more than register functions. I will greatly appreciate if anyone could explain (or at lest give me some hints about) the following questions:

       
  1.    

    I noticed that in all example programs that STM provides, local variables for main() are always defined outside of the main() function (with occasional use of static keyword). Is there any reason for that? Should I follow a similar practice? Should I avoid using local variables inside the main?

       
  2.    
  3.    

    I have a gloabal variable which is updated within the clock interrupt handle. I am using the same variable inside another function as a loop condition. Don't I need to access this variable using some form of atomic read operation? How can I know that a clock interrupt does not change its value in the middle of the function execution? Should I need to cancel clock interrupt everytime I need to use this variable inside a function? (However, this seems extremely ineffective to me as I use it as loop condition. I believe there should be better ways of doing it).

       
  4.    
  5.    

    Keil automatically inserts a startup code which is written in assembly (i.e. startup_stm32f4xx.s). This startup code has the following import statements: IMPORT SystemInit IMPORT __main I "C", it makes sense. However, in C++ both main and system_init have different names (e.g. _int_main__void). How can this startup code can still work in C++ even without using "extern "C" " (I tried and it worked). How can the c++ linker (armcc --cpp) can associate these statements with the correct functions?

       

Outcomes