Hello Circuit Dojo Community,
I am wondering if anyone here can provide me some insights or paths to debugging Zephyr initialization code which runs just before a given app’s void main(void) or comparable main routine runs?
The issue I have relates to an STMicro accelerometer for which I am trying to initialize an interrupt. There are kind of three pieces I can identify to setting up a hardware based interrupt line from a sensor to a dev board’s MCU:
(1) expression of GPIO port and pin with “gpio-keys” compatible value, and “okay” node status
(2) sensor driver Kconfig symbol set to ‘y’ to enable/compile interrupt code in driver
(3) run time configuration of sensor interrupt control register, e.g. command(s) to sensor
My dev board is an lpcxpresso55s69. When I build single core Zephyr apps I call out
west build -b lpcxpresso55s69_cpu0, which is required given the way NXP’s board support DTS and DTSI files are named. For a physical interrupt line I’ve chosen Port 1 pin 9. The port is enabled in the SOC device tree file for this board. Pin 9 appears to be one of about five I/O pins not connected to buttons, LEDs or other on board devices.
When my app starts, however, there’s something which keeps the IIS2DH from being ready. First lines of Zephyr console output are:
[00:00:00.009,000] <err> IIS2DH: iis2dh@18: device ������rF����� is not ready
[00:00:00.017,000] <err> IIS2DH: Failed to initialize interrupts
*** Booting Zephyr OS build zephyr-v3.2.0 ***
The code continues on and establishes comm’s with the sensor directly via Zephyr’s I2C API. I configure the sensor’s interrupt register to produce an active low signal on INT1 line when a FIFO watermark value is reached. I start FIFO based data gathering, and can see the interrupt line go low periodically, so long as I read out of the FIFO from time to time and reset the sensor FIFO to completely clear the FIFO and start readings acquisition anew. ( https://www.st.com/resource/en/datasheet/iis2dh.pdf )
As a sanity check I even borrowed code from Zephyr 3.2.0 samples/basic/button app to set up a callback function on the interrupt I was hoping to enable properly through STMicro’s accelerometer driver for their IIS2DH. Just after the above Zephyr boot time messages, my app code produces these diagnostics:
- DEV 1028 - symbol ST_IIS2DH got assigned 'DT_N_S_soc_S_peripheral_50000000_S_flexcomm_8a000_S_iis2dh_18'
- kd_thread_iis2dh - Success finding iis2dh device,
- kd_thread_iis2dh - WARNING - sensor device 'iis2dh@18' is not ready!
- kd_thread_iis2dh - INFO: device name (Zephyr compile time setting) found to be 'iis2dh@18'
- kd_thread_iis2dh - INFO: boot time Zephyr init result value holds 5,
Set up button at gpio@1 pin 9
- config register 4 at 0x23 holds 0x88
Sensor IIS2DH INT1 event 0 at Zephyr time 160801860
I can see Zephyr’s initialization code returns an error value ‘5’. But I can also see that this sensor is alive and gathering qualitatively correct data. An interrupt appears at intervals when I enable it, plus enable data acquisition. Hacked code of my own in the Zephyr app responds to the interrupt and associated callback I set up outside of the STMIcro driver. So hardware functions and is wired correctly.
Given the seeming software nature of this error, where can I look to “see” in what way early pre-main() initialization code is failing to find the sensor “ready”?
west workspace I’ve searched the artifacts in the
buildsubdir, but I don’t find any obvious source files which would be responsible for initializing this sensor.
One other question: is there an “un-initialize” function one may call on a sensor? If yes, is this safe to call if Zephyr’s
device_is_ready(dev) returns false?