当前位置:网站首页>[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
2022-07-01 21:58:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Preface
The configured CubeMX after , Is the beginning of the new project , So first we need some preparation , We will introduce this blog in detail STM32CubeMx And how to create a new project and light it up LED The lamp For beginners If you want to create a project quickly , You can skip the function introduction directly , Watch the project creation column
also , When building a new project , We divide it into specific processes 1~7 If you don't want to see the explanation of each part , Just follow the process ,5 Minutes to successfully light LED The lamp
install STM32CubeMx Please see 《STM32 CubeMx Use tutorial one – Installation tutorial 》
Preparation :
1、STM32 Hardware ( My is STM32F407ZE and STM32F103ZE)
2、STM32CubeMx Software 、 IDE Keil(MDK-ARM) Software
3、STM32F4xxHAL library
New project
1 Select... In the main interface File–>New Project Or click directly ACCEE TO MCU SELECTOR
The chip model selection... Appears Generally, we can directly search the model of our own chip
If you are designing a product and want to choose a chip Under the search bar , Various search methods provided , You can choose the chip core , model , wait , Help you find the right chip
Specific process 1:
- 1 Search chip model
- 2 Select chip
- 3 Create a project
Then the next is the highlight of our whole process
Here we are divided into three parts to explain
1MCU Peripheral resource selection
Here you can choose MCU Various resources and peripherals
There are two ways
- Categories Type selection
take MCU Classification of various peripherals and resources , For users to choose
- A-Z Sequence selection
MCU For peripheral resources, press A-Z Sort , For users to choose
2 Peripheral configuration
Here you can set various functions of the peripherals you choose
Here is the serial port 1 For example We can choose the serial port mode ( asynchronous , Sync , Half duplex ) Serial receive interrupt , And serial port DMA Transmission and so on
It is basically the same as when we configure library functions , however STM32CubeMx Convert these into Graphics and options , We don't need to configure all kinds of things when configuring , We can configure the peripherals we need only by foolproof operation This is CubeMx At the heart of
3 Preview interface
Here is divided into Pin Preview and System Preview
Pin preview is to view what functions are configured on that pin , And each pin position
Click on any pin , Various functions of this pin can be set
This color means Non configurable pin Power dedicated pins are highlighted in yellow . Its configuration Can't change
This color means You configured a I/O The function of the mouth , However, the corresponding peripheral functions are not initialized Pin in no mode state
Green indicates successful configuration
System Preview
System preview is to view various peripherals and configurations GPIO The state of
No problem
A warning , There is a problem with the corresponding configuration Click this option to Peripheral configuration Interface view
Specific configuration of each function (UATR/DMA/ADC/TIM…) We will explain them one by one in the next article , There's no more to it
Specific process 2:
Here we just need to put our LED The corresponding pin is set to GPIO_Output that will do
2 Clock source settings
In fact, it is 32 Clock tree block diagram Let you configure The default clock is the internal clock RC oscillator (HSI)
If you don't understand, please read 《【STM32】 The system clock RCC Detailed explanation ( Hyperdetail , Super comprehensive )》
Specific process 3:
Or first configure it as 72MHz that will do
- Need configuration RCC To use an external clock source
3. engineering management
Set the MCU After each configuration of , The third is the setting of engineering documents
Specific process 4:
Here are the various configurations of the project We only use a limited number of , Other defaults are fine IDE We use MDK5
- The storage directory cannot have Chinese
And then click Code Generator, For further configuration ( a key )
take HAL All of the library .C and .H All copied into the project
advantage : In this way, if other peripherals need to be added later, they may not be used anymore STM32CubeMX It will be very convenient when
shortcoming : Large size , Long compilation time ( For a long )
Just copy what you need .C and .H ( recommend )
advantage : Relatively small volume , The compilation time is short , And the project can be copied
shortcoming : When adding peripherals, you need to reuse STM32CubeMX Import
Does not copy files , Import directly from the package storage location .C and .H
advantage : Small volume , Save hard disk space
shortcoming : Copy to another computer or package location changes , You need to modify the corresponding path
Choose your own way
Specific process 5:
And then click GENERATE CODE Create a project
Create success , Open the project
Specific process 6:while Add the following two lines of code in a loop
HAL_Delay(500);
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_15);
Configure the download tool
Specific process 7:
All configurations of the new project are default We need to choose our own download mode , Check the reset operation after loading and downloading
All your own code, please put it in /* USER CODE BEGIN XXX */ /* USER CODE END XXX */ Between
In this way, when we modify the project, the code you write will not be deleted
Here we are ,STM32CubeMX The introduction to the basic use of , Next, we'll update CubeMX and HAL Library Configuration STM32 Of UART ADC DMA Timer PWM wait
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/130467.html Link to the original text :https://javaforall.cn
边栏推荐
猜你喜欢
杰理之蓝牙耳机品控和生产技巧【篇】
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
Pytest Collection (2) - mode de fonctionnement pytest
基于YOLOv5的口罩佩戴检测方法
leetcode刷题:二叉树01(二叉树的前序遍历)
MySQL series transaction log redo log learning notes
I received a letter from CTO inviting me to interview machine learning engineer
【Leetcode】最大连续1的个数
js如何获取集合对象中某元素列表
Go - exe corresponding to related dependency
随机推荐
朋友圈社区程序源码分享
Getting started with the lockust series
旁路由设置的正确方式
基于三维GIS的不动产管理应用
latex如何打空格
从20s优化到500ms,我用了这三招
能升职加薪?PMP证书含金量浅析
JS how to get a list of elements in a collection object
One of the basic learning of function
vscode的使用
[NOIP2013]积木大赛 [NOIP2018]道路铺设 贪心/差分
基于K-means的用户画像聚类模型
Spark面试题
Icml2022 | interventional contrastive learning based on meta semantic regularization
Significance and measures of security encryption of industrial control equipment
AIDL基本使用
统计字符中每个字符出现的个数
MIT|256KB 内存下的设备上训练
二叉树的基本操作
分离字符串中的字母和数字并使得字母在前数组在后