So the battery at that voltage isn't able to supply the needed current for T_3.6 start - and there was a voltage drop.
Not sure what happens if this were put in setup() - for T_3.6 only - if it makes it that far?
This drops the CPU voltage and speed to 120 MHz - it messes with some peripheral used clocks { compiled for F_CPU and F_BUS at build time } and affected peripherals won't work so an idle wait is best. And wait based millis() may be skewed as well. Not sure if it breaks USB init ongoing at that time::
Code:
setup() {
kinetis_hsrun_disable();
// wait for some time
kinetis_hsrun_enable();
// begin normal setup
}
Another alternative might be a couple iterations of this at the start of setup():
Code:
asm volatile( "wfi" );
Just wrote this to work with USB - but T_3.6 already started by now at full power for some 300ms:
Code:
void setup() {
// put your setup code here, to run once:
kinetis_hsrun_disable();
// wait for some time
do
asm volatile( "wfi" );
while (millis() < 1000 );
kinetis_hsrun_enable();
while (!Serial && millis() < 4000 );
Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
Serial.println(millis());
pinMode( 13, OUTPUT );
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite( 13, !digitalRead( 13 ) );
delay(1000);
}