Introduction to STM32F103C8T6 MCU

1. Introduction

        STM32F103C8T6 is a 32-bit microcontroller based on Cortex-M3 core launched by STMicroelectronics (ST). The hardware adopts LQFP48 package and belongs to the STM32 series of ST microcontrollers. In addition to the well-known STM32, ST also has SPC5X series, STM8 series, etc. The specific parameters are as follows:

kernel Cortex-M3
Flash 64K x 8bit
SHAME 20K x 8bit
GPIO 37 GPIOs, namely PA0-PA15, PB0-PB15, PC13-PC15, PD0-PD1
ADC

2 12bit ADCs total 12 channels, external channels : PA0 to PA7+PB0 to PB1,

Internal channels : temperature sensor channel ADC_Channel_16 and internal reference voltage channel ADC_Channel_17

Timers

                        4 16bit timers/counters, namely TIM1, TIM2, TIM3, TIM4

                                TM1 with dead time insertion, often used to generate PWM control motor

2 watchdog timers (independent watchdog IWDG, window watchdog WWDG)
1 24bit tick timer systick counting down
Working voltage, temperature 2V~3.6V、-40°C ~ 85°C
Communication serial port

                                        2*IIC,2*SPI,3*USART,1*CAN

system clock The internal 8MHz clock HSI can be multiplied up to 64MHz, and the external 8MHz clock HSE can be multiplied up to 72MHz

        ARM changed the name to Cortex after ARM11, and divided it into three categories: A, R and M. The M series includes M0, M0+, M3, M4, and M7. Cortex-M3 is an MCU core based on ARMv7 architecture launched by ARM company. ST company completed the design of peripheral circuits such as USART, DMA, and GPIO on the basis of this core. The STM32 developed under different cores of the M series can be roughly divided into three parts: low-power series, mainstream series, and high-performance series. The specific information is shown in the following figure:

        The cores of the same series are generally the same. For example, the F1 series are developed with the Cortex-M3 core, but according to the size of the Flash, the STM32 can be divided into small-capacity products (<64K), medium-capacity products (between 64K-128K), and large-capacity products3 Each part of the capacity product needs to use different startup files when using the standard library SPL to develop and modify it at the precompiled place. The specific information is shown in the following figure:

        The entire system structure of STM32F103C8T6 can be divided into the Cortex-M3 core designed by ARM and the bus matrix optimized by ST on this basis, DMA (Direct Memory Access, direct memory read), AHB, APB1, and external devices mounted on APB2. There are two parts, the detailed structure is shown in the following figure:

        Cortex-M3 abandons the von Neumann structure (Princeton structure) and adopts the Harvard Architecture ( Harvard Architecture ) that separates instruction storage and data storage , so that Cortex-M3 also has an independent 32-bit instruction bus And 32-bit data bus, data access will no longer occupy the instruction bus, and the MCU running speed is improved after reading instructions and data at the same time. A macro comparison of the von Neumann and Haval structures is shown in the figure below:
        Cortex-M3 is a 32-bit processor core, which is why STM32 is called a 32-bit microcontroller. It has 32 address buses, which means that the maximum addressing space is 2^{32}=2^{2}*2^{30}=4GByte. In addition, the registers of Cortex-M3 are 32-bit, and the memory interface is also 32-bit. The detailed structure is shown in the following figure:

-------------------------------------------------------------------------------------------------------------------------------

Click to jump: Relevant learning materials (CSDN)

Baidu network disk: https://pan.baidu.com/s/1ok8i8YeiNITmnNs-QEPVqw Extraction code: 1234

--------------------------------------------------------------------------------------------------------------------------------

2. Minimum system board

        Maybe you have often heard the word minimum system board , so what is the minimum system board? In fact, the smallest system board is the most streamlined circuit, which can only maintain the most basic normal operation of the MCU. The minimum system is generally composed of an external reset circuit, an external clock circuit and the MCU body. In addition, there are no other external devices such as Bluetooth, external EEPROM, clock chip DS1302, and SPI interface display screen. (Note: STM32 supports internal clock and power-on reset, but in the traditional sense, the minimum system is composed of external reset circuit, external clock circuit and MCU body.) I bought a minimum system board of STM32F103C8T6 on Taobao. The design is exquisite. Well, it looks like this:

        If you still don't know much about the minimum system, then you can see that the minimum system is really streamlined and can't be simplified any more.

        In fact, the minimum system board bought by Taobao is not much different from the blue minimum system board of 10 wallets, but some pins are drawn out so that they can be inserted into peripherals such as display screens. The design of the board is very clever, all the pins are drawn out, and four interfaces are reserved for easy access to the display screen and other equipment, and the SWD debugging interface is reserved, and ST-LINK can be used to download programs and emulations.

        Unlike the STC89C52RC microcontroller, the GPIO of the STM32F103C8T6 has 8 modes, including the pull-up and pull-down input modes, so the pull-up and pull-down resistors can not be designed when connecting buttons. According to his schematic diagram, one end of the key KEY0 is connected to 3.3V VCC, and the other end is connected to the PA0 pin. One end of the light-emitting diode LED0 is also connected to 3.3V VCC through a 1KΩ resistor, and the other end is connected to PC13. Therefore, if you want to make the diode emit light, you need to make PC13 output low level. The maximum operating voltage of STM32 is 3.6V, and an LDO (low dropout linear regulator) is used to reduce the input voltage VIN to 3.3v to power the microcontroller. Four 0.1uf bypass capacitors between 3.3V and GND (removing high-frequency AC signals) are connected to the chip's 4 VDD and 4 VSS (WHAT? Why does the chip have four VDD and four VSS? I Guess it should be to enhance the power supply capacity to ensure the reliability of the power supply).

