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

Can't get PDM code to compile


I'm trying to add PDM into my project but can't get it to compile. When I try to call

return nrfx_pdm_init(&pdm_cfg, drv_audio_pdm_event_handler);

I get the error "main() undefined reference to `nrfx_pdm_init'"

This looks like it it is in the file nrfx_pdm.c, which is included in my project - but the code is greyed out from the line

#if NRFX_CHECK(NRFX_PDM_ENABLED)

But NRFX PDM is enabled in my sdk_config.h

// <e> NRFX_PDM_ENABLED - nrfx_pdm - PDM peripheral driver
//==========================================================
#ifndef NRFX_PDM_ENABLED
#define NRFX_PDM_ENABLED 1
#endif

I've run out of ideas to check - can you give me any clue?

Parents
  • Actually as is typical I found the answer just after posting... I didn't have the PDM hardware option enabled in sdk_config.h only the driver.

    Are there any code snippets available for using the nrfx drivers? I found a couple of posts relating to the legacy drivers but none for the newer drivers, and they seem to be quite different e.g. initialization and allocation of buffers (which is about as far as I have got at the moment)

  • Nick_RA said:
    Actually as is typical I found the answer just after posting...

     Good Slight smile

    We have some examples in the SDK that showcase most of our peripherals, but unfortunately, it doesn't look like we have one for PDM. What chip are you using?

    I guess the only thing I have to give you is the documentation for the drivers.

    I don't have any HW to test PDM for, so it is a bit difficult for me to test the drivers, and you probably already know more about PDM than me. The new drivers should work pretty much the same as the old one, from an API point of view. The main difference between the "legacy" and the nrfx drivers is that the nrfx drivers are separated from the SDK, so that they are easier to use as stand alone drivers.

    There is even a file that maps the old "legacy" function calls to the nrfx ones. Please check out nrf_drv_pdm.h in SDK\integration\nrfx\legacy

    BR,

    Edvin

  • If this were just for GPIO or something I would agree, but the PDM seems quite different. For example the legacy driver is initialised by passing it two buffer addresses, and it fills the buffers alternately. The new driver doesn't include buffers.

    The docs say " the sampling procedure is started by calling the nrf_drv_pdm_start function" and "The driver will immediately request a sample buffer from the user by generating an event (nrf_drv_pdm_evt_t::buffer_requested is set). To start the sampling, you must pass the buffer by calling nrf_drv_pdm_buffer_set." which is sort of contradictory.

    I'm thinking that I call  nrf_drv_pdm_start , and have nrf_drv_pdm_buffer_set in the event handler? What I'm not really seeing at the moment is the workflow, how the functions & events hang together.

    FWIW, I don't need continuous recording, a one-shot sample will be fine as the only function here is to determine ambient noise level.

    (BTW, you don't strictly need hardware to test PDM if you don't mind data being 0000 or FFFF - although I think that Thingy:52 includes a PDM mic?)

    I have nRF52832 and PCA10040 by the way with an external PDM mic.

  • Hello,

    Did you manage to get this up and running? Did you try to start using nrf_drv_pdm_start, and provide the buffer in the event handler?

Reply Children
  • I got some ways. The legacy mapping didn't work as the first steps failed using a code snippet posted on here

    nrf_drv_pdm_config_t pdm_cfg = NRF_DRV_PDM_DEFAULT_CONFIG(CONFIG_IO_PDM_CLK,
                                                                  CONFIG_IO_PDM_DATA,
                                                                  m_pdm_buff[0],
                                                                  m_pdm_buff[1],
                                                                  CONFIG_PDM_BUFFER_SIZE_SAMPLES);

    .. failed with something like "macro NRF_DRV_PDM_DEFAULT_CONFIG passed 5 parameters but expected 2"

    For a test I just set the same buffer in the event handler and it seems to do something sensible. That's enough for the moment as it's enabled me to finish my PCB design with a PDM microphone included.

    Is the event handler solely called on buffer full? I ask because there doesn't seem to be any event type passed to it.

  • NRF_DRV_PDM_DEFAULT_CONFIG() only takes two parameters, _pin_clk and _pin_din. Try:

    nrf_drv_pdm_config_t pdm_cfg = NRF_DRV_PDM_DEFAULT_CONFIG(CONFIG_IO_PDM_CLK, CONFIG_IO_PDM_DATA);

    please check the definition in nrfx_pdm.h. This will set pdm_cfg with the following parameters:

    pdm_cfg =                   \
    {                                                                     \
        .mode               = (nrf_pdm_mode_t)NRFX_PDM_CONFIG_MODE,       \
        .edge               = (nrf_pdm_edge_t)NRFX_PDM_CONFIG_EDGE,       \
        .pin_clk            = _pin_clk,                                   \
        .pin_din            = _pin_din,                                   \
        .clock_freq         = (nrf_pdm_freq_t)NRFX_PDM_CONFIG_CLOCK_FREQ, \
        .gain_l             = NRF_PDM_GAIN_DEFAULT,                       \
        .gain_r             = NRF_PDM_GAIN_DEFAULT,                       \
        .interrupt_priority = NRFX_PDM_CONFIG_IRQ_PRIORITY                \
    }

    The rest of the parameters are probably from your sdk_config.h and/or apply_old_config.h.

    Search for the definitions in your project to see where they are set and changed (apply_old_config.h).

    Since you have a project up and running, I assume you have called something like nrf_drv_pdm_init() -> nrf_drv_pdm_start(), and possibly a nrf_drv_pdm_buffer_set() in between these two (and you may or may not have used the nrfx_... function names directly, instead of the legacy names, which you can find in nrf_drv_pdm.h).

    What do these function calls return? If they all return NRF_SUCCESS (=0), do you get any events in the pdm handler?
    BR,
    Edvin
Related