• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    C
  • Created about 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Arduino RTC library for STM32.

STM32RTC

A RTC library for STM32.

Requirement

API

This library is based on the Arduino RTCZero library. The library allows to take control of the internal RTC of the STM32 boards.

Singleton design pattern is used to ensure that only one STM32RTC instance is instantiated:

/* Get the rtc object */
STM32RTC& rtc = STM32RTC::getInstance();

The following functions are not supported:

  • void standbyMode(): use the STM32 Low Power library instead.
  • uint8_t getAlarmMonth(): month not supported by STM32 RTC architecture.
  • uint8_t getAlarmYear(): year not supported by STM32 RTC architecture.
  • void setAlarmMonth(uint8_t month): month not supported by STM32 RTC architecture.
  • void setAlarmYear(uint8_t year): year not supported by STM32 RTC architecture.
  • void setAlarmDate(uint8_t day, uint8_t month, uint8_t year): month and year not supported by STM32 RTC architecture.

The following functions have been added to support specific STM32 RTC features:

RTC hours mode (12 or 24)

  • void begin(Hour_Format format)

RTC clock source

  • Source_Clock getClockSource(void) : get current clock source.
  • void setClockSource(Source_Clock source, uint32_t predivA, uint32_t predivS) : set the clock source (LSI_CLOCK, LSE_CLOCK or HSE_CLOCK) and (a)synchronous prescaler values. This function must be called before begin(). Use (PREDIVA_MAX + 1) and (PREDIVS_MAX +1) to reset value and use computed ones. Those values have to match the following conditions: 1Hz = RTC CLK source / ((predivA + 1) * (predivS + 1))

RTC Asynchronous and Synchronous prescaler

  • void getPrediv(uint32_t *predivA, uint32_t *predivS) : get (a)synchronous prescaler values if set else computed ones for the current clock source.
  • void setPrediv(uint32_t predivA, uint32_t predivS) : set (a)synchronous prescaler values. This function must be called before begin(). Use (PREDIVA_MAX + 1) and (PREDIVS_MAX +1) to reset value and use computed ones. Those values have to match the following conditions: 1Hz = RTC CLK source / ((predivA + 1) * (predivS + 1))

SubSeconds management

  • uint32_t getSubSeconds(void)
  • void setSubSeconds(uint32_t subSeconds)

Hour format (AM or PM)

  • uint8_t getHours(AM_PM *period = nullptr)
  • void setHours(uint8_t hours, AM_PM period = AM)
  • void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 1000, AM_PM period = AM)
  • void setAlarmHours(uint8_t hours, AM_PM period = AM)
  • uint8_t getAlarmHours(AM_PM *period)
  • void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, AM_PM period)

Week day configuration

  • uint8_t getWeekDay(void)
  • void setWeekDay(uint8_t weekDay)
  • void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year)

Time and date configuration (added for convenience)

  • void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period = nullptr)
  • void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)

Since STM32RTC version higher than 1.0.3

SubSeconds alarm management

Important note:

  • STM32F1 and STM32L1xx (Ultra Low Power Medium (ULPM) density) series do not support subsecond.
  • Subsecond โ€œresolutionโ€ depends on synchronous prescaler value. Bigger than this value is, better resolution will get for subsecond.
  • void setAlarmSubSeconds(uint32_t subSeconds)

  • Updated API:

    • void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 0, AM_PM period = AM)
    • uint32_t getEpoch(uint32_t *subSeconds = nullptr)
    • void setEpoch(uint32_t ts, uint32_t subSeconds = 0)
    • void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0)

Library version management

