Skip to content

Commit

Permalink
Add RTC support
Browse files Browse the repository at this point in the history
  • Loading branch information
GrumpyOldPizza committed Oct 23, 2016
1 parent 9375f89 commit 9cc3282
Show file tree
Hide file tree
Showing 20 changed files with 1,625 additions and 72 deletions.
1 change: 1 addition & 0 deletions cores/stm32l4/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern "C"{
#undef DAC1
#undef SPI1
#undef SPI2
#undef RTC

#define F_CPU SystemCoreClock

Expand Down
10 changes: 10 additions & 0 deletions cores/stm32l4/STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
#include "Arduino.h"
#include "wiring_private.h"

uint32_t STM32Class::readBackup(unsigned int index)
{
return stm32l4_rtc_read_backup(index);
}

void STM32Class::writeBackup(unsigned int index, uint32_t data)
{
stm32l4_rtc_write_backup(index, data);
}

uint64_t STM32Class::getSerial()
{
uint32_t serial0, serial1, serial2;
Expand Down
3 changes: 3 additions & 0 deletions cores/stm32l4/STM32.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

class STM32Class {
public:
uint32_t readBackup(unsigned int idx);
void writeBackup(unsigned int idx, uint32_t val);

uint64_t getSerial();

float getVBAT();
Expand Down
2 changes: 2 additions & 0 deletions cores/stm32l4/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void init( void )
armv7m_systick_initialize(STM32L4_SYSTICK_IRQ_PRIORITY);
armv7m_timer_initialize();

stm32l4_rtc_configure(STM32L4_RTC_IRQ_PRIORITY);

stm32l4_exti_create(&stm32l4_exti, STM32L4_EXTI_IRQ_PRIORITY);
stm32l4_exti_enable(&stm32l4_exti);

Expand Down
8 changes: 5 additions & 3 deletions cores/stm32l4/wiring_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern "C" {
#include "stm32l4_spi.h"
#include "stm32l4_usbd_cdc.h"
#include "stm32l4_system.h"
#include "stm32l4_rtc.h"

#include "wiring_constants.h"

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

#define STM32L4_USB_IRQ_PRIORITY 14
#define STM32L4_I2C_IRQ_PRIORITY 13
#define STM32L4_UART_IRQ_PRIORITY 12
#define STM32L4_SPI_IRQ_PRIORITY 11
#define STM32L4_RTC_IRQ_PRIORITY 13
#define STM32L4_I2C_IRQ_PRIORITY 12
#define STM32L4_UART_IRQ_PRIORITY 11
#define STM32L4_SPI_IRQ_PRIORITY 10

#define STM32L4_EXTI_IRQ_PRIORITY 4
#define STM32L4_SYSTICK_IRQ_PRIORITY 3
Expand Down
55 changes: 55 additions & 0 deletions libraries/RTC/examples/Epoch/Epoch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Epoch time example for Arduino Zero and MKR1000
Demonstrates how to set time using epoch for the Arduino Zero and MKR1000
This example code is in the public domain
created by Sandeep Mistry <[email protected]>
31 Dec 2015
modified
18 Feb 2016
*/

#include <RTC.h>

void setup() {
Serial.begin(9600);

RTC.setEpoch(1451606400); // Jan 1, 2016
}

void loop() {
Serial.print("Unix time = ");
Serial.println(RTC.getEpoch());

Serial.print("Seconds since Jan 1 2000 = ");
Serial.println(RTC.getY2kEpoch());

// Print date...
Serial.print(RTC.getDay());
Serial.print("/");
Serial.print(RTC.getMonth());
Serial.print("/");
Serial.print(RTC.getYear());
Serial.print("\t");

// ...and time
print2digits(RTC.getHours());
Serial.print(":");
print2digits(RTC.getMinutes());
Serial.print(":");
print2digits(RTC.getSeconds());

Serial.println();

delay(1000);
}

void print2digits(int number) {
if (number < 10) {
Serial.print("0");
}
Serial.print(number);
}

78 changes: 78 additions & 0 deletions libraries/RTC/examples/SimpleRTC/SimpleRTC.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Simple RTC for Arduino Zero and MKR1000
Demonstrates the use of the RTC library for the Arduino Zero and MKR1000
This example code is in the public domain
http://arduino.cc/en/Tutorial/SimpleRTC
created by Arturo Guadalupi <[email protected]>
15 Jun 2015
modified
18 Feb 2016
modified by Andrea Richetta <[email protected]>
24 Aug 2016
*/

#include <RTC.h>

/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 16;

/* Change these values to set the current initial date */
const byte day = 15;
const byte month = 6;
const byte year = 15;

void setup()
{
Serial.begin(9600);

// Set the time
RTC.setHours(hours);
RTC.setMinutes(minutes);
RTC.setSeconds(seconds);

// Set the date
RTC.setDay(day);
RTC.setMonth(month);
RTC.setYear(year);

// you can use also
//RTC.setTime(hours, minutes, seconds);
//RTC.setDate(day, month, year);
}

void loop()
{
// Print date...
print2digits(RTC.getDay());
Serial.print("/");
print2digits(RTC.getMonth());
Serial.print("/");
print2digits(RTC.getYear());
Serial.print(" ");

// ...and time
print2digits(RTC.getHours());
Serial.print(":");
print2digits(RTC.getMinutes());
Serial.print(":");
print2digits(RTC.getSeconds());

Serial.println();

delay(1000);
}



void print2digits(int number) {
if (number < 10) {
Serial.print("0"); // print a 0 before if the number is < than 10
}
Serial.print(number);
}
50 changes: 50 additions & 0 deletions libraries/RTC/examples/SimpleRTCAlarm/SimpleRTCAlarm.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Simple RTC Alarm for Arduino Zero and MKR1000
Demonstrates how to set an RTC alarm for the Arduino Zero and MKR1000
This example code is in the public domain
http://arduino.cc/en/Tutorial/SimpleRTCAlarm
created by Arturo Guadalupi <[email protected]>
25 Sept 2015
modified
21 Oct 2015
*/

#include <RTC.h>

/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 16;

/* Change these values to set the current initial date */
const byte day = 25;
const byte month = 9;
const byte year = 15;

void setup()
{
Serial.begin(9600);

RTC.setTime(hours, minutes, seconds);
RTC.setDate(day, month, year);

RTC.setAlarmTime(16, 0, 10);
RTC.enableAlarm(RTC.MATCH_HHMMSS);

RTC.attachInterrupt(alarmMatch);
}

void loop()
{

}

void alarmMatch()
{
Serial.println("Alarm Match!");
}
57 changes: 57 additions & 0 deletions libraries/RTC/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#######################################
# Syntax Coloring Map For RTC
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

RTCZero KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

getDay KEYWORD2
getMonth KEYWORD2
getYear KEYWORD2
getHours KEYWORD2
getMinutes KEYWORD2
getSeconds KEYWORD2

setDay KEYWORD2
setMonth KEYWORD2
setYear KEYWORD2
setHours KEYWORD2
setMinutes KEYWORD2
setSeconds KEYWORD2
setDate KEYWORD2
setTime KEYWORD2

getEpoch KEYWORD2
getY2kEpoch KEYWORD2
setEpoch KEYWORD2
setY2kEpoch KEYWORD2

getAlarmDay KEYWORD2
getAlarmMonth KEYWORD2
getAlarmYear KEYWORD2
getAlarmHours KEYWORD2
getAlarmMinutes KEYWORD2
getAlarmSeconds KEYWORD2

setAlarmDay KEYWORD2
setAlarmMonth KEYWORD2
setAlarmYear KEYWORD2
setAlarmHours KEYWORD2
setAlarmMinutes KEYWORD2
setAlarmSeconds KEYWORD2
setAlarmDate KEYWORD2
setAlarmTime KEYWORD2

enableAlarm KEYWORD2
disableAlarm KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
9 changes: 9 additions & 0 deletions libraries/RTC/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=RTC
version=1.0
author=Thomas Roell
maintainer[email protected]
sentence=Allows to use the RTC functionalities.
paragraph=With this library you can use the RTC peripheral to program actions related to date and time.
category=Timing
url=http://www.arduino.cc/en/Reference/RTCZero
architectures=stm32l4
Loading

0 comments on commit 9cc3282

Please sign in to comment.