文章目录
一: stem32的简单程序编译1·新建文件夹2. 选择stem32芯片3·对run-time environment进行设置4·编写程序5.保存6.调试7.点击start debug 开始操作8,再次点击start debug结束
二:总结
一: stem32的简单程序编译
1·新建文件夹
2. 选择stem32芯片
3·对run-time environment进行设置
4·编写程序
#define PERIPH_BASE ((unsigned int)0x40000000)
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
#define GPIOA_BASE (APB2PERIPH_BASE + 0x0800)
#define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00)
#define GPIOC_BASE (APB2PERIPH_BASE + 0x1000)
#define GPIOD_BASE (APB2PERIPH_BASE + 0x1400)
#define GPIOE_BASE (APB2PERIPH_BASE + 0x1800)
#define GPIOF_BASE (APB2PERIPH_BASE + 0x1C00)
#define GPIOG_BASE (APB2PERIPH_BASE + 0x2000)
#define GPIOA_ODR_Addr (GPIOA_BASE+12)
#define GPIOB_ODR_Addr (GPIOB_BASE+12)
#define GPIOC_ODR_Addr (GPIOC_BASE+12)
#define GPIOD_ODR_Addr (GPIOD_BASE+12)
#define GPIOE_ODR_Addr (GPIOE_BASE+12)
#define GPIOF_ODR_Addr (GPIOF_BASE+12)
#define GPIOG_ODR_Addr (GPIOG_BASE+12)
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define LED0 MEM_ADDR(BITBAND(GPIOA_ODR_Addr,8))
typedef struct
{
volatile unsigned int CR
;
volatile unsigned int CFGR
;
volatile unsigned int CIR
;
volatile unsigned int APB2RSTR
;
volatile unsigned int APB1RSTR
;
volatile unsigned int AHBENR
;
volatile unsigned int APB2ENR
;
volatile unsigned int APB1ENR
;
volatile unsigned int BDCR
;
volatile unsigned int CSR
;
} RCC_TypeDef
;
#define RCC ((RCC_TypeDef *)0x40021000)
typedef struct
{
volatile unsigned int CRL
;
volatile unsigned int CRH
;
volatile unsigned int IDR
;
volatile unsigned int ODR
;
volatile unsigned int BSRR
;
volatile unsigned int BRR
;
volatile unsigned int LCKR
;
} GPIO_TypeDef
;
#define GPIOA ((GPIO_TypeDef *)GPIOA_BASE)
void LEDInit( void )
{
RCC
->APB2ENR
|=1<<2;
GPIOA
->CRH
&=0XFFFFFFF0;
GPIOA
->CRH
|=0X00000003;
}
void Delay_ms( volatile unsigned int t
)
{
unsigned int i
,n
;
for (n
=0;n
<t
;n
++)
for (i
=0;i
<800;i
++);
}
int main(void)
{
LEDInit();
while (1)
{
LED0
=0;
Delay_ms(500);
LED0
=1;
Delay_ms(500);
}
}
5.保存
注意:一定要·add sourcegroup,不然会出现没有错误· 如下图·: 最后成功编译:
6.调试
(1)首先点击dedug进行如下设置:
(2)点击setting后弹出下图点OK
7.点击start debug 开始操作
8,再次点击start debug结束
二:总结
第一次使用的话过程比较繁琐,很多步骤会忘记,就会导致失败,要注意细。