diff --git a/blue-pill/blinky/Makefile b/blue-pill/blinky/Makefile new file mode 100644 index 0000000..ce23de3 --- /dev/null +++ b/blue-pill/blinky/Makefile @@ -0,0 +1,52 @@ +# configurables +OBJS := blinky.o +TARGET := blinky + +# targets +ELF := $(TARGET).elf +BIN := $(TARGET).bin + +# toolchain setup +ARMTC := arm-none-eabi +ARMCC := $(ARMTC)-gcc +CC := $(ARMCC) +LD := $(ARMCC) +ARMSIZE := $(ARMTC)-size +OBJCOPY := $(ARMTC)-objcopy + +# compiler options +CPUFLAGS := -mcpu=cortex-m3 -mthumb +CFLAGS := -Wall -Wextra -Os -MD $(CPUFLAGS) +LDFLAGS := $(CPUFLAGS) -nostartfiles -Wl,-T,bluepill.ld +LDLIBS := -lc -lnosys + +# programmer options +STARTMEM := 0x8000000 + +# targets + +.PHONY: all +all: $(BIN) + +$(ELF): $(OBJS) + $(ARMCC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) + $(ARMSIZE) -A $@ + +$(BIN): $(ELF) + $(OBJCOPY) -O binary $< $@ + +.PHONY: flash +flash: $(BIN) + st-flash write $(BIN) $(STARTMEM) + +.PHONY: erase +erase: + st-flash erase + +.PHONY: install +install: erase flash + +.PHONY: clean +clean: + rm -f *.o *.bin *.elf *.d *.map + diff --git a/blue-pill/blinky/blinky.c b/blue-pill/blinky/blinky.c new file mode 100644 index 0000000..9f6dbc2 --- /dev/null +++ b/blue-pill/blinky/blinky.c @@ -0,0 +1,55 @@ +/* based on example from https://github.com/satoshinm/pill_blink */ + +static inline void +delay(unsigned long ms) +{ + for (unsigned long i = 0; i < ms; ++i) __asm__("nop"); +} + +static inline void +led_off() { + (*(volatile unsigned int *)(0x40011010)) = (1 << 13); +} + +static inline void +led_on() { + (*(volatile unsigned int *)(0x40011014)) = (1 << 13); +} + +void __attribute__ ((weak, naked)) reset_handler(void) { + (*(volatile unsigned int *)(0x40021018)) |= (1 << 4); + + (*(volatile unsigned int *)(0x40011004)) |= (0x00 << (((13 - 8) * 4) + 2)); + (*(volatile unsigned int *)(0x40011004)) |= (0x02 << ((13 - 8) * 4)); + + while(1) { + led_off(); + delay(1000000); + led_on(); + delay(100000); + led_off(); + delay(100000); + led_on(); + delay(100000); + } +} + +__attribute__ ((section(".vectors"))) +struct { + unsigned int *initial_sp_value; + void (*reset)(void); + void (*nmi)(void); + void (*hard_fault)(void); + void (*memory_manage_fault)(void); + void (*bus_fault)(void); + void (*usage_fault)(void); + void (*reserved_x001c[4])(void); + void (*sv_call)(void); + void (*debug_monitor)(void); + void (*reserved_x0034)(void); + void (*pend_sv)(void); + void (*systick)(void); + void (*irq[68])(void); +} vector_table = { + .reset = reset_handler, +}; diff --git a/blue-pill/blinky/bluepill.ld b/blue-pill/blinky/bluepill.ld new file mode 100644 index 0000000..bdbdac1 --- /dev/null +++ b/blue-pill/blinky/bluepill.ld @@ -0,0 +1,19 @@ +/* from https://github.com/satoshinm/pill_blink/ */ + +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K +} + +EXTERN(vector_table); +ENTRY(reset_handler); + +SECTIONS +{ + .text : { + *(.vectors) + *(.text*) + . = ALIGN(4); + } >rom +} diff --git a/blue-pill/pins.txt b/blue-pill/pins.txt new file mode 100644 index 0000000..eff2b84 --- /dev/null +++ b/blue-pill/pins.txt @@ -0,0 +1,12 @@ +BOARD: + + | | + +-+-+-+-+-+ + | | | | + 4 3 2 1 + +1: ground (black) +2: SWCLK (white) +3: SWDIO (grey) +4: 3V3 (purple) + diff --git a/blue-pill/skeleton/Makefile b/blue-pill/skeleton/Makefile new file mode 100644 index 0000000..7c868d0 --- /dev/null +++ b/blue-pill/skeleton/Makefile @@ -0,0 +1,52 @@ +# configurables +OBJS := +TARGET := + +# targets +ELF := $(TARGET).elf +BIN := $(TARGET).bin + +# toolchain setup +ARMTC := arm-none-eabi +ARMCC := $(ARMTC)-gcc +CC := $(ARMCC) +LD := $(ARMCC) +ARMSIZE := $(ARMTC)-size +OBJCOPY := $(ARMTC)-objcopy + +# compiler options +CPUFLAGS := -mcpu=cortex-m3 -mthumb +CFLAGS := -Wall -Wextra -Os -MD $(CPUFLAGS) +LDFLAGS := $(CPUFLAGS) -nostartfiles -Wl,-T,bluepill.ld +LDLIBS := -lc -lnosys + +# programmer options +STARTMEM := 0x8000000 + +# targets + +.PHONY: all +all: $(BIN) + +$(ELF): $(OBJS) + $(ARMCC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) + $(ARMSIZE) -A $@ + +$(BIN): $(ELF) + $(OBJCOPY) -O binary $< $@ + +.PHONY: flash +flash: $(BIN) + st-flash write $(BIN) $(STARTMEM) + +.PHONY: erase +erase: + st-flash erase + +.PHONY: install +install: erase flash + +.PHONY: clean +clean: + rm -f *.o *.bin *.elf *.d *.map + diff --git a/blue-pill/skeleton/bluepill.ld b/blue-pill/skeleton/bluepill.ld new file mode 100644 index 0000000..57b696a --- /dev/null +++ b/blue-pill/skeleton/bluepill.ld @@ -0,0 +1,19 @@ +# from https://github.com/satoshinm/pill_blink/ + +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K +} + +EXTERN(vector_table); +ENTRY(reset_handler); + +SECTIONS +{ + .text : { + *(.vectors) + *(.text*) + . = ALIGN(4); + } >rom +}