1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/sam3: uart driver enhancements

- enabled driver to run in TX only mode
- make use of gpio_init_mux() for pin intialization
- simplyfied pin configuration
- adapted pin configuartion for arduino-due and udoo
This commit is contained in:
Hauke Petersen 2017-02-09 11:35:28 +01:00
parent f0d0009820
commit 1a3fefb6bf
4 changed files with 77 additions and 56 deletions

View File

@ -68,45 +68,37 @@ static const timer_conf_t timer_config[] = {
*/ */
static const uart_conf_t uart_config[] = { static const uart_conf_t uart_config[] = {
{ {
.dev = (Uart *)UART, .dev = (Uart *)UART,
.rx_port = PIOA, .rx_pin = GPIO_PIN(PA, 8),
.tx_port = PIOA, .tx_pin = GPIO_PIN(PA, 9),
.rx_pin = 8, .mux = GPIO_MUX_A,
.tx_pin = 9, .pmc_id = ID_UART,
.mux = GPIO_MUX_A, .irqn = UART_IRQn
.pmc_id = ID_UART,
.irqn = UART_IRQn
}, },
{ {
.dev = (Uart *)USART0, .dev = (Uart *)USART0,
.rx_port = PIOA, .rx_pin = GPIO_PIN(PA, 10),
.tx_port = PIOA, .tx_pin = GPIO_PIN(PA, 11),
.rx_pin = 10, .mux = GPIO_MUX_A,
.tx_pin = 11, .pmc_id = ID_USART0,
.mux = GPIO_MUX_A, .irqn = USART0_IRQn
.pmc_id = ID_USART0,
.irqn = USART0_IRQn
}, },
{ {
.dev = (Uart *)USART1, .dev = (Uart *)USART1,
.rx_port = PIOA, .rx_pin = GPIO_PIN(PA, 12),
.tx_port = PIOA, .tx_pin = GPIO_PIN(PA, 13),
.rx_pin = 12, .mux = GPIO_MUX_A,
.tx_pin = 13, .pmc_id = ID_USART1,
.mux = GPIO_MUX_A, .irqn = USART1_IRQn
.pmc_id = ID_USART1,
.irqn = USART1_IRQn
}, },
{ {
.dev = (Uart *)USART3, .dev = (Uart *)USART3,
.rx_port = PIOD, .rx_pin = GPIO_PIN(PD, 5),
.tx_port = PIOD, .tx_pin = GPIO_PIN(PD, 4),
.rx_pin = 4, .mux = GPIO_MUX_B,
.tx_pin = 5, .pmc_id = ID_USART3,
.mux = GPIO_MUX_B, .irqn = USART3_IRQn
.pmc_id = ID_USART3, }
.irqn = USART3_IRQn
},
}; };
/* define interrupt vectors */ /* define interrupt vectors */

View File

@ -66,11 +66,38 @@ static const timer_conf_t timer_config[] = {
* @{ * @{
*/ */
static const uart_conf_t uart_config[] = { static const uart_conf_t uart_config[] = {
/* device, rx port, tx port, rx pin, tx pin, mux, PMC bit, IRGn line */ {
{(Uart *)UART, PIOA, PIOA, 8, 9, GPIO_MUX_A, ID_UART, UART_IRQn}, .dev = (Uart *)UART,
{(Uart *)USART0, PIOA, PIOA, 10, 11, GPIO_MUX_A, ID_USART0, USART0_IRQn}, .rx_pin = GPIO_PIN(PA, 8),
{(Uart *)USART1, PIOA, PIOA, 12, 13, GPIO_MUX_A, ID_USART1, USART1_IRQn}, .tx_pin = GPIO_PIN(PA, 9),
{(Uart *)USART3, PIOD, PIOD, 4, 5, GPIO_MUX_B, ID_USART3, USART3_IRQn} .mux = GPIO_MUX_A,
.pmc_id = ID_UART,
.irqn = UART_IRQn
},
{
.dev = (Uart *)USART0,
.rx_pin = GPIO_PIN(PA, 10),
.tx_pin = GPIO_PIN(PA, 11),
.mux = GPIO_MUX_A,
.pmc_id = ID_USART0,
.irqn = USART0_IRQn
},
{
.dev = (Uart *)USART1,
.rx_pin = GPIO_PIN(PA, 12),
.tx_pin = GPIO_PIN(PA, 13),
.mux = GPIO_MUX_A,
.pmc_id = ID_USART1,
.irqn = USART1_IRQn
},
{
.dev = (Uart *)USART3,
.rx_pin = GPIO_PIN(PD, 5),
.tx_pin = GPIO_PIN(PD, 4),
.mux = GPIO_MUX_B,
.pmc_id = ID_USART3,
.irqn = USART3_IRQn
}
}; };
/* define interrupt vectors */ /* define interrupt vectors */

View File

@ -204,10 +204,8 @@ typedef struct {
*/ */
typedef struct { typedef struct {
Uart *dev; /**< U(S)ART device used */ Uart *dev; /**< U(S)ART device used */
Pio *rx_port; /**< port for RX pin */ gpio_t rx_pin; /**< RX pin */
Pio *tx_port; /**< port for TX pin */ gpio_t tx_pin; /**< TX pin */
uint8_t rx_pin; /**< RX pin */
uint8_t tx_pin; /**< TX pin */
gpio_mux_t mux; /**< MUX used for pins */ gpio_mux_t mux; /**< MUX used for pins */
uint8_t pmc_id; /**< bit in the PMC register of the device*/ uint8_t pmc_id; /**< bit in the PMC register of the device*/
uint8_t irqn; /**< interrupt number of the device */ uint8_t irqn; /**< interrupt number of the device */

View File

@ -22,6 +22,7 @@
#include "cpu.h" #include "cpu.h"
#include "board.h" #include "board.h"
#include "periph/uart.h" #include "periph/uart.h"
#include "periph/gpio.h"
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
@ -50,25 +51,28 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
/* enable clock */ /* enable clock */
uart_poweron(uart); uart_poweron(uart);
/* configure pins /* reset configuration */
TODO: optimize once GPIO refactoring is merged */ dev->UART_CR = 0;
uart_config[uart].rx_port->PIO_PDR = (1 << uart_config[uart].rx_pin); dev->UART_IDR = 0x0000ffff;
uart_config[uart].rx_port->PIO_ABSR &= ~(1 << uart_config[uart].rx_pin);
uart_config[uart].tx_port->PIO_ABSR |= (uart_config[uart].mux << /* configure pins */
uart_config[uart].rx_pin); gpio_init_mux(uart_config[uart].tx_pin, uart_config[uart].mux);
uart_config[uart].tx_port->PIO_PDR = (1 << uart_config[uart].tx_pin); if (rx_cb) {
uart_config[uart].tx_port->PIO_ABSR &= ~(1 << uart_config[uart].tx_pin); gpio_init_mux(uart_config[uart].rx_pin, uart_config[uart].mux);
uart_config[uart].tx_port->PIO_ABSR |= (uart_config[uart].mux << }
uart_config[uart].tx_pin);
/* configure baud rate and set mode to 8N1 */ /* configure baud rate and set mode to 8N1 */
dev->UART_BRGR = (CLOCK_CORECLOCK / (16 * baudrate)); dev->UART_BRGR = (CLOCK_CORECLOCK / (16 * baudrate));
dev->UART_MR = UART_MR_PAR_NO | US_MR_CHRL_8_BIT; dev->UART_MR = UART_MR_PAR_NO | US_MR_CHRL_8_BIT;
dev->UART_CR = UART_CR_RXEN | UART_CR_TXEN | UART_CR_RSTSTA;
/* enable RX interrupt */ if (rx_cb) {
NVIC_EnableIRQ(uart_config[uart].irqn); dev->UART_CR = UART_CR_RXEN | UART_CR_TXEN | UART_CR_RSTSTA;
dev->UART_IER = UART_IER_RXRDY; NVIC_EnableIRQ(uart_config[uart].irqn);
dev->UART_IER = UART_IER_RXRDY;
}
else {
dev->UART_CR = UART_CR_TXEN | UART_CR_RSTSTA;
}
return UART_OK; return UART_OK;
} }