Tangwx

Tangwx

博客网站

01. Overview of STM32 Basic Knowledge

1 Overview of STM32 Basic Knowledge#

1.1 Introduction to STM32#

STM32 is a 32-bit microcontroller developed by STMicroelectronics based on the ARM Cortex-M core.

M stands for Microcontroller.

STM32 is commonly used in embedded fields such as smart vehicles, drones, robots, wireless communication, the Internet of Things, industrial control, and entertainment electronic products.

STM32 is powerful, has excellent performance, rich on-chip resources, and low power consumption, making it a classic embedded microcontroller.

image-20220809082441069

1.2 Introduction to ARM#

ARM refers to both ARM Holdings and ARM processor cores.

ARM Holdings is a leading global semiconductor intellectual property (IP) provider, with over 95% of smartphones and tablets worldwide using ARM architecture.

ARM Holdings designs ARM cores, while semiconductor manufacturers enhance the core's peripheral circuits and produce chips.

image-20220809083032037

image-20220809083101283

1.3 Introduction to STM32F103C8T6#

Series: Mainstream series STM32F1

Core: ARM Cortex-M3

Main frequency: 72MHz

RAM: 20K (SRAM)

ROM: 64K (Flash)

Power supply: 2.0~3.6V (Standard 3.3V)

Package: LQFP48

image-20220809084122792

1.4 On-chip Resources/Peripherals#

STM32 can integrate operating systems such as FreeRTOS, UCOS, etc. If these operating systems are used, SysTick is required to provide timing for task switching.

UART stands for asynchronous serial port, while STM32's USART supports both asynchronous and synchronous serial ports, with asynchronous serial ports being more commonly used.

AbbreviationNameAbbreviationName
NVICNested Vector Interrupt ControllerCANCAN Communication
SysTickSystem Tick TimerUSBUSB Communication
RCCReset and Clock ControlRTCReal-Time Clock
GPIOGeneral Purpose I/OCRCCRC Check
AFIOAlternate Function I/OPWRPower Control
EXTIExternal InterruptBKPBackup Register
TIMTimerIWDGIndependent Watchdog
ADCAnalog-to-Digital ConverterWWDGWindow Watchdog
DMADirect Memory AccessDACDigital-to-Analog Converter
USARTSynchronous/Asynchronous Serial CommunicationSDIOSD Card Interface
I2CI2C CommunicationFSMCFlexible Static Memory Controller
SPISPI CommunicationUSB OTGUSB Host Interface

1.5 Chip Naming Convention#

image-20220809084423056

1.6 System Architecture#

The Cortex-M3 core features three buses: ICode instruction bus, DCode data bus, and System bus.

The ICode and DCode buses are primarily used to connect to Flash memory.

Flash stores the programs we write.

The ICode instruction bus is used to load program instructions.

The DCode data bus is used to load data, such as constants and debug data.

The System bus connects to SRAM and FSMC.

SRAM is used to store variable data during program execution.

The AHB system bus is used to mount major peripherals; AHB stands for Advanced High-performance Bus, typically mounting the most basic or high-performance peripherals, such as reset and clock control circuits. SDIO is also mounted on AHB.

APB1 and APB2 are two peripheral buses; APB stands for Advanced Peripheral Bus, used to connect general peripherals.

Due to differences in bus protocols, speeds, and data transfer formats between AHB and APB, two bridges are needed to complete data conversion and buffering. The overall performance of AHB is higher than that of APB, with APB2 generally having higher performance than APB1. APB2 typically operates at the same frequency as AHB, which is 72MHz, while APB1 generally operates at 36MHz. Therefore, APB2 usually connects to slightly more important peripherals, such as GPIO ports and some key peripherals (USART1, SPI1, TIM1, TIM8, etc.). TIM8, like TIM1, is also a high-end timer, making it an important peripheral. ADC, EXTI, and AFIO are also connected to APB2. Other peripherals like 2, 3, 4, 5, DAC, PWR, and BKP, which are less critical, are allocated to APB1. However, in practice, users generally do not notice performance differences between APB2 and APB1; it is sufficient to know which bus a peripheral is mounted on.

DMA can be seen as a small secretary for the CPU, handling tasks like moving large amounts of data, which would waste CPU time. DMA primarily handles these simple and repetitive tasks. It connects to the bus matrix via the DMA bus and has the same bus control rights as the CPU to access these peripherals. When DMA is needed to transfer data, the peripheral sends a DMA request via the request line, and DMA gains bus control to access and transfer data, all without CPU involvement, saving CPU time for other tasks.

image-20220809084538311

1.7 Pin Definitions#

The red pins are related to power supply.

The blue pins are related to the minimum system.

The green pins are I/O ports and functional pins.

