diff options
Diffstat (limited to 'src/stm32/stm32f1.c')
-rw-r--r-- | src/stm32/stm32f1.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/stm32/stm32f1.c b/src/stm32/stm32f1.c index d4a5c853..927ee1db 100644 --- a/src/stm32/stm32f1.c +++ b/src/stm32/stm32f1.c @@ -51,6 +51,15 @@ get_pclock_frequency(uint32_t periph_base) return FREQ_PERIPH; } +// Enable a GPIO peripheral clock +void +gpio_clock_enable(GPIO_TypeDef *regs) +{ + uint32_t rcc_pos = ((uint32_t)regs - APB2PERIPH_BASE) / 0x400; + RCC->APB2ENR |= 1 << rcc_pos; + RCC->APB2ENR; +} + // Set the mode and extended function of a pin void gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup) @@ -58,8 +67,7 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup) GPIO_TypeDef *regs = digital_regs[GPIO2PORT(gpio)]; // Enable GPIO clock - uint32_t rcc_pos = ((uint32_t)regs - APB2PERIPH_BASE) / 0x400; - RCC->APB2ENR |= 1 << rcc_pos; + gpio_clock_enable(regs); // Configure GPIO uint32_t pos = gpio % 16, shift = (pos % 8) * 4, msk = 0xf << shift, cfg; |