Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lis3mdl_init_interrupt triggers __ASSERT in lis3mdl_sample_fetch #84145

Open
TilmannUnte opened this issue Jan 17, 2025 · 0 comments
Open

lis3mdl_init_interrupt triggers __ASSERT in lis3mdl_sample_fetch #84145

TilmannUnte opened this issue Jan 17, 2025 · 0 comments
Assignees
Labels
area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug

Comments

@TilmannUnte
Copy link
Contributor

Describe the bug
I'm using the LIS3MDL magnetometer connected to I2C with the optional trigger attached to a GPIO pin on my MCU.

With CONFIG_LIS3MDL_TRIGGER enabled, lis3mdl_init calls lis3mdl_init_interrupt.
This function contains a call to lis3mdl_sample_fetch:
if (lis3mdl_sample_fetch(dev, SENSOR_CHAN_ALL) < 0) {

However, lis3mdl_sample_fetch contains the following assertion:
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);

Therefore, the initialization always results in a fatal error, when CONFIG_LIS3MDL_TRIGGER and CONFIG_ASSERT are both set.

I consider this to be a bug, because everything works fine when CONFIG_ASSERT is not set!
Unless I have missed an important detail, I think it would be fine to remove the assertion to fix this bug.

To Reproduce

  • suggested board: disco_l475_iot1
  • clone my test program: https://github.com/TilmannUnte/zephyr_lis3mdl_test
  • build, flash and start serial console
  • press blue user button on board and wait a few seconds for fatal error to appear
  • deactivate CONFIG_ASSERT in prj.conf and retry, the error should be gone

Expected behavior
The LIS3MDL driver should not trip a (pointless?) assertion when setting up the interrupt line.

Impact
With this bug, The CONFIG_LIS3MDL_TRIGGER and CONFIG_ASSERT settings are mutually exclusive.
This is very annoying in complex applications, because assertions have safety critical roles and I cannot just deactivate them.

Logs and console output
These are from my production code, not the test program I linked to, but the error is equivalent:

ASSERTION FAIL [chan == SENSOR_CHAN_ALL] @ WEST_TOPDIR/zephyr/drivers/sensor/st/lis3mdl/lis3mdl.c:69
[00:00:02.348,000] <err> os: r0/a1:  0x00000004  r1/a2:  0x00000045  r2/a3:  0x00000004
[00:00:02.348,000] <err> os: r3/a4:  0x00000004 r12/ip:  0x00005bbd r14/lr:  0x0800981f
[00:00:02.348,000] <err> os:  xpsr:  0x01000000
[00:00:02.348,000] <err> os: s[ 0]:  0x00000000  s[ 1]:  0x08013df5  s[ 2]:  0x00000000  s[ 3]:  0x08002c41
[00:00:02.348,000] <err> os: s[ 4]:  0x00000000  s[ 5]:  0x08002cc7  s[ 6]:  0x08002c41  s[ 7]:  0x00000000
[00:00:02.348,000] <err> os: s[ 8]:  0x00000000  s[ 9]:  0x08002c41  s[10]:  0x00000000  s[11]:  0x0801629b
[00:00:02.348,000] <err> os: s[12]:  0x00000000  s[13]:  0xdafb43d1  s[14]:  0x52ce17f1  s[15]:  0xf7af9383
[00:00:02.348,000] <err> os: fpscr:  0x148621a2
[00:00:02.348,000] <err> os: Faulting instruction address (r15/pc): 0x08016724
[00:00:02.348,000] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:00:02.348,000] <err> os: Current thread: 0x20002d80 (lis3mdl_tcb)
[00:00:02.373,000] <err> os: Halting system
(gdb) break lis3mdl.c:69
Breakpoint 1 at 0x80097c4: file /home/untetilm/zephyrproject/zephyr/drivers/sensor/st/lis3mdl/lis3mdl.c, line 69.
Note: automatically using hardware breakpoints for read-only addresses.
(gdb) continue
Continuing.

Breakpoint 1, lis3mdl_sample_fetch (dev=dev@entry=0x801bae0 <__device_dts_ord_107>, chan=chan@entry=SENSOR_CHAN_ALL) at /home/untetilm/zephyrproject/zephyr/drivers/sensor/st/lis3mdl/lis3mdl.c:69
69		__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
(gdb) info args
dev = 0x801bae0 <__device_dts_ord_107>
chan = SENSOR_CHAN_ALL
(gdb) bt
#0  lis3mdl_sample_fetch (dev=dev@entry=0x801bae0 <__device_dts_ord_107>, chan=chan@entry=SENSOR_CHAN_ALL) at /home/untetilm/zephyrproject/zephyr/drivers/sensor/st/lis3mdl/lis3mdl.c:69
#1  0x08009e7c in lis3mdl_init_interrupt (dev=dev@entry=0x801bae0 <__device_dts_ord_107>) at /home/untetilm/zephyrproject/zephyr/drivers/sensor/st/lis3mdl/lis3mdl_trigger.c:136
#2  0x080099ec in lis3mdl_init (dev=0x801bae0 <__device_dts_ord_107>) at /home/untetilm/zephyrproject/zephyr/drivers/sensor/st/lis3mdl/lis3mdl.c:155
[rest omitted]

Environment:

  • OS: Ubuntu Linux 22.04
  • Zephyr SDK 0.17
  • Zephyr commit: 90d8710
@TilmannUnte TilmannUnte added the bug The issue is a bug, or the PR is fixing a bug label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

4 participants