Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MSI LSE auto calibration and ABD #8

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion 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);
}
7 changes: 6 additions & 1 deletion 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 Expand Up @@ -890,4 +895,4 @@ int serial_is_tx_ongoing(void)
return 0;
}

#endif /* DEVICE_SERIAL */
#endif /* DEVICE_SERIAL */
Loading