Skip to content

Commit eb12fa3

Browse files
chrismas9dpgeorge
authored andcommitted
stm32/powerctrlboot: Add support for HSI at 8MHz on F0 MCUs.
For use with F0 MCUs that don't have HSI48. Select the clock source explicitly in mpconfigboard.h. On the NUCLEO_F091RC board use HSE bypass when HSE is chosen because the NUCLEO clock source is STLINK not a crystal.
1 parent f16e4be commit eb12fa3

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616
#define MICROPY_HW_ENABLE_TIMER (1)
1717
#define MICROPY_HW_HAS_SWITCH (1)
1818

19-
// For system clock, board uses internal 48MHz, HSI48
20-
#define MICROPY_HW_CLK_USE_HSI48 (1)
19+
// For system clock, enable one source:
20+
//#define MICROPY_HW_CLK_USE_HSI (1) // internal 8MHz -> PLL = 48MHz.
21+
#define MICROPY_HW_CLK_USE_HSI48 (1) // internal 48MHz.
22+
//#define MICROPY_HW_CLK_USE_HSE (1) // external crystal -> PLL = 48MHz.
23+
// For HSE set the crystal / clock input frequency HSE_VALUE in stm32f0xx_hal_conf.h
24+
#if MICROPY_HW_CLK_USE_HSE
25+
#define MICROPY_HW_CLK_USE_BYPASS (1) // HSE comes from STLINK 8MHz, not crystal.
26+
#endif
2127

2228
// The board has an external 32kHz crystal
2329
#define MICROPY_HW_RTC_USE_LSE (1)

ports/stm32/powerctrlboot.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void SystemClock_Config(void) {
4848
RCC->CFGR = 0 << RCC_CFGR_PLLMUL_Pos | 3 << RCC_CFGR_PLLSRC_Pos; // PLL mult by 2, src = HSI48/PREDIV
4949
RCC->CFGR2 = 1; // Input clock divided by 2
5050

51-
#else
51+
#elif MICROPY_HW_CLK_USE_HSE
5252
// Use HSE and the PLL to get a 48MHz SYSCLK
5353

5454
#if MICROPY_HW_CLK_USE_BYPASS
@@ -61,6 +61,18 @@ void SystemClock_Config(void) {
6161
RCC->CFGR = ((48000000 / HSE_VALUE) - 2) << RCC_CFGR_PLLMUL_Pos | 2 << RCC_CFGR_PLLSRC_Pos;
6262
RCC->CFGR2 = 0; // Input clock not divided
6363

64+
#elif MICROPY_HW_CLK_USE_HSI
65+
// Use the 8MHz internal oscillator and the PLL to get a 48MHz SYSCLK
66+
67+
RCC->CR |= RCC_CR_HSION;
68+
while ((RCC->CR & RCC_CR_HSIRDY) == 0) {
69+
// Wait for HSI to be ready
70+
}
71+
RCC->CFGR = 4 << RCC_CFGR_PLLMUL_Pos | 1 << RCC_CFGR_PLLSRC_Pos; // PLL mult by 6, src = HSI
72+
RCC->CFGR2 = 0; // Input clock not divided
73+
74+
#else
75+
#error System clock not specified
6476
#endif
6577

6678
RCC->CR |= RCC_CR_PLLON; // Turn PLL on

0 commit comments

Comments
 (0)