nrf54l15 pwm capture on sdk v3.3.1

I have a sensor that outputs PWM that I need to interface to. All I need is an input GPIO pin and using GPIOTE + GPPI + timer capture I would be able to determine the duty cycle ratio.

I found a sample program that gives me an idea on how to go about it. From its README: "Zephyr GPIO driver is disabled to prevent it from registering its own handler for the GPIOTE interrupt."  The driver is disable by placing "CONFIG_GPIO=n" in prj.conf. 

The thing is I do need the GPIO driver to be enabled for other functions. Can it be done with the GPIO driver enabled? Is there an example I could use? If not, documentation?

Thanks

Regards

Sammy

Parents
  • Hi,

    Yes, you've got it right with CONFIG_GPIO=y you should not call nrfx_gpiote_init() or IRQ_CONNECT, the Zephyr GPIO driver does that at boot. I think you also don't need any special accessor. Declaring the instance as you already do looks fine and using it directly without init, it automatically refers to the GPIOTE the GPIO driver set up. That part looks correct.

    To further check why CONFIG_GPIO=y fails, is it possible for you to share the log or error you are getting. Thanks.

    Best Regards,
    Syed Maysum

  • Hi Syed Maysum

    If it should automatically refer to the GPIOTE the GPIO driver set up - it doesn't. 

    I made it work by modifying to:

    const struct device *gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio1));
    
    static nrfx_timer_t timer = NRFX_TIMER_INSTANCE(NRF_TIMER20);
    static nrfx_gppi_t gppi;
    
    #ifndef CONFIG_GPIO
    static nrfx_gpiote_t gpiote_inst =  NRFX_GPIOTE_INSTANCE(NRF_GPIOTE20);
    static nrfx_gpiote_t *gpiote = &gpiote_inst;
    #else
    static nrfx_gpiote_t *gpiote;
    #endif

    and setup:

    #ifndef CONFIG_GPIO
       int err;
       IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE20)+1, IRQ_PRIO_LOWEST, nrfx_gpiote_irq_handler, gpiote, 0);
       err = nrfx_gpiote_init(gpiote, NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
       if (err != 0) {
          LOG_ERR("Failed to initialize GPIOTE driver: %x", err);
       }
    #else
       gpiote = gpio_nrf_gpiote_by_port_get(gpio_dev);
    #endif

    I found a function in the gpio driver that returns the gpiote instance. It is a bit of a hack..I am wondering if there is a better way to do it.

    Thanks

    Regards

    Sammy

Reply
  • Hi Syed Maysum

    If it should automatically refer to the GPIOTE the GPIO driver set up - it doesn't. 

    I made it work by modifying to:

    const struct device *gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio1));
    
    static nrfx_timer_t timer = NRFX_TIMER_INSTANCE(NRF_TIMER20);
    static nrfx_gppi_t gppi;
    
    #ifndef CONFIG_GPIO
    static nrfx_gpiote_t gpiote_inst =  NRFX_GPIOTE_INSTANCE(NRF_GPIOTE20);
    static nrfx_gpiote_t *gpiote = &gpiote_inst;
    #else
    static nrfx_gpiote_t *gpiote;
    #endif

    and setup:

    #ifndef CONFIG_GPIO
       int err;
       IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE20)+1, IRQ_PRIO_LOWEST, nrfx_gpiote_irq_handler, gpiote, 0);
       err = nrfx_gpiote_init(gpiote, NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
       if (err != 0) {
          LOG_ERR("Failed to initialize GPIOTE driver: %x", err);
       }
    #else
       gpiote = gpio_nrf_gpiote_by_port_get(gpio_dev);
    #endif

    I found a function in the gpio driver that returns the gpiote instance. It is a bit of a hack..I am wondering if there is a better way to do it.

    Thanks

    Regards

    Sammy

Children
No Data
Related