---
title: "RTC: Alarm"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/drivers/rtc_alarm/
last_updated: 2026-11-24
sdk_version: 4.44
---
# RTC: Alarm

Source: https://developer.repebble.com/pebbleos/docs/samples/drivers/rtc_alarm/

This sample arms the board’s RTC alarm three seconds ahead and waits for it. The alarm calls back from its interrupt, so the callback only gives a semaphore, which `main()` waits on. An armed alarm also wakes the system from power-off, on the SoCs whose power-off keeps the RTC running.

Run:

`pbl samples samples/drivers/rtc_alarm`

Boards:

only stm32h747i\_disco/m7

## Sources

src/main.c

```
#include \<stdio.h\>#include \<time.h\>#include \<pbl/drivers/rtc.h\>#include \<pbl/kernel/sem.h\>#include \<pbl/kernel/types.h\>#define ALARM\_S 3static PBL\_SEM\_DEFINE(s\_fired, 0, 1);/\* The alarm calls back from its interrupt: it only wakes main(). \*/static void prv\_alarm(const struct pbl\_rtc \*rtc, void \*user\_data) {pbl\_sem\_give(&s\_fired);}int main(void) {time\_t start, now;int ret;ret = pbl\_rtc\_get\_time(RTC, &start);if (ret != 0) {fprintf(stderr, "rtc: read failed (%d)\n", ret);return ret;}ret = pbl\_rtc\_set\_alarm(RTC, start + ALARM\_S, prv\_alarm, nullptr);if (ret != 0) {fprintf(stderr, "rtc: alarm failed (%d)\n", ret);return ret;}printf("rtc: alarm armed for %d s from now\n", ALARM\_S);ret = pbl\_sem\_take(&s\_fired, PBL\_MSEC((ALARM\_S + 2) \* 1000));if (ret != 0) {fprintf(stderr, "rtc: no alarm (%d)\n", ret);return ret;}(void)pbl\_rtc\_get\_time(RTC, &now);printf("rtc: alarm fired after %d s\n", (int)(now - start));printf("Sample done\n");return 0;}
```

## Output

```
rtc: alarm armed for 3 s from now
rtc: alarm fired after 3 s
Sample done
```

Generated from PebbleOS [12b6c531f](https://github.com/coredevices/pebbleos/commit/12b6c531f9e0c2f39fe4e9bb2886314697128f08). This page is maintained in the pebbleos repository: [docs/samples/drivers/rtc\_alarm.md](https://github.com/coredevices/pebbleos/blob/12b6c531f9e0c2f39fe4e9bb2886314697128f08/docs/samples/drivers/rtc_alarm.md).
