Skip to main content
jerry2
Associate III
December 7, 2016
Question

Low-Speed Oscillator on STM32F746

  • December 7, 2016
  • 3 replies
  • 1819 views
Posted on December 07, 2016 at 19:37

I've got a development board based on the STM32F746 from Mikroelektronika. The board has a 32.768 kHz crystal connected to the LSE oscillator pins. I can't get the oscillator to start and come ready.

Here's my code--any idea what I'm doing wrong?

/*

 * Start the LSE (32 kHZ) oscillator

 */

    RCC->APB1ENR |= RCC_APB1ENR_PWREN;        // enable PWR interface clock

    PWR->CR1 |= PWR_CR1_DBP;                                  // disable backup domain write protection

    RCC->BDCR |= RCC_BDCR_BDRST;                        // reset backup domain

    RCC->BDCR &= ~RCC_BDCR_BDRST;                    // deassert backup domain reset

    RCC->BDCR |= RCC_BDCR_LSEON;                        // enable LSE oscillator

    while(!(RCC->BDCR & RCC_BDCR_LSERDY))

                 ;                                                                             // wait for LSE ready

    RCC->BDCR &= ~(0b11 << 8);                                      //

    RCC->BDCR |= 0b01 << 8;                                            // select LSE as RTC clock

    RCC->BDCR |= RCC_BDCR_RTCEN;                        // enable RTC

    This topic has been closed for replies.

    3 replies

    waclawek.jan
    Super User
    December 7, 2016
    Posted on December 07, 2016 at 20:06

    How do you know that LSE is not running?

    Have a look also at

    https://community.st.com/0D50X00009XkaBaSAJ

    JW

    jerry2
    jerry2Author
    Associate III
    December 7, 2016
    Posted on December 07, 2016 at 22:17

    I don't know whether it's actually running. I'm inferring that it is if the LSERDY bit in the BDCR register comes on. I never see this bit getting set--the while loop never exits.

    Tesla DeLorean
    Guru
    December 7, 2016
    Posted on December 07, 2016 at 20:19

    Does the F7 have the write buffer hazard with respect to you enabling a clock, and then immediately trying to write to the peripheral? (Check Errata)

    I'd probably fence those first two writes.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    jerry2
    jerry2Author
    Associate III
    December 7, 2016
    Posted on December 07, 2016 at 22:17

    I don't think that's the problem. The issue persists even when I single-step the code in the debugger.

    Tesla DeLorean
    Guru
    December 7, 2016
    Posted on December 07, 2016 at 22:29

    This I'll presume is with 

    Mikroelektronika's MikroC? Is it handling the volatile nature of peripheral registers properly? Can you turn optimization off?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    ST Renegade
    Associate
    December 7, 2016
    Posted on December 07, 2016 at 22:21

    Hi Jerry,

    as usual I'm going to advise you to use the STM32CubeMX tool. The code should be functional. Try to run it, and if it works, compare your code with the one generated with yours + check the ref manual etc. for details why it's done this way etc...

    Good luck,

    Renegade