From fd59ef5ac44ac889d6a2d06013c0cb686f58e889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sun, 28 Oct 2018 22:44:53 +0100 Subject: [PATCH] blue pill: use HSE as RTC clock to be able to toogle onboard LED --- application.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/application.c b/application.c index e1db3f6..cb388b1 100644 --- a/application.c +++ b/application.c @@ -275,7 +275,12 @@ void main(void) // setup RTC printf("setup internal RTC: "); - rtc_auto_awake(RCC_LSE, 32768-1); // ensure internal RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly (power off the micro-controller for the change to take effect) +#if defined(BLUE_PILL) // for boards without a Low Speed External oscillator + // /!\ WARNING the blue pill LSE oscillator is affected when toggling the onboard LED, thus prefer the HSE + rtc_auto_awake(RCC_LSE, 8000000 / 128 - 1); // use High Speed External oscillator (8 MHz / 128) as RTC clock (VBAT can't be used to keep the RTC running) +#else // for boards with an precise Low Speed External oscillator + rtc_auto_awake(RCC_LSE, 32768 - 1); // ensure internal RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly (power off the micro-controller for the change to take effect) +#endif rtc_interrupt_enable(RTC_SEC); // enable RTC interrupt on "seconds" nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt printf("OK\n"); @@ -308,9 +313,7 @@ void main(void) while (rtc_internal_tick_flag) { // the internal RTC ticked rtc_internal_tick_flag = false; // reset flag action = true; // action has been performed -#if !defined(BLUE_PILL) // on the blue pill the LED is close to the 32.768 kHz oscillator and heavily influences it led_toggle(); // toggle LED (good to indicate if main function is stuck) -#endif } if (action) { // go to sleep if nothing had to be done, else recheck for activity action = false;