This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-AM243: GPIO interrupts and drivers not working with FREERTOS tasks

Part Number: LP-AM243
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hi guys i was trying to use GPIO ISR with xTaskResumeFromISR( TaskHandle_t xTaskToResume )   and i get again no errors from compiler but by program halts at Drivers_open();

#include <stdlib.h>
#include <kernel/dpl/DebugP.h>
#include "ti_drivers_config.h"
#include "ti_board_config.h"
#include "FreeRTOS.h"
#include "task.h"
#include "ti_drivers_open_close.h"
#include "ti_board_open_close.h"
#include <stdio.h>

#define MAIN_TASK_SIZE (16384U/sizeof(configSTACK_DEPTH_TYPE))
void buttonisr(void *args);
TaskHandle_t gMainTask=NULL;
TaskHandle_t gTask1=NULL;
static HwiP_Object buttonobj;
uint32_t gpioBaseAddr,cnt=0;


void maintask(void *args)
{

while(1)
{ vTaskSuspend(NULL);
DebugP_log("button pressed\r\n");
vTaskResume(gTask1);
}

}


void button_innit(){

Drivers_open();
DebugP_log("Start 14 !!\r\n");
Board_driversOpen();
HwiP_Params button;
int32_t pinNum,intrNum;
uint32_t stat;
gpioBaseAddr = (uint32_t) AddrTranslateP_getLocalAddr(BUTTON_BASE_ADDR);
pinNum = BUTTON_PIN;
intrNum = BUTTON_INTR_NUM;
DebugP_log("Start 2 !!\r\n");


HwiP_Params_init(&button);
button.intNum = intrNum;
button.callback = &buttonisr;
button.args = (void*) pinNum;
button.isPulse = TRUE;
stat = HwiP_construct(&buttonobj, &button);
DebugP_assert(stat == SystemP_SUCCESS );
DebugP_log("Register pin interrupt parameters done !!\r\n");

}

void task1(void *p)
{

while(1)
{
DebugP_log("button Task running!! %d\r\n",cnt);

}
}

void buttonisr(void *args)
{
uint32_t pinNum = (uint32_t) args;
uint32_t bankNum = GPIO_GET_BANK_INDEX(pinNum);
uint32_t intrStatus, pinMask = GPIO_GET_BANK_BIT_MASK(pinNum);
int32_t stat;

intrStatus = GPIO_getBankIntrStatus(gpioBaseAddr, bankNum);
GPIO_clearBankIntrStatus(gpioBaseAddr, bankNum, intrStatus);

if(intrStatus & pinMask)
{
cnt = GPIO_pinRead(gpioBaseAddr, pinNum);


BaseType_t check;
check = xTaskResumeFromISR(gMainTask);
portYIELD_FROM_ISR(check); // from portmacro.h

}

}


int main(void)
{

DebugP_log("Start 11 !!\r\n");
System_init();
DebugP_log("Start 12 !!\r\n");
Board_init();
DebugP_log("Start 13 !!\r\n");


button_innit();
xTaskCreate( maintask,"task0",MAIN_TASK_SIZE,NULL,tskIDLE_PRIORITY,&gMainTask );
xTaskCreate( task1,"task1",MAIN_TASK_SIZE,NULL,configMAX_PRIORITIES-1,&gTask1 );


vTaskStartScheduler();

DebugP_assertNoLog(0);
Board_driversClose();
Drivers_close();

return 0;
}

