This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF52840 SDK16 - How to use the nrfx PPI driver

Hi everyone,

I use the nrf52840 and the SDK 16. I copied the saadc example and I want to modify it and use the RTC instead of the timer as an event for PPI. I've noticed that the example uses the legacy driver instead of the new nrfx implementation. I want to migrate into the nrfx driver. I found this migration guide but it's not clear to me. In the API reference of the PPI allocator there is no function for initialization. Should I use the legacy API nrf_drv_ppi_init()?

Also in the migration guide, there is the following note that I do not understand.

Also, according to the following note should I keep both PPI_ENABLED and NRFX_PPI_ENABLED set to 1?

//==========================================================
// <e> NRFX_PPI_ENABLED - nrfx_ppi - PPI peripheral allocator
//==========================================================
#ifndef NRFX_PPI_ENABLED
#define NRFX_PPI_ENABLED 1
#endif

.....
....
..

// <e> PPI_ENABLED  - nrf_drv_ppi - PPI peripheral driver - legacy layer
#ifndef PPI_ENABLED
#define PPI_ENABLED 1
#endif

Parents
  • In the API reference of the PPI allocator there is no function for initialization. Should I use the legacy API nrf_drv_ppi_init()?

    No, there is no initialization/uninitialization functions in this API. You only need to allocate, assign, and enable a channel for it to work.

    Also, according to the following note should I keep both PPI_ENABLED and NRFX_PPI_ENABLED set to 1?

    Hmm, do you you currently have an issue with building the new PPI driver? I'd start by setting both to 1, and if that does not work, set PPI_ENABLED to 0. 

Reply
  • In the API reference of the PPI allocator there is no function for initialization. Should I use the legacy API nrf_drv_ppi_init()?

    No, there is no initialization/uninitialization functions in this API. You only need to allocate, assign, and enable a channel for it to work.

    Also, according to the following note should I keep both PPI_ENABLED and NRFX_PPI_ENABLED set to 1?

    Hmm, do you you currently have an issue with building the new PPI driver? I'd start by setting both to 1, and if that does not work, set PPI_ENABLED to 0. 

Children
  • Hi haakonsh,

    Thank you for your answer!!

    No, there is no initialization/uninitialization functions in this API. You only need to allocate, assign, and enable a channel for it to work.

    So this is enough? I comment out the nrf_drv_ppi_init() function. However, before commenting out it was working fine...

    static void ppi_init(void) {
    
      uint32_t err_code;
      uint32_t rtc_tick_event_addr;    // variable to hold the address of rtc event
      uint32_t saadc_sample_task_addr; // variable to hold the address of saadc task
    
      //err_code = nrf_drv_ppi_init(); // initialize the ppi module
      //APP_ERROR_CHECK(err_code);
    
      err_code = nrfx_ppi_channel_alloc(&m_ppi_channel); // allocate the channel. This function checks for the available channels and automatically allocates the channel
      APP_ERROR_CHECK(err_code);
    
      rtc_tick_event_addr = nrfx_rtc_event_address_get(&rtc, NRF_RTC_EVENT_TICK); // get the RTC event address
      saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();                   // get the saadc task address
    
      err_code = nrfx_ppi_channel_assign(m_ppi_channel, rtc_tick_event_addr, saadc_sample_task_addr); // Assing event and task endpoints to the PPI channel
      APP_ERROR_CHECK(err_code);
    
      err_code = nrfx_ppi_channel_enable(m_ppi_channel); // Enable the PPI channel
      APP_ERROR_CHECK(err_code);
    }

    Hmm, do you you currently have an issue with building the new PPI driver? I'd start by setting both to 1, and if that does not work, set PPI_ENABLED to 0. 

    If I set both to 1 it compiles fine. If I set PPI_ENABLED to 0 it cannot find the nrfx based functions. So, I guess every time I use the new implementation (nrfx drivers) I have to enable the legacy as well?

  • Nikosant03 said:
    If I set both to 1 it compiles fine. If I set PPI_ENABLED to 0 it cannot find the nrfx based functions. So, I guess every time I use the new implementation (nrfx drivers) I have to enable the legacy as well?

    Yes, that's what I've experienced at least. 

    Nikosant03 said:
    However, before commenting out it was working fine...

    All you did was to initialize the old driver without actually using it. So some RAM and flash is wasted, but it should not break anything i think. 

Related