S type represents power supply.

I type represents input.

O type represents output.

IO type represents input/output.

FT indicates that this pin can tolerate 5V voltage; those without FT can only tolerate 3.3V voltage.

STM32 uses a partitioned power supply method, with multiple power supply pins. When using, VSS is connected to GND, and VDD is connected to 3.3V.

STM32 supports two debugging methods: SWD and JTAG.

SWD requires two lines, SWDIO and SWCLK.

JTAG requires five lines: JTMS, JTCK, JTDI, JTDO, NJTRST.

STLINK uses the SWD method to download and debug programs, so it only occupies PA13 and PA14 I/O ports.

When downloading using SWD, PA15, PB3, and PB4 can be switched to ordinary I/O ports, but this needs to be configured in the program; by default, they will not be used as I/O ports.

image-20220810080019866

image-20220811092650888

Pin NumberPin NamePin DefinitionMain Function
1VBATBackup battery power pin; this pin can connect to a 3V battery. When the system power is off, the backup battery can provide power to the internal RTC clock and backup register.VBAT
2PC13-TAMPER-RTCI/O pin or intrusion detection or RTC; the I/O pin can output or read high or low levels according to the program. Intrusion detection can be used for security functions, and RTC can output RTC calibration clock, RTC alarm pulse, or second pulse.PC13
3,4PC14-OSC32_IN/PC15-OSC32_OUTI/O pin or connect to a 32.768KHz RTC crystalPC14/PC15
5,6OSC_IN/OSC_OUTConnect to the system's main crystal, usually 8MHz; the chip has a phase-locked loop circuit that can multiply this 8MHz frequency to ultimately produce a 72MHz frequency as the system's main clock.OSC_IN/OSC_OUT
7NRSTSystem reset pin; N indicates low-level resetNRST
8,9VSSA/VDDAPower supply for the internal analog part, such as ADC, RC oscillator, etc.; VSS is connected to GND, and VDD is connected to 3.3V.VSSA/VDDA
10PA0-WKUPI/O pin with WKUP function; can wake up the STM32 in standby mode.PA0
11-19PA1、PA2、PA3、PA4、PA5、PA6、PA7、PB0、PB1I/O pinsPA1-PB1
20PB2I/O pin or BOOT1 pin; the BOOT pin is used to configure the startup mode.PB2/BOOT1
21,22PB10、PB11I/O pinsPB10,PB11
23,24VSS_1/VDD_1System main power supply pin; VSS is negative, VDD is positive.VSS_1/VDD_1
25-33PB12、PB13、PB14、PB15、PA8、PA9、PA10、PA11、PA12I/O pinsPB12、PB13、PB14、PB15、PA8、PA9、PA10、PA11、PA12
34PA13I/O pin or debug portJTMS/SWDIO
35,36VSS_2/VDD_2System main power supply pin; VSS is negative, VDD is positive.VSS_2/VDD_2
37-40PA14/PA15/PB3/PB4I/O pins or debug ports (used for debugging and downloading programs)JTCK_SWCLK/JTDI/JTDO/NJTRST
41-43PB5/PB6/PB7I/O pinsPB5/PB6/PB7
44BOOT0Like BOOT1, also used for startup configuration.BOOT0
45,46PB8/PB9I/O pinsPB8/PB9
47,48VSS_3/VDD_3System main power supply pin; VSS is negative, VDD is positive.VSS_3/VDD_3

1.8 Boot Configuration#

The purpose of the boot configuration is to specify where the program starts running. Generally, programs execute from the Flash program memory, but in certain cases, we can also start the program from other locations to achieve special functions.

BOOT1=0 BOOT0=1 mode is used for serial port downloading; the system memory stores a segment of the BootLoader program in STM32. The role of the BootLoader program is to receive data from the serial port and refresh it to the main flash memory, allowing programs to be downloaded via the serial port. Typically, we configure this mode when we need to download programs via the serial port.

BOOT0=0 sets the boot mode to the main flash memory mode, where the main flash memory is selected as the startup area, and the program inside the flash memory is executed normally. This mode is the most commonly used mode and is generally the default configuration.

BOOT1=1 BOOT0=1 configures for SRAM startup, which is mainly used for program debugging and is currently used less frequently.

The value of the BOOT pin is valid at the moment of power-up reset; afterwards, it can be arbitrary.

image-20220809084630785

1.9 Minimum System Circuit#

OSC32 refers to a 32.768KHz crystal oscillator; 32768 is 2 raised to the power of 15, and the internal RTC circuit can generate a 1-second time signal through a division of 2 raised to the power of 15.

image-20220809084704647

RTC crystal oscillator is a 32.768KHz crystal.

img

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.