Go Down

Topic: Port Pin and PIO_SODR and PIO_CODR Addresses in Assembler (Read 4293 times) previous topic - next topic



Im trying to find out the exact addresses of the Pins and PIO_CODR and PIO_SODR for all the digital pins.
I want to use these for the assembler part of my code.
To set the pin voltage to high and low without using any c++ commands in my library.
I already tried to read those values somehow but it didnt seem to work that well.

Is there any documentation about it, like the address for Pin 22 =  #0x0FFFADFF  and the PIO_SODR = #0xFFDDFFAA ?


Yeah, there is documentation for it.

In the SAM3X/A documentation for the chip (document 11057) - AT91SAM ARM-based Flash MCU SAM3X SAM3A Series - on pages 660 and 661 are the addresses you're looking for.

For instance:
PIO_SODR is 0x400E0E30 (PIOA), 0x400E1030 (PIOB), 0x400E1230 (PIOC), 0x400E1430 (PIOD), 0x400E1630 (PIOE), 0x400E1830 (PIOF)


Thanks alot.

Im a bit new to the Arduino stuff and still trying to process all the information.
Its an awful lot of stuff to learn, especially if you try to create a library.

But i dont seem to find the pinValue in there.

At the moment these are the parts of my code where i want to erase the methods and just use the values out of the document.

//pin is 22 for example a digital output pin

Pio * port = g_APinDescription[pin].pPort;
uint32_t pinValue = g_APinDescription[pin].ulPin;
PIO_SetOutput(port, pinValue, LOW, 0, 0);


"str %[val], %[set]\n"

      : "=r" (colors)
      : "0" (colors),
        [set] "m" (port->PIO_SODR),
        [clear] "m" (port->PIO_CODR),
        [val] "r" (pinValue)
      : "r3", "r12", "cc"


Can you also tell me where i can find the pinValues that i get from g_APinDescription[22].ulpin and how can i find out which Pin belongs to which PIOx  ( x stands for A-F ) 
Its a 1400 pages document and i did go through it 1 time now and dont seem to find what im looking for.


First of all, stop and ask yourself why you want to make things so complicated. Are you trying to break some sort of speed record for port manipulation?

Still, look at this file: arduino\hardware\arduino\sam\variants\arduino_due_x\variant.cpp in that file is the definition of g_APinDescription. In there you can find the values... sort of. Even that file uses symbolic names. You really are better off just using the symbolic names. Going straight to the actual addresses doesn't really gain you anything other than making your code extremely hard to follow and/or understand.


Jun 08, 2013, 05:46 pm Last Edit: Jun 08, 2013, 05:55 pm by Demokra Reason: 1
Yea the Speed-record is what i am looking for actually.
I want to address alot of pins inside of my assembler part and the extended assembly just takes 10 commands and i only have 12 registers.
So i could only get the SODR/CODR/pinValues for about 3 pins in total like this.
And thats not enough for what i am planning to do.


I also read about parallel pin axcess somewhere, but is that only "pseudo parallel" like a one core cpu is kind of multitasking or is it really parallel?



If you set multiple bits in one of the control registers then they'll really change in parallel. So, it's possible to change the state of multiple pins at once but they've got to be in the same bank (A,B,C,D,etc)


Yea i finally think i got how it works and why i use an uint32 for these banks.
Each bank has 32 pins and if i want to axcess the first 3 pins i set the int to "00000000000000000000000000000111" = 7

In the end i want to axcess 24 pins as fast as possible.
So if i find one bank with 24 digital pins i could do that with just one instruction.
Thats great news.

Now i just have to find out which bit of the uint32 is for which pin inside the PioA etc...
Maybe i can get that info while i reverse engineer a bit with atmel studio.
Or make an output to my pc somehow.
Get an array with all the digital pins and look at the values.
If he tells me pin 22 = 64 i know which bit is set in which bits are not set. 

Is there an easy way to output the data in the console on my pc while i have the due connected to my USB?

Thanks alot for your great help Collin80


The answer to your question about which pins are on PIOA, PIOB, etc can be found in the very first topic of the DUE forum http://forum.arduino.cc/index.php?topic=132130.0. Answers to how you communicate with your PC while having it connected to USB can be found on the arduino webpage and is used in almost every example code that comes with the Arduino software.

I warmly advice you to spend some time learning about the DUE by yourself on the arduino webpage and looking for the answers of your questions either there or here in the DUE forum, by reading previous posts (like the important pinned first topics). It will make your life much easier and your project much more efficient! I have the feeling you have an unwanted talent to complicate things more than they need to be ;) .. just as a personal advice ;)

What is your final project about that needs you to switch 24 pins really in parallel (meaning parallel within <12ns!)?


Jun 10, 2013, 12:02 pm Last Edit: Jun 10, 2013, 02:24 pm by Demokra Reason: 1
I did find the pinout Diagram before as well but i didnt know how to read it.
But now i seem to understand how it works and can start to test around with my assembler code.

And the output was just so i could use g_Apindescription to output the value to my pc so i know which pin is 22 but now i know its PIOB 26.
So i assume that means its the 26 Bit for PIOB.

For my project i have to set 108 RGB LED's at 24 Pins which need to get 24 bit of data for the color.
So i send 24*24*108 bits.

I tried different approaches but its not going that well and are not fast enough in the end.
Its not about making it more complicated, it is just about the speed.

And now that i have the pinValues and addresses for PIO_SODR/CODR i still cant seem to use it directly with the "str" command.
I have also been looking through variant.cpp and corresponding files but it is a bit cryptic and every file points to another file where the information might be hidden.

Go Up