Debugging out-of-tree device driver in NRF Connect

We're trying to develop a device driver by putting it in our application folder (under /drivers).

The west build system now recognises and builds it through the Kconfig and yaml files, but we can't debug it.

We can set breakpoints in our application main.c, and the debugger stops at those breakpoints, but when we set breakpoints in the device driver itself, the debugger doesn't stop there.

Same with RTT messages through Segger J-link - LOG_DBG(), LOG_ERR() and others in our main.c get printed, but the same functions in our driver don't get printed. The driver is basically the LPS22HB driver with slight modifications to become an LPS22DF driver (basically just changing the WHOAMI response from 0xB1 to 0xB4). For the DTS file:

&i2c0 {
	compatible = "nordic,nrf-twi";
	status = "okay";
	pinctrl-0 = <&i2c0_default>;
	pinctrl-1 = <&i2c0_sleep>;
	pinctrl-names = "default", "sleep";
	clock-frequency = <I2C_BITRATE_FAST>;
	lps22df-press@5c {
		compatible = "st,lps22df-press";
		reg = <0x5c>;
		label = "LPS22DF";
	};
};

For the driver CMakelists.txt:

# SPDX-License-Identifier: Apache-2.0

zephyr_library()

zephyr_library_sources(lps22df.c)

And the init function in lps22df.c, none of the LOG_DBG() messages print out:

static int lps22df_init(const struct device *dev)
{
	const struct lps22df_config * const config = dev->config;
	struct lps22df_data *data = dev->data;

	data->i2c_master = device_get_binding(config->i2c_master_dev_name);

	if (!data->i2c_master) {
		LOG_DBG("I2c master not found: %s",
			    config->i2c_master_dev_name);
		return -EINVAL;
	}

	if (lps22df_init_chip(dev) < 0) {
		LOG_DBG("Failed to initialize chip");
		return -EIO;
	}

	return 0;
}

But this one in main.c *does* print out:

    const struct device *dev = device_get_binding("LPS22DF");
	    if (dev == NULL) {
		    LOG_ERR("Could not get LPS22DF device\n");
		    return;
	    }

Parents Reply
  • Try adding the sensor driver in a similar manner as explained here: RE: MCUBoot: adding custom serial flash driver as secondary partition 

    In the reply linked to above, the out-of-tree driver was meant to be used by MCUboot, so the reply will apply to you if you just swap out MCUboot with your application (lvgl_test).

    Let me know if you have any issues with following the instructions in the link


    Explanation:

    The way the driver is added in the out_of_tree_driver example will only make it possible to access it directly.

    However, in your case you're not accessing the functions in lpsddf.c directly, but instead you're accessing them through the API zephyr/drivers/sensor.h

    For example, if you run sensor_sample_fetch(), it will trigger the function lps22df_channel_get().

    In order for Zephyr to see the out of tree lps22df.c and map it to the sensor.h API, you have to use the approach I linked to at the top.

    Best regards,

    Simon

Children
Related