1
1
/* mbed Microcontroller Library
2
2
* Copyright (c) 2019 ARM Limited
3
+ * Copyright (c) 2019 STMicroelectronics
3
4
* SPDX-License-Identifier: Apache-2.0
4
5
*
5
6
* Licensed under the Apache License, Version 2.0 (the "License");
31
32
#include "stm32wbxx.h"
32
33
#include "mbed_error.h"
33
34
#include "stm32wbxx_ll_hsem.h"
34
- #include "stm32wbxx_ll_hsem.h"
35
35
#include "otp.h"
36
- #include "hw_conf.h" /* Common BLE file where BLE shared resources are defined */
36
+ // #include "hw_conf.h" /* Common BLE file where BLE shared resources are defined */
37
37
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
- }
74
38
75
39
static void Config_HSE (void )
76
40
{
@@ -102,22 +66,27 @@ void SetSysClock(void)
102
66
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0 };
103
67
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0 };
104
68
69
+ __HAL_RCC_HSEM_CLK_ENABLE ();
70
+
105
71
while (LL_HSEM_1StepLock (HSEM , CFG_HW_RCC_SEMID ));
106
72
107
73
Config_HSE ();
108
74
109
- /* Configure the main internal regulator output voltage */
75
+ __HAL_RCC_LSEDRIVE_CONFIG ( RCC_LSEDRIVE_LOW );
110
76
__HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1 );
111
77
112
78
/* Initializes the CPU, AHB and APB busses clocks */
113
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE ;
79
+ RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE ;
114
80
RCC_OscInitStruct .HSEState = RCC_HSE_ON ;
115
81
RCC_OscInitStruct .HSIState = RCC_HSI_ON ;
82
+ RCC_OscInitStruct .HSI48State = RCC_HSI48_ON ;
83
+ RCC_OscInitStruct .LSEState = RCC_LSE_ON ;
116
84
RCC_OscInitStruct .HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT ;
117
85
RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
118
86
if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
119
87
error ("HAL_RCC_OscConfig error\n" );
120
88
}
89
+
121
90
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
122
91
*/
123
92
RCC_ClkInitStruct .ClockType = RCC_CLOCKTYPE_HCLK4 | RCC_CLOCKTYPE_HCLK2
@@ -129,33 +98,27 @@ void SetSysClock(void)
129
98
RCC_ClkInitStruct .APB2CLKDivider = RCC_HCLK_DIV1 ;
130
99
RCC_ClkInitStruct .AHBCLK2Divider = RCC_SYSCLK_DIV1 ;
131
100
RCC_ClkInitStruct .AHBCLK4Divider = RCC_SYSCLK_DIV1 ;
132
-
133
- if (HAL_RCC_ClockConfig (& RCC_ClkInitStruct , FLASH_LATENCY_1 ) != HAL_OK ) {
101
+ if (HAL_RCC_ClockConfig (& RCC_ClkInitStruct , FLASH_LATENCY_3 ) != HAL_OK ) {
134
102
error ("HAL_RCC_ClockConfig error\n" );
135
103
}
104
+
136
105
/** Initializes the peripherals clocks
137
106
*/
138
- PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_SMPS ;
107
+ PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_SMPS | RCC_PERIPHCLK_RFWAKEUP | RCC_PERIPHCLK_RNG ;
108
+ PeriphClkInitStruct .RngClockSelection = RCC_RNGCLKSOURCE_HSI48 ;
109
+ PeriphClkInitStruct .RFWakeUpClockSelection = RCC_RFWKPCLKSOURCE_LSE ;
139
110
PeriphClkInitStruct .SmpsClockSelection = RCC_SMPSCLKSOURCE_HSE ;
140
- PeriphClkInitStruct .SmpsDivSelection = RCC_SMPSCLKDIV_RANGE0 ;
141
-
111
+ PeriphClkInitStruct .SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1 ;
142
112
if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct ) != HAL_OK ) {
143
113
error ("HAL_RCCEx_PeriphCLKConfig error\n" );
144
114
}
145
115
146
- /**
147
- * Select HSI as system clock source after Wake Up from Stop mode
148
- */
149
- LL_RCC_SetClkAfterWakeFromStop (LL_RCC_STOP_WAKEUPCLOCK_HSI );
116
+ LL_PWR_SMPS_SetStartupCurrent (LL_PWR_SMPS_STARTUP_CURRENT_80MA );
117
+ LL_PWR_SMPS_SetOutputVoltageLevel (LL_PWR_SMPS_OUTPUT_VOLTAGE_1V40 );
118
+ // LL_PWR_SMPS_Enable();
150
119
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 ();
120
+ /* Select HSI as system clock source after Wake Up from Stop mode */
121
+ LL_RCC_SetClkAfterWakeFromStop (LL_RCC_STOP_WAKEUPCLOCK_HSI );
159
122
160
123
LL_HSEM_ReleaseLock (HSEM , CFG_HW_RCC_SEMID , 0 );
161
124
}
0 commit comments