Skip to content

Commit da9bfb8

Browse files
committed
Change the SystemClock_Config for BLE on this nucleo_wb55rg
enabling IPCC module of the stm32WB55 to support with the correct Peripheral CLK Config and otp which contains the device bd address Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 95e58e6 commit da9bfb8

File tree

3 files changed

+143
-58
lines changed

3 files changed

+143
-58
lines changed

variants/PNUCLEO_WB55RG/otp.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
******************************************************************************
3+
* @file otp.h
4+
* @author MCD Application Team
5+
* @brief OTP manager interface
6+
******************************************************************************
7+
* @attention
8+
*
9+
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10+
* All rights reserved.</center></h2>
11+
*
12+
* This software component is licensed by ST under BSD 3-Clause license,
13+
* the "License"; You may not use this file except in compliance with the
14+
* License. You may obtain a copy of the License at:
15+
* opensource.org/licenses/BSD-3-Clause
16+
*
17+
******************************************************************************
18+
*/
19+
20+
21+
/* Define to prevent recursive inclusion -------------------------------------*/
22+
#ifndef __OTP_H
23+
#define __OTP_H
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/* Includes ------------------------------------------------------------------*/
30+
/* ----------------------------------- *
31+
* Packed usage (compiler dependent) *
32+
* ----------------------------------- */
33+
#undef PACKED__
34+
#undef PACKED_STRUCT
35+
36+
typedef struct __packed {
37+
uint8_t bd_address[6];
38+
uint8_t hse_tuning;
39+
uint8_t id;
40+
} OTP_ID0_t;
41+
42+
/* Exported constants --------------------------------------------------------*/
43+
#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE
44+
45+
#define CFG_OTP_END_ADDRESS OTP_AREA_END_ADDR
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif /*__OTP_H */
52+
53+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

variants/PNUCLEO_WB55RG/variant.cpp

Lines changed: 88 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "pins_arduino.h"
20+
#include "otp.h"
2021

2122
#ifdef __cplusplus
2223
extern "C" {
@@ -88,71 +89,100 @@ const PinName digitalPin[] = {
8889
extern "C" {
8990
#endif
9091

92+
static uint8_t * OTP_Read( uint8_t id )
93+
{
94+
uint8_t *p_id;
95+
96+
p_id = (uint8_t*)(CFG_OTP_END_ADDRESS - 7) ;
97+
98+
while( ((*( p_id + 7 )) != id) && ( p_id != (uint8_t*)CFG_OTP_BASE_ADDRESS) )
99+
{
100+
p_id -= 8 ;
101+
}
102+
103+
if((*( p_id + 7 )) != id)
104+
{
105+
p_id = 0 ;
106+
}
107+
108+
return p_id ;
109+
}
110+
111+
static void Config_HSE(void)
112+
{
113+
OTP_ID0_t *p_otp;
114+
115+
/**
116+
* Read HSE_Tuning from OTP
117+
*/
118+
p_otp = (OTP_ID0_t *) OTP_Read(0);
119+
if (p_otp) {
120+
LL_RCC_HSE_SetCapacitorTuning(p_otp->hse_tuning);
121+
}
122+
}
123+
91124
/**
92125
* @brief System Clock Configuration
93126
* @param None
94127
* @retval None
95128
*/
96129
WEAK void SystemClock_Config(void)
97130
{
98-
RCC_OscInitTypeDef RCC_OscInitStruct = {};
99-
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
100-
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
101-
102-
/* Configure LSE Drive Capability */
103-
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
104-
/* Configure the main internal regulator output voltage */
105-
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
106-
/* Initializes the CPU, AHB and APB busses clocks */
107-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE
108-
| RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI;
109-
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
110-
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
111-
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
112-
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
113-
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
114-
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
115-
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
116-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
117-
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
118-
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
119-
RCC_OscInitStruct.PLL.PLLN = 32;
120-
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
121-
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
122-
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
123-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
124-
Error_Handler();
125-
}
126-
/* Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers */
127-
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK4 | RCC_CLOCKTYPE_HCLK2
128-
| RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
129-
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
130-
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
131-
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
132-
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
133-
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
134-
RCC_ClkInitStruct.AHBCLK2Divider = RCC_SYSCLK_DIV2;
135-
RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;
136-
137-
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) {
138-
Error_Handler();
139-
}
140-
/* Initializes the peripherals clocks */
141-
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS | RCC_PERIPHCLK_USB;
142-
PeriphClkInitStruct.PLLSAI1.PLLN = 24;
143-
PeriphClkInitStruct.PLLSAI1.PLLP = RCC_PLLP_DIV2;
144-
PeriphClkInitStruct.PLLSAI1.PLLQ = RCC_PLLQ_DIV2;
145-
PeriphClkInitStruct.PLLSAI1.PLLR = RCC_PLLR_DIV2;
146-
PeriphClkInitStruct.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_USBCLK;
147-
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
148-
PeriphClkInitStruct.SmpsClockSelection = RCC_SMPSCLKSOURCE_HSI;
149-
PeriphClkInitStruct.SmpsDivSelection = RCC_SMPSCLKDIV_RANGE0;
150-
151-
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
152-
Error_Handler();
153-
}
154-
/* Enable MSI Auto calibration */
155-
HAL_RCCEx_EnableMSIPLLMode();
131+
RCC_OscInitTypeDef RCC_OscInitStruct = {};
132+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
133+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
134+
135+
Config_HSE();
136+
137+
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
138+
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
139+
140+
/* Initializes the CPU, AHB and APB busses clocks */
141+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE;
142+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
143+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
144+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
145+
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
146+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
147+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
148+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
149+
Error_Handler();
150+
}
151+
152+
/* Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers */
153+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK4 | RCC_CLOCKTYPE_HCLK2
154+
| RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
155+
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
156+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
157+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
158+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
159+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
160+
RCC_ClkInitStruct.AHBCLK2Divider = RCC_SYSCLK_DIV1;
161+
RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;
162+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
163+
Error_Handler();
164+
}
165+
166+
/* Initializes the peripherals clocks */
167+
/* RNG needs to be configured like in M0 core, i.e. with HSI48 */
168+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SMPS | RCC_PERIPHCLK_RFWAKEUP |
169+
RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_USB;
170+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
171+
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_HSI48;
172+
PeriphClkInitStruct.RFWakeUpClockSelection = RCC_RFWKPCLKSOURCE_LSE;
173+
PeriphClkInitStruct.SmpsClockSelection = RCC_SMPSCLKSOURCE_HSE;
174+
PeriphClkInitStruct.SmpsDivSelection = RCC_SMPSCLKDIV_RANGE1;
175+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
176+
Error_Handler();
177+
}
178+
179+
LL_PWR_SMPS_SetStartupCurrent(LL_PWR_SMPS_STARTUP_CURRENT_80MA);
180+
LL_PWR_SMPS_SetOutputVoltageLevel(LL_PWR_SMPS_OUTPUT_VOLTAGE_1V40);
181+
LL_PWR_SMPS_Enable();
182+
183+
/* Select HSI as system clock source after Wake Up from Stop mode */
184+
LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI);
185+
156186
}
157187

158188
#ifdef __cplusplus

variants/PNUCLEO_WB55RG/variant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ extern "C" {
120120
// for EEPROM emulation to the last 512k pages.
121121
#define FLASH_PAGE_NUMBER 127
122122

123+
#define HAL_IPCC_MODULE_ENABLED
124+
123125
#ifdef __cplusplus
124126
} // extern "C"
125127
#endif

0 commit comments

Comments
 (0)