Using the Real-Time Clock

The STM32 microcontroller on Mountaineer boards support real-time clocks. Starting with release 4.3 of NETMF for STM32, this feature can be enabled. There are two ways in which the real-time clock (RTC) can be used:

  1. Set the clock whenever the board is powered up or rebooted, e.g., by fetching the time from an Internet server
  2. Set the clock once and make sure that the microcontroller remains sufficiently powered for the RTC circuit to run forever (even if the microcontroller is not powered)

Variant 1: Set the RTC after booting

If you have an Ethernet Mountaineer Mainboard with an Internet connection, you can enable NTP (network time protocol) after booting. Using the NTP protocol, you can retrieve the current time from a time server, and set the RTC accordingly. How to do this is shown in this sample program:

NtpTest sample program
Compressed Archive in ZIP Format 831 Bytes

Variant 2: Power the RTC

Both for the USB and the Ethernet mainboard, you can provide a hardware extension that powers the RTC built into the STM32 microcontroller, even when the microcontroller and the attached modules are not powered. You could provide a battery, but even if you only use a capacitor, it can keep the RTC running for more than a week. There is a special microcontroller pin that needs to be powered with 1.65 to 3.6 Volt, and only consumes a tiny amount of power (about 3 uA). The circuit that you need looks like this: