Connect CAN devices to Thingy91

I am trying to connect two CAN devices mcp2515 to the SPI3 on the gpio spare of the tingy91 but I have a problem compiling the overlay file. Is there someone who can help me?

I am attaching the configuration and the overlay that gives me problems at the end of the compilation.

CONFIGURATION:

# configuration
CONFIG_CAN=y
CONFIG_SPI=y
CONFIG_GPIO=y

OVERLAY:

&spi3 {
    status = "okay";
    cs-gpios = <&gpio0 3 1>,<&gpio0 11 1>;
    sck-pin = <6>;
    mosi-pin = <26>;
    miso-pin = <5>;
    can1: mcp2515@0 {
        compatible = "microchip,mcp2515";
        spi-max-frequency = <1000000>;
        int-gpios = <&gpio1 27 1>;
        status = "okay";
        label = "MCP2515A";
        reg = <0x0>;
        osc-freq = <20000000>;
        bus-speed = <250000>;
        sjw = <1>;
        prop-seg = <2>;
        phase-seg1 = <7>;
        phase-seg2 = <6>;
        #address-cells = <1>;
        #size-cells = <0>;
    };
    can2: mcp2515@1 {
        compatible = "microchip,mcp2515";
        spi-max-frequency = <1000000>;
        int-gpios = <&gpio1 28 1>;
        status = "okay";
        label = "MCP2515B";
        reg = <0x1>;
        osc-freq = <20000000>;
        bus-speed = <250000>;
        sjw = <1>;
        prop-seg = <2>;
        phase-seg1 = <7>;
        phase-seg2 = <6>;
        #address-cells = <1>;
        #size-cells = <0>;
    };
};
/ {
 aliases {
    can-primary = &can1;
    can-secondary = &can2;
    };
};

COMPILATOR ERROR:

...
...
...

[297/302] Generating linker.cmd
[298/302] Generating isr_tables.c, isrList.bin
[299/302] Building C object zephyr/CMakeFiles/zephyr_final.dir/misc/empty_file.c.obj
[300/302] Building C object zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj
[301/302] Building C object zephyr/CMakeFiles/zephyr_final.dir/dev_handles.c.obj
[302/302] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       58144 B        72 KB     78.86%
            SRAM:       37600 B       256 KB     14.34%
        IDT_LIST:          0 GB         2 KB      0.00%
[163/187] Building C object zephyr/drivers/spi/CMakeFiles/drivers__spi.dir/spi_nrfx_spim.c.obj
FAILED: zephyr/drivers/spi/CMakeFiles/drivers__spi.dir/spi_nrfx_spim.c.obj 
ccache /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DNRF52840_XXAA -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -I/opt/nordic/ncs/v2.0.0/zephyr/include/zephyr -I/opt/nordic/ncs/v2.0.0/zephyr/include -Izephyr/include/generated -I/opt/nordic/ncs/v2.0.0/zephyr/soc/arm/nordic_nrf/nrf52 -I/opt/nordic/ncs/v2.0.0/zephyr/soc/arm/nordic_nrf/common/. -I/opt/nordic/ncs/v2.0.0/nrf/include -I/opt/nordic/ncs/v2.0.0/modules/hal/cmsis/CMSIS/Core/Include -I/opt/nordic/ncs/v2.0.0/modules/hal/nordic/nrfx -I/opt/nordic/ncs/v2.0.0/modules/hal/nordic/nrfx/drivers/include -I/opt/nordic/ncs/v2.0.0/modules/hal/nordic/nrfx/mdk -I/opt/nordic/ncs/v2.0.0/zephyr/modules/hal_nordic/nrfx/. -isystem /opt/nordic/ncs/v2.0.0/zephyr/lib/libc/minimal/include -isystem /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include -isystem /opt/nordic/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed -isystem /opt/nordic/ncs/v2.0.0/nrfxlib/crypto/nrf_cc310_platform/include -Os -imacros /opt/nordic/Samples/52840DK/52840DK/SPIOverlayTH/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -imacros /opt/nordic/ncs/v2.0.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/opt/nordic/Samples/52840DK/52840DK/SPIOverlayTH=CMAKE_SOURCE_DIR -fmacro-prefix-map=/opt/nordic/ncs/v2.0.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/opt/nordic/ncs/v2.0.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT zephyr/drivers/spi/CMakeFiles/drivers__spi.dir/spi_nrfx_spim.c.obj -MF zephyr/drivers/spi/CMakeFiles/drivers__spi.dir/spi_nrfx_spim.c.obj.d -o zephyr/drivers/spi/CMakeFiles/drivers__spi.dir/spi_nrfx_spim.c.obj -c /opt/nordic/ncs/v2.0.0/zephyr/drivers/spi/spi_nrfx_spim.c
In file included from /opt/nordic/ncs/v2.0.0/zephyr/include/zephyr/toolchain.h:50,
                 from /opt/nordic/ncs/v2.0.0/zephyr/include/zephyr/init.h:10,
                 from /opt/nordic/ncs/v2.0.0/zephyr/include/zephyr/device.h:29,
                 from /opt/nordic/ncs/v2.0.0/zephyr/include/zephyr/drivers/spi.h:24,
                 from /opt/nordic/ncs/v2.0.0/zephyr/drivers/spi/spi_nrfx_spim.c:7:
