老外做的汉语网站,wordpress代码高亮插件,免费网站申请域名39939cn,黑龙江省建设教育网站查询1、标准外设库获取
第一步#xff0c;首先获取标准外设库#xff0c;可以从官网进行下载。
https://www.st.com.cn/zh/embedded-software/stm32-standard-peripheral-libraries.html
根据自己的型号选择不同的系列#xff0c;我这里选择是STM32F1系列 下载最新版本V3.6首先获取标准外设库可以从官网进行下载。
https://www.st.com.cn/zh/embedded-software/stm32-standard-peripheral-libraries.html
根据自己的型号选择不同的系列我这里选择是STM32F1系列 下载最新版本V3.6点击获取版本后需要进行登录账号没有账号的话可以填写邮箱ST官方会通过邮件的方式自动发送下载链接一般点击之后几分钟之内就会收到邮件邮件里面点击链接进行获取软件。 2、标准库模板搭建
在标准库模块搭建之前需要做好下面工作keill安装不做过多介绍pack包可以在keill在线安装也可以通过官网下载安装标准库第一步已经完成。
已经安装好 Keil 软件已经安装好 STM32F1xx 的 Pack 包已经下载好 STM32F1xx 标准固件库
2.1、工程文件目录创建
Project:放工程文件编译文件等。Firmware放 ARM 内核文件标准外设库文件等。Hardware放开发板的硬件驱动文件。User放 main 函数stm32f4xx_it 文件systick 文件。Doc: 放 readme.txt 文件工程说明文件。 2.2、固件库移植
下载官方标准固件库之后得到是是一个zip压缩文件将文件解压。 然后将en.stsw-stm32054_v3-6-0\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries 文件夹下的内容全部拷贝到新建目录的Firmware 下 2.3、程序入口移植
找到我们的固件库的下载目录将en.stsw-stm32054_v3-6-0\STM32F10x_StdPeriph_Lib_V3.6.0\Project\STM32F10x_StdPeriph_Template中的如下文件进行拷贝 将这些文件全部都拷贝到我们的新建目录User文件下 2.4、Keil工程相关配置
打开 keil点击最上面的 Project 选项卡选择 New uVision Project 选项新建一个工程 选择保存路径为我们刚才创建的文件夹下的 Project文件名为 STM32Template然后点击保存 现在我们工程创建好了下一步选择对应芯片型号 确定所需芯片之后弹出 RTE 的环境配置对话框选择工程所需的组件不用配置,点击取消 下一步分组创建将相应文件添加到分组中 创建完分组左边项目览 如下图所示Firmare中存放着我们的标准外设文件。根据需要进行添加 需要注意不同103的启动文件不一样根据自己的型号进行选择我这边是STMF103C6T6,32k内存属于小容量芯片选择startup_stm32f10x_ld.s 如何选择可以看这下面两个图片了解自己的芯片内存大小选择合适的启定文件导入。 导入之后下一步进入工程配置
点击魔法棒进入配置在Target中选择V6.21。 output中勾选Browse infomation勾选之后编译的时候自动生成hex文件。 在C/C中按照如下图进行配置include Path为文件路径根据自己分组进行添加。 在Debug选择自己的烧录方式 2.5、增加延时函数
在User中增加systick.h和systick.c
/*!\file systick.h\brief the header file of systick\version 2016-08-15, V1.0.0, firmware for GD32F4xx\version 2018-12-12, V2.0.0, firmware for GD32F4xx\version 2020-09-30, V2.1.0, firmware for GD32F4xx\version 2022-03-09, V3.0.0, firmware for GD32F4xx
*//*Copyright (c) 2022, GigaDevice Semiconductor Inc.Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/#ifndef SYS_TICK_H
#define SYS_TICK_H#include stdint.h/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);void delay_1us(uint32_t count);#endif /* SYS_TICK_H */
/*!\file systick.c\brief the systick configuration file\version 2024-01-15, V3.2.0, firmware for GD32F4xx
*//*Copyright (c) 2024, GigaDevice Semiconductor Inc.Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/#include stm32f10x.h
#include systick.hvolatile static uint32_t delay;/*!\brief configure systick\param[in] none\param[out] none\retval none
*/
void systick_config(void)
{/* setup systick timer for 1000000Hz interrupts */if(SysTick_Config(SystemCoreClock / 1000000U)) {/* capture error */while(1) {}}/* configure the systick handler priority */NVIC_SetPriority(SysTick_IRQn, 0x00U);
}/*!\brief delay a time in milliseconds\param[in] count: count in milliseconds\param[out] none\retval none
*/
void delay_1ms(uint32_t count)
{delay count*1000;while(0U ! delay) {}
}//睡眠1us1/1000ms
void delay_1us(uint32_t count)
{delay count;while(0U ! delay) {}
}/*!\brief delay decrement\param[in] none\param[out] none\retval none
*/
void delay_decrement(void)
{if(0U ! delay) {delay--;}
}打开stm32f10x_it.c拉到最后然后删除 2.6、程序代码修改
打开 main.c 文件删除一些不必要的代码加上系统时钟剩余部分如下
#include stm32f10x.h
#include stdio.h
#include systick.hint main(void)
{
//系统滴答时钟初始化
systick_config();while (1){}
}在stm32f10x_it.h中添加头文件systick.h
3、测试程序
点亮PC13,每秒进行亮灭闪烁。
#include stm32f10x.h
#include stdio.h
#include systick.h//PC13 GPIO初始化void gpio_config() {//开启时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //开启GPIOC的时钟//使用各个外设前必须开启时钟否则对外设的操作无效/*GPIO初始化*///定义结构体变量GPIO_InitTypeDef GPIO_InitStruct;//GPIO引脚赋值为第13号引脚GPIO_InitStruct.GPIO_Pin GPIO_Pin_13;//GPIO速度赋值为50MHzGPIO_InitStruct.GPIO_Speed GPIO_Speed_50MHz;//GPIO模式赋值为推挽输出模式GPIO_InitStruct.GPIO_Mode GPIO_Mode_Out_PP;//将赋值后的构体变量传递给GPIO_Init函数GPIO_Init(GPIOC,GPIO_InitStruct);}int main(void)
{//系统滴答时钟初始化systick_config();//GPIO初始化gpio_config();while (1){//引脚设置为低电平GPIO_ResetBits(GPIOC,GPIO_Pin_13);//延时1000msdelay_1ms(1000);//引脚设置为高电平GPIO_SetBits(GPIOC,GPIO_Pin_13);//延时1000msdelay_1ms(1000);}
}
4、问题与解决
1、STM32报错Error: L6218E: Undefined symbol assert_param .\Objects\STMF103FC6T6.axf: Error: L6218E: Undefined symbol assert_param (referred from stm32f10x_gpio.o).
在C\C设置一栏中输入USE_STDPERIPH_DRIVER使宏生效即可解决问题 2、../User/stm32f10x_it.c(136): error: call to undeclared function delay_decreme
delay_decreme未定义需要在stm32f10x_it.h中添加头文件systick.h
../User/stm32f10x_it.c(136): error: call to undeclared function delay_decrement; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]136 | delay_decrement(); #ifndef __STM32F10x_IT_H
#define __STM32F10x_IT_H#ifdef __cplusplusextern C {
#endif /* Includes ------------------------------------------------------------------*/
#include stm32f10x.h
#include systick.h
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);#ifdef __cplusplus
}
#endif#endif /* __STM32F10x_IT_H */ 文章转载自: http://www.morning.gczzm.cn.gov.cn.gczzm.cn http://www.morning.smpmn.cn.gov.cn.smpmn.cn http://www.morning.fxwkl.cn.gov.cn.fxwkl.cn http://www.morning.touziyou.cn.gov.cn.touziyou.cn http://www.morning.mllmm.cn.gov.cn.mllmm.cn http://www.morning.jkmjm.cn.gov.cn.jkmjm.cn http://www.morning.tpyrn.cn.gov.cn.tpyrn.cn http://www.morning.xpqyf.cn.gov.cn.xpqyf.cn http://www.morning.ftmzy.cn.gov.cn.ftmzy.cn http://www.morning.klwxh.cn.gov.cn.klwxh.cn http://www.morning.kdrly.cn.gov.cn.kdrly.cn http://www.morning.lpyjq.cn.gov.cn.lpyjq.cn http://www.morning.lgrkr.cn.gov.cn.lgrkr.cn http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.jcnmy.cn.gov.cn.jcnmy.cn http://www.morning.jyznn.cn.gov.cn.jyznn.cn http://www.morning.cjxqx.cn.gov.cn.cjxqx.cn http://www.morning.lkbdy.cn.gov.cn.lkbdy.cn http://www.morning.ndmbz.cn.gov.cn.ndmbz.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.krfpj.cn.gov.cn.krfpj.cn http://www.morning.qnrpj.cn.gov.cn.qnrpj.cn http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn http://www.morning.bfycr.cn.gov.cn.bfycr.cn http://www.morning.qpsxz.cn.gov.cn.qpsxz.cn http://www.morning.kgfsz.cn.gov.cn.kgfsz.cn http://www.morning.dyxzn.cn.gov.cn.dyxzn.cn http://www.morning.ykrkq.cn.gov.cn.ykrkq.cn http://www.morning.fkyrk.cn.gov.cn.fkyrk.cn http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn http://www.morning.jbblf.cn.gov.cn.jbblf.cn http://www.morning.wfjyn.cn.gov.cn.wfjyn.cn http://www.morning.pyncx.cn.gov.cn.pyncx.cn http://www.morning.ejknty.cn.gov.cn.ejknty.cn http://www.morning.ltcnd.cn.gov.cn.ltcnd.cn http://www.morning.tnwgc.cn.gov.cn.tnwgc.cn http://www.morning.lgwjh.cn.gov.cn.lgwjh.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.xrksf.cn.gov.cn.xrksf.cn http://www.morning.elbae.cn.gov.cn.elbae.cn http://www.morning.dtzxf.cn.gov.cn.dtzxf.cn http://www.morning.gbpanel.com.gov.cn.gbpanel.com http://www.morning.txqsm.cn.gov.cn.txqsm.cn http://www.morning.rdlrm.cn.gov.cn.rdlrm.cn http://www.morning.wfyzs.cn.gov.cn.wfyzs.cn http://www.morning.mtqqx.cn.gov.cn.mtqqx.cn http://www.morning.qnwyf.cn.gov.cn.qnwyf.cn http://www.morning.sgbss.cn.gov.cn.sgbss.cn http://www.morning.hkgcx.cn.gov.cn.hkgcx.cn http://www.morning.hmxb.cn.gov.cn.hmxb.cn http://www.morning.pndw.cn.gov.cn.pndw.cn http://www.morning.rfwgg.cn.gov.cn.rfwgg.cn http://www.morning.frxsl.cn.gov.cn.frxsl.cn http://www.morning.kbdjn.cn.gov.cn.kbdjn.cn http://www.morning.tkzqw.cn.gov.cn.tkzqw.cn http://www.morning.xrhst.cn.gov.cn.xrhst.cn http://www.morning.rgwz.cn.gov.cn.rgwz.cn http://www.morning.nlwrg.cn.gov.cn.nlwrg.cn http://www.morning.qggxt.cn.gov.cn.qggxt.cn http://www.morning.rmxk.cn.gov.cn.rmxk.cn http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn http://www.morning.frxsl.cn.gov.cn.frxsl.cn http://www.morning.knnc.cn.gov.cn.knnc.cn http://www.morning.ggtgl.cn.gov.cn.ggtgl.cn http://www.morning.jlxqx.cn.gov.cn.jlxqx.cn http://www.morning.lydtr.cn.gov.cn.lydtr.cn http://www.morning.dlhxj.cn.gov.cn.dlhxj.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.rhfbl.cn.gov.cn.rhfbl.cn http://www.morning.pndhh.cn.gov.cn.pndhh.cn http://www.morning.yrpg.cn.gov.cn.yrpg.cn http://www.morning.tgyzk.cn.gov.cn.tgyzk.cn http://www.morning.fbylq.cn.gov.cn.fbylq.cn http://www.morning.rrwft.cn.gov.cn.rrwft.cn http://www.morning.jfcbs.cn.gov.cn.jfcbs.cn http://www.morning.jpwkn.cn.gov.cn.jpwkn.cn http://www.morning.xsfg.cn.gov.cn.xsfg.cn http://www.morning.fwkq.cn.gov.cn.fwkq.cn http://www.morning.ckfqt.cn.gov.cn.ckfqt.cn http://www.morning.trhrk.cn.gov.cn.trhrk.cn