当前位置:网站首页>0 basic self-study STM32 (wildfire) -- what is a register?

0 basic self-study STM32 (wildfire) -- what is a register?

2022-06-22 08:04:00 Fecter11

a key :
Memory mapping
Register mapping

First, learn to distinguish the components 1 Pin No , Note counterclockwise rotation .
## First figure out the internal structure of the chip
 A sketch
 Official Chinese Reference Manual
“AHB, yes Advanced High performance Bus Abbreviation , Advanced high performance bus ;
APB, yes Advanced Peripheral Bus Abbreviation , Advanced peripheral bus .”
 Insert picture description here

 System structure
 Insert picture description here

Icode
Drive unit :
 Insert picture description here
 Insert picture description here
 Insert picture description here
Passive unit :
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Here's a quote
 Insert picture description here
Next, check out the official data book ( English version )

 Insert picture description here
ARM The kernel is 32 position , That's it 2 Of 32 Power , That is to say 4294967296byte( byte ),1kb=1024byte, That is, that is 4194304kB,1mb =1024kb, That is to say 4096mb, and 1gb=1024mb , In the end is 4gb
therefore arm The kernel can access 4gb Content ,arm Then we will 4g The memory is divided into eight blocks .
 Insert picture description here
512mb*8=4096mb=4g

 Insert picture description here

flash It's in the first piece
 Insert picture description here
We can see from the external package of the chip that the chip used by wildfire is stm32f103zet6
Among them e On behalf of 512k Of flash
 Insert picture description here
Obviously, only a small part is used
 Insert picture description here
The point is block2 Peripheral part

 Insert picture description here

Memory mapping ( a key )
What is memory mapping ?
The memory itself does not have address information , His address is assigned by the game film manufacturer or user , The process of assigning addresses to memory is memory mapping

 Insert picture description here
Register mapping
With stc51 For example

# include <stdio.h>

sbit  LED = P0^0;

void main (void)
{
    
	P0 = 0xfe;
	LED =0;

}

Pay attention to the... We use P0, It is contained in the header file , The header file uses sfr Keyword let P0 Corresponding to the address of the corresponding register .

And in the stm32 Middle yield GPIOB Port of 16 Pin outputs high level , How to do that ??
Access memory units through absolute addresses
//GPIOB All ports output High level

*(unsigned int*(0x40010C0C) = 0xFFFF;

We find GPIOB Register start address of
 Insert picture description here
 Insert picture description here
We see the ODR The address offset of :0x0C, The offset here is the offset from the base address of the register just found . because GPIOB There is more than one register for .
that GPIOB The address of the port is :GPIOB The base address + Address offset
We can be right IO To operate

*(unsigned int*(0x40010C0C) = 0xFFFF;

among 0x40010C0C Is the address of the register
For the above, we need to grasp several key points :
1:0x40010C0C As GPIOB Output data register ODR How do people find your address ?
2:(unsigned int
) What is the role of ?
3: Learn how to use c Linguistic “*” Number
*

*(unsigned int*(0x40010C0C) = 0xFFFF;

Let's first cast 0x40010C0C As address .
If we write it directly as 0x40010C0C = 0xFFFF; The compiler doesn't know 0x40010C0C It's the address , So I can't use it . We need to force conversion .

Obviously, the above method is troublesome .

Access memory unit by register alias :

//GPIOB All ports output high level 
# define GPIOB_ODR (unsigned int*(0x40010C0C) ;
* GPIOB_ODR = 0xFF;

For the convenience of operation, you can also “*” Also defined in the alias of the register

//GPIOB All ports output high level 
# define GPIOB_ODR *(unsigned int*(0x40010C0C) ;
GPIOB_ODR = 0xFF;
原网站

版权声明
本文为[Fecter11]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220758581463.html