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

nRF52840-DK GPIOTE with FreeRTOS Tasks

Hi all,

I am trying to generally gain a better understanding of the GPIOTE module and how it can benefit myself in the project I am working on.

I am essentially attempting to leverage the functionality of FreeRTOS Tasks, whilst also using GPIOTE.

What I am trying to achieve is using 1 GPIO for sending data, another GPIO for receiving data and using the FreeRTOS Tasks to carry out some processing of said data.

My idea was to send the board in to low-power or standby mode, and use the GPIOTE module to trigger the event handlers that I pass, which will simply resume the FreeRTOS task that corresponds to said GPIO activity.

Example

GPIO 1 receives signal state change -> event handler triggered -> FreeRTOS task resumed -> FreeRTOS task carries out processing -> FreeRTOS suspends itself when there's no more processing required.

GPIO 2 needs to send data and causes a change -> event handler triggered -> FreeRTOS task resumed -> FreeRTOS task carries out processing -> FreeRTOS suspends itself when there's no more processing required.

When tasks are suspended, I wish to go to low power and rely on an interrupt, let's say motion sensor or any other trivial example, which can also ideally be triggered by a GPIOTE event. 

My questions would be:

1. Is this the most appropriate way of handling such a task? 

2. Is this possible, and if so, is there supporting documentation that is up to date? The website appears to be littered with old examples.

3. Are there any hiccups I ought to be aware of in attempting to approach the project in this way?

Thanks,

mpw

  • Hi mpw,

    What you are trying to achieve is quite simple using GPIOTE interrupts and FreeRTOS task notifications.

    There are no direct examples of what you wanted to do, but configuring the GPIOTE to generate the interrupt with state changes on the pin you want and controlling which task to resume using the task notification is quite straightforward thing to do. 

  • Thank you, Susheel. 

    I have spent a few days and I still don't feel I understand GPIOTE any better with the documentation available for the SDK 16.0.

    It has notes on the documentation saying to use the legacy layer, but then proceeds to say to use GPIOTE registration and initialise the module with:

    APP_GPIOTE_INIT(MAX_USERS);

    What I am trying to achieve seems simple conceptually, but I wish to use the SDK correctly for future compatibility. 

    I want to register 1 pin for a transition from HIGH to LOW, then when that takes place I want a handler to be called and clear the interrupt (this is hard to find, too, is it handled automatically?), do some processing/raise a flag, then exit the handler. 

    The examples in the SDK don't make use of registration or anything of that sort and most of the handlers in the examples are using dummy handlers.

    What is the correct way to use the GPIOTE module for simply initialisation, setting a config for high to low, passing a handler to GPIOTE module for callback, and then clearing that interrupt when inside the handler? It seems like a very powerful feature to have that I want to utilise properly.

    Thanks,

    Michael

  • An example on how to register for GPIOTE IN event with an event handler is shown in a very simple and clean way in nRF5_SDK_16.0.0_98a08e2/examples/peripheral/pin_change_int/main.c., this is exactly what you seek with GPIOTE as far as I understand.

    Connecting the above example to tasks notifications and event handlers is a very straight forward task. Please attempt to do a template of your work and we can discuss here more on the challenges you are facing once you started to merge GPIOTE and FreeRTOS task notifications.

Related