今天收到了开发板,首先体验stm32cubeMX的快速创建工程,并实现printf的打印输出。
1、打开stm32cubeMX,我使用的版本为6.14。创建一个基于stm32u385RG的基础工程:

2、查找开发板的用户手册与原理图,找到stlink与stm32u385的串口连接。在UM3063中有关于uart的记录:

通过查看开发板后面的跳线,U385的USART1通过PA9/PA10与STLINK的相连。
3、开启usart1,stm32cubmx已经自动给配置好IO为PA9/PA10。波特率也自动给到了115200。

4、工程生成配置如下,生成mdk的工程。

5、生成后,使用mdk打开工程,添加重定向的代码,由于我后期需要需要touchgfx,所以不能使用微库。代码如下:
/* USER CODE BEGIN 1 */
#include "stdio.h"
/* ------------------通过重定向将printf函数映射到串口1上-------------------*/
#if !defined(__MICROLIB)
//#pragma import(__use_no_semihosting)
__asm (".global __use_no_semihosting\n\t");
void _sys_exit(int x) //避免使用半主机模式
{
x = x;
}
//__use_no_semihosting was requested, but _ttywrch was
void _ttywrch(int ch)
{
ch = ch;
}
FILE __stdout;
#endif
#if defined ( __GNUC__ ) && !defined (__clang__)
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
/* 实现串口发送一个字节数据的函数 */
//serial_write(&serial1, (uint8_t)ch); //发送一个自己的数据到串口
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 1000);
return ch;
}
/* USER CODE END 1 */
【验证】
在man中添加测试代码,然后打开串口助手,成功输出如下:

【总结】
stm32u385由于有开源免费的stm32cube的生态支持,非常容易就上手了。 |