1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #9127 from basilfx/feature/efm32_uart_modes

cpu: efm32: provide non-standard UART modes
This commit is contained in:
Francisco Acosta 2018-06-04 18:38:25 +02:00 committed by GitHub
commit 188886d9f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 83 additions and 2 deletions

View File

@ -126,6 +126,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PB, 14), .tx_pin = GPIO_PIN(PB, 14),
.loc = USART_ROUTELOC0_RXLOC_LOC9 | .loc = USART_ROUTELOC0_RXLOC_LOC9 |
USART_ROUTELOC0_TXLOC_LOC9, USART_ROUTELOC0_TXLOC_LOC9,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0, .cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn .irq = USART0_RX_IRQn
} }

View File

@ -175,6 +175,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PA, 0), .tx_pin = GPIO_PIN(PA, 0),
.loc = USART_ROUTELOC0_RXLOC_LOC0 | .loc = USART_ROUTELOC0_RXLOC_LOC0 |
USART_ROUTELOC0_TXLOC_LOC0, USART_ROUTELOC0_TXLOC_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0, .cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn .irq = USART0_RX_IRQn
}, },
@ -184,6 +187,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PC, 6), .tx_pin = GPIO_PIN(PC, 6),
.loc = USART_ROUTELOC0_RXLOC_LOC11 | .loc = USART_ROUTELOC0_RXLOC_LOC11 |
USART_ROUTELOC0_TXLOC_LOC11, USART_ROUTELOC0_TXLOC_LOC11,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1, .cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn .irq = USART1_RX_IRQn
}, },
@ -193,6 +199,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PD, 10), .tx_pin = GPIO_PIN(PD, 10),
.loc = LEUART_ROUTELOC0_RXLOC_LOC18 | .loc = LEUART_ROUTELOC0_RXLOC_LOC18 |
LEUART_ROUTELOC0_TXLOC_LOC18, LEUART_ROUTELOC0_TXLOC_LOC18,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0, .cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn .irq = LEUART0_IRQn
} }

View File

@ -176,6 +176,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PA, 0), .tx_pin = GPIO_PIN(PA, 0),
.loc = USART_ROUTELOC0_RXLOC_LOC0 | .loc = USART_ROUTELOC0_RXLOC_LOC0 |
USART_ROUTELOC0_TXLOC_LOC0, USART_ROUTELOC0_TXLOC_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0, .cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn .irq = USART0_RX_IRQn
}, },
@ -185,6 +188,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PC, 7), .tx_pin = GPIO_PIN(PC, 7),
.loc = USART_ROUTELOC0_RXLOC_LOC11 | .loc = USART_ROUTELOC0_RXLOC_LOC11 |
USART_ROUTELOC0_TXLOC_LOC11, USART_ROUTELOC0_TXLOC_LOC11,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1, .cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn .irq = USART1_RX_IRQn
}, },
@ -194,6 +200,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = GPIO_PIN(PD, 10), .tx_pin = GPIO_PIN(PD, 10),
.loc = LEUART_ROUTELOC0_RXLOC_LOC18 | .loc = LEUART_ROUTELOC0_RXLOC_LOC18 |
LEUART_ROUTELOC0_TXLOC_LOC18, LEUART_ROUTELOC0_TXLOC_LOC18,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0, .cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn .irq = LEUART0_IRQn
} }

View File

@ -177,6 +177,9 @@ static const uart_conf_t uart_config[] = {
.tx_pin = MODULE_PIN_F6, .tx_pin = MODULE_PIN_F6,
.loc = USART_ROUTELOC0_RXLOC_LOC0 | .loc = USART_ROUTELOC0_RXLOC_LOC0 |
USART_ROUTELOC0_TXLOC_LOC0, USART_ROUTELOC0_TXLOC_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART0, .cmu = cmuClock_USART0,
.irq = USART0_RX_IRQn .irq = USART0_RX_IRQn
} }

View File

@ -237,6 +237,9 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PE, 1), .rx_pin = GPIO_PIN(PE, 1),
.tx_pin = GPIO_PIN(PE, 0), .tx_pin = GPIO_PIN(PE, 0),
.loc = UART_ROUTE_LOCATION_LOC1, .loc = UART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_UART0, .cmu = cmuClock_UART0,
.irq = UART0_RX_IRQn .irq = UART0_RX_IRQn
}, },
@ -245,6 +248,9 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 1), .rx_pin = GPIO_PIN(PD, 1),
.tx_pin = GPIO_PIN(PD, 0), .tx_pin = GPIO_PIN(PD, 0),
.loc = USART_ROUTE_LOCATION_LOC1, .loc = USART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1, .cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn .irq = USART1_RX_IRQn
}, },
@ -253,6 +259,9 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 5), .rx_pin = GPIO_PIN(PD, 5),
.tx_pin = GPIO_PIN(PD, 4), .tx_pin = GPIO_PIN(PD, 4),
.loc = LEUART_ROUTE_LOCATION_LOC0, .loc = LEUART_ROUTE_LOCATION_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0, .cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn .irq = LEUART0_IRQn
} }

View File

