STM32的标准库环境搭建
一、建立文件夹
Buid
文件夹存放编译后的输出文件,如HEX文件等。
Doc
文件夹存放开发所需的资料,如芯片的参考手册等。
Driver
文件夹存放寄存器库和标准库,这将是移植的重点。
Lib
文件夹存放开发中的模块库,如MPU6050库等。
Project
文件夹存放keil的项目文件。
USER
文件夹存放我们的用户文件,如main.c文件等。
keilkill.bat
文件是用来快速清理编译后产生的文件的,可以减轻文件的体积。
二、移植寄存器库和标准库文件
下载标准库文件
前往ST官网下载标准库文件
解压得到
开始移植文件
打开之前建立的Driver
文件夹,新建一个名为CMSIS
的文件夹和一个名为StdPeriph_Driver
前者来存放基本的固件库(寄存器库),我们依次放入内核文件、启动文件、系统初始化文件。后者来存放我们的标准库文件
这些文件我们可以从之前解压的STM32F10x_StdPeriph_Lib_V3.6.0
文件中找到。
已F10x为例,
内核文件在
E:\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\CMSIS\CM3\CoreSupport
启动文件在
E:\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm
宏定义文件和系统初始化文件在
E:\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x
全部将其移入CMSIS
文件夹。
然后打开之前建立的StdPeriph_Driver
文件夹
我们将移入这些文件
已F10x为例,
标准库源代码文件在
E:\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries\STM32F10x_StdPeriph_Driver
用户配置文件和中断回调函数文件在
E:\STM32F10x_StdPeriph_Lib_V3.6.0\Project\STM32F10x_StdPeriph_Template
将文件移入StdPeriph_Driver
文件夹。
提示
这里提供stm32f10x下载链接,直接从我服务器里下载,速度较慢。(点此下载)启动文件HD、MD、LD为单片机FLASH容量,如果是f103c8t6选md就可以
三、新建项目并配置
打开keil新建项目选择对应芯片,如没有该芯片前往官网下载芯片支持包点此前往搜索下载,将项目新建在之前创建的Project
文件夹下。
依次添加组
将文件全部移入对应文件夹(可只移入.c
文件和.s
文件)。
点开魔法棒添加全局宏定义USE_STDPERIPH_DRIVER
来启用标准库。
可添加STM32F10X_LD等宏定义选择容量,不添加默认应该为MD
勾选C99Mode
。
添加include Paths
,将所有有代码的文件路径都添加上
转到Output栏和Listing栏,设置路径到之前建立的Build
文件夹,并勾选Create HEX File
。
提示
点开系统初始化文件可以配置时钟频率
最后在main.c
里copy一下代码点灯测试即可。
#include "stm32f10x.h"
void Delay(uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
int main(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(1){
GPIO_ResetBits(GPIOC, GPIO_Pin_13);
Delay(0xfffff);
GPIO_SetBits(GPIOC, GPIO_Pin_13);
Delay(0xfffff);
}
}
0w0
Ahaa, its fastidious discussion on the topic of this post at this place at this webpage, I
have read all that, so at this time me also commenting here.
ST已经停止了对标准库的支持,建议使用Hal或LL库进行学习和开发( ๑´•ω•)
Pretty! This has been an incredibly wonderful article.
Thanks for supplying this information.
Hmm is anyone else having problems with the pictures on this blog loading?
I'm trying to find out if its a problem on my end or if it's the blog.
Any feed-back would be greatly appreciated.
I was curious if you ever considered changing the structure
of your website? Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect
with it better. Youve got an awful lot of text for only having 1 or two pictures.
Maybe you could space it out better?
Hello, I would like to subscribe for this web site to
obtain latest updates, so where can i do it please assist.
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
You clearly know what youre talking about, why waste your
intelligence on just posting videos to your blog when you
could be giving us something enlightening to read?
Hey! I know this is kinda off topic however I'd figured I'd ask.
Would you be interested in exchanging links or maybe guest
authoring a blog post or vice-versa? My website goes
over a lot of the same topics as yours and I feel we could greatly benefit from each other.
If you happen to be interested feel free to send me an email.
I look forward to hearing from you! Superb blog by the way!