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.

Semaphore_pend issue: HTTP Client Library

Other Parts Discussed in Thread: CC3200

Problem:

I am getting the following error on a CC3200 application using TI-RTOS and the HTTP Client Library.

Semaphore: line 207: assertion failure: A_badContext: bad calling context. Must be called from a Task.

This happens when a Semaphore_pend occurs. I know that Semaphore_pend must take place within a Task and not HWI or SWI. So perhaps this is related to the issue. Note: I am not creating the Semaphore_pend, this is being performed by the SimpleLink driver.

My application has a handler which is initiated when I press button, it then established a secure TLS connection, performs a HTTP GET and then a HTTP POST which then sends an SMS message.

Everything works perfectly on the first press, but on the second press of the button I get the crash as described above on the HTTP POST. (I do not believe this has anything to do with the button, as further tests that remove this do not change the result)

Additional Details:

Versions being used:
CC3200 SDK v1.1
TI-RTOS SimpleLink v2.13.01.09
XDC Tools v3.31.01.33

I have tried both the MIN and the FULL version of the HTTP Client Library, they get the same issue. 

I did need to make a change to the the httpcli.c and increase the size of all configurable lengths.

Questions:

What could be the cause? What do I need to keep an eye on?

Has there been a recent test of the HTTP Client Library using HTTP POST, TLS 1.2 and TI-RTOS. where more than one HTTP POST is sent?

Thanks!

Glenn.

  • Hi Glenn,

    Seems like somewhere semaphore API called in non-task context. Can you please share changes you made.

    Regards,

    Aashish

  • Hi Aashish,

    Thanks for looking into this.

    I have created two different application both have issues.

    Application 1:

    I started with the email application from the SDK and then added the HTTP Client Library, this application returns the error described above. 

    Application 2:

    I started with the GPIO Interrupt application that comes with the TI-RTOS for SimpleLink examples (available from within CCS). I then added the HTTP Client Library. This does not return an error, but it hangs at the stage the second HTTP POST is performed.

    Other Changes

    I need to update the configurable length in the httpcli.c file as below.

    /* Configurable lengths */
    #define CONTENT_BUFLEN 256
    #define URI_BUFLEN 256
    #define SEND_BUFLEN 256
    #define MAX_FIELD_NAME_LEN 24

    Rebuilt this webclient.a for both the full and min versions. 

    Code

    I have attached Application 1. I needed to change the service URLs that I am using, as these contain security keys for the REST APIs. But you should be able to see the code, and set up testing if needed.

    TestSMSDoorBell.zip

    Please let me know if you have any questions.

    Glenn.

  • Hi Glenn,


    Please review below lines of code in HTTPPostMethod that causing memory corruption:
    static char bearerToken[36] = "";
    strcat(bearerToken, "Bearer ");
    strcat(bearerToken, (const char *)accessToken);
    strcat(bearerToken, "\0");


    After 2-3 rd iteration bearerToken try to accessing 37th byte where as allocated 36. If we comment above mention line everything work fine.



    Regards,
    Aashish

  • Hi Aashish,

    Thank you so much for spotting this bug in my code! The error message sent me in a completely wrong direction.

    Here is the fix:

    static char bearerToken[50];

    for (i = 0; i < 50; i++)
    bearerToken[i] = 0x00;

    strcat(bearerToken, "Bearer ");
    strcat(bearerToken, (const char *)accessToken);
    strcat(bearerToken, "\0");

    For others trouble shooting these sorts of issues, I recommend you see how things look when just using HTTP, you can use a service like RequestBin to see the what the server receives. If I did this, I would have seen that the Authorization Header was growing. Of course you can also step through the code and view contents of variables.

    Glenn.