mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #18946 from jue89/feature/efm32-uart-mode
cpu/efm32: add periph_uart_modecfg support for Gecko Series 2
This commit is contained in:
commit
35a84d29b2
@ -14,7 +14,6 @@ config BOARD_COMMON_SLWSTK6000B
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
# additional hardware present in the board
|
||||
select HAVE_SAUL_GPIO
|
||||
select HAVE_SI7021
|
||||
|
@ -15,6 +15,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -16,7 +16,6 @@ config BOARD_E180_ZG120B_TB
|
||||
select HAS_PERIPH_RTT
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
select HAS_EFM32_CORETEMP
|
||||
select HAS_RIOTBOOT
|
||||
|
||||
|
@ -7,7 +7,7 @@ FEATURES_PROVIDED += periph_adc
|
||||
FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
# Put other features for this board (in alphabetical order)
|
||||
FEATURES_PROVIDED += efm32_coretemp
|
||||
|
@ -17,7 +17,6 @@ config BOARD_IKEA_TRADFRI
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
select HAS_EFM32_CORETEMP
|
||||
select HAS_RIOTBOOT
|
||||
|
||||
|
@ -8,7 +8,7 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
# Put other features for this board (in alphabetical order)
|
||||
FEATURES_PROVIDED += efm32_coretemp
|
||||
|
@ -19,7 +19,6 @@ config BOARD_SLSTK3400A
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
|
||||
select MODULE_SILABS_BC if TEST_KCONFIG
|
||||
# additional hardware present in the board
|
||||
|
@ -9,6 +9,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -19,7 +19,6 @@ config BOARD_SLSTK3401A
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
|
||||
select MODULE_SILABS_AEM if TEST_KCONFIG
|
||||
select MODULE_SILABS_BC if TEST_KCONFIG
|
||||
|
@ -8,6 +8,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -19,7 +19,6 @@ config BOARD_SLSTK3402A
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
|
||||
select MODULE_SILABS_AEM if TEST_KCONFIG
|
||||
select MODULE_SILABS_BC if TEST_KCONFIG
|
||||
|
@ -8,6 +8,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -19,7 +19,6 @@ config BOARD_SLTB001A
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
select MODULE_SILABS_PIC if TEST_KCONFIG
|
||||
|
||||
# additional hardware present in the board
|
||||
|
@ -8,6 +8,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -19,7 +19,6 @@ config BOARD_SLTB009A
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
select HAVE_SAUL_GPIO
|
||||
|
||||
source "$(RIOTBOARD)/common/silabs/Kconfig"
|
||||
|
@ -9,6 +9,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -21,7 +21,6 @@ config BOARD_SLWSTK6220A
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
|
||||
select MODULE_SILABS_AEM if TEST_KCONFIG
|
||||
select MODULE_SILABS_BC if TEST_KCONFIG
|
||||
|
@ -10,6 +10,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -19,7 +19,6 @@ config BOARD_STK3200
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
|
||||
select HAVE_SAUL_GPIO
|
||||
select MODULE_SILABS_BC if TEST_KCONFIG
|
||||
|
@ -8,6 +8,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -21,7 +21,6 @@ config BOARD_STK3600
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
|
||||
select HAVE_SAUL_GPIO
|
||||
select MODULE_SILABS_AEM if TEST_KCONFIG
|
||||
|
@ -10,6 +10,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -21,7 +21,6 @@ config BOARD_STK3700
|
||||
select HAS_PERIPH_SPI
|
||||
select HAS_PERIPH_TIMER
|
||||
select HAS_PERIPH_UART
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
|
||||
select HAVE_SAUL_GPIO
|
||||
select MODULE_SILABS_AEM if TEST_KCONFIG
|
||||
|
@ -10,6 +10,6 @@ FEATURES_PROVIDED += periph_rtc
|
||||
FEATURES_PROVIDED += periph_rtt
|
||||
FEATURES_PROVIDED += periph_spi
|
||||
FEATURES_PROVIDED += periph_timer
|
||||
FEATURES_PROVIDED += periph_uart periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_uart
|
||||
|
||||
include $(RIOTBOARD)/common/silabs/Makefile.features
|
||||
|
@ -17,6 +17,7 @@ config CPU_COMMON_EFM32
|
||||
select HAS_PERIPH_GPIO_LL
|
||||
select HAS_PERIPH_RTT_SET_COUNTER
|
||||
select HAS_PERIPH_RTT_OVERFLOW
|
||||
select HAS_PERIPH_UART_MODECFG
|
||||
select HAS_PERIPH_WDT
|
||||
select HAVE_SHARED_PERIPH_RTT_PERIPH_RTC
|
||||
|
||||
|
@ -20,6 +20,7 @@ FEATURES_PROVIDED += periph_gpio periph_gpio_irq
|
||||
FEATURES_PROVIDED += periph_gpio_ll
|
||||
FEATURES_PROVIDED += periph_rtt_set_counter
|
||||
FEATURES_PROVIDED += periph_rtt_overflow
|
||||
FEATURES_PROVIDED += periph_uart_modecfg
|
||||
FEATURES_PROVIDED += periph_wdt
|
||||
|
||||
FEATURES_CONFLICT += periph_rtc:periph_rtt
|
||||
|
@ -429,18 +429,33 @@ typedef struct {
|
||||
* @brief UART device configuration.
|
||||
*/
|
||||
#ifndef DOXYGEN
|
||||
/**
|
||||
* @brief Marker for unsupported UART modes
|
||||
*/
|
||||
#define UART_MODE_UNSUPPORTED 0xf0
|
||||
|
||||
/**
|
||||
* @brief Override parity values
|
||||
* @{
|
||||
*/
|
||||
#define HAVE_UART_PARITY_T
|
||||
#if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
|
||||
typedef enum {
|
||||
UART_PARITY_NONE = 0,
|
||||
UART_PARITY_ODD = 1,
|
||||
UART_PARITY_EVEN = 2,
|
||||
UART_PARITY_MARK = 3,
|
||||
UART_PARITY_SPACE = 4,
|
||||
UART_PARITY_NONE = 0,
|
||||
UART_PARITY_ODD = 1,
|
||||
UART_PARITY_EVEN = 2,
|
||||
UART_PARITY_MARK = 3,
|
||||
UART_PARITY_SPACE = 4,
|
||||
} uart_parity_t;
|
||||
#else
|
||||
typedef enum {
|
||||
UART_PARITY_NONE = 0,
|
||||
UART_PARITY_EVEN = 2,
|
||||
UART_PARITY_ODD = 3,
|
||||
UART_PARITY_MARK = UART_MODE_UNSUPPORTED | 0,
|
||||
UART_PARITY_SPACE = UART_MODE_UNSUPPORTED | 1,
|
||||
} uart_parity_t;
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@ -448,12 +463,21 @@ typedef enum {
|
||||
* @{
|
||||
*/
|
||||
#define HAVE_UART_DATA_BITS_T
|
||||
#if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
|
||||
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;
|
||||
#else
|
||||
typedef enum {
|
||||
UART_DATA_BITS_5 = UART_MODE_UNSUPPORTED | 0,
|
||||
UART_DATA_BITS_6 = UART_MODE_UNSUPPORTED | 1,
|
||||
UART_DATA_BITS_7 = 1,
|
||||
UART_DATA_BITS_8 = 2,
|
||||
} uart_data_bits_t;
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@ -461,10 +485,17 @@ typedef enum {
|
||||
* @{
|
||||
*/
|
||||
#define HAVE_UART_STOP_BITS_T
|
||||
#if defined(_SILICON_LABS_32B_SERIES_0) || defined(_SILICON_LABS_32B_SERIES_1)
|
||||
typedef enum {
|
||||
UART_STOP_BITS_1 = 2,
|
||||
UART_STOP_BITS_2 = 4,
|
||||
} uart_stop_bits_t;
|
||||
#else
|
||||
typedef enum {
|
||||
UART_STOP_BITS_1 = 1,
|
||||
UART_STOP_BITS_2 = 3,
|
||||
} uart_stop_bits_t;
|
||||
#endif
|
||||
/** @} */
|
||||
#endif /* ndef DOXYGEN */
|
||||
|
||||
|
@ -86,6 +86,29 @@ static inline void _set_pm_mode(uart_t dev) { (void) dev; }
|
||||
static inline void _setup_pm_mode(uart_t dev, uint8_t mode) { (void) dev; (void) mode; }
|
||||
#endif /* !IS_ACTIVE(MODULE_PM_LAYERED) */
|
||||
|
||||
static void _uart_enable(uart_t dev)
|
||||
{
|
||||
EUSART_TypeDef *uart = uart_config[dev].dev;
|
||||
|
||||
/* enable tx */
|
||||
EUSART_Enable_TypeDef enable = eusartEnableTx;
|
||||
|
||||
/* enable rx if needed */
|
||||
if (isr_ctx[dev].rx_cb) {
|
||||
enable |= eusartEnableRx;
|
||||
}
|
||||
|
||||
EUSART_Enable(uart, enable);
|
||||
}
|
||||
|
||||
static void _uart_disable(uart_t dev)
|
||||
{
|
||||
EUSART_TypeDef *uart = uart_config[dev].dev;
|
||||
|
||||
/* disable tx and rx */
|
||||
EUSART_Enable(uart, eusartDisable);
|
||||
}
|
||||
|
||||
#define GET_PIN(x) (x & 0xf)
|
||||
#define GET_PORT(x) (x >> 4)
|
||||
|
||||
@ -170,21 +193,34 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uart_poweron(uart_t dev)
|
||||
#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)
|
||||
{
|
||||
EUSART_TypeDef *uart = uart_config[dev].dev;
|
||||
|
||||
CMU_ClockEnable(uart_config[dev].cmu, true);
|
||||
|
||||
/* enable tx */
|
||||
EUSART_Enable_TypeDef enable = eusartEnableTx;
|
||||
|
||||
/* enable rx if needed */
|
||||
if (isr_ctx[dev].rx_cb) {
|
||||
enable |= eusartEnableRx;
|
||||
if (data_bits >= UART_MODE_UNSUPPORTED || parity >= UART_MODE_UNSUPPORTED) {
|
||||
return UART_NOMODE;
|
||||
}
|
||||
|
||||
EUSART_Enable(uart, enable);
|
||||
/* uart must be disabled to alter modes */
|
||||
_uart_disable(dev);
|
||||
|
||||
uart->FRAMECFG = (data_bits << _EUSART_FRAMECFG_DATABITS_SHIFT)
|
||||
| (parity << _EUSART_FRAMECFG_PARITY_SHIFT)
|
||||
| (stop_bits << _EUSART_FRAMECFG_STOPBITS_SHIFT);
|
||||
|
||||
_uart_enable(dev);
|
||||
|
||||
return UART_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_poweron(uart_t dev)
|
||||
{
|
||||
CMU_ClockEnable(uart_config[dev].cmu, true);
|
||||
|
||||
_uart_enable(dev);
|
||||
|
||||
/* block power mode */
|
||||
_set_pm_mode(dev);
|
||||
@ -192,13 +228,10 @@ void uart_poweron(uart_t dev)
|
||||
|
||||
void uart_poweroff(uart_t dev)
|
||||
{
|
||||
EUSART_TypeDef *uart = uart_config[dev].dev;
|
||||
|
||||
/* unblock power mode */
|
||||
_clear_pm_mode(dev);
|
||||
|
||||
/* disable tx and rx */
|
||||
EUSART_Enable(uart, eusartDisable);
|
||||
_uart_disable(dev);
|
||||
|
||||
CMU_ClockEnable(uart_config[dev].cmu, false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user