Skip to content
Snippets Groups Projects
Commit 0c47233f authored by Bas Stottelaar's avatar Bas Stottelaar
Browse files

cpu: efm32: add support for non-standard UART modes.

parent 63ca6130
Branches
No related tags found
No related merge requests found
include $(RIOTCPU)/efm32/efm32-features.mk
FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_flashpage
......@@ -8,4 +10,8 @@ ifeq (1,$(EFM32_TNRG))
FEATURES_PROVIDED += periph_hwrng
endif
ifeq (1,$(EFM32_UART_MODES))
export CFLAGS += -DEFM32_UART_MODES=1
endif
include $(RIOTCPU)/cortexm_common/Makefile.features
# 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
......@@ -359,6 +359,20 @@ typedef struct {
} 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.
*/
......@@ -366,7 +380,10 @@ typedef struct {
void *dev; /**< UART, USART or LEUART device used */
gpio_t rx_pin; /**< pin used for RX */
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 */
IRQn_Type irq; /**< the devices base IRQ channel */
} uart_conf_t;
......
......@@ -26,8 +26,10 @@
#include "periph/gpio.h"
#include "em_usart.h"
#include "em_usart_utils.h"
#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0
#include "em_leuart.h"
#include "em_leuart_utils.h"
#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.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);
......@@ -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.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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment