1、问题描述:
用RT-Thread studio软件生成的项目代码中插件cubemx去配置其他的外设,然后生成代码之后,也参考了网上的做法,添加了scanscript和weak cubemx生成的main函数,但是还是报错,跟网上遇到的情况不一样;
前面操作在RT-Thread studio使用(持续更新)
错误的的提示:
16:22:09 **** Incremental Build of configuration Debug for project test2 ****
make -j4 all
arm-none-eabi-gcc "../drivers/drv_usart.c"
../drivers/drv_usart.c:28:8: error: unknown type name 'UART_HandleTypeDef'
static UART_HandleTypeDef handle;
^
../drivers/drv_usart.c:380:30: error: unknown type name 'UART_HandleTypeDef'
__WEAK void HAL_UART_MspInit(UART_HandleTypeDef *huart)
^
../drivers/drv_usart.c: In function 'stm32_configure':
../drivers/drv_usart.c:393:11: error: request for member 'Instance' in something not a structure or union
handle.Instance = config->Instance;
^
../drivers/drv_usart.c:394:11: error: request for member 'Init' in something not a structure or union
handle.Init.BaudRate = 115200;
^
../drivers/drv_usart.c:395:11: error: request for member 'Init' in something not a structure or union
handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
^
../drivers/drv_usart.c:395:32: error: 'UART_HWCONTROL_NONE' undeclared (first use in this function)
handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
^
../drivers/drv_usart.c:395:32: note: each undeclared identifier is reported only once for each function it appears in
../drivers/drv_usart.c:396:11: error: request for member 'Init' in something not a structure or union
handle.Init.Mode = UART_MODE_TX_RX;
^
../drivers/drv_usart.c:396:32: error: 'UART_MODE_TX_RX' undeclared (first use in this function)
handle.Init.Mode = UART_MODE_TX_RX;
^
../drivers/drv_usart.c:397:11: error: request for member 'Init' in something not a structure or union
handle.Init.OverSampling = UART_OVERSAMPLING_16;
^
../drivers/drv_usart.c:397:32: error: 'UART_OVERSAMPLING_16' undeclared (first use in this function)
handle.Init.OverSampling = UART_OVERSAMPLING_16;
^
../drivers/drv_usart.c:398:11: error: request for member 'Init' in something not a structure or union
handle.Init.WordLength = UART_WORDLENGTH_8B;
^
../drivers/drv_usart.c:398:32: error: 'UART_WORDLENGTH_8B' undeclared (first use in this function)
handle.Init.WordLength = UART_WORDLENGTH_8B;
^
../drivers/drv_usart.c:399:11: error: request for member 'Init' in something not a structure or union
handle.Init.StopBits = UART_STOPBITS_1;
^
../drivers/drv_usart.c:399:32: error: 'UART_STOPBITS_1' undeclared (first use in this function)
handle.Init.StopBits = UART_STOPBITS_1;
^
../drivers/drv_usart.c:400:11: error: request for member 'Init' in something not a structure or union
handle.Init.Parity = UART_PARITY_NONE;
^
../drivers/drv_usart.c:400:32: error: 'UART_PARITY_NONE' undeclared (first use in this function)
handle.Init.Parity = UART_PARITY_NONE;
^
../drivers/drv_usart.c:402:9: warning: implicit declaration of function 'HAL_UART_Init' [-Wimplicit-function-declaration]
if (HAL_UART_Init(&handle) != HAL_OK)
^
../drivers/drv_usart.c: In function 'rt_hw_console_output':
../drivers/drv_usart.c:429:13: warning: implicit declaration of function 'HAL_UART_Transmit' [-Wimplicit-function-declaration]
HAL_UART_Transmit(&handle, (uint8_t *)&a, 1, 1);
^
../drivers/drv_usart.c: In function 'rt_hw_console_getchar':
../drivers/drv_usart.c:440:9: warning: implicit declaration of function '__HAL_UART_GET_FLAG' [-Wimplicit-function-declaration]
if (__HAL_UART_GET_FLAG(&handle, UART_FLAG_RXNE) != RESET)
^
../drivers/drv_usart.c:440:38: error: 'UART_FLAG_RXNE' undeclared (first use in this function)
if (__HAL_UART_GET_FLAG(&handle, UART_FLAG_RXNE) != RESET)
^
../drivers/drv_usart.c:447:20: error: request for member 'Instance' in something not a structure or union
ch = handle.Instance->DR & 0xff;
^
../drivers/drv_usart.c:452:41: error: 'UART_FLAG_ORE' undeclared (first use in this function)
if(__HAL_UART_GET_FLAG(&handle, UART_FLAG_ORE) != RESET)
^
../drivers/drv_usart.c:454:13: warning: implicit declaration of function '__HAL_UART_CLEAR_OREFLAG' [-Wimplicit-function-declaration]
__HAL_UART_CLEAR_OREFLAG(&handle);
^
../drivers/drv_usart.c: At top level:
../drivers/drv_usart.c:251:17: warning: 'stm32_gpio_configure' defined but not used [-Wunused-function]
static rt_err_t stm32_gpio_configure(struct stm32_uart_config *config)
^
make: *** [drivers/subdir.mk:27: drivers/drv_usart.o] Error 1
"make -j4 all" terminated with exit code 2. Build might be incomplete.
16:22:10 Build Failed. 20 errors, 5 warnings. (took 1s.459ms)
2、原因分析:
移植RT-Thread时使用了串口1作为RT-Thread studio上面的终端串口,开始时工程默认配置好,但重新配置完Cube后,串口1确没有配置,所以出现报错!
3、问题解决:
我的实验的板子是stm32f103c8t6,看数据手册配置好usart1,然后重新生成工程:
然后重新编译之后,就解决问题了