This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF5340 - TWIM driver not initialized

Hi,

I was able to create a device driver support for a DAC, model TI DAC80501Z.
In the first place I put the driver in zephyr/drivers/sensors.

I works fine.

Then I made some effort to move the driver in zephyr/drivers/dac, which seems more appropriate for a DAC.
When the driver reads the I2C peripheral, Zephyr complains the TWIM driver is not initialized:

ASSERTION FAIL [p_cb->state == NRFX_DRV_STATE_INITIALIZED] @ WEST_TOPDIR/modules/hal/nordic/nrfx/drivers/src/nrfx_twim.c:326<CR><LF>
E: r0/a1: 0x00000004 r1/a2: 0x00000146 r2/a3: 0x00000040<CR><LF>
E: r3/a4: 0x00013a15 r12/ip: 0x00000000 r14/lr: 0x0000b7d7<CR><LF>
E: xpsr: 0x69000000<CR><LF>
E: Faulting instruction address (r15/pc): 0x0000fb4a<CR><LF>
E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0<CR><LF>
E: Current thread: 0x20001050 (unknown)<CR><LF>
E: Resetting system<CR><LF>

I don't know why.
In the .config file I already have

CONFIG_NRFX_TWIM=y
CONFIG_NRFX_TWIM1=y

Thanks
Gabriele

  • I think DAC80501Z should be under zephyr\drivers\sensor, since it is a separate device not integrated into a microcontroller.

    Let me try to explain. The drivers in e.g. ncs\v1.3.0\zephyr\drivers\dacncs\v1.3.0\zephyr\drivers\adc or ncs\v1.3.0\zephyr\drivers\spi are linked to soc specific drivers. E.g. for the spi driver spi_nrfx_spim.c:

    1. ncs\v1.3.0\zephyr\drivers\spi\spi_nrfx_spim.c → 
    2. ncs\v1.3.0\modules\hal\nordic\nrfx\drivers\src\nrfx_spim.c

    For your device, this direct linking is not possible, it has to go through three steps:

    1. zephyr/drivers/sensors/dac8050 → 
    2. ncs\v1.3.0\zephyr\drivers\spi\spi_nrfx_spim.c or ncs\v1.3.0\zephyr\drivers\i2c\i2c_nrfx_twim.c → 
    3. ncs\v1.3.0\modules\hal\nordic\nrfx\drivers\src\nrfx_spim.c or ncs\v1.3.0\modules\hal\nordic\nrfx\drivers\src\nrfx_twim.c

    So that's the reason I think it should be placed in zephyr\drivers\sensor. I have not looked into your errors, but the placement may be the reason.

    However, I am not 100% sure about this, you could ask here and get the perspective from some other Zephyr developers. 

    Best regards,

    Simon

  • Hi Simon,

    from Zephyr Slack channel I got the answer.
    They stress out the fact that we have external ADCs in drivers/adc and external GPIOs in drivers/gpio, so we should be able to have external DACs in drivers/dac.
    The specific problem was the init priority value of the DAC, which was lower than for I2C and within the same level (POST_KERNEL). I solved using a larger value.

    Best regards,
    Gabriele

Related