当前位置:网站首页>[STM32] (I) overview and GPIO introduction
[STM32] (I) overview and GPIO introduction
2022-07-05 00:28:00 【Record the years of ignorance】
Preface
For a variety of reasons ,STM32 It is imperative to study , Can't , But for high-quality learning , I first collated and summarized many materials I found before , I plan to write a systematic study note .
For a single-chip learning , I think we should generally pay attention to the following points :
- Specify chip pins and on-chip peripherals , Such as IO mouth , interrupt , Timer , Serial port ,ADC etc.
- Data manual , It is convenient to refer to the register or program responding to the query when using a module
- routine , Generally speaking , The official will give a certain routine , It is convenient for users to learn and use .
- Practice more
Reference link
- Automation Association of Jiangke University _STM32 Introductory tutorial _bilibili—— It's really very detailed , Recommendation of conscience !
The following text and pictures are mostly from the content in this video tutorial .
STM32F103 summary
STM32 yes ST( Italian French semiconductor ) The company is based on ARM Cortex-M Kernel developed 32 Bit MCU , So-called M, namely Microcontroller An acronym for ,32 Represents that the single chip microcomputer is 32 position .
Core understanding and product selection
STM32 Is based on ARM Kernel design , But it seems that many people can't distinguish the relationship between kernel and MCU . This video details this point . As shown in the figure below :
Simply speaking , Namely ARM The company provides cores , then ST The company improves the peripheral memory and peripherals , Make the single chip microcomputer have different functions . Besides , Other SCM companies will also be based on ARM Kernel to add other types of peripherals (Peripherals), Thus forming be based on ARM Kernel but function 、 SCM products of different models .
About ARM The various models of the kernel are shown in the figure below :
among ,Cortex-M Series is mainly used for embedded and single chip computers , That's what we're used to STM32F103 The kernel of . Other product cores and features are shown in the figure below :
System structure diagram
You can see from the manual , Small 、 in 、 The internal structure of high-capacity products is similar , As shown in the figure below :
among ,Cortex-M3 For the kernel ,ICode and DCode Instruction bus and data bus related to the kernel , Used to perform Flash Program instructions in ,System For system bus , Used to connect other peripherals .AHB(Advanced High performance Bus) For advanced high-performance bus , Used to connect peripherals with high performance requirements , Like a clock RCC And reset .APB1 and APB2(Advanced Peripheral Bus) For advanced peripheral bus , Used to connect peripherals on the chip , among APB2 The maximum clock is 72MHz,APB1 The maximum clock is 36MHz, because APB1、APB2 The clock and AHB There are some differences , Therefore, a bridge circuit is needed .
Here's the thing to remember , Which peripherals are connected APB1, What are connections APB2, Because it is generally necessary to enable the clock of the corresponding bus before using peripherals , Otherwise, the peripheral cannot run . among ,GPIO And peripheral devices “1 Contestant No ” Mounted on APB2 On , Other peripherals “ Not 1 Contestant No ” and ADC Mount it on APB2 On , Relatively slow .
STM32F103C8T6
The above description is STM32F1 The function and structure of the series integrity , Specific to the smallest system board used and its chip model , Also need to have some understanding .
This video tutorial is based on STM32F103C8T6 The smallest system board of the chip , According to the model selection manual , We can know that the main frequency of this type of chip is 72MHz, The power supply is 2.0~3.6V, General choice 3.3V Power supply .
The circuit schematic diagram of the minimum system board is shown below :
Besides , Attention is also needed STM32 Start configuration of , namely BOOT0 and BOOT1 Configuration of , These two pins determine where the MCU starts to execute the program , The specific settings are shown in the figure below :
among , In the first mode, the program starts from the main flash memory , Is the mode of normal running program , This mode is generally used ; The second mode is to start from the system memory , That's what we call it BootLoader, Generally used as serial port download .
Besides , According to the notes at the bottom of the table , When the system is reset ,SYSCLK Of the 4 Rising edge ,BOOT The value of the pin will be locked , At this point, you can put BOOT0 The pin configuration is normal IO Mouth .
Standard library development Keil New project
STM32 Development mode , There are three : Register development 、 Standard library development 、HAL Library Development , among , because STM32 All of the registers are 32 position , And a large number , So few people use registers to develop , Most of them use standard libraries or HAL Library to develop . Here we mainly introduce the development method of standard library , So just use Keil that will do .
however , There is a big trouble in the development of standard library , That is, it is troublesome to establish engineering documents , We need to arrive first. ST Download the compressed package of the standard peripheral library on the official website , Then add some files in the project .
- 1、 Create a project , Select the corresponding device
- 2、 Create several subfolders in the project folder , Convenient for project management :Start、Library、System、User、Peripherals, The name can be any , Easy to understand . And at the same time Keil Create a project with the same name Group.
It should be noted that : establish group after , Be sure to add the corresponding folder in the project inclusion
And at the same time define Add the definition of using the standard library :USE_STDPERIPH_DRIVER - 3、 Open a standard library file , stay Keil Add corresponding files in the project . It's complicated here , Refer to the tutorial in the video for details
actually , If you only need some functions , You can only add some official .c and .h file , But to create a “ It's not good to try ” Project engineering template , You can add all source files and header files , It's just that the compilation speed is a little slower .
- 4、 Set the debugger according to your actual situation
Step on the pit diary
- 1、 Report errors FCARM - Output Name not specified, please check 'Options for Target - Utilities’
reason : Wrong type selection when adding files
Should be changed to All files. And right click to add the file , You can find the corresponding error of its attribute .
Reference link - 2、 Use ST-Link Download the program to the development board , It is found that the program can only be run by pressing the reset button
solve : Check... In the setting Reset and run outside , You also need to uncheck Enable
Reference link
GPIO
Additional reference links
summary
STM32 Of GPIO More complicated , But after understanding the principle, it is still very simple to master the basic use . Inside IO The mouth structure is shown in the figure below :
among , It is worth mentioning that , Schottky trigger at input , In essence, it is a Schmidt trigger ( It's a translation error ), It has hysteresis comparison curve , It can make the read signal not affected by fluctuations . Output terminal , Bit settings / The clear register is used to set the output data register , Because the output data register can only be read and written as a whole , And if you need to change a bit , You need to set it in place / Clear register , To write a bit , And other bits do not change the effect .
Precisely because STM32 Of GPIO The internal structure is complex , therefore GPIO A total of... Can be configured 8 Kind of I / O mode , As shown in the following table :
8 The code in the standard library corresponding to each mode is shown in the following figure :
Generally speaking , Use GPIO The steps are as follows :
- Can make the clock ( Can make APB2 Clock on bus )
- initialization GPIO port , Including setting pin (Pin)、 Pattern (Mode)、 Speed (Speed) Equal parameter
- Use the corresponding API Function interface for input and output
among , When initializing the port , Generally, you need to define a GPIO The structure of the body , Then configure the parameters in the structure separately , The reference codes are as follows :
API Function summary
Initialization complete GPIO After the port , Next is the operation input and output , Here we need to use all kinds of API function . How to find these functions ? It's simple , Open the added stm32f10x_gpio.h file , Slide to the bottom , You can see the commonly used API Function .
Although the quantity is a little more , But in fact, there are not many commonly used functions . Its function is shown in the figure below :
If you need to view the specific definition of the function , You can right-click the function declaration , choice Go To Definition Of xxxxx, If you need to return the function declaration , Right click the defined function , choice Toggle Head.
Attached below is a LED Flashing code :
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
while (1)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_0);
Delay_ms(500);
GPIO_SetBits(GPIOA, GPIO_Pin_0);
Delay_ms(500);
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_RESET);
Delay_ms(500);
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_SET);
Delay_ms(500);
GPIO_WriteBit(GPIOA, GPIO_Pin_0, (BitAction)0);
Delay_ms(500);
GPIO_WriteBit(GPIOA, GPIO_Pin_0, (BitAction)1);
Delay_ms(500);
}
}
CubeMX Study the tutorial
https://zhuanlan.zhihu.com/STM32CubeMX
https://www.waveshare.net/study/article-629-1.html
边栏推荐
- 2022.07.03(LC_6111_统计放置房子的方式数)
- 初识ROS
- abc 258 G - Triangle(bitset)
- [path planning] RRT adds dynamic model for trajectory planning
- Robot reinforcement learning synergies between pushing and grassing with self supervised DRL (2018)
- [monitoring] ZABBIX
- Summer challenge brings you to play harmoniyos multi terminal piano performance
- Hisilicon 3559 universal platform construction: YUV422 pit stepping record
- 城市轨道交通站应急照明疏散指示系统设计
- Nine Qi single chip microcomputer ny8b062d single key control four LED States
猜你喜欢
【雅思阅读】王希伟阅读P3(Heading)
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
npm install报错 强制安装
js如何实现数组转树
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
Continuous modification of business scenario functions
初识ROS
Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
Skills in analyzing the trend chart of London Silver
Learn C language from scratch day 024
随机推荐
ORB(Oriented FAST and Rotated BRIEF)
He worked as a foreign lead and paid off all the housing loans in a year
[IELTS reading] Wang Xiwei reading P3 (heading)
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
AcWing164. 可达性统计(拓扑排序+bitset)
Hologres query management and timeout processing
同事的接口文档我每次看着就头大,毛病多多。。。
Tester's algorithm interview question - find mode
Acrel-EMS综合能效平台在校园建设的意义
Enterprise application business scenarios, function addition and modification of C source code
[error reporting] "typeerror: cannot read properties of undefined (reading 'split')“
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
他做国外LEAD,用了一年时间,把所有房贷都还清了
模板的进阶
初识ROS
Cross domain request
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
How to effectively monitor the DC column head cabinet
【北京大学】Tensorflow2.0-1-开篇
Parsing of XML