Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to setup UART dynamically on cc13xx/cc26xx devices #2435

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions cpu/cc26xx-cc13xx/dev/cc26xx-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
/*---------------------------------------------------------------------------*/
static int (*input_handler)(unsigned char c);
/*---------------------------------------------------------------------------*/
/* UART configurations. Defaults are for 115,200, 8-N-1 operation. */
static uint32_t cc26xx_uart_baudrate = CC26XX_UART_CONF_BAUD_RATE;
static uint32_t cc26xx_uart_config = (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE
| UART_CONFIG_PAR_NONE);
/*---------------------------------------------------------------------------*/
static bool
usable_rx(void)
{
Expand Down Expand Up @@ -173,11 +178,9 @@ configure(void)
ti_lib_ioc_pin_type_uart(UART0_BASE, BOARD_IOID_UART_RX, BOARD_IOID_UART_TX,
BOARD_IOID_UART_CTS, BOARD_IOID_UART_RTS);

/* Configure the UART for 115,200, 8-N-1 operation. */
/* Configure the UART with defined configurations. */
ti_lib_uart_config_set_exp_clk(UART0_BASE, ti_lib_sys_ctrl_clock_get(),
CC26XX_UART_CONF_BAUD_RATE,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
cc26xx_uart_baudrate, cc26xx_uart_config);

/*
* Generate an RX interrupt at FIFO 1/2 full.
Expand Down Expand Up @@ -306,6 +309,21 @@ cc26xx_uart_init()
}
/*---------------------------------------------------------------------------*/
void
cc26xx_uart_setup(uint32_t baudrate, uint32_t config)
{
/* Return early if disabled by user conf or if ports are misconfigured */
if(!usable_rx() && !usable_tx()) {
return;
}

cc26xx_uart_baudrate = baudrate;
cc26xx_uart_config = config;

/* Reconfigure UART with new parameters */
enable();
}
/*---------------------------------------------------------------------------*/
void
cc26xx_uart_write_byte(uint8_t c)
{
/* Return early if disabled by user conf or if ports are misconfigured */
Expand Down
22 changes: 22 additions & 0 deletions cpu/cc26xx-cc13xx/dev/cc26xx-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@
*/
void cc26xx_uart_init();

/**
* \brief Change default UART configurations to custom one
* \param baudrate
* \config UART data format
* This parameter is the bitwise or of three values
* Number of data bits
* - \ref UART_CONFIG_WLEN_8 : 8 data bits per byte.
* - \ref UART_CONFIG_WLEN_7 : 7 data bits per byte.
* - \ref UART_CONFIG_WLEN_6 : 6 data bits per byte.
* - \ref UART_CONFIG_WLEN_5 : 5 data bits per byte.
* - Number of stop bits
* - \ref UART_CONFIG_STOP_ONE : One stop bit.
* - \ref UART_CONFIG_STOP_TWO : Two stop bits.
* - Parity
* - \ref UART_CONFIG_PAR_NONE
* - \ref UART_CONFIG_PAR_EVEN
* - \ref UART_CONFIG_PAR_ODD
* - \ref UART_CONFIG_PAR_ONE
* - \ref UART_CONFIG_PAR_ZERO
*/
void cc26xx_uart_setup(uint32_t baudrate, uint32_t config);

/**
* \brief Sends a single character down the UART
* \param b The character to transmit
Expand Down