微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > STM32(cortex_m3) 的 Bit-Banding 该怎样理解?

STM32(cortex_m3) 的 Bit-Banding 该怎样理解?

时间:10-02 整理:3721RD 点击:
STM32(cortex_m3) 的 Bit-Banding 该怎样理解?

原文是这样的:

Bit-Banding
The Cortex-M3 memory map includes two bit-band memory regions. These regions map each word in an alias region of memory to a bit in a bit-band region of memory. Writing to a word in the alias region has the same effect as a read-modify-write operation on the targeted bit in the bit-band region.
All the STM32F10x peripheral registers are mapped in a bit-band region. This feature is consequently intensively used in functions which perform single bit set/reset in order to reduce and optimize code size.
......
/* Peripheral address in the alias region */
#define PERIPH_BB_BASE ((u32)0x42000000)

它 举 的 例子中, 这个 PERIPH_BB_BASE ((u32)0x42000000) 是如何确定的?

这个文档 是 STM32 的 Firware library  的 PDF文件。


Bit-Banding的意思是:对Bit-Band区一个字的操作对应实际存储器中的一位。

在STM32F10xxx的技术参考手册中第2.3.3节,有这样的描述:

Cortex-M3存储器映像包括两个位段(bit-band)区。这两个位段区将别名存储器区中的每个字映射到位段存储器区的一个位,在别名存储区写入一个字具有对位段区的目标位执行读-改-写操作的相同效果。

在STM32F10x里,外设寄存器和SRAM都被映射到一个位段区里,这允许执行单一的位段的写和读操作。

下面的映射公式给出了别名区中的每个字是如何对应位带区的相应位的:
bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number × 4)
其中:
- bit_word_addr 是别名存储器区中字的地址,它映射到某个目标位。
- bit_band_base 是别名区的起始地址。
- byte_offset 是包含目标位的字节在位段里的序号
- bit_number 是目标位所在位置(0-31)
下面的例子说明如何映射别名区中SRAM地址为0x20000300的字节中的位2:
0x22006008 = 0x22000000 + (0x300*32) + (2*4).
对0x22006008地址的写操作和对SRAM中地址0x20000300字节的位2执行读-改-写操作有着相同的效果。

读0x22006008地址返回SRAM中地址0x20000300字节的位2的值(0x01 or 0x00)。

请参考《Cortex-M3技术参考手册》以了解更多有关位段的信息。

上面例子中的基地址0x22000000和你所讲的基地址0x42000000是固定在芯片中,你必须用这两个地址;基地址0x22000000用于操作内置RAM,基地址0x42000000用于操作内置外设。


如果你有其他的理解,欢迎回帖讨论


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top