söndag 26 december 2010

Open source LPC17xx development

This summer I wanted to try something new in the microcontroller area and decided to advance from 8-bit AVR and PIC to 32-bit ARM. There is a jungle of ARM-based microcontrollers out there and deciding on which one is "the best" isn't very easy. I ended up choosing an NXP LPC17xx Cortex-M3 based micro controller since the price was fairly good and I found MicropendousX, an open hardware dev-board project with free open source schematics and pcb-layout in KiCad (free open source EDA-tool) format.
I used the 1758 version (Seems abandoned in favour for the 1768) but removed ethernet and redrew the layout using more hole-mounted components to make it easier to mount, probe and re-wire.

I will add the schematic and board files someday, hopefully soon...

The result:
Features:
A simple "Wiggler" parallel port programmer and OpenOCD works fine to program and debug the micro controller. I think I used the programmer described here but with a connector that fits my board.

The GNU toolchain I use is the arm-none-eabi lite edition of G++ from Codesourcery.

As an IDE I use Eclipse. Stepping through C and assembler code works like a charm. I think I used these instructions to get it working.

lördag 25 december 2010

Calling Cortex-M3 assembler function in RAM from gcc C

I needed a fast  function written in assembler and run from RAM. I thought the most simple way to do this without adding stuff to the linker script was to change the .text directive to .data (same as initialised variables). But the result of the change was a hard fault when the function got called.
The solution was to tell gcc it is a function with .type logic_sample_fast, %function
So the whole function looks like this:
.syntax unified
.cpu cortex-m3
.thumb
.data
.align 4

#define FIO0PIN                    (0x2009c014)
#define FIO1PIN                    (0x2009c034)
#define LOGIC_IN_FIOPIN_REG        FIO1PIN

.global logic_sample_fast
.type logic_sample_fast, %function
.thumb_func
logic_sample_fast:
    movw r1, :lower16:LOGIC_IN_FIOPIN_REG
    movt r1, :upper16:LOGIC_IN_FIOPIN_REG
    cpsid i
trig0:
    ldrb r2, [r1]
    ands r3, r2, #1
    bne trig0
trig1:
    ldrb r2, [r1]
    ands r3, r2, #1
    beq trig1
    .rept (40*8)
    ldrb r2, [r1]
    strb r2, [r0], #1
    .endr
    cpsie i
    bx lr
And the definition in C like this:
void logic_sample_fast(uint8_t *buffer);