crashing after adding a driver to dts

hello Nordic

i work with ncs 1.7.1, with nrf52832 soc

i tried to add a driver and for some reason i fail and i can not understand why

this is my dts

// Copyright (c) 2022 Nordic Semiconductor ASA
// SPDX-License-Identifier: Apache-2.0

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

/ {
	model = "halo_ep2";
	compatible = "halo-ep2";

	chosen {
		zephyr,sram = &sram0;
		zephyr,flash = &flash0;
		zephyr,code-partition = &slot0_partition;
		nordic,pm-ext-flash = &augu_flash_is25lp128;
	};

	sensors_on: sensors_on_node {
		compatible = "augury,gpio-power";
		power_gpios = <&gpio0 22 GPIO_ACTIVE_LOW>;
		label = "SENSORS_ON";
		status = "okay";
		#power_resource-cells = <0>;
	};

	sensor_5v_en: sensor_5v_en_node {
		compatible = "augury,gpio-power";
		power_gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
		label = "SENSOR_5V_EN";
		status = "okay";
		#power_resource-cells = <0>;
	};

	flash_on: flash_on_node {
		compatible = "augury,gpio-power";
		power_gpios = <&gpio0 23 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
		label = "FLASH_ON";
		status = "okay";
		#power_resource-cells = <0>;
	};	

    leds {
        compatible = "gpio-leds";
        led0_red: led_0 {
            gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>;
            label = "RED_LED_0";
        };
        led1_orange: led_1 {
            gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>;
            label = "ORANGE_LED_1";
        };
        led2_green: led_2 {
            gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>;
            label = "GREEN_LED_2";
        };							
    };

	aliases {
		led0-red = &led0_red;
		led1-orange = &led1_orange;
		led2-green = &led2_green;

	};
};

	&adc {
		status ="okay";
	};

	&gpiote {
		status ="okay";
	};

	&gpio0 {
		status ="okay";
	};


	&spi0 {
		status = "okay";
		sck-pin = <8>;	// gpio 0 pin 8
		mosi-pin = <GPIO_PULL_DOWN>;
		miso-pin = <7>;	// gpio 0 pin 7
		compatible = "nordic,nrf-spim";
		ads8866_chain@0 {
			compatible = "ti,ads8866_chain";
			reg = <0>;
			conv_gpios = <&gpio0 6 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
			label = "ADS8866_CHAIN";
			power_resources = <&sensor_5v_en>;
			spi-max-frequency = <8000000>;
		};
	};
	&spi1 {
		compatible = "nordic,nrf-spim";
		status = "okay";
		sck-pin = <20>;
		mosi-pin = <14>;    // p0.14
		miso-pin = <16>;    // p0.16
		cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
		iis3dwb@0 {
			compatible = "st,iis3dwb";
			reg = <0>;
			int1_gpios = <&gpio0 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
			int2_gpios = <&gpio0 12 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
			label = "IIS3DWB";
			power_resources = <&sensors_on>;
			spi-max-frequency = <8000000>;
		};
	};

	&spi2 {
		status = "okay";
		sck-pin = <5>; // gpio 0 pin 5
		mosi-pin = <4>; // gpio 0 pin 4
		miso-pin = <2>; // gpio 0 pin 2
		compatible = "nordic,nrf-spim";
		cs-gpios = <&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
		augu_flash_is25lp128: augu_flash_is25lp128@0 {
			compatible = "issi,augu_flash_is25lp128";
			reg = <0>;
			label = "AUGU_FLASH_IS25LP128";
			power_resources = <&flash_on>;
			jedec_id = [9d 60 18];
			spi-max-frequency = <8000000>; //<133000000>;
			page_size = <256>;
			block_size = <65536>;
			size = <0x8000000>;
		};
	};
	&flash0 {
		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			mbr_partition: partition@0 {
				label = "mbr";
				reg = <0x00000000 0x00001000>;
			};
			boot_partition: partition@1000 {
				label = "mcuboot";
				reg = <0x1000 0xc000>;
			};
			slot0_partition: partition@d000 {
				label = "image-0";
				reg = <0xd000 0x6c800>;
			};
			slot1_partition: partition@79800 {
				label = "image-1";
				reg = <0x79800 0x800>;
			};
			storage_partition: partition@7a000 {
				label = "storage";
				reg = <0x7a000 0x6000>;
			};
		};
	};

