Difference between __I and __IO and __O in CMSIS core

I means Input O means Output IO means Input and Output

As Long Pham notes, it is a naming convention, but also it is normal to use meanings to a type. Like an integer can be a counter, a timestamp, a date etc.

There are some reasons to use this:

  • It is good for readability
  • Whenever in future the type of an I, O or IO would change, (user) source code using I, O and IO does not need to be changed, only the type definitions / defines itself.

Since this is for the definition of a hardware register map:

I think the reason is that C, unlike C++, allows the declaration of const qualified variables without providing an initializer:

volatile const uint32_t REG; // Ok in C, invalid in C++

Similarly, C++ doesn't allow const members of struct/classes to be uninitialized either. This is inconvenient when we have read-only hardware registers and wish to make a register map by using structs (classes).

This C++ language limitation is likely why this header uses a dirty hack #ifdef __cplusplus to remove const from a register that should have been const qualified.

Tags:

C++

C

Stm32

Cmsis