From 2ee1f48895f6624e872f3ece1e4cda2740a46052 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 18 Dec 2021 19:12:41 -0500 Subject: stm32: Add new gpioperiph.c file for gpio_peripheral() code The gpio_peripheral() code is the same in stm32f0.c, stm32f4.c, and stm32h7.c. Move that function to a new gpioperiph.c file to avoid code duplication. Signed-off-by: Kevin O'Connor --- src/stm32/stm32f4.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'src/stm32/stm32f4.c') diff --git a/src/stm32/stm32f4.c b/src/stm32/stm32f4.c index 3e5fc2d2..267a5c74 100644 --- a/src/stm32/stm32f4.c +++ b/src/stm32/stm32f4.c @@ -1,4 +1,4 @@ -// Code to setup clocks and gpio on stm32f2/stm32f4 +// Code to setup clocks on stm32f2/stm32f4 // // Copyright (C) 2019 Kevin O'Connor // @@ -75,31 +75,6 @@ gpio_clock_enable(GPIO_TypeDef *regs) RCC->AHB1ENR; } -#define STM_OSPEED 0x2 // ~50Mhz at 40pF on STM32F4 (~25Mhz at 40pF on STM32F2) - -// Set the mode and extended function of a pin -void -gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup) -{ - GPIO_TypeDef *regs = digital_regs[GPIO2PORT(gpio)]; - - // Enable GPIO clock - gpio_clock_enable(regs); - - // Configure GPIO - uint32_t mode_bits = mode & 0xf, func = (mode >> 4) & 0xf, od = mode >> 8; - uint32_t pup = pullup ? (pullup > 0 ? 1 : 2) : 0; - uint32_t pos = gpio % 16, af_reg = pos / 8; - uint32_t af_shift = (pos % 8) * 4, af_msk = 0x0f << af_shift; - uint32_t m_shift = pos * 2, m_msk = 0x03 << m_shift; - - regs->AFR[af_reg] = (regs->AFR[af_reg] & ~af_msk) | (func << af_shift); - regs->MODER = (regs->MODER & ~m_msk) | (mode_bits << m_shift); - regs->PUPDR = (regs->PUPDR & ~m_msk) | (pup << m_shift); - regs->OTYPER = (regs->OTYPER & ~(1 << pos)) | (od << pos); - regs->OSPEEDR = (regs->OSPEEDR & ~m_msk) | (STM_OSPEED << m_shift); -} - #define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 4096) #define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT" -- cgit v1.2.3-70-g09d2