Skip to content

Commit

Permalink
Merge pull request #8 from farmblox/farmblox-main
Browse files Browse the repository at this point in the history
Add MSI LSE auto calibration and ABD
  • Loading branch information
diggerdata authored Feb 27, 2025
2 parents 2344bb7 + 83d1bbe commit 112056b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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 @@ -628,6 +628,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 @@ -892,4 +897,4 @@ int serial_is_tx_ongoing(void)
return 0;
}

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

0 comments on commit 112056b

Please sign in to comment.