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;
	    }

Related