Extracting CS47L63 driver from nRF5340 Audio DK application

After some considerable effort, I have extracted the CS47L63 driver from the nrf5340_audio application, and finally have the absolute bare minimum proof of concept code that builds and functions exactly as expected.

But only if debug optimizations (-Og) are enabled in the build configuration.

Without those, the CS47L63 does not initialize correctly, and its driver tries to use I2C instead of SPI to communicate, which of course fails. Note that cs47l63_comm_init() does not produce any log errors, but does not return 0.

I don't know how to debug the issue because it works flawlessly when debug optimizations are enabled, but not without, and my Zephyr knowledge is too limited to discern my subtle mistake. I'm asking for a more experienced developer to please point me in the right direction.

The /src/drivers/ directory only contains 4 files copied verbatim from the nrf5340_audio repo, and my main.c is incredibly sparse, so it should be very easy to understand (it just briefly beeps the internal tone generator).

I have attached the project, and would greatly appreciate whatever assistance or guidance anyone can provide.

nrfadk_codec_test.zip

  • I solved my maddeningly subtle problem.

    The cs47l63_comm_init() function creates a thread to handle codec events, and then calls k_thread_name_set() to assign it the name "CS47L63".

    Zephyr's thread naming feature requires CONFIG_THREAD_NAME to be set, which is what I was missing and the debug optimizations were adding, and was causing the init function to return early before properly configuring the control port for SPI communication.

    By enabling the above Kconfig token, the driver now initializes correctly and my code works as expected, regardless of debug optimizations. I hope this helps anyone else trying to reuse the CS47L63 driver on its own.

Related