External RTC doesn't keep time and date

Hello,
I am using Colibri T20 and the external battery backed RTC (M41T83ZMY6F) is not working.
I change the time and date and when I reboot the Colibri it goes back to the original preset date which is in 2009 and a random time.
I am not sure where the problem is. How can I fix this ?

Thanks

Dear @shiva_eghbal

The M41T83 is not in the list of supported RTCs. It requires a different algorithm for reading and writing the time and date over i2c.

You can verify if the registers are compatible with one of the other RTCs in the list. In this case you only need to adjust the registry settings to make the RTC work.
If it is not supported, you need to implement your own code (typicall you would use our i2c library for this) to read and write date and time.
Once you manage to read and write date/time, we can provide you with supporting code which covers the surrounding algorithms in RtcSync.

I recommend you also activate and monitor the debug messages. There you should see reports whenever the system tries to read or write the RTC.

Regards, Andy

Hello,

I am using a source code that was previously developed by another company for our machines.
The code was used with PXA270 and RTC was working.
I am now upgrading the custom board and the processor to T20.
There is already an I2C library file in the release folder of Toradex_CE800 (ARMV7).
So they must have implemented the code to read/write time and date.
Can you guide me what I should do with the code now ?

Thanks

Dear @shiva_eghbal

Please refer to this post about RtcSync. It contains a customizable version of the RtcSync tool, along with instructions how to use it.

The basic concept is as follows:
There is a binary part of RtcSync, which is constant and hardware independent. The hardware-specific i2c accesses are all inside a DLL.

Your task is to write a DLL which exports only 2 functions:

  • SetRealTime()
  • GetRealTime()

Based on the example in the linked post, and the source code you already have, this should be rather easy.

Best Regards
Andy

Hi
Could you please explain more about how I need to do this?
I downloaded the customRTCDll file that has the source code and header file.
I cannot open the vcproj.
I created a new DLL Win32 console application and added the .cpp and .h codes from customRTCDll.
I added the I2CLib header file and library file.
Now I try to build it, but it gives me the following error:

dllmain.cpp(8) : error C2731: 'DllMain' : function cannot be overloaded
1>        .\dllmain.cpp(4) : see declaration of 'DllMain'

Am I on the right path ?
How can i fix this error?
Thanks

Dear @shiva_eghbal
According to the error message you try to link two object files together which both contain a DllMain() function.
Anyway, here’s the process I recommend:

  • Download our Toradex CE libraries
  • Download the CustomRtcSync_1_3644.zip (which you already have)
  • Extract the CustomRtcSync into a subfolder of ....\Toradex CE Libraries\LibDemos\ so the project file will end up at ....\Toradex CE Libraries\LibDemos\CustomRtcSync\CustomRTCSyncDll\CustomRTCSyncDll.vcproj
    The directory depth below the Toradex CE Libraries folder is important, otherwise the property sheets (*.vsprops) are not found.
  • Open the vcproj file in VS2008
  • Build the project

This worked flawlessly for me.

Regards, Andy

Hi Andy,
I did that and the project runs and builds successfully now.
As I build it on debug mode it created the application and on release mode it made .dll file.
To export the set and get functions, do I need to add the following to the .cpp file within this project ?

__declspec(dllexport) SetRealTime()
__declspec(dllexport) GetRealTime()

Thanks

There’s two options to make the two functions in the DLL visible to external applications:

  1. Either you insert the __declspec(dllexport) statements into your source code, or
  2. Add a .def file to your project and list the function names there.

You can use the PEInfo tool to verify that SetRealTime() and GetRealTime() are listed in the Exports section of the DLL.

Regards, Andy

Thanks Andy.
I did it and found the 2 functions in export section of PEInfo.
I put CustomRTCSync.exe and CustomRTCSyncDll.Dll in Flashdisk\system and set Launch48 in registry to CustomRTCSync.exe.
Now instead of 01/05/2009 which was the date I used to get at reboot, I get 02/02/2018.
I tried changing and saving it few times, but it goes back to it after booting.
How can I set it to today’s date and current time?

Thanks

Dear @shiva_eghbal
Please activate debug messages.
During booting, you should see a debug message like

RTC Time restored (26.04.2018 13:43:23)

After you set the time through the system tray applet and press [Apply], you should see a debug message like

RTC Time set (26.04.2018 14:43:33)

If the reported times are identical to the one shown in the system tray, you should debug your functions SetRealTime() and/or GetRealTime(). Make sure you write and read your RTC’s registers correctly.

Regards, Andy

Hello,
I followed the link and entered the bootloader using Tera Term. I typed X

set dbg.serial = 1         // 0: disable, 1: enable 
save dbg

and restarted the system. All I got is the messages in the image attached.
933-bootloader.png
Where should I look for the debug messages?

Hi @shiva_eghbal

There’s two issues:

  1. You should not enter the comment //0: disable, 1: enable
  2. The screenshot shows that you entered a different command than what you describe.

Simply try this:

set dbg.serial=1
save dbg
set dbg

The last command is to verify that the value has actually been modified to 1.

Regards, Andy

Hello I get: RTC Time restored (22.02.2022 22:56:35) But when I set the time on the system and press Apply, I don’t get any debug message! I tried saving the registry as well, but I don’t get any more messages. ![alt text][1]

What should I do? [1]: /community/storage/temp/936-debugmessages.png

Dear @shiva_eghbal

Your attached picture seems lost. I’m not sure whether there was important information in it.

However, you need to debug your code:
For debugging, open your DLL in VS2008, set
Project Properties → Debug → Remote Executable to RtcSync.exe and
the command line parameter to AppRunAfterTimeChange (case sensitive!).

The latter will tell RtcSync to write the current system time back to the RTC.
Set a breakpoint in the SetRealTime() and start debugging.

Regards, Andy

Hello @andy.tx
I did this and I get the following messages:

Load module: rtcsync.exe
Load module: fpcrt.dll
Load module: coredll.dll
RTC Time set (02.02.2018 07:01:16)
The program '[0x7FD030E] rtcsync.exe' has exited with code 1 (0x1).

Just to confirm, I didn’t modify the codes in the CustomRTCSync as they already included .def with:

EXPORTS
        SetRealTime
		GetRealTime

and header file with :

#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
 
extern "C"
{
   DECLDIR SetRealTime();
   DECLDIR GetRealTime();
}

Is that enough?

Thanks

Dear @shiva_eghbal
That should be enough. I can’t see why the program does not stop at the breakpoint. Can you ZIP your whole project and add it here? That’s probably the easiest way to find any wrong setting.
Regards, Andy

Hi Andy
The project I have been working with is attached.
link text
Thanks

Hi @shiva_eghbal
There were some errors in the project configuration. I fixed the template you originally downloaded in the related post. The modified files are:

  • CustomRTCSyncDll.c
  • CustomRTCSyncDll.vcproj

Please download the project again and replace these files in your project setup.
Regards, Andy

Thanks for all the help Andy.
With the new files it has been working. It has kept the correct time and date since yesterday.