【rtt问题】RT-Thread studio创建的工程,自己新建的文件中调用不到hal库中的宏定义、结构体


1、问题描述:

RT-Thread studio创建的工程自己新建的文件中调用不到hal库中的宏定义、结构体、在调用hal库的那些调用,都提示没有定义:

在这里插入图片描述
编译信息如下:

…/applications/Bsp/bsp_led_test.c: In function ‘bsp_led_test_init’:
…/applications/Bsp/bsp_led_test.c:36:5: error: unknown type name ‘GPIO_InitTypeDef’
GPIO_InitTypeDef gpio_init_struct;
^
…/applications/Bsp/bsp_led_test.c:21:49: warning: implicit declaration of function ‘__HAL_RCC_GPIOC_CLK_ENABLE’ [-Wimplicit-function-declaration]
#define LED_TEST_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOC_CLK_ENABLE(); }while(0) /* PC鍙f椂閽熶娇鑳? /
^
…/applications/Bsp/bsp_led_test.c:38:5: note: in expansion of macro ‘LED_TEST_GPIO_CLK_ENABLE’
LED_TEST_GPIO_CLK_ENABLE(); /
LED_test鏃堕挓浣胯兘 /
^
…/applications/Bsp/bsp_led_test.c:40:21: error: request for member ‘Pin’ in something not a structure or union
gpio_init_struct.Pin = LED_TEST_GPIO_PIN; /
LED_test寮曡剼 /
^
…/applications/Bsp/bsp_led_test.c:20:45: error: ‘GPIO_PIN_13’ undeclared (first use in this function)
#define LED_TEST_GPIO_PIN GPIO_PIN_13
^
…/applications/Bsp/bsp_led_test.c:40:28: note: in expansion of macro ‘LED_TEST_GPIO_PIN’
gpio_init_struct.Pin = LED_TEST_GPIO_PIN; /
LED_test寮曡剼 /
^
…/applications/Bsp/bsp_led_test.c:20:45: note: each undeclared identifier is reported only once for each function it appears in
#define LED_TEST_GPIO_PIN GPIO_PIN_13
^
…/applications/Bsp/bsp_led_test.c:40:28: note: in expansion of macro ‘LED_TEST_GPIO_PIN’
gpio_init_struct.Pin = LED_TEST_GPIO_PIN; /
LED_test寮曡剼 /
^
…/applications/Bsp/bsp_led_test.c:41:21: error: request for member ‘Mode’ in something not a structure or union
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP; /
鎺ㄦ尳杈撳嚭 /
^
…/applications/Bsp/bsp_led_test.c:41:29: error: ‘GPIO_MODE_OUTPUT_PP’ undeclared (first use in this function)
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP; /
鎺ㄦ尳杈撳嚭 /
^
…/applications/Bsp/bsp_led_test.c:42:21: error: request for member ‘Pull’ in something not a structure or union
gpio_init_struct.Pull = GPIO_PULLUP; /
涓婃媺 /
^
…/applications/Bsp/bsp_led_test.c:42:29: error: ‘GPIO_PULLUP’ undeclared (first use in this function)
gpio_init_struct.Pull = GPIO_PULLUP; /
涓婃媺 /
^
…/applications/Bsp/bsp_led_test.c:43:21: error: request for member ‘Speed’ in something not a structure or union
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH; /
楂橀?? /
^
…/applications/Bsp/bsp_led_test.c:43:30: error: ‘GPIO_SPEED_FREQ_HIGH’ undeclared (first use in this function)
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH; /
楂橀?? /
^
…/applications/Bsp/bsp_led_test.c:44:5: warning: implicit declaration of function ‘HAL_GPIO_Init’ [-Wimplicit-function-declaration]
HAL_GPIO_Init(LED_TEST_GPIO_PORT, &gpio_init_struct); /
鍒濆鍖朙ED_test寮曡剼 /
^
…/applications/Bsp/bsp_led_test.c:19:45: error: ‘GPIOC’ undeclared (first use in this function)
#define LED_TEST_GPIO_PORT GPIOC
^
…/applications/Bsp/bsp_led_test.c:44:19: note: in expansion of macro ‘LED_TEST_GPIO_PORT’
HAL_GPIO_Init(LED_TEST_GPIO_PORT, &gpio_init_struct); /
鍒濆鍖朙ED_test寮曡剼 */
^
make: *** [applications/Bsp/subdir.mk:18: applications/Bsp/bsp_led_test.o] Error 1
make: *** Waiting for unfinished jobs…
“make -j4 all” terminated with exit code 2. Build might be incomplete.

2、原因分析:

网上有说把hal库中的stm32f1xx_hal_conf.h中的#define HAL_GPIO_MODULE_ENABLED宏定义打开,但是实测无效:
在这里插入图片描述

2、问题解决:

在自己新建的驱动文件中去包含头文件:

#include “stm32f1xx_hal.h”

在这里插入图片描述
注意:后续在初始化DAC驱动时候时候,bsp_dac_1.c源文件已包含"stm32f1xx_hal.h"头文件,但是还是报错调不到库函数,后来发现是stm32f1xx_hal_conf.h 中宏定义没有打开,所以不要忘记了这一步操作;

#define HAL_DAC_MODULE_ENABLED
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42640280/article/details/128935600