Using PPI trace with Timer0

Hi,

I tried to implement PPI for a very timing sensitive application. The sample PPI_trace uses the RTC but it is too slow for my application so I'd want ot use timer0 but it seems its instances are in nrfx dependencies. Is there a clean way to use it ?

Best reagrds,

Charles

  • Hey,

    Really sorry for the late response. 

    c.tessierpiart said:
    ret = gpio_pin_configure_dt(&filtered_synchro  , GPIO_INPUT | GPIO_INT_DEBOUNCE); 
    sends the application into hardfault.

    Could you tell me what it looks like when this happens.? Also, let me know how to reproduce the issue on my side.

    Regards,

    Swathy

  • Hi,

    It has been a while and I managed to make my IOs work. I just used DT_NODELABAL instead of DT_ALIAS, dont know why it works and at this point I am too afraid to ask.

    Meanwhile, I tried your suggestion but on my main application the counter start makes it restart and on the exemple that I modified, there is no more output signal.

    Here is the modified sample : 

    /*
     * Copyright (c) 2019 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    #include <zephyr.h>
    #include <debug/ppi_trace.h>
    #include <drivers/counter.h>
    #include <hal/nrf_rtc.h>
    #include <hal/nrf_clock.h>
    #include <device.h>
    #include <logging/log.h>
    #include "hal/nrf_timer.h"
    
    LOG_MODULE_REGISTER(app);
    
    #define ALARM_PERIOD_US 50000
    
    #if IS_ENABLED(CONFIG_USE_TIMER2)
    #define TIMER       NRF_TIMER2
    #define TIMER_LABEL DT_LABEL(DT_NODELABEL(timer2))
    #else
    #define TIMER       NRF_TIMER3
    #define TIMER_LABEL DT_LABEL(DT_NODELABEL(timer3))
    #endif
    
    static void alarm_callback(const struct device *dev, uint8_t chan_id, uint32_t ticks,
    			   void *user_data);
    
    static struct counter_alarm_cfg alarm_cfg = {
    	.callback = alarm_callback,
    	.flags = COUNTER_ALARM_CFG_ABSOLUTE,
    };
    
    static void ppi_trace_pin_setup(uint32_t pin, uint32_t evt)
    {
    	void *handle;
    
    	handle = ppi_trace_config(pin, evt);
    	__ASSERT(handle != NULL,
    		"Failed to initialize trace pin, no PPI or GPIOTE resources?");
    
    	ppi_trace_enable(handle);
    }
    
    static void ppi_trace_setup(void)
    {
    	ppi_trace_pin_setup(3,
    		nrf_timer_event_address_get(TIMER, NRF_TIMER_EVENT_COMPARE0));
    
    	LOG_INF("PPI trace setup done.");
    }
    
    static void alarm_callback(const struct device *dev, uint8_t chan_id,
    			   uint32_t ticks, void *user_data)
    {
    	int err;
    	uint32_t alarm_cnt = (uint32_t)user_data + 1;
    
    	alarm_cfg.ticks = ticks + counter_us_to_ticks(dev, ALARM_PERIOD_US);
    	alarm_cfg.user_data = (void *)alarm_cnt;
    
    	err = counter_set_channel_alarm(dev, 0, &alarm_cfg);
    	__ASSERT_NO_MSG(err == 0);
    	(void)err;
    }
    
    static void counter_setup(void)
    {
    	int err;
    	const struct device *dev = device_get_binding(TIMER_LABEL);
    
    	__ASSERT(dev, "Sample cannot run on this board.");
    
    	alarm_cfg.ticks = counter_us_to_ticks(dev, ALARM_PERIOD_US);
    	err = counter_set_channel_alarm(dev, 0, &alarm_cfg);
    	__ASSERT_NO_MSG(err == 0);
    
    	err = counter_start(dev);
    	__ASSERT_NO_MSG(err == 0);
    }
    
    void main(void)
    {
    	ppi_trace_setup();
    	counter_setup();
    }
    

    Note that, until I replaced the RTC and rtc reference with TIMER and timer references, it worked fine.

    Best regards, Charles

  • Hi,

    I was away on vacation and hence couldn't get back to you sooner.. I can see that you have managed to make the IO's work. What is the current update of this issue.?

    Regards,

    Swathy

Related