Re: Adding support for Nordic PDM Driver in Devicetree #nrf52832 #pdm #driver


Bolivar, Marti
 

"Frederik David Damsgaard Popp via lists.zephyrproject.org"
<frdm=demant.com@...> writes:

Hi Martí

Thank you for your detailed answer! This was a great help
You're welcome!





Strictly speaking, actual drivers -- as in drivers/subsystem/my_driver.c
files -- are enabled using Kconfig, not devicetree. So
CONFIG_MY_DRIVER=y in Kconfig means "enable my driver," which means
something like "compile my_driver.c."


I think I get it now. The dts must specify whether or not the PDM hardware is available on the given board, and if so, what pins etc.
The Kconfig are used to enable the driver to use for the application,
and the CMakeLists includes the correct sources, based on whether the
implementation should be either nrfx or some other implementation.
Correct.





config MY_AUDIO_DRIVER
bool
default $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_PDM))
help
Enable my audio driver.

It looks like someone already prepared the setup for a PDM driver, since the SOC Kconfig defines a HAS_HW_NRF_PDM, which means I could depend on that?
I tried something like this:

config PDM_NRFX
bool "nRF PDM nrfx driver"
default y
depends on HAS_HW_NRF_PDM
select NRFX_PDM
help
Enable support for nrfx Hardware PDM driver for nRF52 MCU series.

Totally based off of the PWM Kconfig, but it should work right?
Those HAS_HW_NRF_* options are slated for removal at some point:

https://github.com/zephyrproject-rtos/zephyr/issues/8481

It would be better not to add more uses of them, especially if this work
is going upstream.





It looks like there is already a dts/bindings/audio/nordic,nrf-pdm.yaml
file, though, so it doesn't seem like you need to define your own
binding. I didn't find any drivers for it in the upstream tree, though.

I took a look at the pwm_nrfx driver, which seems to act as a sort of wrapper for the nrfx_pwm driver in the Nordic HAL module.
I assume that I would have to do something similar, as there already
is a pdm driver in the Nordic HAL module?
That is the "shim driver" approach, yes. It's a perfectly valid way of
doing things in Zephyr.

This way I would take an already implemented PDM driver for Nordic chipsets (such as the nRF52832 on the Nordic Thingy 52), and incorporate it into the Zephyr system, and making it hardware agnostic.
The remaining thing to do, is then modify the devicetree for the Nordic devices that actually have PDM hardware, so that the driver can be used for these boards.

Again, I'm working this stuff out as I go, and this is the method I found so far, but I think it makes sense.
I would love to hear your (or anyone else with some knowledge on this)
input, to make sure I'm on the right path.
At least the nRF5340 and nRF9160 SoC DTSI files have pdm nodes defined.
If you need to add them for other SoCs, the existing definitions may be
a good starting point.

Martí


Best
Frederik

Join devel@lists.zephyrproject.org to automatically receive all group messages.