STM32
直播中

study875

12年用户 1091经验值
私信 关注
[问答]

IAR编译器是怎样去使用printf重定向的

IAR编译器是怎样去使用printf重定向的?
vscode是怎样去使用printf重定向的?

回帖(1)

莫钻红

2021-11-30 10:23:28

/*IAR编译器使用printf重定向*/
int fputc(int ch,FILE *file)
{
        while(__HAL_UART_GET_FLAG(bsp_log.port, UART_FLAG_TC) == 0);
        HAL_UART_Transmit(bsp_log.port, (uint8_t*)&ch,1,0xff);
        return ch;
}

/*vscode使用printf重定向*/
int _write(int fd, char *pBuffer, int size)
{
    // for (int i = 0; i < size; i++)
    // {
    //     while ((USART1->SR & 0X40) == 0)
    //         ;                     //等待上一次串口数据发送完成
    //     USART1->DR = (u8)pBuffer; //写DR,串口1将发送数据
    // }
    while (__HAL_UART_GET_FLAG(bsp_log.port, UART_FLAG_TC) == 0)
        ;
    HAL_UART_Transmit(bsp_log.port, (uint8_t *)pBuffer, size, 0xff);
    return size;
}

#Makefile中添加
    -u _printf_float

例:# libraries
    LIBS = -lc -lm -lnosys
    LIBDIR =
    LDFLAGS = $(MCU) -specs=nano.specs -u _printf_float -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
  
举报

更多回帖

发帖
×
20
完善资料,
赚取积分