在CubeMX中开发NUCLEO-L476RG是很方便的,这里实现一个USART1 printf()程序。
1.在CubeMX中新建一个项目,选择Board selector->NUCLEO-L476RG
2.在pinout->peripherals->usart1中配置如下:
3.在configuration->connectivity中配置usart1
4.生成keil project
5.在main.c中加入如下代码,实现printf()重定向到USART1
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(500);
printf("hello,world!\r\n");
}
/* USER CODE END 3 */
}
………
/* USER CODE BEGIN 4 */
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
6.运行结果