Skip to content

Instantly share code, notes, and snippets.

@kamilion
Created November 6, 2019 06:22
Show Gist options
  • Save kamilion/7d22c7872f50290096af793fe1efbe5d to your computer and use it in GitHub Desktop.
Save kamilion/7d22c7872f50290096af793fe1efbe5d to your computer and use it in GitHub Desktop.
Teensy 4.0 Clockspeed (iMX RT1062)
/*
* Clock speed changes
* Lifted from:
* https://forum.pjrc.com/threads/57444-How-to-change-clock-speed-on-Teensy-4-0?p=214257&viewfull=1#post214257
*/
#if defined(__IMXRT1062__)
extern "C" uint32_t set_arm_clock(uint32_t frequency);
#endif
uint32_t count, prior_count;
uint32_t prior_msec;
uint32_t count_per_second;
bool flip = true;
void setup() {
#if defined(__IMXRT1062__)
set_arm_clock(24000000);
#endif
Serial.begin(1000000); // edit for highest baud your board can use
while (!Serial) ;
#if defined(__IMXRT1062__)
//set_arm_clock(24000000);
Serial.print("F_CPU_ACTUAL=");
Serial.println(F_CPU_ACTUAL);
#endif
count = 10000000; // starting with 8 digits gives consistent chars/line
prior_count = count;
count_per_second = 0;
prior_msec = millis();
pinMode( LED_BUILTIN, OUTPUT );
digitalWriteFast( LED_BUILTIN, flip );
}
void loop() {
while (1) {
Serial.print(" >count=");
Serial.print(count);
Serial.print(", lines/s=");
Serial.print(count_per_second);
if ( !(count % 4) ) {
Serial.print(' ');
Serial.println(millis() / 1000);
}
count = count + 1;
uint32_t msec = millis();
if (msec - prior_msec > 1000) {
flip = !flip;
digitalWriteFast( LED_BUILTIN, flip );
if ( !Serial ) {
delay( 50 );
flip = !flip;
digitalWriteFast( LED_BUILTIN, flip );
}
prior_msec = prior_msec + 1000;
count_per_second = count - prior_count;
prior_count = count;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment