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/MSP432E401Y: tcp socket creation fails socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

Part Number: MSP432E401Y
Other Parts Discussed in Thread: CC3120, , MSP432E411Y

Tool/software: TI-RTOS

Hi,

I am trying to get a tcp client socket to communicate to a tcpserver.  I am using ti-rtos ndk configured via the XGCONF (rtsc project).  My .cfg contains the following NDK related info:


var Ndk = xdc.loadPackage('ti.ndk.config');
var Global = xdc.useModule('ti.ndk.config.Global');
var Ip = xdc.useModule('ti.ndk.config.Ip');
var Udp = xdc.useModule('ti.ndk.config.Udp');
var Tcp = xdc.useModule('ti.ndk.config.Tcp');

Global.IPv6 = false;
Global.stackLibType = Global.MIN;
Global.networkOpenHook = "&netOpenHook";
Global.networkIPAddrHook = "&netIPAddrHook";
Global.autoOpenCloseFD = true;

Global.pktNumFrameBufs = 10;
Global.memRawPageCount = 6;
Global.ndkThreadStackSize = 1536;
Global.lowTaskStackSize = 1536;
Global.normTaskStackSize = 1536;
Global.highTaskStackSize = 1536; 

---------------------------------------------------

The code compiles and links.  However, when I attempt to create the socket via the instruction clientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) the return value is always a -1.  fdError() also returns a negative one. 

Debugging indicates that the following code residing in unit slnetsock.c  function :  int16_t SlNetSock_create(int16_t domain, int16_t type, int16_t protocol, uint32_t ifBitmap, int16_t flags) fails at the line below:

/* Before creating a socket, check if there is a free place in the array */
    if ( retVal < SLNETERR_RET_CODE_OK )
    {
        /* There isn't a free space in the array, return error code          */
        return retVal;
    }

I am new to XGCONF and TI_RTOS, I am expecting that I have inadvertently left something out of my .cfg file?  I am trying to create the socket in a Task.

Thanks,

