Why DMA
To send "Hello", the CPU puts one byte in USART2's data register, then checks again and again until it has gone: polling. At 9600 baud a byte takes about 1.04 ms, so five bytes keep a 168 MHz CPU waiting about 875,000 clock ticks.
DMA, direct memory access, is a small engine on the chip that copies data by itself. The CPU tells it where the data is, where it goes and how many items. Then the CPU is free until DMA raises an interrupt.
The STM32F407 has 2 DMA controllers with 8 streams each. A fixed table wires each request, a peripheral's call for data, to a stream and channel: USART2 transmit is DMA1, stream 6, channel 4. Its registers are memory addresses, starting at 0x400260A0.
Set it up by hand
Line 1 writes PAR, the peripheral address register. It holds the address of USART2's data register, 0x40004404. Every byte will be written there. S is our short name for DMA1_Stream6, a pointer to the stream's registers.
Line 2 writes M0AR, the memory address register: where msg starts in SRAM. Say the linker put it at 0x20000000. DMA reads the first byte, H, from there.
Line 3 writes NDTR, the number of data items: 5, one for each letter of Hello. NDTR counts down by one after every byte moved. At 0 the stream stops by itself.
Line 4 sets the control register in one go: 0x08000450. Bits 27 to 25 hold 4: channel 4. MINC, bit 10, steps through memory. DIR = 01, bits 7 to 6, means memory to peripheral. TCIE, bit 4, asks for an interrupt.
Line 5 sets DMAT, bit 7 of USART2's CR3 register. Now, whenever its data register is empty, USART2 sends a request to DMA, instead of waiting for the CPU to notice.
Let it run
Line 6 sets EN, bit 0 of CR, and the stream starts. Each request moves one byte from SRAM into the data register, and NDTR counts 5, 4, 3, 2, 1, 0. Meanwhile the CPU is free to run other code.
At NDTR = 0, DMA sets the TCIF6 flag and interrupt 17 runs DMA1_Stream6_IRQHandler. The handler clears the flag through HIFCR. The CPU wrote 6 registers instead of waiting about 875,000 ticks.
What happens
;; step 1/10 · poll
polling: the CPU copies every byte itself
for each of the 5 bytes of "Hello":
wait until DR is empty (TXE = 1)
USART2->DR = byte;
one byte 10 bits at 9600 baud = 1.04 ms
5 bytes 5.21 ms
CPU 168 MHz x 5.21 ms = 875,000 ticks spent waiting
The card shows the six set-up lines. The whole function also turns on the DMA1 clock (bit 21 of RCC->AHB1ENR), clears USART2's TC flag by writing 0 to it, and enables interrupt 17 in the NVIC. USART2 itself is set up as in ST's STM32F4-Discovery example: 9600 baud, 8 data bits, no parity, one stop bit. Transfer complete means DMA has handed the last byte to the data register, not that it has left the pin: it still needs about 1.04 ms on the wire. Wait for USART2's own TC flag before turning the port off.