aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32f4/clock.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-07-28 17:55:57 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-07-28 17:57:02 -0400
commitbc9c8cd7a052c03301995edafde62385ec7fb8a8 (patch)
tree5f1b176e9844e96de3ed686e53ce476de5f29b50 /src/stm32f4/clock.c
parentef0784afe6f142b8549ecf7630cbbd5ed627bd36 (diff)
downloadkutter-bc9c8cd7a052c03301995edafde62385ec7fb8a8.tar.gz
kutter-bc9c8cd7a052c03301995edafde62385ec7fb8a8.tar.xz
kutter-bc9c8cd7a052c03301995edafde62385ec7fb8a8.zip
stm32f4: Only enable peripherals once
Add is_enabled_pclock() and only initialize spi and adc once during configuration. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stm32f4/clock.c')
-rw-r--r--src/stm32f4/clock.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/stm32f4/clock.c b/src/stm32f4/clock.c
index bbd58aa5..b5fd16f8 100644
--- a/src/stm32f4/clock.c
+++ b/src/stm32f4/clock.c
@@ -28,6 +28,23 @@ enable_pclock(uint32_t periph_base)
}
}
+// Check if a peripheral clock has been enabled
+int
+is_enabled_pclock(uint32_t periph_base)
+{
+ if (periph_base < APB2PERIPH_BASE) {
+ uint32_t pos = (periph_base - APB1PERIPH_BASE) / 0x400;
+ return RCC->APB1ENR & (1<<pos);
+ } else if (periph_base < AHB1PERIPH_BASE) {
+ uint32_t pos = (periph_base - APB2PERIPH_BASE) / 0x400;
+ return RCC->APB2ENR & (1<<pos);
+ } else if (periph_base < AHB2PERIPH_BASE) {
+ uint32_t pos = (periph_base - AHB1PERIPH_BASE) / 0x400;
+ return RCC->AHB1ENR & (1<<pos);
+ }
+ return 0;
+}
+
// Return the frequency of the given peripheral clock
uint32_t
get_pclock_frequency(uint32_t periph_base)