野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 23630|回复: 1

HAL库模板下添加新的.c .h文件出现identifier问题

[复制链接]
发表于 2021-2-4 13:45:51 | 显示全部楼层 |阅读模式
根据HALcubeF1做了个工程模板,不添加其他文件下是可以编译不报错的。
可添加了自己写的BSP.C和BSP.H后报错identifier
野火论坛202102041334575539..png
看了一下,这是个枚举类型,在stm32f1xx_hal_def.h中定义。
可我的bsp.h中已经包含了这个头文件,我自己BSP文件中也没有用这个枚举。
库中的其他外设文件都是这样写的,也没问题,不添加自己写的BSP.c时也能正常编译,添加了后就报错。
可BSP编译列表中也有这个头文件,依然报错,不知如何解决。恳请大佬教我。工程文件在最后。
野火论坛202102041340063050..png
  1. /* Define to prevent recursive inclusion -------------------------------------*/
  2. #ifndef __BSP_H
  3. #define __BSP_H

  4. /* Includes ------------------------------------------------------------------*/
  5. #include "stm32f1xx_hal_def.h"

  6. /* Exported types ------------------------------------------------------------*/

  7. /* Exported define -----------------------------------------------------------*/

  8. /* 端口引脚定义 */
  9. //R 红色灯
  10. #define R_LED_PIN                  GPIO_PIN_5               
  11. #define R_LED_GPIO_PORT            GPIOA                     
  12. //G 绿色灯
  13. #define G_LED_PIN                  GPIO_PIN_6               
  14. #define G_LED_GPIO_PORT            GPIOA                     
  15. //B 蓝色灯
  16. #define B_LED_PIN                  GPIO_PIN_7              
  17. #define B_LED_GPIO_PORT            GPIOA                       
  18. //打开LED的IO的时钟
  19. #define LED_GPIO_CLK_ENABLE()    __HAL_RCC_GPIOA_CLK_ENABLE()

  20. /* Exported constants --------------------------------------------------------*/

  21. /* Exported variables --------------------------------------------------------*/

  22. /* Exported macro ------------------------------------------------------------*/

  23. /* 定义单独控制RGB的宏 */
  24. //红绿蓝开灯
  25. #define R_LED_ON                HAL_GPIO_WritePin(R_LED_GPIO_PORT,R_LED_PIN,GPIO_PIN_SET)
  26. #define G_LED_ON                HAL_GPIO_WritePin(G_LED_GPIO_PORT,G_LED_PIN,GPIO_PIN_SET)
  27. #define B_LED_ON                HAL_GPIO_WritePin(B_LED_GPIO_PORT,B_LED_PIN,GPIO_PIN_SET)
  28. //红绿蓝关灯
  29. #define R_LED_OFF                HAL_GPIO_WritePin(R_LED_GPIO_PORT,R_LED_PIN,GPIO_PIN_RESET)
  30. #define G_LED_OFF                HAL_GPIO_WritePin(G_LED_GPIO_PORT,G_LED_PIN,GPIO_PIN_RESET)
  31. #define B_LED_OFF                HAL_GPIO_WritePin(B_LED_GPIO_PORT,B_LED_PIN,GPIO_PIN_RESET)
  32. //红绿蓝反转
  33. #define R_LED_TOGGLE                HAL_GPIO_TogglePin(R_LED_GPIO_PORT, R_LED_PIN)
  34. #define G_LED_TOGGLE                HAL_GPIO_TogglePin(G_LED_GPIO_PORT, G_LED_PIN)
  35. #define B_LED_TOGGLE                HAL_GPIO_TogglePin(B_LED_GPIO_PORT, B_LED_PIN)

  36. /* 定义基本混色的宏*/
  37. //红
  38. #define LED_RED  \
  39.                                         R_LED_ON;\
  40.                                         G_LED_OFF;\
  41.                                         B_LED_OFF
  42. //绿
  43. #define LED_GREEN                \
  44.                                         R_LED_OFF;\
  45.                                         G_LED_ON;\
  46.                                         B_LED_OFF
  47. //蓝
  48. #define LED_BLUE        \
  49.                                         R_LED_OFF;\
  50.                                         G_LED_OFF;\
  51.                                         B_LED_ON                       
  52. //黄(红+绿)                                       
  53. #define LED_YELLOW        \
  54.                                         R_LED_ON;\
  55.                                         G_LED_ON;\
  56.                                         B_LED_OFF
  57. //紫(红+蓝)
  58. #define LED_PURPLE        \
  59.                                         R_LED_ON;\
  60.                                         G_LED_OFF;\
  61.                                         B_LED_ON
  62. //青(绿+蓝)
  63. #define LED_CYAN \
  64.                                         R_LED_OFF;\
  65.                                         G_LED_ON;\
  66.                                         B_LED_ON                                       
  67. //白(红+绿+蓝)
  68. #define LED_WHITE        \
  69.                                         R_LED_ON;\
  70.                                         G_LED_ON;\
  71.                                         B_LED_ON                                       
  72. //黑(全部关闭)
  73. #define LED_RGBOFF        \
  74.                                         R_LED_OFF;\
  75.                                         G_LED_OFF;\
  76.                                         B_LED_OFF


  77. /* Exported functions prototypes----------------------------------------------*/
  78. void GPIO_Congfig(void);



  79. #endif /* __BSP_H */