@ -237,6 +237,9 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PE, 1), .rx_pin = GPIO_PIN(PE, 1),
.tx_pin = GPIO_PIN(PE, 0), .tx_pin = GPIO_PIN(PE, 0),
.loc = UART_ROUTE_LOCATION_LOC1, .loc = UART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_UART0, .cmu = cmuClock_UART0,
.irq = UART0_RX_IRQn .irq = UART0_RX_IRQn
}, },
@ -245,6 +248,9 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 1), .rx_pin = GPIO_PIN(PD, 1),
.tx_pin = GPIO_PIN(PD, 0), .tx_pin = GPIO_PIN(PD, 0),
.loc = USART_ROUTE_LOCATION_LOC1, .loc = USART_ROUTE_LOCATION_LOC1,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_USART1, .cmu = cmuClock_USART1,
.irq = USART1_RX_IRQn .irq = USART1_RX_IRQn
}, },
@ -253,6 +259,9 @@ static const uart_conf_t uart_config[] = {
.rx_pin = GPIO_PIN(PD, 5), .rx_pin = GPIO_PIN(PD, 5),
.tx_pin = GPIO_PIN(PD, 4), .tx_pin = GPIO_PIN(PD, 4),
.loc = LEUART_ROUTE_LOCATION_LOC0, .loc = LEUART_ROUTE_LOCATION_LOC0,
#if EFM32_UART_MODES
.mode = UART_MODE_8N1,
#endif
.cmu = cmuClock_LEUART0, .cmu = cmuClock_LEUART0,
.irq = LEUART0_IRQn .irq = LEUART0_IRQn
} }

View File

@ -1,3 +1,5 @@
include $(RIOTCPU)/efm32/efm32-features.mk
FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_flashpage
@ -8,4 +10,8 @@ ifeq (1,$(EFM32_TNRG))
FEATURES_PROVIDED += periph_hwrng FEATURES_PROVIDED += periph_hwrng
endif endif
ifeq (1,$(EFM32_UART_MODES))
export CFLAGS += -DEFM32_UART_MODES=1
endif
include $(RIOTCPU)/cortexm_common/Makefile.features include $(RIOTCPU)/cortexm_common/Makefile.features

View File

@ -0,0 +1,4 @@
# This file provides defaults for additional EFM32-specific features. You
# should override them from the command line, or in your Makefile. Note that
# some features may not be applicable to all EFM32 boards or CPUs.
export EFM32_UART_MODES ?= 0

View File

@ -359,6 +359,20 @@ typedef struct {
} timer_conf_t; } timer_conf_t;
/** @} */ /** @} */
/**
* @brief Internal macro for combining UART modes data bits (x), stop bits
* (y, in half bits) and parity (z).
*/
#define UART_MODE(x, y, z) ((z << 8) | ((y * 2) << 4) | x)
/**
* @brief Internal, pre-defined UART modes.
* @{
*/
#define UART_MODE_8N1 UART_MODE(8, 1, 0)
#define UART_MODE_8E1 UART_MODE(8, 1, 2)
/** @} */
/** /**
* @brief UART device configuration. * @brief UART device configuration.
*/ */
@ -366,7 +380,10 @@ typedef struct {
void *dev; /**< UART, USART or LEUART device used */ void *dev; /**< UART, USART or LEUART device used */
gpio_t rx_pin; /**< pin used for RX */ gpio_t rx_pin; /**< pin used for RX */
gpio_t tx_pin; /**< pin used for TX */ gpio_t tx_pin; /**< pin used for TX */
uint32_t loc; /**< location of USART pins */ uint32_t loc; /**< location of UART pins */
#if EFM32_UART_MODES
uint32_t mode; /**< UART mode of operation */
#endif
CMU_Clock_TypeDef cmu; /**< the device CMU channel */ CMU_Clock_TypeDef cmu; /**< the device CMU channel */
IRQn_Type irq; /**< the devices base IRQ channel */ IRQn_Type irq; /**< the devices base IRQ channel */
} uart_conf_t; } uart_conf_t;

View File

@ -26,8 +26,10 @@
#include "periph/gpio.h" #include "periph/gpio.h"
#include "em_usart.h" #include "em_usart.h"
#include "em_usart_utils.h"
#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 #if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0
#include "em_leuart.h" #include "em_leuart.h"
#include "em_leuart_utils.h"
#endif #endif
/** /**
@ -73,6 +75,11 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
init.enable = usartDisable; init.enable = usartDisable;
init.baudrate = baudrate; init.baudrate = baudrate;
#if EFM32_UART_MODES
init.databits = USART_DataBits2Def((uart_config[dev].mode >> 0) & 0xf);
init.stopbits = USART_StopBits2Def((uart_config[dev].mode >> 4) & 0xf);
init.parity = USART_Parity2Def((uart_config[dev].mode >> 8) & 0xf);
#endif
USART_InitAsync(uart, &init); USART_InitAsync(uart, &init);
@ -104,6 +111,11 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
init.enable = leuartDisable; init.enable = leuartDisable;
init.baudrate = baudrate; init.baudrate = baudrate;
#if EFM32_UART_MODES
init.databits = LEUART_DataBits2Def((uart_config[dev].mode >> 0) & 0xf);
init.stopbits = LEUART_StopBits2Def((uart_config[dev].mode >> 4) & 0xf);
init.parity = LEUART_Parity2Def((uart_config[dev].mode >> 8) & 0xf);
#endif
LEUART_Init(leuart, &init); LEUART_Init(leuart, &init);

View File

@ -1,6 +1,6 @@
PKG_NAME=gecko_sdk PKG_NAME=gecko_sdk
PKG_URL=https://github.com/basilfx/RIOT-gecko-sdk PKG_URL=https://github.com/basilfx/RIOT-gecko-sdk
PKG_VERSION=d381e526d68a2d0c951f37040c1c2e168ac66cd6 PKG_VERSION=a5e7be18ef3d7947ab6f04f9cd74f8808da7aece
PKG_LICENSE=Zlib PKG_LICENSE=Zlib
ifneq ($(CPU),efm32) ifneq ($(CPU),efm32)