37 lines
773 B
Markdown
37 lines
773 B
Markdown
---
|
|
title: STM32串口打印重定义
|
|
updated: 2022-01-11 01:27:18Z
|
|
created: 2022-01-11 01:20:11Z
|
|
tags:
|
|
- mcu
|
|
- printf
|
|
- 代码块
|
|
---
|
|
|
|
STM32串口打印重定义
|
|
```c
|
|
#ifdef __GNUC__
|
|
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
|
|
set to 'Yes') calls __io_putchar() */
|
|
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
|
#else
|
|
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
|
|
#endif /* __GNUC__ */
|
|
|
|
/**
|
|
* @brief Retargets the C library printf function to the USART.
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
PUTCHAR_PROTOTYPE
|
|
{
|
|
/* Place your implementation of fputc here */
|
|
/* e.g. write a character to the USART */
|
|
HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xFFFF);
|
|
return ch;
|
|
}
|
|
```
|
|
|
|
#mcu
|
|
#printf
|
|
#代码块 |