this is the fault

[00000025] <err> os: r0/a1:  0x00000004  r1/a2:  0x00000214  r2/a3:  0x00000000
[00000026] <err> os: r3/a4:  0x00000001 r12/ip:  0xa0000000 r14/lr:  0x0002d0e1
[00000026] <err> os:  xpsr:  0x61000000
[00000026] [1;31m<err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
[00000027] <err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000
[00000027] <err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
[00000028] <err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
[00000028] <err> os: fpscr:  0x00000000
[00000028] <err> os: Faulting instruction address (r15/pc): 0x0003b51c
[00000028] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00000029] <err> os: Current thread: 0x20004370 (unknown)
[00012168] <err> fatal_error: Resetting system
ASSERTION FAIL [nrf_gpio_pin_present_check(*p_pin)] @ WEST_TOPDIR/modules/hal/nordic/nrfx/hal/nrf_gpio.h:532

at the moment the driver .c is empty, this is the driver.yaml

description: |
    Texas Instruments ADS8866 daisy chain 

compatible: "ti,ads8866_chain"

include: spi-device.yaml

properties:
    conv_gpios:
      type: phandle-array
      required: true
    str_gpios:
      type: phandle-array
      required: false
    stbr_gpios:
      type: phandle-array
      required: false
    power_resources:
      type: phandle-array
      required: true

any ideas what is the issue ?

hope to read from you soon

Ziv

  • ok the fix for the above issue is to set the unconnected MOSI to the value of NRFX_SPIM_PIN_NOT_USED , which is 0xFF

    so it passes the driver init, however, 

    when i try to init the spi  'nrfx_spim_init(..)'return -EBUSY and if i try to uninit first with 'nrfx_spim_uninit(..)' then i get the following crash:

    [00003039] <err> os: ***** BUS FAULT *****
    [00003040] <err> os:   Imprecise data bus error
    [00003040] <err> os: r0/a1:  0x00020000  r1/a2:  0x0000000a  r2/a3:  0xe000e100
    [00003041] <err> os: r3/a4:  0x0000005b r12/ip:  0x50000000 r14/lr:  0x0002db0f
    [00003041] <err> os:  xpsr:  0x01000000
    [00003041] <err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
    [00003042] <err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000
    [00003042] <err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
    [00003043] <err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
    [00003043] <err> os: fpscr:  0x00000600
    [00003043] <err> os: Faulting instruction address (r15/pc): 0x0002db18
    [00003043] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
    [00003044] <err> os: Current thread: 0x20004bf0 (unknown)
    [00023698] <err> fatal_error: Resetting system
    *** Booting Zephyr OS build v2.6.99-ncs1-1  ***

    any ideas ?

    hope to read from you soon

    best regards

    Ziv

  • Hello,

    I am not entirely sure which driver you are trying to add to your project (existing or new one), maybe you can share your project and explain what driver you are trying to add that you have problem with?

    In general you can find that there are multiple tests and samples using drivers in zephyr, these show how you can implement a particular peripheral to your project:
    https://github.com/nrfconnect/sdk-zephyr/tree/main/tests/drivers 
    https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/drivers 

    Have in mind that if you are calling device_get_binding() in your project then it's already initializing the spi driver (if used) and you need to use the spi zephyr api or sensor api, so that may be the reason why calling nrfx_spim_init() return EBUSY.

    If you want to use the nrfx_spi driver api directly, then you need to look at the below sample that show how to use nrfx_gpiote directly (similar approach can be done for nrfx_spi), have in mind that in this case you also need to add handling of the interrupt by using IRQ_CONNECT():
    https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/boards/nrf/nrfx 

    Kenneth

  • ok the problem for the seconde issue is that in the driver init function i forgot to bind the bus

    spi_dev = device_get_binding(..bus_name)
    that, with the unused mosi set to 0xFF in dts,  solved the issu
    best regards
    Ziv
Related