做公司網(wǎng)站 找誰(shuí)做網(wǎng)絡(luò)營(yíng)銷(xiāo)主要學(xué)什么
1、標(biāo)準(zhǔn)外設(shè)庫(kù)獲取
第一步,首先獲取標(biāo)準(zhǔn)外設(shè)庫(kù),可以從官網(wǎng)進(jìn)行下載。
https://www.st.com.cn/zh/embedded-software/stm32-standard-peripheral-libraries.html
根據(jù)自己的型號(hào)選擇不同的系列,我這里選擇是STM32F1系列
下載最新版本V3.6,點(diǎn)擊獲取版本后,需要進(jìn)行登錄賬號(hào),沒(méi)有賬號(hào)的話(huà),可以填寫(xiě)郵箱,ST官方會(huì)通過(guò)郵件的方式自動(dòng)發(fā)送下載鏈接,一般點(diǎn)擊之后幾分鐘之內(nèi)就會(huì)收到郵件,郵件里面點(diǎn)擊鏈接進(jìn)行獲取軟件。
2、標(biāo)準(zhǔn)庫(kù)模板搭建
在標(biāo)準(zhǔn)庫(kù)模塊搭建之前,需要做好下面工作,keill安裝不做過(guò)多介紹,pack包可以在keill在線(xiàn)安裝,也可以通過(guò)官網(wǎng)下載安裝,標(biāo)準(zhǔn)庫(kù)第一步已經(jīng)完成。
- 已經(jīng)安裝好 Keil 軟件
- 已經(jīng)安裝好 STM32F1xx 的 Pack 包
- 已經(jīng)下載好 STM32F1xx 標(biāo)準(zhǔn)固件庫(kù)
2.1、工程文件目錄創(chuàng)建
- Project:放工程文件,編譯文件等。
- Firmware:放 ARM 內(nèi)核文件,標(biāo)準(zhǔn)外設(shè)庫(kù)文件等。
- Hardware:放開(kāi)發(fā)板的硬件驅(qū)動(dòng)文件。
- User:放 main 函數(shù),stm32f4xx_it 文件,systick 文件。
- Doc: 放 readme.txt 文件,工程說(shuō)明文件。
2.2、固件庫(kù)移植
下載官方標(biāo)準(zhǔn)固件庫(kù)之后,得到是是一個(gè)zip壓縮文件,將文件解壓。
然后將en.stsw-stm32054_v3-6-0\STM32F10x_StdPeriph_Lib_V3.6.0\Libraries
文件夾下的內(nèi)容全部拷貝到新建目錄的Firmware 下
2.3、程序入口移植
找到我們的固件庫(kù)的下載目錄,將en.stsw-stm32054_v3-6-0\STM32F10x_StdPeriph_Lib_V3.6.0\Project\STM32F10x_StdPeriph_Template
中的如下文件進(jìn)行拷貝
將這些文件全部都拷貝到我們的新建目錄User文件下
2.4、Keil工程相關(guān)配置
打開(kāi) keil,點(diǎn)擊最上面的 Project 選項(xiàng)卡,選擇 New uVision Project 選項(xiàng)新建一個(gè)工程
選擇保存路徑為我們剛才創(chuàng)建的文件夾下的 Project,文件名為 STM32Template,然后點(diǎn)擊保存
現(xiàn)在我們工程創(chuàng)建好了,下一步選擇對(duì)應(yīng)芯片型號(hào)
確定所需芯片之后,彈出 RTE 的環(huán)境配置對(duì)話(huà)框,選擇工程所需的組件,不用配置,點(diǎn)擊取消
下一步分組創(chuàng)建,將相應(yīng)文件添加到分組中
創(chuàng)建完分組左邊項(xiàng)目覽 如下圖所示,Firmare中存放著我們的標(biāo)準(zhǔn)外設(shè)文件。根據(jù)需要進(jìn)行添加,
需要注意,不同103的啟動(dòng)文件不一樣,根據(jù)自己的型號(hào)進(jìn)行選擇,我這邊是STMF103C6T6,32k內(nèi)存,屬于小容量芯片,選擇startup_stm32f10x_ld.s
如何選擇可以看這下面兩個(gè)圖片,了解自己的芯片內(nèi)存大小選擇合適的啟定文件導(dǎo)入。
導(dǎo)入之后下一步進(jìn)入工程配置
點(diǎn)擊魔法棒,進(jìn)入配置,在Target中選擇V6.21。
output中勾選Browse infomation,勾選之后編譯的時(shí)候自動(dòng)生成hex文件。
在C/C++中按照如下圖進(jìn)行配置,include Path為文件路徑,根據(jù)自己分組進(jìn)行添加。
在Debug選擇自己的燒錄方式
2.5、增加延時(shí)函數(shù)
在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.h"volatile 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) {}
}//睡眠1us=1/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--;}
}
打開(kāi)"stm32f10x_it.c"拉到最后,然后刪除
2.6、程序代碼修改
打開(kāi) main.c 文件,刪除一些不必要的代碼,加上系統(tǒng)時(shí)鐘,剩余部分如下:
#include "stm32f10x.h"
#include <stdio.h>
#include "systick.h"int main(void)
{
//系統(tǒng)滴答時(shí)鐘初始化
systick_config();while (1){}
}
在stm32f10x_it.h中添加頭文件systick.h
3、測(cè)試程序
點(diǎn)亮PC13,每秒進(jìn)行亮滅閃爍。
#include "stm32f10x.h"
#include <stdio.h>
#include "systick.h"//PC13 GPIO初始化void gpio_config() {//開(kāi)啟時(shí)鐘RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //開(kāi)啟GPIOC的時(shí)鐘//使用各個(gè)外設(shè)前必須開(kāi)啟時(shí)鐘,否則對(duì)外設(shè)的操作無(wú)效/*GPIO初始化*///定義結(jié)構(gòu)體變量GPIO_InitTypeDef GPIO_InitStruct;//GPIO引腳,賦值為第13號(hào)引腳GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;//GPIO速度,賦值為50MHzGPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;//GPIO模式,賦值為推挽輸出模式GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;//將賦值后的構(gòu)體變量傳遞給GPIO_Init函數(shù)GPIO_Init(GPIOC,&GPIO_InitStruct);}int main(void)
{//系統(tǒng)滴答時(shí)鐘初始化systick_config();//GPIO初始化gpio_config();while (1){//引腳設(shè)置為低電平GPIO_ResetBits(GPIOC,GPIO_Pin_13);//延時(shí)1000msdelay_1ms(1000);//引腳設(shè)置為高電平GPIO_SetBits(GPIOC,GPIO_Pin_13);//延時(shí)1000msdelay_1ms(1000);}
}
4、問(wèn)題與解決
1、STM32報(bào)錯(cuò)Error: L6218E: Undefined symbol assert_param
.\Objects\STMF103FC6T6.axf: Error: L6218E: Undefined symbol assert_param (referred from stm32f10x_gpio.o).
在C\C++設(shè)置一欄中輸入U(xiǎn)SE_STDPERIPH_DRIVER使宏生效即可解決問(wèn)題
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 */