[TOC]

RTT-Studio使用CubeMx开发串口报错

一、问题描述

在RT-Thread Studio进行开发,建立了基于芯片(STM32F407ZET6)的工程,打开STM32CubeMX进行基本外设配置,配置完成生成代码,回到Studio IDE进行编译时一堆报错,具体如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
../drivers/drv_usart.c:94:5: error: unknown type name 'UART_HandleTypeDef'
UART_HandleTypeDef handle;
^
../drivers/drv_usart.c: In function 'stm32_configure':
../drivers/drv_usart.c:413:17: error: request for member 'Instance' in something not a structure or union
uart->handle.Instance = uart->config->Instance;
^
../drivers/drv_usart.c:414:17: error: request for member 'Init' in something not a structure or union
uart->handle.Init.BaudRate = cfg->baud_rate;
^
../drivers/drv_usart.c:415:17: error: request for member 'Init' in something not a structure or union
uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
^
../drivers/drv_usart.c:415:38: error: 'UART_HWCONTROL_NONE' undeclared (first use in this function)
uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
^
../drivers/drv_usart.c:415:38: note: each undeclared identifier is reported only once for each function it appears in
../drivers/drv_usart.c:416:17: error: request for member 'Init' in something not a structure or union
uart->handle.Init.Mode = UART_MODE_TX_RX;

二、原因分析

以上报错都是与串口有关,而移植RT-Thread时使用了串口1作为终端串口,开始时工程默认配置好,但重新配置完Cube后,串口1确没有配置,所以出现报错!

三、解决方法

在STM32CubeMX里面配置一下我们用到的终端串口,例如我这里使用的是串口1,在cubeMX里面点击配置就行

20210503205107

bug解决

20210503210458

wechat