2025-11-17 6:47 AM - last edited on 2025-11-17 6:54 AM by mƎALLEm
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:
Schematic:
Clock Configuration:
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!
2025-11-17 6:53 AM
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?
2025-11-17 6:54 AM
…and why are you selecting LSI instead of the LSE?
2025-11-17 7:18 AM
@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..
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?
2025-11-17 7:22 AM
Hi,
I measured the oscillator with an oscilloscope and could not get a proper signal.
2025-11-17 7:24 AM - edited 2025-11-17 7:26 AM
@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:
2025-11-17 8:30 AM
STM32CubeIDE does not allow me to select LSE. I cannot make any settings in that section.
2025-11-17 8:32 AM
STM32CubeIDE does not allow me to select LSE. I cannot make any settings in that section.
Boot pin is connected to GND via pull down.
I can share the project files soon.