STM32F4 开发指南(库函数版)
ALIENTEK 探索者 STM32F407 开发板教程
I
STM32F4 开发指南
V1.1–库函数版本
−ALIENTEK 探索者 STM32F407 开发板教程
STM32F4 开发指南(库函数版)
ALIENTEK 探索者 STM32F407 开发板教程
II
广州市星翼电子科技有限公司
淘宝店铺 1:http://eboard.taobao.com
淘宝店铺 2:http://openedv.taobao.com
技术支持论坛 (开源电子网) :www.openedv.com
官方网站:www.alientek.com
最新资料下载链接:http://www.openedv.com/posts/list/13912.htm
E-mail: 389063473@qq.com QQ: 389063473
咨询电话:020-38271790
传真号码:020-36773971
团队:正点原子团队
正点原子,做最全面、最优秀的嵌入式开发平台软硬件供应商。
友 情 提 示
如果您想及时免费获取“正点原子”最新资料,敬请关注正点原子
微信公众平台,我们将及时给您发布最新消息和重要资料。
关注方法:
(1)微信“扫一扫”,扫描右侧二维码,添加关注
(2)微信添加朋友公众号输入“正点原子”关注
(3)微信添加朋友输入“alientek_stm32” 关注
STM32F4 开发指南(库函数版)
ALIENTEK 探索者 STM32F407 开发板教程
III
内容简介 ........................................................................................................................ I
前言 ................................................................................................................................ 2
第一篇 硬件篇 .............................................................................................................. 4
第一章 实验平台简介 .................................................................................................. 5
1.1 ALIENTEK 探索者 STM32F4 开发板资源初探 ................................................ 5
1.2 ALIENTEK 探索者 STM32F4 开发板资源说明 ................................................ 7
1.2.1 硬件资源说明 ................................................................................................... 7
1.2.2 软件资源说明 ................................................................................................. 12
1.2.3 探索者 IO 引脚分配 ...................................................................................... 13
第二章 实验平台硬件资源详解 ................................................................................ 18
2.1 开发板原理图详解 ............................................................................................ 18
2.1.1 MCU ................................................................................................................. 18
2.1.2 引出 IO 口 ....................................................................................................... 19
2.1.3 USB 串口/串口 1 选择接口 ............................................................................ 20
2.1.4 JTAG/SWD ....................................................................................................... 21
2.1.5 SRAM ............................................................................................................... 21
2.1.6 LCD 模块接口 ................................................................................................. 22
2.1.7 复位电路 ......................................................................................................... 23
2.1.8 启动模式设置接口 ......................................................................................... 23
2.1.9 RS232 串口 ...................................................................................................... 23
2.1.10 RS485 接口 .................................................................................................... 24
2.1.11 CAN/USB 接口 .............................................................................................. 25
2.1.12 EEPROM ........................................................................................................ 25
2.1.13 光敏传感器 ................................................................................................... 26
2.1.14 SPI FLASH ..................................................................................................... 26
2.1.15 六轴加速度传感器 ....................................................................................... 27
2.1.16 温湿度传感器接口 ....................................................................................... 27
2.1.17 红外接收头 ................................................................................................... 28
2.1.18 无线模块接口 ............................................................................................... 28
2.1.19 LED ................................................................................................................ 28
2.1.20 按键 ............................................................................................................... 29
2.1.21 TPAD 电容触摸按键 ..................................................................................... 29
2.1.22 OLED/摄像头模块接口 ................................................................................ 30
STM32F4 开发指南(库函数版)
ALIENTEK 探索者 STM32F407 开发板教程
IV
2.1.23 有源蜂鸣器 ................................................................................................... 30
2.1.24 SD 卡接口 ...................................................................................................... 31
2.1.25 ATK 模块接口 ................................................................................................ 31
2.1.26 多功能端口 ................................................................................................... 32
2.1.27 以太网接口(RJ45) ................................................................................... 33
2.1.28 I2S 音频编解码器 .......................................................................................... 34
2.1.29 电源 ............................................................................................................... 34
2.1.30 电源输入输出接口 ....................................................................................... 35
2.1.31 USB 串口 ....................................................................................................... 36
2.2 开发板使用注意事项 ......................................................................................... 36
2.3 STM32F4 学习方法 ............................................................................................ 37
第二篇 软件篇 ............................................................................................................ 39
第三章 MDK5 软件入门 ............................................................................................ 40
3.1 STM32 官方标准固件库简介 ............................................................................ 40
3.1.1 库开发与寄存器开发的关系 ........................................................................ 40
3.1.2 STM32 固件库与 CMSIS 标准讲解 .......................................................... 41
3.1.3 STM32F4 官方库包介绍 ............................................................................ 42
3.1.3.1 文件夹介绍: .............................................................................................. 43
3.1.3.2 关键文件介绍: .......................................................................................... 43
3.2 MDK5 简介 ......................................................................................................... 45
3.3 新建基于 STM32F40x 固件库的 MDK5 工程模板 ........................................ 46
3.3.1 MDK5 安装步骤 .............................................................................................. 47
3.3.2 新建工程模板 .................................................................................................. 47
3.4 程序下载与调试 ................................................................................................ 74
3.4.1 STM32 串口程序下载 ..................................................................................... 74
3.4.2 JLINK 下载与调试程序 .................................................................................. 80
3.5 MDK5 使用技巧 ................................................................................................. 89
3.5.1 文本美化 ......................................................................................................... 89
3.5.2 语法检测&代码提示 ...................................................................................... 92
3.5.3 代码编辑技巧 ................................................................................................. 93
3.5.4 其他小技巧 ..................................................................................................... 97
第四章 STM32F4 开发基础知识入门 ..................................................................... 100
4.1 MDK 下 C 语言基础复习 ................................................................................ 100
STM32F4 开发指南(库函数版)
ALIENTEK 探索者 STM32F407 开发板教程
V
4.1.1 位操作 ........................................................................................................... 100
4.1.2 define 宏定义 ................................................................................................. 101
4.1.3 ifdef 条件编译 ................................................................................................ 101
4.1.4 extern 变量申明 ............................................................................................. 102
4.1.5 typedef 类型别名 ........................................................................................... 102
4.1.6 结构体 ........................................................................................................... 103
4.2 STM32F4 总线架构 .......................................................................................... 105
4.3 STM32F4 时钟系统 .......................................................................................... 106
4.3.1 STM32F4 时钟树概述 ................................................................................... 106
4.3.2 STM32F4 时钟初始化配置 ........................................................................... 109
4.3.3 STM32F4 时钟使能和配置 ........................................................................... 114
4.4 IO 引脚复用器和映射 ................................................................................... 116
4.5 STM32 NVIC 中断优先级管理 ....................................................................... 119
4.6 MDK 中寄存器地址名称映射分析 ................................................................. 123
4.7 MDK 固件库快速组织代码技巧 ..................................................................... 125
第五章 SYSTEM 文件夹介绍 ................................................................................. 131
5.1 delay 文件夹代码介绍 .......................................................... 错误!未定义书签。
5.1.1 delay_init 函数 .................................................................... 错误!未定义书签。
5.1.2 delay_us 函数 ...................................................................... 错误!未定义书签。
5.1.3 delay_xms 函数 ................................................................... 错误!未定义书签。
5.1.4 delay_ms 函数 ..................................................................... 错误!未定义书签。
5.2 sys 文件夹代码介绍 ......................................................................................... 139
5.2.1 IO 口的位操作实现 .................................................................................... 139
5.3 usart 文件夹介绍 .............................................................................................. 140
5.3.1 printf 函数支持 .............................................................................................. 141
5.3.2 uart_init 函数 .................................................................................................. 141
5.3.3 USART1_IRQHandler 函数........................................................................... 144
第三篇 实战篇 .......................................................................................................... 146
第六章 跑马灯实验 .................................................................................................. 147
6.1 STM32F4 IO 简介 ............................................................................................ 147
6.2 硬件设计 .......................................................................................................... 155
6.3 软件设计 .......................................................................................................... 155
6.4 下载验证 .......................................................................................................... 168