Skip to content

Commit d999a60

Browse files
committed
[WB] Move HSE Capacitor Tuning api to clock api file
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 64b7d90 commit d999a60

File tree

4 files changed

+56
-128
lines changed

4 files changed

+56
-128
lines changed

cores/arduino/stm32/clock.h

+14-36
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,15 @@
1-
/**
2-
******************************************************************************
3-
* @file clock.h
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
7-
* @brief Header for clock.c module
8-
******************************************************************************
9-
* @attention
10-
*
11-
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
12-
*
13-
* Redistribution and use in source and binary forms, with or without modification,
14-
* are permitted provided that the following conditions are met:
15-
* 1. Redistributions of source code must retain the above copyright notice,
16-
* this list of conditions and the following disclaimer.
17-
* 2. Redistributions in binary form must reproduce the above copyright notice,
18-
* this list of conditions and the following disclaimer in the documentation
19-
* and/or other materials provided with the distribution.
20-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
21-
* may be used to endorse or promote products derived from this software
22-
* without specific prior written permission.
23-
*
24-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34-
*
35-
******************************************************************************
36-
*/
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2016-2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
3713

3814
/* Define to prevent recursive inclusion -------------------------------------*/
3915
#ifndef __CLOCK_H
@@ -62,6 +38,8 @@ uint32_t getCurrentMillis(void);
6238
uint32_t getCurrentMicros(void);
6339

6440
void enableClock(sourceClock_t source);
41+
void configHSECapacitorTuning(void);
42+
6543
#ifdef __cplusplus
6644
}
6745
#endif

libraries/SrcWrapper/src/stm32/clock.c

+26-37
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,20 @@
1-
/**
2-
******************************************************************************
3-
* @file clock.c
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
7-
* @brief provide clock services for time purpose
8-
*
9-
******************************************************************************
10-
* @attention
11-
*
12-
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
13-
*
14-
* Redistribution and use in source and binary forms, with or without modification,
15-
* are permitted provided that the following conditions are met:
16-
* 1. Redistributions of source code must retain the above copyright notice,
17-
* this list of conditions and the following disclaimer.
18-
* 2. Redistributions in binary form must reproduce the above copyright notice,
19-
* this list of conditions and the following disclaimer in the documentation
20-
* and/or other materials provided with the distribution.
21-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
22-
* may be used to endorse or promote products derived from this software
23-
* without specific prior written permission.
24-
*
25-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35-
*
36-
******************************************************************************
37-
*/
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2016-2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
3813
#include "backup.h"
3914
#include "clock.h"
15+
#include "otp.h"
4016
#include "stm32yyxx_ll_cortex.h"
17+
#include "stm32yyxx_ll_rcc.h"
4118

4219
#ifdef __cplusplus
4320
extern "C" {
@@ -160,6 +137,18 @@ void enableClock(sourceClock_t source)
160137
}
161138
}
162139

140+
void configHSECapacitorTuning(void)
141+
{
142+
#if defined(OTP_AREA_BASE) && defined(STM32WBxx)
143+
OTP_BT_t *p_otp;
144+
/* Read HSE_Tuning from OTP with index 0 */
145+
p_otp = (OTP_BT_t *) OTP_Read(0);
146+
if ((p_otp) && (!LL_RCC_HSE_IsReady())) {
147+
LL_RCC_HSE_SetCapacitorTuning(p_otp->hse_tuning);
148+
}
149+
#endif
150+
}
151+
163152
#ifdef __cplusplus
164153
}
165154
#endif

libraries/SrcWrapper/src/stm32/hw_config.c

+16-39
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,19 @@
1-
/**
2-
******************************************************************************
3-
* @file hw_config.c
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
7-
* @brief provide some hw interface for the Arduino interface
8-
*
9-
******************************************************************************
10-
* @attention
11-
*
12-
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
13-
*
14-
* Redistribution and use in source and binary forms, with or without modification,
15-
* are permitted provided that the following conditions are met:
16-
* 1. Redistributions of source code must retain the above copyright notice,
17-
* this list of conditions and the following disclaimer.
18-
* 2. Redistributions in binary form must reproduce the above copyright notice,
19-
* this list of conditions and the following disclaimer in the documentation
20-
* and/or other materials provided with the distribution.
21-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
22-
* may be used to endorse or promote products derived from this software
23-
* without specific prior written permission.
24-
*
25-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35-
*
36-
******************************************************************************
37-
*/
38-
#include "stm32_def.h"
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2016-2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
#include "dwt.h"
3914
#include "hw_config.h"
15+
#include "clock.h"
4016
#include "usbd_if.h"
41-
#include "dwt.h"
4217

4318
#ifdef __cplusplus
4419
extern "C" {
@@ -63,6 +38,8 @@ void hw_config_init(void)
6338
__HAL_RCC_HSEM_CLK_ENABLE();
6439
#endif
6540

41+
configHSECapacitorTuning();
42+
6643
/* Configure the system clock */
6744
SystemClock_Config();
6845

variants/PNUCLEO_WB55RG/variant.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "pins_arduino.h"
20-
#include "otp.h"
2120

2221
#ifdef __cplusplus
2322
extern "C" {
@@ -89,19 +88,6 @@ const PinName digitalPin[] = {
8988
extern "C" {
9089
#endif
9190

92-
static void Config_HSE(void)
93-
{
94-
OTP_BT_t *p_otp;
95-
96-
/**
97-
* Read HSE_Tuning from OTP
98-
*/
99-
p_otp = (OTP_BT_t *) OTP_Read(0);
100-
if (p_otp) {
101-
LL_RCC_HSE_SetCapacitorTuning(p_otp->hse_tuning);
102-
}
103-
}
104-
10591
/**
10692
* @brief System Clock Configuration
10793
* @param None
@@ -113,8 +99,6 @@ WEAK void SystemClock_Config(void)
11399
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
114100
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
115101

116-
Config_HSE();
117-
118102
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
119103
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
120104

0 commit comments

Comments
 (0)