Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smile demo #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions smile/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

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

all : notmain.bin

clean:
rm -f *.bin
rm -f *.o
rm -f *.elf
rm -f *.list

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

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

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

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


2 changes: 2 additions & 0 deletions smile/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a simple demo that will create an image on the MicroBit
LED matrix.
50 changes: 50 additions & 0 deletions smile/flash.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.cpu cortex-m0
.thumb


.thumb_func
.global _start
_start:
stacktop: .word 0x20004000
.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 .

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

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

.thumb_func
.globl dummy
dummy:
bx lr

.end
12 changes: 12 additions & 0 deletions smile/flash.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MEMORY
{
rom : ORIGIN = 0x00000000, LENGTH = 0x40000
ram : ORIGIN = 0x20000000, LENGTH = 0x4000
}

SECTIONS
{
.text : { *(.text*) } > rom
.rodata : { *(.rodata*) } > rom
.bss : { *(.bss*) } > ram
}
61 changes: 61 additions & 0 deletions smile/notmain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Formatted to allman style
void PUT32(unsigned int, unsigned int);
void dummy(unsigned int);

#define GPIOBASE 0x50000000
#define GPIO_OUTSET (GPIOBASE + 0x508)
#define GPIO_OUTCLR (GPIOBASE + 0x50C)
#define GPIO_DIRSET (GPIOBASE + 0x518)

unsigned char grid[5][5][2] =
{
{{13, 4},{14, 7},{13, 5},{14, 8},{13, 6}},
{{15, 7},{15, 8},{15, 9},{15,10},{15,11}},
{{14, 5},{13,12},{14, 6},{15,12},{14, 4}},
{{13,11},{13,10},{13, 9},{13, 8},{13, 7}},
{{15, 6},{14,10},{15, 4},{14, 9},{15, 5}}
};

unsigned char image[5][5] =
{
{0, 1, 0, 1, 0},
{0, 1, 0, 1, 0},
{0, 0, 0, 0, 0},
{1, 0, 0, 0, 1},
{0, 1, 1, 1, 0}
};

void delay()
{
for (unsigned int ra = 0; ra < 20; ra++);
}

void pixel(unsigned int x, unsigned int y)
{
PUT32(GPIO_OUTSET, 1 << grid[x][y][0]);
PUT32(GPIO_OUTCLR, 1 << grid[x][y][1]);
delay();
PUT32(GPIO_OUTCLR, 1 << grid[x][y][0]);
PUT32(GPIO_OUTSET, 1 << grid[x][y][1]);
}

void notmain()
{
PUT32(GPIO_DIRSET, 0xFFF0);
PUT32(GPIO_OUTCLR, 0xE000);
PUT32(GPIO_OUTSET, 0x1FF0);

while (1)
{
for (unsigned int x = 0; x < 5; x++)
{
for (unsigned int y = 0; y < 5; y++)
{
if (image[x][y])
{
pixel(x, y);
}
}
}
}
}