blue-pill: fix linker scripts and asm led turnon
This commit is contained in:
parent
ca7eaec903
commit
943e2bfa93
|
@ -0,0 +1,70 @@
|
|||
# configurables
|
||||
OBJS :=
|
||||
TARGET := blink
|
||||
OBJS += $(TARGET).o
|
||||
|
||||
# targets
|
||||
ELF := $(TARGET).elf
|
||||
BIN := $(TARGET).bin
|
||||
|
||||
# toolchain setup
|
||||
ARMTC := arm-none-eabi
|
||||
CC := $(ARMTC)-gcc
|
||||
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) -g
|
||||
LDFLAGS := $(CPUFLAGS) -nostartfiles -Wl,-T,bluepill.ld
|
||||
LDLIBS := -lc -lnosys
|
||||
|
||||
# programmer options
|
||||
STARTMEM := 0x8000000
|
||||
|
||||
# targets
|
||||
|
||||
.PHONY: all
|
||||
all: $(BIN)
|
||||
|
||||
$(ELF): $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
|
||||
$(ARMSIZE) $@
|
||||
|
||||
.PHONY: strip
|
||||
strip: $(ELF)
|
||||
$(ARMTC)-strip $(ELF)
|
||||
$(ARMSIZE) $(ELF)
|
||||
|
||||
$(BIN): $(ELF)
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
.PHONY: flash
|
||||
flash: $(BIN)
|
||||
st-flash write $(BIN) $(STARTMEM)
|
||||
|
||||
.PHONY: erase
|
||||
erase:
|
||||
st-flash erase
|
||||
|
||||
.PHONY: reset
|
||||
reset:
|
||||
st-flash reset
|
||||
|
||||
.PHONY: install
|
||||
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
|
|
@ -0,0 +1,43 @@
|
|||
.syntax unified
|
||||
.cpu cortex-m3
|
||||
.thumb
|
||||
|
||||
.section .text
|
||||
.global vectors
|
||||
vectors:
|
||||
.align 2
|
||||
.word 0
|
||||
.word _start
|
||||
|
||||
.thumb_func
|
||||
.global _start
|
||||
_start:
|
||||
/* enable port C clock */
|
||||
ldr r0, =0x40021000
|
||||
ldr r1, [r0, #0x18]
|
||||
mov r2, #5
|
||||
orr r1, r2
|
||||
str r1, [r0, #0x18]
|
||||
|
||||
/*
|
||||
* enable output mode at a max of 2 MHz.
|
||||
* note that the default is a general purpose output push-pull,
|
||||
* which is what it should be.
|
||||
*/
|
||||
ldr r0, =0x40011000
|
||||
ldr r1, [r0, #0x04]
|
||||
mov r2, #0x02
|
||||
lsl r2, #0x14
|
||||
orr r1, r2
|
||||
str r1, [r0, #0x04]
|
||||
|
||||
/* write LED pin (PC13) */
|
||||
ldr r0, =0x40011000
|
||||
ldr r1, [r0, #0x10]
|
||||
mov r2, #0x01
|
||||
lsl r2, #0x0d
|
||||
lsl r2, #0x10
|
||||
orr r1, r2
|
||||
str r1, [r0, #0x10]
|
||||
|
||||
hang: bl .
|
|
@ -0,0 +1,18 @@
|
|||
MEMORY
|
||||
{
|
||||
flash (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
EXTERN(vectors);
|
||||
ENTRY(_start);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : {
|
||||
*(.vectors*)
|
||||
*(.text*)
|
||||
. = ALIGN(4);
|
||||
} > flash
|
||||
.bss : { *(.bss*) } > sram
|
||||
}
|
|
@ -9,6 +9,8 @@
|
|||
.cpu cortex-m3
|
||||
.thumb
|
||||
|
||||
.section .text
|
||||
.global vectors
|
||||
vectors:
|
||||
.align 2
|
||||
.long 0x20005000 /* stack pointer points to top of SRAM */
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
MEMORY
|
||||
{
|
||||
flash (rx) : ORIGIN = 0x00000000, LENGTH = 128K
|
||||
flash (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
EXTERN(vectors);
|
||||
ENTRY(reset_handler);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : { *(.text*) } > flash
|
||||
.text : {
|
||||
*(.vectors*)
|
||||
*(.text*)
|
||||
. = ALIGN(4);
|
||||
} > flash
|
||||
.bss : { *(.bss*) } > sram
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue