zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.6k stars 6.49k forks source link

NRF51822 BLE ~400uA idle current consumption #24564

Closed scttnlsn closed 4 years ago

scttnlsn commented 4 years ago

I'm trying to create a BLE peripheral that periodically notifies the central of a sensor value and then goes to sleep. I'm noticing that even during the k_sleep, there's a significant current draw of ~400uA at 3.3V. Here's the full code of a minimal example that reproduces the issue:

#include <zephyr.h>
#include <device.h>

#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <sys/byteorder.h>
#include <sys/types.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>

static u8_t val = 0;

// 8D9D7800-5B61-412A-AB71-5C7E0E559086
static struct bt_uuid_128 uuid_service = BT_UUID_INIT_128(
  0x86, 0x90, 0x55, 0x0E, 0x7E, 0x5C, 0x71, 0xAB,
  0x2A, 0x41, 0x61, 0x5B, 0x00, 0x78, 0x9D, 0x8D);

// 8D9D7801-5B61-412A-AB71-5C7E0E559086
static struct bt_uuid_128 uuid_characteristic = BT_UUID_INIT_128(
  0x86, 0x90, 0x55, 0x0E, 0x7E, 0x5C, 0x71, 0xAB,
  0x2A, 0x41, 0x61, 0x5B, 0x01, 0x78, 0x9D, 0x8D);

static ssize_t ble_read_value(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset) {
  const uint8_t *value = attr->user_data;
  return bt_gatt_attr_read(conn, attr, buf, len, offset, value, sizeof(*value));
}

static void ble_ccc_cfg_changed(const struct bt_gatt_attr *attr, u16_t value) {
  ARG_UNUSED(attr);

  bool notif_enabled = (value == BT_GATT_CCC_NOTIFY);
  (void) notif_enabled;
}

BT_GATT_SERVICE_DEFINE(ble_gatt_service,
  BT_GATT_PRIMARY_SERVICE(&uuid_service),

  BT_GATT_CHARACTERISTIC(
    &uuid_characteristic.uuid,
    BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
    BT_GATT_PERM_READ,
    ble_read_value,
    NULL,
    &val),

  BT_GATT_CCC(ble_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
);

// advertisement data
static const struct bt_data ad[] = {
  BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR))
};

// scan response data
static const struct bt_data sd[] = {
  BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, (sizeof(CONFIG_BT_DEVICE_NAME) - 1)),
};

void ble_ready(int err) {
  if (err) {
    return;
  }

  bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
}

void main(void) {
  bt_enable(ble_ready);

  int counter = 0;

  while (1) {
    bt_gatt_notify(NULL, &ble_gatt_service.attrs[1], (u8_t *) &counter, 1);
    counter++;
    k_sleep(3000);
  }
}

Do I need to explicitly force a certain sleep mode? Do I need to explicitly disable certain peripherals?

Thanks!

carlescufi commented 4 years ago

@scttnlsn can you please provide your configuration (build/zephyr/.config) as well?

scttnlsn commented 4 years ago

@carlescufi Here's the full contents of build/zephyr/.config:


#
# Modules
#

#
# Optional modules. Make sure they're installed, via the project manifest.
#
# CONFIG_CANOPENNODE is not set
# CONFIG_CIVETWEB is not set
# CONFIG_LIBMETAL is not set
# CONFIG_HAS_SEMTECH_LORAMAC is not set
# CONFIG_HAS_SEMTECH_RADIO_DRIVERS is not set
# CONFIG_MBEDTLS is not set
# CONFIG_HAS_MEC_HAL is not set
CONFIG_HAS_NRFX=y

#
# nrfx drivers
#
# CONFIG_NRFX_ADC is not set
# CONFIG_NRFX_GPIOTE is not set
# CONFIG_NRFX_LPCOMP is not set
# CONFIG_NRFX_NVMC is not set
# CONFIG_NRFX_PPI is not set
# CONFIG_NRFX_QDEC is not set
# CONFIG_NRFX_RNG is not set
# CONFIG_NRFX_RTC is not set
# CONFIG_NRFX_RTC0 is not set
# CONFIG_NRFX_RTC1 is not set
# CONFIG_NRFX_SPI is not set
# CONFIG_NRFX_SPI0 is not set
# CONFIG_NRFX_SPI1 is not set
# CONFIG_NRFX_SPIS is not set
# CONFIG_NRFX_SPIS1 is not set
# CONFIG_NRFX_TEMP is not set
# CONFIG_NRFX_TIMER is not set
# CONFIG_NRFX_TIMER0 is not set
# CONFIG_NRFX_TIMER1 is not set
# CONFIG_NRFX_TIMER2 is not set
# CONFIG_NRFX_TWI is not set
# CONFIG_NRFX_TWI0 is not set
# CONFIG_NRFX_TWI1 is not set
# CONFIG_NRFX_UART is not set
# CONFIG_NRFX_UART0 is not set
# CONFIG_NRFX_WDT is not set
# CONFIG_NRFX_WDT0 is not set
# CONFIG_NRFX_PRS is not set
# CONFIG_NRFX_PRS_BOX_0 is not set
# CONFIG_NRFX_PRS_BOX_1 is not set
# CONFIG_NRFX_PRS_BOX_2 is not set
# CONFIG_NRFX_PRS_BOX_3 is not set
# CONFIG_NRFX_PRS_BOX_4 is not set
# end of nrfx drivers

