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

Zephyr nRF52840 device crashes when turning off UART with device_set_power_state(uart, DEVICE_PM_OFF_STATE, NULL, NULL)

Hello,

we need to disable UART0 to achieve low power operation of our device. This is done by running:

uart_irq_rx_disable(uart);
device_set_power_state(uart, DEVICE_PM_OFF_STATE, NULL, NULL);

This works correctly on a minimal example when building using default devicetree for nrf52840dk.

But it crashes when we use our custom device tree.

*** Booting Zephyr OS build v2.3.0-rc1-ncs1  ***
*** Booting Zephyr OS build v2.3.0-rc1-ncs1  ***
*** Booting Zephyr OS build v2.3.0-rc1-ncs1  ***

The line that triggers the crash is device_set_power_state(uart, DEVICE_PM_OFF_STATE, NULL, NULL);

This is our prj.conf:

#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_NEWLIB_LIBC=y

CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_0_NRF_FLOW_CONTROL=y
CONFIG_SERIAL=y
CONFIG_GPIO=y
CONFIG_REBOOT=y

# Make sure printk is not printing to the UART console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_HEAP_MEM_POOL_SIZE=2048

# turn on BLE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="LP"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1
CONFIG_BT_GATT_NUS_UART_BUFFER_SIZE=30
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y

# Enable the NUS service
CONFIG_BT_GATT_NUS=y

# NVS Flash read/write
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_NVS=y

# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# DFU add
# Enable mcumgr.
CONFIG_MCUMGR=y

# Ensure an MCUboot-compatible binary is generated.
CONFIG_BOOTLOADER_MCUBOOT=y

# Required by the `taskstat` command.
CONFIG_THREAD_MONITOR=y

# Enable statistics and statistic names.
CONFIG_STATS=y
CONFIG_STATS_NAMES=y

# Enable most core commands.
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
CONFIG_MCUMGR_CMD_STAT_MGMT=y

CONFIG_LOG=n
#CONFIG_LOG_DEFAULT_LEVEL=4

# BT DFU
# Allow for large Bluetooth data packets.
CONFIG_BT_L2CAP_TX_MTU=260
CONFIG_BT_RX_BUF_LEN=260

# Enable the Bluetooth (unauthenticated) and shell mcumgr transports.
CONFIG_MCUMGR_SMP_BT=y
CONFIG_MCUMGR_SMP_BT_AUTHEN=n
CONFIG_MCUMGR_SMP_SHELL=y

# Enable the LittleFS file system.
CONFIG_FILE_SYSTEM=n
CONFIG_FILE_SYSTEM_LITTLEFS=n

# Enable file system commands
CONFIG_MCUMGR_CMD_FS_MGMT=n

# # Low power
CONFIG_SYS_POWER_MANAGEMENT=y
# # Required to disable default behavior of deep sleep on timeout
CONFIG_SYS_PM_STATE_LOCK=y
CONFIG_DEVICE_POWER_MANAGEMENT=y

# Sensors
CONFIG_SENSOR=y
CONFIG_I2C=y
CONFIG_LIS2DW12=y
CONFIG_LIS2DW12_POWER_MODE=3
CONFIG_LIS2DW12_ACCEL_RANGE_8G=y
CONFIG_LIS2DW12_INT_PIN_1=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_NRFX_TEMP=y
CONFIG_TEMP_NRF5=y

# network
CONFIG_CPLUSPLUS=y
CONFIG_SPI=y

#battery measurement
CONFIG_ADC=y

and this is our devicetree:

/*
 * Copyright (c) 2017 Linaro Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>

/ {
	model = "Irnas NRF52840";
	compatible = "nordic,irnas-nrf52840";

	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;
	};

	vbatt {
		compatible = "voltage-divider";
		io-channels = <&adc 2>;
		output-ohms = <0>;
		full-ohms = <0>;
	};

	leds {
		compatible = "gpio-leds";
		led0: led_0 {
			gpios = <&gpio0 27 GPIO_ACTIVE_LOW>;
			label = "Red LED 0";
		};
	};

	/* These aliases are provided for compatibility with samples */
	aliases {
		led0 = &led0;
	};
};

&adc {
	status = "okay";
};

&gpiote {
	status = "okay";
};

&gpio0 {
	status = "okay";
};

&gpio1 {
	status = "okay";
};

&uart0 {
	status = "okay";
	compatible = "nordic,nrf-uarte";
	current-speed = <115200>;
	tx-pin = <15>;
	rx-pin = <14>;
	rts-pin = <0xFFFFFFFF>;
	cts-pin = <0xFFFFFFFF>;
};

arduino_serial: &uart1 {
	status = "disabled";
};

arduino_i2c: &i2c0 {
	compatible = "nordic,nrf-twi";
    status = "okay";
	sda-pin = <6>;
	scl-pin = <7>;
    lis2dw12-accel@19 {
        compatible = "st,lis2dw12";
        label = "LIS2DW12-ACCEL";
        reg = <0x19>;

    };
};

&i2c1 {
	status = "disabled";
};

&pwm0 {
	status = "okay";
	ch0-pin = <44>;
	ch0-inverted;
};

&spi0 {
	/* Cannot be used together with i2c0. */
    status = "disabled";
};

&spi1 {
    status = "disabled";
};

&spi2 {
	compatible = "nordic,nrf-spi";
    status = "okay";
	sck-pin= <19>;
	mosi-pin = <20>;
	miso-pin= <21>;
};

