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.

MSP432P401R: UART Crash

Part Number: MSP432P401R

I am using the red launchpad and have a strange issue illustrated in the program below.

I am creating a pretty braindead UART buffer, but I can only send 128 characters before it crashes inside a unhandled interrupt stub. I am not sure what is happening. I don't think it is using any stack or heap, but it sure looks like I am overrunning memory somewhere...

/*
 * Program to control FET switches for bridge simulation
 * UART test
 *
 * Ports used:
 * Port J: Pins 2 &3 - Crystal

 * Port 1: Pins 2&3 Back Channel UART
 *
 *
 *
 */
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>

/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

void executeCommand(char *cmd);
int getData(char *cmd, char *name);
void waitForSerial(void);


/* UART Configuration Parameter. These are the configuration parameters to
 * make the eUSCI A UART module to operate with a 115200 baud rate. These
 * values were calculated using the online calculator that TI provides
 * at:
 * software-dl.ti.com/.../index.html
 */
const eUSCI_UART_Config uartConfig =
{
 EUSCI_A_UART_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
 156,                                      // BRDIV =
 4,                                       // 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  // Oversampling
};

/* Other Rates
 *  9600
 *  BRDIV: 156
 *  UCXBRF: 4
 *  UCXBRS: 0
 *  Oversample: 1
 *
 *  38400
 *  BRDIV: 39
 *  UCXBRF: 1
 *  UCXBRS: 0
 *  Oversample: 1
 *
 *  115200
 *  BRDIV: 13
 *  UCXBRF: 1
 *  UCXBRS: 37
 *  Oversample: 1
 *
 */

char TXData[256];
volatile int8_t TXIdx = -1; // No transmission

uint8_t RXData;
uint8_t RXIdx = 0;
char RXLine[64];

volatile int ii;
// Commands
// Sent as <hello?> with delimiters <>
#define HELLO_CMD "hello"

// Falltime mode with data
#define MODE_CMD "mode"

// Delay between data points
#define DELAY_CMD "delay"

// how many data points to skip
#define STEP_CMD "step"

#define INFO_CMD "info"

#define MAX_MODE (7)

volatile int Mode = 0;



int Step = 8;
int Count = 0;

int main(void)
{
    int i;

    /* Halting the Watchdog */
    MAP_WDT_A_holdTimer();

    //![Simple CS Config]
    /* 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_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
                                                   GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); // UART



    /* 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, 1);
    MAP_FlashCtl_setWaitState(FLASH_BANK1, 1);
    CS_startHFXT(false);

    /* Initializing MCLK to HFXT (effectively 48MHz) */
    MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
    // The UART is limited to 24 MHz...
    MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_2);

    /* Configuring UART Module */
    MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);

    /* Enable UART module */
    MAP_UART_enableModule(EUSCI_A0_BASE);

    /* Enabling interrupts */
    MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT|EUSCI_A_UART_TRANSMIT_INTERRUPT);

    MAP_Interrupt_enableInterrupt(INT_EUSCIA0);

    /* Enabling MASTER interrupts */
    MAP_Interrupt_enableMaster();

    //debug
    waitForSerial();
    strcpy(TXData, "Hello, World!\r\n");

    TXIdx = 0;


    while (1)
    {

        if (TXIdx == -1) {
            Count = Count+Step;

            sprintf(TXData, "\n\r%d", Count);
            for (i=0; i<Count; i++) {
                strcat(TXData, "x");
            }

            TXIdx = 0;
        }

        // check for outgoing serial

        if (TXIdx == 0)
        {
            // Start the transmission
            MAP_UART_transmitData(EUSCI_A0_BASE, TXData[TXIdx++]);
        }


    } // while()
}


/* EUSCI A0 UART ISR */
void EUSCIA0_IRQHandler(void)
{
    uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);

    MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);

    if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
    {

        RXData = MAP_UART_receiveData(EUSCI_A0_BASE);


    } else if (status & EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG) {
        // Ready to transmit the next byte
        if (TXIdx == -1) return;

        if (TXData[TXIdx] == '\0')
        {
            // Done transmitting
            TXIdx = -1;

        } else {
            MAP_UART_transmitData(EUSCI_A0_BASE, TXData[TXIdx++]);

        }
    }

}



void waitForSerial(void)
{
    // Wait for TXIdx to go to -1...
    while (TXIdx != -1);

}

**Attention** This is a public forum