@@ -42,7 +42,7 @@ extern void SetSysClock(void);
4242# if defined(MBED_CONF_TARGET_LSE_DRIVE_LOAD_LEVEL )
4343# define LSE_DRIVE_LOAD_LEVEL MBED_CONF_TARGET_LSE_DRIVE_LOAD_LEVEL
4444# else
45- # if defined(RCC_LSE_HIGHDRIVE_MODE )
45+ # if defined(RCC_LSE_HIGHDRIVE_MODE ) // STM32F4
4646# define LSE_DRIVE_LOAD_LEVEL RCC_LSE_LOWPOWER_MODE
4747# else
4848# define LSE_DRIVE_LOAD_LEVEL RCC_LSEDRIVE_LOW
@@ -70,17 +70,6 @@ extern void SetSysClock(void);
7070 */
7171
7272static void LSEDriveConfig (void ) {
73- // this config can be changed only when LSE is stopped
74- // LSE could be enabled before a reset and will remain running, disable first
75- RCC_OscInitTypeDef RCC_OscInitStruct = {0 };
76- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSE ;
77- RCC_OscInitStruct .LSEState = RCC_LSE_OFF ;
78- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK )
79- {
80- error ("LSEDriveConfig : failed to disable LSE\n" );
81- }
82-
83- // set LSE drive level. Exception only for F4_g2 series
8473 HAL_PWR_EnableBkUpAccess ();
8574 #if defined(__HAL_RCC_LSEDRIVE_CONFIG )
8675 __HAL_RCC_LSEDRIVE_CONFIG (LSE_DRIVE_LOAD_LEVEL );
@@ -180,9 +169,10 @@ void mbed_sdk_init()
180169 /* Configure the System clock source, PLL Multiplier and Divider factors,
181170 AHB/APBx prescalers and Flash settings */
182171#if defined(LSE_CONFIG_AVAILABLE )
183- // LSE maybe used later, but crystal load drive setting is necessary before
184- // enabling LSE
185- LSEDriveConfig ();
172+ // LSE oscillator drive capability set before LSE is started
173+ if (!LL_RCC_LSE_IsReady ()) {
174+ LSEDriveConfig ();
175+ }
186176#endif
187177 SetSysClock ();
188178 SystemCoreClockUpdate ();
@@ -199,16 +189,19 @@ void mbed_sdk_init()
199189 /* wait until CPU2 wakes up from stop mode */
200190 while (LL_RCC_D2CK_IsReady () == 0 );
201191#endif /* CORE_M4 */
192+
202193#else /* Single core */
203194 // Update the SystemCoreClock variable.
204195 SystemCoreClockUpdate ();
205196 HAL_Init ();
206197
207- /* Configure the System clock source, PLL Multiplier and Divider factors,
208- AHB/APBx prescalers and Flash settings */
209198#if defined(LSE_CONFIG_AVAILABLE )
210- LSEDriveConfig ();
199+ // LSE oscillator drive capability set before LSE is started
200+ if (!LL_RCC_LSE_IsReady ()) {
201+ LSEDriveConfig ();
202+ }
211203#endif
204+
212205 SetSysClock ();
213206 SystemCoreClockUpdate ();
214207#endif /* DUAL_CORE */
0 commit comments