cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L031K6 Custom Board - External 32.768 kHz Crystal Issue

cekz
Visitor

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!

7 REPLIES 7
mƎALLEm
ST Employee

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?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Peter BENSCH
ST Employee

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

@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?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hi,

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


@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

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

STM32CubeIDE does not allow me to select LSE. I cannot make any settings in that section.

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.