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

Enabling PDM on nrf9160 in non-secure (NS) mode

Greetings,

we are writing a library for nrf9160dk, which is using PDM to read out microphone data from an extension module.

we are using NCS v1.5.0

To summarize the code, the initialization looks something like this:

void microphone_init(void)
{
    nrfx_err_t err;

    /* PDM driver configuration */
    nrfx_pdm_config_t config_pdm = NRFX_PDM_DEFAULT_CONFIG(PDM_CLK_PIN, PDM_DIN_PIN);
    config_pdm.clock_freq = NRF_PDM_FREQ_1280K;
    config_pdm.ratio = NRF_PDM_RATIO_80X;
    config_pdm.edge = NRF_PDM_EDGE_LEFTRISING;
    config_pdm.gain_l = NRF_PDM_GAIN_MAXIMUM;
    config_pdm.gain_r = NRF_PDM_GAIN_MAXIMUM;

    /* PDM interrupt configuration necessary for Zephyr */
    IRQ_DIRECT_CONNECT(PDM_IRQn, 6, nrfx_pdm_irq_handler, 0);

    err = nrfx_pdm_init(&config_pdm, pdm_data_handler);
    if(err != NRFX_SUCCESS){
        ei_printf("PDM init error: %d\n", err);
    }
    else{
        ei_printf("PDM init OK\n");
    }
}

static void pdm_data_handler(nrfx_pdm_evt_t const * p_evt)
{
    nrfx_err_t err = NRFX_SUCCESS;
    static uint8_t buf_toggle = 0;

    if(p_evt->error != 0){
        ei_printf("PDM handler error ocured\n");
        ei_printf("pdm_data_handler error: %d, %d  \n", p_evt->error, p_evt->buffer_requested);
        return;
    }
    if(true == p_evt->buffer_requested){
        buf_toggle ^= 1;
        err = nrfx_pdm_buffer_set(pdm_buffer_temp[buf_toggle], AUDIO_DSP_SAMPLE_BUFFER_SIZE);
        if(err != NRFX_SUCCESS){
            printk("PDM buffer init error: %d\n", err);
        }
    }
    if(p_evt->buffer_released != NULL){
            write_data = true;
            current_buff = pdm_buffer_temp[buf_toggle];
    }
}

The code then crashes in nrfx_pdm_init, specifically in nrfx/drivers/src/nrxf_pdm.c at line 204 calling nrf_pdm_ratio_set, which sets the value of the RATIO register.
The issue is thus non-accessibility of PDM hardware from non secure application code.

If I add CONFIG_SPM_NRF_PDM0_NS=y to spm.conf, then this compile time warning is generated:

warning: SPM_NRF_PDM0_NS (defined at /home/tjaz/NCS/ncs_v1.5.0/nrf/subsys/spm/Kconfig:291) was
assigned the value 'y' but got the value 'n'. Check these unsatisfied dependencies:
SOC_NRF5340_CPUAPP (=n). See
http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_SPM_NRF_PDM0_NS.html and/or look up
SPM_NRF_PDM0_NS in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.

So, I can only set this if compiling for nrf5340...

If I then go into spm.c and just force enable it by adding PERIPH("NRF_PDM", NRF_PDM_S, 1) on line 444, the driver starts to work.

--- 

This "fix" is not acceptable. To enable PDM for nrf9160, we would now have to create a patch file, that adds this one line to spm.c, and then tell users of the library to patch their ncs installation.

The question of this thread is thus:
How can we enable PDM0_NS for nrf9160 either on the configuration level, or directly in application code. A solution that modifies zephyr/ncs is not acceptable.

Regards,
Tjaž 

Parents Reply Children
No Data
Related