Problems integrating Battery Voltage example

I've been trying to integrate the Battery Voltage example (v2.0.0\zephyr\samples\boards\nrf\battery) into my existing code.  I can get the example to work stand alone on my hardware, but when I try and incorporate battery.c and battery.h into my own code, I get a bunch of build errors.

C:\Nordic\v2.0.0\zephyr\include\zephyr\device.h:96:39: error: '__device_dts_ord_DT_N_S_vbatt_P_io_channels_IDX_0_PH_ORD' undeclared here (not in a function)
   96 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
      |                                       ^~~~~~~~~
C:\Nordic\v2.0.0\zephyr\include\zephyr\device.h:291:37: note: in expansion of macro 'DEVICE_NAME_GET'
  291 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_NAME(node_id))
      |                                     ^~~~~~~~~~~~~~~
C:\Nordic\v2.0.0\zephyr\include\zephyr\device.h:311:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  311 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ^~~~~~~~~~~~~~~~~~
c:\Nordic\Development\LSR-MAX\LSR-MAX_V0_09\src\battery.c:69:9: note: in expansion of macro 'DEVICE_DT_GET'
   69 |  .adc = DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(VBATT)),
      |         ^~~~~~~~~~~~~

The errors seem to be associated with these sections of the example code (note that I have modified these slightly from the example, as I have defined the vbatt node in my overlay file)

static const struct divider_config divider_config = {
	.io_channel = {
		DT_IO_CHANNELS_INPUT(VBATT),
	},
	.power_gpios = {
		DT_GPIO_LABEL(VBATT, power_gpios),
		DT_GPIO_PIN(VBATT, power_gpios),
		DT_GPIO_FLAGS(VBATT, power_gpios),
	},
	.output_ohm = DT_PROP(VBATT, output_ohms),
	.full_ohm = DT_PROP(VBATT, full_ohms),
};

static struct divider_data divider_data = {
	.adc = DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(VBATT)),
};

For some reason, the following aren't being recognised:

DT_IO_CHANNELS_INPUT
DT_GPIO_LABEL
DT_GPIO_PIN
DT_GPIO_FLAGS
DT_PROP
DEVICE_DT_GET
I can't see anything in the #includes, or the prj.conf file that would indicate why these errors are occuring.
Can anyone assist me to fix these problems?
 
Cheers,
Mike
Parents
  • Hello Mike,

    It looks like there may be an issue with the device tree overlay as DEVICE_DT_GET() fails to retrieve the node identifier. I suggest that you try to compare the generated zephyr.dts in <project build directory>/zephyr/ from the two projects to see if there are any relevant differences. First thing you may want to check is if the zephyr.dts for the failed build includes the vbatt node as expected.

    Cheers,

    Vidar

  • HI Vidar,

    Looks like you were right - the vbatt node wasn't getting included in the zephyr.dts file for my code.  Not sure why - perhaps had something to do with the position within the overlay file relative to other node definitions.

    Anyway, I moved it to the top of my overlay file and it now seems to be working as expected

    Thanks for your help

    Cheers,

    Mike

Reply Children
Related