1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-12 19:10:32 +03:00

Properly handle HSI if selected (#14259)

* Properly handle HSI if selected

In some places, PERSISTENT_OBJECT_HSE_VALUE being zero is used to imply that the MCU should be clocked from HSI, but the code doesn't really follow through and results in an invalid clock tree setup.

The proposed changes should fix this.

* Apply suggestions from code review

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>

* Update system_stm32g4xx.c

HSI should now be implicitly selected when SYSTEM_HSE_MHZ is defined as 0 or omitted in the target config.

USE_CLOCK_SOURCE_HSI is not necessary.

* Update src/platform/STM32/startup/system_stm32g4xx.c

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>

* Update src/platform/STM32/startup/system_stm32g4xx.c

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>

---------

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>
Co-authored-by: Petr Ledvina <ledvinap@gmail.com>
This commit is contained in:
crteensy 2025-02-27 13:46:26 +01:00 committed by GitHub
parent a801aadf9c
commit d8cd6b743b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -118,7 +118,6 @@ void SystemInit(void)
void SystemCoreClockUpdate(void)
{
uint32_t hse_value = persistentObjectRead(PERSISTENT_OBJECT_HSE_VALUE);
uint32_t tmp, pllvco, pllr, pllsource, pllm;
/* Get SYSCLK source -------------------------------------------------------*/
@ -381,10 +380,12 @@ void SystemClock_Config(void)
// Initializes the CPU, AHB and APB busses clocks
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48
|RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
const bool useHse = persistentObjectRead(PERSISTENT_OBJECT_HSE_VALUE) != 0;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48
| RCC_OSCILLATORTYPE_LSI
| (useHse ? RCC_OSCILLATORTYPE_HSE : 0);
RCC_OscInitStruct.HSEState = useHse ? RCC_HSE_ON : RCC_HSE_OFF;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;