zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.86k stars 6.62k forks source link

bq274xx sensor - Fails to compile when CONFIG_PM_DEVICE enabled #39712

Closed ballardr closed 3 years ago

ballardr commented 3 years ago

Describe the bug When using the bq274xx sensor (kconfigs: CONFIG_SENSOR=y; CONFIG_BQ274XX=y), in conjunction with kconfig CONFIG_PM_DEVICE, the bq274xx sensor module fails to compile as on line 652 of zephyr/drivers/sensor/bq274xx/bq274xx.c, it tries to access the struct member "pm_state" of bq274xx which is of type "struct bq274xx_data" (as per line 414). However in zephyr/drivers/sensor/bq274xx/bq274xx.h it can be seen this structure has no pm_state member.

To Reproduce Enable the following kconfigs: CONFIG_SENSOR=y CONFIG_BQ274XX=y CONFIG_PM=y CONFIG_PM_DEVICE=y

Expected behavior The code in question is designed to make sure the sensor is powered

Impact Fails to compile

Logs and console output F:/zephyrproject/zephyr/drivers/sensor/bq274xx/bq274xx.c: In function 'bq274xx_gauge_configure': F:/zephyrproject/zephyr/drivers/sensor/bq274xx/bq274xx.c:652:9: error: 'struct bq274xx_data' has no member named 'pm_state' 652 | bq274xx->pm_state = PM_DEVICE_STATE_ACTIVE; | ^~ In file included from F:/zephyrproject/zephyr/include/sys/util_macro.h:34, from F:/zephyrproject/zephyr/include/sys/util.h:17, from F:/zephyrproject/zephyr/include/kernel/sched_priq.h:9, from F:/zephyrproject/zephyr/include/kernel_includes.h:23, from F:/zephyrproject/zephyr/include/kernel.h:17, from F:/zephyrproject/zephyr/include/init.h:11, from F:/zephyrproject/zephyr/include/device.h:29, from F:/zephyrproject/zephyr/include/drivers/i2c.h:23, from F:/zephyrproject/zephyr/drivers/sensor/bq274xx/bq274xx.c:9:

Environment (please complete the following information):

Work around For the time being, I'm commenting out lines 651 to 653 of zephyr/drivers/sensor/bq274xx/bq274xx.c

ballardr commented 3 years ago

It also assumes there is an interrupt for some reason: lines 762-767:

#ifdef CONFIG_PM_DEVICE
#define BQ274XX_INT_CFG(index)                            \
    .int_gpios = GPIO_DT_SPEC_INST_GET(index, int_gpios),
#else
#define BQ274XX_INT_CFG(index)
#endif

The above (and the functions using int_gpios) also cause a failure in compilation. Once again to work around, I commented out the code inside bq274xx_exit_shutdown_mode() and bq274xx_enter_shutdown_mode()

I am not using the interrupt as I'm not using the power management on the battery monitor currently (I may in a future hardware revision if nessisary)

gmarull commented 3 years ago

The build issue has already been fixed https://github.com/zephyrproject-rtos/zephyr/pull/39706, consider opening a new issue if you'd like to see the int_gpios part improved or made more flexible.

ballardr commented 3 years ago

The fix you have mentioned does not fix the main issue in this bug report: F:/zephyrproject/zephyr/drivers/sensor/bq274xx/bq274xx.c: In function 'bq274xx_gauge_configure': F:/zephyrproject/zephyr/drivers/sensor/bq274xx/bq274xx.c:652:9: error: 'struct bq274xx_data' has no member named 'pm_state

gmarull commented 3 years ago

Sorry I pasted the wrong link, and I see it hasn't been merged yet (https://github.com/zephyrproject-rtos/zephyr/pull/39706)

ballardr commented 1 year ago

@gmarull , should be fixed in pull request https://github.com/zephyrproject-rtos/zephyr/pull/39706 (see files tab). I think you need Zephyr 3.1 however or later (I don't think they back patched 2.7 with this bug fix). I'm no longer on the same project so I can't test

mountaindrew1959 commented 1 year ago

ok. after reading a little further, i figured it out. the original example overlay for the BQ274XX did not have an interrupt line configured in the sensor node. after adding that, my project compiles with both the PM and sensor drivers.