Unix系统中开发STM32重定向printf

Unix系统中开发STM32重定向printf

此文章方法可以一并解决重定向问题[[解决“_close is not implemented and will always fail”等编译警告]]。 重写_write函数即可重定向printf输出: #include <stdio.h> int _write(int file, char *p

此文章方法可以一并解决重定向问题[[解决“_close is not implemented and will always fail”等编译警告]]。
重写_write函数即可重定向printf输出:

#include <stdio.h>

int _write(int file, char *ptr, int len)
{
  HAL_UART_Transmit(&huart1, (uint8_t *)ptr, len, HAL_MAX_DELAY);
  return len;
}
Comment