How to create __rtc_localfile in makefile?

Status
Not open for further replies.

WMXZ

Well-known member
The new teensy firmware uses __rtc_localtime to initialize the RTC, which is said to be generated by the arduino IDE.

I'm using a makefile. Paul's example makefile has for this the loader instruction "--defsym=__rtc_localtime=0 "

OK zero local time is not very helpful.
Is there any way to generate the right numbers of seconds from system time when running the loader to calculate ?

__DATE__ and __TIME__ is not helpful as this is only set when file, where it is used, is compiled.
and using an external program to estimate the number of seconds is a little bit cumbersome.

I'm using Windows 10.
 
I don't think 'that means what you think it means:: "--defsym=__rtc_localtime=0 " ... see below.

When I ran this posted sketch through IDE, the compiler pushed a value through compile that would set the clock to the compile time.
Teensy-3-2-RTC-time-sync-frustration

If you do that with the IDE and have verbose on it shows the cmdline switch makes it work::

I just ran it and get this Serial output (time is right - why the Comm error I don't know - that looks new?):
Comple Time=16:14:35, Date=Mar 25 2016
DS1307 Communication Error :-{
Please check your circuitry

I find this "--defsym=__rtc_localtime=1458922471" on line 107 of my verbose:
"I:\Teensy168\hardware\teensy/../tools/arm/bin/arm-none-eabi-gcc" -Os -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=1458922471 "-TI:\Teensy168\hardware\teensy\avr\cores\teensy3/mk20dx256.ld" --specs=nano.specs -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -o "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp/T_SetTime.ino.elf" "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp\sketch\T_SetTime.ino.cpp.o" "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp\libraries\Wire\Wire.cpp.o" "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp\libraries\Wire\utility\twi.c.o" "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp\libraries\Time\DateStrings.cpp.o" "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp\libraries\Time\Time.cpp.o" "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp\libraries\DS1307RTC\DS1307RTC.cpp.o" "C:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp/core\core.a" "-LC:\Users\Tim\AppData\Local\Temp\build08499a023840cffff6d6cd0fb951ee47.tmp" -larm_cortexM4l_math -lm
 
This only ever gets used if you've added the 32.768 kHz RTC crystal, and even then, only if the RTC is found to be uninitialized (first use after VBAT without power).

If you *really* want to do this without Arduino, well, you're going to have some work to do. This is one of many little things Arduino can do which Makefiles can't. Or can't on their own. You'll have to run a script or command line program which can do it.

For example, on Linux the "date" command can do it. Here's a makefile:

Code:
TS = $(shell date +%s)

all:
	echo $(TS)

I'm pretty sure Microsoft's "date" command doesn't support this syntax. Or maybe it does? If you have Perl or Python, I'm sure a trivial script could do this.
 
Paul - just trying this the Teensy_3.2 I had handy - WITH CRYSTAL - was the one with the PROP SHIELD on.

I keep getting:
Comple Time=17:47:33, Date=Mar 25 2016
DS1307 Communication Error :-{
Please check your circuitry

... - I popped the shield off - and then I get no Serial output. This is using the Sketch from link in Post #2 above.

I'm going to try to see if I can change it - but the error is odd.

Interesting to know Arduino is feeding the TIME through the build. BTW: I looked the other week and I did not come across a way to have Windows "date or time" to give the UTC time directly - except PowerShell.

I did find these notes:
rem display system time and date
time /t
date /t

rem http://stackoverflow.com/questions/9871499/how-to-get-utc-time-with-windows-batch-file

rem This will set the variables Day, DayofWeek, Hour, Minute, Month, Quarter, Second, WeekInMonth and Year which you can use, then.
for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do set %%x

rem Unix epoch from Windows ... If you have PowerShell you can use
powershell [long]((date).touniversaltime()-[datetime]'1970-01-01').totalmilliseconds

rem ports of common GNU utilities to native Win32
rem https://sourceforge.net/projects/unxutils/

<edit> UPDATE: I wasn't running the sketch I thought I was, I still don't know why the Serial output goes DEAD when the PROP Shield is removed?

But the error is another issue . . .
 
Last edited:
This only ever gets used if you've added the 32.768 kHz RTC crystal, and even then, only if the RTC is found to be uninitialized (first use after VBAT without power).
That is what I deduced from the start-up code and yes I have a RTC xtal
If you *really* want to do this without Arduino, well, you're going to have some work to do. This is one of many little things Arduino can do which Makefiles can't. Or can't on their own. You'll have to run a script or command line program which can do it.
if there are no Makefile tricks I will have to do so.

For example, on Linux the "date" command can do it. Here's a makefile:

Code:
TS = $(shell date +%s)

all:
	echo $(TS)

I'm pretty sure Microsoft's "date" command doesn't support this syntax. Or maybe it does? If you have Perl or Python, I'm sure a trivial script could do this.

and under Windows
Code:
TS= $(shell echo %date%_%time%)
default:  
	@echo $(TS)
gives me a complete timestamp in my gnu make windows environment

Now I only have to find/create and a script that returns me the seconds I needed for __rtc_localtime.
(I have not used perl for ages, but maybe python has some build-in time functions)

Edit:
using python
the following makefile gives me a seconds based timestap
Code:
pyCmd = $(shell python -c '$1')
TS:=$(call pyCmd,import time; print "%d" % time.time())
default:  
	@echo $(TS)

Edit 2:
adding a phony target to the link stage, forces the link to be executed all the time with the update time stamp.

OK, problem solved

Edit 3:
time is in GMT, which is fine for me.
 
Last edited:
Status
Not open for further replies.
Back
Top