3. Naming rules

        I found the STM32F103 Chinese manual on the Internet. The naming principle of the microcontroller is shown in the following figure:

4. Pin layout & pin multiplexing

        According to the naming rules, the C in STM32F103 C 8T6 represents that this chip has 48 pins, and its pin arrangement is shown in the following figure:

        The STM32 microcontroller has rich functions, and only 48 pins are not enough to allocate all functions, so some pins can realize several functions, which is called pin multiplexing. Generally speaking, the first function of most pins is GPIO (General Purpose Input Output). But it is worth noting that the default functions of PA13, PA14, P15, PB3, PB4, PC14, PC15, PD0, and PD1 are not GPIO, and the AFIO clock needs to be turned on when using them. Pay attention to this. An UP at station B made an intuitive picture, as shown below:

Image source: Public account "Electronic Development Learning"

        The default functions of the STM32F103 series microcontroller pins provided by the official manual are shown in the following figure:

5. Program download

        STM32 MCU supports 3 program download methods, which can be divided into ISP serial port download (using USB-TTL to connect to PA9, PA10), SWD download (using ST-LINK to connect to PA13, PA14), JTAG download (using JLINK to connect to PA13, PA14, PA15, PB3, PB4).

1. ISP download

        The whole process of ISP is In-System Programming, which means online system programming. The STM32 microcontroller can generally be programmed through the UART1 pin. When programming, it needs to cooperate with BOOT0 and BOOT1 to be grounded or not. BOOT0 and BOOT1 can be combined into four states. The meaning of different positions is shown in the figure below, where X is an irrelevant item.

        Before using the ISP serial port to download, you need to use a jumper cap to short BOOT0 to the 1 position and BOOT1 to the 0 position before powering on the microcontroller, that is, the system memory mode, and then the program can be downloaded through the serial port. After the ISP serial port download is completed, the power is turned off. Before the microcontroller is powered on, it is necessary to use a jumper cap to short BOOT0 to the position of 0, that is, the main flash memory mode.

        Due to the TTL level communication protocol used by the single-chip microcomputer, a serial-to-serial chip is required for serial communication with the USB port of the computer. The common ones are CH340 series (such as CH340N), FT232, PL2303, etc. The following figure takes CH340T as an example.

        The GND of the downloader is connected to the GND of the single-chip microcomputer (connect one), the 3.3V of the downloader is connected to the 3.3V of the single-chip microcomputer (or the 5V of the downloader is connected to the VIN of the single-chip microcomputer), the RXD of the downloader is connected to the single-chip microcomputer PA9 (U1TX), and the downloader TXD is connected to the single-chip microcomputer PA10. (U1RX) is connected.

        After understanding the wiring, you can try to compile and download. There are a lot of download software, ST officially released the Flash Loader Demonstrator software for program download, and there is also a FLYMCU download software in China.

Flash Loader Demonstrator

2. SWD download

        To download using the SWD interface, you only need to connect 3.3V (if the board for programming the program comes with its own power supply, the 3.3V pin does not need to be connected), GND, SWDIO (PA13), SWCLK (PA14), RST (non-essential connection), you can Buy more than ten pieces of ST-LINK downloader from Taobao (this U disk shape is not actually produced by ST company, but it can be used after burning their firmware). Using the SWD interface can not only program programming, but also realize online simulation (debug). The simulation process can monitor data such as registers, which is very suitable for software development (finding problems). It is worth noting that ST-LINK/V2 only supports burning programs for its own STM32 and STM8, and does not support burning programs for other companies' MCUs (even if they are also equipped with Cortex-M3 cores).

ST-LINK/V2

