stm32: Allow a board to configure the HSE in bypass mode.
To use HSE bypass mode the board should define: #define MICROPY_HW_CLK_USE_BYPASS (1) If this is not defined, or is defined to 0, then HSE oscillator mode is used.
This commit is contained in:
parent
68b70fac5c
commit
cf9fc7346d
|
@ -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
|
// 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_OscInitTypeDef RCC_OscInitStruct;
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
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.PLLState = RCC_PLL_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||||
RCC_OscInitStruct.PLL.PLLM = m;
|
RCC_OscInitStruct.PLL.PLLM = m;
|
||||||
|
@ -500,7 +500,7 @@ STATIC mp_obj_t machine_sleep(void) {
|
||||||
// reconfigure the system clock after waking up
|
// reconfigure the system clock after waking up
|
||||||
|
|
||||||
// enable HSE
|
// 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)) {
|
while (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,13 @@
|
||||||
#error Unsupported MCU series
|
#error Unsupported MCU series
|
||||||
#endif
|
#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
|
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
|
||||||
// Provide block device macros if internal flash storage is enabled
|
// Provide block device macros if internal flash storage is enabled
|
||||||
#define MICROPY_HW_BDEV_IOCTL flash_bdev_ioctl
|
#define MICROPY_HW_BDEV_IOCTL flash_bdev_ioctl
|
||||||
|
|
|
@ -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
|
/* 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) */
|
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 */
|
/* Wait till HSE is ready */
|
||||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
|
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
|
||||||
|
|
|
@ -404,7 +404,7 @@ void SystemClock_Config(void)
|
||||||
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
||||||
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
|
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
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;
|
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
|
||||||
#if defined(STM32H7)
|
#if defined(STM32H7)
|
||||||
RCC_OscInitStruct.CSIState = RCC_CSI_OFF;
|
RCC_OscInitStruct.CSIState = RCC_CSI_OFF;
|
||||||
|
|
Loading…
Reference in New Issue