本次F469搭载的仿真器版本为ST-LINK V2.1,最重要的一个特点是集成了虚拟串口。
大致使用方式是,仿真器通过连接MCU的串口,可以作为串口转USB模块直接与PC等通讯。
以下,将进行关于USART以及虚拟串口的实验。
1.安装STLINK V2.1驱动
使用虚拟串口功能,需要进行驱动升级。
ST官网提供了驱动,这里我下载下来提供给大家。
2.选定管脚
打开MB1189原理图说明,可以看到仿真器的虚拟串口对应的管脚是PB10与PB11。
3.新建工程并初始化USART3
PB10与PB11对应的是串口3,在cube中进行初始化。
设置波特率为115200,其余按照默认设置。
4.生成所需工程
5.加入用户代码
在while 1中,加入几行发送程序。
uint8_t send = "hello";
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_UART_Transmit(&huart3, send, 5, 500);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
6.实验
烧录程序,实验效果见下图。