Skip to content

Commit

Permalink
adding uart02 example
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch67 committed Apr 10, 2016
1 parent 8ecdf1f commit d6ae04c
Show file tree
Hide file tree
Showing 7 changed files with 544 additions and 0 deletions.
98 changes: 98 additions & 0 deletions ATSAMD21/uart02/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

ARMGNU = arm-none-eabi
#ARMGNU = arm-linux-gnueabi

AOPS = --warn --fatal-warnings -mcpu=cortex-m0
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding -mcpu=cortex-m0

LOPS = -Wall -m32 -emit-llvm -target arm-none-eabi -mcpu=cortex-m0 -mthumb
LLCOPS = -march=thumb -mcpu=cortex-m0
#LLCOPS = -mcpu=cortex-m0
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
#at some point they changed this option, gee thanks
#OOPS = -std-compile-opts
OOPS = -std-link-opts

gcc : uart02.gcc.thumb.flash.bin uart02.gcc.thumb.sram.bin

all : gcc clang

clang : uart02.clang.thumb.norm.flash.bin uart02.clang.thumb.opt.flash.bin uart02.clang.thumb.norm.sram.bin uart02.clang.thumb.opt.sram.bin

clean:
rm -f *.bin
rm -f *.o
rm -f *.elf
rm -f *.list
rm -f *.bc
rm -f *.opt.s
rm -f *.norm.s
rm -f *.hex

#---------------------------------

flash.o : flash.s
$(ARMGNU)-as $(AOPS) flash.s -o flash.o

sram.o : sram.s
$(ARMGNU)-as $(AOPS) sram.s -o sram.o

uart02.gcc.thumb.o : uart02.c
$(ARMGNU)-gcc $(COPS) -mthumb -c uart02.c -o uart02.gcc.thumb.o

uart02.gcc.thumb.flash.bin : flash.ld flash.o uart02.gcc.thumb.o
$(ARMGNU)-ld -o uart02.gcc.thumb.flash.elf -T flash.ld flash.o uart02.gcc.thumb.o
$(ARMGNU)-objdump -D uart02.gcc.thumb.flash.elf > uart02.gcc.thumb.flash.list
$(ARMGNU)-objcopy uart02.gcc.thumb.flash.elf uart02.gcc.thumb.flash.bin -O binary

uart02.gcc.thumb.sram.bin : sram.ld sram.o uart02.gcc.thumb.o
$(ARMGNU)-ld -o uart02.gcc.thumb.sram.elf -T sram.ld sram.o uart02.gcc.thumb.o
$(ARMGNU)-objdump -D uart02.gcc.thumb.sram.elf > uart02.gcc.thumb.sram.list
$(ARMGNU)-objcopy uart02.gcc.thumb.sram.elf uart02.gcc.thumb.sram.hex -O ihex
$(ARMGNU)-objcopy uart02.gcc.thumb.sram.elf uart02.gcc.thumb.sram.bin -O binary

#---------------------------------

uart02.clang.bc : uart02.c
clang $(LOPS) -c uart02.c -o uart02.clang.bc

uart02.clang.thumb.norm.flash.bin : flash.ld flash.o uart02.clang.bc
#llc $(LLCOPS) uart02.clang.bc -o uart02.clang.thumb.norm.s
#$(ARMGNU)-as $(AOPS) uart02.clang.thumb.norm.s -o uart02.clang.thumb.norm.o
llc $(LLCOPS) uart02.clang.bc -filetype=obj -o uart02.clang.thumb.norm.o
$(ARMGNU)-ld -o uart02.clang.thumb.norm.flash.elf -T flash.ld flash.o uart02.clang.thumb.norm.o
$(ARMGNU)-objdump -D uart02.clang.thumb.norm.flash.elf > uart02.clang.thumb.norm.flash.list
$(ARMGNU)-objcopy uart02.clang.thumb.norm.flash.elf uart02.clang.thumb.norm.flash.bin -O binary

uart02.clang.thumb.opt.flash.bin : flash.ld flash.o uart02.clang.bc
opt $(OOPS) uart02.clang.bc -o uart02.clang.thumb.opt.bc
#llc $(LLCOPS) uart02.clang.thumb.opt.bc -o uart02.clang.thumb.opt.s
#$(ARMGNU)-as $(AOPS) uart02.clang.thumb.opt.s -o uart02.clang.thumb.opt.o
llc $(LLCOPS) uart02.clang.thumb.opt.bc -filetype=obj -o uart02.clang.thumb.opt.o
$(ARMGNU)-ld -o uart02.clang.thumb.opt.flash.elf -T flash.ld flash.o uart02.clang.thumb.opt.o
$(ARMGNU)-objdump -D uart02.clang.thumb.opt.flash.elf > uart02.clang.thumb.opt.flash.list
$(ARMGNU)-objcopy uart02.clang.thumb.opt.flash.elf uart02.clang.thumb.opt.flash.bin -O binary


