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

nRF9160 samples : undefined device names for device_get_binding

Hello,

I'm using ncs 1.2.0 and trying to compile sample projects like  v1.2.0\nrf\samples\sensor\bh1749, also v1.2.0\zephyr\samples\sensor\* but all the defines for device label like "DT_INST_0_ROHM_BH1749_BUS_NAME" passed to device_get_binding() are unknown. 

What's the proper way to define them in the project!. Should I make an overlay file where I define the communication peripheral....etc ? if yes, how can I link between lets say the SPI and the device ?

Regards,

Parents
  • Hi!

    The sample you refer to for BH1749 only works with the Thingy:91 not the nRF91 DK, because the DK does not have that sensor. If you build it using the nrf9160_pca20035ns board you shouldn't be getting any errors.

    Please take a look at this line in the .dts file of the Thingy:91 boards file. This is how the sensor should be defined in an overlay file (in another case, where you, for example, included an external sensor). 

     

    if yes, how can I link between lets say the SPI and the device ?

     You can take a look at the .dts file I linked to above to see how these defines should look. 

    This NCS tutorial explains how to use the sensor drivers and what overlay files are.

    Best regards,

    Heidi

  • Thank you Heidi for your response.

    I have followed the tuotorials series and have a good understanding of the ncs usage.

    I'm actually trying to add CAN data tusing the nrF9160 DK and mcp2515 chip. So I started from this ncs\v1.2.0\zephyr\samples\drivers\CAN which uses the same chip.

    building the project right away doesn't work obviously, It says undefined  DT_ALIAS_CAN_PRIMARY_LABEL passing in device_get_binding();

    so I added the mcp2515.overlay in the CMakeLists.txt as shown below

    cmake_minimum_required(VERSION 3.13.1)
    set(<image_name>_DTC_OVERLAY_FILE
    ${CMAKE_CURRENT_SOURCE_DIR}/mcp2515.overlay
    )

    so my question is, how to add the CAN into the nrf9160 DK ? 

    Best regards

Reply
  • Thank you Heidi for your response.

    I have followed the tuotorials series and have a good understanding of the ncs usage.

    I'm actually trying to add CAN data tusing the nrF9160 DK and mcp2515 chip. So I started from this ncs\v1.2.0\zephyr\samples\drivers\CAN which uses the same chip.

    building the project right away doesn't work obviously, It says undefined  DT_ALIAS_CAN_PRIMARY_LABEL passing in device_get_binding();

    so I added the mcp2515.overlay in the CMakeLists.txt as shown below

    cmake_minimum_required(VERSION 3.13.1)
    set(<image_name>_DTC_OVERLAY_FILE
    ${CMAKE_CURRENT_SOURCE_DIR}/mcp2515.overlay
    )

    so my question is, how to add the CAN into the nrf9160 DK ? 

    Best regards

Children
  • Okay, I see. 

    Chris said:
    so my question is, how to add the CAN into the nrf9160 DK ? 

     It looks like what you have done is correct.

    but all the defines for device label like "DT_INST_0_ROHM_BH1749_BUS_NAME" passed to device_get_binding() are unknown. 

    What error are you seeing specifically? 

    Can you attach the mcp2515.overlay file?

     

    Chris said:
    cmake_minimum_required(VERSION 3.13.1)
    set(<image_name>_DTC_OVERLAY_FILE
    ${CMAKE_CURRENT_SOURCE_DIR}/mcp2515.overlay
    )

    For this line just beware that if <image_name> has an overlay file from before, you need to put the existing file name between those two arguments.

  • CAN.zip

    I attached the project that I copied from v1.2.0\zephyr\samples\drivers\CAN.

    I only added the overlay file for mcp2515 to cMakeLists.txt

    I get the following error 

    ../src/main.c: In function 'main':
    ../src/main.c:198:44: error: 'DT_ALIAS_CAN_PRIMARY_LABEL' undeclared (first use in this function); did you mean 'DT_ALIAS_TIMER_1_LABEL'?
       printk("DT_ALIAS_CAN_PRIMARY_LABEL %d\n",DT_ALIAS_CAN_PRIMARY_LABEL);
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~
                                                DT_ALIAS_TIMER_1_LABEL

    One this is that not clear for me, what child name should I use to enable CAN over SPI

    I simply put CAN as showing below

    set(CAN_DTC_OVERLAY_FILE
    ${CMAKE_CURRENT_SOURCE_DIR}/mcp2515.overlay

    Thank you Heidi for your help.

  • Okay, it builds for me now, just had to change a few things.

    1. First of all the .overlay file should have the same name as the board you're building for, so "nrf9160_pca10090ns.overlay". 

    2. Second, SPI1 will crash with UART1 on the DK by default, so it's easier to just avoid that one and use SPI3 instead.

    3. And then in the .overlay file in your project, there were a few errors in the definitions of GPIO's.

    The overlay filed here works for me, just make sure to have the correct name. 

    &spi3 {
        status = "okay";
        cs-gpios = <&gpio0 13 0>; /* D10 */
        sck-pin = <10>;
        mosi-pin = <11>;
        miso-pin = <12>;
        can1: mcp2515@0 {
            compatible = "microchip,mcp2515";
            spi-max-frequency = <1000000>;
            int-gpios = <&gpio0 31 0>; /* D2 */
            status = "okay";
            label = "CAN_1";
            reg = <0x0>;
            osc-freq = <16000000>;
            bus-speed = <125000>;
            sjw = <1>;
            prop-seg = <2>;
            phase-seg1 = <7>;
            phase-seg2 = <6>;
            #address-cells = <1>;
            #size-cells = <0>;
        };
    };
    / {
     aliases {
        can-primary = &can1;
        };
    };

    Best regards,

    Heidi

  • Thank you Heidi very much for your help, now it is working, I just had to enable some stuff in the prj.conf file.

    Below is the config that worked for me

    CONFIG_SERIAL=n
    CONFIG_CAN=y
    CONFIG_CAN_1=y
    CONFIG_SPI=y
    CONFIG_CAN_MCP2515=y
    CONFIG_CAN_INIT_PRIORITY=80
    CONFIG_CAN_MAX_FILTER=5
    
    CONFIG_SHELL=y
    CONFIG_CAN_SHELL=y
    CONFIG_DEVICE_SHELL=y

Related