3. JTAG download

        The JTAG interface needs to use TMS (mode selection), TCK (clock), TDI (data input), TDO (data output), nTRST (reset, not necessary), corresponding to the STM32F103C8T6 is PA13 (TMS), PA14 (TCK), PA15(TDI), PB3(TDO), PB4(nTRST) pins, the first function of these pins is the JTAG interface, which is why these pins cannot be simply used as GPIO. When using JTAG download, you can use the J-LINK downloader (the genuine SEGGER J-LINK is more expensive, and the domestic imitation is recommended to buy the V9 version or above), or you can use the ST company's original or domestic imitation ST-LINK with JTAG interface /V2 (as introduced by Punctual Atomic, but still expensive, woohoo). However, the functions that can be realized by JTAG can also be realized by SWD in general. I am lazy and generally do not use this download interface.

J-LINK
ST-LINK/V2

        If we don't need to use JTAG download, but the GPIO resources are tight or the PCB design has already used these pins whose first function is JTAG, then we need to turn off JTAG. For example, if I want to use GPIOA15 as the GPIO port, then the code level needs to be implemented like this:

    GPIO_InitTypeDef GPIO_InitStructure;
 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);//使能PORTA时钟
	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);// 关闭JTAG但使能SWD
	GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_15;//PA15
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
 	GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIO

Detailed closing method: see another blogger's "STM32 JTAG Debugging"

6. RTT

        The full name of RTT is Real Time Transfer, which translates to real-time transmission. Why introduce this to you? It is mentioned above that J-LINK, ST-LINK, etc. can download programs, and can also simulate online. So the question is, do they directly support serial communication? The answer is no! ! ! But don't panic, in response to this problem, SEGGER has launched a shared memory technology. This function can save the need to use an external USART for serial data testing, which is very convenient. However, since RTT is launched by SEGGER, this requires the use of J-LINK V8 and above debuggers. If you are not bad, you can give priority to J-LINK. RTT supports all MCUs with ARM Cortex-M0/M0+/M1/M3/M4/M7/M23/M33 cores, not limited to STM32.

SEGGER official website

         However, to use the RTT function, you need to add the source code provided by SEGGER to the project file. The official website installation package: " data-link-title="<official website download>"><official website download> For detailed installation and use tutorials, see "Tough Guy" Information shared by brother" .

        After importing the source code, you can use the following functions in the program. These functions are easy to know according to the description:

Function name describe
SEGGER_RTT_Read() Read data from an input buffer.
SEGGER_RTT_Write() Write data to an output buffer.
SEGGER_RTT_WriteString() Write a zero-terminated string to an output buffer.
SEGGER_RTT_printf() Write a formatted string to an output buffer.
SEGGER_RTT_GetKey() Get one character from input buffer 0.
SEGGER_RTT_HasKey() Check if a character is available in input buffer 0.
SEGGER_RTT_WaitKey() Wait for a character to be available in input buffer 0 and get it.
SEGGER_RTT_ConfigUpBuffer() Configure an up (output) buffer.
SEGGER_RTT_ConfigDownBuffer() Configure a down (input) buffer.
SEGGER_RTT_Init() Initialize RTT Control Block structure when using RAM only targets.
SEGGER_RTT_SetTerminal() Set the "virtual" Terminal to use for output on channel 0 via Write and WriteString.
SEGGER_RTT_TerminalOut() Send a zero-terminated string via a "virtual" terminal.

         Finally, to use RTT, you need to install J-Link RTT Viewer, J-Link RTT Client, and J-Link RTT Logger on the computer. These three terminals can be installed and used as you like. 

RTTViewer

7. RTOS

        RTOS (Real-time operating system) is a general term for real-time operating systems. Currently, there are various real-time operating systems such as freeRTOS, RT-Thread, and UCOS-III on the market. At the complex and powerful hardware level of STM32, programmers will not Then just use it as a traditional MCU to run bare metal programs (bare metal refers to programs that do not use RTOS), but start to consider program coordination and parallel multitasking (not parallel in the true sense, because the single core is at the same time. can only handle one thing). RTOS is an interesting thing. If you are interested, I will consider updating an article about RTOS later. You can go to the freeRTOS official website to see or read articles by other authors. 

8. Introduction to the original text of the official website

        The STM32F103xx medium-density performance line family incorporates the high-performance ARM®Cortex®-M3 32-bit RISC core operating at a 72 MHz frequency, high-speed embedded memories (Flash memory up to 128 Kbytes and SRAM up to 20 Kbytes), and an extensive range of enhanced I/Os and peripherals connected to two APB buses. All devices offer two 12-bit ADCs, three general purpose 16-bit timers plus one PWM timer, as well as standard and advanced communication interfaces: up to two I2Cs and SPIs, three USARTs, an USB and a CAN.

        The devices operate from a 2.0 to 3.6 V power supply. They are available in both the –40 to +85 °C temperature range and the –40 to +105 °C extended temperature range. A comprehensive set of power-saving mode allows the design of low-power applications.
