Skip to content

SPI4 on nRF5340 not working when using k_sleep() in main #35945

@alexsven

Description

@alexsven

Describe the bug
When building a release build with no serial, no debug etc. I've noticed that SPI4 won't work if there is a k_sleep() in main. I know this is a very special edge case, but it could be part of a larger issue.

The bug can be seen using a logic analyzer connected to:
MOSI: P0.09
MISO: P0.10
SCK: P0.08
CS: P0.011

When the k_sleep is present, only the CS-pin toggles

When swapping out SPI4 with SPI1/SPI2/SPI3 everything works, if I use a k_busy_wait() instead of a k_sleep() it also works. And if any sort of debug features are enabled (like serial, debug, log etc) it also works.

To Reproduce
I've attached a very simple sample here so that it can be reproduced with a nRF5340DK (I used a 0.11.0 version)
spi_fail.txt <-- rename to spi_fail.patch
So all is needed is to apply the patch, run:
west build -b nrf5340dk_nrf5340_cpuapp
and
west flash

I'm testing this in zephyr hash ebfe9be, but I have also verified on latest master (e2068d1). If using latest master CONFIG_OBJECT_TRACING=n must be removed from prj.conf

Metadata

Metadata

Assignees

Labels

area: SPISPI busbugThe issue is a bug, or the PR is fixing a bugplatform: nRFNordic nRFxpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions