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/MSP432P401R: UART Callback on TI-RTOS

Part Number: MSP432P401R

Tool/software: TI-RTOS

Hello,

We are trying to implement uart callback function on MSP432P401R.

We set the parameters as described below,

uartParams.readMode = UART_MODE_CALLBACK;
uartParams.readCallback = (UART_Callback)UartReadCallback;
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
//uartParams.readTimeout = UART_WAIT_FOREVER;
uartParams.baudRate = 9600;

The callback function is described below,

void UartReadCallback(UART_Handle handle, void *rxbuf, size_t size){
charAvail=true;
System_printf("callback function\n");
System_flush();
}

The callback function is never called.

How to implement uart callback function ?

Is their any example code for uart callback function ?

  • Hi Nikitha,

    Which version of TI-RTOS are you using?

    Also, can you show us where you do your first UART_read(..)? You must perform a read for the callback to be called.

    If you want code examples, I suggest that you look into the Resource Explorer (under the View menu in CCS).

    It is also avaiable here:

    Regards,

    Michel

  • Hi  Michel,

    following TI-RTOS versions we are using:

    tirtos_tivac_2_16_00_08

    tirtos_tivac_2_16_01_14

    Here we are doing our 1st UART_read()

    UART_Handle uart;
    UART_Params uartParams;
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;
    uart = UART_open(Board_UART0, &uartParams);
    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    UART_read(uart, &input, 1);

    In resource explorer there is no examples for UART callback, it consist of 2 examples (Logging and echo).

    Regards,

    Nikitha

  • Hi Michel,

    This code we are using and the diagram below shows you where we use the first uart_read.

    In resource file explorer we couldn't   find the callback function for uart, it consist of uart logging and echo.

    Regards,

    Nikitha.

  • Hi Nikitha,

    You are correct, I checked and couldn't find any example code to use with callback mode.

    I think I am missing something:
    in the first code that you posted, you have the following line:
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = (UART_Callback)UartReadCallback;
    However, in your second piece of code, you do not set the mode or the callback function.

    Another thing: I do not see any call to UART_Init (UART_Handle handle) or Board_initUART();
    I believe that Board_initUART() simply calls UART_Init. If you can write to the UART, than it means that the init was already done.

    One last thing: you should have a variable of type UARTMSP432_HWAttrs in your project. Can you check and make sure that it is present and properly defined.



    Regards,
    Michel
  • Hi Michel,

    This is our code last time we sent you only the main lines in the code.

    UART_Handle uart;
    UART_Params uartParams;

    const char echoPrompt[] = "\fEchoing characters:\r\n";

    UART_Params_init(&uartParams);

    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = (UART_Callback)UartReadCallback;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;

    uart = UART_open(Board_UART0, &uartParams);

    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    UART_read(uart, &input, 1);

    while (1) {
            if(charAvail){
                 UART_write(uart, &input, 1);
           }
    }

    The variable of type UARTMSP432_HWAttrs is present  in our project in UARTMSP432.h file it is defined as shown below.

    typedef struct UARTMSP432_HWAttrs {
    /*! UART Peripheral's base address */
    unsigned int baseAddr;
    /*! UART Peripheral's interrupt vector */
    unsigned int intNum;
    /*! UART Peripheral's interrupt priority */
    unsigned int intPriority;
    /*! UART Clock source */
    uint8_t clockSource;
    /*!< UART Bit order */
    uint32_t bitOrder;
    /*!< Number of UARTMSP432_BaudrateConfig entries */
    uint8_t numBaudrateEntries;
    /*!< Pointer to a table of possible UARTMSP432_BaudrateConfig entries */
    UARTMSP432_BaudrateConfig const *baudrateLUT;
    /*! Pointer to a application ring buffer */
    unsigned char *ringBufPtr;
    /*! Size of ringBufPtr */
    size_t ringBufSize;
    } UARTMSP432_HWAttrs;

    Regards,

    Nikitha.

  • Hi Nikitha,

    You forgot to show me where you call UART_Init(...)., not UART_Params_init.(..)

    One more thing: do you start the read from a task? TI-RTOS needs to be running for the UART to work. You start TI-RTOS by calling BIOS_start();

    I am running out of ideas, but can you check that the code works in blocking mode? This will validate that your IOs and UART are being configured.

    Regards,
    Michel
  • Hi Michel,

    void UartReadCallback(UART_Handle handle, void *rxbuf, size_t size){

                charAvail=true;

    }
    Void taskFxn(UArg arg0, UArg arg1){

    UART_Handle uart;
    UART_Params uartParams;
    const char echoPrompt[] = "\fEchoing characters:\r\n";

    UART_Params_init(&uartParams);
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = (UART_Callback)UartReadCallback;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;
    uart = UART_open(Board_UART0, &uartParams);

    if (uart == NULL) {
               System_abort("Error opening the UART");
    }

    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    UART_read(uart, &input, 1);
    while (1) {
                 if(charAvail){
                         UART_write(uart, &input, 1);
                }
    }

    }

    int main(void)
    {
    Task_Params taskParams;

    Board_initGeneral();
    Board_initGPIO();
    Board_initUART();

    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)taskFxn, &taskParams, NULL);


    GPIO_write(Board_LED0, Board_LED_ON);

    BIOS_start();

    return (0);
    }

    The read has been started in the task.

    The code works in blocking mode. 

    Regards,

    Nikitha.