DTS for sensor example using NRF_PSEL fails to build

Hi,

I'm trying to get up and running using the PMW3360 sensor driver (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/drivers/pmw3360.html) using the NRF52840 DK.

I'm using the sample DTS provided on that page:

&pinctrl {
    spi1_default_alt: spi1_default_alt {
        group1 {
            psels = <NRF_PSEL(SPI_SCK, 0, 16)>,
                    <NRF_PSEL(SPI_MISO, 0, 15)>,
                    <NRF_PSEL(SPI_MOSI, 0, 17)>;
        };
    };

    spi1_sleep_alt: spi1_sleep_alt {
        group1 {
            psels = <NRF_PSEL(SPI_SCK, 0, 16)>,
                    <NRF_PSEL(SPI_MISO, 0, 15)>,
                    <NRF_PSEL(SPI_MOSI, 0, 17)>;
            low-power-enable;
      };
    };
};

&spi1 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    pinctrl-0 = <&spi1_default_alt>;
    pinctrl-1 = <&spi1_sleep_alt>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio0 13 0>;

    pmw3360@0 {
            compatible = "pixart,pmw3360";
            reg = <0>;
            irq-gpios = <&gpio0 21 0>;
            spi-max-frequency = <2000000>;
            label = "PMW3360";
    };
};

To my eye (I've spent quite a few hours over the course of a few days reviewing/learning about DTS) I don't see anything obviously wrong. However, building the project fails:

-- Application: /Users/max/Documents/my_project/mouse/ptx
-- Cache files will be written to: /Users/max/Library/Caches/zephyr
-- Zephyr version: 3.0.99 (/Users/max/Documents/nrfconnect/zephyr)
-- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
-- Board: nrf52840dk_nrf52840
-- Found dtc: /opt/nordic/ncs/v1.9.1/toolchain/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (/opt/nordic/ncs/v1.9.1/toolchain)
-- Found BOARD.dts: /Users/max/Documents/nrfconnect/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
-- Found devicetree overlay: /Users/max/Documents/my_project/mouse/ptx/boards/nrf52840dk_nrf52840.overlay
devicetree error: /Users/max/Documents/my_project/mouse/ptx/boards/nrf52840dk_nrf52840.overlay:4 (column 66): parse error: expected number or parenthesized expression
CMake Error at /Users/max/Documents/nrfconnect/zephyr/cmake/modules/dts.cmake:213 (message):
  gen_defines.py failed with return code: 1
Call Stack (most recent call first):
  /Users/max/Documents/nrfconnect/zephyr/cmake/modules/zephyr_default.cmake:121 (include)
  /Users/max/Documents/nrfconnect/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:51 (include)
  /Users/max/Documents/nrfconnect/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:81 (include_boilerplate)
  /Users/max/Documents/my_project/mouse/ptx/build/CMakeLists.txt:8 (find_package)

Note that 1) the overlay is discovered and 2) there is no column 66 on line 4 in my overlay. I went to the `zephyr.dts.pre` to see if I could spot the issue, where my overlay was present at the bottom:

# 1 "<command-line>" 2
# 1 "/Users/max/Documents/my_project/mouse/ptx/boards/nrf52840dk_nrf52840.overlay" 1
&pinctrl {
    spi1_default_alt: spi1_default_alt {
        group1 {
            psels = <((((((0) * 32U) + (16)) & 0x3FU) << 0U) | ((NRF_FUN_SPI_SCK & 0xFFFFU) << 16U))>,
                    <((((((0) * 32U) + (15)) & 0x3FU) << 0U) | ((NRF_FUN_SPI_MISO & 0xFFFFU) << 16U))>,
                    <((((((0) * 32U) + (17)) & 0x3FU) << 0U) | ((NRF_FUN_SPI_MOSI & 0xFFFFU) << 16U))>;
        };
    };

    spi1_sleep_alt: spi1_sleep_alt {
        group1 {
            psels = <((((((0) * 32U) + (16)) & 0x3FU) << 0U) | ((NRF_FUN_SPI_SCK & 0xFFFFU) << 16U))>,
                    <((((((0) * 32U) + (15)) & 0x3FU) << 0U) | ((NRF_FUN_SPI_MISO & 0xFFFFU) << 16U))>,
                    <((((((0) * 32U) + (17)) & 0x3FU) << 0U) | ((NRF_FUN_SPI_MOSI & 0xFFFFU) << 16U))>;
            low-power-enable;
      };
    };
};

&spi1 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    pinctrl-0 = <&spi1_default_alt>;
    pinctrl-1 = <&spi1_sleep_alt>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio0 13 0>;

    pmw3360@0 {
            compatible = "pixart,pmw3360";
            reg = <0>;
            irq-gpios = <&gpio0 21 0>;
            spi-max-frequency = <2000000>;
            label = "PMW3360";
    };
};

Line 4 col 66 is where `NRF_FUN_SPI_SCK` is referenced, at the first character. I'm assuming that -- based on the parse error -- the macro for `NRF_FUN_SPI_SCK` isn't able to be resolved.

A few questions:

- I can't find any documentation for `NRF_FUN_*` definitions via search and I'm not sure where I should be looking.

- Is there something obviously wrong with my DTS overlay?

