Difference between revisions of "STM32 Bit Banding"

From Stm32World Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
[[Category:STM32]][[Category:STM32 Development]][[Category:C]]{{metadesc|Bit Banding in STM32 MCUs}}
 
[[Category:STM32]][[Category:STM32 Development]][[Category:C]]{{metadesc|Bit Banding in STM32 MCUs}}
 
In older 8-bit [[MCU]]s it was quite common to have instructions to clear or set a bit as one atomic instruction.  By atomic it means the read->modify->write can not be interrupted resulting in other bits being set wrongly.
 
In older 8-bit [[MCU]]s it was quite common to have instructions to clear or set a bit as one atomic instruction.  By atomic it means the read->modify->write can not be interrupted resulting in other bits being set wrongly.
 +
 +
== Macro's to Calculate Bit Band Address ==
 +
 +
<pre>
 +
#define BITBAND_SRAM_REF    0x20000000
 +
#define BITBAND_SRAM_BASE  0x22000000
 +
#define BITBAND_PERIPH_REF  0x40000000
 +
#define BITBAND_PERIPH_BASE 0x42000000
 +
 +
#define bitband_t *(volatile uint32_t*)
 +
 +
#define m_BITBAND_SRAM(address,bit) (BITBAND_SRAM_BASE + (((uint32_t)address) - BITBAND_SRAM_REF) * 32 + (bit) * 4)
 +
#define m_BITBAND_PERIPH(address,bit) (BITBAND_PERIPH_BASE + (((uint32_t)address) - BITBAND_PERIPH_REF) * 32 + (bit) * 4)
 +
</pre>
  
 
== Miscellaneous Links ==
 
== Miscellaneous Links ==
  
 
To be added
 
To be added

Revision as of 06:49, 20 October 2024

In older 8-bit MCUs it was quite common to have instructions to clear or set a bit as one atomic instruction. By atomic it means the read->modify->write can not be interrupted resulting in other bits being set wrongly.

Macro's to Calculate Bit Band Address

#define BITBAND_SRAM_REF    0x20000000
#define BITBAND_SRAM_BASE   0x22000000
#define BITBAND_PERIPH_REF  0x40000000
#define BITBAND_PERIPH_BASE 0x42000000

#define bitband_t *(volatile uint32_t*)

#define m_BITBAND_SRAM(address,bit) (BITBAND_SRAM_BASE + (((uint32_t)address) - BITBAND_SRAM_REF) * 32 + (bit) * 4)
#define m_BITBAND_PERIPH(address,bit) (BITBAND_PERIPH_BASE + (((uint32_t)address) - BITBAND_PERIPH_REF) * 32 + (bit) * 4)

Miscellaneous Links

To be added