# CONFIG_OPENAMP is not set
# CONFIG_MIPI_SYST_LIB is not set
# CONFIG_TINYCBOR is not set
# end of Modules

# CONFIG_SPI is not set
# CONFIG_I2C is not set
# CONFIG_MODEM is not set
# CONFIG_BT_HCI_ACL_FLOW_CONTROL is not set
CONFIG_BT_HCI_VS_EXT=y
CONFIG_BOARD="nrf51_ble400"
CONFIG_BT_CTLR=y
CONFIG_SOC="nRF51822_QFAA"
CONFIG_SOC_SERIES="nrf51"
CONFIG_NUM_IRQS=26
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=32768
# CONFIG_WATCHDOG is not set
# CONFIG_GPIO is not set
CONFIG_SYS_POWER_MANAGEMENT=y
# CONFIG_SYS_POWER_DEEP_SLEEP_STATES is not set
CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_1=y
# CONFIG_DEVICE_POWER_MANAGEMENT is not set
CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT=y
CONFIG_CLOCK_CONTROL=y
CONFIG_NRF_RTC_TIMER=y
CONFIG_SYS_CLOCK_TICKS_PER_SEC=32768
CONFIG_BUILD_OUTPUT_HEX=y
CONFIG_TEXT_SECTION_OFFSET=0
CONFIG_FLASH_SIZE=256
CONFIG_FLASH_BASE_ADDRESS=0x0
CONFIG_SRAM_SIZE=16
CONFIG_SRAM_BASE_ADDRESS=0x20000000
# CONFIG_CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS is not set
CONFIG_TINYCRYPT=y
CONFIG_SOC_GECKO_EMU=y
CONFIG_HEAP_MEM_POOL_SIZE=0
CONFIG_BOARD_NRF51_BLE400=y

#
# Board Options
#
# CONFIG_SOC_SERIES_BEETLE is not set
# CONFIG_SOC_SERIES_MPS2 is not set
# CONFIG_SOC_SERIES_MUSCA is not set
# CONFIG_SOC_SERIES_MUSCA_B1 is not set
# CONFIG_SOC_SERIES_SAM3X is not set
# CONFIG_SOC_SERIES_SAM4E is not set
# CONFIG_SOC_SERIES_SAM4S is not set
# CONFIG_SOC_SERIES_SAME70 is not set
# CONFIG_SOC_SERIES_SAMV71 is not set
# CONFIG_SOC_SERIES_SAMD20 is not set
# CONFIG_SOC_SERIES_SAMD21 is not set
# CONFIG_SOC_SERIES_SAMD51 is not set
# CONFIG_SOC_SERIES_SAME51 is not set
# CONFIG_SOC_SERIES_SAME53 is not set
# CONFIG_SOC_SERIES_SAME54 is not set
# CONFIG_SOC_SERIES_SAMR21 is not set
# CONFIG_SOC_SERIES_VALKYRIE is not set
# CONFIG_SOC_SERIES_PSOC62 is not set
# CONFIG_SOC_SERIES_MEC1501X is not set
# CONFIG_SOC_SERIES_MEC1701X is not set
CONFIG_SOC_SERIES_NRF51X=y
# CONFIG_SOC_SERIES_NRF52X is not set
# CONFIG_SOC_SERIES_NRF53X is not set
# CONFIG_SOC_SERIES_NRF91X is not set
# CONFIG_SOC_SERIES_IMX_6X_M4 is not set
# CONFIG_SOC_SERIES_IMX7_M4 is not set
# CONFIG_SOC_SERIES_IMX_RT is not set
# CONFIG_SOC_SERIES_KINETIS_K2X is not set
# CONFIG_SOC_SERIES_KINETIS_K6X is not set
# CONFIG_SOC_SERIES_KINETIS_K8X is not set
# CONFIG_SOC_SERIES_KINETIS_KE1XF is not set
# CONFIG_SOC_SERIES_KINETIS_KL2X is not set
# CONFIG_SOC_SERIES_KINETIS_KV5X is not set
# CONFIG_SOC_SERIES_KINETIS_KWX is not set
# CONFIG_SOC_SERIES_LPC54XXX is not set
# CONFIG_SOC_SERIES_LPC55XXX is not set
# CONFIG_SOC_QEMU_CORTEX_A53 is not set
# CONFIG_SOC_SERIES_EFM32GG11B is not set
# CONFIG_SOC_SERIES_EFM32HG is not set
# CONFIG_SOC_SERIES_EFM32JG12B is not set
# CONFIG_SOC_SERIES_EFM32PG12B is not set
# CONFIG_SOC_SERIES_EFM32WG is not set
# CONFIG_SOC_SERIES_EFR32FG1P is not set
# CONFIG_SOC_SERIES_EFR32MG12P is not set
# CONFIG_SOC_SERIES_STM32F0X is not set
# CONFIG_SOC_SERIES_STM32F1X is not set
# CONFIG_SOC_SERIES_STM32F2X is not set
# CONFIG_SOC_SERIES_STM32F3X is not set
# CONFIG_SOC_SERIES_STM32F4X is not set
# CONFIG_SOC_SERIES_STM32F7X is not set
# CONFIG_SOC_SERIES_STM32G0X is not set
# CONFIG_SOC_SERIES_STM32G4X is not set
# CONFIG_SOC_SERIES_STM32H7X is not set
# CONFIG_SOC_SERIES_STM32L0X is not set
# CONFIG_SOC_SERIES_STM32L1X is not set
# CONFIG_SOC_SERIES_STM32L4X is not set
# CONFIG_SOC_SERIES_STM32MP1X is not set
# CONFIG_SOC_SERIES_STM32WBX is not set
# CONFIG_SOC_TI_LM3S6965 is not set
# CONFIG_SOC_SERIES_CC13X2_CC26X2 is not set
# CONFIG_SOC_SERIES_CC32XX is not set
# CONFIG_SOC_SERIES_MSP432P4XX is not set
# CONFIG_SOC_XILINX_ZYNQMP_RPU is not set