Any help would be appreciated

  • Hello,
    Have you had any success or tried to use any of the examples?

    dev.ti.com/.../

    dev.ti.com/.../

    Regards,
    Chris
  • Hello Manuel,

    I have noticed that you have posted another post on NDK and XGCONF here: e2e.ti.com/.../720129

    Is there a reason you want to use XGCONF?

    In the Simplelink MSP432E4 SDK, the XGCONF file is not used to configure NDK. Instead that configuration is included in the ndk_tirtos.c or ndk_freertos.c file. You can of-course use the XGCONF with NDK, but that's not the out of box solution provided.

    The Simplelink MSP432E4 SDK also provides a new Network Services (NS) library that encapsulates the NDK. All the example in this SDK (including the ones mentioned by Chris above) use NS layer. It provides the following two layers:
    * The SlNetSock layer allows applications to be ported between the CC3120 TCP/IP stack and the NDK. These APIs are under the block "SlNetSock (socket layer)". This API also allows using the TLS protocol.
    * The BSD sockets are an industry standard APIs that are built on top of the SlNetSock APIs. As the BSD sockets standard does not support TLS, these APIs don't support TLS. These APIs are under the block "BSD (Standard)".

    The error seems to indicate that the "socket" API is being used from the Network Services layer instead of from the NDK. Not sure if the Network Services layer has been initialized.

    My recommendation is to use the "tcpecho" example (link provided by Chris) as a starting point and then modify it to your needs.

    Thanks,
    Sai
  • Hello Manuel,

    I noticed that you have notified that the above post did not resolve you issue. Can you provide details?

    Did you try using the "tcpecho" example as a starting point? Or do you think this example does not work for you? Did you have any issue using that example?

    Are you using the XGCONF and ndk_<rtos>.c file together in the application? Since they perform the same functionality, you should use one or the other.

    Thanks,
    Sai
  • Thanks for the reply. I'm new to TI-RTOS/XGCONF. Most likely I do have sometype of configuration problem and/or I am misundertanding NDK.

    In my desired application I was planning on using mailboxes and semaphores to process messages received via a TCP connection along with performing other tasks (hwi/swi). Therefore, I thought I could/would use XGCONF to statically configure the mailboxes, semaphores and ethernet connection.

    I did successfully run the tcpecho example on my MSP432E401Y board. However, this example, I believe is a CSC based example as opposed to a RTSC example. As you indicated above, the tcpecho example utilizes the ndk_tirtos.c . For a RTSC project, I assumed by loading NDK by (var Ndk = xdc.loadPackage('ti.ndk.config')) and by using var Tcp = xdc.useModule('ti.ndk.config.Tcp') I was enabling my application cto create a TCP socket.

    My goal is to develope aTI RTOS application that utilizes an ethernet connection, mailboxes and semaphores to process received ethernet data and to monitor the status of external peripherals. Any further recommendations on setting up a network connection in an RTOS application would be appreciated.

    Lastly, I did find a similar post on the TI website related to the same problem I have encountered. The post is : RTOS/MSP432E411Y: socket() call failing with out-of-memory condition. Not sure if this was topic was ever reolved.

    Thanks,
    Manny
  • Hi,
    As indicated in a previous post I was successful in running the example tcpecho project. I decided to modify/expand the tcpecho project to an RTSC project which utilizes a NDK client socket that will connect to a remote server. I am using XGConf because my application will need to support semaphores , mailboxes, and tasks in addition to NDK.

    I may have resolved the socket create failure - I was including NDK and non NDK socket libraries in the same project - when I removed the NDK socket libraries includes the socket creation did pass. However, a call to NDK_connect call is now failing. I have not debugged the failure yet, I was wondering if the failure could be related to the connect call being implemented before the stack has obtained an IP address? My XGCONF includes GLOBAL, IP, TCP and the following hooks : Global.networkOpenHook = "&netOpenHook"; Global.networkIPAddrHook = "&netIPAddrHook".

    My questions are as follows:
    For a client TCP socket (not a server TCP socket), when would the netOpenHook and netIPAddrHook hooks be called? Does it make sense to perform the connection after the netIPAddrHook function is called? (Providing that it is called for a TCP Client). Using XGCONF IP setting, does it matter if the IP address is obtained statically or dynamically?

    Thanks for your pateince and time.

    Manny
  • Hello Manuel,

    You could potentially configure semaphores , mailboxes, and tasks using the C code. The SimpleLink MSP432E4 SDK has examples that show how to do this in the folder "./examples/rtos/MSP_EXP432E401Y". Most of the examples in this SDK use industry standard POSIX APIs which are built on top of the RTOS APIs.

    If you still want to use the XGCONF tool, can you please attach your project here so that we can take a look as to what might be causing the issue?

    Thanks,
    Sai
  • Hi,

    The "tcpecho" example did provide a good starting point. Unlike the tcpecho example, I needed to incorporate a NDK TCP client socket to connect to a server socket and to respond to received messages. Also, my application required that status be sent to the server on a periodic basis (unsolicited).

    I was able to configure the NDK socket in the config.cfg as follows (just a snippet of my existing .cfg file :


    /* ================ Clock configuration ================ */


    /*=================================================================*/
    var Ndk = xdc.loadPackage('ti.ndk.config');
    var Global = xdc.useModule('ti.ndk.config.Global');
    var Ip = xdc.useModule('ti.ndk.config.Ip');
    var Udp = xdc.useModule('ti.ndk.config.Udp');
    var Tcp = xdc.useModule('ti.ndk.config.Tcp');
    Tcp.transmitBufSize = 2048; // remove
    Tcp.receiveBufSize = 2048;

    Global.IPv6 = false;
    Global.stackLibType = Global.MIN;
    Global.networkOpenHook = "&netOpenHook";
    Global.networkIPAddrHook = "&netIPAddrHook"; // ***************** IMPORTANT*********************

    /* automatically call fdOpen/CloseSession for our sockets Task */
    Global.autoOpenCloseFD = true;

    Global.pktNumFrameBufs = 10;
    Global.memRawPageCount = 6;
    Global.ndkThreadStackSize = 1536;
    Global.lowTaskStackSize = 1536;
    Global.normTaskStackSize = 1536;
    Global.highTaskStackSize = 1536;
    /*=================================================================*/


    Within a Task, I was able to create the NDK tcp client socket and to connect to a remote server. ( The Task was created within the netIpAddrHook function identified in the .cfg file - this was key).

    clientSocket = NDK_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    connectStatus =
    NDK_connect(clientSocket, (struct sockaddr *)&serverAddr,
    sizeof(serverAddr));

    In retrospect, the tcpEcho example and the NDK API Guide provided sufficient information to get me past the communication issues.

    Thanks for all your help and patience.

**Attention** This is a public forum