复制代码
  1. /**
  2.   ******************************************************************************
  3.   * @file    NAME
  4.   * @author  WHO
  5.   * [url=home.php?mod=space&uid=41770]@brief[/url]   DO WHAT
  6.   ******************************************************************************/

  7. /* Includes ------------------------------------------------------------------*/
  8. #include "BSP.h"

  9. /* Private typedef -----------------------------------------------------------*/
  10. /* Private define ------------------------------------------------------------*/
  11. /* Private macro -------------------------------------------------------------*/
  12. /* Private constants ---------------------------------------------------------*/
  13. /* Private variables ---------------------------------------------------------*/
  14. /* Private function prototypes -----------------------------------------------*/
  15. /* Private functions ---------------------------------------------------------*/
  16. /**
  17.   * @brief  初始化按键和LED的GPIO
  18.   * @param  None
  19.   * @retval None
  20.   */
  21. void GPIO_Congfig(void)
  22. {
  23. /*定义一个GPIO_InitTypeDef类型的结构体*/
  24.     GPIO_InitTypeDef  GPIO_InitStruct;

  25.     /*开启LED相关的GPIO外设时钟*/
  26.                 LED_GPIO_CLK_ENABLE();
  27.        
  28.     /*选择要控制的GPIO引脚*/                                                                                                                          
  29.     GPIO_InitStruct.Pin = R_LED_PIN;       

  30.     /*设置引脚的输出类型为推挽输出*/
  31.     GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;  

  32.     /*设置引脚为上拉模式*/
  33.     GPIO_InitStruct.Pull  = GPIO_PULLUP;

  34.     /*设置引脚速率为高速 */   
  35.     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  36.     /*调用库函数,使用上面配置的GPIO_InitStructure初始化GPIO*/
  37.     HAL_GPIO_Init(R_LED_GPIO_PORT, &GPIO_InitStruct);       

  38.     /*选择要控制的GPIO引脚*/                                                                                                                          
  39.     GPIO_InitStruct.Pin = G_LED_PIN;       
  40.     HAL_GPIO_Init(G_LED_GPIO_PORT, &GPIO_InitStruct);       

  41.     /*选择要控制的GPIO引脚*/                                                                                                                          
  42.     GPIO_InitStruct.Pin = B_LED_PIN;       
  43.     HAL_GPIO_Init(B_LED_GPIO_PORT, &GPIO_InitStruct);       

  44.     /*关闭RGB灯*/
  45.     LED_RGBOFF;

  46. }




  47. /*********************************************END OF FILE**********************/
复制代码
STM32F1_HAL_MDK_Templates - 2021.2.3.zip (2.04 MB, 下载次数: 3)
回复

使用道具 举报

 楼主| 发表于 2021-2-4 18:44:43 | 显示全部楼层
找到问题了,要在BSP.C中添加
#include "stm32f1xx_hal.h"
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-10-6 08:23 , Processed in 0.033333 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表