#
# Hardware Configuration
#
CONFIG_SOC_FAMILY="nordic_nrf"
CONFIG_SOC_FAMILY_NRF=y
CONFIG_HAS_HW_NRF_ADC=y
CONFIG_HAS_HW_NRF_CCM=y
CONFIG_HAS_HW_NRF_ECB=y
CONFIG_HAS_HW_NRF_GPIO0=y
CONFIG_HAS_HW_NRF_GPIOTE=y
CONFIG_HAS_HW_NRF_LPCOMP=y
CONFIG_HAS_HW_NRF_MPU=y
CONFIG_HAS_HW_NRF_PPI=y
CONFIG_HAS_HW_NRF_QDEC=y
CONFIG_HAS_HW_NRF_RNG=y
CONFIG_HAS_HW_NRF_RTC0=y
CONFIG_HAS_HW_NRF_RTC1=y
CONFIG_HAS_HW_NRF_SPI0=y
CONFIG_HAS_HW_NRF_SPI1=y
CONFIG_HAS_HW_NRF_SPIS1=y
CONFIG_HAS_HW_NRF_TEMP=y
CONFIG_HAS_HW_NRF_TIMER0=y
CONFIG_HAS_HW_NRF_TIMER1=y
CONFIG_HAS_HW_NRF_TIMER2=y
CONFIG_HAS_HW_NRF_TWI0=y
CONFIG_HAS_HW_NRF_TWI1=y
CONFIG_HAS_HW_NRF_UART0=y
CONFIG_HAS_HW_NRF_WDT=y
CONFIG_SOC_NRF51822_QFAA=y
# CONFIG_SOC_NRF51822_QFAB is not set
# CONFIG_SOC_NRF51822_QFAC is not set
# end of Hardware Configuration

CONFIG_SOC_COMPATIBLE_NRF=y

#
# ARM Options
#
CONFIG_CPU_CORTEX=y
CONFIG_CPU_CORTEX_M=y
CONFIG_ISA_THUMB2=y
CONFIG_STACK_ALIGN_DOUBLE_WORD=y
# CONFIG_RUNTIME_NMI is not set
CONFIG_PLATFORM_SPECIFIC_INIT=y
CONFIG_FAULT_DUMP=2
CONFIG_CPU_CORTEX_M0=y
CONFIG_ARMV6_M_ARMV8_M_BASELINE=y
CONFIG_XIP=y

#
# ARM Cortex-M0/M0+/M3/M4/M7/M23/M33 options
#
CONFIG_GEN_ISR_TABLES=y
# CONFIG_SW_VECTOR_RELAY is not set
# end of ARM Cortex-M0/M0+/M3/M4/M7/M23/M33 options

CONFIG_GEN_IRQ_VECTOR_TABLE=y
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_IDLE_STACK_SIZE=256
CONFIG_ISR_STACK_SIZE=2048
CONFIG_TEST_EXTRA_STACKSIZE=0
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1024
CONFIG_OFFLOAD_WORKQUEUE_STACK_SIZE=1024
CONFIG_ARCH="arm"
# end of ARM Options

# CONFIG_ARC is not set
CONFIG_ARM=y
# CONFIG_X86 is not set
# CONFIG_NIOS2 is not set
# CONFIG_RISCV is not set
# CONFIG_XTENSA is not set
# CONFIG_ARCH_POSIX is not set

#
# General Architecture Options
#
# CONFIG_STACK_GROWS_UP is not set

#
# Interrupt Configuration
#
# CONFIG_DYNAMIC_INTERRUPTS is not set
CONFIG_GEN_SW_ISR_TABLE=y
CONFIG_ARCH_SW_ISR_TABLE_ALIGN=0
CONFIG_GEN_IRQ_START_VECTOR=0
# end of Interrupt Configuration
# end of General Architecture Options

CONFIG_ARCH_HAS_RAMFUNC_SUPPORT=y
CONFIG_ARCH_HAS_NESTED_EXCEPTION_DETECTION=y
CONFIG_ARCH_HAS_THREAD_ABORT=y

#
# General Kernel Options
#
CONFIG_MULTITHREADING=y
CONFIG_NUM_COOP_PRIORITIES=16
CONFIG_NUM_PREEMPT_PRIORITIES=15
CONFIG_MAIN_THREAD_PRIORITY=0
CONFIG_COOP_ENABLED=y
CONFIG_PREEMPT_ENABLED=y
CONFIG_PRIORITY_CEILING=0
CONFIG_NUM_METAIRQ_PRIORITIES=0
# CONFIG_SCHED_DEADLINE is not set
# CONFIG_SCHED_CPU_MASK is not set
# CONFIG_THREAD_STACK_INFO is not set
# CONFIG_THREAD_CUSTOM_DATA is not set
CONFIG_ERRNO=y
CONFIG_SCHED_DUMB=y
# CONFIG_SCHED_SCALABLE is not set
# CONFIG_SCHED_MULTIQ is not set
# CONFIG_WAITQ_SCALABLE is not set
CONFIG_WAITQ_DUMB=y

#
# Kernel Debugging and Metrics
#
# CONFIG_INIT_STACKS is not set
# CONFIG_KERNEL_DEBUG is not set
CONFIG_BOOT_DELAY=0
# CONFIG_EXECUTION_BENCHMARKING is not set
# CONFIG_THREAD_MONITOR is not set
# CONFIG_THREAD_NAME is not set
# end of Kernel Debugging and Metrics

#
# Work Queue Options
#
CONFIG_SYSTEM_WORKQUEUE_PRIORITY=-1
CONFIG_OFFLOAD_WORKQUEUE_PRIORITY=-1
# end of Work Queue Options

#
# Atomic Operations
#
CONFIG_ATOMIC_OPERATIONS_C=y
# end of Atomic Operations

#
# Timer API Options
#
CONFIG_TIMESLICING=y
CONFIG_TIMESLICE_SIZE=0
CONFIG_TIMESLICE_PRIORITY=0
CONFIG_POLL=y
# end of Timer API Options

#
# Other Kernel Object Options
#
CONFIG_NUM_MBOX_ASYNC_MSGS=10
CONFIG_NUM_PIPE_ASYNC_MSGS=10
# end of Other Kernel Object Options

CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN=y
CONFIG_SWAP_NONATOMIC=y
CONFIG_SYS_CLOCK_EXISTS=y

#
# Initialization Priorities
#
CONFIG_KERNEL_INIT_PRIORITY_OBJECTS=30
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT=40
CONFIG_KERNEL_INIT_PRIORITY_DEVICE=50
CONFIG_APPLICATION_INIT_PRIORITY=90
# end of Initialization Priorities

#
# Security Options
#
# CONFIG_STACK_CANARIES is not set
CONFIG_STACK_POINTER_RANDOM=0
# end of Security Options

#
# SMP Options
#
CONFIG_MP_NUM_CPUS=1
# end of SMP Options

CONFIG_TICKLESS_IDLE=y
CONFIG_TICKLESS_IDLE_THRESH=3
CONFIG_TICKLESS_KERNEL=y
# CONFIG_SYS_PM_STATE_LOCK is not set
# CONFIG_SYS_PM_DIRECT_FORCE_MODE is not set
# CONFIG_SYS_PM_DEBUG is not set
CONFIG_SYS_PM_POLICY_RESIDENCY=y
# CONFIG_SYS_PM_POLICY_DUMMY is not set
# CONFIG_SYS_PM_POLICY_APP is not set
CONFIG_SYS_PM_MIN_RESIDENCY_DEEP_SLEEP_1=60000
# end of General Kernel Options

CONFIG_HAS_DTS=y

#
# Device Drivers
#
# CONFIG_IEEE802154 is not set
# CONFIG_CONSOLE is not set
CONFIG_HAS_SEGGER_RTT=y
# CONFIG_USE_SEGGER_RTT is not set
# CONFIG_NET_LOOPBACK is not set
# CONFIG_SERIAL is not set

#
# Interrupt Controllers
#
# CONFIG_SWERV_PIC is not set
# CONFIG_MULTI_LEVEL_INTERRUPTS is not set
# end of Interrupt Controllers

#
# Timer Drivers
#
# CONFIG_SYSTEM_CLOCK_DISABLE is not set
# CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME is not set
# CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE is not set
CONFIG_SYSTEM_CLOCK_INIT_PRIORITY=0
CONFIG_TICKLESS_CAPABLE=y
# end of Timer Drivers

