diff options
author | Damien George <damien.p.george@gmail.com> | 2018-07-31 17:25:53 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-07-31 17:25:53 +1000 |
commit | 21dae87710d8053b2283ef223cb33248bab107b3 (patch) | |
tree | 4d20fad99016f332dd3614c58361617186852b73 | |
parent | 9dfbb6cc169ab95f07876d97824fd2c3dae229a1 (diff) |
stm32/modmachine: Get machine.sleep working on F0 MCUs.
-rw-r--r-- | ports/stm32/modmachine.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index 639ee9fad..be36431cf 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -524,6 +524,20 @@ STATIC mp_obj_t machine_sleep(void) { // reconfigure the system clock after waking up + #if defined(STM32F0) + + // Enable HSI48 + __HAL_RCC_HSI48_ENABLE(); + while (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSI48RDY)) { + } + + // Select HSI48 as system clock source + MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_SYSCLKSOURCE_HSI48); + while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_HSI48) { + } + + #else + // enable HSE __HAL_RCC_HSE_CONFIG(MICROPY_HW_CLK_HSE_STATE); while (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) { @@ -545,6 +559,8 @@ STATIC mp_obj_t machine_sleep(void) { #endif + #endif + return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep); |