找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1258|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

stm32自己寫庫函數(shù),報(bào)錯(cuò)GPIO沒有定義

[復(fù)制鏈接]
回帖獎(jiǎng)勵(lì) 2 黑幣 回復(fù)本帖可獲得 2 黑幣獎(jiǎng)勵(lì)! 每人限 1 次
跳轉(zhuǎn)到指定樓層
樓主
ID:488382 發(fā)表于 2023-11-20 15:54 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
庫函數(shù):
#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;

主函數(shù):
#include "stm32f10x.h"

int main(void)
{
       
GPIOB->ODR |=((1)<<(4*0));
        //打開GPIOB端口時(shí)鐘
RCC_APB2ENR |= ((1)<< 3 );


}
void SystemInit()
{
        //do nothing
}  



報(bào)錯(cuò)main.c(6): error:  #20: identifier "GPIO_TypeDef" is undefined   
這是什么情況?庫函數(shù)編譯沒有錯(cuò),主函數(shù)里加入GPIOB就報(bào)錯(cuò),時(shí)鐘是對的
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:267719 發(fā)表于 2023-11-21 14:16 | 只看該作者
庫函數(shù):
#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)//此處大小寫不對 不應(yīng)該是GPIO_TypeDef
回復(fù)

使用道具 舉報(bào)

板凳
ID:123289 發(fā)表于 2023-11-21 15:50 | 只看該作者
誠如是,自己依CPU手冊地址,補(bǔ)充定義一下即可。
回復(fù)

使用道具 舉報(bào)

地板
ID:1088099 發(fā)表于 2023-11-21 16:58 | 只看該作者
自己注意一下大小寫。結(jié)構(gòu)體定義是:GPIO_Typedef,庫函數(shù)中:GPIO_TypeDef
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表