Sunday, February 6, 2011

leaflabs maple

Recently received a leaflabs maple r5. Contains an STM32F103RB.

I am using the dfu-util from the openmoko folks.


svn co https://svn.openmoko.org/trunk/src/host/dfu-util/
cd dfu-util
./autogen.sh
./configure
make
make install


When you have a program to load, both after plugging in to the usb connector and after pressing the reset button there is some activity on the blue led (hate blue leds, going to replace it) you run this command when that is going on (otherwise, the usb can disconnect, unless you have code on there keeping it alive).

dfu-util -a1 -d 1EAF:0003 -D filename.bin -R

Simple count based loop blink the led example program:

startup.s:



.word 0x20005000
.word notmain
.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
.word hang

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_fun
dummy_fun:
bx lr

notmain.c



void PUT32 ( unsigned int, unsigned int);
unsigned int GET32 ( unsigned int );

void notmain ( void )
{
unsigned int ra;
unsigned int rb;

ra=GET32(0x40021018);
ra&=(~4);
PUT32(0x40021018,ra);

ra=GET32(0x4002100C);
ra&=~4;
rb=ra|4;
PUT32(0x4002100C,rb);
PUT32(0x4002100C,ra);

ra=GET32(0x40021018);
ra|=4;
PUT32(0x40021018,ra);

ra=GET32(0x40010800);
ra&=(~0x00F00000);
ra|= 0x00100000;
PUT32(0x40010800,ra);

while(1)
{
for(ra=0;ra<1000000;ra++) dummy_fun(ra);
PUT32(0x40010810,0x00000020);
for(ra=0;ra<10000;ra++) dummy_fun(ra);
PUT32(0x40010810,0x00200000);
}
}


Makefile:


# dfu-util -a1 -d 1EAF:0003 -D filename.bin -R

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

COPSjustthumb = -O2 -mthumb -nostdlib -nostartfiles -ffreestanding
COPS = -O2 -march=armv7-m -mcpu=cortex-m3 -mtune=cortex-m3 -mthumb -nostdlib -nostartfiles -ffreestanding

maple.bin : maple.elf
$(ARMGNU)-objcopy -O binary maple.elf maple.bin

maple.elf: startup.s memmap notmain.c
$(ARMGNU)-gcc -O2 -march=armv7-m -mcpu=cortex-m3 -mtune=cortex-m3 -mthumb -nostdlib -nostartfiles -ffreestanding startup.s notmain.c -T memmap -o maple.elf
$(ARMGNU)-objdump -D maple.elf > maple.list

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


memmap (linker script):

MEMORY {
flash (rwx) : ORIGIN = 0x08005000, LENGTH = 256k
}

SECTIONS {
.text : { *(.text*) } > flash
}


The length is probably wrong on that linker script. Just a cut and paste. No libraries or includes are used so the code sourcery lite toolchains or a roll your own will work just fine.

The program enables clocks to the gpio, resets the gpio interface just for good measure, sets PA5 as a push-pull output. dummy_fun() is there simply to prevent the optimizer from trying to optimize out the delay count loop.