这块板子的stlink有接芯片的串口,具体为:

理论上可以不需要再找个usb 转串口小板进行功能配置。
配置串口
csdn上的基础工程已经配置到了能闪灯,但是自己添加串口打印printf(包括增加__io_putchar重定向函数)时,发现虽然编译能够通过,但是看不到打印,说明配置还是有缺。因此再去查 cubemx2工程,这个时候还真发现了问题,虽然芯片配置页显示pa2和pa3配置成了串口,但是对应的usart2串口配置并没有配置,此时切到配置外设的页面,启用usart2,配置成异步模式,之后点击生成工程,收到了提示有warning,便观察界面,发现时钟树有问题,此时也没有去细看是什么问题,尝试性地点击右上角的解决时钟问题,问题就自动解决了。
配置过程


CubeMX2配置修改
代码修改
增加重定向函数
int __io_putchar(int ch)
{
uint8_t data = (uint8_t)ch;
if (HAL_UART_Transmit(mx_usart2_uart_gethandle(), &data, 1U, 100U) != HAL_OK)
{
return EOF;
}
return ch;
}增加打印信息
int main(void)
{
/** System Init: this code placed in targets folder initializes your system.
* It calls the initialization (and sets the initial configuration) of the peripherals.
* You can use STM32CubeMX to generate and call this code or not in this project.
* It also contains the HAL initialization and the initial clock configuration.
*/
if (mx_system_init() != SYSTEM_OK)
{
return (-1);
}
else
{
/*
* You can start your application code here
*/
printf("Hello EEPW\r\n");
while (1) {
// PA5 is the pin connected to the on-board LED
HAL_GPIO_TogglePin(HAL_GPIOA, HAL_GPIO_PIN_5);
HAL_Delay(500);
}
}
} /* end main */输出结果
Hello EEPW
我要赚赏金
