Hi there,
I´m trying to replicate the blinking led programm of c in assembly, for educational purposes
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(250); // wait for a second
}
This is the assembly code
.syntax unified
.cpu cortex-m0plus
.thumb
.global main
.equ LED_PIN, 0x50000000 // Memory-mapped address of LED pin
.equ LED_PIN_CONFIG, 0x40000000 // Memory-mapped address of the pin configuration register
.equ LED_PIN_MASK, 0x2000 // 1 shifted 13 times to the left
.equ DELAY_COUNT, 0xFFFFFF
main:
ldr r0, =LED_PIN_CONFIG
movs r1, #1
str r1, [r0] // Configure LED_PIN as an output
setup:
ldr r0, =LED_PIN
ldr r1, =LED_PIN_MASK
turn_on:
str r1, [r0] // Turn on the LED
bl delay
turn_off:
movs r1, #0
str r1, [r0] // Turn off the LED
bl delay
b setup
delay:
ldr r0, =DELAY_COUNT
delay_loop:
subs r0, r0, #1
bne delay_loop
bx lr
I compiled it, and got the bin
arm-none-eabi-as -mcpu=cortex-m0plus -mthumb -o blink.o blink.S
arm-none-eabi-ld -o blink.elf blink.o
arm-none-eabi-objcopy -O binary blink.elf blink.bin
I upload the binary
arm-none-eabi-objcopy -O binary blink.elf blink.bin
It uploads with this message:
Set binary mode
readWord(addr=0)=0x20002dd8
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
version()=v1.1 [Arduino:XYZ] Nov 27 2019 16:35:59
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x20002dd8
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
writeWord(addr=0x20004020,value=0x20008000)
Device : ATSAMD21G18A
readWord(addr=0)=0x20002dd8
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Chip ID : 10010005
version()=v1.1 [Arduino:XYZ] Nov 27 2019 16:35:59
Version : v1.1 [Arduino:XYZ] Nov 27 2019 16:35:59
Address : 8192
Pages : 3968
Page Size : 64 bytes
Total Size : 248KB
Planes : 1
Lock Regions : 16
Locked : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security : false
Boot Flash : true
readWord(addr=0x40000834)=0x7000a
BOD : true
readWord(addr=0x40000834)=0x7000a
BOR : true
Arduino : FAST_CHIP_ERASE
Arduino : FAST_MULTI_PAGE_WRITE
Arduino : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 0.851 seconds
Write 52 bytes to flash (1 pages)
write(addr=0x20005000,size=0x40)
writeBuffer(scr_addr=0x20005000, dst_addr=0x2000, size=0x40)
[==============================] 100% (1/1 pages)
done in 0.083 seconds
Verify 52 bytes of flash with checksum.
checksumBuffer(start_addr=0x2000, size=0x34) = b9a0
Verify successful
done in 0.064 seconds
CPU reset.
readWord(addr=0)=0x20002dd8
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
writeWord(addr=0xe000ed0c,value=0x5fa0004)
But it does not work and the board goes back to bootload mode
Anyone have an idea on how to achive this?