Skip to content

Commit

Permalink
Add MSI LSE auto calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
diggerdata committed Dec 10, 2024
1 parent befcd87 commit 3816faf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions targets/TARGET_STM/TARGET_STM32WL/system_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ MBED_WEAK void SetSysClock(void)
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

#if MBED_CONF_TARGET_LSE_AVAILABLE
// Enable LSE Oscillator to automatically calibrate the MSI clock
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // No PLL update
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC32_IN/OSC32_OUT
MBED_ASSERT(HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK);
#endif

/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
Expand All @@ -54,6 +63,11 @@ MBED_WEAK void SetSysClock(void)
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
MBED_ASSERT(HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK);

#if MBED_CONF_TARGET_LSE_AVAILABLE
HAL_RCCEx_EnableMSIPLLMode();
#endif

/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3 | RCC_CLOCKTYPE_HCLK
Expand All @@ -66,4 +80,6 @@ MBED_WEAK void SetSysClock(void)
RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;
MBED_ASSERT(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) == HAL_OK);
/* Peripheral clock enable */

// HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);
}
5 changes: 5 additions & 0 deletions targets/TARGET_STM/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,11 @@ HAL_StatusTypeDef init_uart(serial_t *obj)
huart->TxXferSize = 0;
huart->RxXferCount = 0;
huart->RxXferSize = 0;
#if defined(UART_AUTO_BAUD_RATE)
huart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_AUTOBAUDRATE_INIT;
huart->AdvancedInit.AutoBaudRateEnable = UART_ADVFEATURE_AUTOBAUDRATE_ENABLE;
huart->AdvancedInit.AutoBaudRateMode = UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT;
#endif
#if defined(UART_ONE_BIT_SAMPLE_DISABLE) // F0/F3/F7/G0/H7/L0/L4/L5/WB
huart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
#endif
Expand Down

0 comments on commit 3816faf

Please sign in to comment.