当前位置:网站首页>[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
边栏推荐
- UVM教程
- 统计字符中每个字符出现的个数
- leetcode刷题:二叉树01(二叉树的前序遍历)
- 上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
- BC35&BC95 ONENET MQTT(旧)
- leetcode刷题:栈与队列02(用队列实现栈)
- Go — 相关依赖对应的exe
- BlocProvider 为什么感觉和 Provider 很相似?
- Simple interactive operation of electron learning (III)
- Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
猜你喜欢
随机推荐
游览器打开摄像头案例
leetcode刷题:二叉树03(二叉树的后序遍历)
功利点没啥!
Using closures to switch toggle by clicking a button
TOPS,处理器运算能力单位、每秒钟可进行一万亿次
leetcode刷题:二叉树01(二叉树的前序遍历)
都能看懂的LIS(最长上升子序列)问题[通俗易懂]
[noip2013] building block competition [noip2018] road laying greed / difference
开环和闭环是什么意思?
Kuberntes云原生实战一 高可用部署架构
Classify boost libraries by function
从20s优化到500ms,我用了这三招
【深度学习】利用深度学习监控女朋友的微信聊天?
手动实现function isInstanceOf(child,Parent)
【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
能升职加薪?PMP证书含金量浅析
编程英语生词笔记本
安装mysql时出现:需要这两个包perl(Data::Dumper),perl(JSON)
locust 系列入门
中通笔试题:翻转字符串,例如abcd打印出dcba