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.

AM3358: UART write callback

Part Number: AM3358
Other Parts Discussed in Thread: SYSBIOS

Why does UART_write not invoke read callback function?

if (UART_read(uart, (void *)(uintptr_t)addrScanPrompt, UART_TEST_READ_LEN) == UART_ERROR)

{

goto Err;

}//read is UART_MODE_CALLBACK

if (UART_write(uart, (void *)(uintptr_t)addrEchoPrompt, sizeof(echoPrompt)) == UART_ERROR)

{

goto Err;

}  //write is UART_MODE_BLOCKING

if (UART_osalPendLock(callbackSem, uartParams.readTimeout) != SemaphoreP_OK)//stop here forever

{

goto Err;

}

but

if (UART_read(uart, (void *)(uintptr_t)addrScanPrompt, UART_TEST_READ_LEN) == UART_ERROR)

{

goto Err;

}//read is UART_MODE_CALLBACK

input "this way work!"  from serial port 0

if (UART_osalPendLock(callbackSem, uartParams.readTimeout) != SemaphoreP_OK)//it run pass this line to next line.

{

goto Err;

}

Why? Here uart is uart0. Thanks

  • Hi Anping,

    Do you use AM335x PSDK RTOS v6.01, PDK 1.0.16 and CCS v9.1.0?

    Do you use AM335x TI board or custom board?

    Do you use TI UART test/example or you are creating your own?


    Regards,
    Pavel

  • Hi Pavel

         I use PDK 1.0.16 and BeagleBone Black. CCS 8.3.1. I create my own project. Thanks

  • SemaphoreP_Handle callbackSem = NULL;
    /*
     *  ======== UART callback test ========
     *
     *  The test function tests the read/write in callback mode
     */
    static bool UART_test_callback(bool dmaMode)
    {
        char              rx_buf[32];
    	const char        message_to_send_by_uart[EXPECTED_MSG_LENGTH] = "message to send by uart!\n";
        bool              ret = false;
    
        /* Create call back semaphore */
    	SemaphoreP_Params semParams;
        UART_osalSemParamsInit(&semParams);
        semParams.mode = SemaphoreP_Mode_BINARY;
        callbackSem = UART_osalCreateBlockingLock(0, &semParams);
    
        /* Test read/write API's in callback mode */
    
        /* UART SoC init configuration */
        /* Get the default UART init configurations */
    	UART_HwAttrs uart_cfg;
        UART_socGetInitCfg(uartTestInstance, &uart_cfg);
        uart_cfg.edmaHandle = NULL;
        uart_cfg.dmaMode    = FALSE;
        uart_cfg.loopback   = FALSE;
    
        /* Set the DMA enabled UART init configurations */
        UART_socSetInitCfg(uartTestInstance, &uart_cfg);
    
        /* Set callback mode for both read and write */
    	UART_Params       uartParams;
        UART_Params_init(&uartParams);
        uartParams.readCallback = UART_callback;
        uartParams.readMode = UART_MODE_CALLBACK;
        uartParams.parityType = uartParity;
    
        UART_Handle uart = UART_open(uartTestInstance, &uartParams);
        if (uart == NULL)
        {
            goto Err;
        }
    
        memset(rx_buf, 0, 32);
    
        if (UART_read(uart, (void *)&rx_buf[0], 32) == UART_ERROR)
        {
            goto Err;
        }
    	
        if (UART_write(uart, (void *)&message_to_send_by_uart[0], sizeof(message_to_send_by_uart)) == UART_ERROR)
        {
            goto Err;
        }
    	
        if (UART_osalPendLock(callbackSem, uartParams.writeTimeout) != SemaphoreP_OK)-> stop here unless I input on serial port. UART_write doesn't trigger callback function
        {
            goto Err;
        }
    
    	ret = true;
    Err:
        if (uart)
        {
            UART_close(uart);
        }
        if (callbackSem)
        {
        	UART_osalDeleteBlockingLock(callbackSem);
        	callbackSem = NULL;
        }
        return (ret);
    }

  • Anping Chen said:
      I use PDK 1.0.16 and BeagleBone Black. CCS 8.3.1

    I would recommend to switch to CCS v9.1.0, as this is the version which match with PDK 1.0.16:

    http://software-dl.ti.com/processor-sdk-rtos/esd/docs/latest/rtos/index_release_specific.html

    Regards,
    Pavel

  • Hi Pavel

        I can't use CCS v9.1.0 because it is out of my control. We all use CCS 8.3.1. I like to know why UART_write don't trigger UART_read callback function. Thanks

  • https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/791/3021.OSLayerTest.7zHi Pavel

        Any progress? Enclosed is my toy project. UART_write can't trigger UART_read callback function. Thanks

  • Anping,

    UART_write() is used in interrupt mode. Please check if you have enabled interrupts in UART module and Cortex-A8 MPU.

    I can also suggest you to:

    - try with polling mode, UART_readPolling() and UART_writePolling(). In polling mode, no interrups are needed

    - try with the default main_uart_test.c UART test. Check if this test is running fine on your BeagleBone Black board then align your custom test to this UART test.

    pdk_am335x_1_0_16/packages/ti/drv/uart/test/am335x/armv7/bios/UART_BasicExample_bbbAM335x_armTestProject.txt

    pdk_am335x_1_0_16/packages/ti/drv/uart/test/src/main_uart_test.c

    pdk_am335x_1_0_16/packages/ti/drv/uart/soc/am335x/UART_soc.c

    pdk_am335x_1_0_16/packages/ti/drv/uart/test/am335x/armv7/bios/am335x_app_bbbam335x.cfg

    Regards,
    Pavel

  • Hi Pavel

        can you repeat issue on your side by my toy project?

    I add two lines

    /* UART SoC init configuration */

    /* Get the default UART init configurations */

    UART_HwAttrs uart_cfg;

    UART_socGetInitCfg(0, &uart_cfg);

    uart_cfg.edmaHandle = NULL;

    uart_cfg.txTrigLvl = UART_TXTRIGLVL_16;//I add

    uart_cfg.dmaMode = FALSE;

    uart_cfg.loopback = FALSE;

    uart_cfg.enableInterrupt = TRUE;//I add

    /* Set the DMA enabled UART init configurations */

    UART_socSetInitCfg(0, &uart_cfg);

    /* Set callback mode for both read and write */

    UART_Params uartParams;

    UART_Params_init(&uartParams);

    uartParams.readCallback = UART_callback;

    uartParams.readMode = UART_MODE_CALLBACK;

    uartParams.parityType = UART_PAR_NONE;

    The issue is still there. If I manually input from PuTTY., it trigger UART_read's callback function. How let UART_write to trigger UART_read's callback function? Thanks

  • Hi Pavel

         In fact UART_BasicExample_bbbAM335x_armTestProject seem not to have "UART_write trigger UART_read's callback function" case. I test UART_BasicExample_bbbAM335x_armTestProject on my BeagleBone Black success! I input 16 chars from PuTTY trigger UART_read's callback function! Thanks

  • Anping,

    Anping Chen said:
    In fact UART_BasicExample_bbbAM335x_armTestProject seem not to have "UART_write trigger UART_read's callback function" case. I test UART_BasicExample_bbbAM335x_armTestProject on my BeagleBone Black success! I input 16 chars from PuTTY trigger UART_read's callback function! Thanks

    Did you resolve your issue? Or you still have open questions?

    May be UART_write2() function will be in better use for your test.

    Regards,
    Pavel

  • Hi Pavel

        No. I am looking for you to help me to solve. To Change CCS or use UART_write2() might work. It avoid the issue, not solve the issue! Why does UART_write not trigger UART_read's callback function? It should even if I use CCS8.3.1. Thanks

  • Hi Pavel

         I have provided my toy project to you. Can you repeat the issue on your side? Please let me to know what else I can do.  Thanks

  • Anping Chen said:
    To Change CCS or use UART_write2() might work. It avoid the issue, not solve the issue! Why does UART_write not trigger UART_read's callback function? It should even if I use CCS8.3.1.

    So you mean that UART_write() works fine in PDK 1.0.16 with CCS 9.1.0? But fails on PDK 1.0.16 with CCS 8.3.1?

    Regards,
    Pavel

  • No. I don't try CCS 9.1.0 or UART_write2() at all. Thanks

  • Anping,

    Anping Chen said:
    Why does UART_write not trigger UART_read's callback function?

    UART_write should trigger UART_write's callback, not UART_read's callback.

    I modified below test, to create two UART_calback functions, one for UART_write and one for UART_read. And I can see that UART_write trigger UART_writecallback, while UART_read trigger UART_readcallback function.

    pdk_am335x_1_0_16/packages/ti/drv/uart/test/src/main_uart_test.c

    /*
     *  ======== UART callback test ========
     *
     *  The test function tests the read/write in callback mode
     */
    static bool UART_test_callback(bool dmaMode)
    {

    .....

    /* Set callback mode for both read and write */
        UART_Params_init(&uartParams);
        uartParams.readCallback = UART_readcallback;
        uartParams.readMode = UART_MODE_CALLBACK;
        uartParams.writeCallback = UART_writecallback;
        uartParams.writeMode = UART_MODE_CALLBACK;

    ..

    }

    void UART_readcallback(UART_Handle handle, void *buf, size_t count)
    {
        UART_osalPostLock(callbackSem);
    }

    void UART_writecallback(UART_Handle handle, void *buf, size_t count)
    {
        UART_osalPostLock(callbackSem);
    }

     


    Regards,
    Pavel

  • Hi Pavel

         Can you send me your modified main_uart_test.c?

         What do you mean UART_read trigger UART_readcallback function? Can you explain it a little bit? It is better for you to give me a use case.

    When you use UART_read, UART_readcallback function trigger when there is something to read. 1) I can type something from PuTTY serial port to trigger UART_readcallback function. It do as what I expect. Or 2) I use UART_write to write something to serial port in order to trigger UART_readcallback function. But it doesn't. Thanks

         

  • Hi Pavel

        I run UART_BasicExample_bbbAM335x_armTestProject on my BeagleBone Black again. After executing line 1585

    if (UART_read(uart, (void *)(uintptr_t)addrScanPrompt, UART_TEST_READ_LEN) == UART_ERROR)

    {

    goto Err;

    }

    and executing line 1589

    if (UART_osalPendLock(callbackSem, uartParams.readTimeout) != SemaphoreP_OK)

    {

    goto Err;

    }

    it will hang there until I type something from PuTTY serial port. In other word there are something to read. Can I use

    UART_write to input something to serial port in order to UART_read can read, therefore to trigger UART_read's callback function? I think it could. Please use my toy project to repeat the issue on your side in order for you to understand what my issue is. Thanks

  • Hi Pavel

         When there is something to read on serial port, it will trigger UART_read's callback function!  I can type something from PuTTY serial port to trigger UART_readcallback function. I can use UART_write to write something to serial port to trigger UART_read's callback function. I even use another application to input something to serial port to trigger UART_read's callback function. Am I right? Thank you for your help.

  • Anping,

    I have explored the UART test step by step, pdk_am335x_1_0_16/packages/ti/drv/uart/test/src/main_uart_test.c, and these are my observations how this driver woks in callback mode:

    1. UART_open()

    2. UART_write() - this function write string (dataPrint[40] and echoPrompt[40]) on PC UART console (not CCS console)

    3. UART_osalPendLock() -> SemaphoreP_pend()

    4. UART_writecallback



    5. UART_read()

    6. UART_osalPendLock()

    ------> At this point we need to enter chars from the keyboard

    7. UART_readcallback()



    8. UART_write() - write the chars that we entered from keyboard into char scanPrompt[256]

    9. UART_osalPendLock()

    10. UART_writecallback()

    11. UART_close(uart);

    I am attaching my modified version of pdk_am335x_1_0_16/packages/ti/drv/uart/test/src/main_uart_test.c for reference:

    4130.main_uart_test.c

    Regards,
    Pavel

  • Hi Pavel

         I run pdk_am335x_1_0_16/packages/ti/drv/uart/test/src/main_uart_test.c on my BeagleBone Black many times. My question is instead of  we need to enter chars from the keyboard after 6), can we have other way to enter chars? like using UART_write or using other application. Thanks

  • Anping Chen said:
    I run pdk_am335x_1_0_16/packages/ti/drv/uart/test/src/main_uart_test.c on my BeagleBone Black many times. My question is instead of  we need to enter chars from the keyboard after 6), can we have other way to enter chars? like using UART_write or using other application. Thanks

    If you do not want to read chars from the keyboard, you can hardcode the char string in char scanPrompt[256]; and do not use UART_read() at all. 

    char scanPrompt[256] = "\r\n <enter your string here, instead from keyboard> \r\n";

    char dataPrint[40] = "\r\n enter the data of 16 character \r\n";

    char echoPrompt[40] = "\n\r Data entered is as follows \r\n";

    UART_test_callback()

    {

    UART_write(dataPrint); --> print "enter the data of 16 character"

    UART_write(echoPrompt); --> print "Data entered is as follows"

    UART_write(scanPrompt); --> print "<enter your string here, instead from keyboard>"

    }

    Regards,
    Pavel

  • Hi Pavel

         In project which I send you

    if (UART_read(uart, (void *)&rx_buf[0], 32) == UART_ERROR)

    {

    goto Err;

    }

    if (UART_write(uart, (void *)&message_to_send_by_uart[0], sizeof(message_to_send_by_uart)) == UART_ERROR)

    {

    goto Err;

    }

    if (UART_osalPendLock(callbackSem, uartParams.writeTimeout) != SemaphoreP_OK)//can't pass this line because UART_write don't trigger UART_read callback function

    {

    goto Err;

    }

    UART_write(uart, (void *)&message_to_send_by_uart[0], sizeof(message_to_send_by_uart)) write message_to_send_by_uart to uart(UART0 here). Why UART_read(uart, (void *)&rx_buf[0], 32) can't read what UART_write write,? just like we enter chars from the keyboard. Thanks

  • Hi Pavel

        Do you have any update on my issue? In fact to use UART_write, or another application, to feed UART_read and trigger its callback function are more practical than to enter chars from the keyboard. Thanks

  • Anping Chen said:
    Do you have any update on my issue? In fact to use UART_write, or another application, to feed UART_read and trigger its callback function are more practical than to enter chars from the keyboard. Thanks

    Anping,

    I will notify our UART expert for help.

    Regards,
    Pavel

  • Hi Pavel

         Thanks. I need to use UART_write, or another application, to feed UART_read and trigger its callback function. TI can add them to your example projects.  Happy New year!

  • Hi Anping,

    I haven't looked at your example code, so I'm unfamiliar with the details. However, I'll try to answer your question:

    >> I need to use UART_write, or another application, to feed UART_read and trigger its callback function.

    To use UART_write() on the same core as UART_read():

    • Connect the Tx pin for the 'write' UART to the Rx pin for the 'read' UART in an external loopback
    • For UART_read()/UART_write() in the same SYSBIOS Task: issue UART_read() in UART_MODE_CALLBACK before UART_write() . This will allow the UART_read() to return so UART_write() can be called. You could issue UART_write() in UART_MODE_CALLBACK before UART_read(), but some characters might be lost if insufficient buffering is available in the UART FIFO to accommodate the delay between the write and read functions.
    • For UART_read()/UART_write() in different SYSBIOS Tasks: set the UART_read() to occur first, e.g. by setting the "reader" Task as higher priority than the "writer" Task.

    For the case of another application, I assume you mean the UART write will be performed on some other hardware (BBB or not) using some other software (PRSDK or not). In this case, simply connect the other hardware Tx pin (this app will perform the UART write) to the BBB Rx pin (this app will perform the UART_read()). You can manually synchronize the UART write and UART_read() by first running the BBB application, and then running the "other" application to avoid losing UART characters due to insufficient buffering in the UART FIFO. Additional code could be added to both applications to implement an automatic synchronization scheme (e.g. some sort of GPIO handshaking).

    There is a test program written for the UART PRU firmware which extensively uses loopback testing. Details can be found at the following locations:

    Regards,
    Frank

  • Hi Frank

         Happy new year. Enclosed is my toy project which I send Pavel before 

    UART_read read to rx_buf

    UART_write write message_to_send_by_uart.

    UART_write  rx_buf which should be message_to_send_by_uart.

    It doesn't work as expected. https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/791/03502.OSLayerTest.7zCan you tell me what is wrong.

     

  • Hi Anping,

    No, I'm afraid you'll need to debug this on your own.

    Regards,
    Frank

  • Hi Frank

          I use uart_cfg.loopback = TRUE; as what you instruct.

    if (UART_osalPendLock(callbackSem, uartParams.writeTimeout) != SemaphoreP_OK)//can't pass this line because UART_write don't trigger UART_read callback function

    don't block any more. but  rx_buf is not message_to_send_by_uart.

    If I don't use uart_cfg.loopback = FALSE;

    if (UART_osalPendLock(callbackSem, uartParams.writeTimeout) != SemaphoreP_OK)//can't pass this line because UART_write don't trigger UART_read callback function

    will block. But If I type a message on PuTTY serial port. rx_buf  is what I type.

    My question is why rx_buf is not what UART_write write :message_to_send_by_uart.

    Thanks

        

  • Anping,

    I was referring to external loopback (i.e. external pins on the device), not internal UART loopback.

    We provide test & examples in PRSDK for various use cases for the IPs on the SoCs. Please use these as a guide for your application development.

  • Hi Frank

        I run UART_BasicExample_bbbAM335x_armTestProject on my BBB success. I know various test cases well. As my toy project show(delete uart_cfg.loopback = TRUE;)

    UART_write write the message message_to_send_by_uart not to trigger UART_read's callback function. It stop at line

    if (UART_osalPendLock(callbackSem, uartParams.writeTimeout) != SemaphoreP_OK)

    forever. If I type the message message_to_send_by_uart from PuTTY serial port, it to trigger UART_read's callback function and rx_buf = message_to_send_by_uart. Why does UART_write not trigger UART_read's callback function?  Thanks

  • Hi Frank

         In my project which I send you I just want to know why UART_write can't input the message to trigger UART_read's callback function. There is no your example project for this use case. To input the message by PuTTY serial port can trigger UART_read's callback function! Your example projects and my project confirm it. I don't know if I explain it clear.  Thanks

  • Hi Frank

      Your external loopback mean to connect UART1_TXD to UART1_RXD or UART2_TXD to UART2_RXD or UART4_TXD to UART4_RXD or UART5_TXD to UART5_RXD, am I right? if yes, Because I use UART0, I should connect UART0_TXD to UART0_RXD to let UART_write to trigger UART_read callback function. But we don't know where UART0_TXD and UART0_RXD locate. How to solve this issue. Thanks

       

  • Anping,

    Yes, that's the idea.

    Look at the AM335x datasheet to determine the UART0 Tx & Rx pins (Balls) & pin mux settings. Next look at the BBB schematic to determine if any of the UART0 Tx & Rx pins are routed to a header (e.g. J1).

    Regards,
    Frank

  • Do you know where J1_4 and J1_5 locate in BeagleBone Black. Thanks

  • On the top of the board next to P9.

  • Hi Frank

         Is J1 header Debug Serial Header which has 6 pins next to P9? Thanks


  • Anping,

    Yes, it's labeled on the board.

  • Hi Frank

         I see it. Thanks