一.串口1的打印重定义。
#pragma import(__use_no_semihosting)
//标准库需要的支持函数
struct __FILE
{
int handle;
};
FILE __stdout;
//定义_sys_exit()以避免使用半主机模式
void _sys_exit(int x)
{
x = x;
}
//重定义fputc函数
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0);//循环发送,直到发送完毕
USART1->DR = (uint8_t) ch;
return ch;
}
二.打印功能:#include ”stdarg.h“
typedef struct _DOWNLOAD_PARA
{
//align
uint32_t crc;
//align
uint16_t magic;
uint8_t Res0[2];
//chip factory code
uint8_t sta_baudrate;/*0x01:9600bps, 0x02:115200bps, 0x03:256000bps, 0x04:460800bps*/
uint8_t sta_packet_len;/*01:512byte, 0x02:1024byte, 0x03:2048byte 0x04:4096byte*/
uint8_t sta_timeout;/*单位s*/
uint8_t sta_ABarea;/*0x01:自动识别区 0x02,固定升级A区,0x03固定升级B区*/
uint32_t printf_control;
uint8_t Res1[30];
}
DOWNLOAD_PARA;
DOWNLOAD_PARA DownLoad_Para_Info;
#define PRINT_BUF_SIZE 4200// 200// 100 //调试缓冲区大小
char szBuffer[PRINT_BUF_SIZE];
//串口打印控制
int console_write(int ch)
{
HAL_UART_Transmit(&huart1,(u8*)&ch,1,5);
return 0;
}
//输出打印重新封装
int putch_api(int ch)
{
return console_write(ch);
}
//输出打印字符串数据
int puts_api(const char *s)
{
while (*s != 0) {
putch_api(*s++);
}
return 0;
}
//打印数据八进制
void print_oct_api(char ch2, unsigned long l)
{
unsigned char ch;
int i;
ch2 &#