/opt/nordic/ncs/v2.0.0/zephyr/include/zephyr/toolchain/gcc.h:77:36: error: static assertion failed: "/soc/spi@4002f000 defined without required pin configuration"
   77 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
      |                                    ^~~~~~~~~~~~~~
/opt/nordic/ncs/v2.0.0/zephyr/soc/arm/nordic_nrf/common/soc_nrf_common.h:218:2: note: in expansion of macro 'BUILD_ASSERT'
  218 |  BUILD_ASSERT((IS_ENABLED(CONFIG_PINCTRL) &&   \
      |  ^~~~~~~~~~~~
/opt/nordic/ncs/v2.0.0/zephyr/drivers/spi/spi_nrfx_spim.c:518:2: note: in expansion of macro 'NRF_DT_CHECK_PIN_ASSIGNMENTS'
  518 |  NRF_DT_CHECK_PIN_ASSIGNMENTS(SPIM(idx), 1,          \
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/nordic/ncs/v2.0.0/zephyr/drivers/spi/spi_nrfx_spim.c:596:1: note: in expansion of macro 'SPI_NRFX_SPIM_DEVICE'
  596 | SPI_NRFX_SPIM_DEVICE(3);
      | ^~~~~~~~~~~~~~~~~~~~
/opt/nordic/ncs/v2.0.0/zephyr/include/zephyr/toolchain/gcc.h:77:36: error: static assertion failed: "/soc/spi@4002f000 has legacy *-pin properties defined although PINCTRL is enabled"
   77 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
      |                                    ^~~~~~~~~~~~~~
/opt/nordic/ncs/v2.0.0/zephyr/soc/arm/nordic_nrf/common/soc_nrf_common.h:229:2: note: in expansion of macro 'BUILD_ASSERT'
  229 |  BUILD_ASSERT(!IS_ENABLED(CONFIG_PINCTRL) ||   \
      |  ^~~~~~~~~~~~
/opt/nordic/ncs/v2.0.0/zephyr/drivers/spi/spi_nrfx_spim.c:518:2: note: in expansion of macro 'NRF_DT_CHECK_PIN_ASSIGNMENTS'
  518 |  NRF_DT_CHECK_PIN_ASSIGNMENTS(SPIM(idx), 1,          \
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/nordic/ncs/v2.0.0/zephyr/drivers/spi/spi_nrfx_spim.c:596:1: note: in expansion of macro 'SPI_NRFX_SPIM_DEVICE'
  596 | SPI_NRFX_SPIM_DEVICE(3);
      | ^~~~~~~~~~~~~~~~~~~~
[164/187] Linking C static library zephyr/kernel/libkernel.a
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/v2.0.0/bin/cmake --build /opt/nordic/Samples/52840DK/52840DK/SPIOverlayTH/build


*/

Thank you
Babos

Parents
  • Hi,

    Try adding this configuration option to your prj.conf

    CONFIG_CAN_MCP2515=y


    In addition, you could try adding a line right below &spi3 in your 52840dk_nrf52840.overlay file

    compatible = "nordic,nrf-spim";


    Best regards,
    Dejan

  • Hello Dejan,

    yes off course 'CONFIG_CAN_MCP2515=y' but is for thingy91_nrf52840 board.

    I solved it like this:

    &pinctrl {
        spi3_default: spi3_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
                        <NRF_PSEL(SPIM_MISO, 0, 5)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>;
            };
        };
    
        spi3_sleep: spi3_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
                        <NRF_PSEL(SPIM_MISO, 0, 5)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>;
                low-power-enable;
            };
        };
    
    };
    &spi3 {
        status = "okay";
        cs-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>,
                   <&gpio1 11 GPIO_ACTIVE_LOW>,
                   <&gpio0 30 GPIO_ACTIVE_LOW>,
                   <&gpio0 9 GPIO_ACTIVE_LOW>;
        pinctrl-0 = <&spi3_default>;
        pinctrl-1 = <&spi3_sleep>;
        pinctrl-names = "default", "sleep";
    
        can1_mcp2518: mcp2515@0 {
            compatible = "microchip,mcp2515";
            spi-max-frequency = <1000000>;
            int-gpios = <&gpio0 27 0>;
            status = "okay";
            label = "MCP2518A";
            reg = <0x0>;
            osc-freq = <20000000>;
            bus-speed = <250000>;
            sjw = <1>;
            prop-seg = <2>;
            phase-seg1 = <7>;
            phase-seg2 = <6>;
            #address-cells = <1>;
            #size-cells = <0>;
        };
        can2_mcp2518: mcp2515@1 {
            compatible = "microchip,mcp2515";
            spi-max-frequency = <1000000>;
            int-gpios = <&gpio0 28 0>;
            status = "okay";
            label = "MCP2518B";
            reg = <0x1>;
            osc-freq = <20000000>;
            bus-speed = <250000>;
            sjw = <1>;
            prop-seg = <2>;
            phase-seg1 = <7>;
            phase-seg2 = <6>;
            #address-cells = <1>;
            #size-cells = <0>;
        };
        ioexpander: mcp23sxx@2 {
            compatible = "microchip,mcp23sxx";
            label = "MCP23S08";
            #gpio-cells = <2>;
            ngpios = <8>;
            gpio-controller;
            reg = <0x2>;
            spi-max-frequency = <800000>;
        };
        adc104s021: spi-device@3 {
            compatible = "spi-device";
            reg = <0x3>;
            spi-max-frequency = <800000>;
            label = "ADC104S021";
        };
    };
    /{
        aliases{
            can-primary = &can1_mcp2518;
            can-secondary = &can2_mcp2518;
            io-expander = &ioexpander;
            adc104s021=&adc104s021;
        };
    };
    / {
        chosen {
                zephyr,console = &cdc_acm_uart0;
        };
    };
    
    &zephyr_udc0 {
        cdc_acm_uart0: cdc_acm_uart0 {
                compatible = "zephyr,cdc-acm-uart";
                label = "CDC_ACM_0";
        };
    };
    

    Best Regards,

    Babos

Reply
  • Hello Dejan,

    yes off course 'CONFIG_CAN_MCP2515=y' but is for thingy91_nrf52840 board.

    I solved it like this:

    &pinctrl {
        spi3_default: spi3_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
                        <NRF_PSEL(SPIM_MISO, 0, 5)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>;
            };
        };
    
        spi3_sleep: spi3_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
                        <NRF_PSEL(SPIM_MISO, 0, 5)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>;
                low-power-enable;
            };
        };
    
    };
    &spi3 {
        status = "okay";
        cs-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>,
                   <&gpio1 11 GPIO_ACTIVE_LOW>,
                   <&gpio0 30 GPIO_ACTIVE_LOW>,
                   <&gpio0 9 GPIO_ACTIVE_LOW>;
        pinctrl-0 = <&spi3_default>;
        pinctrl-1 = <&spi3_sleep>;
        pinctrl-names = "default", "sleep";
    
        can1_mcp2518: mcp2515@0 {
            compatible = "microchip,mcp2515";
            spi-max-frequency = <1000000>;
            int-gpios = <&gpio0 27 0>;
            status = "okay";
            label = "MCP2518A";
            reg = <0x0>;
            osc-freq = <20000000>;
            bus-speed = <250000>;
            sjw = <1>;
            prop-seg = <2>;
            phase-seg1 = <7>;
            phase-seg2 = <6>;
            #address-cells = <1>;
            #size-cells = <0>;
        };
        can2_mcp2518: mcp2515@1 {
            compatible = "microchip,mcp2515";
            spi-max-frequency = <1000000>;
            int-gpios = <&gpio0 28 0>;
            status = "okay";
            label = "MCP2518B";
            reg = <0x1>;
            osc-freq = <20000000>;
            bus-speed = <250000>;
            sjw = <1>;
            prop-seg = <2>;
            phase-seg1 = <7>;
            phase-seg2 = <6>;
            #address-cells = <1>;
            #size-cells = <0>;
        };
        ioexpander: mcp23sxx@2 {
            compatible = "microchip,mcp23sxx";
            label = "MCP23S08";
            #gpio-cells = <2>;
            ngpios = <8>;
            gpio-controller;
            reg = <0x2>;
            spi-max-frequency = <800000>;
        };
        adc104s021: spi-device@3 {
            compatible = "spi-device";
            reg = <0x3>;
            spi-max-frequency = <800000>;
            label = "ADC104S021";
        };
    };
    /{
        aliases{
            can-primary = &can1_mcp2518;
            can-secondary = &can2_mcp2518;
            io-expander = &ioexpander;
            adc104s021=&adc104s021;
        };
    };
    / {
        chosen {
                zephyr,console = &cdc_acm_uart0;
        };
    };
    
    &zephyr_udc0 {
        cdc_acm_uart0: cdc_acm_uart0 {
                compatible = "zephyr,cdc-acm-uart";
                label = "CDC_ACM_0";
        };
    };
    

    Best Regards,

    Babos

Children
Related