Skip to main content
Explorer II
November 28, 2023
Question

STM32F030R8 PWM using LSE as source for Timer

  • November 28, 2023
  • 4 replies
  • 2328 views

Hi all, 

I was wondering if there is a way to set up the LSE as the source for a Timer on the STM32F030R8 to generate a PWM output signal. Currently doing a deep dive on clock configurations, timers, etc. and I have been able to use the HSE for PWM, but can I use the LSE for PWM? Maybe with RTC?

Thank you in advance for answers!

    This topic has been closed for replies.

    4 replies

    Super User
    November 28, 2023

    why dont you look at the clock tree, CubeMx shows you , what you can do/connect or not ?

    tolgaustAuthor
    Explorer II
    November 28, 2023

    Reading the clock tree, I don't think LSE can be directly fed into a timer, so I was just curious if I was forgetting about something / unaware of some special thing to do to be able to use LSE as the source! 

    Technical Moderator
    November 28, 2023

    Hello @tolgaust and welcome to the ST COMMUNITY :smiling_face_with_smiling_eyes:.

    According to the clock tree of the STM32F030R8 (DS9773 page 15) you Can find that the timer Can use only 4 clock sources (HSE, HSI, HSE_PLL and HSI_PLL). So you can't use LSE as clock source for a timer.

    Screenshot_2023-11-28-21-54-24-89_e2d5b3f32b79de1d45acd1fad96fbb0f.jpg

    Best Regards 

    STTwo-32 

    Technical Moderator
    November 28, 2023

    Hello @tolgaust,

    According to RM0360 STM32F030R8, the timer clock frequencies are automatically fixed by hardware. There are two cases:
    – if the APB prescaler is 1, the timer clock frequencies are set to the same frequency as that of the APB domain;
    – otherwise, they are set to twice (x2) the frequency of the APB domain.

    In particular, TIM14 channel 1 input capture, can be used for the calibration HSI, LSI or HSI14 or to measure the frequency of all on-board clock sources (see RM0360, section 7.2.12).

    Here HSE/32 can be connected to TIM14 channel1, but I can't understand how you were able to use the HSE for PWM ? Can you give more details ?

    CMYL_1-1701208594544.png

    Best regards

    tolgaustAuthor
    Explorer II
    November 29, 2023

    I followed a guide online on configuring a timer to generate a PWM, and set TIM16 for the following settings:

    tolgaust_0-1701286247922.png

    Then I selected HSE as the source on the System Clock Mux for the APB1 peripheral clocks. 

    tolgaust_1-1701286277606.png

    Lastly, from my understanding, setting HSE source to BYPASS uses the High Speed crystal on the ST-Link debugger part of the nucleo board as its HSE crystal

    tolgaust_2-1701286312350.png

     

    Technical Moderator
    November 29, 2023

    In this case the HSE is the clock source of the System Clock, the rest of the clocks in the tree derived from this clock source, mainly the AHB clock HCLK and the APB clock PCLK. The timers clock source is the PCLK.

     

    For the HSE Bypass : In this mode, an external clock source must be provided (from a GBF for example ...). It can have a frequency of up to 32 MHz.

    According to the Nucleo board schematic (MB1136), there is no way to use the STLINK HSE crystal (fig1 the HSE feeding the STM32F0 and fig2 the HSE that feeds STLINK)

    CMYL_0-1701292729031.png 

    CMYL_1-1701292785354.png