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[] = {
{
.dev = (Uart *)UART,
.rx_port = PIOA,
.tx_port = PIOA,
.rx_pin = 8,
.tx_pin = 9,
.mux = GPIO_MUX_A,
.pmc_id = ID_UART,
.irqn = UART_IRQn
.dev = (Uart *)UART,
.rx_pin = GPIO_PIN(PA, 8),
.tx_pin = GPIO_PIN(PA, 9),
.mux = GPIO_MUX_A,
.pmc_id = ID_UART,
.irqn = UART_IRQn
},
{
.dev = (Uart *)USART0,
.rx_port = PIOA,
.tx_port = PIOA,
.rx_pin = 10,
.tx_pin = 11,
.mux = GPIO_MUX_A,
.pmc_id = ID_USART0,
.irqn = USART0_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_port = PIOA,
.tx_port = PIOA,
.rx_pin = 12,
.tx_pin = 13,
.mux = GPIO_MUX_A,
.pmc_id = ID_USART1,
.irqn = USART1_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_port = PIOD,
.tx_port = PIOD,
.rx_pin = 4,
.tx_pin = 5,
.mux = GPIO_MUX_B,
.pmc_id = ID_USART3,
.irqn = USART3_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 */

View File

@ -66,11 +66,38 @@ static const timer_conf_t timer_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},
{(Uart *)USART0, PIOA, PIOA, 10, 11, GPIO_MUX_A, ID_USART0, USART0_IRQn},
{(Uart *)USART1, PIOA, PIOA, 12, 13, GPIO_MUX_A, ID_USART1, USART1_IRQn},
{(Uart *)USART3, PIOD, PIOD, 4, 5, GPIO_MUX_B, ID_USART3, USART3_IRQn}
{
.dev = (Uart *)UART,
.rx_pin = GPIO_PIN(PA, 8),
.tx_pin = GPIO_PIN(PA, 9),
.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 */

View File

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

View File

@ -22,6 +22,7 @@
#include "cpu.h"
#include "board.h"
#include "periph/uart.h"
#include "periph/gpio.h"
#define ENABLE_DEBUG (0)
#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 */
uart_poweron(uart);
/* configure pins
TODO: optimize once GPIO refactoring is merged */
uart_config[uart].rx_port->PIO_PDR = (1 << uart_config[uart].rx_pin);
uart_config[uart].rx_port->PIO_ABSR &= ~(1 << uart_config[uart].rx_pin);
uart_config[uart].tx_port->PIO_ABSR |= (uart_config[uart].mux <<
uart_config[uart].rx_pin);
uart_config[uart].tx_port->PIO_PDR = (1 << uart_config[uart].tx_pin);
uart_config[uart].tx_port->PIO_ABSR &= ~(1 << uart_config[uart].tx_pin);
uart_config[uart].tx_port->PIO_ABSR |= (uart_config[uart].mux <<
uart_config[uart].tx_pin);
/* reset configuration */
dev->UART_CR = 0;
dev->UART_IDR = 0x0000ffff;
/* configure pins */
gpio_init_mux(uart_config[uart].tx_pin, uart_config[uart].mux);
if (rx_cb) {
gpio_init_mux(uart_config[uart].rx_pin, uart_config[uart].mux);
}
/* configure baud rate and set mode to 8N1 */
dev->UART_BRGR = (CLOCK_CORECLOCK / (16 * baudrate));
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 */
NVIC_EnableIRQ(uart_config[uart].irqn);
dev->UART_IER = UART_IER_RXRDY;
if (rx_cb) {
dev->UART_CR = UART_CR_RXEN | UART_CR_TXEN | UART_CR_RSTSTA;
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;
}