From 52d86f7bc6d5e534f22c3b4698ca873a3213c8a3 Mon Sep 17 00:00:00 2001 From: Alvaro Valdebenito Date: Tue, 22 Dec 2020 10:18:20 +0100 Subject: [PATCH] update stm32 platform, #2 --- lib/RTCutil/RTCutil.cpp | 38 +++++++++++++++++++++----------------- platformio.ini | 29 ++++++++++++++++++----------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/lib/RTCutil/RTCutil.cpp b/lib/RTCutil/RTCutil.cpp index 4173ea3..695efd8 100644 --- a/lib/RTCutil/RTCutil.cpp +++ b/lib/RTCutil/RTCutil.cpp @@ -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 // 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 // builtin RTC +STM32RTC& rtc = STM32RTC::getInstance(); +#include +static tm now; static uint32_t unixtime; #elif HAST_RTC == DS1307 || HAST_RTC == DS3231 || HAST_RTC == PCF8583 || HAST_RTC == PCF8563 -#include // External RTC +#include // External RTC #if HAST_RTC == DS1307 static RTC_DS1307 rtc; #elif HAST_RTC == DS3231 @@ -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); @@ -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(); @@ -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 @@ -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 diff --git a/platformio.ini b/platformio.ini index 5f5756b..f2ffd09 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 @@ -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 @@ -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 @@ -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