大家有没有验证基于官方的串口打印的例子,基于开发板N32G45XRL-STB开发板.验证失败的,下面是我验证的代码添加:
void RCC_Configuration(void)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_AFIO,ENABLE); //enable GPIOA clk
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_USART1,ENABLE); //enable usart1 clk
}
#define USARTx_GPIO GPIOA
#define USART_Tx_Pin GPIO_PIN_9
#define USART_Rx_Pin GPIO_PIN_10
void GPIO_Configuration(void)
{
GPIO_InitType GPIO_InitStructure;
/* Configure USARTx Tx as alternate function push-pull */
GPIO_InitStructure.Pin = USART_Tx_Pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //这个地方换过了几种 GPIO_Mode_Out_OD ,GPIO_Mode_AF_OD,GPIO_Mode_AF_PP
GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure);
/* Configure USARTx Rx as input floating */
GPIO_InitStructure.Pin = USART_Rx_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure);
}
USART_InitType USART_InitStructure;
void USART_Printf_Configuration(void)
{
/* USARTy and USARTz configuration ------------------------------------------------------*/
USART_InitStructure.BaudRate = 115200;
USART_InitStructure.WordLength = USART_WL_8B;
USART_InitStructure.StopBits = USART_STPB_1;
USART_InitStructure.Parity = USART_PE_NO;
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
/* Configure USARTx */
USART_Init(USART1, &USART_InitStructure);
/* Enable the USARTx */
USART_Enable(USART1, ENABLE);
}
主函数处理:
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART_Printf_Configuration();
printf("N32G45RE printf test.\r\n");
while(1)
{
printf("N32G45RE printf test.\r\n");
Delay(0x28ffff);
}
}
测试结果无任何的打印数据,有谁知道是什么原因.
|