Merge pull request #4070 from thomaseichinger/hauke_fix_l1_uartpins
cpu/stm32l1: cleaned up UART pin configuration slightly
This commit is contained in:
commit
c0782d68e8
@ -72,11 +72,9 @@ static const timer_conf_t timer_config[] = {
|
|||||||
#define UART_0_ISR isr_usart2
|
#define UART_0_ISR isr_usart2
|
||||||
#define UART_0_BUS_FREQ 32000000
|
#define UART_0_BUS_FREQ 32000000
|
||||||
/* UART 0 pin configuration */
|
/* UART 0 pin configuration */
|
||||||
#define UART_0_PORT GPIOA
|
#define UART_0_RX_PIN GPIO(PORT_A, 3)
|
||||||
#define UART_0_PORT_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOAEN)
|
#define UART_0_TX_PIN GPIO(PORT_A, 2)
|
||||||
#define UART_0_RX_PIN 3
|
#define UART_0_AF GPIO_AF7
|
||||||
#define UART_0_TX_PIN 2
|
|
||||||
#define UART_0_AF 7
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GPIO configuration
|
* @brief GPIO configuration
|
||||||
|
|||||||
@ -80,6 +80,16 @@ typedef enum {
|
|||||||
GPIO_AF14 /**< use alternate function 14 */
|
GPIO_AF14 /**< use alternate function 14 */
|
||||||
} gpio_af_t;
|
} gpio_af_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configure the alternate function for the given pin
|
||||||
|
*
|
||||||
|
* @note This is meant for internal use in STM32L1 peripheral drivers only
|
||||||
|
*
|
||||||
|
* @param[in] pin pin to configure
|
||||||
|
* @param[in] af alternate function to use
|
||||||
|
*/
|
||||||
|
void gpio_init_af(gpio_t pin, gpio_af_t af);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration data structure
|
* @brief Timer configuration data structure
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "periph_conf.h"
|
#include "periph_conf.h"
|
||||||
#include "periph/uart.h"
|
#include "periph/uart.h"
|
||||||
|
#include "periph/gpio.h"
|
||||||
|
|
||||||
/* guard file in case no UART device was specified */
|
/* guard file in case no UART device was specified */
|
||||||
#if UART_NUMOF
|
#if UART_NUMOF
|
||||||
@ -94,11 +95,10 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, uart_tx_cb_t t
|
|||||||
int uart_init_blocking(uart_t uart, uint32_t baudrate)
|
int uart_init_blocking(uart_t uart, uint32_t baudrate)
|
||||||
{
|
{
|
||||||
USART_TypeDef *dev = 0;
|
USART_TypeDef *dev = 0;
|
||||||
GPIO_TypeDef *port = 0;
|
gpio_t tx_pin = 0;
|
||||||
uint32_t tx_pin = 0;
|
gpio_t rx_pin = 0;
|
||||||
uint32_t rx_pin = 0;
|
gpio_af_t af = 0;
|
||||||
uint8_t af = 0;
|
float clk = 0;
|
||||||
uint32_t clk = 0;
|
|
||||||
uint16_t mantissa;
|
uint16_t mantissa;
|
||||||
uint8_t fraction;
|
uint8_t fraction;
|
||||||
|
|
||||||
@ -106,37 +106,31 @@ int uart_init_blocking(uart_t uart, uint32_t baudrate)
|
|||||||
#if UART_0_EN
|
#if UART_0_EN
|
||||||
case UART_0:
|
case UART_0:
|
||||||
dev = UART_0_DEV;
|
dev = UART_0_DEV;
|
||||||
port = UART_0_PORT;
|
|
||||||
clk = UART_0_CLK;
|
clk = UART_0_CLK;
|
||||||
tx_pin = UART_0_TX_PIN;
|
tx_pin = UART_0_TX_PIN;
|
||||||
rx_pin = UART_0_RX_PIN;
|
rx_pin = UART_0_RX_PIN;
|
||||||
af = UART_0_AF;
|
af = UART_0_AF;
|
||||||
UART_0_CLKEN();
|
UART_0_CLKEN();
|
||||||
UART_0_PORT_CLKEN();
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if UART_1_EN
|
#if UART_1_EN
|
||||||
case UART_1:
|
case UART_1:
|
||||||
dev = UART_1_DEV;
|
dev = UART_1_DEV;
|
||||||
port = UART_1_PORT;
|
|
||||||
clk = UART_1_CLK;
|
clk = UART_1_CLK;
|
||||||
tx_pin = UART_1_TX_PIN;
|
tx_pin = UART_1_TX_PIN;
|
||||||
rx_pin = UART_1_RX_PIN;
|
rx_pin = UART_1_RX_PIN;
|
||||||
af = UART_1_AF;
|
af = UART_1_AF;
|
||||||
UART_1_CLKEN();
|
UART_1_CLKEN();
|
||||||
UART_1_PORT_CLKEN();
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if UART_2_EN
|
#if UART_2_EN
|
||||||
case UART_2:
|
case UART_2:
|
||||||
dev = UART_2_DEV;
|
dev = UART_2_DEV;
|
||||||
port = UART_2_PORT;
|
|
||||||
clk = UART_2_CLK;
|
clk = UART_2_CLK;
|
||||||
tx_pin = UART_2_TX_PIN;
|
tx_pin = UART_2_TX_PIN;
|
||||||
rx_pin = UART_2_RX_PIN;
|
rx_pin = UART_2_RX_PIN;
|
||||||
af = UART_2_AF;
|
af = UART_2_AF;
|
||||||
UART_2_CLKEN();
|
UART_2_CLKEN();
|
||||||
UART_2_PORT_CLKEN();
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
@ -144,25 +138,10 @@ int uart_init_blocking(uart_t uart, uint32_t baudrate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* uart_configure RX and TX pins, set pin to use alternative function mode */
|
/* uart_configure RX and TX pins, set pin to use alternative function mode */
|
||||||
port->MODER &= ~(3 << (rx_pin * 2) | 3 << (tx_pin * 2));
|
gpio_init(tx_pin, GPIO_DIR_OUT, GPIO_NOPULL);
|
||||||
port->MODER |= 2 << (rx_pin * 2) | 2 << (tx_pin * 2);
|
gpio_init_af(tx_pin, af);
|
||||||
/* and assign alternative function */
|
gpio_init(rx_pin, GPIO_DIR_IN, GPIO_NOPULL);
|
||||||
if (rx_pin < 8) {
|
gpio_init_af(rx_pin, af);
|
||||||
port->AFR[0] &= ~(0xf << (rx_pin * 4));
|
|
||||||
port->AFR[0] |= af << (rx_pin * 4);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
port->AFR[1] &= ~(0xf << ((rx_pin - 8) * 4));
|
|
||||||
port->AFR[1] |= af << ((rx_pin - 8) * 4);
|
|
||||||
}
|
|
||||||
if (tx_pin < 8) {
|
|
||||||
port->AFR[0] &= ~(0xf << (tx_pin * 4));
|
|
||||||
port->AFR[0] |= af << (tx_pin * 4);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
port->AFR[1] &= ~(0xf << ((tx_pin - 8) * 4));
|
|
||||||
port->AFR[1] |= af << ((tx_pin - 8) * 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* uart_configure UART to mode 8N1 with given baudrate */
|
/* uart_configure UART to mode 8N1 with given baudrate */
|
||||||
clk /= baudrate;
|
clk /= baudrate;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user