From: texane Date: Fri, 14 Jan 2011 15:54:01 +0000 (-0600) Subject: [add] dirty example X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=fe76cc4a6bcef49ffa893762ced5ea9d7d420b82;p=fw%2Fstlink [add] dirty example --- diff --git a/example/build.sh b/example/build.sh new file mode 100755 index 0000000..39e8fb4 --- /dev/null +++ b/example/build.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +CHAIN=$HOME/sat/bin/arm-none-eabi +PATH=$HOME/sat/arm-none-eabi/bin:$PATH + +$CHAIN-gcc \ + -O2 \ + -mlittle-endian \ + -mthumb \ + -mcpu=cortex-m3 \ + -ffreestanding \ + -nostdlib \ + -nostdinc \ + main.c + +$CHAIN-objcopy \ + -O binary \ + a.out \ + /tmp/foobar \ No newline at end of file diff --git a/example/main.c b/example/main.c new file mode 100644 index 0000000..7b96605 --- /dev/null +++ b/example/main.c @@ -0,0 +1,27 @@ +typedef unsigned int uint32_t; + +#define GPIOC 0x40011000 // port C +#define GPIOC_CRH (GPIOC + 0x04) // port configuration register high +#define GPIOC_ODR (GPIOC + 0x0c) // port output data register +#define LED_BLUE (1<<8) // pin 8 +#define LED_GREEN (1<<9) // pin 9 + +#define delay() \ +do { \ + register unsigned int i; \ + for (i = 0; i < 1000000; ++i) \ + __asm__ __volatile__ ("nop\n\t":::"memory"); \ +} while (0) + +static void __attribute__((naked)) __attribute__((used)) main(void) +{ + *(volatile uint32_t*)GPIOC_CRH = 0x44444411; + + while (1) + { + *(volatile uint32_t*)GPIOC_ODR = LED_BLUE | LED_GREEN; + delay(); + *(volatile uint32_t*)GPIOC_ODR = 0; + delay(); + } +} diff --git a/example/o.bin b/example/o.bin new file mode 100755 index 0000000..76324f7 Binary files /dev/null and b/example/o.bin differ