Skip to content

spi: nRF HAL driver asserts when PM is used #42299

@JordanYates

Description

@JordanYates

Describe the bug

When controlling the PM state of a SPIM instance with pm_device_state_set before it has been used, an assertion is triggered inside the HAL driver (nrfx_spim.c).

The HAL driver cleanup function validates that the driver has been previously configured with an NRFX_ASSERT, which is enabled with CONFIG_ASSERT. https://github.com/zephyrproject-rtos/hal_nordic/blob/a42b016d7c7610489f5f8c79773fedc05ba352ee/nrfx/drivers/src/nrfx_spim.c#L527

The issue was introduced in #37632, which defers initialising the SPIM until it is first used.

To Reproduce

Add the following code which runs before device drivers together with CONFIG_ASSERT=y.

const struct device *spi = DEVICE_DT_GET(DT_NODELABEL(spi0));
pm_device_state_set(spi, PM_DEVICE_STATE_SUSPENDED);

Expected behavior
Assertion should not be triggered.

Logs and console output
Assertion failure inside pm_device_state_set, spim_nrfx_pm_control, nrfx_spim_init.

ASSERTION FAIL [p_cb->state != NRFX_DRV_STATE_UNINITIALIZED] @ WEST_TOPDIR/modules/hal/nordic/nrfx/drivers/src/nrfx_spim.c:50

Environment (please complete the following information):

  • Zephyr v2.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    LTSLong term release branch relatedbugThe issue is a bug, or the PR is fixing a bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions