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.

EVMK2H: how to change uart baud rate in Test project

Part Number: EVMK2H

I have imported a test project UART_BasicExample_K2H_c66xTestProject to test UART connectivity that works fine for a baud rate of 115200. Is it possible to change the baudrate and possibly other attributes of UART? I found this comment in the UART_v0.h library.

/* For KS2, the UART module frequency depends on the SoC/UART input
       clock which is a board configuration rather than a SoC configuration.
       The initial frequency value is set to the the SoC input clock,
       the UART module frequency is calculated in UART_init_v0() */

In the test project, I tried to set the baudrate but it did not come to effect. Example

UART_Params      uartParams;
uartParams.baudRate = 9600;
/* Initialize the default configuration params. */
UART_Params_init(&uartParams);

or wherever UART_HwAttrs instance is called, such as

UART_HwAttrs uart_cfg;
uart_cfg.frequency = 9600;

UART_socGetInitCfg(UART_INSTANCE, &uart_cfg);

Can it be changed on this development board?

  • Hi,

    Which SDK is this?

    Best Regards,
    Yordan
  • It is PDK K2H 4.0.4

    I also have processor SDK RTOS K2H 3.02 installed but the library I used is from PDK version above.

  • Hi,

    I've asked the pdk team to elaborate. Feedback will be posted here.

    Best Regards,
    Yordan
  • Sherry,

    Yes, the UART baudrate can absolutely be changed on this device to the required baud rate settings.  If you look at the device datasheet, you will notice that that SYSLCK /6  is used to source the UART module and inside the UART module, there is Prescalar and a oversampling factor that needs to be set to achieve a certain baudrate.

    If you now look at the UART driver call UART_open_v0 call for this device, it reads in the baudrate field from the params structure to compute the prescalar using 16 bit oversampling and the provided CPU frequency(from UART_HWAttr) to set the UART module to the desired baud rate.

            /* Computing the Divisor Value for params.baudRate */
            divisorValue = UART_divisorValCompute_v0(hwAttrs->frequency,
                                                          object->params.baudRate,
                                                          UART16x_OPER_MODE);
            /* Configuring the Baud Rate settings. */
            UART_divisorLatchWrite_v0(hwAttrs->baseAddr, divisorValue);


    As long as you pass the correct value of SYSCLK /6 which is the setting of the core clock as done in the board library and the GEL files. and provide the params.baudrate parameter the driver will set the UART module prescaler and oversampling to get to that baudrate. Note you will then have to set the host serial console to appropriate baudrate to communicate with the device.

    Regards,

    Rahul

  • Rahul, Thank you.
    None of my functions appear to call UART_open_v0() or the divisor computations quoted above. I found this after I dug into the function calls post-build. However, I realised that UART_params_init() function call in the test project was importing the default values defined in C:\ti\pdk_k2hk_4_0_4\packages\ti\drv\uart\src\UART_drv.c

    void UART_Params_init(UART_Params *params)
    {
    
        *params = UART_defaultParams;
    }
    
    /* Default UART parameters structure */
    const UART_Params UART_defaultParams = {
        UART_MODE_BLOCKING,           /* readMode */
        UART_MODE_BLOCKING,           /* writeMode */
        ...
        115200,               /* baudRate */
        ...                 /* readCallback2 */
        NULL,                 /* writeCallback2 */
    };

    Hence in the test project, I simply have to overwrite the variable of baudrate in the UART_Params instance just before UART_open() and just after the UART_params_init() function call (unlike doing it before UART_Params_init() that I have stated above). This saved me from changes to the GEL file or any board files. It worked.

     /* Initialize the default configuration params. */
        UART_Params_init(&uartParams);
        uartParams.baudRate = 9600;
        uart = UART_open(UART_INSTANCE, &uartParams);