Introduction: the H7 board and an assembly review
You meet the STM32H750B-DK, build the course’s stm32h7-asm project in STM32CubeIDE and step through it with the debugger. The exercises revise the ARM assembly you know from the first year: registers, loads and stores, flags and loops.
What you need to understand
- The core has 16 registers:
r0-r12for data,sp(stack pointer),lr(return address) andpc. Flags N, Z, C, V live inAPSR. - ARM is a load/store architecture: only
ldrandstrtouch memory, every calculation works on registers. - An
ssuffix (subs,adds) updates the flags, and a conditional branch (beq,bne,blt…) reads them. Without thes, a countdown loop never ends. ldr r0, =labelloads an address (or a big constant),ldr r0, [r1]loads the word at the address inr1.- The memory map: code runs from flash at
0x08000000, the course project keeps variables and the stack in AXI SRAM at0x24000000, and peripherals are registers at fixed addresses (0x4000 0000and up).
Assembly example
Paste into Main.s of stm32h7-asm. Assembled with the arm-none-eabi-as from STM32CubeIDE.
.syntax unified
.cpu cortex-m7
.thumb
.data
table: .word 3, 7, -2, 10, 5 // five 32-bit numbers in RAM
sum: .word 0
.text
.global main
.type main, %function
main:
ldr r0, =table // r0 = address of the first element
mov r1, #5 // r1 = elements left
mov r2, #0 // r2 = running sum
next:
ldr r3, [r0], #4 // r3 = word at r0, then r0 = r0 + 4
add r2, r2, r3
subs r1, r1, #1 // S: sets the Z flag when r1 reaches 0
bne next
ldr r0, =sum
str r2, [r0] // sum = 23: check it in the Memory view
end: b endCommon mistakes
subinstead ofsubsin a loop counter: the flags never change andbneloops forever.- Mixing up
ldr r0, =x(address of x) andldr r0, [r0](value at that address). - Values in
.dataare copied from flash to RAM by the startup code beforemain. Looking at them beforemainruns shows garbage.