Last active
April 15, 2024 01:07
-
-
Save todbot/119582ba35fae1503ec36d96d9ae366f to your computer and use it in GitHub Desktop.
samd21 blink LED on PA06 on Trinket M0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// samd21 blink LED on PA10 on Trinket M0 | |
// adapted / stolen from: | |
// https://github.com/LifeWithDavid/RaspberryPiPico-BareMetalAdventures/blob/main/Chapter%2004/assembly.s | |
.cpu cortex-m0 | |
.syntax unified | |
.thumb | |
.global main // used in startup.s | |
.section .text | |
main: | |
movs r2, #128 // 0x80 | |
lsls r2, r2, #3 // shift r2 * 8 = 0x400 = 1<<10 = PA06 | |
ldr r0, =PORT_DIRSET // load DIRSET address into r0 | |
str r2, [r0, #0] // set bit 10 in PORT_DIRSET (make output) | |
ldr r1, =PORT_OUTCLR // load OUTCLR address into r0 | |
ldr r0, =PORT_OUTSET // and OUTSET into r1 (wasteful but I'm learning) | |
todloop: | |
str r2, [r0, #0] // set bit 10 in OUTCLR (r2 has (1<<10)) | |
ldr r3, =DELAY1 | |
bl delay // call subroutine | |
str r2, [r1, #0] // set bit 10 in OUTSET (r2 has (1<<10)) | |
ldr r3, =DELAY2 | |
bl delay // call subroutine | |
b todloop // continue forever | |
delay: | |
subs r3, #1 // subtract one from reg 3 | |
bne delay // loop back if not zero | |
bx lr // return from subroutine | |
//mov r0, r0 // to word align data below? | |
// data must be 4-byte aligned? how to achieve? | |
.data | |
.equ DELAY1, 180000 | |
.equ DELAY2, 140000 | |
.equ PORT_DIR, 0x41004400 | |
.equ PORT_DIRCLR, 0x41004404 | |
.equ PORT_DIRSET, 0x41004408 | |
.equ PORT_DIRTGL, 0x4100440C | |
.equ PORT_OUT, 0x41004410 | |
.equ PORT_OUTCLR, 0x41004414 | |
.equ PORT_OUTSET, 0x41004418 | |
.equ PORT_OUTTGL, 0x4100441C | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More standard way might be loading the base address for PORT DIR and PORT OUT and using SET/CLR offsets: