This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Low power BLE advertising with Zephyr on nrf52840, is it supported?

I'm using the NRF52840-DK with the SB40 jumper cut, then powering through P21 and measuring with an ammeter across P22. USB is unplugged during measurement. I'm using zephyr with ncs v1.2.0.

I have built the samples/boards/nrf/system_off example and I was able to get about 400uA of current draw. By modifying the example to include CONFIG_SERIAL=n I was then able to get roughly 3uA. I have since tried to modify that example to include bluetooth advertising, but I can't get the current draw below 1.3mA. Here is my code:

#include <zephyr.h>
#include <device.h>
#include <power/power.h>
#include <bluetooth/bluetooth.h>
#include <hal/nrf_gpio.h>

/* 1000 msec = 1 sec */
#define SLEEP_TIME	1000


/* 1000 msec = 1 sec */
#define SLEEP_TIME	1000

#define BT_LE_ADV_CONN_NAME_SLOW BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \
					    BT_LE_ADV_OPT_USE_NAME, \
					    BT_GAP_ADV_SLOW_INT_MIN, \
					    BT_GAP_ADV_SLOW_INT_MAX)

static u8_t mfg_data[] = { 0xff, 0xff, 0xAB };

static const struct bt_data ad[] = {
        BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3),
};

void main(void)
{
    u32_t cnt = 0;
    sys_pm_ctrl_disable_state(SYS_POWER_STATE_DEEP_SLEEP_1);

    int err = bt_enable(NULL);
    if (err) {
        printk("Bluetooth init failed (err %d)\n", err);
        return;
    }

    err = bt_le_adv_start(BT_LE_ADV_CONN_NAME_SLOW, ad, ARRAY_SIZE(ad),
                          NULL, 0);
    if (err) {
        printk("Advertising failed to start (err %d)\n", err);
        return;
    }

    while (1) {
        cnt++;

        k_sleep(SLEEP_TIME);
    }
}

and prj.conf

CONFIG_GPIO=y
CONFIG_OPENOCD_SUPPORT=n
CONFIG_ASSERT=y

CONFIG_BT=y
CONFIG_BT_BROADCASTER=y
CONFIG_BT_DEVICE_NAME="Zephyr Test"

CONFIG_SYS_POWER_MANAGEMENT=y
CONFIG_SYS_POWER_DEEP_SLEEP_STATES=y
CONFIG_SYS_PM_STATE_LOCK=y
CONFIG_SERIAL=n

The advertising itself appears to work fine. Is this low power advertising supported? If so, could you please tell me what I am missing here? 

Parents
  • Hi,

     

    Thank you for providing sample code and configuration, compiled out-of-the-box.

    I cannot see that you are missing any settings. 1.3 mA is high. Are you connecting with the debugger? That normally gives a bit higher current consumption on nRF52840 (around 1.6 mA). If I do not power cycle or reset the device after programming (ninja flash), I see approx. 1.37 mA. Could this be the issue?

    I took the samples/bluetooth/peripheral_dis, pasted your code into main.c, and added these to prj.conf:

    CONFIG_SYS_POWER_MANAGEMENT=y
    CONFIG_SYS_POWER_DEEP_SLEEP_STATES=y
    CONFIG_SYS_PM_STATE_LOCK=y
    CONFIG_SERIAL=n

     

    After power cycling (or issuing a "nrfjprog --reset"), this behaves as expected when testing with nRF52840-DK (SB40 cut), with the lowest power consumption is approx. 4 uA, and throttles higher once per second, per the advertising interval you set.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Thank you for providing sample code and configuration, compiled out-of-the-box.

    I cannot see that you are missing any settings. 1.3 mA is high. Are you connecting with the debugger? That normally gives a bit higher current consumption on nRF52840 (around 1.6 mA). If I do not power cycle or reset the device after programming (ninja flash), I see approx. 1.37 mA. Could this be the issue?

    I took the samples/bluetooth/peripheral_dis, pasted your code into main.c, and added these to prj.conf:

    CONFIG_SYS_POWER_MANAGEMENT=y
    CONFIG_SYS_POWER_DEEP_SLEEP_STATES=y
    CONFIG_SYS_PM_STATE_LOCK=y
    CONFIG_SERIAL=n

     

    After power cycling (or issuing a "nrfjprog --reset"), this behaves as expected when testing with nRF52840-DK (SB40 cut), with the lowest power consumption is approx. 4 uA, and throttles higher once per second, per the advertising interval you set.

     

    Kind regards,

    Håkon

Children
  • Hi Håkon,

    Thanks for your quick reply. I just tried `nrfjprog --reset` and it now works fine; I'm measuring about 6mA during TX and otherwise a few uA during sleep.

    I was using openocd to flash; it seems that when using openocd to flash the device, it is not reset correctly and perhaps the debugger stays enabled? I'm using the version that goes with Zephyr: https://github.com/zephyrproject-rtos/openocd and I'm using it over nrfjprog because the IDE I am using (CLion) supports debugging/flashing with openocd.

    The invocation is this: 

    /home/jeremy/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/openocd -c "tcl_port disabled" -s /home/jeremy/zephyr-sdk/sysroots/x86_64-pokysdk-linux/usr/share/openocd/scripts -c "gdb_port 3333" -c "telnet_port 4444" -f /home/jeremy/Desktop/low_power_test/nordic_nrf52_dk.cfg -c "program \"/home/jeremy/Desktop/low_power_test/cmake-build-debug/zephyr/zephyr.elf\"" -c reset -c shutdown

    Open On-Chip Debugger 0.10.0+dev-01340-ga0e8edc4e-dirty (2020-02-14-05:38)
    Licensed under GNU GPL v2
    For bug reports, read
    	http://openocd.org/doc/doxygen/bugs.html
    Info : Zephyr: looking for target: cortex_m
    Info : Zephyr: target known, params at 0x907220
    Info : J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 21 2020 17:30:48
    Info : Hardware version: 1.00
    Info : VTarget = 3.300 V
    Info : clock speed 1000 kHz
    Info : SWD DPIDR 0x2ba01477
    Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
    Info : Listening on port 3333 for gdb connections
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x0000140c msp: 0x20002408
    ** Programming Started **
    Info : nRF52840-xxAA(build code: C0) 1024kB Flash, 256kB RAM
    Warn : Flash protection of this nRF device is not supported
    Info : Padding image section 0 at 0x0000cef0 with 5 bytes
    Info : Padding image section 1 at 0x0000d3fd with 3 bytes (bank write end alignment)
    Warn : Adding extra erase range, 0x0000d400 .. 0x0000dfff
    ** Programming Finished **
    shutdown command invoked

Related