Pages: [1]   Go Down
Author Topic: How to define physical memory addresses/registers?  (Read 910 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
uint32_t *IOD_OWER = (uint32t*)0x400E14A0 // create a pointer with the address of the register

Thanks in advance!
Logged

Nashville Tennessee, USA
Offline Offline
Sr. Member
****
Karma: 15
Posts: 366
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: September 23, 2013, 06:41:22 am by noblepepper » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I've also just discovered this brief paper:

http://www.atmel.com/Images/avr_3_04.pdf

that briefly states a not-so-pretty but definitive way to map the register addresses to variables.  It looks like this:
Code:
#define PORTA (* (volatile unsigned char *) 0x38)
I'd imagine that a 32-bit microcontroller would have a snippet of code more like this:
Code:
#define IOD_OWER (* (volatile unsigned int *) 0x400E14A0)

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if the unsigned int is 32 bit ....
« Last Edit: September 23, 2013, 01:58:00 pm by robtillaart » Logged

Rob Tillaart

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

Nashville Tennessee, USA
Offline Offline
Sr. Member
****
Karma: 15
Posts: 366
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged

Pages: [1]   Go Up
Jump to: