cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476G-Disco LSE Startup Problem

gokhannsahin
Associate II
Posted on January 05, 2018 at 14:44

Hi everyone,

I want to use RTC module and LSE crystal which is default on board 32768KHz. I generate the code via STM32Cube because I couldn't find any example of RTC that used via LSE. After generated, the code doesn't pass the LSE ready check. I guess the reason for that issue isn't hardware because the code is running on discovery board. I have tried firmware 1.10 and 1.9 libraries for stm32l4 but the result is same. Where am I doing wrong?

#stm32l476-discovery-board #lse-startup
20 REPLIES 20
Posted on January 06, 2018 at 19:06

Hi Sahin.gokhan

Can you share your code (main.c) where SystemClockConfig() is defined ?

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.

Posted on January 06, 2018 at 19:23

I think something is wrong and incomplete into

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;

SystemClockConfig() should configure: 

RCC_OscInitStruc for main SYSCLK by using HSE, MSI or HSI with or without PLL.

And configure LSE or LSI. Not both.

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.

Posted on January 06, 2018 at 19:48

Here an example. Coud you try it ?

void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct;
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 RCC_PeriphCLKInitTypeDef PeriphClkInit;
 /**Configure LSE Drive Capability */
 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
 /**Initializes the CPU, AHB and APB busses clocks */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
 RCC_OscInitStruct.LSEState = RCC_LSE_ON;
 RCC_OscInitStruct.MSIState = RCC_MSI_ON;
 RCC_OscInitStruct.MSICalibrationValue = 0;
 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
 RCC_OscInitStruct.PLL.PLLM = 1;
 RCC_OscInitStruct.PLL.PLLN = 40;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
 /**Initializes the CPU, AHB and APB busses clocks */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
 PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
 
 /**Configure the main internal regulator output voltage */
 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
 /**Configure the Systick interrupt time */
 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 /**Configure the Systick */
 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 /* SysTick_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

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.

Posted on January 06, 2018 at 20:53

Very similar issue:

https://os.mbed.com/questions/67987/STM32L476-LSE-startup-issues/

 
Posted on January 06, 2018 at 20:25

This is from the ST exemplars, they turns one oscillator on, and the other off.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 06, 2018 at 20:41

I've tested your 

SystemClock_Config() on NucleoL476RG (with LSE 32768 mounted) and function is OK.

No Hard fault for me.

Check LSE on board. Maybe is a hardware issue.

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.

gokhannsahin
Associate II
Posted on January 08, 2018 at 10:24

‌ thank you for your suggestion, although tried on your link, the problem isn't still solved.

The kitwas bought yesterday and only that code was run on it. Furthermore, can't see any oscillation that is similar to 32768Khz in pins of crystal.

________________

Attachments :

issue.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy8f&d=%2Fa%2F0X0000000b4f%2F5INmfvPM3D62WutIn2kj8OxYJLVWjLoUsRBAaGdh334&asPdf=false
Posted on January 08, 2018 at 10:38

It could be a hw problem but your probe (osciloscope) may affect the circuit and prevents the LSE from starting anyway (during the time when the scope is connected to the circuit). I guess they use pretty low capacitors (4.7-10pF).

I want to say that LSE may does not work but connecting scope may also prevent it from starting so it i snot a prove that LSE is broken.

I can test it on my board but later after work.

Posted on January 08, 2018 at 18:36

Just generated simple CubeMX project for the STM32L476-DISCO board:

 

There are enabled LSE for RTC clocking, RTC and the time is displayed on the LCD.

The code is awful but seems to work without any issue.

Please note: the project is prepared to run in SRAM without flashing the board so if you want to use it without any modification start in in debugger.

If you want to flash it change the Target IROM settings to reflect real flash addresses.

It's for KEIL IDE.

gokhannsahin
Associate II
Posted on January 09, 2018 at 12:47

Golab.Piotr

‌ thank you, I break the crystal without knowing it when trying the 32768KHz in order to scope. I have tried to scope the only pin that is routed out of RTC (512Hz) not pins of crystal, finally, it run.Thank you again.:)