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

cpu/efm32: provide periph_uart_mode #12323

Merged
merged 4 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions boards/ikea-tradfri/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PB, 14),
.loc = USART_ROUTELOC0_RXLOC_LOC9 |
USART_ROUTELOC0_TXLOC_LOC9,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn
}
Expand Down
9 changes: 0 additions & 9 deletions boards/slstk3401a/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PA, 0),
.loc = USART_ROUTELOC0_RXLOC_LOC0 |
USART_ROUTELOC0_TXLOC_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn
},
Expand All @@ -192,9 +189,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PC, 6),
.loc = USART_ROUTELOC0_RXLOC_LOC11 |
USART_ROUTELOC0_TXLOC_LOC11,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn
},
Expand All @@ -204,9 +198,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PD, 10),
.loc = LEUART_ROUTELOC0_RXLOC_LOC18 |
LEUART_ROUTELOC0_TXLOC_LOC18,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn
}
Expand Down
6 changes: 0 additions & 6 deletions boards/slstk3402a/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PA, 0),
.loc = USART_ROUTELOC0_RXLOC_LOC0 |
USART_ROUTELOC0_TXLOC_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn
},
Expand All @@ -183,9 +180,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PD, 10),
.loc = LEUART_ROUTELOC0_RXLOC_LOC18 |
LEUART_ROUTELOC0_TXLOC_LOC18,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn
}
Expand Down
9 changes: 0 additions & 9 deletions boards/sltb001a/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PA, 0),
.loc = USART_ROUTELOC0_RXLOC_LOC0 |
USART_ROUTELOC0_TXLOC_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn
},
Expand All @@ -192,9 +189,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PC, 7),
.loc = USART_ROUTELOC0_RXLOC_LOC11 |
USART_ROUTELOC0_TXLOC_LOC11,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn
},
Expand All @@ -204,9 +198,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PD, 10),
.loc = LEUART_ROUTELOC0_RXLOC_LOC18 |
LEUART_ROUTELOC0_TXLOC_LOC18,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn
}
Expand Down
3 changes: 0 additions & 3 deletions boards/slwstk6000b/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ static const uart_conf_t uart_config[] = {
.tx_pin = MODULE_PIN_F6,
.loc = USART_ROUTELOC0_RXLOC_LOC0 |
USART_ROUTELOC0_TXLOC_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn
}
Expand Down
9 changes: 0 additions & 9 deletions boards/stk3600/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PE, 1),
.tx_pin = GPIO_PIN(PE, 0),
.loc = UART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_UART0,
.irq = UART0_RX_IRQn
},
Expand All @@ -245,9 +242,6 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 1),
.tx_pin = GPIO_PIN(PD, 0),
.loc = USART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn
},
Expand All @@ -256,9 +250,6 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 5),
.tx_pin = GPIO_PIN(PD, 4),
.loc = LEUART_ROUTE_LOCATION_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn
}
Expand Down
9 changes: 0 additions & 9 deletions boards/stk3700/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PE, 1),
.tx_pin = GPIO_PIN(PE, 0),
.loc = UART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_UART0,
.irq = UART0_RX_IRQn
},
Expand All @@ -245,9 +242,6 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 1),
.tx_pin = GPIO_PIN(PD, 0),
.loc = USART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn
},
Expand All @@ -256,9 +250,6 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 5),
.tx_pin = GPIO_PIN(PD, 4),
.loc = LEUART_ROUTE_LOCATION_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn
}
Expand Down
40 changes: 40 additions & 0 deletions cpu/efm32/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,46 @@ typedef struct {
/**
* @brief UART device configuration.
*/
#ifndef DOXYGEN
/**
* @brief Override parity values
* @{
*/
#define HAVE_UART_PARITY_T
typedef enum {
UART_PARITY_NONE = 0,
UART_PARITY_ODD = 1,
UART_PARITY_EVEN = 2,
UART_PARITY_MARK = 3,
UART_PARITY_SPACE = 4,
} uart_parity_t;
/** @} */

/**
* @brief Override data bits length values
* @{
*/
#define HAVE_UART_DATA_BITS_T
typedef enum {
UART_DATA_BITS_5 = 5,
UART_DATA_BITS_6 = 6,
UART_DATA_BITS_7 = 7,
UART_DATA_BITS_8 = 8,
} uart_data_bits_t;
/** @} */

/**
* @brief Override stop bits length values
* @{
*/
#define HAVE_UART_STOP_BITS_T
typedef enum {
UART_STOP_BITS_1 = 2,
UART_STOP_BITS_2 = 4,
} uart_stop_bits_t;
/** @} */
#endif /* ndef DOXYGEN */

typedef struct {
void *dev; /**< UART, USART or LEUART device used */
gpio_t rx_pin; /**< pin used for RX */
Expand Down
36 changes: 36 additions & 0 deletions cpu/efm32/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,42 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
return 0;
}

#ifdef MODULE_PERIPH_UART_MODECFG
int uart_mode(uart_t dev, uart_data_bits_t data_bits, uart_parity_t parity,
uart_stop_bits_t stop_bits)
{
if (parity == UART_PARITY_MARK || parity == UART_PARITY_SPACE) {
return UART_NOMODE;
}

#ifdef USE_LEUART
if (_is_usart(dev)) {
#endif
USART_TypeDef *uart = (USART_TypeDef *) uart_config[dev].dev;

USART_FrameSet(uart,
USART_DataBits2Def(data_bits),
USART_StopBits2Def(stop_bits),
USART_Parity2Def(parity));
#ifdef USE_LEUART
} else {
if (data_bits != UART_DATA_BITS_8) {
return UART_NOMODE;
benpicco marked this conversation as resolved.
Show resolved Hide resolved
}

LEUART_TypeDef *leuart = (LEUART_TypeDef *) uart_config[dev].dev;

LEUART_FrameSet(leuart,
LEUART_DataBits2Def(data_bits),
LEUART_StopBits2Def(stop_bits),
LEUART_Parity2Def(parity));
}
#endif

return UART_OK;
}
#endif

void uart_write(uart_t dev, const uint8_t *data, size_t len)
{
#ifdef USE_LEUART
Expand Down
2 changes: 1 addition & 1 deletion pkg/gecko_sdk/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PKG_NAME=gecko_sdk
PKG_URL=https://github.com/basilfx/RIOT-gecko-sdk
PKG_VERSION=50996be7377cec885954312b7d4caf61788aaa40
PKG_VERSION=755f5430c05d95812603524f9aa7516964dd5758
PKG_LICENSE=Zlib

ifneq ($(CPU),efm32)
Expand Down