Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization of real time clock on stm32f3 Discovery board #87

Open
smedellin90 opened this issue Apr 6, 2020 · 3 comments
Open

Initialization of real time clock on stm32f3 Discovery board #87

smedellin90 opened this issue Apr 6, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@smedellin90
Copy link

smedellin90 commented Apr 6, 2020

Hello!

I have not been able to find a way to initialize the rtc on the stm32f3 Discovery board.
For the STM32F103C8, initialization would go something like this (using cortex-m-rtfm crate):

use stm32f1xx_hal::{delay, gpio, i2c, rtc, spi, stm32, timer};

#[app(device = stm32f1xx_hal::stm32, peripherals = true)]
const APP: () = {
   
       #[init(spawn = [msg])]
       fn init(mut c: init::Context) -> init::LateResources {
           let mut rcc = c.device.RCC.constrain();
           let mut backup_domain = rcc
                .bkp
                .constrain(c.device.BKP, &mut rcc.apb1, &mut c.device.PWR);
           let mut rtc_dev = rtc::Rtc::rtc(c.device.RTC, &mut backup_domain); // initialization of rtc
           // rest is omitted
       }
}

Is there a way to initialize the real time clock currently using the stm32f3xx-hal?

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Apr 6, 2020

Currently, the RTC module is missing from the stm32f3xx-hal. But the stm32f3-series do support RTCs, so it should be possible.

PRs for an rtc module are welcome! :)

@Sh3Rm4n Sh3Rm4n added the enhancement New feature or request label Apr 6, 2020
@smedellin90
Copy link
Author

I'm currently working on an RTC module for the stm32f3xx-hal. I'm running into a peculiar issue at the moment with the RTC init flag (RTC_ISR register, INITF bit). Below is a function that writes prescaler values into the PRER register:

    fn perform_prescaler_write(&mut self, prediv_s: u32, prediv_a: u32) {
        // Disabling write protection to RTC reg block
        self.regs.wpr.write(|w| unsafe { w.bits(0xCA) });
        self.regs.wpr.write(|w| unsafe { w.bits(0x53) });
        // Setting RTC Initialization bit to make prescalers programmable
        self.regs.isr.modify(|_, w| { w.init().set_bit()});
        // wait for initilization mode to take effect
        while self.regs.isr.read().initf().bit() == false {} // Never finishes
        // Setting Prescalers for 1 hz RTC
        let raw_bits: u32 = prediv_s | (prediv_a << 16);
        self.regs.prer.write(|w| unsafe { w.bits(raw_bits) });
        // Take device out of Initialization mode
        self.regs.isr.modify(|_, w| { w.init().clear_bit()});
        // wait for last write to be done
        while !self.regs.isr.read().initf().bit() == false {}
    }

It will get hung up, waiting for RTC initialization mode to be set. Has anyone run into this issue? I'm currently using the stm32f3 discovery board.

@David-OConnor
Copy link
Contributor

Is this working now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants