Go Down

Topic: How to define physical memory addresses/registers? (Read 2100 times) previous topic - next topic


Hi everyone,

Back in the good ol' days of 8-bit Arduino, we could manipulate ports directly with keywords that redirected to memory addresses, like DDRD, PORTD, PIND, etc.

Just wondering: does a list of the memory addresses/registers of the Due exist somewhere?  Right now, I can see their names on the datasheet, but certain names aren't fixed.  For example, an address to turn on the pins of a port might be PIO_SODR, but, for port D, would it be PIOD_SODR or PIO_SODR_D, etc?

If a big list doesn't exist, how can we write our C code to actually write-to and read-from these registers?
Is there a more traditional way than something like:
Code: [Select]

uint32_t *IOD_OWER = (uint32t*)0x400E14A0 // create a pointer with the address of the register

Thanks in advance!


Sep 23, 2013, 01:39 pm Last Edit: Sep 23, 2013, 01:41 pm by noblepepper Reason: 1
A lot of the definitions are in the hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/instance directory. The macro for your example would be REG_PIOD_SODR which is defined in hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/instance/instance_piod.h

Here is a snippet that sets bits 1 to 8 of PIOC according to the value in "d", these bits are pins 33 to 40 on the Due:
Code: [Select]
REG_PIOC_ODSR = (REG_PIOC_ODSR & 0xFFFFFE01) | ((d << 1) & 0x000001FE)

You can avoid the bit masking if you use SODR and CODR but you have to do two writes instead of one.


Many thanks!  It looks like I just didn't do enough probing into the file strucure!

I've also just discovered this brief paper:


that briefly states a not-so-pretty but definitive way to map the register addresses to variables.  It looks like this:
Code: [Select]

#define PORTA (* (volatile unsigned char *) 0x38)

I'd imagine that a 32-bit microcontroller would have a snippet of code more like this:
Code: [Select]

#define IOD_OWER (* (volatile unsigned int *) 0x400E14A0)


Sep 23, 2013, 08:56 pm Last Edit: Sep 23, 2013, 08:58 pm by robtillaart Reason: 1
if the unsigned int is 32 bit ....
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


I believe the macros defined in these headers do exactly such.

Code: [Select]
REG_PIOA_SODR   (*(WoReg*)0x400E0E30U)

looks like compiler speak for "this is a write only register " to me. If you follow the breadcrumb trail you can probably find all the gory details.

Go Up