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.

RTOS/MSP-EXP432E401Y: RTOS crashes wenn Task is not created at runtime

Part Number: MSP-EXP432E401Y

Tool/software: TI-RTOS

Hello,

if my httpTaskFxn is created with

   taskHandle = TaskCreate(httpTaskFxn, NULL, 1, HTTPTASKSTACKSIZE, 0,
                0, 0);

from the netIPAddrHook() callback function everything works normal.

If i try to construct the Task this way...

// main.c

// HTTP Task
#define HTTP_STACKSIZE   4096
extern void httpTaskFxn(UArg arg0, UArg arg1);
Task_Struct httpTaskStruct;
char httpTaskStack[HTTP_STACKSIZE];

int main (void) {
...
    Task_Params_init(&httpTaskParams);
    httpTaskParams.stackSize = HTTP_STACKSIZE;
    httpTaskParams.stack = &httpTaskStack;
    httpTaskParams.priority = 3;
    Task_construct(&httpTaskStruct, (Task_FuncPtr)httpTaskFxn, &httpTaskParams, NULL);
...
}

It stops here:

void httpTaskFxn(uint32_t arg0, uint32_t arg1)
{

    ret = HTTPCli_connect(&cli, (struct sockaddr *)&addr, 0, NULL);   // crashes at this line
    if (ret < 0) {
        printError("httpTask: connect failed", ret);
    }


}

/*
 *  ======== Hwi_excHandler ========
 */
Void Hwi_excHandler(UInt *excStack, UInt lr)
{
    Hwi_module->excActive[0] = TRUE;

    /* spin here if no exception handler is plugged */
    while (Hwi_excHandlerFunc == NULL) {
	;
    }

    Hwi_excHandlerFunc(excStack, lr);
}

