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_write() execution during interrupt callback function stopping execution of code

Part Number: MSP432P401R
Other Parts Discussed in Thread: SYSCONFIG

Hi, below is a snippet of the basic code I'm running.

void gpioButtonFxn0(uint_least8_t index)
{
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_GPIO_LED0);

    res = ADC_convert(adc, &adcValue0);
    adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);
    printf("%d\n", adcValue0MicroVolt);

    UART_write(uart, &adcValue0MicroVolt, sizeof(adcValue0MicroVolt));
    printf("UART_write() finished\n");
}

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    /* Call driver init functions */
    GPIO_init();
    ADC_init();
    UART_init();
    // I2C_init();
    // SPI_init();
    // Watchdog_init();

    // initialiaze ADC
    ADC_Params_init(&params);
    adc = ADC_open(Board_ADC0, &params);

    if (adc == NULL) {
        printf("ADC_open() failed\n");
        while (1);
    }

    // initialize UART
    UART_Params_init(&uartParams);
    uartParams.writeMode = UART_MODE_CALLBACK;
    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) {
        printf("UART_open() failed\n");
        while (1);
    }

    /* Turn on user LED */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);

    /* Enable interrupts */
    GPIO_enableInt(Board_GPIO_6_1);

    while (1) {
        sleep(1);
        printf("In while loop...\n");
    }
}

If I comment out the UART_write() line in my callback function, I'm able to continuously toggle my LED and perform ADC conversions (at the same time, "In while loop..." keeps printing). However, with the UART_write() command, the execution of this code completely stops. I reach the printing "UART_write() finished" portion, but my code no longer executes. Does anyone know why this may be?

Regards,

Michael

  • Hi Michael,

    Where is your UART callback function?

    Thanks,

    Alexis

  • Hi Alexis,

    I don't actually have a UART callback function. I only configured my mode to CALLBACK from BLOCKING because of some reading I did online...do I need one? What function does it serve? The only place on SysConfig that I can find to configure a UART callback function is the "Error callback function."

    Regards,

    Michael

  • Hi Alexis,

    It's been a couple of days -- can you form a response to my previous questions? I think a little bit of clarity regarding UART callback functions would be really helpful to my application, thanks!

    Regards,

    Michael

  • Hi Michael,

    Sorry for the delayed response! Based on the documentation, I would say you need  the callback function at the very least to know when it is safe to perform another UART_write since the buffer is not copied. See below: 

    "UART_MODE_CALLBACK is non-blocking and UART_read() and UART_write() will return while data is being sent in the context of a hardware interrupt. When the read or write finishes, the UART driver will call the user's callback function. In some cases, the UART data transfer may have been canceled, or a newline may have been received, so the number of bytes sent/received are passed to the callback function. Your implementation of the callback function can use this information as needed. Since the user's callback may be called in the context of an ISR, the callback function must not make any RTOS blocking calls. The buffer passed to UART_write() in UART_MODE_CALLBACK is not copied. The buffer must remain coherent until all the characters have been sent (ie until the tx callback has been called with a byte count equal to that passed to UART_write())."

    Try implementing one and see if this resolves your issue. 

    SysConfig is a tool to help generate your board files, however initializing the UART driver and setting the parameters (and callback function) is done in the application code. 

    Hope this clears things up! 

    Thanks,

    Alexis

  • Hey Alexis,

    Thanks for the response. I was able to dig through the documentation and find out how to implement one. It looks like even having a completely empty callback function has solved my issue. Thanks for the information!

    Regards,

    Michael

**Attention** This is a public forum