diff --git a/cpu/efm32/Makefile.features b/cpu/efm32/Makefile.features index 210e48d1aa..7de1476cdd 100644 --- a/cpu/efm32/Makefile.features +++ b/cpu/efm32/Makefile.features @@ -15,4 +15,8 @@ ifeq (1,$(EFM32_UART_MODES)) CFLAGS += -DEFM32_UART_MODES=1 endif +ifeq (1,$(EFM32_LEUART_ENABLED)) + CFLAGS += -DEFM32_LEUART_ENABLED=1 +endif + include $(RIOTCPU)/cortexm_common/Makefile.features diff --git a/cpu/efm32/doc.txt b/cpu/efm32/doc.txt index 2983ba3fb9..4e037d791e 100644 --- a/cpu/efm32/doc.txt +++ b/cpu/efm32/doc.txt @@ -62,7 +62,12 @@ * ======================= * * The EFM32/EFR32/EZR32 MCUs have support for low-power peripherals. Support - * is enabled by default, but can be disabled by setting LOW_POWER_ENABLED=0. + * is enabled by default, but can be disabled if not used. + * + * - Setting `EFM32_LEUART_ENABLED=0` will disable support for the LEUART + * in the UART driver peripheral and save approximately 400 bytes. + * + * Refer to `cpu/efm32/efm32-features.mk` for more options. */ /** diff --git a/cpu/efm32/efm32-features.mk b/cpu/efm32/efm32-features.mk index d9cc3da6f0..d4997373e6 100644 --- a/cpu/efm32/efm32-features.mk +++ b/cpu/efm32/efm32-features.mk @@ -2,3 +2,4 @@ # 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 +export EFM32_LEUART_ENABLED ?= 1 diff --git a/cpu/efm32/include/periph_cpu.h b/cpu/efm32/include/periph_cpu.h index 6446559350..a024187215 100644 --- a/cpu/efm32/include/periph_cpu.h +++ b/cpu/efm32/include/periph_cpu.h @@ -38,15 +38,6 @@ extern "C" { #endif -/** - * @brief Enable support for Low-power peripherals (if supported by CPU). - * @{ - */ -#ifndef LOW_POWER_ENABLED -#define LOW_POWER_ENABLED (1) -#endif -/** @} */ - /** * @brief Internal macro for combining ADC resolution (x) with number of * shifts (y). diff --git a/cpu/efm32/periph/uart.c b/cpu/efm32/periph/uart.c index 15847c03de..8d0d5f72e1 100644 --- a/cpu/efm32/periph/uart.c +++ b/cpu/efm32/periph/uart.c @@ -27,7 +27,15 @@ #include "em_usart.h" #include "em_usart_utils.h" -#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 + +/** + * @brief Defines whether LEUART is enabled and supported + */ +#if EFM32_LEUART_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 +#define USE_LEUART +#endif + +#ifdef USE_LEUART #include "em_leuart.h" #include "em_leuart_utils.h" #endif @@ -37,6 +45,7 @@ */ static uart_isr_ctx_t isr_ctx[UART_NUMOF]; +#ifdef USE_LEUART /** * @brief Check if device is a U(S)ART device. */ @@ -44,6 +53,7 @@ static inline bool _is_usart(uart_t dev) { return ((uint32_t) uart_config[dev].dev) < LEUART0_BASE; } +#endif int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) { @@ -61,7 +71,7 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) gpio_init(uart_config[dev].tx_pin, GPIO_OUT); /* initialize the UART/USART/LEUART device */ -#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 +#ifdef USE_LEUART if (_is_usart(dev)) { #endif USART_TypeDef *uart = (USART_TypeDef *) uart_config[dev].dev; @@ -98,7 +108,7 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) /* enable peripheral */ USART_Enable(uart, usartEnable); -#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 +#ifdef USE_LEUART } else { LEUART_TypeDef *leuart = (LEUART_TypeDef *) uart_config[dev].dev; @@ -146,13 +156,13 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) void uart_write(uart_t dev, const uint8_t *data, size_t len) { -#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 +#ifdef USE_LEUART if (_is_usart(dev)) { #endif while (len--) { USART_Tx(uart_config[dev].dev, *(data++)); } -#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 +#ifdef USE_LEUART } else { while (len--) { LEUART_Tx(uart_config[dev].dev, *(data++)); @@ -173,13 +183,13 @@ void uart_poweroff(uart_t dev) static void rx_irq(uart_t dev) { -#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 +#ifdef USE_LEUART if (_is_usart(dev)) { #endif if (USART_IntGet(uart_config[dev].dev) & USART_IF_RXDATAV) { isr_ctx[dev].rx_cb(isr_ctx[dev].arg, USART_RxDataGet(uart_config[dev].dev)); } -#if LOW_POWER_ENABLED && defined(LEUART_COUNT) && LEUART_COUNT > 0 +#ifdef USE_LEUART } else { if (LEUART_IntGet(uart_config[dev].dev) & LEUART_IF_RXDATAV) { isr_ctx[dev].rx_cb(isr_ctx[dev].arg, LEUART_RxDataGet(uart_config[dev].dev));