Skip to content

Commit

Permalink
update stm32 platform, #2
Browse files Browse the repository at this point in the history
  • Loading branch information
avaldebe committed Dec 22, 2020
1 parent e5bd2d1 commit 52d86f7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
38 changes: 21 additions & 17 deletions lib/RTCutil/RTCutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@

#if HAST_RTC == INTERNAL_32kHz || HAST_RTC == INTERNAL_62kHz
#define INTERNAL_RTC
#ifndef __STM32F1__
#ifndef STM32F1
#error "Internal RTC options only for STM32F1"
#endif
#include <RTClock.h> // builtin RTC
#if HAST_RTC == INTERNAL_32kHz // LSE: low-speed external oscillator
static RTClock rtc(RTCSEL_LSE); // 32768 Hz crystal
#elif HAST_RTC == INTERNAL_62kHz // HSE: high-speed external oscillator
static RTClock rtc(RTCSEL_HSE); // 8 MHz/128 (62500 Hz)
#endif
static tm_t now;
#include <STM32RTC.h> // builtin RTC
STM32RTC& rtc = STM32RTC::getInstance();
#include <time.h>
static tm now;
static uint32_t unixtime;
#elif HAST_RTC == DS1307 || HAST_RTC == DS3231 || HAST_RTC == PCF8583 || HAST_RTC == PCF8563
#include <RTClib.h> // External RTC
#include <RTClib.h> // External RTC
#if HAST_RTC == DS1307
static RTC_DS1307 rtc;
#elif HAST_RTC == DS3231
Expand All @@ -50,6 +47,12 @@ bool rtc_stale()
}
void rtc_init()
{
#if HAST_RTC == INTERNAL_32kHz // LSE: low-speed external oscillator
rtc.setClockSource(STM32RTC::LSE_CLOCK); // 32768 Hz crystal
#elif HAST_RTC == INTERNAL_62kHz // HSE: high-speed external oscillator
rtc.setClockSource(STM32RTC::HSE_CLOCK); // 8 MHz/128 (62500 Hz)
#endif
rtc.begin(); // initialize RTC 24H format
if (rtc_stale())
{
rtc_now(BUILD_TIME);
Expand All @@ -59,8 +62,9 @@ void rtc_init()
uint32_t rtc_now()
{
#ifdef INTERNAL_RTC
rtc.getTime(now);
unixtime = rtc.getTime();
unixtime = rtc.getEpoch();
time_t rawtime = unixtime;
now = *localtime(&rawtime);
#else
now = rtc.now();
unixtime = now.unixtime();
Expand All @@ -71,7 +75,7 @@ uint32_t rtc_now()
uint32_t rtc_now(uint32_t time)
{
#ifdef INTERNAL_RTC
rtc.setTime(time);
rtc.setEpoch(time);
#else
rtc.adjust(DateTime(time));
#endif
Expand All @@ -85,19 +89,19 @@ char *rtc_fmt(const char fmt)
{
#ifdef INTERNAL_RTC
case 'D': // long date
sprintf(str, "%04u-%02u-%02u", 1970 + now.year, now.month, now.day);
strftime(str, sizeof(str), "%Y-%m-%d", &now);
break;
case 'd': // short date
sprintf(str, "%02u%02u%02u", now.year - 30, now.month, now.day);
strftime(str, sizeof(str), "%y%m%d", &now);
break;
case 'T': // long time
sprintf(str, "%02u:%02u:%02u", now.hour, now.minute, now.second);
strftime(str, sizeof(str), "%H:%M:%S", &now);
break;
case 't': // short time
sprintf(str, "%02u%02u", now.hour, now.minute);
strftime(str, sizeof(str), "%H%M", &now);
break;
case 'C': // file.csv
sprintf(str, "%02u%02u%02u.csv", now.year - 30, now.month, now.day);
strftime(str, sizeof(str), "%y%m%d.csv", &now);
break;
#else
case 'D': // long date
Expand Down
29 changes: 18 additions & 11 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@

[platformio]
description = Multichannel Voltage/Current Logger
libdeps_dir = ~/.platformio/lib
default_envs = STM32f103c8

[env]
framework = arduino
targets = checkprogsize
lib_deps =
INA2xx
SdFat
CircularBuffer
OneButton
RTClib
U8g2
sv-zanshin/INA2xx
greiman/SdFat
rlogiacco/CircularBuffer
mathertel/OneButton
olikraus/U8g2
build_flags =
!echo -D GIT_REV=\\\"`git describe`\\\"
; -D BREADBOARD
Expand All @@ -31,6 +29,9 @@ build_flags =
; @3.3V/8 MHz, RTC: DS1307; display: SH1106 128x64; tact button D3
platform = atmelavr
board = pro8MHzatmega328
lib_deps =
${env.lib_deps}
adafruit/RTClib
build_flags =
${env.build_flags}
-D HAST_RTC=DS1307
Expand All @@ -40,9 +41,12 @@ build_flags =

[env:STM32f103c8]
; 64 KB flash, RTC: 32768 Hz crystal; display: UC1701 128x64 on SPI2; tact button PA0
platform = ststm32@<=4.5.0
platform = ststm32
debug_tool = stlink
board = bluepill_f103c8
board = genericSTM32F103C8
lib_deps =
${env.lib_deps}
stm32duino/STM32duino RTC
build_flags =
${env.build_flags}
-D HAST_RTC=INTERNAL_32kHz
Expand All @@ -55,9 +59,12 @@ build_flags =

[env:STM32f103cb]
; 128 KB flash, RTC: 62500 Hz (8 MHz/128) clock; no display: use Serial1; tact button PA0
platform = ststm32@<=4.5.0
platform = ststm32
debug_tool = stlink
board = maple_mini_b20
board = genericSTM32F103CB
lib_deps =
${env.lib_deps}
stm32duino/STM32duino RTC
build_flags =
${env.build_flags}
-D HAST_RTC=INTERNAL_62kHz
Expand Down

0 comments on commit 52d86f7

Please sign in to comment.