Skip to content

Commit

Permalink
Merge pull request #12322 from basilfx/feature/efm32_low_power_feature
Browse files Browse the repository at this point in the history
cpu/efm32: move LOW_POWER_ENABLED to efm32-features.mk
  • Loading branch information
benpicco committed Sep 30, 2019
2 parents fe6d892 + 6a17cb7 commit 1243955
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 25 deletions.
2 changes: 0 additions & 2 deletions boards/slstk3401a/doc.txt
Expand Up @@ -151,8 +151,6 @@ You can override the branch's clock source by adding `CLOCK_LFA=source` to your
### Low-power peripherals
The low-power UART is capable of providing an UART peripheral using a low-speed clock. When the LFB clock source is the LFRCO or LFXO, it can still be used in EM2. However, this limits the baud rate to 9600 baud. If a higher baud rate is desired, set the clock source to CORELEDIV2.

If you don't need low-power peripheral support, passing `LOW_POWER_ENABLED=0` to the compiler will disable support in the drivers (currently LEUART). This feature costs approximately 600 bytes (default compilation settings, LEUART only).

**Note:** peripheral mappings in your board definitions will not be affected by this setting. Ensure you do not refer to any low-power peripherals.

### RTC or RTT
Expand Down
2 changes: 0 additions & 2 deletions boards/slstk3402a/doc.txt
Expand Up @@ -153,8 +153,6 @@ You can override the branch's clock source by adding `CLOCK_LFA=source` to your
### Low-power peripherals
The low-power UART is capable of providing an UART peripheral using a low-speed clock. When the LFB clock source is the LFRCO or LFXO, it can still be used in EM2. However, this limits the baud rate to 9600 baud. If a higher baud rate is desired, set the clock source to CORELEDIV2.

If you don't need low-power peripheral support, passing `LOW_POWER_ENABLED=0` to the compiler will disable support in the drivers (currently LEUART). This feature costs approximately 600 bytes (default compilation settings, LEUART only).

**Note:** peripheral mappings in your board definitions will not be affected by this setting. Ensure you do not refer to any low-power peripherals.

### RTC or RTT
Expand Down
2 changes: 0 additions & 2 deletions boards/sltb001a/doc.txt
Expand Up @@ -139,8 +139,6 @@ You can override the branch's clock source by adding `CLOCK_LFA=source` to your
### Low-power peripherals
The low-power UART is capable of providing an UART peripheral using a low-speed clock. When the LFB clock source is the LFRCO or LFXO, it can still be used in EM2. However, this limits the baud rate to 9600 baud. If a higher baud rate is desired, set the clock source to CORELEDIV2.

If you don't need low-power peripheral support, passing `LOW_POWER_ENABLED=0` to the compiler will disable support in the drivers (currently LEUART). This feature costs approximately 600 bytes (default compilation settings, LEUART only).

**Note:** peripheral mappings in your board definitions will not be affected by this setting. Ensure you do not refer to any low-power peripherals.

### RTC or RTT
Expand Down
4 changes: 4 additions & 0 deletions cpu/efm32/Makefile.features
Expand Up @@ -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
7 changes: 6 additions & 1 deletion cpu/efm32/doc.txt
Expand Up @@ -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.
*/

/**
Expand Down
1 change: 1 addition & 0 deletions cpu/efm32/efm32-features.mk
Expand Up @@ -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
9 changes: 0 additions & 9 deletions cpu/efm32/include/periph_cpu.h
Expand Up @@ -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).
Expand Down
24 changes: 17 additions & 7 deletions cpu/efm32/periph/uart.c
Expand Up @@ -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
Expand All @@ -37,13 +45,15 @@
*/
static uart_isr_ctx_t isr_ctx[UART_NUMOF];

#ifdef USE_LEUART
/**
* @brief Check if device is a U(S)ART device.
*/
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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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++));
Expand All @@ -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));
Expand Down
1 change: 1 addition & 0 deletions tests/cpu_efm32_features/Makefile
Expand Up @@ -11,5 +11,6 @@ BOARD_WHITELIST := ikea-tradfri \

# see cpu/efm32/efm32-features.mk for the supported flags
EFM32_UART_MODES = 1
EFM32_LEUART_ENABLED = 0

include $(RIOTBASE)/Makefile.include
3 changes: 2 additions & 1 deletion tests/cpu_efm32_features/README.md
Expand Up @@ -3,7 +3,8 @@
## Introduction
The EFM32 support several features that can be toggled compile-time.

This test will ensure that RIOT-OS will compile whenever these features are toggled.
This test will ensure that RIOT-OS will compile whenever these features are
toggled.

## Expected result
The test application compiles for EFM32-based boards.
6 changes: 5 additions & 1 deletion tests/cpu_efm32_features/main.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Bas Stottelaar <basstottelaar@gmail.com>
* Copyright (C) 2018-2019 Bas Stottelaar <basstottelaar@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -20,6 +20,10 @@

#include "periph/uart.h"

#if EFM32_LEUART_ENABLED
#error "Expected EFM32_LEUART_ENABLED feature to be disabled."
#endif

int main(void)
{
/* test if uart_config[i].mode is set to a know value */
Expand Down

0 comments on commit 1243955

Please sign in to comment.