CONFIG_ENTROPY_GENERATOR=y
CONFIG_ENTROPY_NRF5_RNG=y
CONFIG_ENTROPY_NRF5_BIAS_CORRECTION=y
CONFIG_ENTROPY_NRF5_THR_POOL_SIZE=8
CONFIG_ENTROPY_NRF5_THR_THRESHOLD=4
CONFIG_ENTROPY_NRF5_ISR_POOL_SIZE=16
CONFIG_ENTROPY_NRF5_ISR_THRESHOLD=12
CONFIG_ENTROPY_NRF5_PRI=2
CONFIG_ENTROPY_HAS_DRIVER=y
CONFIG_ENTROPY_NAME="ENTROPY_0"
# CONFIG_SHARED_IRQ is not set
# CONFIG_I2S is not set
# CONFIG_PWM is not set
# CONFIG_PINMUX is not set
# CONFIG_ADC is not set
CONFIG_CLOCK_CONTROL_NRF=y
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC is not set
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_250PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_100PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_75PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_50PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM is not set
CONFIG_CLOCK_CONTROL_NRF_K32SRC_20PPM=y
# CONFIG_PTP_CLOCK is not set
# CONFIG_IPM is not set
# CONFIG_FLASH is not set
# CONFIG_SENSOR is not set
# CONFIG_COUNTER is not set
# CONFIG_DMA is not set
# CONFIG_USB is not set
# CONFIG_CRYPTO is not set
# CONFIG_DISPLAY is not set
# CONFIG_LED_STRIP is not set
# CONFIG_WIFI is not set
# CONFIG_LED is not set
# CONFIG_CAN is not set
# CONFIG_AUDIO is not set
# CONFIG_NEURAL_NET_ACCEL is not set
# CONFIG_HWINFO is not set
# CONFIG_ESPI is not set
# CONFIG_PS2 is not set
# CONFIG_KSCAN is not set
# CONFIG_VIDEO is not set
# CONFIG_EEPROM is not set
# end of Device Drivers

#
# C Library
#
CONFIG_MINIMAL_LIBC=y
# CONFIG_NEWLIB_LIBC is not set
# CONFIG_EXTERNAL_LIBC is not set
CONFIG_HAS_NEWLIB_LIBC_NANO=y
CONFIG_MINIMAL_LIBC_MALLOC=y
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=0
CONFIG_MINIMAL_LIBC_CALLOC=y
CONFIG_MINIMAL_LIBC_REALLOCARRAY=y
# CONFIG_MINIMAL_LIBC_LL_PRINTF is not set
# end of C Library

#
# Additional libraries
#
# CONFIG_LVGL is not set

#
# OS Support Library
#
# CONFIG_JSON_LIBRARY is not set
# CONFIG_RING_BUFFER is not set
# CONFIG_BASE64 is not set
# end of OS Support Library

CONFIG_POSIX_MAX_FDS=4
# CONFIG_POSIX_API is not set
# CONFIG_PTHREAD_IPC is not set
# CONFIG_POSIX_CLOCK is not set
CONFIG_MAX_TIMER_COUNT=5
# CONFIG_POSIX_MQUEUE is not set
# CONFIG_UPDATEHUB is not set
# end of Additional libraries

CONFIG_BT=y
CONFIG_BT_HCI=y
# CONFIG_BT_CUSTOM is not set
# CONFIG_BT_HCI_RAW is not set
CONFIG_BT_PERIPHERAL=y
# CONFIG_BT_CENTRAL is not set
CONFIG_BT_BROADCASTER=y

#
# Observer
#
# CONFIG_BT_OBSERVER is not set
# end of Observer

#
# GATT Services
#
# CONFIG_BT_GATT_DIS is not set
# CONFIG_BT_GATT_BAS is not set
# CONFIG_BT_GATT_HRS is not set
# end of GATT Services

CONFIG_BT_CONN=y
CONFIG_BT_MAX_CONN=1
# CONFIG_BT_REMOTE_VERSION is not set
CONFIG_BT_PHY_UPDATE=y
CONFIG_BT_DATA_LEN_UPDATE=y
CONFIG_BT_HAS_HCI_VS=y
CONFIG_BT_HCI_VS=y
# CONFIG_BT_WAIT_NOP is not set
CONFIG_BT_ASSERT=y
CONFIG_BT_ASSERT_VERBOSE=y
# CONFIG_BT_ASSERT_PANIC is not set
CONFIG_BT_DEBUG_NONE=y
# CONFIG_BT_DEBUG_LOG is not set
# CONFIG_BT_DEBUG_MONITOR is not set

#
# Host Stack Configuration
#
CONFIG_BT_HCI_HOST=y
CONFIG_BT_HCI_CMD_COUNT=2
CONFIG_BT_RX_BUF_COUNT=3
CONFIG_BT_RX_BUF_LEN=76
CONFIG_BT_DISCARDABLE_BUF_COUNT=3
CONFIG_BT_DISCARDABLE_BUF_SIZE=45
CONFIG_BT_HCI_TX_STACK_SIZE=640
# CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT is not set
CONFIG_BT_HCI_ECC_STACK_SIZE=1100
CONFIG_BT_HCI_TX_PRIO=7
CONFIG_BT_HCI_RESERVE=0
CONFIG_BT_RECV_IS_RX_THREAD=y
CONFIG_BT_RX_STACK_SIZE=1024
CONFIG_BT_RX_PRIO=8
# CONFIG_BT_WHITELIST is not set
CONFIG_BT_CONN_TX_MAX=3
CONFIG_BT_AUTO_PHY_UPDATE=y
# CONFIG_BT_REMOTE_INFO is not set
# CONFIG_BT_SMP is not set

