blue-pill: fix bootloader.

This commit is contained in:
2018-03-07 19:50:01 -08:00
parent 524f860331
commit 5734a63997
10 changed files with 188 additions and 73 deletions

View File

@@ -14,10 +14,11 @@ LD := $(ARMTC)-gcc
AS := $(ARMTC)-as
ARMSIZE := $(ARMTC)-size
OBJCOPY := $(ARMTC)-objcopy
PAGER ?= less
# compiler options
CPUFLAGS := -mcpu=cortex-m3 -mthumb -std=c99
CFLAGS := -Wall -Wextra -Os -MD $(CPUFLAGS)
CFLAGS := -Wall -Wextra -Os -MD $(CPUFLAGS) -g
LDFLAGS := $(CPUFLAGS) -nostartfiles -Wl,-T,bluepill.ld
LDLIBS := -lc -lnosys
@@ -49,10 +50,21 @@ flash: $(BIN)
erase:
st-flash erase
.PHONY: reset
reset:
st-flash reset
.PHONY: install
install: erase flash
install: erase flash reset
.PHONY: clean
clean:
rm -f *.o *.bin *.elf *.d *.map
.PHONY: disass
disass: $(ELF)
$(ARMTC)-objdump -D $(ELF) | $(PAGER)
.PHONY: dump
dump: $(ELF)
$(ARMTC)-objcopy -D $(ELF) > $(TARGET).dump

View File

@@ -19,11 +19,12 @@ led_on() {
set_pin(GPIO_C, LED_PIN);
}
int
void
main(void)
{
*RCC |= (1 << 4); /* enable port C clock */
output_mode(GPIO_C, LED_PIN, OUTPUT_GPP, OUTPUT_MAX_2MHZ);
led_on();
while(1) {
led_off();

View File

@@ -1,19 +1,11 @@
/* from https://github.com/satoshinm/pill_blink/ */
MEMORY
{
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
flash (rx) : ORIGIN = 0x00000000, LENGTH = 128K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
}
EXTERN(vector_table);
ENTRY(reset_handler);
SECTIONS
{
.text : {
*(.vectors)
*(.text*)
. = ALIGN(4);
} >rom
.text : { *(.text*) } > flash
.bss : { *(.bss*) } > sram
}

View File

@@ -5,24 +5,32 @@
* TODO: is the IRQv buffer actually needed right now?
*/
.cpu cortex-m3
.thumb
.globl vectors
vectors:
.align 2
.long 0x100 /* best guess at stack pointer */
.long 0x20002000 /* best guess at stack pointer */
.long reset_handler /* reset handler */
.long 0 /* NMI handler */
.long 0 /* hard_fault_handler */
.long 0 /* memory management handler */
.long 0 /* bus fault handler */
.long 0 /* usage fault handler */
.long hang /* NMI handler */
.long hang /* hard_fault_handler */
.long hang /* memory management handler */
.long hang /* bus fault handler */
.long hang /* usage fault handler */
.skip 0x20 /* reserved */
.long 0 /* svcall handler */
.long 0 /* debug handler */
.long hang /* svcall handler */
.long hang /* debug handler */
.skip 4 /* reserved */
.long 0 /* pendsv handler */
.long 0 /* systick handler */
.skip 0xf4 /* remaining / IRQ vectors */
.long hang /* pendsv handler */
.long hang /* systick handler */
.skip 0x100 /* remaining / IRQ vectors */
.globl reset_handler
.thumb_func
hang: b .
.thumb_func
reset_handler:
bl main