From c930fc392b6977b17d6f7953bd738583974208c2 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 20 Aug 2019 01:04:20 -0400 Subject: stm32: Make sure to enable the gpio clock prior to setting the first value Signed-off-by: Kevin O'Connor --- src/stm32/stm32f4.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/stm32/stm32f4.c') diff --git a/src/stm32/stm32f4.c b/src/stm32/stm32f4.c index dab8d524..5a09f2d6 100644 --- a/src/stm32/stm32f4.c +++ b/src/stm32/stm32f4.c @@ -53,6 +53,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 - AHB1PERIPH_BASE) / 0x400; + RCC->AHB1ENR |= 1 << rcc_pos; + RCC->AHB1ENR; +} + // Set the mode and extended function of a pin void gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup) @@ -60,8 +69,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 - AHB1PERIPH_BASE) / 0x400; - RCC->AHB1ENR |= (1<> 4; -- cgit v1.2.3-70-g09d2