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/MSP432P401R: How to use external crystal 48MHz in TI-RTOS?

Part Number: MSP432P401R
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

<MCU>: MSP430P401R

<IDE>: CCS 7.1.0.00016

<Code Reference 1>: MSP-EXP432P401R - Rev 2.x (Red) in TI-RTOS for MSP430 V2.20.00.06

<Code Reference 2>: SimpleLink MSP432 SDK V1.30.00.40

Hi,

I'm trying to use a 48MHz crystal in my application.

I imported project "cs_hfxt_start_MSP_EXP432P401R_nortos_ccs" from <Code Reference 2>.

It works perfect !!!

But I have no idea how to do this in TI-RTOS.

In this thread(https://e2e.ti.com/support/embedded/tirtos/f/355/t/505658

I import an empty project from <Code Reference 1>.

And add following code in empty.cfg

var Timer = xdc.useModule('ti.sysbios.family.arm.msp432.Timer');
Timer.intFreq.hi = 0;
Timer.intFreq.lo = 48000000;

var BIOS = xdc.useModule('ti.sysbios.BIOS');
BIOS.cpuFreq.hi = 0;
BIOS.cpuFreq.lo = 48000000;

I got an error shows "ti.sysbios.family.arm.msp432.Timer: no property named 'intFreq'"

Q1. External crystal and DCO, which one is working on MCLK and SMCLK now? how to prove?

Q2. How do I set MCLK/SMCLK source to external crystal?

Any response would be helpful, thanks for the time you spent to read this post.

YHH

  • YHH,

      In TI-RTOS / TI Drivers MCLK/HSMCLK are not controlled directly as in driverlib example you referenced. Rather, these settings

    get modified with the Power_setPerformanceLevel() API function.  You can select from 4 performance levels listed below. In this

    case you would want Level =3;

    * Level MCLK (MHz) HSMCLK (MHz) SMCLK (MHz) ACLK (Hz)
    * ----- ---------- ------------ ----------- ---------
    *   0    12           3              3       32768
    *   1    24           6              6       32768
    *   2    48          24             12       32768
    *   3    48          48             24       32768

    You can find documentation for this and other power API functions in TI Resource Explorer. The TI Driver API docs are there at:

    Software -> SimpleLink MSP432 SDK -> Documents -> Drivers -> TI Drivers Runtime APIs (doxygen)  and TI Drivers Power Management.

    For the Power_setPerformanceLevel() API, only the DCO clock source is supported.  You would have to use the driverlib calls

    from the example you referenced to change this to an external crystal.

    Code from the cs_hfxt_start.c example that sets the clock source for MCLK.

    /* Initializing MCLK to HFXT (effectively 48MHz) */
    MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);

    Note here the use of CS_HFXTCLK_SELECT to set MCLK to use an external crystal.

    Regards,

      Bob

     

  • Hi Bob,

    I do some test depends on you comment.

    A)

    Here is uartecho example(SimpleLink MSP432 SDK/TI drivers/uartecho/TI-RTOS/) I modified with driverlib added.

    uartecho.c

    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /*
     *  ======== uartecho.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        char        input;
        const char  echoPrompt[] = "Echoing characters:\r\n";
        UART_Handle uart;
        UART_Params uartParams;
    
        /* Halting the Watchdog */
        MAP_WDT_A_holdTimer();
    
        /* Configuring pins for peripheral/crystal usage and LED for output */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
                GPIO_PIN3 | GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN4);
    
        /* Just in case the user wants to use the getACLK, getMCLK, etc. functions,
         * let's set the clock frequency in the code.
         */
        CS_setExternalClockSourceFrequency(32000,48000000);
    
        /* Starting HFXT in non-bypass mode without a timeout. Before we start
         * we have to change VCORE to 1 to support the 48MHz frequency */
        MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
        MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
        MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
        CS_startHFXT(false);
    
        /* Initializing MCLK to HFXT (effectively 48MHz) */
        MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
        MAP_CS_initClockSignal(CS_HSMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
        MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_2);
    
        /* Call driver init functions */
        //GPIO_init();
        UART_init();
    
        /* Turn on user LED */
        //GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
    
        /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 115200;
    
        uart = UART_open(Board_UART0, &uartParams);
    
        if (uart == NULL) {
            /* UART_open() failed */
            while (1);
        }
    
        UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
        /* Loop forever echoing */
        while (1) {
            UART_read(uart, &input, 1);
            UART_write(uart, &input, 1);
        }
    }
    

    B)

    * Level MCLK (MHz) HSMCLK (MHz) SMCLK (MHz) ACLK (Hz)
    * ----- ---------- ------------ ----------- ---------
    * 0           12                       3                            3                      32768
    * 1           24                       6                            6                      32768
    * 2           48                     24                         12                       32768
    * 3           48                     48                         24                       32768

    I got the correct response of UART0 based on following setting.

    1. Set ".initialPerfLevel = 3" in MSP_EXP432P401R.c

    MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
    MAP_CS_initClockSignal(CS_HSMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
    MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_2);

    2. Set ".initialPerfLevel = 2" in MSP_EXP432P401R.c

    MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
    MAP_CS_initClockSignal(CS_HSMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_2);
    MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_4);

    C) I guess the answer is...

    1. Use different DCO frequency

        1.a - Set the frequency you wanted by ".initialPerfLevel = X" in the MSP_EXP432P401R.c

    2. Use 48MHz external crystal 

        2.a - set the external crystal by MAP_CS_initClockSignal()

        2.b - set the correct frequency of ".initialPerfLevel = X" in the MSP_EXP432P401R.c

    Is it correct?

    * I'm trying to find the way to show the current MCLK/HSMCLK/SMCLK frequency.

    D)

    How about using different frequency crystal which is not on the list? (for example 8MHz/16MHz)

    Regards,

    YHH

**Attention** This is a public forum