This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NCS v2.4.0: low power by example

Dear Support team,

I'm involved in the activity to migrate to NCS a project already developed & successfuly tested with using nRF52 SDK v17.1.0, over the custom board initially designed.

That custom board is based on nRF52832_xxAA, battery powered, equipped with an inertial sensor from STM (MEMS) over SPI0, and a 8Mbit flash memory over SPI1, plus some LEDs and one button. The original .dts file is contained in the folder "<ncs_path>\v2.4.0\zephyr\boards\arm\nrf52dk_nrf52832" successfully overlayed for what concerns the custom I/O mapping. Indeed, everything is working fine without MCUBOOT (I'll add it as a final step when everything will be fixed), until I decided to check the power absorbment from the battery that reported around 150 microAmps in "idle" mode (advertising active and the whole system waiting for events).

As I expect an absorbment from 10 to 20 microAmp, I decided to start from the beginning: the "empty" main as reported below:

int main(void)
{
   while(1)
      NRF_POWER->SYSTEMOFF = 1;

   return 0;
}

This "empty" main reports 30.0 microAmps (NCS) against the 0.30 microAmps reported by the same "empty" main in the APP built with SDK v17.1.0, anyone could tell me whats's possibly wrong ?


PS: "CONFIG_SERIAL=n" has been applied already as many posts seeemed to be resolutive, also in the overlay "&uart0" is stated as "disabled".

PS #2: already included and built some examples from zephyr/samples/bluetooth (only advertising just to remain basic) and I never saw an absorbment less than 100 microAmps, therefore I can't exclude the extension nRF Connect for VSCode, as it's common to all test made so far

  • Hi Hakon,

    Yes, there is an external SPI flash but I assume that when all related I/O pins are set to HI-Z it shouldn't be backdriven, anyway just to try I've uncommented the line below for &spi0 and &spi1:

       compatible = "nordic,nrf-spim";
    And magically the extra-current disappeared !!!! How do you explain this?
    thank you, Paolo
    // compatible = "nordic,nrf-spim";
    compatible = "nordic,nrf-spim";

    tag.dts

    /*
     * Copyright (c) 2017 Shawn Nock <[email protected]>
     * Copyright (c) 2017 Linaro Limited
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    /dts-v1/;
    #include <nordic/nrf52832_qfaa.dtsi>
    #include "nrf52dk_nrf52832-pinctrl.dtsi"
    
    / {
    	model = "Nordic nRF52 DK NRF52832";
    	compatible = "nordic,nrf52-dk-nrf52832";
    
    	chosen {
    		zephyr,console = &uart0;
    		zephyr,shell-uart = &uart0;
    		zephyr,uart-mcumgr = &uart0;
    		zephyr,bt-mon-uart = &uart0;
    		zephyr,bt-c2h-uart = &uart0;
    		zephyr,sram = &sram0;
    		zephyr,flash = &flash0;
    		zephyr,code-partition = &slot0_partition;
    	};
    
    	/* These aliases are provided for compatibility with samples */
    	aliases {
    		// led0 = &led0;
    		// led1 = &led1;
    		// led2 = &led2;
    		// led3 = &led3;
    		// pwm-led0 = &pwm_led0;
    		// sw0 = &button0;
    		// sw1 = &button1;
    		// sw2 = &button2;
    		// sw3 = &button3;
    		// bootloader-led0 = &led0;
    		// mcuboot-button0 = &button0;
    		// mcuboot-led0 = &led0;
    		watchdog0 = &wdt0;
    	};
    };
    
    &adc {
    	status = "okay";
    };
    
    &gpiote {
    	status = "okay";
    };
    
    &gpio0 {
    	status = "okay";
    };
    
    &uart0 {
    	status = "okay";
    	compatible = "nordic,nrf-uarte";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart0_default>;
    	pinctrl-1 = <&uart0_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    &pinctrl {
    	uart0_default: uart0_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 20)>,
    				<NRF_PSEL(UART_RX, 0, 19)>;
    		};
    	};
    
    	uart0_sleep: uart0_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 20)>,
    				<NRF_PSEL(UART_RX, 0, 19)>;
    			low-power-enable;
    		};
    	};
    
    	spi0_default: spi0_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 17)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 16)>,
    				<NRF_PSEL(SPIM_MISO, 0, 15)>;
    		};
    	};
    
    	spi0_sleep: spi0_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 17)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 16)>,
    				<NRF_PSEL(SPIM_MISO, 0, 15)>;
    			low-power-enable;
    		};
    	};
    
    	spi1_default: spi1_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 7)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 6)>,
    				<NRF_PSEL(SPIM_MISO, 0, 3)>;
    		};
    	};
    
    	spi1_sleep: spi1_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 7)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 6)>,
    				<NRF_PSEL(SPIM_MISO, 0, 3)>;
    			low-power-enable;
    		};
    	};
    };
    
    &spi0 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi0_default>;
    	pinctrl-1 = <&spi0_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
    	spi0_cs: spi0_cs@0 {
    		reg = <0>;
    	};
    };
    	
    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi1_default>;
    	pinctrl-1 = <&spi1_sleep>;
    	pinctrl-names = "default", "sleep";
     	cs-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
     	spi1_cs: spi1_cs@0 {
     		reg = <0>;
     	};
    };
    
    &flash0 {
    
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		boot_partition: partition@0 {
    			label = "mcuboot";
    			reg = <0x00000000 0xc000>;
    		};
    		slot0_partition: partition@c000 {
    			label = "image-0";
    			reg = <0x0000C000 0x37000>;
    		};
    		slot1_partition: partition@43000 {
    			label = "image-1";
    			reg = <0x00043000 0x37000>;
    		};
    		storage_partition: partition@7a000 {
    			label = "storage";
    			reg = <0x0007a000 0x00006000>;
    		};
    	};
    };
    

  • Hi All,

    Trying to make some steps ahead I began to evolve blinky project by initializing some structures aiming to exchange some basic data but unfortunately I got the following error from linker:

    d:/programmi/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `spi_init':
    D:\Project\blinky\src\main.c:74: undefined reference to `__device_dts_ord_78'
    collect2.exe: error: ld returned 1 exit status

    That error arises only when: compatible = "nordic,nrf-spim"; if I replace with: compatible = "nordic,nrf-spi" the error disappears and the build completes successfully.

    Anyone can tell me what's missing ?

    thank you in advance, Paolo

    main.c

    /*
     * Copyright (c) 2016 Intel Corporation
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/spi.h>
    
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS   1000
    
    /* The devicetree node identifier for the "led0" alias. */
    #define LED0_NODE DT_NODELABEL(led_red)
    
    /*
     * A build error on this line means your board is unsupported.
     * See the sample documentation for information on how to fix this.
     */
    static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
    
    
    
    // MEMS
    #define MEMS_SPI_NODE			DT_NODELABEL(spi0)
    static const struct device 	*mems_spi_dev = DEVICE_DT_GET(MEMS_SPI_NODE);
    
    #define MEMS_SPI_CS_NODE		DT_NODELABEL(spi0_cs)
    static const struct spi_cs_control mems_spi_cs_ctrl = {
    	.gpio = SPI_CS_GPIOS_DT_SPEC_GET(MEMS_SPI_CS_NODE),
    	.delay = 2
    };
    
    static const struct spi_config mems_spi_cfg = {
    	.frequency = 8000000,	// 8MHZ
    	.operation = SPI_WORD_SET(8),
    	.cs = &mems_spi_cs_ctrl
    };
    
    #define	SPI_BUF_SIZE	256
    static uint8_t tx_buf[SPI_BUF_SIZE];
    static uint8_t rx_buf[SPI_BUF_SIZE];
    
    static struct spi_buf tx_spi_bufs[] = {
    	{
    		.buf = tx_buf
    	}
    };
    
    static struct spi_buf rx_spi_bufs[] = {
    	{
    		.buf = rx_buf
    	}
    };
    
    static const struct spi_buf_set spi_tx_buf_set = {
    	.buffers = tx_spi_bufs,
    	.count = 1
    };
    
    static const struct spi_buf_set spi_rx_buf_set = {
    	.buffers = rx_spi_bufs,
    	.count = 1
    };
    
    
    int spi_init(void)
    {
    	if (!device_is_ready(mems_spi_dev))
    		return 1;
    
    	return 0;	// OK
    }
    
    
    int main(void)
    {
    	if (!gpio_is_ready_dt(&led))
    	{
    		return 0;
    	}
    
    	int ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
    	if (ret < 0)
    		return 0;
    
    	spi_init();
    
    	while (1) 
    	{
    		ret = gpio_pin_toggle_dt(&led);
    		if (ret < 0)
    			return 0;
    		
    		k_msleep(SLEEP_TIME_MS);
    	}
    	
    	return 0;
    }
    

    board.dts

    /*
     * Copyright (c) 2017 Shawn Nock <[email protected]>
     * Copyright (c) 2017 Linaro Limited
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    /dts-v1/;
    #include <nordic/nrf52832_qfaa.dtsi>
    #include "nrf52dk_nrf52832-pinctrl.dtsi"
    
    / {
    	model = "Nordic nRF52 DK NRF52832";
    	compatible = "nordic,nrf52-dk-nrf52832";
    
    	chosen {
    		zephyr,console = &uart0;
    		zephyr,shell-uart = &uart0;
    		zephyr,uart-mcumgr = &uart0;
    		zephyr,bt-mon-uart = &uart0;
    		zephyr,bt-c2h-uart = &uart0;
    		zephyr,sram = &sram0;
    		zephyr,flash = &flash0;
    		zephyr,code-partition = &slot0_partition;
    	};
    
    	/* These aliases are provided for compatibility with samples */
    	aliases {
    		// led0 = &led0;
    		// led1 = &led1;
    		// led2 = &led2;
    		// led3 = &led3;
    		// pwm-led0 = &pwm_led0;
    		// sw0 = &button0;
    		// sw1 = &button1;
    		// sw2 = &button2;
    		// sw3 = &button3;
    		// bootloader-led0 = &led0;
    		// mcuboot-button0 = &button0;
    		// mcuboot-led0 = &led0;
    		watchdog0 = &wdt0;
    	};
    };
    
    &adc {
    	status = "okay";
    };
    
    &gpiote {
    	status = "okay";
    };
    
    &gpio0 {
    	status = "okay";
    };
    
    &pinctrl {
    	uart0_default: uart0_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 20)>,
    				<NRF_PSEL(UART_RX, 0, 19)>;
    		};
    	};
    
    	uart0_sleep: uart0_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 20)>,
    				<NRF_PSEL(UART_RX, 0, 19)>;
    			low-power-enable;
    		};
    	};
    
    	spi0_default: spi0_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 17)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 16)>,
    				<NRF_PSEL(SPIM_MISO, 0, 15)>;
    		};
    	};
    
    	spi0_sleep: spi0_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 17)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 16)>,
    				<NRF_PSEL(SPIM_MISO, 0, 15)>;
    			low-power-enable;
    		};
    	};
    
    	spi1_default: spi1_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 7)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 6)>,
    				<NRF_PSEL(SPIM_MISO, 0, 3)>;
    		};
    	};
    
    	spi1_sleep: spi1_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 7)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 6)>,
    				<NRF_PSEL(SPIM_MISO, 0, 3)>;
    			low-power-enable;
    		};
    	};
    };
    
    &uart0 {
    	status = "okay";
    	compatible = "nordic,nrf-uarte";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart0_default>;
    	pinctrl-1 = <&uart0_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    &spi0 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi0_default>;
    	pinctrl-1 = <&spi0_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
    	spi0_cs: spi0_cs@0 {
    		reg = <0>;
    	};
    };
    	
    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi1_default>;
    	pinctrl-1 = <&spi1_sleep>;
    	pinctrl-names = "default", "sleep";
     	cs-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
     	spi1_cs: spi1_cs@0 {
     		reg = <0>;
     	};
    };
    
    &flash0 {
    
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		boot_partition: partition@0 {
    			label = "mcuboot";
    			reg = <0x00000000 0xc000>;
    		};
    		slot0_partition: partition@c000 {
    			label = "image-0";
    			reg = <0x0000C000 0x37000>;
    		};
    		slot1_partition: partition@43000 {
    			label = "image-1";
    			reg = <0x00043000 0x37000>;
    		};
    		storage_partition: partition@7a000 {
    			label = "storage";
    			reg = <0x0007a000 0x00006000>;
    		};
    	};
    };
    

    board.overlay

    / {
    	outputs {
    		compatible = "gpio-leds";
    		led_red: led_red {
    			gpios = <&gpio0 24 GPIO_ACTIVE_LOW>;
    		};
    	};
    };
    

    prj.conf

    CONFIG_GPIO=y
    CONFIG_SPI=y
    

  • Hi,

     

    Try deleting your build-folder for each time that you change the "compatible" line in the overlay file. 

    pzuck said:
    I assume that when all related I/O pins are set to HI-Z it shouldn't be backdriven, anyway just to try I've uncommented the line below for &spi0 and &spi1:

    You have to set the CSN inactive to avoid added consumption from any external IC. If it floats, it can draw excessive current.

     

    Kind regards,

    Håkon

  • Hi,

    The error persists even if I delete "build" folder. Any other hints ?

    As I'm a newbie in Zephyr it would be more effective to figure out the difference between spi & spim in the compatible item...

    regard, Paolo

  • Hi Hakon,

    Pls confirm if you managed to build without errors, I'm stuck on this point since long time...

    thank you, Paolo

Related