Is GPIO9_DR volatile?

madmyers

Active member
Hey. I'm new to Teensy and using some code that accesses GPIO9_DR. Using the Arduino IDE, I'd like to ensure the definition includes volatile so things like

while ( (GPIO9_DR&0x80000000) != 0) {}

Don't get optimized out.

I've been unable to find the definition of GPIO9_DR to answer this question myself. So ---

1. Does GPIO9_DR include volatile in its definition?
2. To help a new guy, where would I find this answer so I don't need to ask in the future? :)

Thanks
 
As you can see in cores/teensy/imxrt.h, GPIO9_DR is accessed via a structure where the target member is volatile. The link is to Paul's Github repo for the Teensyduino cores, with each release version having their own tag.

It is possible to use the GCC compiler (hardware/tools/arm/bin/arm-none-eabi-gcc -E -dM file) to preprocess the core headers (repeatedly, using a temporary file) and find out the exact definition of each macro, but I've find the Github interface is fast enough, so haven't bothered yet.
 
Just to add a bit more info, long ago we had much simpler defines. But in practice that leads to inefficient code. When each define is just an address, the compiler doesn't "know" they're all the same peripheral. In typical usage where you access several of a peripheral's registers within the same function, the compiler would allocate a separate register for each address. Using the struct lets the compiler generate efficient code by allocating and initializing only 1 register with the base address. Then is uses instructions which encode the offset within the struct right into each LD or STR instruction. The struct approach also makes writing more generic code much simpler. But even in the case of code that just uses the peripheral specific register names directly, these more complicated defines actually result in the compiler generating more efficient code.
 
Back
Top