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 */
37
36
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
37
75
38
static void Config_HSE (void )
76
39
{
@@ -102,22 +65,27 @@ void SetSysClock(void)
102
65
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0 };
103
66
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0 };
104
67
68
+ __HAL_RCC_HSEM_CLK_ENABLE ();
69
+
105
70
while (LL_HSEM_1StepLock (HSEM , CFG_HW_RCC_SEMID ));
106
71
107
72
Config_HSE ();
108
73
109
- /* Configure the main internal regulator output voltage */
74
+ __HAL_RCC_LSEDRIVE_CONFIG ( RCC_LSEDRIVE_LOW );
110
75
__HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1 );
111
76
112
77
/* 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 ;
114
79
RCC_OscInitStruct .HSEState = RCC_HSE_ON ;
115
80
RCC_OscInitStruct .HSIState = RCC_HSI_ON ;
81
+ RCC_OscInitStruct .HSI48State = RCC_HSI48_ON ;
82
+ RCC_OscInitStruct .LSEState = RCC_LSE_ON ;
116
83
RCC_OscInitStruct .HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT ;
117
84
RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
118
85
if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
119
86
error ("HAL_RCC_OscConfig error\n" );
120
87
}
88
+
121
89
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
122
90
*/
123
91
RCC_ClkInitStruct .ClockType = RCC_CLOCKTYPE_HCLK4 | RCC_CLOCKTYPE_HCLK2
@@ -129,33 +97,27 @@ void SetSysClock(void)
129
97
RCC_ClkInitStruct .APB2CLKDivider = RCC_HCLK_DIV1 ;
130
98
RCC_ClkInitStruct .AHBCLK2Divider = RCC_SYSCLK_DIV1 ;
131
99
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 ) {
134
101
error ("HAL_RCC_ClockConfig error\n" );
135
102
}
103
+
136
104
/** Initializes the peripherals clocks
137
105
*/
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 ;
139
109
PeriphClkInitStruct .SmpsClockSelection = RCC_SMPSCLKSOURCE_HSE ;
140
- PeriphClkInitStruct .SmpsDivSelection = RCC_SMPSCLKDIV_RANGE0 ;
141
-
110
+ PeriphClkInitStruct .SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1 ;
142
111
if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct ) != HAL_OK ) {
143
112
error ("HAL_RCCEx_PeriphCLKConfig error\n" );
144
113
}
145
114
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();
150
118
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 );
159
121
160
122
LL_HSEM_ReleaseLock (HSEM , CFG_HW_RCC_SEMID , 0 );
161
123
}
0 commit comments