STM32 gotchas
106. Bit-banding cannot be used with DMA

Bit-banding is an interesting addition to the Cortex-M3/M4 processors (used in STM32F1/L1/F2/F4/F3/L4/G4), which allows atomic access1 to a portion of memory and peripherals.

In some cases, it is tempting to use this access to read or write single bits also from DMA (e.g. to flip polarity of TIMx_CHx output by writing to its respective TIMx_CCER.CCxP).

This does not work, as bit-banding is performed by an extension on the S-port of the processor. This extension intercepts accesses from processor targeted to the bit-addressable regions, "translates" the address from the bit-addressable to the "real" memory/peripheral address, generates the appropriate bitmask, and converts the bit-banding access to either a RMW operation modifying the required bit if it is a write, or to a read followed by mask-and-shift to return only the required bit on the data bus for the processor.

However, accesses from DMA don't go through this extension.

DMA accesses don't go through bit-banding extension on S-port of processor.

In other words, for DMA (and other bus-masters), the bit-addressable alias area is simply nonexistent, and accessing it results in DMA transfer error.

1. Bit-oriented access through bit-banding is atomic from the processor's perspective, i.e. it cannot be interrupted by any other process within the processor. However, if the target of access is a bit within a peripheral register with other bits changed directly by hardware, the consequences are the same as with any other read-modify-write accesses to such peripheral registers. See detailed discussion of this issue here.