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/MSP430F5529: Help to configure UART drivers Baudrate in TI-RTOS

Part Number: MSP430F5529
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hello, 

I am currently developing a project using UART driver in TI-RTOS for MSP430F5529.

I have 2 problems relating to UART driver:

Question 1:

When I configured UART baudrate using different SMCLK frequency than 8192000 Hz, I got the wrong data sent throught UART

+ I configured the SMCLK clockFreq: 

BIOS.cpuFreq.lo = 24000000;
ClockFreqs.SMCLK = 24000000;
ClockFreqs.ACLK = 32768;

+ Then I used this tool to calculate baudrate: http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html

+ Even I tried to use lower SMCLK frequency such as 4000000MHz, I still got the error in data.

+ After all, I only got the right data when I use SMCLK freq = 8192000Hz.

+ My UART configuration is based on the configuration in uartecho example for TI-RTOS.

Question 2:

+ I want to use both UART A0 and A1 in MSP430F5529, so what should I do to configure?

I tried this code but I didn't work:

/*
 * ****************************************************************************
 *  @def    MSP430F5529_UARTName
 *  @brief  Enum of UART names on the MSP430F5529
 */
typedef enum MSP430F5529_UARTName {
	MSP430F5529_UART_A0 = 0,
	MSP430F5529_UART_A1 = 1,

	MSP430F5529_UART_COUNT		//Number of UART objects
} MSP430F5529_UARTName;


/*
 * *****************************************************************
 * @def		uartUSCIAHWAttrs
 * @brief	UART hardware attributes
 */
const UARTUSCIA_HWAttrs uartUSCIAHWAttrs[MSP430F5529_UART_COUNT] =
{
    {
        .baseAddr = USCI_A0_BASE,
        .clockSource = USCI_A_UART_CLOCKSOURCE_SMCLK,
        .bitOrder = USCI_A_UART_LSB_FIRST,
        .numBaudrateEntries = sizeof(uartUSCIABaudrates)/sizeof(UARTUSCIA_BaudrateConfig),
        .baudrateLUT = uartUSCIABaudrates
    },
    {
        .baseAddr = USCI_A1_BASE,
        .clockSource = USCI_A_UART_CLOCKSOURCE_SMCLK,
        .bitOrder = USCI_A_UART_LSB_FIRST,
        .numBaudrateEntries = sizeof(uartUSCIABaudrates)/sizeof(UARTUSCIA_BaudrateConfig),
        .baudrateLUT = uartUSCIABaudrates
    }
};


/*
 * *****************************************************************
 * @def		UART_config
 * @brief	UART configuration list
 */
const UART_Config UART_config[] = {
    {
        .fxnTablePtr = &UARTUSCIA_fxnTable,
        .object = &uartUSCIAObjects[0],
        .hwAttrs = &uartUSCIAHWAttrs[0]
    },

    {
        .fxnTablePtr = &UARTUSCIA_fxnTable,
        .object = &uartUSCIAObjects[1],
        .hwAttrs = &uartUSCIAHWAttrs[1]
    },

    {NULL, NULL, NULL}
};

