Skip to content

Commit 9fbc750

Browse files
committed
Add support for HSE bypass on STM32.
1 parent 94042ac commit 9fbc750

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ See the [Kalico Additions document](https://docs.kalico.gg/Kalico_Additions.html
140140

141141
- [tmc2240: adjustable driver_CS and current_range](https://github.com/KalicoCrew/kalico/pull/556)
142142

143+
- [core: support for STM32 MCUs with oscillators rather than crystals](https://github.com/KalicoCrew/kalico/pull/709)
144+
143145
If you're feeling adventurous, take a peek at the extra features in the bleeding-edge-v2 branch [feature documentation](docs/Bleeding_Edge.md)
144146
and [feature configuration reference](docs/Config_Reference_Bleeding_Edge.md):
145147

src/stm32/Kconfig

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,17 @@ config ARMCM_RAM_VECTORTABLE
352352
choice
353353
prompt "Clock Reference" if LOW_LEVEL_OPTIONS
354354
config STM32_CLOCK_REF_8M
355-
bool "8 MHz crystal"
355+
bool "8 MHz external"
356356
config STM32_CLOCK_REF_12M
357-
bool "12 MHz crystal"
357+
bool "12 MHz external"
358358
config STM32_CLOCK_REF_16M
359-
bool "16 MHz crystal"
359+
bool "16 MHz external"
360360
config STM32_CLOCK_REF_20M
361-
bool "20 MHz crystal"
361+
bool "20 MHz external"
362362
config STM32_CLOCK_REF_24M
363-
bool "24 MHz crystal"
363+
bool "24 MHz external"
364364
config STM32_CLOCK_REF_25M
365-
bool "25 MHz crystal"
365+
bool "25 MHz external"
366366
config STM32_CLOCK_REF_INTERNAL
367367
bool "Internal clock"
368368
endchoice
@@ -385,6 +385,13 @@ config STM32F0_TRIM
385385
Default is 16 (use factory default). Each increment increases
386386
the clock rate by ~240KHz.
387387

388+
choice
389+
prompt "External Clock Type" if LOW_LEVEL_OPTIONS && !STM32_CLOCK_REF_INTERNAL && MACH_STM32G474
390+
config STM32_CLOCK_HSE_CRYSTAL
391+
bool "HSE Crystal"
392+
config STM32_CLOCK_HSE_BYPASS
393+
bool "HSE Bypass"
394+
endchoice
388395

389396
######################################################################
390397
# Communication inteface

src/stm32/stm32g4.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ gpio_clock_enable(GPIO_TypeDef *regs)
7676
RCC->AHB2ENR;
7777
}
7878

79-
#if !CONFIG_STM32_CLOCK_REF_INTERNAL
80-
DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PF0,PF1");
79+
#if CONFIG_STM32_CLOCK_REF_INTERNAL
80+
// No pins required.
81+
#elif CONFIG_STM32_CLOCK_HSE_BYPASS
82+
DECL_CONSTANT_STR("RESERVE_PINS_hse_clock", "PF0");
83+
#else // CONFIG_STM32_CLOCK_HSE_CRYSTAL
84+
DECL_CONSTANT_STR("RESERVE_PINS_hse_clock", "PF0,PF1");
8185
#endif
8286

8387
static void
@@ -94,6 +98,9 @@ enable_clock_stm32g4(void)
9498
pll_base = 4000000;
9599
#endif
96100
uint32_t div = CONFIG_CLOCK_REF_FREQ / pll_base - 1;
101+
if (CONFIG_STM32_CLOCK_HSE_BYPASS) {
102+
RCC->CR |= RCC_CR_HSEBYP;
103+
}
97104
RCC->CR |= RCC_CR_HSEON;
98105
while (!(RCC->CR & RCC_CR_HSERDY))
99106
;

0 commit comments

Comments
 (0)