From 4383fbf60b0d7494bc7295daaec73670ce3786cb Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 16 Mar 2016 12:16:04 +0100 Subject: [PATCH] cpu/stm32f4/uart: use common clk_en functions --- cpu/stm32f4/include/periph_cpu.h | 1 + cpu/stm32f4/periph/uart.c | 27 +++------------------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/cpu/stm32f4/include/periph_cpu.h b/cpu/stm32f4/include/periph_cpu.h index 11651bb0c5..575b7dc9f3 100644 --- a/cpu/stm32f4/include/periph_cpu.h +++ b/cpu/stm32f4/include/periph_cpu.h @@ -122,6 +122,7 @@ typedef struct { gpio_t rx_pin; /**< RX pin */ gpio_t tx_pin; /**< TX pin */ gpio_af_t af; /**< alternate pin function to use */ + uint8_t bus; /**< APB bus */ uint8_t irqn; /**< IRQ channel */ uint8_t dma_stream; /**< DMA stream used for TX */ uint8_t dma_chan; /**< DMA channel used for TX */ diff --git a/cpu/stm32f4/periph/uart.c b/cpu/stm32f4/periph/uart.c index aa0261029f..dda1f6011a 100644 --- a/cpu/stm32f4/periph/uart.c +++ b/cpu/stm32f4/periph/uart.c @@ -45,17 +45,6 @@ static inline USART_TypeDef *_dev(uart_t uart) static mutex_t _tx_dma_sync[UART_NUMOF]; static mutex_t _tx_lock[UART_NUMOF]; -/** - * @brief Find out which peripheral bus the UART device is connected to - * - * @return 1: APB1 - * @return 2: APB2 - */ -static inline int _bus(uart_t uart) -{ - return (uart_config[uart].rcc_mask < RCC_APB1ENR_USART2EN) ? 2 : 1; -} - int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) { USART_TypeDef *dev; @@ -88,7 +77,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) uart_poweron(uart); /* calculate and set baudrate */ - if (_bus(uart) == 1) { + if (uart_config[uart].bus == APB1) { divider = CLOCK_APB1 / (16 * baudrate); } else { @@ -144,22 +133,12 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len) void uart_poweron(uart_t uart) { - if (_bus(uart) == 1) { - RCC->APB1ENR |= uart_config[uart].rcc_mask; - } - else { - RCC->APB2ENR |= uart_config[uart].rcc_mask; - } + periph_clk_en(uart_config[uart].bus, uart_config[uart].rcc_mask); } void uart_poweroff(uart_t uart) { - if (_bus(uart) == 1) { - RCC->APB1ENR &= ~(uart_config[uart].rcc_mask); - } - else { - RCC->APB2ENR &= ~(uart_config[uart].rcc_mask); - } + periph_clk_dis(uart_config[uart].bus, uart_config[uart].rcc_mask); } static inline void irq_handler(int uart, USART_TypeDef *dev)