当前位置:网站首页>STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
2022-07-06 09:25:00 【Bitter tea seeds】
系列文章目录
STM32F103ZE学习记录:主要参考正点原子教程
文章目录
前言
这篇笔记主要是介绍一下使用ST_SLINK进行烧录点亮LED灯程序,以及我遇到的一些问题,
一、环境的搭建
1.新建编程文件操作步骤
1.1在以搭建好的工程文件中,新建外设文件夹

1.2在工程文件夹中,添加路径

1.3建立<.c>和<.h>文件

1.4将<.c>文件添加到文件夹中


<.h>同样的操作步骤
2.ST_LINK烧录搭建
2.1点击魔术棒



但是我在使用STLINK下载时出现了问题
3.STlink下载出现st-link usb communication error解决方法
解决方法就是进行固件升级;
点击ST-LinkUpgrade.exe,打开st-link upgrade软件进行固件升级
插上st-link固件到电脑,点击Device Connect按钮,连接st-link
千万不要将USB接口拔掉,否则会导致升级失败

若出现如下报错,则可尝试重新插拔st-link固件,或者换一个usb接口进行连接
连接成功!如下图,可以看到当前固件版本以及即将升级的版本,点击yes进行升级
更新驱动
已管理员身份运行D:\MDKkeil5\ARM\STLink\USBDriver\stlink_winusb_install.bat文件,进行驱动更新
点击下一步,直至完成。
问题就轻松加愉快的解决了!
二、LED跑马灯程序
STM32与51单片机确实不同,STM32要比51更高级;
STM32程序直接调用库函数,比51要方便很多,STM32的寄存器很多,功能也比51要更加强大。
*操作步骤借鉴正点原子PPT
实际上也是对寄存器进行操作。
1.LED.c程序
用到的重要函数 *借鉴正点原子PPT
代码如下(所示):
#include "led.h"
#include "stm32f10x.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//使能GPIOB的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);//使能GPIOE的时钟
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;//选择推挽是因为可以直接输出高电平
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5;//选择GPIOB5
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;//输出速度是50M
GPIO_Init(GPIOB,&GPIO_InitStruct);//GPIOB5初始化
GPIO_SetBits(GPIOB,GPIO_Pin_5);//对GPIOB5设置高电平
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;//选择推挽是因为可以直接输出高电平
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5;//选择GPIOB5
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;//输出速度是50M
GPIO_Init(GPIOE,&GPIO_InitStruct);//GPIOE5初始化
GPIO_SetBits(GPIOE,GPIO_Pin_5);//对GPIOE5设置高电平
}
2.LED.h程序
代码如下(所示):
#ifndef __led_H
#define __led_H
void LED_Init(void);
#endif
在这里我遇到了一个警告,很有意思啊
3…\harwred\led\led.h(7): warning: #1-d: last line of file ends without a newline
这可能是MDK开发人员留的一个小彩蛋,就是最后一行代码,必须回车才可以,感觉那个人一定有强迫症。
4.main.c程序
进行函数的调用就可以了
代码如下(所示):
#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
int main(void)
{
LED_Init();//进行LED初始化的调用
delay_init();//进行延时函数初始化的调用
while(1)
{
GPIO_SetBits(GPIOB,GPIO_Pin_5);//对GPIOB5设置高电平
delay_ms(500);//延时500毫秒
GPIO_ResetBits(GPIOB,GPIO_Pin_5);//对GPIOB5设置低电平
delay_ms(500);//延时500毫秒
GPIO_SetBits(GPIOE,GPIO_Pin_5);//对GPIOE5设置高电平
delay_ms(500);//延时500毫秒
// GPIO_ResetBits(GPIOB,GPIO_Pin_5);//对GPIOB5设置低电平
GPIO_ResetBits(GPIOE,GPIO_Pin_5);//对GPIOE5设置低电平
delay_ms(500);//延时500毫秒
}
}
5.最后进行STLINK的下载

实验现象
STM32LED灯闪烁
边栏推荐
- Brief description of compiler optimization level
- ArrayList set
- Threads et pools de threads
- A method and implementation of using VSTO to prohibit excel cell editing
- Automated testing problems you must understand, boutique summary
- Servlet
- Iterators and generators
- How to rename multiple folders and add unified new content to folder names
- Jupyter installation and use tutorial
- 几款开源自动化测试框架优缺点对比你知道吗?
猜你喜欢
![[200 opencv routines] 98 Statistical sorting filter](/img/ba/9097df20f6d43dfce9fc1e374e6597.jpg)
[200 opencv routines] 98 Statistical sorting filter
软件测试需求分析之什么是“试纸测试”

Video scrolling subtitle addition, easy to make with this technique

Interface test interview questions and reference answers, easy to grasp the interviewer

FSM and I2C experiment report

LeetCode#36. Effective Sudoku

LeetCode#19. Delete the penultimate node of the linked list

Brief introduction to libevent

ucore lab 2

csapp shell lab
随机推荐
转行软件测试必需要知道的知识
ucore lab5
ucore lab 6
软件测试需求分析之什么是“试纸测试”
UCORE Lab 1 system software startup process
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
学习记录:TIM—基本定时器
Market trend report, technical innovation and market forecast of Chinese hospital respiratory humidification equipment
Scoring system based on 485 bus
ucore lab7
Winter vacation daily question - maximum number of balloons
Collection集合与Map集合
如何成为一个好的软件测试员?绝大多数人都不知道的秘密
软件测试面试要问的性能测试术语你知道吗?
Iterators and generators
Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
Pedestrian re identification (Reid) - Overview
How to do agile testing in automated testing?
What are the commonly used SQL statements in software testing?
ucore lab 2