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.

UART read and write code problem

Hi,

I want to use the function platform_uart_read and platform_uart_write to read an array from and write an array to the serial port. But I don't want to load the whole project in the folder C:\Program Files\Texas Instruments\mcsdk_2_00_05_17\tools\post. Can anybody tell me how can I create and build my project in order to use the above two functions independently?

Regards,

Yang

  • You can get the UART platform_uart_read/write functions using the Platform Library.  See the README for the POST and it has details regarding the location of the Platform Library.  Also, you'd want to include the platform.h file.

    Best Regards,
    Chad

  • Hi Chad,

    Thanks for your reply! I have added the platform.h file as well as the lib to my project and now it can compile and run successfully. However, the result shown on the serial port is not correct. I write "HELLO" to the serial port, the port just prints H, rather than the whole word HELLO. The following is my code.

    #include <string.h>
    #include "ti\platform\platform.h"
    #include "ti\platform\resource_mgr.h"

    /* OSAL functions for Platform Library */
    uint8_t *Osal_platformMalloc (uint32_t num_bytes, uint32_t alignment)
    {
        return malloc(num_bytes);
    }

    void Osal_platformFree (uint8_t *dataPtr, uint32_t num_bytes)
    {
        /* Free up the memory */
        if (dataPtr)
        {
            free(dataPtr);
        }
    }

    void Osal_platformSpiCsEnter(void)
    {
        /* Get the hardware semaphore.
         *
         * Acquire Multi core CPPI synchronization lock
         */
        while ((CSL_semAcquireDirect (PLATFORM_SPI_HW_SEM)) == 0);

        return;
    }

    void Osal_platformSpiCsExit (void)
    {
        /* Release the hardware semaphore
         *
         * Release multi-core lock.
         */
        CSL_semReleaseSemaphore (PLATFORM_SPI_HW_SEM);

        return;
    }

    int post_write_uart
    (
        char*      msg
    )
    {
        uint32_t i;
        uint32_t msg_len = strlen(msg);

        /* Write the message to the UART */
        for (i = 0; i < msg_len; i++)
        {
            if (platform_uart_write(msg[i]) != Platform_EOK)
            {
                return -1;
            }
        }

        return 0;
    }
    void main(void)
    {
     post_write_uart("HELLO");
    }

    I don't quite understand the functioin of the OSAL part in the code, but removal of this part will cause compile failure. Why does the serial port just print "H" instead of  "HELLO"?

    Regards,

    Yang

  • Have you hooked up an emulator and see if/where it's stuck?

    Put a while(1); loop/trap after your "post_write_uart("HELLO"); in main and see if you're getting to it or not.

    Best Regards,

    Chad

  • Hi Chad,

    Thanks for your reply!

    I use Step Into to run the code step by step, and it runs correctly with the word "HELLO" printed on the serial port letter by letter. However, if I use Resume to run the code, only "H" is printed and the DSP keeps running all the time without termination.

    Regards,

    Yang

  • Hi Chad,

    I add the platform init function in the main function as following and now it can correctly printf on the serial port. However, the platform_uart_write function writes char to the port, and I want to write float array to the port. So how should I change the function in order to write float array to the port?

        platform_init_flags     init_flags;
        platform_init_config    init_config;

        memset(&init_config, 0, sizeof(platform_init_config));
        memset(&init_flags, 0x01, sizeof(platform_init_flags));

        platform_init(&init_flags, &init_config);

     

    Regards,

    Yang

  • Yang,

    I see you've started another thread to discuss how to write floats through the UART.  I've pinged a colleague to take a look at this new thread as I believe the original intent of this thread is now closed.

    Best Regards,

    Chad

  • Hi Chad,

    Yes, thanks to your help and now I've handled the original problem. Now I'm concerning how to write and read floats through the UART. Do you have any idea how to do it? We can discuss this here or in the new thread. Thank you so much!

    Regards,

    Yang