#
# L2CAP Options
#
CONFIG_BT_L2CAP_TX_BUF_COUNT=3
CONFIG_BT_L2CAP_TX_FRAG_COUNT=2
CONFIG_BT_L2CAP_TX_MTU=23
# end of L2CAP Options

#
# ATT and GATT Options
#
CONFIG_BT_ATT_ENFORCE_FLOW=y
CONFIG_BT_ATT_PREPARE_COUNT=0
CONFIG_BT_ATT_TX_MAX=3
CONFIG_BT_GATT_SERVICE_CHANGED=y
CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_BT_GATT_CACHING=y
# CONFIG_BT_GATT_ENFORCE_CHANGE_UNAWARE is not set
# CONFIG_BT_GATT_CLIENT is not set
CONFIG_BT_GATT_READ_MULTIPLE=y
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=y
CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=y
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=2400
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=3200
CONFIG_BT_PERIPHERAL_PREF_SLAVE_LATENCY=10
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=42
# end of ATT and GATT Options

CONFIG_BT_MAX_PAIRED=0
CONFIG_BT_CREATE_CONN_TIMEOUT=3
CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT=5000
# CONFIG_BT_DEVICE_NAME_DYNAMIC is not set
CONFIG_BT_DEVICE_NAME="Zephyr"
CONFIG_BT_DEVICE_APPEARANCE=0
CONFIG_BT_ID_MAX=1
# CONFIG_BT_ECC is not set
# CONFIG_BT_HOST_CCM is not set
# CONFIG_BT_TESTING is not set
# CONFIG_BT_BREDR is not set
# CONFIG_BT_HCI_VS_EVT_USER is not set

#
# BLE Controller support
#
CONFIG_BT_CTLR_LE_ENC_SUPPORT=y
CONFIG_BT_CTLR_CONN_PARAM_REQ_SUPPORT=y
CONFIG_BT_CTLR_EXT_REJ_IND_SUPPORT=y
CONFIG_BT_CTLR_SLAVE_FEAT_REQ_SUPPORT=y
CONFIG_BT_CTLR_EXT_SCAN_FP_SUPPORT=y
CONFIG_BT_CTLR_ADV_EXT_SUPPORT=y
CONFIG_BT_CTLR_CHAN_SEL_2_SUPPORT=y
CONFIG_BT_CTLR_MIN_USED_CHAN_SUPPORT=y
CONFIG_BT_CTLR_DTM_HCI_SUPPORT=y
CONFIG_BT_CTLR_XTAL_ADVANCED_SUPPORT=y
CONFIG_BT_CTLR_SCHED_ADVANCED_SUPPORT=y
CONFIG_BT_CTLR_TIFS_HW_SUPPORT=y
CONFIG_BT_LL_SW_SPLIT=y
# CONFIG_BT_LL_SW_LEGACY is not set
CONFIG_BT_LLL_VENDOR_NORDIC=y

#
# BLE Controller configuration
#
CONFIG_BT_CTLR_CRYPTO=y
CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE=448
CONFIG_BT_CTLR_RX_PRIO=6
CONFIG_BT_CTLR_HCI_VS_BUILD_INFO=""
CONFIG_BT_CTLR_RX_BUFFERS=1
CONFIG_BT_CTLR_TX_BUFFERS=3
CONFIG_BT_CTLR_TX_BUFFER_SIZE=27
# CONFIG_BT_CTLR_TX_PWR_PLUS_4 is not set
CONFIG_BT_CTLR_TX_PWR_0=y
# CONFIG_BT_CTLR_TX_PWR_MINUS_4 is not set
# CONFIG_BT_CTLR_TX_PWR_MINUS_8 is not set
# CONFIG_BT_CTLR_TX_PWR_MINUS_12 is not set
# CONFIG_BT_CTLR_TX_PWR_MINUS_16 is not set
# CONFIG_BT_CTLR_TX_PWR_MINUS_20 is not set
# CONFIG_BT_CTLR_TX_PWR_MINUS_30 is not set
# CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL is not set
CONFIG_BT_CTLR_COMPANY_ID=0x05F1
CONFIG_BT_CTLR_SUBVERSION_NUMBER=0xFFFF

#
# BLE Controller features
#
CONFIG_BT_CTLR_LE_ENC=y
CONFIG_BT_CTLR_CONN_PARAM_REQ=y
CONFIG_BT_CTLR_EXT_REJ_IND=y
CONFIG_BT_CTLR_SLAVE_FEAT_REQ=y
CONFIG_BT_CTLR_LE_PING=y
CONFIG_BT_CTLR_MIN_USED_CHAN=y
CONFIG_BT_CTLR_CHAN_SEL_2=y
# CONFIG_BT_CTLR_ADV_EXT is not set
# CONFIG_BT_CTLR_DTM_HCI is not set
# CONFIG_BT_CTLR_ADVANCED_FEATURES is not set
CONFIG_BT_CTLR_FILTER=y
CONFIG_BT_CTLR_XTAL_ADVANCED=y
CONFIG_BT_CTLR_XTAL_THRESHOLD=1500
CONFIG_BT_CTLR_LLL_PRIO=0
CONFIG_BT_CTLR_ULL_HIGH_PRIO=0
CONFIG_BT_CTLR_ULL_LOW_PRIO=0
CONFIG_BT_CTLR_LOW_LAT=y
CONFIG_BT_CTLR_LOW_LAT_ULL=y
CONFIG_BT_CTLR_TIFS_HW=y
CONFIG_BT_CTLR_LLCP_CONN=1
CONFIG_BT_MAYFLY_YIELD_AFTER_CALL=y
CONFIG_BT_TICKER_COMPATIBILITY_MODE=y

