cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 Problem with HSE that switching to HSI

Edodm85
Associate II

Hi,

I developed my first board with a STM32L431RCT6 (80Mhz) but sometimes I have problems with an external 8MHz crystal (HSE switches to HSI).

 

I configurated the peripherals and the clock with STM32CubeMx.

This is a clock configurator page (I enabled CSS):

1.jpg

This is a RCC page:

2.jpg

The 8Mhz crystal is connected on the pins PH0 and PH1 with two capacitors of 20pF.

When I stop the firmware after the System Clock configuration the HSEON and HSERDY registers are set to a corrent value (set to one).

3.jpg

Then a few lines of the code after (at the beginning of the while loop) the board switches to HSI clock.

4.jpg

Many times the board fail to startup (HSE switches to HSI) but sometime it work fine (HSE without switching to HSI).

The CSS interrupt is never trigger.. 

 

I don't understand the error. Can someone help me? 

I attached the source code and the ioc file.

Thanks,

Edo

 

1 ACCEPTED SOLUTION

Accepted Solutions

Your program runs in the System memory (built-in bootloader, 0x1fffxxxx).

Check BOOT0 pin. If you don't use the built-in bootloader, you can prevent entering it by programming option bytes appropriately.

JW

View solution in original post

5 REPLIES 5

The chip starts with MSI or HSI typically.

If HSE doesn't start due to electrical characteristic issues it will fall back to using the clock it started with.

You can export the clock via MCO PA8 pin, you should check HSE via that. Putting scope probes directly on the OSC pins will change the circuit characteristics.

https://www.st.com/resource/en/application_note/an2867-oscillator-design-guide-for-stm8afals-stm32-mcus-and-mpus-stmicroelectronics.pdf

Check the app note calculation with your crystal, don't just blind copy other designs which might use other parts. Check ST's BOM's for specific componentry they use. Change capacitors if necessary.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

If you place an infinite loop just after the place where you've shown HSE working, will it switch to HSI?

JW

Edodm85
Associate II

Thanks @Tesla DeLorean and @waclawek.jan for your reply.

I enabled the MCO clock output Pin.

I did some tests with HSE and HSI, but the result is the same.

With this code and HSE enable:

int main(void)
{
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
    SystemClock_Config();
    
    volatile uint32_t SysClockFreq = HAL_RCC_GetSysClockFreq();
    __NOP(); 
    
    while (1)
    {
    }
}

 

When I stopped at the breakpoint I saw the 80 MHz clock output:

10_HSE.jpg

DS1Z_QuickPrint20.jpg

 

When I run the program the MCO clock output stops:

11_HSE_ko.jpg

DS1Z_QuickPrint21.jpg

 

The function SysTick_Handler(void) is never called..

Any ideas?

Your program runs in the System memory (built-in bootloader, 0x1fffxxxx).

Check BOOT0 pin. If you don't use the built-in bootloader, you can prevent entering it by programming option bytes appropriately.

JW

Edodm85
Associate II

Thanks @waclawek.jan 

I forgot the pulldown resistor in the BOOT0 pin.