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/TM4C123GH6PGE: UART baud rate wrong

Part Number: TM4C123GH6PGE

Tool/software: TI-RTOS

I have a project using RTOS v 2_16_01_14, I am setting the Tiva clock source like this...

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ);    //clocking from PLL at 50MHz
    SystemClockFreq = ROM_SysCtlClockGet();        //verify 50MHz

I am configuring a UART for 38400 8N1 like this...

void initUART(void)
{
    UART_Params uartParams;

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_UART5)) ;

    MAP_GPIOPinConfigure(GPIO_PE4_U5RX);
    MAP_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_4);    //UART RX
    MAP_GPIOPinConfigure(GPIO_PE5_U5TX);
    MAP_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_5);    //UART TX

    UART_init();

    UART_Params_init(&uartParams);
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.baudRate = 38400;

    uart5 = UART_open(UART5, &uartParams);
    if (uart5 == NULL) {
        System_printf("Error opening UART5 midi");
        System_flush();
    }
}

But the baud rate is wrong when I use the UART. I observe UART_CC is 0x00 (System clock), but UART_IBRD has been set to 0x82(130) and UART_FBRD set to 0x0D(13). According to data sheet these should be IBRD: 50000000/(16x38400)=81.3802 and FBRD: 0.3802x64+0.5=24.

Can someone advise what I have got wrong please.

Thanks in advance, Richard

  • Hi Richard,

    Can you make a simple CCS project that shows the issue and export it. It would be nice to have all the pieces (e.g. driver configuration, .cfg, etc.). The easiest way is to right-click the project, select Export..., General->Archive File, Next, verify the correct project was selected and give it a name (and Finish).

    Todd

    Edit: and have it be able to run on a TI LaunchPad.

  • Richard Bland said:
    I have a project using RTOS v 2_16_01_14, I am setting the Tiva clock source like this...

        ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ);    //clocking from PLL at 50MHz
        SystemClockFreq = ROM_SysCtlClockGet();        //verify 50MHz

    I think the clock configuration in the TI-RTOS setup and the ROM_SysCtlClockSet may be conflicting.

    By default for a TM4C123 device during start-up, before the application main is called, TI-RTOS will configure the clock for 80MHz as per the following:

    And TI-RTOS "computed" CPU frequency calculated by TI-RTOS is used as the expected system frequency which is passed to UARTConfigSetExpClk by the UARTTiva_open function in tirtos_tivac_2_16_00_08\products\tidrivers_tivac_2_16_00_08\packages\ti\drivers\uart\UARTTiva.c.

    What I think may be causing your failure is that:

    a. The expected CPU frequency used by TI-RTOS is 80MHz (the default when a TM4C123 project is created).

    b. While your code calls ROM_SysCtlClockSet to set the system frequency to 50 MHz, the TI-RTOS UART driver is assuming the system frequency is 80 MHz leading to the incorrect baud rate.

    Also, since the default TI-RTOS Clock Configuration assumes a 16.0 MHz crystal, but your board has a 25MHz crystal the system frequency set by the TI-RTOS startup code (before main is reached) may be overclocking the device during startup.

    Therefore, suggest:

    a. Remove the ROM_SysCtlClockSet call from the application.

    b. In the TI-RTOS Clock Configuration set the desired 50 MHz system frequency based upon the 25 MHz crystal in use by setting the Boot - Clocking Options to: