Attach interrupt to M4 core GPIO pin with FreeRTOS

Discussion in 'UDOO NEO' started by PaulR, Jan 14, 2018.

Tags:
  1. PaulR

    PaulR New Member

    Joined:
    Dec 12, 2017
    Messages:
    9
    Likes Received:
    0
    I'm trying to attach an interrupt to a GPIO pin, so it is fired when i press a button, which action is to toggle a LED. Code is run on my udo-neo-full M4 core

    In FreeRTOS you have to set a struct like this

    gpio_config_t gpioInput = {
    "INPUT_GPIO",
    &IOMUXC_SW_MUX_CTL_PAD_SD4_DATA0,
    5,
    &IOMUXC_SW_PAD_CTL_PAD_SD4_DATA0,
    IOMUXC_SW_PAD_CTL_PAD_SD4_DATA0_DSE(6)|
    IOMUXC_SW_PAD_CTL_PAD_SD4_DATA0_SPEED(2)|
    IOMUXC_SW_PAD_CTL_PAD_SD4_DATA0_PKE_MASK,
    GPIO6,
    14 //Pin 39 on J5​
    }
    #define BOARD_GPIO_INPUT (&gpioInput) //just a label

    and then I do:

    static void GPIO_Ctrl_InitInput()
    {
    // struct to describe pin
    gpio_init_config_t inputInit = {
    .pin = BOARD_GPIO_INPUT->pin,
    .direction = gpioDigitalInput,
    .interruptMode = gpioIntRisingEdge //gpioIntFallingEdge
    };
    // Use struct to set GPIO
    GPIO_Init(BOARD_GPIO_INPUT->base, &inputInit);
    GPIO_SetPinIntMode(BOARD_GPIO_INPUT->base, BOARD_GPIO_INPUT->pin, true);
    GPIO_SetIntEdgeSelect(BOARD_GPIO_INPUT->base, BOARD_GPIO_INPUT->pin, true);

    /* Set GPT interrupt priority 3 */
    NVIC_SetPriority(BOARD_GPIO_INPUT_IRQ_NUM, 3);
    NVIC_EnableIRQ(BOARD_GPIO_INPUT_IRQ_NUM);​
    }
    Now, in order to associate a handler to the interrupt, I think i must rewrite the GPIO handler that FreeRTOS has for this pin,which is by default a weak function so the linker uses my function instead of the default one (which is a trivial)(this is the only way i see to "attach" my function to a pin).
    For my GPIO pin, I think this should be GPIO6_Combined_0_15_Handler:

    void GPIO6_Combined_0_15_Handler(void)
    {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    /* Clear the interrupt state */
    GPIO_ClearStatusFlag(BOARD_GPIO_INPUT->base, BOARD_GPIO_INPUT->pin);

    bLedOn = true;

    /* Unlock the task to process the event. */
    xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
    /* Perform a context switch to wake the higher priority task. */
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);​
    }

    but I' m not sure if this handler is called when I press button, because LED does not change,and when I put a "printf" in the handler nothing is shown on UART2 (other messages appear.UART2 is connected to M4 core).Sometimes, it only prints something once,the first time I press the button. Then, never gets called again. Sometimes, nothing is print.

    Does somebody know how an interrupt is attached to a GPIO pin with udoo FreeRTOS?

    Thank you
     
    Last edited: Jan 14, 2018

Share This Page