- Are there any examples that set up a similar sensor which I should take a look at?

Thanks,

Max

  • Hello, 

    The initial issue that I can see is the difference in nRF Connect SDK versions. 

    -- Zephyr version: 3.0.99 (/Users/max/Documents/nrfconnect/zephyr)
    -- Found dtc: /opt/nordic/ncs/v1.9.1/toolchain/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6")
    -- Found toolchain: gnuarmemb (/opt/nordic/ncs/v1.9.1/toolchain)

    Zephyr v3.0.99 is used in the latest version of nRF Connect SDK (v2.0.0), while it's using toolchain from v1.9.1 which is Zephyr v2.7.99. 

    Are you using VS Code extension or building from command line?

    Kind regards,
    Øyvind

  • Hi Øyvind,

    I'm using the VS Code extension.

    I believe I actually solved my issue, but I'm wondering if 2.0.0 does this differently or if the docs need to be updated for the sensor example:

    Instead of `SPI_*` I needed to use `SPIM_*` in the `NRF_PSEL` statements inside the DTS. I found this out here: https://docs.zephyrproject.org/apidoc/latest/nrf-pinctrl_8h.html#a2594557c5e765d65ea7627c5c49e07d6

    I'm running into some additional issues with SPI (I can't seem to reliably instrument SPI using my DLA, in particular for the  MOSI pin the voltage seems to be low for some reason), but I think my other issue is resolved.

    Thanks,

    Max

  • Hmm, I still can't track this issue down re: low voltage on MOSI. On my scope, MOSI voltage is -400mv to 800mv (1.2v peak-to-peak, but the -400mv is a bit suspect to me) and doesn't trigger at all on my DLA with a threshold voltage of 1.5v.

    - I have no pullups/pulldowns on my PMW3360 board for MOSI

    - I've tried this pinctrl configuration, same issue:

    &pinctrl {
        spi1_default_alt: spi1_default_alt {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 16)>,
                        <NRF_PSEL(SPIM_MISO, 0, 15)>;
            };
    
            group2 {
                psels = <NRF_PSEL(SPIM_MOSI, 0, 19)>;
                bias-pull-up;
                drive-mode = <NRF_DRIVE_H0H1>;
            };
        };
    
        spi1_sleep_alt: spi1_sleep_alt {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 16)>,
                        <NRF_PSEL(SPIM_MISO, 0, 15)>;
                // low-power-enable;
            };
            group2 {
                psels = <NRF_PSEL(SPIM_MOSI, 0, 19)>;
                bias-pull-up;
                drive-mode = <NRF_DRIVE_H0H1>;
                // low-power-enable;
            };
        };
    };

    - I've tried multiple output pins on the NRF52840 DK for MOSI, each has the same problem

    - Checked for shorts to ground or other pins on MOSI, nothing came up

    I'm inclined to suspect either an issue with my PMW3360 breakout board (though it's pretty straightforward) or an SPI config issue on my end, but am wondering if there are any suggestions or hints.

  • Hi Max, 

    Due to summer vacation period we might need some time to find the answer to this. 


    maxg said:
    if the docs need to be updated for the sensor example:

    What exact sensor sample are you using? Will have the documentation team look into this. Note that there are changes introduces in v2.0.0 compared to v1.9.1. Please see migration note for v2.0.0

    I'm trying to get up and running using the PMW3360 sensor driver (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/drivers/pmw3360.html) using the NRF52840 DK.

    What version of the nRF52840DK are you using?

    maxg said:
    I believe I actually solved my issue, but I'm wondering if 2.0.0 does this differently or if the docs need to be updated for the sensor example:

    Have you read through the Pin Control in the nRF documentation?

    Kind regards,
    Øyvind

  • No problem regarding delays, hope your summer vacation goes well.

    When I say sensor example, I mean the DTS example outlined here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/drivers/pmw3360.html#id4

    It uses `SPI_*` (which doesn't resolve) instead of `SPIM_*` for the psels in pinctrl. Please let me know if I'm missing something here. I looked over the changelog briefly and I don't believe this has changed from 1.9.x to 2.x but I could be wrong. I'll update to 2.x.

    To be explicit, this (as shown on the docs page):

                psels = <NRF_PSEL(SPI_SCK, 0, 16)>,
                        <NRF_PSEL(SPI_MISO, 0, 15)>,
                        <NRF_PSEL(SPI_MOSI, 0, 17)>;

    I believe should instead be:

                psels = <NRF_PSEL(SPIM_SCK, 0, 16)>,
                        <NRF_PSEL(SPIM_MISO, 0, 15)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 17)>;

    This is what the sticker says on my DK:

    PCA10056
    
    2.0.1
    
    2020.46
    
    683351964

    I've had a chance to reference the pinctrl documentation.

    I switched my MOSI to P0.27 and all started to work correctly with the sensor. I have a feeling that the  GPIO pins I was trying for MOSI are hooked up to other peripherals on the DK and some interaction there was resulting in the voltage difference on just MOSI, but I'm not 100% sure.

    If there's any additional insight on this topic that might come to mind for you, please let me know. I'm left wondering if I was doing something fundamentally incorrect with the DK hardware or my configuration (e.g. DTS or code). 

Related