Which variable types/sizes are atomic on STM32 microcontrollers?

后端 未结 3 1139
醉酒成梦
醉酒成梦 2020-12-09 06:01

Here are the data types on STM32 microcontrollers: http://www.keil.com/support/man/docs/armcc/armcc_chr1359125009502.htm.

These microcontrollers use 32-bit ARM core

3条回答
  •  一向
    一向 (楼主)
    2020-12-09 06:12

    Atomic "arithmetic" can be processed by CPU Core registers!

    It can be any types one or four bytes depends on architecture and instruction set

    BUT modification of any variable located in memory take at least 3 system steps: RMW = Read memory to register, Modify register and Write register to memory.

    Therefore atomic modification can possible only if you control using of CPU registers it does means need use pure assembler and don't use C or Cpp compiler.

    When you use C\Cpp compiler it placed global or global static variable in memory so C\Cpp don't provide any atomic actions and types

    Note: you can use for example "FPU registers" for atomic modification (if you really need it), but you must hide from the compiler and RTOS that architecture has FPU.

提交回复
热议问题