STM32 RTC library version is based on Semantic Versioning 2.0.0 (https://semver.org/)

This will ease some dependencies:

* `STM32_RTC_VERSION_MAJOR` -> major version
* `STM32_RTC_VERSION_MINOR` -> minor version
* `STM32_RTC_VERSION_PATCH` -> patch version
* `STM32_RTC_VERSION_EXTRA` -> Extra label
 with:
  - 0: official release
  - [1-9]: release candidate
  - F[0-9]: development

* `STM32_RTC_VERSION` --> Full version number

STM32_RTC_VERSION can de used to handle some API change:

#if defined(STM32_RTC_VERSION) && (STM32_RTC_VERSION  >= 0x01010000)
  rtc.setAlarmTime(alarmHours, alarmMinutes, alarmSeconds, 123);
#else
  rtc.setAlarmTime(alarmHours, alarmMinutes, alarmSeconds);
#endif

Since STM32RTC version higher than 1.1.1

One-Second interrupt

STM32 RTC includes a one-second interrupt for generating a periodic interrupt signal.

  • This feature is native on the stm32F1xx and mapped on the existing WakeUp interrupt on other stm32 mcus.
  • It is not available on some stm32F0 devices.
  • new API:
    • void attachSecondsInterrupt(voidFuncPtr callback)
    • void detachSecondsInterrupt(void)

Date retention for stm32F1xx

STM32 RTC includes date save/retrieve mechanism for the stm32F1xx mcu, that do not have a date counter.

The content is stored in BackUp memory which is kept during Reset and powered by Vbat when the Vdd is off.

Since STM32 Core version > 1.5.0

Reset time management

By default, if a time is set it will not be reset after a reboot.

Using begin(true) or begin(true, HOUR_24) will reset the RTC registers.

To know if a time has already been set use:

  • bool isTimeSet(void)
  if (!rtc.isTimeSet()) {
    // Set the time
    rtc.setHours(hours);
    rtc.setMinutes(minutes);
    rtc.setSeconds(seconds);
  }

Since STM32RTC version higher than 1.3.4

Second alarm (Alarm B)

Some STM32 RTC have a second alarm named RTC_ALARM_B. It is possible to use it thanks all alarm API with an extra argument:

  • STM32RTC::ALARM_A
  • STM32RTC::ALARM_B
    rtc.attachInterrupt(myCallback, &myCallbackdata, STM32RTC::ALARM_B);
    rtc.setAlarmDay(day, STM32RTC::ALARM_B);
    rtc.setAlarmTime(hours, minutes, seconds + 5, 567, STM32RTC::ALARM_B);
    rtc.enableAlarm(rtc.MATCH_DHHMMSS, STM32RTC::ALARM_B);

Since STM32RTC version higher than 1.3.7

Get the RTC handle

  • RTC_HandleTypeDef *RTC_GetHandle(void)

binary and mix modes

Some STM32 RTC have a binary mode with 32-bit free-running counter in addition to their BCD mode for calendar (for example stm32wl55). Combined with BCD this is the MIX mode. Only using the binary counter is the BIN mode. Three RTC functional modes are available:

  • STM32RTC::MODE_BCD
  • STM32RTC::MODE_MIX
  • STM32RTC::MODE_BIN
  • Binary_Mode getBinaryMode(void);
  • void setBinaryMode(Binary_Mode mode);

Any API using the Subsecond parameter is expressed in milliseconds whatever the RTC input clock. This parameter is [0..999] in MIX or BCD mode and [0..0xFFFFFFFF] in BIN mode. In BIN only mode, time and date registers are not used by the RTC. Thus the getEpoch function is only to be called to get the subsecond [0..0xFFFFFFFF] (returned time_t is not valid). The setAlarmEpoch only uses the sub-second [0..0xFFFFFFFF] (time_t value is useless).

SubSeconds underflow

Only dor STM32WLxx. Manage interrupt (SSRU) when SubSeconds register underflow. Used by STM32LoRaWAN.

  • void attachSubSecondsUnderflowInterrupt(voidFuncPtr callback);
  • void detachSubSecondsUnderflowInterrupt(void);

Refer to the Arduino RTC documentation for the other functions http://arduino.cc/en/Reference/RTC

Source

Source files available at: https://github.com/stm32duino/STM32RTC

More Repositories

1

Arduino_Core_STM32

STM32 core support for Arduino
C
2,742
star
2

STM32FreeRTOS

Real Time Operating System implemented for STM32
C
302
star
3

wiki

Wiki for all STM Arduino cores and tools
236
star
4

STM32LowPower

Arduino Low Power library for STM32
C
180
star
5

STM32Ethernet

Arduino library to support Ethernet for STM32 based board
C++
151
star
6

STM32SD

Enables reading and writing on SD card using SD card slot of the STM32 Board.
C
151
star
7

Arduino_Core_STM8

STM8 core support for Arduino
C
137
star
8

STM32Examples

Arduino library to provide several examples for the Arduino core for STM32 MCUs.
135
star
9

BoardManagerFiles

Storage for Arduino Board Manager JSON and package files etc
Makefile
101
star
10

LwIP

Lightweight TCP/IP stack (LwIP) is a small independent implementation of the TCP/IP protocol suite.
C
92
star
11

Arduino_Tools

Contains upload tools for STM32 based boards
C
86
star
12

FatFs

FatFs is a generic FAT file system module for small embedded systems. The FatFs is written in compliance with ANSI C and completely separated from the disk I/O layer. Therefore it is independent of hardware architecture.
C
81
star
13

ST25DV

Arduino library to support ST25DV components
C++
54
star
14

stm32flash

Open source flash program for STM32 using the ST serial bootloader (https://sourceforge.net/projects/stm32flash)
C
46
star
15

STM32LoRaWAN

Arduino library to support LoRaWAN communication using the STM32WL series.
C
35
star
16

LSM6DSL

Arduino library to support the LSM6DSL 3D accelerometer and 3D gyroscope
C
29
star
17

LSM6DSOX

Arduino library to support the LSM6DSOX 3D accelerometer and 3D gyroscope
C
27
star
18

LSM6DS3

Arduino library to support the LSM6DS3 3D accelerometer and 3D gyroscope
C
20
star
19

VL53L3CX

Arduino library to support the VL53L3CX Time-of-Flight ranging sensor with multi target detection
C++
18
star
20

X-NUCLEO-NFC03A1

Arduino library to support NFC card reader expansion board based on ST25R95
17
star
21

VL53L0X

Arduino library to support the VL53L0X Time-of-Flight and gesture-detection sensor
C++
16
star
22

LSM6DSO

Arduino library to support the LSM6DSO 3D accelerometer and 3D gyroscope
C
15
star
23

I-NUCLEO-LRWAN1

Arduino library to support I-NUCLEO-LRWAN1 LoRaยฎ expansion board based on USIยฎ LoRaWANโ„ข technology module.
C
14
star
24

M24SR64-Y

Arduino library to support the dynamic NFC/RFID Tag IC dual interface M24SR64-Y
C++
14
star
25

VL53L1X

Arduino library to support the VL53L1X Time-of-Flight and gesture-detection sensor
C++
14
star
26

VL53L5CX

Arduino library to support the VL53L5CX Time-of-Flight 8x8 multizone ranging sensor with wide field of view
C
14
star
27

SPBTLE-RF

Arduino library to support the Bluetooth (V4.1 compliant) SPBTLE-RF module
C
11
star
28

MX25R6435F

Arduino library to support the Quad-SPI NOR Flash memory MX25R6435F
C
11
star
29

LIS2DW12

Arduino library to support the LIS2DW12 3D accelerometer
C
10
star
30

Proximity_Gesture

Gesture library for proximity sensors
C
10
star
31

S2-LP

Arduino library to support S2-LP sub-1GHz transceiver
C++
10
star
32

X-NUCLEO-IKS01A3

Arduino library to support motion MEMS and environmental sensor expansion board
10
star
33

arm-none-eabi-gcc

The GNU Arm Embedded Toolchain binaries used by STM32duino cores
Makefile
10
star
34

VL53L7CX

Arduino library to support the VL53L7CX Time-of-Flight 8x8 multizone ranging sensor with 90 degrees FoV
C
10
star
35

VL53L8CX

Arduino library to support the VL53L8CX low-power high-performance 8x8 multizone Time-of-Flight sensor (ToF)
C
9
star
36

X-NUCLEO-53L1A1

Arduino library to support the X-NUCLEO-53L1A1 based on VL53L1X Time-of-Flight and gesture-detection sensor
C++
9
star
37

VL53L1

Arduino library to support the VL53L1 Time-of-Flight ranging sensor with advanced multi-zone and multi-object detection
C++
9
star
38

NFC-RFAL

Arduino library for the RF/NFC abstraction layer (RFAL)
C++
8
star
39

VL53L4CD

Arduino library to support the VL53L4CD Time-of-Flight high accuracy proximity sensor
C++
7
star
40

ASM330LHH

Arduino library to support the ASM330LHH automotive 3D accelerometer and 3D gyroscope
C
7
star
41

LSM6DSR

Arduino library to support the LSM6DSR 3D accelerometer and 3D gyroscope
C
7
star
42

ST25R3911B

Arduino library that provides an implementation of the NFC RFAL for ST25R3911B component
C++
7
star
43

ST25R3916

Arduino library that provides an implementation of the NFC RFAL for ST25R3916 component
C++
7
star
44

CMake_workspace

CMake
7
star
45

LPS22HB

Arduino library to support the LPS22HB 260-1260 hPa absolute digital ouput barometer
C
7
star
46

X-NUCLEO-GNSS1A1

Arduino library to support the X-NUCLEO-GNSS1A1 based on the Teseo-LIV3F module
C++
7
star
47

LIS3MDL

Arduino library to support the LIS3MDL high-performance 3-axis magnetometer
C
7
star
48

FP_Examples

Function Pack software: Examples that combine the usage of multiple X-NUCLEO boards
6
star
49

VL53L4CX

Arduino library to support the VL53L4CX Time-of-Flight high accuracy ranging sensor with multi target detection
C++
6
star
50

LSM6DS0

Arduino library to support the LSM6DS0 3D accelerometer and 3D gyroscope
C
6
star
51

ISM330DHCX

Arduino library to support the ISM330DHCX 3D accelerometer and 3D gyroscope
C
6
star
52

WiFi-ISM43362-M3G-L44

Arduino library to support the Wi-Fi module Inventek ISM43362-M3G-L44 (802.11 b/g/n)
C++
5
star
53

X-NUCLEO-IKS01A2

Arduino library to support motion MEMS and environmental sensor expansion board
5
star
54

MotionFX

Sensor Fusion Library for ST sensors and microcontrollers
C
5
star
55

X-NUCLEO-NFC04A1

Arduino library to support X-NUCLEO-NFC04A1 based on the dynamic NFC/RFID Tag IC ST25DV04K
C++
5
star
56

X-NUCLEO-IKS01A1

Arduino library to support motion MEMS and environmental sensor expansion board
5
star
57

HTS221

Arduino library to support the HTS221 capacitive digital sensor for relative humidity and temperature
C
5
star
58

LSM6DSV16X

Arduino library to support the LSM6DSV16X 3D accelerometer and 3D gyroscope
C
5
star
59

ST25R95

Arduino library that provides an implementation of the NFC RFAL for ST25R95 component
C++
4
star
60

X-NUCLEO-NFC05A1

Arduino library to support NFC card reader expansion board based on ST25R3911B
4
star
61

IIS2MDC

Arduino library to support the IIS2MDC high-performance 3-axis magnetometer
C
4
star
62

X-NUCLEO-IKS02A1-Audio

X-NUCLEO-IKS02A1 audio library to support IMP34DT05 MEMS digital omnidirectional microphone
C++
4
star
63

LSM303AGR

Arduino library to support the LSM303AGR 3D accelerometer and 3D magnetometer
C
4
star
64

VL6180

Arduino library to support the VL6180 Time-of-Flight ranging sensor
C++
4
star
65

X-NUCLEO-IDB05A1

Arduino library to support the X-NUCLEO-IDB05A1 based on Bluetooth (V4.1 compliant) SPBTLE-RF module
4
star
66

X-NUCLEO-NFC06A1

Arduino library to support NFC card reader expansion board based on ST25R3916
4
star
67

Python-Wave-Serial-Encoder

Python application to save a wave audio track through serial port
Python
4
star
68

LPS22HH

Arduino library to support the LPS22HH 260-1260 hPa absolute digital ouput barometer
C
3
star
69

STTS751

Arduino library to support the STTS751 digital temperature sensor
C
3
star
70

VL6180X

Arduino library to support the VL6180X Time-of-Flight and gesture-detection sensor
C++
3
star
71

X-NUCLEO-IHM02A1

Arduino library to support the two axis stepper motor driver based on L6470 component
C++
3
star
72

X-NUCLEO-6180XA1

Arduino library to support the X-NUCLEO-6180XA1 based on VL6180X Time-of-Flight and gesture-detection sensor
C++
3
star
73

X-NUCLEO-53L0A1

Arduino library to support the X-NUCLEO-53L0A1 based on VL53L0X Time-of-Flight and gesture-detection sensor
C++
3
star
74

LIS3DHH

Arduino library to support the LIS3DHH 3D accelerometer
C
2
star
75

LPS25HB

Arduino library to support the LPS25HB 260-1260 hPa absolute digital ouput barometer
C
2
star
76

ISM330DLC

Arduino library to support the ISM330DLC 3D accelerometer and 3D gyroscope
C
2
star
77

X-NUCLEO-IHM12A1

Arduino library to support dual brush DC motor driver based on STSPIN240 component
C++
2
star
78

M95640-R

Arduino library to support M95640-R SPI EEPROM
C++
2
star
79

X-NUCLEO-IKS4A1

Arduino library to support motion MEMS and environmental sensor expansion board
2
star
80

LPS22DF

Arduino library to support the LPS22DF 260-1260 hPa absolute digital ouput barometer
C
1
star
81

X-NUCLEO-53L8A1

Arduino library to support the X-NUCLEO-53L8A1 based on VL53L8CX low-power high-performance 8x8 multizone Time-of-Flight sensor (ToF)
1
star
82

USBMicrophone

Arduino library to support a simple USB Audio class for microphone for STM32 boards
1
star
83

LIS2DUXS12

Arduino library to support the LIS2DUXS12 3D ultralow-power accelerometer with QVAR and AI
C
1
star
84

Arduino_Tools_STM8

Contains upload tools for STM8 based boards (Windows only)
C
1
star
85

X-NUCLEO-53L7A1

Arduino library to support the X-NUCLEO-53L7A1 based on VL53L7CX Time-of-Flight 8x8 multizone ranging sensor with 90 degrees FoV
1
star
86

STEVAL-MKBOXPRO-Examples

Examples for STEVAL-MKBOXPRO board
1
star
87

SHT40-AD1B

Arduino library to support the SHT40-AD1B digital humidity and temperature sensor
C++
1
star
88

VL53L4ED

Arduino library to support the VL53L4ED Time-of-Flight high accuracy proximity sensor
C++
1
star
89

VL53L7CH

Arduino library to support the VL53L7CH artificial intelligence enabler, Time-of-Flight (ToF) 8x8 multizone sensor with 90 degrees FoV
C
1
star
90

MP34DT01

Arduino library to support MP32DT01 digital omnidirectionnal microphones
1
star
91

X-NUCLEO-IKS02A1

Arduino library to support industrial motion MEMS sensor expansion board
1
star
92

X-NUCLEO-53L1A2

Arduino library to support the X-NUCLEO-53L1A2 based on VL53L1 Time-of-Flight ranging sensor with advanced multi object detection
C++
1
star
93

LSM6DSO16IS

Arduino library to support the LSM6DSO16IS 3D accelerometer and 3D gyroscope with ISPU
C
1
star
94

actions

A set of GitHub Actions for STM32duino GitHub organization
Shell
1
star
95

X-NUCLEO-53L5A1

Arduino library to support the X-NUCLEO-53L5A1 based on VL53L5CX Time-of-Flight 8x8 multizone ranging sensor with wide field of view
1
star
96

LSM6DSOSensorHub

Arduino library to support LSM6DSO Sensor Hub feature
C++
1
star
97

X-NUCLEO-NFC01A1

Arduino library to support X-NUCLEO-NFC01A1 based on the dynamic NFC/RFID Tag IC dual interface M24SR64-Y
1
star
98

.github

1
star
99

X-NUCLEO-IHM01A1

Arduino library to support a stepper motor driver based on L6474 component
C++
1
star
100

LIS2MDL

Arduino library to support the LIS2MDL high-performance 3-axis magnetometer
C
1
star