当printf和USART_SendString一起使用的时候会出BUG,不清楚是啥原因
这是USART_SendString
void USART_SendString(USART_TypeDef* USARTx, char *DataString)
{
int i = 0;
USART_ClearFlag(USARTx,USART_FLAG_TC);
while(DataString[i] != '\0')
{
USART_SendData(USARTx,DataString[i]);
while(USART_GetFlagStatus(USARTx,USART_FLAG_TC) == 0);
USART_ClearFlag(USARTx,USART_FLAG_TC);
i++;
}
}
这是printf重定义
#if 1
#pragma import(__use_no_semihosting)
struct __FILE
{
int handle;
};
FILE __stdout;
_sys_exit(int x)
{
x = x;
}
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0);
USART1->DR = (u8) ch;
return ch;
}
#endif
这是初始化
void uart1_init(u32 pclk2,u32 bound)
{
float temp;
u16 mantissa;
u16 fraction;
temp=(float)(pclk2*1000000)/(bound*16);
mantissa=temp;
fraction=(temp-mantissa)*16;
mantissa<<=4;
mantissa+=fraction;
RCC->APB2ENR|=1<<2;
RCC->APB2ENR|=1<<14;
GPIOA->CRH&=0XFFFFF00F;
GPIOA->CRH|=0X000008B0;
RCC->APB2RSTR|=1<<14;
RCC->APB2RSTR&=~(1<<14);
USART1->BRR=mantissa;
USART1->CR1|=0X200C;
#if EN_USART1_RX
USART1->CR1|=1<<8;
USART1->CR1|=1<<5;
MY_NVIC_Init(3,3,USART1_IRQn,2);
#endif
}
|