AnsweredAssumed Answered

IMX8MMini, Cortex-M4 and xTaskResumeFromISR()

Question asked by Sergei Poselenov on Aug 2, 2019
Latest reply on Aug 8, 2019 by Sergei Poselenov

Hello,

I'm trying to run a canonical example of the sleep/wakeup using vTaskSuspend()/xTaskResumefromISR() FreeRTOS - A FREE RTOS for small real time embedded systems using FreeRTOS from the SDK 2.6.0 for IMX8M Mini. I configured a button on my board to generate interrupts and it works in my example.

I cannot make xTaskResumeFromISR() from the GPIO interrupt handler to wake up a task sleeping on vTaskSuspend(). As soon xTaskResumeFromISR() executes, the program just hangs and doesn't react to interrupts anymore.

 

Could please someone suggests what I am missing? Here is my code:

...
typedef unsigned int pin_t;
#define GPIO(port, pin) (( port ) << 5) | (( pin ) & 0x1F)
#define PORT(gpio) (( gpio ) >> 5)
#define PIN(gpio) (( gpio ) & 0x1F)

extern TaskHandle_t ps2_task_handle;

static GPIO_Type *const gpioBases[] = GPIO_BASE_PTRS;

pin_t gpio_irq = GPIO(4, 28); //btn1


void GPIO_irq_handler(void)
{
GPIO_Type * irqbase = gpioBases[PORT(gpio_irq)];

GPIO_ClearPinsInterruptFlags(irqbase, 1 << PIN(gpio_irq));
// GPIO_PortDisableInterrupts(irqbase, 1 << PIN(gpio_irq));
PRINTF("Got irq, wake up the task\n\r");
xTaskResumeFromISR (ps2_task_handle);
PRINTF("irq:OK\n\r");
}

void GPIO4_Combined_16_31_IRQHandler(void)
{
GPIO_irq_handler();
}


void ps2_task(void *param)
{
uint32_t irq;
GPIO_Type * base = gpioBases[PORT(gpio_irq)];
gpio_pin_config_t gpio_input = {kGPIO_DigitalInput, 0, kGPIO_NoIntmode};


irq = GPIO1_Combined_0_15_IRQn + ((PORT(gpio_irq) - 1) * 2 + PIN(gpio_irq)/16);
PRINTF("PS/2 Task started on irq %d\n\r", irq);
GPIO_PinInit(gpioBases[PORT(gpio_irq)], PIN(gpio_irq), &gpio_input);

EnableIRQ(irq);

GPIO_PinSetInterruptConfig(base, PIN(gpio_irq), kGPIO_IntFallingEdge);
GPIO_PortDisableInterrupts(base, -1);
GPIO_PortClearInterruptFlags(base, -1);
GPIO_PortEnableInterrupts(base, 1 << PIN(gpio_irq));

while (1) {
PRINTF("ps2: go to suspend\n\r");
vTaskSuspend (NULL);
PRINTF("ps: woke up!\n\r");
}
}

With code above, I'm getting:

PS/2 Task started on irq 71
ps2: go to suspend
Got irq, wake up the task

Outcomes