I have been unsuccessful meeting the spec frequency of 35 MHz for I/O pins (Pin Group 2 on pg. 1423 of data sheet). The fastest I can get is ~2 MHz, using the below code fragment:
I checked the value of my clock register REG_PMC_MCKR, and found that it should output an 84 MHz signal from PLLACK. Looking at data sheet pg. 544, the PMC Clock Diagram shows the MCK go direct into the peripheral clock. This I assume is the same signal that moves to the PIO controller, labeled "System Clock" on pg. 644.
What else do I need to set to meet the spec for Set/Clear frequency of the I/O lines?
Also the &= operand is equivalent to REG = REG & VAL; so its probably a 2 step operation (you should check the generated assembly code as suggest by DuaneB).
This is the fastest I have managed so far. I haven't verified the output signal but it looks plausible.
void setup(){
Serial.begin(115200);
for(int p=2;p<70;p++)pinMode(p,OUTPUT);
}
#define do10(x) x x x x x x x x x x
void loop(){
uint32_t s=0x7fffffff;
uint32_t r=0x0;
typeof(REG_PIOC_ODSR) *p=®_PIOC_ODSR;
long t=micros();
for(int x=0;x<1000;x++){
do10(do10(do10( *p=s;*p=r; )))
}
t=micros()-t;
Serial.print("1 million write pairs in ");
Serial.print(t);
Serial.print(" uS = ");
Serial.print(1000000.0/double(t));
Serial.println(" MHz");
}
Unless I am missing something, its also a bit pointless - programmatically toggling pins when timers can do it faster and more consistently - i.e. not loop over head or asymmetry.
Thank you all for your responses, I was unaware of a method for getting the assembly from the compiler, so DuaneB that was tremendous help. Using a method similar to the post by stimmer, I was able to scope a 21 MHz signal.
And yes, I am aware of the methods for producing a reliable clock through other protocols, timers, etc. The current application is a user-controlled clocking of data in a finite state machine, I just wanted to see my max pin switching frequency.