void IOSEKPeripheral_openUART(UART_Mode uartMode, MSP430F5529_UARTName uartName)
{
	if(uartMode == UART_MODE_BLOCKING)
	{
		//Create a UART with data processing off.
		UART_Params_init(&uartParams);
		{
			uartParams.readMode = UART_MODE_BLOCKING;
			uartParams.writeMode = UART_MODE_BLOCKING;
			uartParams.readTimeout = UART_WAIT_FOREVER;
			uartParams.writeTimeout = UART_WAIT_FOREVER;
			uartParams.readCallback = NULL;
			uartParams.writeCallback = NULL;
			uartParams.readReturnMode = UART_RETURN_FULL;
			uartParams.readDataMode = UART_DATA_BINARY;
			uartParams.writeDataMode = UART_DATA_BINARY;
			uartParams.readEcho = UART_ECHO_OFF;
			uartParams.baudRate = 115200;
			uartParams.dataLength = UART_LEN_8;
			uartParams.stopBits = UART_STOP_ONE;
			uartParams.parityType = UART_PAR_NONE;
		}
	}
}

  • Hi Duc,
    What version of TI-RTOS are you using? Did you add the baud rate configuration to the table uartUSCIABaudrates[] in the board.c file:

    const UARTUSCIA_BaudrateConfig uartUSCIABaudrates[] = {
    /* {baudrate, input clock, prescalar, UCBRFx, UCBRSx, oversampling} */
    {
    .outputBaudrate = 115200,
    .inputClockFreq = 8192000,
    .prescalar = 4,
    .hwRegUCBRFx = 7,
    .hwRegUCBRSx = 0,
    .oversampling = 1
    },
    {9600, 8192000, 53, 5, 0, 1},
    {9600, 32768, 3, 0, 3, 0},
    };

    Best regards,
    Janet
  • Hi Janet,
    I am using TI-RTOS for MSP430 v2.20

    I added this baudrate to this table:
    {115200, 24000000, 13, 0, 0, 1}

    And then I got some garbage data in UART terminal.

    I also tried to configure with another SMCLK such as: 4000000Hz, 8000000Hz and 16000000Hz. But only when SMCLK = 8000000Hz, I got the correct data?

    Could the problem cause because of the MSP430's power configuration or anything else?

  • Hi Duc,
    Is your UART terminal set to 115200?
    Best regards,
    Janet
  • Hi Janet,
    I 've already set terminal baudrate to 115200 and I still got garbage data.
    Another thing is that, If I don't want to creat EchoFxn task using C code and want to config this task using .cgf file, what can I do? I tried to move echoFxn Task to use as an idle task using XGCONF, but nothing worked. Only creating task by C code in "void main()" works now.
  • Hi Duc,

    Did you actually change the SMCLK frequency?  Just setting ClockFreqs.SMCLK will not actually change the SMCLK frequency.  It just tells the system what the new frequency is.  To change the frequency from the default values set up by BIOS, you need to add these line to your .cfg file:

    var Boot = xdc.useModule('ti.catalog.msp430.init.Boot');
    Boot.configureDCO = false;

    Then in main(), set the clock frequencies as you want them. You will still need to set ClockFreqs in your .cfg file too.

    Best regards,
    Janet
  • Hi Janet, 

    So I need to configure Boot.configureDCO = false; or Boot.configureDCO = true ?

    And I have to configure Clock freqs both by using driverlib and in .cfg file, right?

    So many things to configure clocks -_-

  • Hi Janet,
    I configured .cfg file as you showed me above
    Then I configured clock in main with this code:
    {
    // 1. Set core voltage level to handle 24MHz clock rate
    PMM_setVCore( PMM_CORE_LEVEL_1 );
    PMM_setVCore( PMM_CORE_LEVEL_2 );
    PMM_setVCore( PMM_CORE_LEVEL_3 );

    //**************************************************************************
    // 2. Configure Oscillators
    // Initialize the XT1 and XT2 crystal frequencies being used
    // so driverlib knows how fast they are
    UCS_setExternalClockSource(
    LF_LP_CRYSTAL_FREQUENCY_IN_HZ,
    HF_LP_CRYSTAL_FREQUENCY_IN_HZ
    );

    UCS_turnOnLFXT1(UCS_XT1_DRIVE_0, UCS_XCAP_3);

    // Initializes the XT2 crystal oscillator with no timeout.
    // In case of failure, code hangs here.
    // For time-out instead of code hang use UCS_turnOnXT2WithTimeout().
    UCS_turnOnXT2( UCS_XT2_DRIVE_16MHZ_24MHZ);


    //**************************************************************************
    // 3. Configure clocks frequency
    // Select XT1 as ACLK source (32KHz)
    UCS_initClockSignal(
    UCS_ACLK, // Clock you're configuring
    UCS_XT1CLK_SELECT, // Clock source
    UCS_CLOCK_DIVIDER_1 // Divide down clock source by this much
    );

    // Set the FLL's reference clock source to use XT2 (4MHz)
    UCS_initClockSignal(
    UCS_FLLREF, // Clock you're configuring
    UCS_XT2CLK_SELECT, // Clock source
    UCS_CLOCK_DIVIDER_1 // Divide down clock source by this much
    );

    // Configure the FLL's frequency and set MCLK & SMCLK to use the FLL as their source (24MHz)
    UCS_initFLLSettle(
    MCLK_24MHZ_DESIRED_FREQUENCY_IN_KHZ, // MCLK frequency
    MCLK_24MHZ_FLLREF_RATIO // Ratio between MCLK and FLL's reference clock source
    );
    }

    -----------------
    (when:
    #define LF_LP_CRYSTAL_FREQUENCY_IN_HZ 32768 // 32KHz

    #define HF_LP_CRYSTAL_FREQUENCY_IN_HZ 4000000 // 4MHz

    #define MCLK_24MHZ_DESIRED_FREQUENCY_IN_KHZ 24000 // 24MHz

    #define MCLK_24MHZ_FLLREF_RATIO (MCLK_24MHZ_DESIRED_FREQUENCY_IN_KHZ) \
    / (HF_LP_CRYSTAL_FREQUENCY_IN_HZ / 1000)
    )

    -------------------------
    But now I got nothing in Terminal... How can I do now?
  • Hi Duc,

    I was able to get the UART echo example to work with baud rate 115200 and SMCLK running at 4MHz.  I was not able to get it to work with SMCLK = 24MHz.  My UART baud rate configuration in the board file is:

        {
            .outputBaudrate = 115200,
            .inputClockFreq = 4000000,
            .prescalar = 2,
            .hwRegUCBRFx = 2,
            .hwRegUCBRSx = 3,
            .oversampling = 1
        },

    In uartecho.cfg, I added:

    Boot.configureDCO = false;

    var ClockFreqs = xdc.useModule('ti.sysbios.family.msp430.ClockFreqs');
    BIOS.cpuFreq.lo =  4000000;
    ClockFreqs.SMCLK = 4000000;
    ClockFreqs.ACLK = 32768;

    I took the Boot.c file from SYS/BIOS and modified it to set SMCLK to 4MHz by changing the multiplier in UCS control register 2.  I'm attaching this boot.c file.  I call the function Boot_configureDCO() from main().

    7635.boot.c

    I'm still looking into why it doesn't work for 24MHz.

    Best regards,

    Janet

  • Thank Janet,

    Can you show me how to configure to use 2 UART peripherals on MSP430F5529 Launchpad? I was not able to configure to use both UART peripherals A0 and A1. I just edited Board.h, MSP430F5529.h and MSP430F5529.c in uartecho examples but it didn't work.

     

    + code edited in MSP430F5529.c & .h:
    /*
     * ****************************************************************************
     *  @def    MSP430F5529_UARTName
     *  @brief  Enum of UART names on the MSP430F5529
     */
    typedef enum MSP430F5529_UARTName {
        MSP430F5529_UART_A0 = 0,
        MSP430F5529_UART_A1 = 1,
        MSP430F5529_UART_COUNT      //Number of UART objects
    } MSP430F5529_UARTName;
    /*
     * *****************************************************************
     * @def     uartUSCIAHWAttrs
     * @brief   UART hardware attributes
     */
    const UARTUSCIA_HWAttrs uartUSCIAHWAttrs[MSP430F5529_UART_COUNT] =
    {
        {
            .baseAddr = USCI_A0_BASE,
            .clockSource = USCI_A_UART_CLOCKSOURCE_SMCLK,
            .bitOrder = USCI_A_UART_LSB_FIRST,
            .numBaudrateEntries = sizeof(uartUSCIABaudrates)/sizeof(UARTUSCIA_BaudrateConfig),
            .baudrateLUT = uartUSCIABaudrates
        },
        {
            .baseAddr = USCI_A1_BASE,
            .clockSource = USCI_A_UART_CLOCKSOURCE_SMCLK,
            .bitOrder = USCI_A_UART_LSB_FIRST,
            .numBaudrateEntries = sizeof(uartUSCIABaudrates)/sizeof(UARTUSCIA_BaudrateConfig),
            .baudrateLUT = uartUSCIABaudrates
        }
    };
    /*
     * *****************************************************************
     * @def     UART_config
     * @brief   UART configuration list
     */
    const UART_Config UART_config[] = {
        {
            .fxnTablePtr = &UARTUSCIA_fxnTable,
            .object = &uartUSCIAObjects[0],
            .hwAttrs = &uartUSCIAHWAttrs[0]
        },
        {
            .fxnTablePtr = &UARTUSCIA_fxnTable,
            .object = &uartUSCIAObjects[1],
            .hwAttrs = &uartUSCIAHWAttrs[1]
        },
        {NULL, NULL, NULL}
    };

    void IOSEKPeripheral_initUART(void)
    {
    //Initialize UART pins
    //P3.3,4 = USCI_A0 TXD/RXD
    //------------------------------------------------------
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,
    GPIO_PIN3 | GPIO_PIN4);

    //P4.4,5 = USCI_A1 TXD/RXD
    //------------------------------------------------------
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4,
    GPIO_PIN4 | GPIO_PIN5);

    //Initialize the UART driver
    //------------------------------------------------------
    UART_init();
    }

    * in uartecho.c:
    UART_open(MSP430F5529_UART_A0, uartParams);
  • Hi Duc,

    Your configuration looks ok to me.  It looks like what we have in our test board file:

    3034.MSP_EXP430F5529LP.c

    You can compare this file with yours.

    Best regards,

    Janet

  • thanks, janet.
    My configuration has worked. I forgot to add hardware config of UART A0 into .cfg file. After adding these code, It worked great

    // UART Hwis
    //--------------------------------------
    var halHwi1Params = new halHwi.Params();
    halHwi1Params.instance.name = "IZUart_port_A1";
    Program.global.IZUart_port_A1 = halHwi.create(46, "&UARTUSCIA_hwiIntFxn", halHwi1Params);

    var halHwi2Params = new halHwi.Params();
    halHwi2Params.instance.name = "IZUart_port_A0";
    halHwi2Params.arg = 1;
    Program.global.IZUart_port_A0 = halHwi.create(56, "&UARTUSCIA_hwiIntFxn", halHwi2Params);
  • Thanks, janet.
    My configuration has worked. I forgot to add hardware config of UART A0 into .cfg file. After adding these code, It worked great.

    // UART Hwis
    //--------------------------------------
    var halHwi1Params = new halHwi.Params();
    halHwi1Params.instance.name = "IZUart_port_A1";
    Program.global.IZUart_port_A1 = halHwi.create(46, "&UARTUSCIA_hwiIntFxn", halHwi1Params);

    var halHwi2Params = new halHwi.Params();
    halHwi2Params.instance.name = "IZUart_port_A0";
    halHwi2Params.arg = 1;
    Program.global.IZUart_port_A0 = halHwi.create(56, "&UARTUSCIA_hwiIntFxn", halHwi2Params);
  • Hi Duc,

    I'm glad to hear it's working now.

    Best regards,

    Janet