summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/stm32/modmachine.c4
-rw-r--r--ports/stm32/mpconfigboard_common.h7
-rw-r--r--ports/stm32/stm32_it.c2
-rw-r--r--ports/stm32/system_stm32.c2
4 files changed, 11 insertions, 4 deletions
diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c
index 02a6f2a4b..6b7849bb9 100644
--- a/ports/stm32/modmachine.c
+++ b/ports/stm32/modmachine.c
@@ -377,7 +377,7 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
// even if we don't use the PLL for the system clock, we still need it for USB, RNG and SDIO
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+ RCC_OscInitStruct.HSEState = MICROPY_HW_CLK_HSE_STATE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = m;
@@ -500,7 +500,7 @@ STATIC mp_obj_t machine_sleep(void) {
// reconfigure the system clock after waking up
// enable HSE
- __HAL_RCC_HSE_CONFIG(RCC_HSE_ON);
+ __HAL_RCC_HSE_CONFIG(MICROPY_HW_CLK_HSE_STATE);
while (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) {
}
diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h
index 5f3ac164d..857457fdb 100644
--- a/ports/stm32/mpconfigboard_common.h
+++ b/ports/stm32/mpconfigboard_common.h
@@ -136,6 +136,13 @@
#error Unsupported MCU series
#endif
+// Configure HSE for bypass or oscillator
+#if MICROPY_HW_CLK_USE_BYPASS
+#define MICROPY_HW_CLK_HSE_STATE (RCC_HSE_BYPASS)
+#else
+#define MICROPY_HW_CLK_HSE_STATE (RCC_HSE_ON)
+#endif
+
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
// Provide block device macros if internal flash storage is enabled
#define MICROPY_HW_BDEV_IOCTL flash_bdev_ioctl
diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c
index 04abfd211..db812958f 100644
--- a/ports/stm32/stm32_it.c
+++ b/ports/stm32/stm32_it.c
@@ -369,7 +369,7 @@ STATIC void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) {
/* Configures system clock after wake-up from STOP: enable HSE, PLL and select
PLL as system clock source (HSE and PLL are disabled in STOP mode) */
- __HAL_RCC_HSE_CONFIG(RCC_HSE_ON);
+ __HAL_RCC_HSE_CONFIG(MICROPY_HW_CLK_HSE_STATE);
/* Wait till HSE is ready */
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
diff --git a/ports/stm32/system_stm32.c b/ports/stm32/system_stm32.c
index 251902259..70bbb2a8b 100644
--- a/ports/stm32/system_stm32.c
+++ b/ports/stm32/system_stm32.c
@@ -404,7 +404,7 @@ void SystemClock_Config(void)
/* Enable HSE Oscillator and activate PLL with HSE as source */
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+ RCC_OscInitStruct.HSEState = MICROPY_HW_CLK_HSE_STATE;
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
#if defined(STM32H7)
RCC_OscInitStruct.CSIState = RCC_CSI_OFF;