STM32 第一个工程
一、找到STM32的库
1. 了解库的组成
库文件
1.1 内核文件
内核
启动文件
1.2 外设文件
.c文件
.h文件
2. 找到需要的文件
- 2.1内核文件
- 2.2启动文件
- 2.3外设文件 .c .h 如果你不确定,就全部拷贝
二、新建工程
1. 新建4个文件夹
2. 往文件里面拷贝对应的文件
CORE
FWLIB
USER
3.将工程建立在指定文件夹里面
将工程建立在USER 里面
4. 配置工程参数
1. 将4个文件夹的内容添加到工程中
1.添加.c文件
CORE
FWLIB
USER
2.添加.h文件
成功添加完.h文件的工程配置
添加宏定义
宏定义配置完毕
5.编译
工程成功了 撒花了
6. 下载
下载标志
三 、工程main.c 工程解释
//头文件
#include "stm32f10x.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
//全局变量
GPIO_InitTypeDef GPIO_InitStructure;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
//主函数
int main(void)
{
//开启外设时钟,GPIOD
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
//配置引脚 GPIOD0 2 为复用推挽输出
/* Configure PD0 and PD2 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
while (1)
{
//寄存器的方式 ,驱动引脚输出高低电平
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
}
}