#
# BLE Controller hardware configuration
#

#
# BLE Controller debug configuration
#
# CONFIG_BT_CTLR_PROFILE_ISR is not set
# CONFIG_BT_CTLR_ASSERT_HANDLER is not set
# CONFIG_BT_SHELL is not set
CONFIG_BT_COMPANY_ID=0x05F1
# CONFIG_CONSOLE_SUBSYS is not set
# CONFIG_CPLUSPLUS is not set

#
# System Monitoring Options
#
# CONFIG_BOOT_TIME_MEASUREMENT is not set
# CONFIG_STATS is not set
# end of System Monitoring Options

#
# Debugging Options
#
# CONFIG_DEBUG is not set
# CONFIG_STACK_USAGE is not set
# CONFIG_STACK_SENTINEL is not set
CONFIG_PRINTK=y
# CONFIG_EARLY_CONSOLE is not set
# CONFIG_ASSERT is not set
# CONFIG_FORCE_NO_ASSERT is not set
CONFIG_ASSERT_VERBOSE=y
# CONFIG_ASSERT_NO_FILE_INFO is not set
# CONFIG_ASSERT_NO_COND_INFO is not set
# CONFIG_ASSERT_NO_MSG_INFO is not set
# CONFIG_OBJECT_TRACING is not set
# CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT is not set
# CONFIG_DEBUG_INFO is not set
# CONFIG_OPENOCD_SUPPORT is not set
# end of Debugging Options

# CONFIG_DISK_ACCESS is not set

#
# File Systems
#
# CONFIG_FILE_SYSTEM is not set
# CONFIG_NVS is not set
# end of File Systems

# CONFIG_LOG is not set

#
# Management
#
# CONFIG_MCUMGR_SMP_BT is not set
# CONFIG_MCUMGR_SMP_SHELL is not set
# CONFIG_MCUMGR_SMP_UART is not set
# CONFIG_MCUMGR is not set
# end of Management

#
# Networking
#
CONFIG_NET_BUF=y
CONFIG_NET_BUF_USER_DATA_SIZE=4
# CONFIG_NET_BUF_LOG is not set
# CONFIG_NET_BUF_POOL_USAGE is not set
# CONFIG_NETWORKING is not set
# end of Networking

# CONFIG_SHELL is not set
# CONFIG_IMG_MANAGER is not set

#
# Random subsystem
#
CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y
# CONFIG_XOROSHIRO_RANDOM_GENERATOR is not set
CONFIG_CSPRING_ENABLED=y
CONFIG_HARDWARE_DEVICE_CS_GENERATOR=y
# CONFIG_CTR_DRBG_CSPRNG_GENERATOR is not set
# end of Random subsystem

#
# Storage
#
# end of Storage

# CONFIG_SETTINGS is not set

#
# Testing
#
# CONFIG_ZTEST is not set
# CONFIG_ZTEST_MOCKING is not set
# CONFIG_TEST is not set
# CONFIG_TEST_SHELL is not set
# CONFIG_TEST_USERSPACE is not set
CONFIG_TEST_ARM_CORTEX_M=y
# end of Testing

# CONFIG_TRACING is not set
# CONFIG_CHARACTER_FRAMEBUFFER is not set
# CONFIG_JWT is not set

#
# Controller Area Network (CAN) bus subsystem
#
# CONFIG_ISOTP is not set
# end of Controller Area Network (CAN) bus subsystem

#
# External Sources
#

#
# HALs
#
CONFIG_HAS_CMSIS_CORE=y
CONFIG_HAS_CMSIS_CORE_M=y
# end of HALs

#
# Cryptography
#
# CONFIG_TINYCRYPT_CTR_PRNG is not set
# CONFIG_TINYCRYPT_SHA256 is not set
# CONFIG_TINYCRYPT_ECC_DH is not set
# CONFIG_TINYCRYPT_ECC_DSA is not set
CONFIG_TINYCRYPT_AES=y
# CONFIG_TINYCRYPT_AES_CBC is not set
# CONFIG_TINYCRYPT_AES_CTR is not set
# CONFIG_TINYCRYPT_AES_CCM is not set
CONFIG_TINYCRYPT_AES_CMAC=y
# end of Cryptography

# CONFIG_FNMATCH is not set
# end of External Sources

CONFIG_TOOLCHAIN_GNUARMEMB=y

#
# Build and Link Features
#

