找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 435|回复: 3
收起左侧

stm32自己写库函数,报错GPIO没有定义

[复制链接]
回帖奖励 2 黑币 回复本帖可获得 2 黑币奖励! 每人限 1 次
ID:488382 发表于 2023-11-20 15:54 | 显示全部楼层 |阅读模式
库函数:
#define PERIPH_BASE          ((unsigned int)0x40000000)
#define APB1PERIPH_BASE       PERIPH_BASE   
#define APB2PERIPH_BASE       (PERIPH_BASE+0x10000)   
#define AHBPERIPH_BASE       (PERIPH_BASE+0x20000)   
#define RCC_BASE             (AHBPERIPH_BASE+0x1000)
#define GPIOB_BASE           (APB2PERIPH_BASE+0x0C00)
#define RCC_APB2ENR           *(unsigned int*)(RCC_BASE+0x18)
#define GPIOB     ((GPIO_TypeDef*)GPIOB_BASE)
typedef unsigned int   uint32_t;
typedef unsigned short uint16_t;
typedef struct
{ uint32_t CRL;
        uint32_t CRH;
        uint32_t IDR;
        uint32_t ODR;
        uint32_t BSRR;
        uint32_t BRR;
        uint32_t LCKR;
}
GPIO_Typedef;

主函数:
#include "stm32f10x.h"

int main(void)
{
       
GPIOB->ODR |=((1)<<(4*0));
        //打开GPIOB端口时钟
RCC_APB2ENR |= ((1)<< 3 );


}
void SystemInit()
{
        //do nothing
}  



报错main.c(6): error:  #20: identifier "GPIO_TypeDef" is undefined   
这是什么情况?库函数编译没有错,主函数里加入GPIOB就报错,时钟是对的
回复

使用道具 举报

ID:267719 发表于 2023-11-21 14:16 | 显示全部楼层
库函数:
#define PERIPH_BASE          ((unsigned int)0x40000000)
#define APB1PERIPH_BASE       PERIPH_BASE   
#define APB2PERIPH_BASE       (PERIPH_BASE+0x10000)   
#define AHBPERIPH_BASE       (PERIPH_BASE+0x20000)   
#define RCC_BASE             (AHBPERIPH_BASE+0x1000)
#define GPIOB_BASE           (APB2PERIPH_BASE+0x0C00)
#define RCC_APB2ENR           *(unsigned int*)(RCC_BASE+0x18)
typedef unsigned int   uint32_t;
typedef unsigned short uint16_t;
typedef struct
{ uint32_t CRL;
        uint32_t CRH;
        uint32_t IDR;
        uint32_t ODR;
        uint32_t BSRR;
        uint32_t BRR;
        uint32_t LCKR;
}
GPIO_Typedef;#define GPIOB     ((GPIO_Typedef*)GPIOB_BASE)//此处大小写不对 不应该是GPIO_TypeDef
回复

使用道具 举报

ID:123289 发表于 2023-11-21 15:50 | 显示全部楼层
诚如是,自己依CPU手册地址,补充定义一下即可。
回复

使用道具 举报

ID:1088099 发表于 2023-11-21 16:58 | 显示全部楼层
自己注意一下大小写。结构体定义是:GPIO_Typedef,库函数中:GPIO_TypeDef
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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