diff --git a/stm/Makefile b/stm/Makefile
index 645504871483a36dc225fdbd94ba29645ddb1dd0..f7e5eb61299bb2c3599ac608bf61ddcb68cd9add 100644
--- a/stm/Makefile
+++ b/stm/Makefile
@@ -64,6 +64,7 @@ SRC_C = \
 	i2c.c \
 	usrsw.c \
 	adc.c \
+	rtc.c \
 #	pybwlan.c \
 
 SRC_S = \
diff --git a/stm/main.c b/stm/main.c
index 2865b3a986ccc87a9bc2b709fd190d4eb7d92872..a42367984e3038f998dcf0d4db0fa80ff1a9bead 100644
--- a/stm/main.c
+++ b/stm/main.c
@@ -42,6 +42,7 @@
 #include "i2c.h"
 #include "usrsw.h"
 #include "adc.h"
+#include "rtc.h"
 
 int errno;
 
@@ -543,87 +544,6 @@ mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
     return mp_const_none;
 }
 
-static void rtc_init(void) {
-    uint32_t rtc_clksrc;
-    uint32_t timeout = 1000000;
-
-    /* Enable the PWR clock */
-    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
-
-    /* Allow access to RTC */
-    PWR_BackupAccessCmd(ENABLE);
-
-    /* Enable the LSE OSC */
-    RCC_LSEConfig(RCC_LSE_ON);
-
-    /* Wait till LSE is ready */
-    while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--timeout > 0)) {
-    }
-
-    /* If LSE timed out, use LSI instead */
-    if (timeout == 0) {
-        /* Enable the LSI OSC */
-        RCC_LSICmd(ENABLE);
-
-        /* Wait till LSI is ready */
-        while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {
-        }
-
-        /* Use LSI as the RTC Clock Source */
-        rtc_clksrc = RCC_RTCCLKSource_LSI;
-    } else {
-        /* Use LSE as the RTC Clock Source */
-        rtc_clksrc = RCC_RTCCLKSource_LSE;
-    }
-
-    /* Select the RTC Clock Source */
-    RCC_RTCCLKConfig(rtc_clksrc);
-
-    /* Note: LSI is around (32KHz), these dividers should work either way */
-    /* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
-    uint32_t uwSynchPrediv = 0xFF;
-    uint32_t uwAsynchPrediv = 0x7F;
-
-    /* Enable the RTC Clock */
-    RCC_RTCCLKCmd(ENABLE);
-
-    /* Wait for RTC APB registers synchronisation */
-    RTC_WaitForSynchro();
-
-    /* Configure the RTC data register and RTC prescaler */
-    RTC_InitTypeDef RTC_InitStructure;
-    RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv;
-    RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv;
-    RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
-    RTC_Init(&RTC_InitStructure);
-
-    // Set the date (BCD)
-    RTC_DateTypeDef RTC_DateStructure;
-    RTC_DateStructure.RTC_Year = 0x13;
-    RTC_DateStructure.RTC_Month = RTC_Month_October;
-    RTC_DateStructure.RTC_Date = 0x26;
-    RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Saturday;
-    RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
-
-    // Set the time (BCD)
-    RTC_TimeTypeDef RTC_TimeStructure;
-    RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
-    RTC_TimeStructure.RTC_Hours   = 0x01;
-    RTC_TimeStructure.RTC_Minutes = 0x53;
-    RTC_TimeStructure.RTC_Seconds = 0x00;
-    RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
-
-    // Indicator for the RTC configuration
-    //RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
-}
-
-mp_obj_t pyb_rtc_read(void) {
-    RTC_TimeTypeDef RTC_TimeStructure;
-    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
-    printf("%02d:%02d:%02d\n", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
-    return mp_const_none;
-}
-
 typedef struct _pyb_file_obj_t {
     mp_obj_base_t base;
     FIL fp;
diff --git a/stm/rtc.c b/stm/rtc.c
new file mode 100644
index 0000000000000000000000000000000000000000..9adfd3a7add0cf4e7f6d7530464afb783e9e8b00
--- /dev/null
+++ b/stm/rtc.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stm32f4xx.h>
+
+#include "misc.h"
+#include "mpconfig.h"
+#include "mpconfigport.h"
+#include "qstr.h"
+#include "obj.h"
+#include "rtc.h"
+
+void rtc_init(void) {
+    uint32_t rtc_clksrc;
+    uint32_t timeout = 1000000;
+
+    /* Enable the PWR clock */
+    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
+
+    /* Allow access to RTC */
+    PWR_BackupAccessCmd(ENABLE);
+
+    /* Enable the LSE OSC */
+    RCC_LSEConfig(RCC_LSE_ON);
+
+    /* Wait till LSE is ready */
+    while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--timeout > 0)) {
+    }
+
+    /* If LSE timed out, use LSI instead */
+    if (timeout == 0) {
+        /* Enable the LSI OSC */
+        RCC_LSICmd(ENABLE);
+
+        /* Wait till LSI is ready */
+        while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {
+        }
+
+        /* Use LSI as the RTC Clock Source */
+        rtc_clksrc = RCC_RTCCLKSource_LSI;
+    } else {
+        /* Use LSE as the RTC Clock Source */
+        rtc_clksrc = RCC_RTCCLKSource_LSE;
+    }
+
+    /* Select the RTC Clock Source */
+    RCC_RTCCLKConfig(rtc_clksrc);
+
+    /* Note: LSI is around (32KHz), these dividers should work either way */
+    /* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
+    uint32_t uwSynchPrediv = 0xFF;
+    uint32_t uwAsynchPrediv = 0x7F;
+
+    /* Enable the RTC Clock */
+    RCC_RTCCLKCmd(ENABLE);
+
+    /* Wait for RTC APB registers synchronisation */
+    RTC_WaitForSynchro();
+
+    /* Configure the RTC data register and RTC prescaler */
+    RTC_InitTypeDef RTC_InitStructure;
+    RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv;
+    RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv;
+    RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
+    RTC_Init(&RTC_InitStructure);
+
+    // Set the date (BCD)
+    RTC_DateTypeDef RTC_DateStructure;
+    RTC_DateStructure.RTC_Year = 0x13;
+    RTC_DateStructure.RTC_Month = RTC_Month_October;
+    RTC_DateStructure.RTC_Date = 0x26;
+    RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Saturday;
+    RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
+
+    // Set the time (BCD)
+    RTC_TimeTypeDef RTC_TimeStructure;
+    RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
+    RTC_TimeStructure.RTC_Hours   = 0x01;
+    RTC_TimeStructure.RTC_Minutes = 0x53;
+    RTC_TimeStructure.RTC_Seconds = 0x00;
+    RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
+
+    // Indicator for the RTC configuration
+    //RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
+}
+
+/******************************************************************************/
+/* Micro Python bindings                                                      */
+
+mp_obj_t pyb_rtc_read(void) {
+    RTC_TimeTypeDef RTC_TimeStructure;
+    RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
+    printf("%02d:%02d:%02d\n", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
+    return mp_const_none;
+}
diff --git a/stm/rtc.h b/stm/rtc.h
new file mode 100644
index 0000000000000000000000000000000000000000..6b1ff1b45496ca94b0d2d8b4ced5bd23fcdeaff2
--- /dev/null
+++ b/stm/rtc.h
@@ -0,0 +1,2 @@
+void rtc_init(void);
+mp_obj_t pyb_rtc_read(void);