Skip to main content
Visitor II
November 17, 2025
Solved

STM32L031K6 Custom Board - External 32.768 kHz Crystal Issue

  • November 17, 2025
  • 3 replies
  • 358 views

Post edited by ST moderator to be inline with the community rules for the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code.

Hello everyone,

I have designed a custom PCB using the STM32L031K6 microcontroller. The board includes an external 32.768 kHz crystal oscillator (LSE - Low Speed External).

The Problem:

I am flashing code to the board using an ST-Link. When running a simple LED blinking application (which uses HAL_Delay), the LED either blinks only once or gets stuck indefinitely within the HAL_Delay function. This strongly suggests an issue with the microcontroller's clock configuration or the LSE activation.

Hardware and Code Details:

  • MCU: STM32L031K6

  • External Oscillator: 32.768 kHz (LSE)

  • Development Environment: STM32CubeIDE

  • Library Used: STM32Cube HAL

  • Problematic Function: HAL_Delay() (This function relies on a properly running clock source, usually SysTick).

I will attach the following:

  1. Schematic:

    cekz_0-1763390587094.pngcekz_1-1763390596972.png

     

  2. Clock Configuration:

    cekz_2-1763390621082.png

     

  3. Simple Example Code:

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_12);

HAL_Delay(250);

}

/* USER CODE END 3 */

}

Any help or suggestions from someone who has faced this issue, especially regarding the LSE configuration or clock startup sequence on the L0 series, would be highly appreciated! Thank you!

    This topic has been closed for replies.
    Best answer by cekz

    Here's how I solved the issue;
    On the STM32L031K6, I couldn't select LSE directly in the Clock Configuration. After enabling RTC Active Clock Source under the "Timers" section, the LSE option became available.

    3 replies

    Technical Moderator
    November 17, 2025

    Hello @cekz and welcome to the ST community,

    So why are you suspecting a LSE issue while HAL_Delay() is based on either a timer or system tick counting?

    cekzAuthor
    Visitor II
    November 17, 2025

    Hi,

    I measured the oscillator with an oscilloscope and could not get a proper signal.

    Technical Moderator
    November 17, 2025

    @cekz wrote:

    Hi,

    I measured the oscillator with an oscilloscope and could not get a proper signal.


    Which oscillator ? LSE?

    This is definitely not a LSE issue as you are reaching the while loop.

    And here, LSI is selected and not LSE:

    mALLEm_0-1763393167993.png

    Technical Moderator
    November 17, 2025

    …and why are you selecting LSI instead of the LSE?

    Technical Moderator
    November 17, 2025

    @Peter BENSCH wrote:

    …and why are you selecting LSI instead of the LSE?


    That's one more reason indicating it's not a LSE issue.. it's something else..

    @cekz 

    1- Could you please share you project?

    2- In the hardware, no need for the NRST pull-up pin. There is one internal to the MCU. Did you fit the JP4 jumper in the position 2-3?

    cekzAuthor
    Visitor II
    November 17, 2025

    Project

    cekzAuthorAnswer
    Visitor II
    November 18, 2025

    Here's how I solved the issue;
    On the STM32L031K6, I couldn't select LSE directly in the Clock Configuration. After enabling RTC Active Clock Source under the "Timers" section, the LSE option became available.