Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @; blinky.s
- @; Shortest blinky program for Blue Pill (STM32F103) ever written.
- @; Binary size is only 26 bytes long.
- @; Build instructions:
- @; arm-none-eabi-as blinky.s -o blinky.o # may worn about alignment, it's ok
- @; arm-none-eabi-ld blinky.o -Ttext=0x08000000 -o blinky.elf
- @; arm-none-eabi-objcopy blinky.elf -O binary blinky.bin
- @; stat -c %s blinky.bin
- @; CPU runs at default 8MHz internal clock.
- .syntax unified
- .cpu cortex-m3
- .thumb
- .global _start
- @; Bit-band addresses:
- @; 2b 1b (see lines 42-48)
- PORTC_ENABLE_BIT = 0x42420310 + 3
- PC13_MODE0_BIT = 0x422200d0
- PC13_OUTPUT_BIT = 0x422201b4
- DIFF_228 = PC13_OUTPUT_BIT - PC13_MODE0_BIT
- .text
- @; Initial stack pointer value is used for storing a register address.
- stack_pointer_value: .word PC13_MODE0_BIT
- reset_vector: .word _start + 1
- _start:
- @; This and next `ldr` instruction align `pc` to word boundary.
- adds r1, #1
- @; Loading address relative to `pc + #0` is size-efficient.
- ldr r0, [pc]
- @; Next word evaluates to
- @; lsls r3, r2, #12
- @; negs r2, r0
- .word PORTC_ENABLE_BIT
- @; Next is undocumented behaviour.
- @; Writing to `bit-band address + 3` value `0x0100`
- @; is the same as writind value `0x0001` to `bit-band address + 0`
- @; 2b (second byte of `r0` has 1 in LSB)
- str r0, [r0]
- @; 1b (first byte of `r0` also has 1 in LSB)
- str r0, [sp]
- @; `r1` holds a counter value; writing it's 15'th bit
- @; to the output makes led blink with a certain frequency.
- movs r0, r1, lsr #14
- @; `sp` contains the bit-band address of `PC13 mode bit 0`,
- @; addind 228 gives the address of `PC13 bit in output register`.
- str r0, [sp, #DIFF_228]
- @; short branch to start
- b.n _start
Advertisement
Add Comment
Please, Sign In to add comment