11/* mbed Microcontroller Library
22 * Copyright (c) 2019 ARM Limited
3+ * Copyright (c) 2019 STMicroelectronics
34 * SPDX-License-Identifier: Apache-2.0
45 *
56 * Licensed under the Apache License, Version 2.0 (the "License");
3132#include "stm32wbxx.h"
3233#include "mbed_error.h"
3334#include "stm32wbxx_ll_hsem.h"
34- #include "stm32wbxx_ll_hsem.h"
3535#include "otp.h"
36- #include "hw_conf.h" /* Common BLE file where BLE shared resources are defined */
3736
38- static void Configure_RF_Clock_Sources (void )
39- {
40- static uint8_t RF_ON = 0 ;
41-
42- if (!RF_ON ) {
43- // Reset backup domain
44- if ((LL_RCC_IsActiveFlag_PINRST ()) && (!LL_RCC_IsActiveFlag_SFTRST ())) {
45- // Write twice the value to flush the APB-AHB bridge
46- // This bit shall be written in the register before writing the next one
47- HAL_PWR_EnableBkUpAccess ();
48- HAL_PWR_EnableBkUpAccess ();
49- __HAL_RCC_BACKUPRESET_FORCE ();
50- __HAL_RCC_BACKUPRESET_RELEASE ();
51- }
52-
53- /**
54- * Select LSE clock
55- */
56- LL_RCC_LSE_Enable ();
57- while (!LL_RCC_LSE_IsReady ());
58-
59- /**
60- * Select wakeup source of BLE RF
61- */
62- LL_RCC_SetRFWKPClockSource (LL_RCC_RFWKP_CLKSOURCE_LSE );
63-
64- /**
65- * Switch OFF LSI
66- */
67- LL_RCC_LSI1_Disable ();
68-
69- RF_ON = 1 ;
70- }
71-
72- return ;
73- }
7437
7538static void Config_HSE (void )
7639{
@@ -102,22 +65,27 @@ void SetSysClock(void)
10265 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0 };
10366 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0 };
10467
68+ __HAL_RCC_HSEM_CLK_ENABLE ();
69+
10570 while (LL_HSEM_1StepLock (HSEM , CFG_HW_RCC_SEMID ));
10671
10772 Config_HSE ();
10873
109- /* Configure the main internal regulator output voltage */
74+ __HAL_RCC_LSEDRIVE_CONFIG ( RCC_LSEDRIVE_LOW );
11075 __HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1 );
11176
11277 /* Initializes the CPU, AHB and APB busses clocks */
113- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE ;
78+ RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE ;
11479 RCC_OscInitStruct .HSEState = RCC_HSE_ON ;
11580 RCC_OscInitStruct .HSIState = RCC_HSI_ON ;
81+ RCC_OscInitStruct .HSI48State = RCC_HSI48_ON ;
82+ RCC_OscInitStruct .LSEState = RCC_LSE_ON ;
11683 RCC_OscInitStruct .HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT ;
11784 RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
11885 if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
11986 error ("HAL_RCC_OscConfig error\n" );
12087 }
88+
12189 /** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
12290 */
12391 RCC_ClkInitStruct .ClockType = RCC_CLOCKTYPE_HCLK4 | RCC_CLOCKTYPE_HCLK2
@@ -129,33 +97,27 @@ void SetSysClock(void)
12997 RCC_ClkInitStruct .APB2CLKDivider = RCC_HCLK_DIV1 ;
13098 RCC_ClkInitStruct .AHBCLK2Divider = RCC_SYSCLK_DIV1 ;
13199 RCC_ClkInitStruct .AHBCLK4Divider = RCC_SYSCLK_DIV1 ;
132-
133- if (HAL_RCC_ClockConfig (& RCC_ClkInitStruct , FLASH_LATENCY_1 ) != HAL_OK ) {
100+ if (HAL_RCC_ClockConfig (& RCC_ClkInitStruct , FLASH_LATENCY_3 ) != HAL_OK ) {
134101 error ("HAL_RCC_ClockConfig error\n" );
135102 }
103+
136104 /** Initializes the peripherals clocks
137105 */
138- PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_SMPS ;
106+ PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_SMPS | RCC_PERIPHCLK_RFWAKEUP | RCC_PERIPHCLK_RNG ;
107+ PeriphClkInitStruct .RngClockSelection = RCC_RNGCLKSOURCE_HSI48 ;
108+ PeriphClkInitStruct .RFWakeUpClockSelection = RCC_RFWKPCLKSOURCE_LSE ;
139109 PeriphClkInitStruct .SmpsClockSelection = RCC_SMPSCLKSOURCE_HSE ;
140- PeriphClkInitStruct .SmpsDivSelection = RCC_SMPSCLKDIV_RANGE0 ;
141-
110+ PeriphClkInitStruct .SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1 ;
142111 if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct ) != HAL_OK ) {
143112 error ("HAL_RCCEx_PeriphCLKConfig error\n" );
144113 }
145114
146- /**
147- * Select HSI as system clock source after Wake Up from Stop mode
148- */
149- LL_RCC_SetClkAfterWakeFromStop (LL_RCC_STOP_WAKEUPCLOCK_HSI );
115+ LL_PWR_SMPS_SetStartupCurrent (LL_PWR_SMPS_STARTUP_CURRENT_80MA );
116+ LL_PWR_SMPS_SetOutputVoltageLevel (LL_PWR_SMPS_OUTPUT_VOLTAGE_1V40 );
117+ // LL_PWR_SMPS_Enable();
150118
151- /**
152- * Set RNG on HSI48
153- */
154- LL_RCC_HSI48_Enable ();
155- while (!LL_RCC_HSI48_IsReady ());
156- LL_RCC_SetCLK48ClockSource (LL_RCC_CLK48_CLKSOURCE_HSI48 );
157-
158- Configure_RF_Clock_Sources ();
119+ /* Select HSI as system clock source after Wake Up from Stop mode */
120+ LL_RCC_SetClkAfterWakeFromStop (LL_RCC_STOP_WAKEUPCLOCK_HSI );
159121
160122 LL_HSEM_ReleaseLock (HSEM , CFG_HW_RCC_SEMID , 0 );
161123}
0 commit comments