aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32/stm32f4.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-08-20 13:32:14 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-08-20 19:39:49 -0400
commite32be928dc042b61876384fac9ef2a225d10e929 (patch)
tree260659bab600486cb42b9dfdeaa9a764f56744b2 /src/stm32/stm32f4.c
parentc930fc392b6977b17d6f7953bd738583974208c2 (diff)
downloadkutter-e32be928dc042b61876384fac9ef2a225d10e929.tar.gz
kutter-e32be928dc042b61876384fac9ef2a225d10e929.tar.xz
kutter-e32be928dc042b61876384fac9ef2a225d10e929.zip
stm32: Add support for configuring open drain output mode
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stm32/stm32f4.c')
-rw-r--r--src/stm32/stm32f4.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/stm32/stm32f4.c b/src/stm32/stm32f4.c
index 5a09f2d6..9d40f34c 100644
--- a/src/stm32/stm32f4.c
+++ b/src/stm32/stm32f4.c
@@ -72,7 +72,7 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup)
gpio_clock_enable(regs);
// Configure GPIO
- uint32_t mode_bits = mode & 0x0f, func = mode >> 4;
+ 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;
@@ -81,6 +81,7 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup)
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) | (0x02 << m_shift);
}