Skip to content

Commit 9cc3282

Browse files
Add RTC support
1 parent 9375f89 commit 9cc3282

File tree

20 files changed

+1625
-72
lines changed

20 files changed

+1625
-72
lines changed

cores/stm32l4/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern "C"{
4949
#undef DAC1
5050
#undef SPI1
5151
#undef SPI2
52+
#undef RTC
5253

5354
#define F_CPU SystemCoreClock
5455

cores/stm32l4/STM32.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#include "Arduino.h"
3030
#include "wiring_private.h"
3131

32+
uint32_t STM32Class::readBackup(unsigned int index)
33+
{
34+
return stm32l4_rtc_read_backup(index);
35+
}
36+
37+
void STM32Class::writeBackup(unsigned int index, uint32_t data)
38+
{
39+
stm32l4_rtc_write_backup(index, data);
40+
}
41+
3242
uint64_t STM32Class::getSerial()
3343
{
3444
uint32_t serial0, serial1, serial2;

cores/stm32l4/STM32.h

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
class STM32Class {
3535
public:
36+
uint32_t readBackup(unsigned int idx);
37+
void writeBackup(unsigned int idx, uint32_t val);
38+
3639
uint64_t getSerial();
3740

3841
float getVBAT();

cores/stm32l4/wiring.c

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ void init( void )
9090
armv7m_systick_initialize(STM32L4_SYSTICK_IRQ_PRIORITY);
9191
armv7m_timer_initialize();
9292

93+
stm32l4_rtc_configure(STM32L4_RTC_IRQ_PRIORITY);
94+
9395
stm32l4_exti_create(&stm32l4_exti, STM32L4_EXTI_IRQ_PRIORITY);
9496
stm32l4_exti_enable(&stm32l4_exti);
9597

cores/stm32l4/wiring_private.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern "C" {
4949
#include "stm32l4_spi.h"
5050
#include "stm32l4_usbd_cdc.h"
5151
#include "stm32l4_system.h"
52+
#include "stm32l4_rtc.h"
5253

5354
#include "wiring_constants.h"
5455

@@ -60,9 +61,10 @@ extern "C" {
6061
#define STM32L4_PWM_IRQ_PRIORITY 15
6162

6263
#define STM32L4_USB_IRQ_PRIORITY 14
63-
#define STM32L4_I2C_IRQ_PRIORITY 13
64-
#define STM32L4_UART_IRQ_PRIORITY 12
65-
#define STM32L4_SPI_IRQ_PRIORITY 11
64+
#define STM32L4_RTC_IRQ_PRIORITY 13
65+
#define STM32L4_I2C_IRQ_PRIORITY 12
66+
#define STM32L4_UART_IRQ_PRIORITY 11
67+
#define STM32L4_SPI_IRQ_PRIORITY 10
6668

6769
#define STM32L4_EXTI_IRQ_PRIORITY 4
6870
#define STM32L4_SYSTICK_IRQ_PRIORITY 3
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Epoch time example for Arduino Zero and MKR1000
3+
4+
Demonstrates how to set time using epoch for the Arduino Zero and MKR1000
5+
6+
This example code is in the public domain
7+
8+
created by Sandeep Mistry <s.mistry@arduino.cc>
9+
31 Dec 2015
10+
modified
11+
18 Feb 2016
12+
*/
13+
14+
#include <RTC.h>
15+
16+
void setup() {
17+
Serial.begin(9600);
18+
19+
RTC.setEpoch(1451606400); // Jan 1, 2016
20+
}
21+
22+
void loop() {
23+
Serial.print("Unix time = ");
24+
Serial.println(RTC.getEpoch());
25+
26+
Serial.print("Seconds since Jan 1 2000 = ");
27+
Serial.println(RTC.getY2kEpoch());
28+
29+
// Print date...
30+
Serial.print(RTC.getDay());
31+
Serial.print("/");
32+
Serial.print(RTC.getMonth());
33+
Serial.print("/");
34+
Serial.print(RTC.getYear());
35+
Serial.print("\t");
36+
37+
// ...and time
38+
print2digits(RTC.getHours());
39+
Serial.print(":");
40+
print2digits(RTC.getMinutes());
41+
Serial.print(":");
42+
print2digits(RTC.getSeconds());
43+
44+
Serial.println();
45+
46+
delay(1000);
47+
}
48+
49+
void print2digits(int number) {
50+
if (number < 10) {
51+
Serial.print("0");
52+
}
53+
Serial.print(number);
54+
}
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Simple RTC for Arduino Zero and MKR1000
3+
4+
Demonstrates the use of the RTC library for the Arduino Zero and MKR1000
5+
6+
This example code is in the public domain
7+
8+
http://arduino.cc/en/Tutorial/SimpleRTC
9+
10+
created by Arturo Guadalupi <a.guadalupi@arduino.cc>
11+
15 Jun 2015
12+
modified
13+
18 Feb 2016
14+
modified by Andrea Richetta <a.richetta@arduino.cc>
15+
24 Aug 2016
16+
*/
17+
18+
#include <RTC.h>
19+
20+
/* Change these values to set the current initial time */
21+
const byte seconds = 0;
22+
const byte minutes = 0;
23+
const byte hours = 16;
24+
25+
/* Change these values to set the current initial date */
26+
const byte day = 15;
27+
const byte month = 6;
28+
const byte year = 15;
29+
30+
void setup()
31+
{
32+
Serial.begin(9600);
33+
34+
// Set the time
35+
RTC.setHours(hours);
36+
RTC.setMinutes(minutes);
37+
RTC.setSeconds(seconds);
38+
39+
// Set the date
40+
RTC.setDay(day);
41+
RTC.setMonth(month);
42+
RTC.setYear(year);
43+
44+
// you can use also
45+
//RTC.setTime(hours, minutes, seconds);
46+
//RTC.setDate(day, month, year);
47+
}
48+
49+
void loop()
50+
{
51+
// Print date...
52+
print2digits(RTC.getDay());
53+
Serial.print("/");
54+
print2digits(RTC.getMonth());
55+
Serial.print("/");
56+
print2digits(RTC.getYear());
57+
Serial.print(" ");
58+
59+
// ...and time
60+
print2digits(RTC.getHours());
61+
Serial.print(":");
62+
print2digits(RTC.getMinutes());
63+
Serial.print(":");
64+
print2digits(RTC.getSeconds());
65+
66+
Serial.println();
67+
68+
delay(1000);
69+
}
70+
71+
72+
73+
void print2digits(int number) {
74+
if (number < 10) {
75+
Serial.print("0"); // print a 0 before if the number is < than 10
76+
}
77+
Serial.print(number);
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Simple RTC Alarm for Arduino Zero and MKR1000
3+
4+
Demonstrates how to set an RTC alarm for the Arduino Zero and MKR1000
5+
6+
This example code is in the public domain
7+
8+
http://arduino.cc/en/Tutorial/SimpleRTCAlarm
9+
10+
created by Arturo Guadalupi <a.guadalupi@arduino.cc>
11+
25 Sept 2015
12+
13+
modified
14+
21 Oct 2015
15+
*/
16+
17+
#include <RTC.h>
18+
19+
/* Change these values to set the current initial time */
20+
const byte seconds = 0;
21+
const byte minutes = 0;
22+
const byte hours = 16;
23+
24+
/* Change these values to set the current initial date */
25+
const byte day = 25;
26+
const byte month = 9;
27+
const byte year = 15;
28+
29+
void setup()
30+
{
31+
Serial.begin(9600);
32+
33+
RTC.setTime(hours, minutes, seconds);
34+
RTC.setDate(day, month, year);
35+
36+
RTC.setAlarmTime(16, 0, 10);
37+
RTC.enableAlarm(RTC.MATCH_HHMMSS);
38+
39+
RTC.attachInterrupt(alarmMatch);
40+
}
41+
42+
void loop()
43+
{
44+
45+
}
46+
47+
void alarmMatch()
48+
{
49+
Serial.println("Alarm Match!");
50+
}

libraries/RTC/keywords.txt

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#######################################
2+
# Syntax Coloring Map For RTC
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
RTCZero KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
getDay KEYWORD2
16+
getMonth KEYWORD2
17+
getYear KEYWORD2
18+
getHours KEYWORD2
19+
getMinutes KEYWORD2
20+
getSeconds KEYWORD2
21+
22+
setDay KEYWORD2
23+
setMonth KEYWORD2
24+
setYear KEYWORD2
25+
setHours KEYWORD2
26+
setMinutes KEYWORD2
27+
setSeconds KEYWORD2
28+
setDate KEYWORD2
29+
setTime KEYWORD2
30+
31+
getEpoch KEYWORD2
32+
getY2kEpoch KEYWORD2
33+
setEpoch KEYWORD2
34+
setY2kEpoch KEYWORD2
35+
36+
getAlarmDay KEYWORD2
37+
getAlarmMonth KEYWORD2
38+
getAlarmYear KEYWORD2
39+
getAlarmHours KEYWORD2
40+
getAlarmMinutes KEYWORD2
41+
getAlarmSeconds KEYWORD2
42+
43+
setAlarmDay KEYWORD2
44+
setAlarmMonth KEYWORD2
45+
setAlarmYear KEYWORD2
46+
setAlarmHours KEYWORD2
47+
setAlarmMinutes KEYWORD2
48+
setAlarmSeconds KEYWORD2
49+
setAlarmDate KEYWORD2
50+
setAlarmTime KEYWORD2
51+
52+
enableAlarm KEYWORD2
53+
disableAlarm KEYWORD2
54+
55+
#######################################
56+
# Constants (LITERAL1)
57+
#######################################

libraries/RTC/library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=RTC
2+
version=1.0
3+
author=Thomas Roell
4+
maintainer=grumpyoldpizza@gmail.com
5+
sentence=Allows to use the RTC functionalities.
6+
paragraph=With this library you can use the RTC peripheral to program actions related to date and time.
7+
category=Timing
8+
url=http://www.arduino.cc/en/Reference/RTCZero
9+
architectures=stm32l4

0 commit comments

Comments
 (0)