Configuration of UART for MSP432

Hello,

I’m trying to set up a the UART using the freeRTOS calls. I’m using MSP432P401R.


What i have:

At the moment, I have programmed the UART ‘bare metal’ configuring the pins manually, and it worked:

void init_UART_emulador(void){
    UCA0CTLW0 |= UCSWRST;
    UCA0CTLW0 |= UCSSEL__SMCLK;
    UCA0MCTLW = UCOS16;
    UCA0BRW = 3;

    P1DIR |= DIR_UART;                   // PORT P1.0 com a sortida (Data direction: Selector Tx/Rx)
    P1SEL0 &= ~DIR_UART;                 // PORT P1.0 com I/O digital (GPIO)
    P1SEL1 &= ~DIR_UART;
    P1OUT &= ~DIR_UART;                  // Inicialitzem port P1.0 a 0 (Rx)

    P1SEL0 |= BIT2 | BIT3;      //I/O UART function
    P1SEL1 &= ~ (BIT2 | BIT3);

    //Reactivem la linia de comunicacions serie
    UCA0CTLW0 &= ~UCSWRST;
    //Interrupcions
    EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG;    // Clear eUSCI RX interrupt flag
    EUSCI_A0->IE |= EUSCI_A_IE_RXIE;
    NVIC->ICPR[0] |= 1 <<((EUSCIA0_IRQn) & 31); // Comprovem que no hi ha int residual pendent a la USCI
    NVIC->ISER[0] |= 1 <<((EUSCIA0_IRQn) & 31); // Habilitem les int. de la USCI
}

Currently I need a 500kbs baudrate. At the main I have a call of a function init_ucs_24MHz(), which sets the SMCKL to 24Mhz (this function is from a lib so i can’t see what it does internally).


Now, I have downloaded the FreeRTOS demo for my controller. In this demo there’s a Serial file where they configure the UART, so I’m trying to stick with it. Here’s the functions that I have assembled:

void prvConfigureClocks( void )
{
    /* Set Flash wait state for high clock frequency.  Refer to datasheet for
    more details. */
    FlashCtl_setWaitState( FLASH_BANK0, 2 );
    FlashCtl_setWaitState( FLASH_BANK1, 2 );

    /* The full demo configures the clocks for maximum frequency, whereas the
    blinky demo uses a slower clock as it also uses low power features.  Maximum
    freqency also needs more voltage.

    From the datashee:  For AM_LDO_VCORE1 and AM_DCDC_VCORE1 modes, the maximum
    CPU operating frequency is 48 MHz and maximum input clock frequency for
    peripherals is 24 MHz. */
    PCM_setCoreVoltageLevel( PCM_VCORE1 );
    CS_setDCOCenteredFrequency( CS_DCO_FREQUENCY_24 );
    CS_initClockSignal( CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
    CS_initClockSignal( CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
    CS_initClockSignal( CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
    CS_initClockSignal( CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
}
const eUSCI_UART_Config xUARTConfig =
{
    EUSCI_A_UART_CLOCKSOURCE_SMCLK, /* SMCLK Clock Source. */
    3,                            /* BRDIV */
    0,                              /* UCxBRF */
    0,                              /* UCxBRS */
    EUSCI_A_UART_NO_PARITY,         /* No Parity. */
    EUSCI_A_UART_LSB_FIRST,         /* MSB First. */
    EUSCI_A_UART_ONE_STOP_BIT,      /* One stop bit. */
    EUSCI_A_UART_MODE,              /* UART mode. */
    EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION /* Low Frequency Mode. */
};
void init_uart0(void){
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION );

    /* Use the library functions to initialise and enable the UART. */
    MAP_UART_initModule( EUSCI_A0_BASE, &xUARTConfig );
    MAP_UART_enableModule( EUSCI_A0_BASE );

    MAP_UART_clearInterruptFlag( EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT | EUSCI_A_UART_TRANSMIT_INTERRUPT );
    MAP_UART_enableInterrupt( EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT );


    /* The interrupt handler uses the FreeRTOS API function so its priority must
    be at or below the configured maximum system call interrupt priority.
    configKERNEL_INTERRUPT_PRIORITY is the priority used by the RTOS tick and
    (should) always be set to the minimum priority. */
    MAP_Interrupt_setPriority( INT_EUSCIA0, configKERNEL_INTERRUPT_PRIORITY );
    MAP_Interrupt_enableInterrupt( INT_EUSCIA0 );
}

Now, when I use this set up the UART no longer sends any information. I suspect that there’s something wrong with the clock, but I don’t now what.

If you need more information I will gladly provide it,

Thanks!

Which demo are you using? Is it exactly for the same part?

If you replace the UART setup code in init_uart0 with the code from your bare metal application, does it work?

Hello,

I was using the demo for MSP432.

I solved the problem this morning: I was not configuring the PIN P1 in the init_uart0() for the half-duplex, also I was not inicialiting any task or the scheduler, and a few minor other things.

Now I have another problem though: when I use a queue in the IRS routine for the UART it doesn’t read all the bytes. I suspect that the problem is that the queue is too slow for the baudrate (500kbps), but I’m not sure. If I use a global variable + flag it works fine though.