Hello,
I'm missing something and I would like to clear it out. Let's start with code (I'm using Arduino IDE 1.8.10 and Teensyduino 1.48 and Teensy 3.6 in this example) - toogling the pin 13 (PC5):
It works just fine, I get ~4.73MHz (almost) square wave.
Now I have something like that (setting up pin 13 using registers):
And same as before I get ~4.73MHz (almost) square wave.
In all above examples the program size is: 8784 bytes (~0.84%) and global variables take 3048 bytes (~1.16%).
But if i do something like that - remove pinMode() and only use the registers:
The program size is now: 2440 bytes (~0.23%) and global variables take 1092 bytes (~0.41%). Which is great, but unfortunately the program is not working now. I guess that startup initialization (.startup section ?) is missing when no core's function is used.
I would be very grateful for pointing me out what is the issue and how to make it right and maybe explain with details why .startup section (if it is the issue) is not invoked in such case.I also appreciate the quick explanation of low-level initialization stuff connected with it.
I'm missing something and I would like to clear it out. Let's start with code (I'm using Arduino IDE 1.8.10 and Teensyduino 1.48 and Teensy 3.6 in this example) - toogling the pin 13 (PC5):
Code:
#include <Arduino.h>
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
GPIOC_PTOR |= (uint32_t)(1 << 5); // make use of pin toggle output register (PTOR)
}
void yield(){}
It works just fine, I get ~4.73MHz (almost) square wave.
Now I have something like that (setting up pin 13 using registers):
Code:
#include <Arduino.h>
void setup()
{
pinMode(11, OUTPUT); // ! setting pin 11 not 13
PORTC_PCR5 = (uint32_t)(1 << 8); // set as GPIO mode
GPIOC_PDDR |= (uint32_t)(1 << 5); // set as Output
}
void loop()
{
GPIOC_PTOR |= (uint32_t)(1 << 5); // make use of pin toggle output register (PTOR)
}
void yield(){}
And same as before I get ~4.73MHz (almost) square wave.
In all above examples the program size is: 8784 bytes (~0.84%) and global variables take 3048 bytes (~1.16%).
But if i do something like that - remove pinMode() and only use the registers:
Code:
#include <Arduino.h>
void setup()
{
// pinMode(11, OUTPUT); // ! setting pin 11 not 13
PORTC_PCR5 = (uint32_t)(1 << 8); // set as GPIO mode
GPIOC_PDDR |= (uint32_t)(1 << 5); // set as Output
}
void loop()
{
GPIOC_PTOR |= (uint32_t)(1 << 5); // make use of pin toggle output register (PTOR)
}
void yield(){}
The program size is now: 2440 bytes (~0.23%) and global variables take 1092 bytes (~0.41%). Which is great, but unfortunately the program is not working now. I guess that startup initialization (.startup section ?) is missing when no core's function is used.
I would be very grateful for pointing me out what is the issue and how to make it right and maybe explain with details why .startup section (if it is the issue) is not invoked in such case.I also appreciate the quick explanation of low-level initialization stuff connected with it.