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

VL53L0x with NCS 1.5.0 on nRF52832

I'm new to the NCS/Zephyr environment. In the past I got the nRF52832 working with the VL53L0x. I ported arduino code of the VL53L0x and got it working well. But now I'm trying to move to the NCS/Zephyr tools. 

I selected the peripheral_uart example and added I2C driver. It runs perfect and therefore time to move on with I2C devices.

I found in de zephyr directory the VL53L0x files and I found in the "Configure nRF Connect SDK Project" the Sensor and VL53L0x option.

But now I got stuck.

Running the code with only selected the VL53L0x option the code will not compile anymore. In devicetree.h

#define DT_INST(inst, compat) UTIL_CAT(DT_N_INST, DT_DASH(inst, compat))

I got the following error:

ncs/v1.5.0/zephyr/include/devicetree.h:300:40: error: 'DT_N_INST_0_st_vl53l0x_BUS_P_label' undeclared (first use in this function)

ncs/v1.5.0/zephyr/include/devicetree.h:300:40: error: 'DT_N_INST_0_st_vl53l0x_REG_IDX_0_VAL_ADDRESS' undeclared (first use in this function); did you mean 'DT_N_S_cpus_S_cpu_0_REG_IDX_0_VAL_ADDRESS'?

How can I solve these issues?

Parents
  • I guess you're getting this error since you've only enable the firmware specific parts of the sensor, but have not enabled the hardware.

    When you enable VL53L0x in "Configure nRF Connect SDK Project", the config CONFIG_VL53L0X, will get set equal to y. Like done here. Be aware if you configure it through "Configure nRF Connect SDK Project", it will only get added to the build folder, and if you delete the build folder, or change the name, it will get lost. To make it permanent, you should add it to the prj.conf file

    Unfortunately I could not find any example in NCS where this is done, not even in the vl53LOx sample, but you could look at some other I2C speficic sensor, to get an idea how to do it. E.g. check out zephyr/samples/sensor/ccs811/boards/nrf51_ble400.overlay and zephyr/samples/sensor/mpu6050/boards/nrf52dk_nrf52832.overlay.

    These may be useful as well:

    If you're having issues with enabling the hardware part of the VL53L0x, please get back to me, and I will try to assist.

    Best regards,

    Simon

  • Thank you for your reply.

    I added a BME280 to my board to test the above. And I got the BME280 running in no time. After adapting the code to the VL53L0x I got a bit further than before.

    However, as soon as I fetch data from the VL53L0x the code will crash and it points me to the fault_s.S line 80.

    mrs r0,MSP

    And in the debug terminal I got the following.

    [00:02:16.865,844] [1;31m<err> os: ***** MPU FAULT *****[0m
    [00:02:16.865,875] [1;31m<err> os:   Instruction Access Violation[0m
    [00:02:16.865,875] [1;31m<err> os: r0/a1:  0x00000000  r1/a2:  0x00000038  r2/a3:  0x00000000[0m
    [00:02:16.865,875] [1;31m<err> os: r3/a4:  0xf8e92dbe r12/ip:  0x00000000 r14/lr:  0x0000fedb[0m
    [00:02:16.865,875] [1;31m<err> os:  xpsr:  0x00000000[0m
    [00:02:16.865,905] [1;31m<err> os: Faulting instruction address (r15/pc): 0xf8e92dbe[0m
    [00:02:16.865,905] [1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0[0m
    [00:02:16.865,905] [1;31m<err> os: Current thread: 0x20002370 (unknown)[0m

    The code I'm using for both sensors I copied from the samples and a bit altered.

            const struct device *dev_bme = device_get_binding(BME280_LABEL);
    
            if (dev_bme == NULL) {
              printk("No device \"%s\" found; did initialization fail?\n", BME280_LABEL);
            } else {
              printk("Found device \"%s\"\n", BME280_LABEL);
            }
            
            const struct device *dev_vl = device_get_binding(VL53L0X_LABEL);
            if (dev_bme == NULL) {
            printk("No device \"%s\" found; did initialization fail?\n", VL53L0X_LABEL);
            } else {
              printk("Found device \"%s\"\n", VL53L0X_LABEL);
            }

    The response of this code is very prommising:

    (15:44:04.319) (0.000) Found device "BME280"
    (15:44:04.319) (0.000) Found device "VL53L0X"

    Once the sensors are found I execute the following code. And as soon the fetch from the VL53 is executed I get the message MPU fault.

    struct sensor_value temp, press, humidity, proxi, distance;
    
            printk("fetching dev_bme data\n");
    		sensor_sample_fetch(dev_bme);
                    
    		sensor_channel_get(dev_bme, SENSOR_CHAN_AMBIENT_TEMP, &temp);
    		sensor_channel_get(dev_bme, SENSOR_CHAN_PRESS, &press);
    		sensor_channel_get(dev_bme, SENSOR_CHAN_HUMIDITY, &humidity);
    
    		printk("temp: %d.%02d; press: %d.%02d; humidity: %d.%02d\n",
    		      temp.val1, temp.val2/10000, (press.val1*10), press.val2/10,
    		      humidity.val1, humidity.val2);
    
            printk("fetching dev_vl data\n");
            sensor_sample_fetch(dev_vl);
                    
            sensor_channel_get(dev_vl, SENSOR_CHAN_PROX, &proxi);
            sensor_channel_get(dev_vl, SENSOR_CHAN_DISTANCE, &distance);
            printk("proximity:  %d\n", proxi.val1);
            printk("proximity:  %.3fm\n", sensor_value_to_double(&distance));

    Can you help me?

  • I assume you've copied the sample zephyr\samples\sensor\vl53l0x, including prj.conf and the necessary configurations

    Would you be able to provide me the overlay file, as well as the file <sample>/build/zephyr/zephyr.dts?

    Could you try to do some debugging, and figure out exactly what line is causing the issue? sensor_sample_fetch should call the following functions I think

    • vl53l0x_sample_fetch() | zephyr\drivers\sensor\vl53l0x\vl53l0x.c
    • VL53L0X_PerformSingleRangingMeasurement() | \modules\hal\st\sensor\vl53l0x\api\core\src\vl53l0x_api.c
    • VL53L0X_WrByte() | zephyr\drivers\sensor\vl53l0x\vl53l0x_platform.c

    Try to add some printk's or do some debugging to see where it fails.

    You could also ask for help in any of the Zephyr resources below, to see if anyone are familiar with this sensor.

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.0/zephyr/introduction/index.html#community-support 

  • I found within the VL53 API that my sensor generates a "VL53L0X_ERROR_CONTROL_INTERFACE".

    It looks there is something broken within the sensor. A new sensor made it all work.

    Thank you for the support. Adding printk to the VL53L0x API was very helpfull.

  • I'm happy to help and awesome to hear that you got it to work!

Reply Children
No Data
Related