Paul: Please look below - there is a problem with this object creation calling Wire.begin() differently. It isn't from the change to timing of usb_init as I restored and doubled the delay(350). The odd thing is that compiling with LTO must re-order when the object is created?
First thing I did was try to see blink right away. There is no entry to setup() at all - even to turn on the LED - until this line is commented: //AM2321 ac;
It is correct there is trouble with this library causing the Teensy to ABEND - but the trouble is not with Serial.begin() but before.
I made this change to determine there is no sign of usable entry to setup()::
Code:
void setup()
{
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
Serial.begin(115200); // USB is always 12 Mbit/sec
Serial.println( millis());
// ...
This failure is with default Optimize 'Faster'
As suggested above changing the compile optimization quickly allows it to run when set to 'Smallest code with LTO' or 'Faster with LTO'
When I change to 'Smallest code' it again no longer enters setup and turns on the LED.
@sigi :: Please compile your existing code "with LTO" and report your findings if it is fully functional. You might want to make the edit above to setup() to get the LED powered quickly to see signs of life.
There is something wrong here when non-LTO compiles are selected based on this limited test case. I changed the timing before the call { to setup() } to this ridiculous wait and it still will not function:
Code:
delay(50);
delay(350); // ADDED
delay(350); // ADDED
usb_init();
delay(350);
If compiled 'LTO' the TD_1.36 default timing on entry to setup I see is 410 ms or less on my system with a T_3.1. { and it works }
Looking a bit to see what AM2321 might do I find it does a Wire.begin() on creation.
I made these changes and it now starts up fine with 'smallest' or 'Faster' - so the trouble is that instantiating the object "ac" is hitting 'Wire.begin() badly?
Code:
AM2321 ac; //Uncomment to unblock
#include <Wire.h> // ADDED
void setup()
{
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
Serial.begin(115200); // USB is always 12 Mbit/sec
delay(100);
Wire.begin(); // ADDED
digitalWrite(led1, LOW);
Serial.println (F("=========MeteoStation 100ms =========")) ;
And in the library code I:\Code\libraries\AM2321\AM2321.cpp:
Code:
AM2321::AM2321() {
//Wire.begin(); // COMMENTED
temperature = 0;
humidity = 0;
}
NOTE: I also added this and it had No effect - even on the time of entry to setup()::
Code:
void startup_late_hook(void) {
delayMicroseconds(100000);
delayMicroseconds(100000);
delayMicroseconds(100000);
delayMicroseconds(100000);
}