Creating EGU init and handler

Hi, 

I am using nRF5340 with SDK v1.7.1.

Short question: I need to use the following features from PPI and DPPI respectively,

  • Associate one task or event with more than one channel.
  • Associate one channel with multiple tasks and multiple events.

I was told in a previous ticket that EGU would be the way to implement this, however, I am new to EGU and can find very few examples on how to implement it using both of these features. I do not want to call an interrupt, I just want to trigger EGU tasks from events or tasks from EGU events. 

Longer question:

Here are my other tickets:

 Allocating the SAADC to multiple DPPI channels   

 Implementing EGU with DPPI 

I would like to have four trigger channels which will excite the device at specific acquisition times and ADC will then sample on the rising and falling edges of the trigger. This is the current DPPI set up, Timer and GPIOTE work as expected but the SAADC only samples the last time it is called due to DPPI limitations. 

    NRF_TIMER1->PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;
	NRF_SAADC->SUBSCRIBE_SAMPLE = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;

	NRF_TIMER1->PUBLISH_COMPARE[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_1;
	NRF_GPIOTE->SUBSCRIBE_SET[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_1;
	NRF_SAADC->SUBSCRIBE_SAMPLE = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_1;

	NRF_TIMER1->PUBLISH_COMPARE[2] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_2;
	NRF_GPIOTE->SUBSCRIBE_CLR[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_2;
	NRF_SAADC->SUBSCRIBE_SAMPLE = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_2;
	
	NRF_TIMER1->PUBLISH_COMPARE[3] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_3;
	NRF_GPIOTE->SUBSCRIBE_SET[2] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_3;
	NRF_SAADC->SUBSCRIBE_SAMPLE = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_3;

	NRF_TIMER1->PUBLISH_COMPARE[4] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_4;
	NRF_GPIOTE->SUBSCRIBE_CLR[2] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_4;
	NRF_SAADC->SUBSCRIBE_SAMPLE = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_4;

	NRF_TIMER1->PUBLISH_COMPARE[5] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_5;

I was instructed to trigger SUBSCRIBE_TRIGGER[0-3] in the EGU, one on each channel. The EGU will then publish PUBLISH_TRIGGERED[0-3], which can all be set to channel 4.
Now, trigger SUBSCRIBE_SAMPLE on channel 4. Something like the following: 

    NRF_TIMER1->PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;
    
    NRF_TIMER1->PUBLISH_COMPARE[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;
    NRF_GPIOTE->SUBSCRIBE_OUT[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_0;
    NRF_EGU0->SUBSCRIBE_TRIGGER[0] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_0;

    NRF_TIMER1->PUBLISH_COMPARE[2] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_1;
    NRF_GPIOTE->SUBSCRIBE_OUT[1] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_1;
    NRF_EGU0->SUBSCRIBE_TRIGGER[1] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_1;

    NRF_TIMER1->PUBLISH_COMPARE[3] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_2;
    NRF_GPIOTE->SUBSCRIBE_OUT[2] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_2;
    NRF_EGU0->SUBSCRIBE_TRIGGER[2] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_2;

    NRF_TIMER1->PUBLISH_COMPARE[4] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_3;
    NRF_GPIOTE->SUBSCRIBE_OUT[2] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_3;
    NRF_EGU0->SUBSCRIBE_TRIGGER[3] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_3;

    NRF_EGU0->PUBLISH_TRIGGERED[0] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_4;
    NRF_EGU0->PUBLISH_TRIGGERED[1] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_4;
    NRF_EGU0->PUBLISH_TRIGGERED[2] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_4;
    NRF_EGU0->PUBLISH_TRIGGERED[3] = EGU_SUBSCRIBE_TRIGGER_EN_Msk | dppi_channel_4;
    NRF_SAADC->SUBSCRIBE_SAMPLE = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | dppi_channel_4;

The issue I am having is writing the nrfx_egu_init() function and EGU event handler as I cannot find any examples that use this syntax or that don't use interrupts.

Thank you!

  • Hi,

    If you only intend to use EGU together with DPPI to trigger tasks and subscribe to events, there should be no need to initialize the EGU driver or setup an event handler. This is primarily needed if you want to trigger a software interrupt based on a HW event, at a different priority than the peripheral's default priority, or from software.

    "Event generator unit (EGU) provides support for interlayer signaling. This means providing support for atomic triggering of both CPU execution and hardware tasks, from both firmware (by CPU) and hardware (by PPI). This feature can, for instance, be used for triggering CPU execution at a lower priority execution from a higher priority execution, or to handle a peripheral's interrupt service routine (ISR) execution at a lower priority for some of its events. However, triggering any priority from any priority is possible."

    Is the DPPI part not working as you expect with the code you have added?

    Best regards,
    Jørgen

Related