uart02.clang.thumb.norm.sram.bin : sram.ld sram.o uart02.clang.bc
#llc $(LLCOPS) uart02.clang.bc -o uart02.clang.thumb.norm.s
#$(ARMGNU)-as $(AOPS) uart02.clang.thumb.norm.s -o uart02.clang.thumb.norm.o
llc $(LLCOPS) uart02.clang.bc -filetype=obj -o uart02.clang.thumb.norm.o
$(ARMGNU)-ld -o uart02.clang.thumb.norm.sram.elf -T sram.ld sram.o uart02.clang.thumb.norm.o
$(ARMGNU)-objdump -D uart02.clang.thumb.norm.sram.elf > uart02.clang.thumb.norm.sram.list
$(ARMGNU)-objcopy uart02.clang.thumb.norm.sram.elf uart02.clang.thumb.norm.sram.hex -O ihex
$(ARMGNU)-objcopy uart02.clang.thumb.norm.sram.elf uart02.clang.thumb.norm.sram.bin -O binary

uart02.clang.thumb.opt.sram.bin : sram.ld sram.o uart02.clang.bc
opt $(OOPS) uart02.clang.bc -o uart02.clang.thumb.opt.bc
#llc $(LLCOPS) uart02.clang.thumb.opt.bc -o uart02.clang.thumb.opt.s
#$(ARMGNU)-as $(AOPS) uart02.clang.thumb.opt.s -o uart02.clang.thumb.opt.o
llc $(LLCOPS) uart02.clang.thumb.opt.bc -filetype=obj -o uart02.clang.thumb.opt.o
$(ARMGNU)-ld -o uart02.clang.thumb.opt.sram.elf -T sram.ld sram.o uart02.clang.thumb.opt.o
$(ARMGNU)-objdump -D uart02.clang.thumb.opt.sram.elf > uart02.clang.thumb.opt.sram.list
$(ARMGNU)-objcopy uart02.clang.thumb.opt.sram.elf uart02.clang.thumb.opt.sram.hex -O ihex
$(ARMGNU)-objcopy uart02.clang.thumb.opt.sram.elf uart02.clang.thumb.opt.sram.bin -O binary




30 changes: 30 additions & 0 deletions ATSAMD21/uart02/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

See the previous level README for schematic and programmers reference
information and how to run these programs.

This program assumes the chip is in a just out of reset state, that no
other software has configured the peripherals or adjusted clocks, etc.

derived from uart01. This is a baseline to use for other examples.

This sparkfun board has a couple of TX/RX pins called out

The ones next to the SWCLK/SWDIO

TX PB22 SERCOM5 PAD[2] PORT FUNCTION D
RX PB23 SERCOM5 PAD[3] PORT FUNCTION D

The arduino ones in the corner

TX PA10 SERCOM0 PAD[2] FUNCTION C SERCOM2 PAD[2] FUNCTION D
RX PA11 SERCOM0 PAD[3] FUNCTION C SERCOM2 PAD[3] FUNCTION D

This example defaults to SERCOM5 the PB22/PB23 pins. Set a define
in the code to swich to SERCOM0.

It starts by using the status bits to blast characters out, then
prints a few interesting things, and goes into a loop that echos
out what it receives.

Currently the CPUID shows 410CC601 for my part so this is an r0p1
version of the Cortex-M0+, so that version of the TRM should be used.
13 changes: 13 additions & 0 deletions ATSAMD21/uart02/flash.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

MEMORY
{
ram : ORIGIN = 0x00000000, LENGTH = 0x1000
}

SECTIONS
{
.text : { *(.text*) } > ram
.rodata : { *(.rodata*) } > ram
.bss : { *(.bss*) } > ram
}

75 changes: 75 additions & 0 deletions ATSAMD21/uart02/flash.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

.cpu cortex-m0
.thumb

.thumb_func
.global _start
_start:
stacktop: .word 0x20001000
.word reset
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang

.thumb_func
reset:
bl notmain
b hang
.thumb_func
hang: b .

.align

.thumb_func
.globl PUT8
PUT8:
strb r1,[r0]
bx lr

.thumb_func
.globl PUT16
PUT16:
strh r1,[r0]
bx lr

.thumb_func
.globl PUT32
PUT32:
str r1,[r0]
bx lr

.thumb_func
.globl GET8
GET8:
ldrb r0,[r0]
bx lr

.thumb_func
.globl GET16
GET16:
ldrh r0,[r0]
bx lr

.thumb_func
.globl GET32
GET32:
ldr r0,[r0]
bx lr

.thumb_func
.globl dummy
dummy:
bx lr

.end
13 changes: 13 additions & 0 deletions ATSAMD21/uart02/sram.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

MEMORY
{
ram : ORIGIN = 0x20000000, LENGTH = 0x1000
}

SECTIONS
{
.text : { *(.text*) } > ram
.rodata : { *(.rodata*) } > ram
.bss : { *(.bss*) } > ram
}

59 changes: 59 additions & 0 deletions ATSAMD21/uart02/sram.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

.cpu cortex-m0
.thumb

.thumb_func
.global _start
_start:
ldr r0,stacktop
mov sp,r0
bl notmain
b hang
.thumb_func
hang: b .

.align
stacktop: .word 0x20002000

.thumb_func
.globl PUT8
PUT8:
strb r1,[r0]
bx lr

.thumb_func
.globl PUT16
PUT16:
strh r1,[r0]
bx lr

.thumb_func
.globl PUT32
PUT32:
str r1,[r0]
bx lr

.thumb_func
.globl GET8
GET8:
ldrb r0,[r0]
bx lr

.thumb_func
.globl GET16
GET16:
ldrh r0,[r0]
bx lr

.thumb_func
.globl GET32
GET32:
ldr r0,[r0]
bx lr

.thumb_func
.globl dummy
dummy:
bx lr

.end
Loading

0 comments on commit d6ae04c

Please sign in to comment.