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.

MSP432E401Y: MSP432E401 UART HWI code example

Part Number: MSP432E401Y

Hello, i am trying to port my code from nortos to rtos, however i have not been able to find a good example for a uart interrupt driven for RTOS, my application expects asynchronous and unexpected communication thru serial ports, the communication protocol used is SECS/GEM (RS232) and HSMS on the other side (TCPIP), on SECS1/RS232 the size of the packets can go from 1 byte to 258.

my current solution works with interruptions, and background/foreground event driven style code, the processor is most of the time sleeping. processing data coming from the ports and putting it into circular buffers the interruptions handle the low level handshaking, and when a full package is received then it they post an event and awake the processor,

 

I need to move to RTOS because i want to keep it to one processor granted with the CC2XXBOOST for WiFi, or if anyone has an example of using WiFi witn NORTOS.

thanks.

  • Hello Luis,

    I will review this post and provide feedback tomorrow as today is a US holiday for our engineering team.

    Best Regards,

    Ralph Jacobi

  • Hi,

    I created a RS232-TCP/IP passthrough app on a MSP432E401 Launchpad dev kit. Once you are using an RTOS, you don't need to worry too much about UART interrupts - the device drivers take care of that.


    First, set up a UART in the gui:

    Config the UART. I did this in main, before starting the tasks. e.g.:

    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readTimeout = 10;

    /* Create a UART for the console */
    uart = UART_open(CONFIG_UART_0, &uartParams);
    if (uart == NULL)
    {
    while (1);
    }

    ti_ndk_config_Global_startupFxn();

    /* Start BIOS */
    BIOS_start();

    Then, create a task to read/write to the UART. I had a timeout so that I could check on the TCP/IP connection, but if you set no timeout, the task will block until there is something to read:

    char uartBuf[512];
    bool keepRunning = connectionIsGood(clientfd, &NoDataCount);
    Display_printf(display, 0, 0, "Initial Server link test result %d.", keepRunning);
    while(keepRunning)
    {
    /* Get any UART characters, with a timeout so we can keep an eye on the TCP connection. */
    int uartBytes = UART_read(uart, uartBuf, sizeof(uartBuf));
    if(uartBytes)
    {
    /* Forward the received characters. */
    // Display_printf(display, 0, 0, "Seen %d UART characters.", uartBytes);
    bytesSent = send(clientfd, uartBuf, uartBytes, 0);
    if (bytesSent < 0 || bytesSent != uartBytes)
    {
    Display_printf(display, 0, 0, "Send failed with %d.", bytesSent);
    keepRunning = false;
    }
    }
    else
    {
    keepRunning = connectionIsGood(clientfd, &NoDataCount);
    }
    }

    You might consider using UART2 (that is, the UART2 option on the GUI which means the advanced UART driver, not UART device number 2). This can use DMA for the transfer, so is probably more efficient Slight smile

    Hope that helps!

    Jim

  • Thanks Jim, are you familiar with SECS/GEM/HSMS protocols? the UART side of the controller needs to handshake with the equipment, then receive and verify the package then ir can forward that to the TCP socket,

    regards

  • Hi,

    Sorry, I don't know anything about those protocols.

    The TI RTOS and drivers will take care of the low level UART details for you. You don't need to worry about interrupt handling, but just consider buffers of data, so you should be able to build your message, send it, then try and read 258 bytes.

    You may want to set a timeout so that it comes back if the message is shorter, or perhaps you can read enough bytes for the reply header and work out how many more to expect after that.

    Beware! Both UARTs and TCP sockets offer blocking reads and writes, but there is a slight difference. If you read from a UART, it will bock until the requested number of characters have been received (or until a timeout, if set). A TCP socket read will deliver up to the requested number of bytes, but will return with fewer, if no more are available, even if no timeout has been set. 

    Sorry, don't know any more!

    Jim

  • Jim, again thanks for trying to help, i need what i asked on the header, i need a HWI example or an example of using the WiFi APIs without RTOS.

    Anyone from TI with expertise on that?

  • Hello Luis,

    After reviewing the resources I am aware of, I have not found any TI generated examples with UART using the HWI. Looking at the source code for the drivers, it is supported in the HWI, so it should be possible to configure it. Jim's given you a good start point, just would need to add what is needed to plug into HWI and then create the callback etc.

    Best Regards,

    Ralph Jacobi

  • Hi,

    I must admit, I am a little confused about why you need to be using HWI unless you have very precise timing requirements - which seems unlikely for serial comms Slight smile
    The RTOS takes care of that for you and hands you buffers of data when available. Your task can ask for as much data as it wants - one byte at a time if necessary. It will block until that data is available, which just means that the RTOS will give time to whatever other tasks you have created that need to be doing something else.

    It might be quite a design change from what you have so far!

    Jim