my program output : Start 11 !!
                                  Start 12 !!
                                   Start 13 !!

  • Hi Aditya,

    Thanks for your question.

    Please expect delayed responses as the assigned expert is out of office until early next week.

    Regards,

    Vaibhav

  • Hi Aditya,

    Thanks for your patience.

    This is the expected behavior. The issue is with the DebugP_log() API.

    As you can see the button_innit() function is going to call the Drivers_uartOpen() API which will open enable UART driver for output logs.

    The UART driver is using Semaphores, that will not work until the scheduler is started.

    You can use the DebugP_log() API once the scheduler is started.

    Hope the above information helps.

    Regards,

    Tushar

  • I replaced all debugp_log() with printf and moved the buttoninit() below vTaskStartScheduler(); but still my program doesnt seem to work or show any output.

  • Hi Aditya,

    I replaced all debugp_log() with printf and moved the buttoninit() below vTaskStartScheduler(); but still my program doesnt seem to work or show any output.

    The code will never return from the vTaskStartScheduler() API so the statement after API call will not be executed, that's why you are not able to see any output.

    Please refer below screenshot

    Hope the above information helps.

    Regards,

    Tushar

  • Thank you for your prompt reply, I did the following improvement in the code.

    #include <stdlib.h>
    #include <kernel/dpl/DebugP.h>
    #include "ti_drivers_config.h"
    #include "ti_board_config.h"
    #include "FreeRTOS.h"
    #include "task.h"
    #include "ti_drivers_open_close.h"
    #include "ti_board_open_close.h"
    #include <stdio.h>

    #define MAIN_TASK_SIZE (16384U/sizeof(configSTACK_DEPTH_TYPE))
    void buttonisr(void *args);
    TaskHandle_t gMainTask = NULL;
    TaskHandle_t gTask1 = NULL;
    static HwiP_Object buttonobj;
    uint32_t gpioBaseAddr, cnt = 0;

    void maintask(void *args)
    {

    while (1)
    {
    vTaskSuspend(NULL);
    printf("button pressed\r\n");
    vTaskResume(gTask1);
    }

    }

    void button_innit()
    {
    Drivers_open();
    Board_driversOpen();

    HwiP_Params button;
    int32_t pinNum, intrNum;
    uint32_t stat;
    gpioBaseAddr = (uint32_t) AddrTranslateP_getLocalAddr(BUTTON_BASE_ADDR);
    pinNum = BUTTON_PIN;
    intrNum = BUTTON_INTR_NUM;
    printf("Start 2 !!\r\n");

    HwiP_Params_init(&button);
    button.intNum = intrNum;
    button.callback = &buttonisr;
    button.args = (void*) pinNum;
    button.isPulse = TRUE;
    stat = HwiP_construct(&buttonobj, &button);
    DebugP_assert(stat == SystemP_SUCCESS);
    printf("Register pin interrupt parameters done !!\r\n");

    }

    void task1(void *p)
    {

    while (1)
    {
    printf("button Task running!! %d\r\n", cnt);

    }
    }

    void buttonisr(void *args)
    {
    uint32_t pinNum = (uint32_t) args;
    uint32_t bankNum = GPIO_GET_BANK_INDEX(pinNum);
    uint32_t intrStatus, pinMask = GPIO_GET_BANK_BIT_MASK(pinNum);


    intrStatus = GPIO_getBankIntrStatus(gpioBaseAddr, bankNum);
    GPIO_clearBankIntrStatus(gpioBaseAddr, bankNum, intrStatus);

    BaseType_t check;
    check = xTaskResumeFromISR(gMainTask);
    portYIELD_FROM_ISR(check); // from portmacro.h

    if (intrStatus & pinMask)
    {
    cnt += 1;


    }

    }

    int main(void)
    {


    System_init();

    Board_init();

    printf("Start 11 !!\r\n");

    xTaskCreate(maintask, "task0", 200, NULL, tskIDLE_PRIORITY+1,
    &gMainTask);
    printf("Start 11.5 !!\r\n");
    xTaskCreate(task1, "task1", 200, NULL, tskIDLE_PRIORITY,
    &gTask1);

    portENABLE_INTERRUPTS();
    button_innit();
    vTaskStartScheduler();


    DebugP_assertNoLog(0);
    Board_driversClose();
    Drivers_close();

    return 0;
    }

    now the output :

    Start 11 !!
    Start 11.5 !!
    Start 2 !!
    Register pin interrupt parameters done !!
    button Task running!! 0
    button Task running!! 0
    button Task running!! 0
    button Task running!! 0

    goes on 

  • Hi Aditya,

    Thanks for your response.

    From the above logs it looks like that the print statement are working fine and the issue has been resolved. 

    Can you please close the thread if original query has been answered.

    Regards,

    Tushar

  • i am still not able to trigger HW interrupts with FREERTOSTasks, which is part of my original query

  • Hi Aditya,

    I have checked the above code. I can see that you are not calling Board_gpioInit() API anywhere in the code.

    Can you please replace the button_innit() function with the below code and try again?

    Please find below code.

    void button_innit()
    {
        Drivers_open();
        Board_driversOpen();
        Board_gpioInit();
    
    
        HwiP_Params button;
        int32_t pinNum, intrNum;
        uint32_t stat;
        gpioBaseAddr = (uint32_t) AddrTranslateP_getLocalAddr(BUTTON_BASE_ADDR);
        pinNum = BUTTON_PIN;
        intrNum = BUTTON_INTR_NUM;
        printf("Start 2 !!\r\n");
    
        HwiP_Params_init(&button);
        button.intNum = intrNum;
        button.callback = &buttonisr;
        button.args = (void*) pinNum;
        button.isPulse = TRUE;
        stat = HwiP_construct(&buttonobj, &button);
        DebugP_assert(stat == SystemP_SUCCESS);
        printf("Register pin interrupt parameters done !!\r\n");
    
    }

    After implementing the above change you would be able to get an interrupt.

    Regards,

    Tushar

  • Thank you Tushar for the Help, But after doing that i still dont have the output , interrupt is somehow not triggered. I checked all my configuration in sysconfig and physical connection. The GPIO interrupt works independently when nortos is used.

  • Hi Aditya,

    I have tried the above code at my end and it is working fine.

    I am attaching the project below. 

    Project - gpio_input_interrupt

    Please try the above project and let us know the results.

    Regards,

    Tushar

  • Hi Tushar,

    Thank you for your effort , i will try the above project with fresh installation of CCS environment. 

    Kind regards,

    Aditya

  • Hi Aditya,

    Thanks for your response.

    We look forward to hear from you. Please let us know if you face any difficulty.

    Regards,

    Tushar