&spi3 {
    status = "disabled";
};

&qspi {
	status = "okay";
	sck-pin = <19>;
	io-pins = <20>, <21>, <22>, <23>;
	csn-pins = <17>;
	mx25r64: mx25r6435f@0 {
		compatible = "nordic,qspi-nor";
		reg = <0>;
		writeoc = "pp4io";
		readoc = "read4io";
		sck-frequency = <8000000>;
		label = "MX25R64";
		jedec-id = [c2 28 17];
		size = <67108864>;
		has-be32k;
		has-dpd;
		t-enter-dpd = <10000>;
		t-exit-dpd = <35000>;
	};
};

&flash0 {
	/*
	 * For more information, see:
	 * http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
	 */
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x000000000 0x0000C000>;
		};
		slot0_partition: partition@c000 {
			label = "image-0";
			reg = <0x0000C000 0x00067000>;
		};
		slot1_partition: partition@73000 {
			label = "image-1";
			reg = <0x00073000 0x00067000>;
		};
		scratch_partition: partition@da000 {
			label = "image-scratch";
			reg = <0x000da000 0x0001e000>;
		};

		/*
		 * The flash starting at 0x000f8000 and ending at
		 * 0x000fffff is reserved for use by the application.
		 */

		/*
		 * Storage partition will be used by FCB/LittleFS/NVS
		 * if enabled.
		 */
		storage_partition: partition@f8000 {
			label = "storage";
			reg = <0x000f8000 0x00008000>;
		};
	};
};

&usbd {
	compatible = "nordic,nrf-usbd";
	status = "okay";
};

In addition we have tried the following:

CONFIG_SERIAL=n
but west complained that it cannot be disabled:
warning: SERIAL (defined at drivers/serial/Kconfig:6) was assigned the value 'n' but got the value
'y'. See http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_SERIAL.html and/or look up
SERIAL in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.
and
CONFIG_PRINTK=n, but west also complained that it cannot be disabled:

warning: PRINTK (defined at subsys/debug/Kconfig:108) was assigned the value 'n' but got the value
'y'. See http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_PRINTK.html and/or look up
PRINTK in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.

So we searched on google and devzone and found that Boot banner could be the problem, so we tried to disable it with CONFIG_BOOT_BANNER=n

but then the build failed with this message:

295/306] Linking CXX executable zephyr/zephyr_prebuilt.elf
FAILED: zephyr/zephyr_prebuilt.elf 
: && ccache /opt/gnuarmemb/bin/arm-none-eabi-g++     zephyr/CMakeFiles/zephyr_prebuilt.dir/misc/empty_file.c.obj  -o zephyr/zephyr_prebuilt.elf  -Wl,-T  zephyr/linker.cmd  -Wl,-Map=/home/vid/repos/irnas-fw/build/zephyr/zephyr_prebuilt.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/mpu/libarch__arm__core__aarch32__cortex_m__mpu.a  zephyr/lib/libc/newlib/liblib__libc__newlib.a  zephyr/lib/posix/liblib__posix.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/subsys/bluetooth/common/libsubsys__bluetooth__common.a  zephyr/subsys/bluetooth/host/libsubsys__bluetooth__host.a  zephyr/subsys/bluetooth/controller/libsubsys__bluetooth__controller.a  zephyr/subsys/mgmt/libsubsys__mgmt.a  zephyr/subsys/net/libsubsys__net.a  zephyr/subsys/random/libsubsys__random.a  zephyr/drivers/adc/libdrivers__adc.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/i2c/libdrivers__i2c.a  zephyr/drivers/sensor/lis2dw12/libdrivers__sensor__lis2dw12.a  zephyr/drivers/sensor/nrf5/libdrivers__sensor__nrf5.a  zephyr/drivers/spi/libdrivers__spi.a  zephyr/drivers/flash/libdrivers__flash.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/entropy/libdrivers__entropy.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a  modules/mcumgr/lib..__modules__lib__mcumgr.a  modules/nordic/lib..__modules__hal__nordic.a  modules/tinycbor/lib..__modules__lib__tinycbor__zephyr.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.obj  -L"/opt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/8.3.1/thumb/v7e-m/nofp"  -L/home/vid/repos/smartparks-opencollar-edge-fw/build/zephyr  -lgcc  -Wl,--print-memory-usage  /home/vid/ncs/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/soft-float/no-interrupts/libnrf_cc310_platform_0.9.2.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -no-pie  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -lm  -lc  -lgcc  -L"/opt/gnuarmemb/arm-none-eabi"/lib/thumb/v7e-m/nofp  -specs=nano.specs && :
Memory region         Used Size  Region Size  %age Used
           FLASH:      176144 B     486912 B     36.18%
            SRAM:       40208 B       256 KB     15.34%
        IDT_LIST:         200 B         2 KB      9.77/opt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld: zephyr/subsys/mgmt/libsubsys__mgmt.a(smp_shell.c.obj): in function `k_str_out':
/home/vid/repos/irnas-fw/build/zephyr/include/generated/syscalls/kernel.h:1068: undefined reference to `z_impl_k_str_out'
collect2: error: ld returned 1 exit status
%
ninja: build stopped: subcommand failed.

We are using NCS 1.3.0 and get the same results when building on Ubuntu 20 and Windows 10.

What should be done to correctly disable UART?

Regards,

Vid

Related