How to set the RTC in a Program?

I’m trying to set the System time within a VB.net program:

    ''' <summary>
    ''' This sub should set the Systems DateTime.
    ''' </summary>
    ''' <param name="d">Actual DateTime</param>
    ''' <remarks></remarks>
    Private Sub setDateTime(ByVal d As DateTime)
        Try
            Microsoft.VisualBasic.TimeOfDay = d 'Your time...
            Microsoft.VisualBasic.DateString = New Date(d.Year, d.Month, d.Day) 'The date...
        Catch ex As Exception
            'You might have to run as Administrator...?
            MsgBox("Error Setting the Time." & ex.Message)
        End Try
    End Sub

It seems to work - the System DateTime is set (The Sytem Time is adjusted to the set Time). But the problem is, that the Time is lost after a PowerOnReset. Even if the Time was set properly before, after PowerOnReset the Time is reset to 12:00:33, 1.1.2006.

After a reboot, if i set the Time the “common” way, the Time is stored.
Can you give me a hint how to fix this issue?

Best regards, Stefan

Dear @Stefan.P

Let’s figure out whether it is a hardware- or a software issue:

You need a battery-backed RTC in order to keep the time through a power cycle. If you provide any details about the hardware you are using, I might be able to better guide you.

On the software side, it is the RtcSync.exe tool which is responsible to synchronize the system time with the battery-backed RTC. When the debug messages are activated, RtcSync.exe prints a message each time the time is read or written from/to the RTC.
Please enable the debug messages, and use either a serial port connection or the Debug Message Logger tool to monitor the debug messages. If you send me the complete debug log I will probably be able to tell you more about the reason of failure.

Regards, Andy

Dear @andy.tx ,

I use the Stock Ixora Board 1.0a.

Toradex Windows CE 7.0 2.1b2 for Tegra Built Aug  7 2017 15:55:47
INFO:OALLogSetZones: dpCurSettings.ulZoneMask: 0xb
L2 cache enabled
MainMemoryEndAddress adjusted from 0x86000000 to 0x9FE00000
Main Phys Mem: 0x80000000:0x9FDFFFFF
Carveout Phys: 0x9FE00000:0x9FFFFFFF
Cold boot selected
SMP: Active CPUs = 4
Extended Mem : 0xA0000000:0xFFEFFFFF
Chip Id: 0x30 (Handheld SOC) Major: 0x1 Minor: 0x3 SKU: 0xb1
NVRM Initialized shmoo database
PllClocks(Mhz): X=1300, M=800, C=600, P=408, A=24.576
SysClocks(Mhz): CPU=1300, AVP=240, SysBus=240, Mem=400, EMem=800
GraphicClocks(Mhz): Host=106, 3D=133, 2D=133, Epp=133, Mpe=133, Vde=408
Loading FlashFileSystem(eMMC)...
Done FlashFileSystem(eMMC)(0)
Loading Audio...Done
Loading Serial2(UART_B)...Done Serial2(0)
Loading Serial3(UART_C)...Done Serial3(0)
Loading Serial4(UART_D)...Done Serial4(0)
Loading SDIO(SDIO3)...Done(1004)
Loading SDIO(SDIO1)...NvDdkSdioSetClockFrequency: Requested: 100 KHz, Actual: 10                                                                                                                                                                        0 KHz
Done(1004)
Loading PCIe...PCIE: port 0: link down, aborting
                                                PCIE: port 1: link down, abortin                                                                                                                                                                        g
 PCIE: port 2: link up in 0 us
                              Done
Loading USBFunction(Port1)...Done
Bus:Device:Function: VendorID,DeviceID
0:0:0: 0x10de,0xe1c Virtual P2P to 1
0:1:0: 0x10de,0xe1d Virtual P2P to 2
0:2:0: 0x10de,0xe1d Virtual P2P to 3
3:0:0: 0x8086,0x157b
Loading I21x Ethernet...Done
Loading USBHost(Port2)...PCIe: Slot Clock Request Change (0x0)
Done
Loading USBHost(Port3)...Done
Loading DisplayDriver...Done(30)
Set LCD to 800x480 (59Hz)
Set HDMI to 800x480 (60Hz)
Set HDMI to 800x480 (60Hz)
Loading Keyboard/MouseDriver...Done
Loading TouchDriver...Maximum Allowed Error 5:
Done
RTC Time restored (11.02.2019 14:16:40)
Loading NETUI...
Done NETUI
...                                                                                                                                                         0 

If i start the sub from the topic with a short test, i get the following error:

Error while setting RTC time
Error while setting RTC time

After i opened the Systems “Date/Time Properties” i get this:

RTC Time set (11.02.2021 14:26:49)
RTC Time set (11.02.2021 14:26:58)
RTC Time set (11.02.2021 14:26:58)
RTC Time set (11.02.2021 14:27:03)
RTC Time set (11.02.2021 14:27:03)

with this code:

    Private Sub btnTimeTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimeTest.Click

        Dim myDateTime As New DateTime(2019, 2, 11, 17, 0, 0)
        setDateTime(myDateTime)

    End Sub

I get

I2cInit failed.

Error while setting RTC time
Error while setting RTC time

with this code (after Reset):

 Private Sub btnTimeTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimeTest.Click

        Dim myDateTime As DateTime = DateTime.Now
        'Dim myDateTime As New DateTime(2019, 2, 11, 17, 0, 0)
        setDateTime(myDateTime)

    End Sub

I get

RTC Time set (01.01.2006 11:00:17)
RTC Time set (01.01.2006 11:00:17)

Does the dateTime Object contain something which disturbs the RTC if not set?

Best regards, Stefan

Dear @Stefan.P,

We would like to suggest you use v2.2 release image from here: https://developer.toradex.com/software/windows-embedded-compact/t20-t30-wec-software and could you try your testing once again and let us know the result. Just watch the debug message log after every boot, you should get successful RTC Sync message all the times. If it is a success here then later on application triggering RTCSync also most probably will get success.

I have tested RTC sync on v2.2 image release and it is quite stable. May I know, is there any specific reason you want to us the only v2.1B2?

Dear @raja.tx , thank you for this hint.

Unfortunately the behaviour stays similar.

RTC Time set (12.03.2022 13:20:15)
Error while setting RTC time
I2cInit failed.
Error while setting RTC time
Error while setting RTC time

Here the new Boot Info:
Toradex Bootloader 2.2 for Tegra Built Dec 7 2018 15:05:43

Press [SPACE] to enter Bootloader Menu

Apalis T30 2GB 1.1A  Serial: 2712052
RAM: 2048 MB, CarveOut: 2 MB
Locating kernel image in flash...Done(621)
Decompressing IMAGE(26353307, 51248212) from FLASH(0) to RAM(80016000)...Done(471ms)
Jumping to image at 0x80016000...




Toradex Windows CE 7.0 2.2 for Tegra Built Dec  7 2018 15:05:21
INFO:OALLogSetZones: dpCurSettings.ulZoneMask: 0xb
L2 cache enabled
MainMemoryEndAddress adjusted from 0x9F000000 to 0x9FE00000
Main Phys Mem: 0x80000000:0x9FDFFFFF
Carveout Phys: 0x9FE00000:0x9FFFFFFF
Cold boot selected
SMP: Active CPUs = 4
Extended Mem : 0xA0000000:0xFFEFFFFF
Chip Id: 0x30 (Handheld SOC) Major: 0x1 Minor: 0x3 SKU: 0xb1
ATE prog ver 4.0
                Speedo: CPU: 379 (Corner: 3), Core: 219 (Corner: 0)
                                                                   NVRM Initialized shmoo database
PllClocks(Mhz): X=1300, M=800, C=600, P=408, A=24.576
SysClocks(Mhz): CPU=1300, AVP=240, SysBus=240, Mem=400, EMem=800
GraphicClocks(Mhz): Host=106, 3D=133, 2D=133, Epp=133, Mpe=133, Vde=408
Loading ResourceManager...
Done Loading ResourceManager (0 ms)
Loading FlashFileSystem(NAND)...
Failed(0) Loading FlashFileSystem(NAND) (0 ms)
Loading FlashFileSystem(eMMC)...
Done Loading FlashFileSystem(eMMC) (0 ms)
Loading MultimediaManager...
Done Loading MultimediaManager (1 ms)
Loading Audio...
Loading Serial3...
Loading Serial2...
Loading Serial1...
Done Loading Serial3 (2 ms)
Done Loading Serial2 (2 ms)
Failed(0) Loading Serial1 (2 ms)
Done Loading Audio (332 ms)
Loading SDIO...
Loading SDIO2...
Loading PCIe...Done Loading SDIO2 (6 ms)
Done Loading SDIO (8 ms)
NvDdkSdioSetClockFrequency: Requested: 100 KHz, Actual: 100 KHz
PCIE: port 0: link down, aborting
                                 PCIE: port 1: link down, aborting
                                                                  PCIE: port 2: link up in 0 us
                                                                                               Done
Bus:Device:Function: VendorID,DeviceID
0:0:0: 0x10de,0xe1c Virtual P2P to 1
0:1:0: 0x10de,0xe1d Virtual P2P to 2
0:2:0: 0x10de,0xe1d Virtual P2P to 3
3:0:0: 0x8086,0x157b
Loading I21x Ethernet...Done
Loading USBOTG(Port1)...
Loading USBHost(Port3)...
Loading USBHost(Port2)...
Done Loading USBOTG(Port1) (7 ms)
Loading DisplayDriver...
Done Loading DisplayDriver (31 ms)
Set LCD to 800x480 (59Hz)
Set CRT to 800x480 (60Hz)
Set CRT to 800x480 (60Hz)
VBUS=0, ID=0
ChangeMode(0, 2)
OTG(0): Loading HCD...
Loading USBHost(Port1)...
Loading Keyboard/MouseDriver...
Done Loading Keyboard/MouseDriver
Loading TouchDriver...
Maximum Allowed Error 5:
Done Loading TouchDriver
Done Loading USBHost(Port3) (147 ms)
RTC Time restored (07.00.2000 00:01:46)
Done Loading USBHost(Port2) (311 ms)
Done Loading USBHost(Port1) (344 ms)
OTG(0) Done Loading HCD
Loading NETUI...
Done NETUI
...

Is it possible, that there might be a problem if Date and Time change “at once”?

Regarding your Question: We already flashed and commissioned a lot of CPU Modules with v2.1B2. For Future CPU Modules we will use the 2.2 Release. A small side question: The Mobile Device Center will only work with USB OTG? So i need to USB On-The-Go | Toradex Developer Center

But [HKLM\Drivers\BuiltIn\USBEHCI1] does not exist? Can you maybe create a small *.reg file to switch to OTG Mode/Automatic detection?

Dear @Stefan.P,

RTCSync issue seems to be inconsistent. We need to narrow down the issue.
Did you connect any other I2c peripherals on the carrier board then the default ones?

Can you disable your application and just do power cycle the module for 10 times(with our standard release image and no other additional SW and HW) and verify all the times RTC Time restored is getting success? Also, log the debug message during this testing and share with us.

Could you please please share your application source code with build executable files and let me try to reproduce the issue with that.

The Mobile device center will work only on USB Functional(USB OTG) port. The registrey settings already there in our image that you can verify by using UVCView.exe. Run the UVCView.exe application and connect USB B to A to the PC and verify Microsoft USB Sync is popping up on the UVCView.exe tool.

If USB serial functional device is enumerating and only WMDC not connecting then check these links: https://www.toradex.cn/community/questions/10485/windows-mobile-device-center-windows-10-creators-u.html and https://support.waspbarcode.com/kb/articles/windows-10-fix-summary-for-windows-mobile-device-center-issues-win10fix.

Dear @raja.tx ,

We have additional 3 additional I2C devices connected to the I2C1 Bus.

Please find attached the Debug messages. I did the Test with “custom HW and SW”. It seems the Restoring works well every time.

Also attached is the Sourcecode and Executable (VB.net with VS 2008) It is a smaller Software. If it works here, it should also work in the original SW.

The Module (V2.2)(I tested 2) is not updating any entry in the UVCView.exe. Before the Update, and also other Modules with the V2.1… are detected and can connect via WMDC. In the Changeslog there is one entry which made me suspicious:

Best Regards, Stefan

Dear @Stefan.P,

I have tested your application with our hardware setup, it seems to be working always.

It may be the factor that due to additional 3 devices on the I2c bus, driver strength not enough to drive the bus.
Could you try strong pull up(1.8K or 1K) on the I2c bus?

Active sync: Do you have Ixora or Apalis Eval board, Could you try to test on that eval board and verify that Active sync is working.

I posted of that section code here:

if ( m_dwSWCableDetect!=-1) //If we force cable detect in the registry, disable CableDetect & ID Pin interrupts
            newMode = (USBOTG_MODE)m_dwSWCableDetect;
        else
        {
            if(ID == 0) // NOTE: Ignore VBUS
                newMode = USBOTG_Host;
            else if(VBUS == 1)
                newMode = USBOTG_Function;
            else
                newMode = USBOTG_mode_unknow;
        }

There is debug message for VBUS and ID state “VBUS=1, ID=1”, please verify what funtionality it sets in the dbg msg.

I hope this would have been helo you to debug the USB active sync issue.

Dear @raja.tx : Thank you for your support. Indeed it worked with other HW and if i added the Pullups…

This issue might be fixed If you add a Strong Pull-Up Resistor on the SDA and SCL Lines. Something in the Range of 2-5k should work.