Is it not allowed to start this function with Task_construct() ?

  • Hello Simon,

    Which software are you using? If you are using SimpleLink MSP432E4 SDK, is there a reason you are not using POSIX APIs as the examples demonstrate?

    From the code you have provided, I don't see any APIs being called to initialize the TCP/IP Stack before the HTTPCli_connect is being called

    If you want to call the HTTP Task before netIPAddrHook is called, then you also need to make sure that the HTTPCli_connect is called only after IP address is acquired.

    Please refer the httpget example (./examples/rtos/MSP_EXP432E401Y/ns/httpget/) provided in the latest SimpleLink MSP432E4 SDK that can be found here: www.ti.com/.../SIMPLELINK-MSP432-SDK

    Thanks,
    Sai

  • Hi,

    i tried with Task_sleep and also lock the httpTaskFxn() until the network is up.

    the problem is only how i start this task.

    Example:

    If i comment out these lines, everything works as expected.

    /*
    Task_Params_init(&httpTaskParams);
    httpTaskParams.stackSize = HTTP_STACKSIZE;
    httpTaskParams.stack = &httpTaskStack;
    httpTaskParams.priority = 3;
    Task_construct(&httpTaskStruct, (Task_FuncPtr)httpTaskFxn, &httpTaskParams, NULL);
    */

    if i comment out the lines below, to use the Task_construct function, i get errors.

    taskHandle = TaskCreate(httpTaskFxn, NULL, 1, HTTP_STACKSIZE, 0, 0, 0);
    if (!taskHandle) {
    // netOpenHook: Failed to create httpTask thread
    Display_printf(display, 0, 0, "Failed to create httpTask thread");
    while(1);
    }
  • Hello Simon,

    As mentioned in my previous post, the APIs you are using are different from the examples provided in the SimpleLink MSP432E4 SDK.

    Can you answer some of the questions I asked in the previous post? I hope that they will help us understand your starting point and can try to help.

    I found the following e2e post that talks about the difference between task_create() and task_construct(). Hopefully that fixes your issue.
    e2e.ti.com/.../529453

    Please let us know why you want to create the HTTP Task outside of the netIPAddrHook?

    Thanks,
    Sai
  • I want to create all tasks, and later i decide which one should run.

    I cant get the point whats wrong with the API i use?

    I create 3 Tasks, two of them working perfectly well, so there must be something wrong with the third task.

    // MBus Task
    #define MBUS_STACKSIZE   512
    extern void mbusTaskFxn(UArg arg0, UArg arg1);
    Task_Struct mbusTaskStruct;
    char mbusTaskStack[MBUS_STACKSIZE];
    
    // Worker Task
    #define WORKER_STACKSIZE   512
    extern void workerTaskFxn(UArg arg0, UArg arg1);
    Task_Struct workerTaskStruct;
    char workerTaskStack[WORKER_STACKSIZE];
    
    
    // HTTP Task
    #define HTTP_STACKSIZE   4096
    extern void httpTaskFxn(UArg arg0, UArg arg1);
    Task_Struct httpTaskStruct;
    char httpTaskStack[HTTP_STACKSIZE];
    
    
        Task_Params mbusTaskParams;
        Task_Params workerTaskParams;
        Task_Params httpTaskParams;
    
    
    
    // Task 1, works !
        Task_Params_init(&workerTaskParams);
        workerTaskParams.stackSize = WORKER_STACKSIZE;
        workerTaskParams.stack = &workerTaskStack;
        workerTaskParams.priority = 2;
        Task_construct(&workerTaskStruct, (Task_FuncPtr)workerTaskFxn, &workerTaskParams, NULL);
    
    // Task 2, works !
        /* Construct writer/reader Task threads */
        Task_Params_init(&mbusTaskParams);
        mbusTaskParams.stackSize = MBUS_STACKSIZE;
        mbusTaskParams.stack = &mbusTaskStack;
        mbusTaskParams.priority = 1;
        Task_construct(&mbusTaskStruct, (Task_FuncPtr)mbusTaskFxn, &mbusTaskParams, NULL);
    
       
    // Task 3, does not work, and crashes the RTOS
        Task_Params_init(&httpTaskParams);
        httpTaskParams.stackSize = HTTP_STACKSIZE;
        httpTaskParams.stack = &httpTaskStack;
        httpTaskParams.priority = 3;
        Task_construct(&httpTaskStruct, (Task_FuncPtr)httpTaskFxn, &httpTaskParams, NULL);
    

    // The HTTP Task function, contains a 10 seconds sleep, this is more then enough to obtain an IP address.
    
    
    void httpTaskFxn(uint32_t arg0, uint32_t arg1)
    {
        bool moreFlag = false;
        char data[64];
        int ret;
        int len;
        struct sockaddr_in addr;
    
    
        Task_sleep(10000);
        Display_printf(display, 0, 0, "HTTPTask");
    
    
    
        HTTPCli_Struct cli;
        HTTPCli_Field fields[5] = {
            { FIELD_NAME_HOST, HOSTNAME },
            { FIELD_NAME_USER_AGENT, USER_AGENT },
            { FIELD_NAME_CONTENT_TYPE, CONTENT_TYPE},
            { FIELD_NAME_CONTENT_LENGTH, "10"},
            { NULL, NULL }
        };
    
        Display_printf(display, 0, 0, "Sending a HTTP GET request to '%s'\n",
                HOSTNAME);
    
        HTTPCli_construct(&cli);
    
        HTTPCli_setRequestFields(&cli, fields);
    
        ret = HTTPCli_initSockAddr((struct sockaddr *)&addr, HOSTNAME, 0);
        if (ret < 0) {
            printError("httpTask: address resolution failed", ret);
        }
    
        ret = HTTPCli_connect(&cli, (struct sockaddr *)&addr, 0, NULL);
        if (ret < 0) {
            printError("httpTask: connect failed", ret);
        }
    
        ret = HTTPCli_sendRequest(&cli, POST, REQUEST_URI, false);
        if (ret < 0) {
            printError("httpTask: send failed", ret);
        }
    
        memset(data, 'A',sizeof(data));
        HTTPCli_sendBinaryData(&cli, (uint8_t *) &data, sizeof(data));
    
    
        ret = HTTPCli_getResponseStatus(&cli);
        if (ret != HTTP_OK) {
            printError("httpTask: cannot get status", ret);
        }
    
        Display_printf(display, 0, 0, "HTTP Response Status Code: %d\n", ret);
    
        ret = HTTPCli_getResponseField(&cli, data, sizeof(data), &moreFlag);
         if (ret != HTTPCli_FIELD_ID_END) {
               printError("httpTask: response field processing failed", ret);
         }
    
    
        len = 0;
        do {
            ret = HTTPCli_readResponseBody(&cli, data, sizeof(data), &moreFlag);
            if (ret < 0) {
                printError("httpTask: response body processing failed", ret);
            } else {
                Display_printf(display, 0, 0, "%s", data);
            }
    
            len += ret;
        } while (moreFlag);
    
        Display_printf(display, 0, 0, "Received %d bytes of payload\n", len);
    
    
        HTTPCli_disconnect(&cli);
        HTTPCli_destruct(&cli);
    
    }

  • Hi Simon,

    It looks like you are using two different priotities when creating your task which could cause your code to execute on a different order. Try changing:

    httpTaskParams.priority = 1;

    So that both methods of creating the Task give it the same priority.

    Thanks,
    Gerardo

**Attention** This is a public forum