当前位置:网站首页>[003] embedded learning: creating project templates - using stm32cubemx
[003] embedded learning: creating project templates - using stm32cubemx
2022-06-13 00:49:00 【Python's path to becoming a God】
【 This paper is about Baiwen & Weidong mountain 【 IOT smart home training camp 】 Learning notes series 】
introduction
STM32CubeMX yes ST Italian French semiconductor launched STM32 A series of chip graphic visual configuration tools , You can use the graphical wizard to Cortex-M series MCU Generate initialization code project template . It is very easy to configure... Through a step-by-step process STM32 Microcontrollers and microprocessors , As well as Arm Cortex-M Kernel or oriented Arm Cortex-A Kernel specific Linux The device tree generates the corresponding initialization C Code .
Compare with Keil Create a project template ,STM32CubeMX Few steps 、 Quick start , The visual interface helps to understand and add interest . But the generated project template is rather bloated , And you need to write code according to the specified rules .
1 Engineering creation
1.1 Select the method to create the project
Initial operation STM32CubeMX, The following interface will pop up . Click on “ACCESS TO MCU SELECTOR”, Create a project by selecting a chip , Pictured 1 Shown .

chart 1 Create a project by selecting a chip
Then select the chip model . Enter in the search box “STM32F103C8”, Choose... On the right “LQFP48” encapsulation , Finally, click “Start Project”, Start creating projects , Pictured 2 Shown .

chart 2 Choose chip model
1.2 GPIO To configure
GPIO(General-Purpose IO ports, Universal input / Output interface ), Used to sense external signals ( The input mode ) And control external equipment ( The output mode ), The thin pins around the chip are GPIO.
|
|
KEY PA0;LEDPA1 | |
chart 3 103MINI Schematic diagram of development board ( Local )
chart 3 Weibaiwen.com 103MINI Partial schematic diagram of development board , It can be seen from the drawing that PA0 The pin is connected to the key ;PA1 Pin and LED Connected to a . According to the schematic diagram , Conduct MCU Of GPIO To configure .
Enter the pin configuration interface , This interface can graphically select chip pins and configure , Pictured 4 Shown .

chart 4 Pin configuration interface
Insert the pin PA1 Set to GPIO_Output Pattern , Insert the pin PA0 Set to GPIO_Input Pattern , After the configuration is completed, see the figure 5 Sum graph 6 Shown .

chart 5 GPIO Pin status after configuration

chart 6 GPIO Details after configuration
1.3 System clock configuration
Clock is very important for a chip , Its function is equivalent to that of human heart , People can live a healthy life only when their heart rate is normal and stable . Empathy , Only when the chip works at the legal and normal clock frequency can it ensure the normal operation of the program . STM32F103 The clock system includes internal high-speed / Low speed clock source 、 External high speed / Low speed clock source 、PLL( PLL ) And system tick timer . So let's go through STM32CubeMX Configure the clock system , So as to deepen the understanding of the clock tree .
According to the schematic diagram , Reasonably configure the clock source . Pictured 7 Shown , First enable the external high-speed clock (HSE) And select “Crystal/Ceramic Resonator”.

chart 7 External high-speed clock (HSE) Set up
The clock source is configured as shown in the figure 8 Shown , You can see the pins PD0 and PD1 Turn green , It represents the input pin and output pin of the external crystal oscillator respectively .

chart 8 External high-speed clock (HSE) Set the pin status after completion
Next, use the external clock HSE Configure the system clock to the maximum value 72Mhz, Pictured 9 Shown .

chart 9 Source and frequency setting of system clock
In the figure 10 in , Click on “GENERATE CODE” Build project :

chart 10 Preview the status after the clock configuration is completed
2 Engineering structure
The folder included in the new project is shown in the figure 11 Shown .

chart 11 Folder structure of the project
Each folder is described below :
- MDK-ARM: Save the startup file
- Core: Store the main function main.c And some core files that may be modified
- Drivers: Deposit CMSIS and HAL library ;
Use Keil Open the new project , The directory tree of the project is shown in the figure 12 Shown .

chart 12 The project is in keil Directory tree structure in
3 Core code
GPIO The core code in initialization, such as code snippets 1 Shown :
Code segment 1:GPIO initialization

The core code in the system clock configuration, such as code snippet 2 Shown :
Code segment 2: System clock configuration

In the main function Main.c Add code snippets to 3 The code in , Download the program to 103MINI Development board . Blue by default LED Light normally on . When the user presses the key , Blue LED The light goes out , When the key is released , Blue LED Lighten up .
Code segment 3: User defined code added in the main function

Conclusion
This paper introduces the use of STM32CubeMX Create a project , To configure GPIO And the system clock .
边栏推荐
猜你喜欢

牌好不好无法预料

也许尘埃落地,我们才能想清楚互联网的本质

gpu加速pytorch能用吗?

Win10 home vs pro vs enterprise vs enterprise LTSC

pytorch和tensorflow有什么区别?

In / out / inout details of MySQL stored procedures
![[error] invalid use of incomplete type uses an undefined type](/img/8a/7cb5d270cfd8831ddc146687fe4499.png)
[error] invalid use of incomplete type uses an undefined type

JPA execution failed in scheduled task -executing an update/delete query transactionrequiredexception

Kali system -- host, dig, dnsenum, imtry for DNS collection and analysis

Canvas airplane game
随机推荐
. The way to prove the effect of throwing exceptions on performance in. Net core
Introduction to ROS from introduction to mastery (zero) tutorial
Canvas airplane game
Aof persistence
MySQL query table field information
Mongodb array operation
Build your own PE manually from winpe of ADK
Today's sleep quality record 74 points
Card constructions -- two points
The scope builder coroutinescope, runblocking and supervisorscope of kotlin collaboration processes run synchronously. How can other collaboration processes not be suspended when the collaboration pro
Leetcode weekly -- April to May
从ADK的WinPE自己手动构建自己的PE
JPA execution failed in scheduled task -executing an update/delete query transactionrequiredexception
Arduino interrupt
[JS component] floating text
Andersen global expands its business in northern Europe through cooperation agreements in Finland and Denmark
What is the difference between pytorch and tensorflow?
Daily buckle exercise - conclusion
[buglist] serial port programming does not read data
[MRCTF2020]Ez_ bypass --BUUCTF

