macro expention

I am trying to understand why my spi_dt_spec doesn't get the right pins when I use the SPI_DT_SPEC_GET(DT_NODELABEL(kx122_spi), SPI_OP, 0); macros.
I tried to expand it and see what the macro actually returns. from what I understand 
SPI_DT_SPEC_GET(DT_NODELABEL(kx122_spi), SPI_OP, 0 expands to 
&__device_dts_ord_DT_N_NODELABEL_kx122_spi_BUS_ORD.
I am getting something wrong because the compiler doesn't recognize this identifier.

P.S. i think it may have something to do with the DT_CAT function:

does this function concats node_id with _BUS to form node_id_BUS?

 

  • Hi,

    Can you share how you are using your spi_dt_spec and explain what you mean by it not getting the right pins?
    Please also share your devicetree file where you define kx122_spi.

    Best regards,
    Marte

  • what heppens is i am tying to communicate with my sensor. i am trying to read the WHO_AM_I register but I don't get a reasonable result (it returns 0) 
    after debugging I saw that the driver expects the pins numbers to be inside this structure:

    it is inside the bus that is inside the spec
    bus->config->def_config
    as you see, I had to cast it to the structure I saw it is casted to deeper inside the callstack.
    you can see that the sck_pin, mosi_pin and miso_pin are all 0.
    this is the overlay:

    /*
     * SPDX-License-Identifier: Apache-2.0
     */

     / {
        aliases {
            extflash0 = &mx25r64;
        };

        leds {
            status = "disabled";
        };

        buttons {
            status = "disabled";
        };
    };

    /* Use the single port interrupt with the sense mechanism for all gpio pin interrupts */
    &gpio0 {
        status = "okay";
        //sense-edge-mask = < 0xffffffff >;
    };

    /* Use the single port interrupt with the sense mechanism for all gpio pin interrupts */
    &gpio1 {
        status = "okay";
        sense-edge-mask = < 0xffffffff >;
    };

    &uart0 {
        status = "okay";
        current-speed = <115200>;  
        // status = "disabled";
    };

    &uart1 {
        status = "disabled";
    };

    &qspi {
        status = "disabled";
    };

    &i2c0{
        status = "disabled";
    };

    &i2c1{
        status = "disabled";
    };

    &spi0{
        status = "disabled";
    };

    &spi1{
        status = "disabled";
    };

    &spi3{
        status = "disabled";
    };




    &spi2 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        cs-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;
        pinctrl-0 = <&spi2_default>;
        pinctrl-1 = <&spi2_sleep>;
        pinctrl-names = "default", "sleep";
        clock-frequency = <8000000>;

        kx122_spi: kx122_spi@0 {
            compatible = "atomation,kx122-spi";
            reg = <0>;
            spi-max-frequency = <8000000>;
            // int1-gpios = <&gpio0 17 (GPIO_ACTIVE_HIGH)>;
        };
    };

    &spi1 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi1_default>;
        pinctrl-1 = <&spi1_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
        bme280: bme280@0 {
            compatible = "bosch,bme280";
            reg = <0>;
            spi-max-frequency = <125000>;
        };
    };

    &pinctrl {
        spi2_default: spi2_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 7)>,
                        <NRF_PSEL(SPIM_MISO, 0, 11)>;
            };
        };

        spi2_sleep: spi2_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 6)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 7)>,
                        <NRF_PSEL(SPIM_MISO, 0, 11)>;
                low-power-enable;
            };
        };
    };

    &pinctrl {
        spi1_default: spi1_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 28)>,                    
                        <NRF_PSEL(SPIM_MOSI, 0, 29)>,
                        <NRF_PSEL(SPIM_MISO, 0, 31)>;
            };
        };
        spi1_sleep: spi1_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 28)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 29)>,
                        <NRF_PSEL(SPIM_MISO, 0, 31)>;
                low-power-enable;
            };
        };
    };
  • Hi,

    Are you using the Zephyr or nrfx SPI drivers? Can you share your full project?

    Best regards,
    Marte

Related