Start bluepill skeleton and blinky project.

This commit is contained in:
Kyle Isom 2018-03-05 23:07:29 -08:00
parent 260a37f13d
commit 71eb73967b
6 changed files with 209 additions and 0 deletions

52
blue-pill/blinky/Makefile Normal file
View File

@ -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

55
blue-pill/blinky/blinky.c Normal file
View File

@ -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,
};

View File

@ -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
}

12
blue-pill/pins.txt Normal file
View File

@ -0,0 +1,12 @@
BOARD:
| |
+-+-+-+-+-+
| | | |
4 3 2 1
1: ground (black)
2: SWCLK (white)
3: SWDIO (grey)
4: 3V3 (purple)

View File

@ -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

View File

@ -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
}