Skip to content

Commit

Permalink
[WB] Move HSE Capacitor Tuning api to clock api file
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Feb 2, 2021
1 parent 64b7d90 commit 67c78b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions cores/arduino/stm32/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ uint32_t getCurrentMillis(void);
uint32_t getCurrentMicros(void);

void enableClock(sourceClock_t source);
void configHSECapacitorTuning(void);

#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 14 additions & 0 deletions libraries/SrcWrapper/src/stm32/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
*/
#include "backup.h"
#include "clock.h"
#include "otp.h"
#include "stm32yyxx_ll_cortex.h"
#include "stm32yyxx_ll_rcc.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -160,6 +162,18 @@ void enableClock(sourceClock_t source)
}
}

void configHSECapacitorTuning(void)
{
#if defined(OTP_AREA_BASE) && defined(STM32WBxx)
OTP_BT_t *p_otp;
/* Read HSE_Tuning from OTP with index 0 */
p_otp = (OTP_BT_t *) OTP_Read(0);
if (p_otp) {
LL_RCC_HSE_SetCapacitorTuning(p_otp->hse_tuning);
}
#endif
}

#ifdef __cplusplus
}
#endif
Expand Down
17 changes: 2 additions & 15 deletions variants/PNUCLEO_WB55RG/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include "pins_arduino.h"
#include "otp.h"
#include "clock.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -89,19 +89,6 @@ const PinName digitalPin[] = {
extern "C" {
#endif

static void Config_HSE(void)
{
OTP_BT_t *p_otp;

/**
* Read HSE_Tuning from OTP
*/
p_otp = (OTP_BT_t *) OTP_Read(0);
if (p_otp) {
LL_RCC_HSE_SetCapacitorTuning(p_otp->hse_tuning);
}
}

/**
* @brief System Clock Configuration
* @param None
Expand All @@ -113,7 +100,7 @@ WEAK void SystemClock_Config(void)
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};

Config_HSE();
configHSECapacitorTuning();

__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
Expand Down

0 comments on commit 67c78b9

Please sign in to comment.