Bit_band is supported. bit_band is implemented in two zones. One of them is the minimum 1 MB range of the SRAM area, and the other is the on-chip peripherals.
// The minimum range of the partition is 1 MB. In addition to the normal ram, the addresses in these two zones also have their own
// Your "bit with alias", and bit with alias expands each bit into a 32-bit word
//
// Each bit expands into a 32-bit word, that is, 1 m is extended to 32 m,
//
// Therefore, the RAM address 0x200000000 (one byte) is extended to 8 32-bit characters, which are:
// 0x220000000, 0x220000004,0x220000008, 0x22000000c, 0x220000010,0x220000014, 0x220000018, 0x22000001c
// The range of the two memory zones that support bit-belt operations is:
// 0x2000_0000-0x200f_ffff (
// 0x4000_0000-0x400f_ffff (minimum 1 MB in the On-Chip external area)
/*
For a bit in the SRAM bit band, the byte address of the BIT is A, and the BSN
The address in the alias area is:
Aliasaddr = 0x22000000 + (a‐0 x 20000000) * 8 + n) * 4 = 0x22000000 + (a‐0 x 20000000) * 32 + N * 4
For a bit of the On-chip peripheral bit band, note that its byte address is a and its bit number is n (0 <= n <= 7 ).
The address in the alias area is:
Aliasaddr = 0x42000000 + (a‐0 x 40000000) * 8 + n) * 4 = 0x42000000 + (a‐0 x 40000000) * 32 + N * 4
In the above formula, "* 4" indicates that a word is 4 bytes, and "* 8" indicates that one byte contains 8 bytes.
*/
// Convert "bit with address + bit serial number" to an alias address macro
# Define bitband (ADDR, bitnum) (ADDR & 0xf0000000) + 0x2000000 + (ADDR & 0 xfffff) <5) + (bitnum <2 ))
// Convert the address into a pointer
# Define mem_addr (ADDR) * (volatile unsigned long *) (ADDR ))
// Mem_addr (bitband (u32) & crcvalue, 1) = 0x1;
For example
// Use the stm32 Library
Gpio_resetbits (gpioc, gpio_pin_4); // turn off led5
Gpio_setbits (gpioc, gpio_pin_7); // enable led2
// General read Operations
Export _gpioc_regs-> bsrr. Bit. br4 = 1; // 1: Clear the corresponding odry bit to 0
Export _gpioc_regs-> bsrr. Bit. bs7 = 1; // 1: Set the corresponding odry bit to 1.
// If you use a bit with an alias
Export _bb_gpioc_regs-> bsrr. BR [4] = 1; // 1: Clear the corresponding odry bit to 0
Export _bb_gpioc_regs-> bsrr. BS [7] = 1; // 1: Set the corresponding odry bit to 1
Code is 10 times more efficient than the stm32 library!
Bit operations on memory variables.
// SRAM variable
Long crcvalue;
// Convert "bit with address + bit serial number" to an alias address macro
# Define bitband (ADDR, bitnum) (ADDR & 0xf0000000) + 0x2000000 + (ADDR & 0 xfffff) <5) + (bitnum <2 ))
// Convert the address into a pointer
# Define mem_addr (ADDR) * (volatile unsigned long *) (ADDR ))
// Set bit1 Of the 32-bit variable to 1:
Mem_addr (bitband (u32) & crcvalue, 1) = 0x1;
// Determine any one (23rd bits:
If (mem_addr (bitband (u32) & crcvalue, 23) = 1)
{
}