defragster
Senior Member+
Blink Simple Sample of HSRUN EEPROM WRITE
This is a Blink Simple Sample of writing the EEPROM - even on the T_3.6 while over 120 MHz. The prior code shows evolving test code to develop and see it work.
This is a Blink Simple Sample of writing the EEPROM - even on the T_3.6 while over 120 MHz. The prior code shows evolving test code to develop and see it work.
Code:
// #include "EESpeedDHR.h" // THIS FILE
// ------------------- COPY BELOW THIS TO YOUR CODE
/*
The following allows writing to EEPROM at HSRUN speeds on T_3.6,
it compiles out when not T_3.6 or under HSRUN speeds
USAGE:
[B] HSRUN_DROP_BLOCK( ) { // DO NO I/O in this block
EEPROM[ 0 ] = 5; // YOUR CODE HERE
}[/B]
*/
uint8_t DropHSRUN( uint8_t DropState ) {
if (DropState) {
Serial.flush(); // make sure nothing queued to send
__disable_irq( ); // Turn off interrupts for the DURATION !!!!
SMC_PMCTRL = SMC_PMCTRL_RUNM(0); // exit HSRUN mode
while (SMC_PMSTAT == SMC_PMSTAT_HSRUN) ; // wait for !HSRUN
}
else {
SMC_PMCTRL = SMC_PMCTRL_RUNM(3); // enter HSRUN mode
while (SMC_PMSTAT != SMC_PMSTAT_HSRUN) delay(1); // wait for HSRUN
__enable_irq( ); // Restore interrupts only when HSRUN restored
}
return DropState; // macro needs 1 on drop call and 0 on raise call to process
}
#define TYPE uint8_t
#if F_CPU > 120000000 && defined(__MK66FX1M0__)
#define HSRUN_DROP_BLOCK() for (TYPE __ToDo=DropHSRUN(1); __ToDo; __ToDo=DropHSRUN(0))
#else
#define HSRUN_DROP_BLOCK() for ( TYPE __ToDo=1; __ToDo; __ToDo=0)
#endif
// ------------------- COPY ABOVE THIS TO YOUR CODE
Code:
#include <EEPROM.h>
[B]#include "EESpeedDHR.h"[/B]
void setup() {
[B] HSRUN_DROP_BLOCK( ) { // DO NO I/O in this block
EEPROM[ 0 ] = EEPROM[ 0 ] + 1;
}[/B]
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(57600);
while (!Serial && (millis () <= 8000));
Serial.print(" __ EEPROM[ 0 ] ="); Serial.println(EEPROM[ 0 ]);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED_BUILTIN on (HIGH is the voltage level)
// put your setup code here, to run once:
}
int ii = 0;
void loop() {
[B] HSRUN_DROP_BLOCK( ) { // DO NO I/O in this block
EEPROM[ ii ] = EEPROM[ ii ] + 1;
}
[/B] Serial.print(" __ EEPROM[ "); Serial.print(ii); Serial.print(" ] ="); Serial.println(EEPROM[ ii ]);
delay(1000);
digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) );
if ( ++ii > E2END / 2) ii = 0;
// put your main code here, to run repeatedly:
}