What is the '__IO' directive in GCC?

embedded, gcc

Solution

If it is not recognised it will be because an appropriate system header containing the definition has not been included.

It will be defined in the chip support header file provided with the toolchain. It is type qualifier, or rather a macro (`#define`) that will expand to a type qualifier. It is used for example as follows:

__IO uint8_t CSSR;

Here `uint8_t` is the type, so __IO cannot in fact be a `typedef` because it is not used where a type is valid. The __IO macro expands to whatever the particular compiler requires to ensure correct I/O access and addressing. In the typical case where I/O is memory mapped, it will simply expand to `volatile` since all I/O should be declared volatile to ensure explicit accesses are not optimised out.

If you want to be sure, download a demo version of the IAR tools and take a look in the header files at how it is defined for your particular architecture. Otherwise you might just use `#define __IO volatile`

Problem

I am working on an embedded device, and there is some code that was originally compiled using the IAR compiler. I am trying to recompile said code using the GCC compiler. There is a particular statement: `typedef __IO` , which simply doesn't get compiled ("Unrecognized symbol error"). Could anyone suggest how I could get this statement to compile properly?

Original source