The STM32F103xx medium-density performance line family includes devices in six different package types: from 36 pins to 100 pins. Depending on the device chosen, different sets of peripherals are included, the description below gives an overview of the complete range of peripherals proposed in this family.
These features make the STM32F103xx medium-density performance line microcontroller family suitable for a wide range of applications such as motor drives, application control, medical and handheld equipment, PC and gaming peripherals, GPS platforms, industrial applications, PLCs, inverters, printers, scanners, alarm systems, video intercoms, and HVACs.

        Main features

  • ARM®32-bit Cortex®-M3 CPU Core
    • 72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1) performance at 0 wait state memory access
    • Single-cycle multiplication and hardware division
  • Memories
    • 64 or 128 Kbytes of Flash memory
    • 20 Kbytes of SRAM
  • Clock, reset and supply management
    • 2.0 to 3.6 V application supply and I/Os
    • POR, PDR, and programmable voltage detector (PVD)
    • 4-to-16 MHz crystal oscillator
    • Internal 8 MHz factory-trimmed RC
    • Internal 40 kHz RC
    • PLL for CPU clock
    • 32 kHz oscillator for RTC with calibration
  • Low-power
    • Sleep, Stop and Standby modes
    • VBAT supply for RTC and backup registers
  • 2 x 12-bit, 1 μs A/D converters (up to 16 channels)
    • Conversion range: 0 to 3.6 V
    • Dual-sample and hold capability
    • Temperature sensor
  • DMA
    • 7-channel DMA controller
    • Peripherals supported: timers, ADC, SPIs, I2Cs and USARTs
  • Up to 80 fast I/O ports
    • 26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almost all 5 V-tolerant
  • Debug mode
    • Serial wire debug (SWD) & JTAG interfaces
  • 7 timers
    • Three 16-bit timers, each with up to 4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder input
    • 16-bit, motor control PWM timer with dead-time generation and emergency stop
    • 2 watchdog timers (Independent and Window)
    • SysTick timer 24-bit downcounter
  • Up to 9 communication interfaces
    • Up to 2 x I2C interfaces (SMBus/PMBus)
    • Up to 3 USARTs (ISO 7816 interface, LIN, IrDA capability, modem control)
    • Up to 2 SPIs (18 Mbit/s)
    • CAN interface (2.0B Active)
    • USB 2.0 full-speed interface
  • CRC calculation unit, 96-bit unique ID
  • Packages are ECOPACK®

9. Summary of the article

        The STM32F103C8T6 microcontroller is designed in LQFP48 package. The chip has a total of 44 pins, of which A0-A15 has a total of 16 pins, B port has B0-B15, a total of 16 pins, and C port has C13-C15, a total of 3 pins. The D port has two pins, D0-D1. It is worth noting that the minimum core boards C14 and C15 are connected to a 32.768K crystal oscillator, and D0 and D1 are connected to an 8MHz crystal oscillator . Generally, they should not be used as IO ports. If you really want to use it, you can only remove the external crystal oscillator circuit (using HSI, LSI), and realize it by remapping and configuring the AFIO_MAPR register.

        In fact, after learning the STC15 series of microcontrollers, I was afraid of the STM32 microcontroller. I think there are many registers of the STC15F2K60S2 microcontroller. How do you remember so many registers of the STM32? Now I started to learn and learned that there is an official firmware library for everyone to call. According to the release time, it can be divided into early firmware library (below V3.0.0), standard peripheral library (click me to jump) , HAL library (click me to jump) , LL library (LL library is included in HAL library) Four kinds. At present, the latest standard library version is V3.5.0, which calls the official API for development. It was released by ST in 2011 and has been suspended for 10 years. Using HAL can be used for graphical development, which is more vivid in the senses. However, because the HAL library aims to solve the different general problems of the standard library on different series of microcontrollers, its code execution efficiency is not as high as that of the standard library. If the compiler optimization level is low, the generated HEX file will be larger. Later, ST launched the LL library for this problem. Most of the API functions of the LL library directly call registers, which improves the execution efficiency of the code. However, the longer the launch, the richer the data we can collect. I am currently learning the development method of the standard library, and I suggest you make a choice according to your own situation.

        More information can be found on ST's official Chinese website: Home - STMicroelectronics .

        Several study forums are recommended:

        1. Punctual Atom: OpenEdv

        2. Hard Rock Forum: Hard Rock Electronics - Community

        3. Tough Guy Embedded Forum: Tough Guy Embedded Forum - Powered by Discuz!

        4. Wildfire Forum: Wildfire Electronic Forum -

        5.51 Black Electronics Forum: 51 Black Electronics Forum - DIY MCU embedded technology learning for single-chip electronic production

        6. STM32 Arduino: STM32 Arduino-Arduino Chinese Community- Powered by Discuz!

Guess you like

Origin blog.csdn.net/fantastic_sky/article/details/110229474