Time compilation for setting clock

Davidelvig

Well-known member
I'm struggling to craft a search string for this, so please forgive if this has been answered.

For a new Teensy (4.1 in my case - and 3.2 until recently) that has not has an RTC connected or powered, I'll like to detect that the clock is not set with a call to timeStatus() in timeLib.h.

If not set (timeNotSet) I'd like to use the compile dateTime.

What's that macro?
 
When first programmed the Teensy will automatically have the Compile/Date time.
If you wish to get that date/time on subsequent powering of the Teensy you can use the code below:
Code:
    Serial.print("Compile: Date "); Serial.print(__DATE__); Serial.print("  Time ");  Serial.println(__TIME__);
 
IIRC::
Teensy 3.x before 4.x put the time in the hex when building and that would be used to set on starting if 'not set' - even days later.
For T_4.x the better usable solution was to have the Loader Teensy.exe pass the time during programming - that is accurate to time of upload - but volatile and lost if not kept powered.

As p#2 notes the sketch can capture build time/date - and for T_4.x as p#4 notes when RTC is detected as not set then it will default 1/1/19
 
For T_4.x the better usable solution was to have the Loader Teensy.exe pass the time during programming - that is accurate to time of upload - but volatile and lost if not kept powered.
@defragster,
When I flash the board in the Arduino IDE, it sets the time to essentially now (?build time)
Not when flashing in PlatformIO

Here are the last lines of a verbose output after build and upload in PlatformIO
Building in release mode
arm-none-eabi-g++ -o .pio/build/db_hardware_v2d/firmware.elf -T imxrt1062_t41.ld -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m7 -Wl,--defsym=__rtc_localtime=1703102898 -mfloat-abi=hard -mfpu=fpv5-d16 -O2 .pio/build/db_hardware_v2d/src/main.cpp.o .pio/build/db_hardware_v2d/src/name.c.o -L/Users/davidelvig/.platformio/packages/framework-arduinoteensy/cores/teensy4 -L.pio/build/db_hardware_v2d -Wl,--start-group .pio/build/db_hardware_v2d/lib96c/libTeensyID.a .pio/build/db_hardware_v2d/lib697/libSPI.a .pio/build/db_hardware_v2d/libd56/libWire.a ".pio/build/db_hardware_v2d/lib856/libSparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library.a" ".pio/build/db_hardware_v2d/lib686/libAdafruit BusIO.a" ".pio/build/db_hardware_v2d/libfef/libAdafruit GFX Library.a" ".pio/build/db_hardware_v2d/lib14a/libAdafruit ST7735 and ST7789 Library.a" .pio/build/db_hardware_v2d/lib82e/libRunningMedian.a .pio/build/db_hardware_v2d/libc72/libMadgwick.a ".pio/build/db_hardware_v2d/lib460/libMIDI Library.a" ".pio/build/db_hardware_v2d/libfcb/libRTC RV-3028-C7 Arduino Library.a" .pio/build/db_hardware_v2d/lib4c5/libSerialFlash.a .pio/build/db_hardware_v2d/lib026/libSdFat.a .pio/build/db_hardware_v2d/libed9/libSD.a .pio/build/db_hardware_v2d/libd9c/libAudio.a .pio/build/db_hardware_v2d/lib6e5/libdbUtility.a .pio/build/db_hardware_v2d/lib7b5/libdbMIDI.a .pio/build/db_hardware_v2d/libbf0/libdbSTEMLibs.a .pio/build/db_hardware_v2d/libf1f/libdbMessageTypes.a .pio/build/db_hardware_v2d/lib0e1/libFastTouch.a .pio/build/db_hardware_v2d/lib91d/libEEPROM.a .pio/build/db_hardware_v2d/liba68/libTime.a .pio/build/db_hardware_v2d/lib766/libdbLibs.a .pio/build/db_hardware_v2d/libFrameworkArduino.a -larm_cortexM7lfsp_math -lm -lstdc++ -Wl,--end-group
MethodWrapper(["checkprogsize"], [".pio/build/db_hardware_v2d/firmware.elf"])
arm-none-eabi-objcopy -O ihex -R .eeprom .pio/build/db_hardware_v2d/firmware.elf .pio/build/db_hardware_v2d/firmware.hex
<lambda>(["upload"], [".pio/build/db_hardware_v2d/firmware.hex"])
AVAILABLE: jlink, teensy-cli, teensy-gui
CURRENT: upload_protocol = teensy-gui
teensy_post_compile -file=firmware -path="/Users/davidelvig/Desktop/DesktopSrc/Master/Tilt/.pio/build/db_hardware_v2d" -tools=/Users/davidelvig/.platformio/packages/tool-teensy -board=TEENSY41 -reboot
============================================================================================= [SUCCESS] Took 4.33 seconds =============================================================================================
Do I need to adjust the CURRENT line above to use teensy-cli? and maybe add a parameter to send the time?
I'm not finding documentation at this level.

Thanks!
 
@defragster,
When I flash the board in the Arduino IDE, it sets the time to essentially now (?build time)
Not when flashing in PlatformIO
...
Not sure about PIO - but when Arduino with upload by 'Teensy.exe' does it the time of upload it set.
Perhaps the cli version doesn't include that step?
 
Back
Top