51 Single chip computer estimates have been used , It can be done alone P1 The first one in the mouth IO Operate , however STM32 This is not allowed , For example 51 Single chip microcomputer can also be independent of a certain IO Operate alone , The concept of bit band operation is introduced , In short , In short , It's to operate alone 32 One of the ports in it , That's why we have a bit band mechanism .

Potential zone , And bit aliased area , Potential zone , That's what you want to do alone IO Area of , that is PA,PB Wait for this pile IO The memory area of the port , And the bit is aliased , It's the address area that gives everyone a new name .M3 kernel
Memory mapping table ,1M In memory BitBand area , There are also corresponding ones 32M In memory BitBand Alias area , Because you inflate each one into one 32 position , Therefore, the memory of the corresponding alias area will also be bitband 32 times .

Official calculation formula , Take peripherals as an example

AliasAddr Is the address of the alias area ,A yes GPIOA->ODR Address of ,n Is a bit on the port , Here it is 1, Through this formula, you can find the address of the corresponding alias area , The next step is to operate on this address , You write for him 1, This bit is output 1, write 0, Just output 0.

0x42000000 Is the starting address of the bit alias region ,A Is the output data register GPIOA->ODR Address of ,A The bitband base address is subtracted first , The offset address relative to the base address of the bit band is obtained , So after the expansion, it is still an offset address , Is the offset from the bitalias base address , Add upper alias base address , The corresponding alias address is obtained , This is the general principle ,

((A‐0x40000000)*8+n)*4 =0x42000000+ (A‐0x40000000)*32 + n*4

Each bit corresponds to one 32 Character of bit , This completes the final address translation , The key is to pay attention to two points , everything , The mutual conversion of two parts of address , Mainly the base address of each part . Second, it's bit up 32 A method concept such as bit address .
// Bit band operation , realization 51 allied GPIO control function
// Concrete realization idea , reference resources 《CM3 Authoritative guide 》 Chapter five （87 page ~92 page ）.M3 with M4 similar , It's just that the register address has changed

//IO Port operation macro definition
&0xFFFFF)<<5)+(bitnum<<2))

//IO Mouth operation , Only for single IO mouth

// ensure n The value of is less than 16