#
# Linker Options
#
# CONFIG_LINKER_ORPHAN_SECTION_PLACE is not set
CONFIG_LINKER_ORPHAN_SECTION_WARN=y
# CONFIG_LINKER_ORPHAN_SECTION_ERROR is not set
# CONFIG_CODE_DATA_RELOCATION is not set
CONFIG_HAS_FLASH_LOAD_OFFSET=y
# CONFIG_USE_DT_CODE_PARTITION is not set
CONFIG_FLASH_LOAD_OFFSET=0
CONFIG_FLASH_LOAD_SIZE=0
# CONFIG_HAVE_CUSTOM_LINKER_SCRIPT is not set
# CONFIG_CUSTOM_RODATA_LD is not set
# CONFIG_CUSTOM_RWDATA_LD is not set
# CONFIG_CUSTOM_SECTIONS_LD is not set
CONFIG_KERNEL_ENTRY="__start"
CONFIG_LINKER_SORT_BY_ALIGNMENT=y
# end of Linker Options

#
# Compiler Options
#
# CONFIG_NATIVE_APPLICATION is not set
CONFIG_SIZE_OPTIMIZATIONS=y
# CONFIG_SPEED_OPTIMIZATIONS is not set
# CONFIG_DEBUG_OPTIMIZATIONS is not set
# CONFIG_NO_OPTIMIZATIONS is not set
CONFIG_COMPILER_OPT=""
# end of Compiler Options

# CONFIG_ASSERT_ON_ERRORS is not set
# CONFIG_NO_RUNTIME_CHECKS is not set
CONFIG_RUNTIME_ERROR_CHECKS=y

#
# Build Options
#
CONFIG_KERNEL_BIN_NAME="zephyr"
CONFIG_OUTPUT_STAT=y
CONFIG_OUTPUT_DISASSEMBLY=y
CONFIG_OUTPUT_PRINT_MEMORY_USAGE=y
CONFIG_BUILD_OUTPUT_BIN=y
# CONFIG_BUILD_OUTPUT_EXE is not set
# CONFIG_BUILD_OUTPUT_S19 is not set
# CONFIG_BUILD_NO_GAP_FILL is not set
# CONFIG_BUILD_OUTPUT_STRIPPED is not set
# CONFIG_APPLICATION_DEFINED_SYSCALL is not set
# CONFIG_MAKEFILE_EXPORTS is not set
# end of Build Options
# end of Build and Link Features

#
# Boot Options
#
# CONFIG_IS_BOOTLOADER is not set
# CONFIG_BOOTLOADER_MCUBOOT is not set
# CONFIG_REBOOT is not set
# CONFIG_MISRA_SANE is not set
# end of Boot Options

#
# Compatibility
#
CONFIG_COMPAT_INCLUDES=y
# end of Compatibility
pabigot commented 4 years ago

The normal go-to explanation for idle power draw of this level is a UART left active, but it seems you don't have UART enabled so that wouldn't be the case here. I do wonder about the impact of SEGGER_RTT, might try turning that off.

How are you measuring the power? FWIW my testing long ago showed the base BLE400 current usage was 120 uA, even if the jumpers to connect UART, LED, and buttons were removed, in applications where the underlying nRF51 daughterboard was using only 3.2 uA. It may be that the draw is not due to the nRF51 but rather something else on your board.

scttnlsn commented 4 years ago

@pabigot Thanks for the tips. I tried powering just the daughterboard and that brought the usage down to ~200uA so I must have some leakage somewhere on the motherboard. The SEGGER_RTT value did not seem to have any impact. I'm just using a DMM to measure the current consumption but perhaps it's so low now that I need a proper device to overcome the burden voltage.

pabigot commented 4 years ago

I like the EEVBlog uCurrent for DMM-based measurement, but I don't see where you can buy them anymore.

carlescufi commented 4 years ago

@scttnlsn Nordic does offer a Power Profiler Kit in case that is of interest: https://www.nordicsemi.com/Software-and-tools/Development-Kits/Power-Profiler-Kit Do you think we should close the issue now?

scttnlsn commented 4 years ago

OK, thanks for the suggestions. Yeah, let's close this for now. I'll put together a better current measuring setup and reopen this if I'm still having issues going forward. Thanks!

beckmx commented 1 year ago

hello guys @scttnlsn @carlescufi a quick doubt, I am also using zephyr and i am migrating a project, i wanted to ask you if by using k_sleep might be enough for making the device into deep sleep? specifically i am doing this:

void main(void)
{
    bt_addr_le_t ble_addr = { BT_ADDR_LE_RANDOM, addr };
    bt_id_create(&ble_addr, NULL);
    bt_enable(bt_ready);
    while (1) {
        k_sleep(K_SECONDS(3));
        bt_le_adv_stop();
        k_sleep(K_SECONDS(30));
        bt_le_adv_start(
            BT_LE_ADV_NCONN_IDENTITY, advertisement_payload, 
            ARRAY_SIZE(advertisement_payload),
            NULL,
            0
        );
    }
}

it does work and advertises shortly as i wanted, but i have my doubts, if it is really deep sleep or in my use case can be considered a good option like this, thanx!