当前位置:网站首页>[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 .
边栏推荐
- Kotlin 协程,job的生命周期
- Kotlin 协程挂起函数 suspend 关键字
- Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
- [MRCTF2020]Ez_ bypass --BUUCTF
- Kotlin 协程的四种启动模式
- 深度学习每周期的步数多少合适?
- Cards are unpredictable
- Arduino uses esp8266+ lighting technology + Xiaoai audio to realize voice control switch
- Three column simple Typecho theme lanstar/ Blue Star Typecho theme
- Daily buckle exercise - conclusion
猜你喜欢
How many rounds of deep learning training? How many iterations?
三栏简约typecho主题Lanstar/蓝星typecho主题
[network protocol] problems and solutions in the use of LwIP
Canvas airplane game
Three column simple Typecho theme lanstar/ Blue Star Typecho theme
Daily buckle exercise - conclusion
BUUCTF之BabyUpload[GXYCTF2019]
ROS2之OpenCV人脸识别foxy~galactic~humble
磁盘分区方式对比(MBR与GPT)
pytorch和tensorflow有什么区别?
随机推荐
1. Google grpc framework source code analysis Hello World
Arduino interrupt
STM32 USB Basics
How to solve the duplication problem when MySQL inserts data in batches?
高阶极点对于波形的影响
硬(磁)盘(一)
MySQL query table field information
Cve-2021-24078 vulnerability analysis
天津银行周传凯:从 0 到 1,我的分布式数据库落地经验谈
kotlin 协程withContext切换线程
杂记:intel11代和12代移动版支持原生Thunderbolt4接口,桌面版不支持
【SCA-CNN 解读】空间与通道注意力:Spatial and Channel-wise Attention
Cards are unpredictable
How many steps are appropriate for each cycle of deep learning?
Kotlin coroutine suspend function suspend keyword
The seventh finals of the Blue Bridge Cup
Target recognition gadget
(01). Net Maui actual construction project
What is meebits? A brief explanation
Today's sleep quality record 74 points