51 microcontroller series based on STM32 development board _ light up an LED and flash it

Development environment:

Development board: STM32PZ6806L
  Chip: ARM_STM32F103_ZE

Required information for development:

STM32F1XX chip circuit schematic
STM32F1XX series chip manual

XX represents the serial version number. Most of the chips developed by ARM are the same. The chip manual will be corrected unless new functions are added. XX represents that the document supports the serial version!

The first step is to analyze the circuit schematic

The first step is to open the circuit schematic of the STM32F1XX chip:


Find the schematic diagram of the LED module circuit, and then check whether the LED circuit module is designed on this board:


After finding it, it means that the board has designed the LED circuit module, then zoom in to see:


As you can see from the LED module circuit schematic, each LED (LED1-LED8) has a diode (D1-D8) connected

The two pins of the diode are distinguished by positive and negative electrodes. From the schematic diagram, it can be known that the positive electrode of the diode corresponds to the LED, and the negative electrode corresponds to the input source.


So if we want to make the LED light, we must first go through the diode connected to the LED, so we need to make the diode work, input a low level from the input source, and then make the negative terminal of the diode work, on the contrary If the input is high, the negative end of the diode will not have any effect!

(Diode polarity connection identification method)


And there are two resistors in the input source, and there are four resistors in each row, which is used to simplify PCB board design


However, the schematic diagram of the internal resistance is not clearly given. The blogger infers that the pull-up and pull-down resistors should be used for current limiting.


In addition, it is also known that the maximum withstand level of the circuit module is +3.3v (0-3.3v)


If the circuit schematic diagram of the LED module is understood, then it is necessary to know which bus of the processor the LED module is connected to!

Why do you need to know which bus is on?

Here's an analogy for finding someone:

Just like looking for someone, you know who he is and what he does, but if you want to find him now, do you want to go to his house?

So before you go to his house, you need to know where his house is and what the house number is. With a specific route and number, you can easily find his house and find him!

Then let's take a look at the circuit schematic diagram, the connection circuit schematic diagram of the CPU block:


Zoom in a bit:



It can be seen that each LED module (1-8) corresponds to the PC special function register (0-7)

If you know the special function register corresponding to the LED, then you need to know which bus the special function register is mounted on and what the mapping address is!

Before starting the search, I will add a little knowledge to you:

What are special function registers? What is a mapped address?

Answer: The special function register is essentially a storage unit and there is no difference between the storage unit in the memory, but the storage unit in the memory is used to store single-byte data, and the storage unit in the microprocessor is usually 4 bytes. Or 8 bytes as a unit, used for special calculations/operations, such as the DS segment register used to store addresses, its size determines the addressing capability of the CPU! The CPU will address according to the address in the DS register, and the address bus bit width should be consistent with the DS register. If the address bus bit width is smaller than the DS register, then the address bus will not be able to express an address larger than itself!

What is a mapped address?

Answer: Here is an analogy. If you live in room xx, building xx in a certain community, then this address is the address of your room. We usually fill in this address every time we order takeaway or express delivery, then the courier will have this address. It is easy to find our room and deliver the goods to us. This address is the mapping of your room, and the mapping of the special function register is as mentioned above. It is to assign a physical address on the development board to it, which is called address mapping. !

Related articles: In- depth understanding of "CPU internal addressing mode" , detailed explanation: the relationship between physical addresses, virtual addresses, memory management, and logical addresses

Closer to home, knowing the special function registers corresponding to the LED module, we can go to the STEM32 chip manual to view the introduction of the various registers of the chip, as well as the address mapping and the bus.

Open the chip manual of STM32


Find the schematic diagram to be introduced to the PC SFR bus hookup on page 2.3.30:


Find the PC special function registers:


As shown in the figure above, the PC special function register is connected by the GPIO pin whose GPIO port is C, and the GPIO port C is connected to the APB2 bus, and APB2 is connected to the AHB2 bus!

Note how this setup is distinguished. First of all, GPIO port C is actually composed of a group of GPIO pins, but this pin is responsible for the I/operation of PC special function registers, and other GPIO pins are responsible for other special function registers. Such as PE, PB, etc., in order to distinguish and make developers easier to read, ARM distinguishes them, that is, port C, port E, port G, etc., corresponding to different special function registers.

Just like a person, you want someone to come and help you, do you have to call his name first, then he will know that you are calling him, if in the case of many people, no one knows you are calling Who!

Closer to home, so if you have a name to work, is it a group? Let a group do or manage a certain thing to form a project system, so ARM has grouped it for easy management, GPIO port C and other ports are planned on the APB2 bus, which is the name of this group It is APB2, and APB2 is planned to be on the AHB2 bus, so the corresponding situation is: GPIO port C and other ports = APB2 and APB2 is also equal to AHB2, which is easy to distinguish and manage, and form a project system!


Here we can know from the above figure that the bus connection pin used by the PC special function register is GPIO, then we have to check how ARM designs the GPIO pin of the development board!

You can find the design of GPIO pins in this development document: STM32 Reference Manual. This development document corresponds to the GPIO pin design of all chips, except for some specific development boards that need to be redesigned, because ARM's series of STM development boards lead The methods used in foot design are all based on this development document and will not be changed. Due to the large document size and many chapters, it is recommended to download the Chinese version:

The design diagram for the GPIO pins can be found in 8.1:


As can be seen from the above figure, the GPIO pins used by STM32 have protection diodes inside to prevent abnormal voltages that are too high or too low from entering the chip. If the voltage is too high, the protection diodes will be burned out, because the diodes will absorb the first The voltage is used to judge whether the voltage value is correct or not, and let it enter the chip. If the voltage is too high, the diode may be burned directly.


Two are connected because one corresponds to input and one corresponds to output, and GPIO belongs to I/O pin!

Secondly, there are pull-up and pull-down resistors to correct the level!


Why do we need pull-up and pull-down resistors with protection diodes?

Answer: Different modules use different voltages, because these modules are not built with the development board, but are soldered on later. These modules are developed by different hardware engineers, so connect pull-up and pull-down resistors, you can put a Uncertain voltage is corrected to the normal voltage used by the module!

We will not look at the rest for the time being, because we can know from this information that we do not need to consider whether the voltage used by the computer is the same as that of the development board when sending the voltage. Of course, make sure that the voltage of your computer cannot be too high! Generally speaking, home computers are around 3.xv, so this voltage protection diode can be fully tolerated!

Knowing the installation of the bus is like the analogy above, knowing the name and wanting to find him and ask him to help, do you need to know where his home is? Do I need to know the phone number even if I make a phone call?

Then we find the mapping of special function registers in the chip manual:

The bus map address can be found in Chapter 4 of the chip manual. Note that the special function register is connected to the bus, so it is the bus map address:


Let's talk about the above address mapping introduction


As can be seen from this figure, ARM divides the address space into four blocks, each with a size of 512-Mbyte (MB), the name is called bloc x and the function

From the above value, ARM divides the address space into four blocks, each block size is 512MB, 4*512=4G space, that is to say, ARM divides the 4G space into 4 blocks, each block is 512MB, we see the function of the following figure :


As shown in the figure above, the role of each space is:


Explaining these is just to let everyone have an understanding of ARM's regional division. The most important place is the address mapping:


The ARM on the right will be divided into four blocks of addresses, and the bus name of each block of addresses will be written out, then you can find the bus name and address that we need to operate in the address mapping table, and you can use C language pointers to control it :


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324880248&siteId=291194637