{"id":23744845,"url":"https://github.com/stm32duino/stm32rtc","last_synced_at":"2025-10-26T07:06:04.480Z","repository":{"id":27486818,"uuid":"108381739","full_name":"stm32duino/STM32RTC","owner":"stm32duino","description":"Arduino RTC library for STM32.","archived":false,"fork":false,"pushed_at":"2025-03-12T14:59:38.000Z","size":162,"stargazers_count":142,"open_issues_count":0,"forks_count":51,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-03-28T23:08:17.405Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stm32duino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-26T08:15:56.000Z","updated_at":"2025-03-26T02:08:40.000Z","dependencies_parsed_at":"2023-02-14T09:00:57.771Z","dependency_job_id":"2d0b60e1-f8ba-483e-b17d-ff9c6b9ce60c","html_url":"https://github.com/stm32duino/STM32RTC","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stm32duino%2FSTM32RTC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stm32duino%2FSTM32RTC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stm32duino%2FSTM32RTC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stm32duino%2FSTM32RTC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stm32duino","download_url":"https://codeload.github.com/stm32duino/STM32RTC/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266564,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-31T12:50:04.845Z","updated_at":"2025-10-26T07:05:59.437Z","avatar_url":"https://github.com/stm32duino.png","language":"C","readme":"# STM32RTC\nA RTC library for STM32.\n\n## Requirement\n* [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32) version \u003e= 1.3.0\n\n# API\n\nThis library is based on the Arduino RTCZero library.\nThe library allows to take control of the internal RTC of the STM32 boards.\n\nSingleton design pattern is used to ensure that only one STM32RTC instance is instantiated:\n```C++\n/* Get the rtc object */\nSTM32RTC\u0026 rtc = STM32RTC::getInstance();\n```\n\nThe following functions are not supported:\n\n* **`void standbyMode()`**: use the STM32 Low Power library instead.\n* **`uint8_t getAlarmMonth()`**: month not supported by STM32 RTC architecture.\n* **`uint8_t getAlarmYear()`**: year not supported by STM32 RTC architecture.\n* **`void setAlarmMonth(uint8_t month)`**: month not supported by STM32 RTC architecture.\n* **`void setAlarmYear(uint8_t year)`**: year not supported by STM32 RTC architecture.\n* **`void setAlarmDate(uint8_t day, uint8_t month, uint8_t year)`**: month and year not supported by STM32 RTC architecture.\n\nThe following functions have been added to support specific STM32 RTC features:\n\n_RTC hours mode (12 or 24)_\n* **`void begin(Hour_Format format)`**\n\n_RTC clock source_\n* **`Source_Clock getClockSource(void)`** : get current clock source.\n* **`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))_**\n\n_RTC Asynchronous and Synchronous prescaler_\n* **`void getPrediv(uint32_t *predivA, uint32_t *predivS)`** : get (a)synchronous prescaler values if set else computed ones for the current clock source.\n* **`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))_**\n\n_SubSeconds management_\n* **`uint32_t getSubSeconds(void)`**\n* **`void setSubSeconds(uint32_t subSeconds)`**\n\n_Hour format (AM or PM)_\n* **`uint8_t getHours(AM_PM *period = nullptr)`**\n* **`void setHours(uint8_t hours, AM_PM period = AM)`**\n* **`void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 1000, AM_PM period = AM)`**\n* **`void setAlarmHours(uint8_t hours, AM_PM period = AM)`**\n* **`uint8_t getAlarmHours(AM_PM *period)`**\n* **`void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, AM_PM period)`**\n\n_Week day configuration_\n* **`uint8_t getWeekDay(void)`**\n* **`void setWeekDay(uint8_t weekDay)`**\n* **`void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year)`**\n\n_Time and date configuration (added for convenience)_\n* **`void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period = nullptr)`**\n* **`void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)`**\n\n### Since STM32RTC version higher than 1.0.3\n\n_SubSeconds alarm management_\n\n  Important note:\n  - STM32F1 and STM32L1xx (Ultra Low Power Medium (ULPM) density) series do not support subsecond.\n  - Subsecond “resolution” depends on synchronous prescaler value. Bigger than this value is, better resolution will get for subsecond.\n\n  * **`void setAlarmSubSeconds(uint32_t subSeconds)`**\n\n  * **Updated API:**\n    * **`void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 0, AM_PM period = AM)`**\n    * **`uint32_t getEpoch(uint32_t *subSeconds = nullptr)`**\n    * **`void setEpoch(uint32_t ts, uint32_t subSeconds = 0)`**\n    * **`void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0)`**\n\n_Library version management_\n\n  STM32 RTC library version is based on Semantic Versioning 2.0.0 (https://semver.org/)\n\n  This will ease some dependencies:\n\n    * `STM32_RTC_VERSION_MAJOR` -\u003e major version\n    * `STM32_RTC_VERSION_MINOR` -\u003e minor version\n    * `STM32_RTC_VERSION_PATCH` -\u003e patch version\n    * `STM32_RTC_VERSION_EXTRA` -\u003e Extra label\n     with:\n      - 0: official release\n      - [1-9]: release candidate\n      - F[0-9]: development\n\n    * `STM32_RTC_VERSION` --\u003e Full version number\n\n  `STM32_RTC_VERSION` can de used to handle some API change:\n```C++\n#if defined(STM32_RTC_VERSION) \u0026\u0026 (STM32_RTC_VERSION  \u003e= 0x01010000)\n  rtc.setAlarmTime(alarmHours, alarmMinutes, alarmSeconds, 123);\n#else\n  rtc.setAlarmTime(alarmHours, alarmMinutes, alarmSeconds);\n#endif\n```\n\n### Since STM32RTC version higher than 1.1.1\n\n_One-Second interrupt_\n\n  STM32 RTC includes a one-second interrupt for generating a periodic interrupt signal.\n  - This feature is native on the stm32F1xx and mapped on the existing WakeUp interrupt on other stm32 mcus.\n  - It is not available on some stm32F0 devices.\n\n  * **new API:**\n    * **`void attachSecondsInterrupt(voidFuncPtr callback)`**\n    * **`void detachSecondsInterrupt(void)`**\n\n\n_Date retention for stm32F1xx_\n\n  STM32 RTC includes date save/retrieve mechanism for the stm32F1xx mcu, that do not have a date counter.\n\n  The content is stored in BackUp memory which is kept during Reset and powered by Vbat when the Vdd is off.\n\n\n### Since STM32 Core version \u003e 1.5.0\n_Reset time management_\n\nBy default, if a time is set it will not be reset after a reboot.\n\nUsing `begin(true)` or `begin(true, HOUR_24)` will reset the RTC registers.\n\nTo know if a time has already been set use:\n* **`bool isTimeSet(void)`**\n```C++\n  if (!rtc.isTimeSet()) {\n    // Set the time\n    rtc.setHours(hours);\n    rtc.setMinutes(minutes);\n    rtc.setSeconds(seconds);\n  }\n```\n\n### Since STM32RTC version higher than 1.3.4\n_Second alarm (Alarm B)_\n\nSome STM32 RTC have a second alarm named `RTC_ALARM_B`.\nIt is possible to use it thanks all alarm API with an extra argument:\n  - `STM32RTC::ALARM_A`\n  - `STM32RTC::ALARM_B`\n\n```C++\n    rtc.attachInterrupt(myCallback, \u0026myCallbackdata, STM32RTC::ALARM_B);\n    rtc.setAlarmDay(day, STM32RTC::ALARM_B);\n    rtc.setAlarmTime(hours, minutes, seconds + 5, 567, STM32RTC::ALARM_B);\n    rtc.enableAlarm(rtc.MATCH_DHHMMSS, STM32RTC::ALARM_B);\n```\n\n### Since STM32RTC version higher than 1.3.7\n_Get the RTC handle_\n\n* **`RTC_HandleTypeDef *RTC_GetHandle(void)`**\n\n_binary and mix modes_\n\nSome STM32 RTC have a binary mode with 32-bit free-running counter\nin addition to their BCD mode for calendar (for example stm32wl55).\nCombined with BCD this is the MIX mode. Only using the binary counter is the BIN mode.\nThree RTC functional modes are available:\n  - `STM32RTC::MODE_BCD`\n  - `STM32RTC::MODE_MIX`\n  - `STM32RTC::MODE_BIN`\n\n* **`Binary_Mode getBinaryMode(void);`**\n* **`void setBinaryMode(Binary_Mode mode);`**\n\n\nAny API using the Subsecond parameter is expressed in milliseconds\nwhatever the RTC input clock. This parameter is [0..999] in MIX or BCD mode\nand [0..0xFFFFFFFF] in BIN mode. In BIN only mode, time and date registers are not used\nby the RTC. Thus the getEpoch function is only to be called to get the subsecond [0..0xFFFFFFFF]\n(returned time_t is not valid). The setAlarmEpoch only uses the sub-second [0..0xFFFFFFFF]\n(time_t value is useless).\n\n_SubSeconds underflow_\n\nOnly dor STM32WLxx. Manage interrupt (SSRU) when SubSeconds register\nunderflow. Used by STM32LoRaWAN.\n\n* **`void attachSubSecondsUnderflowInterrupt(voidFuncPtr callback);`**\n* **`void detachSubSecondsUnderflowInterrupt(void);`**\n\nRefer to the Arduino RTC documentation for the other functions\nhttp://arduino.cc/en/Reference/RTC\n\n### Since STM32RTC version higher than 1.4.0\n_IsFormat_24Hour_\n\nReturns True if the current Hour Format is HOUR_24 else false if Hour format is HOUR_12\n\n\n## Source\n\nSource files available at:\nhttps://github.com/stm32duino/STM32RTC\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstm32duino%2Fstm32rtc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstm32duino%2Fstm32rtc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstm32duino%2Fstm32rtc/lists"}