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.

MSPM0L1306: CCS12.4 Studio如何配置工程使用printf

Part Number: MSPM0L1306


我基于中断的例程使用printf函数,但是重定向失败了,输出到了CIO的对话框中,没有定向到串口,而且__io_putchar函数没有被调用

代码如下,工程属性配置中是否应该进行修改

#include "ti_msp_dl_config.h"
#include <stdio.h>

uint8_t data = 0;

volatile bool uart_send_complete_flag = false;

int __io_putchar(int ch)
{
    DL_UART_Main_transmitData(UART_0_INST, (uint8_t)ch);
    while(uart_send_complete_flag == false){}
    uart_send_complete_flag = false;
    return ch;
}



int main(void)
{
    SYSCFG_DL_init();

    NVIC_ClearPendingIRQ(UART_0_INST_INT_IRQN);
    NVIC_EnableIRQ(UART_0_INST_INT_IRQN);
    DL_SYSCTL_enableSleepOnExit();

    while (1) {
        printf("Hello World!\n");
    }
}

void UART_0_INST_IRQHandler(void)
{
    switch (DL_UART_Main_getPendingInterrupt(UART_0_INST)) {
        case DL_UART_MAIN_IIDX_RX:
            data = DL_UART_Main_receiveData(UART_0_INST);
            DL_UART_Main_transmitData(UART_0_INST, data);
            break;
        case DL_UART_MAIN_IIDX_TX:
            uart_send_complete_flag = true;
            break;
        default:
            break;
    }
}