From 43311096b64df4de5caabd29074d1404e221d5b6 Mon Sep 17 00:00:00 2001 From: olikraus Date: Fri, 14 Apr 2017 12:28:38 +0200 Subject: [PATCH] update --- sys/arm/stm32l031x6/info.txt | 7 ++++- sys/arm/stm32l031x6/u8g2_rtc/Makefile | 2 +- sys/arm/stm32l031x6/u8g2_rtc/main.c | 38 ++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/sys/arm/stm32l031x6/info.txt b/sys/arm/stm32l031x6/info.txt index 6552d2ff..9bec8289 100644 --- a/sys/arm/stm32l031x6/info.txt +++ b/sys/arm/stm32l031x6/info.txt @@ -96,4 +96,9 @@ stm32flash: There seems to be a problem with ch340/ch341 devices ok, i will be using a cp21xx driver here... Conclution: Support of CH340 usb-serial converter for ubuntu linux will be there with Ubunutz 17.04 - \ No newline at end of file +=========== + +steampunk + +http://www.rattlebrained.org/articles/diy-pvc-train-whistle + diff --git a/sys/arm/stm32l031x6/u8g2_rtc/Makefile b/sys/arm/stm32l031x6/u8g2_rtc/Makefile index cfebd74d..cecf7b5b 100644 --- a/sys/arm/stm32l031x6/u8g2_rtc/Makefile +++ b/sys/arm/stm32l031x6/u8g2_rtc/Makefile @@ -117,7 +117,7 @@ all: $(DISNAME) $(HEXNAME) .PHONY: upload upload: $(DISNAME) $(HEXNAME) $(ELFNAME) - stm32flash -e 255 -g 0 -w $(HEXNAME) -v /dev/ttyUSB0 + stm32flash -b 115200 -e 255 -g 0 -w $(HEXNAME) -v /dev/ttyUSB0 $(SIZE) $(ELFNAME) .PHONY: clean diff --git a/sys/arm/stm32l031x6/u8g2_rtc/main.c b/sys/arm/stm32l031x6/u8g2_rtc/main.c index 6ad3dceb..b54e183b 100644 --- a/sys/arm/stm32l031x6/u8g2_rtc/main.c +++ b/sys/arm/stm32l031x6/u8g2_rtc/main.c @@ -1,4 +1,13 @@ -/* LED blink project for the STM32L031 */ +/* + + RTC for the STM32L031 + + EXTI line + 17 RTC alarm + 19 RTC tamper & timestamp & CSS_LSE + 20 RTC wakeup timer + +*/ #include "stm32l031xx.h" #include "delay.h" @@ -14,6 +23,7 @@ uint8_t u8x8_gpio_and_delay_stm32l0(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, /* global variables */ volatile unsigned long SysTickCount = 0; +volatile unsigned long RTCIRQCount = 0; rtc_t rtc; u8g2_t u8g2; @@ -24,6 +34,11 @@ void __attribute__ ((interrupt, used)) SysTick_Handler(void) SysTickCount++; } +void __attribute__ ((interrupt, used)) RTC_IRQHandler(void) +{ + RTC->ISR &= ~RTC_ISR_WUTF; /* clear the wake up flag... is this required? */ + RTCIRQCount++; +} void setHSIClock() @@ -157,6 +172,7 @@ int main() RTC->WPR = 0x0ca; /* disable RTC write protection */ RTC->WPR = 0x053; + /* RTC Start */ RTC->ISR = RTC_ISR_INIT; /* request RTC stop */ while((RTC->ISR & RTC_ISR_INITF)!=RTC_ISR_INITF) /* wait for stop */ ; @@ -164,10 +180,26 @@ int main() RTC->TR = 0; RTC->ISR =~ RTC_ISR_INIT; /* start RTC */ + /* wake up time setup & start */ + RTC->CR &=~ RTC_CR_WUTE; /* disable wakeup timer for reprogramming */ + while((RTC->ISR & RTC_ISR_WUTWF) != RTC_ISR_WUTWF) + ; + + RTC->WUTR = 0x010; /* reload is 1: 1Hz with the 1Hz clock */ + RTC->CR &= ~RTC_CR_WUCKSEL; /* clear selection register */ + RTC->CR |= RTC_CR_WUCKSEL_2; /* select the 1Hz clock */ + RTC->CR |= RTC_CR_WUTE | RTC_CR_WUTIE ; + + RTC->ISR &= ~RTC_ISR_WUTF; /* clear the wake up flag... is this required? */ + RTC->WPR = 0; /* enable RTC write protection */ RTC->WPR = 0; + EXTI->IMR |= EXTI_IMR_IM20; + EXTI->RTSR |= EXTI_RTSR_RT20; + NVIC_EnableIRQ(RTC_IRQn); + NVIC_SetPriority(RTC_IRQn, 0); //PWR->CR &= ~PWR_CR_DBP; /* disable write access to RCC->CSR */ @@ -186,6 +218,10 @@ int main() u8g2_DrawStr(&u8g2, 0, 50, "+"); else u8g2_DrawStr(&u8g2, 0, 50, "-"); + + u8g2_DrawStr(&u8g2, 40,50, u8x8_u8toa(RTCIRQCount, 3)); + + u8g2_SendBuffer(&u8g2); delay_micro_seconds(50000);