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>
This commit is contained in:
Kevin O'Connor 2019-07-28 17:55:57 -04:00
parent ef0784afe6
commit bc9c8cd7a0
4 changed files with 35 additions and 13 deletions

View file

@ -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);