標(biāo)題: stm32自己寫庫函數(shù),報錯GPIO沒有定義 [打印本頁]

作者: 教教我單片機(jī)把    時間: 2023-11-20 15:54
標(biāo)題: stm32自己寫庫函數(shù),報錯GPIO沒有定義
庫函數(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端口時鐘
RCC_APB2ENR |= ((1)<< 3 );


}
void SystemInit()
{
        //do nothing
}  



報錯main.c(6): error:  #20: identifier "GPIO_TypeDef" is undefined   
這是什么情況?庫函數(shù)編譯沒有錯,主函數(shù)里加入GPIOB就報錯,時鐘是對的

作者: carpcarey    時間: 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

作者: yzwzfyz    時間: 2023-11-21 15:50
誠如是,自己依CPU手冊地址,補(bǔ)充定義一下即可。
作者: 金玉之食    時間: 2023-11-21 16:58
自己注意一下大小寫。結(jié)構(gòu)體定義是:GPIO_Typedef,庫函數(shù)中:GPIO_TypeDef




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1