Just as a status update, I am getting there, slowly.
The test program I am using is this:
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (true)
{
Serial.println("Hello World! ");
delay(1000);
}
}
The compiler produces the following assembler code:
.cpu cortex-m0plus
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 1
.eabi_attribute 30, 4
.eabi_attribute 34, 0
.eabi_attribute 18, 4
.file "HelloWorld_Picotest.ino.cpp"
.text
.Ltext0:
.cfi_sections .debug_frame
.section .text.loop,"ax",%progbits
.align 1
.global loop
.syntax unified
.code 16
.thumb_func
.fpu softvfp
.type loop, %function
loop:
.LFB3082:
.file 1 "/home/kelly/Arduino/HelloWorld_Picotest/HelloWorld_Picotest.ino"
.loc 1 8 0
.cfi_startproc
@ Volatile: function does not return.
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
push {r4, lr}
.cfi_def_cfa_offset 8
.cfi_offset 4, -8
.cfi_offset 14, -4
.loc 1 12 0
movs r4, #250
lsls r4, r4, #2
.L2:
.loc 1 11 0 discriminator 1
ldr r1, .L3
ldr r0, .L3+4
bl _ZN7arduino5Print7printlnEPKc
.LVL0:
.loc 1 12 0 discriminator 1
movs r0, r4
bl delay
.LVL1:
b .L2
.L4:
.align 2
.L3:
.word .LC0
.word _UART_USB_
.cfi_endproc
.LFE3082:
.size loop, .-loop
.section .text.setup,"ax",%progbits
.align 1
.global setup
.syntax unified
.code 16
.thumb_func
.fpu softvfp
.type setup, %function
setup:
.LFB3081:
.loc 1 4 0
.cfi_startproc
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
.loc 1 5 0
movs r1, #150
.loc 1 4 0
push {r4, lr}
.cfi_def_cfa_offset 8
.cfi_offset 4, -8
.cfi_offset 14, -4
.loc 1 5 0
lsls r1, r1, #6
ldr r0, .L6
bl _ZN7arduino4UART5beginEm
.LVL2:
.loc 1 6 0
@ sp needed
pop {r4, pc}
.L7:
.align 2
.L6:
.word _UART_USB_
.cfi_endproc
.LFE3081:
.size setup, .-setup
.section .rodata.loop.str1.1,"aMS",%progbits,1
.LC0:
.ascii "Hello World! \000"
.text
.Letext0:
.file 2 "/home/kelly/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/machine/_default_types.h"
.file 3 "/home/kelly/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/sys/_stdint.h"
.file 4 "/home/kelly/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/stdint.h"
Most of that is debugging information, and I have trimmed off several hundred lines similar to the last couple of lines in that output.
My assembler code is this:
.thumb_func // let the compiler know this code must be entered in thumb mode
.thumb // this code is 16 bit thumb code
.global main // make the label 'main' available to the linker
.syntax unified
.extern _UART_USB_ // constant from Arduino IDE
.extern _ZN7arduino4UART5beginEm // Serial.begin( int baud_rate ) as mangled by C++ compiler
.extern _ZN7arduino5Print7printlnEPKc // Serial.println("")
.extern delay // delay(int)
main:
bl setup // initialize USB port
loop:
ldr r0,=_UART_USB_ // data to go via USB port
ldr r1,=message // data is at this address
bl _ZN7arduino5Print7printlnEPKc // go print message
ldr R0,=1000 // delay is 1 second
bl delay
b loop
.align 2
message:
.asciz "Hello World! "
setup:
push {r4,lr}
ldr r0,=_UART_USB_ // set up Serial port
ldr r1,=9600 // baud rate is 9600
bl _ZN7arduino4UART5beginEm // call USB initialization
pop {r4,pc}
It compiles and links without error, so all the labels I am using exist. The problem is that the serial port does not show up to the host computer. It's as if the Serial.begin is not being called. When I add in code to blink an LED, I can verify that the code does return from the Serial.begin and the Serial.println. I can also confirm that the delay function works as intended. I'm obviously missing something somewhere.