diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-07-28 17:55:57 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-07-28 17:57:02 -0400 |
commit | bc9c8cd7a052c03301995edafde62385ec7fb8a8 (patch) | |
tree | 5f1b176e9844e96de3ed686e53ce476de5f29b50 /src/stm32f4/spi.c | |
parent | ef0784afe6f142b8549ecf7630cbbd5ed627bd36 (diff) | |
download | kutter-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/spi.c')
-rw-r--r-- | src/stm32f4/spi.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/stm32f4/spi.c b/src/stm32f4/spi.c index a7e96874..f8852be9 100644 --- a/src/stm32f4/spi.c +++ b/src/stm32f4/spi.c @@ -19,10 +19,12 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate) shutdown("Invalid spi bus"); // Enable SPI - enable_pclock(SPI2_BASE); - gpio_peripheral(GPIO('B', 14), GPIO_FUNCTION(5), 1); - gpio_peripheral(GPIO('B', 15), GPIO_FUNCTION(5), 0); - gpio_peripheral(GPIO('B', 13), GPIO_FUNCTION(5), 0); + if (!is_enabled_pclock(SPI2_BASE)) { + enable_pclock(SPI2_BASE); + gpio_peripheral(GPIO('B', 14), GPIO_FUNCTION(5), 1); + gpio_peripheral(GPIO('B', 15), GPIO_FUNCTION(5), 0); + gpio_peripheral(GPIO('B', 13), GPIO_FUNCTION(5), 0); + } // Calculate CR1 register uint32_t pclk = get_pclock_frequency(SPI2_BASE); |