blue-pill: fix bootloader.
This commit is contained in:
parent
524f860331
commit
5734a63997
|
@ -14,10 +14,11 @@ LD := $(ARMTC)-gcc
|
||||||
AS := $(ARMTC)-as
|
AS := $(ARMTC)-as
|
||||||
ARMSIZE := $(ARMTC)-size
|
ARMSIZE := $(ARMTC)-size
|
||||||
OBJCOPY := $(ARMTC)-objcopy
|
OBJCOPY := $(ARMTC)-objcopy
|
||||||
|
PAGER ?= less
|
||||||
|
|
||||||
# compiler options
|
# compiler options
|
||||||
CPUFLAGS := -mcpu=cortex-m3 -mthumb -std=c99
|
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
|
LDFLAGS := $(CPUFLAGS) -nostartfiles -Wl,-T,bluepill.ld
|
||||||
LDLIBS := -lc -lnosys
|
LDLIBS := -lc -lnosys
|
||||||
|
|
||||||
|
@ -49,10 +50,21 @@ flash: $(BIN)
|
||||||
erase:
|
erase:
|
||||||
st-flash erase
|
st-flash erase
|
||||||
|
|
||||||
|
.PHONY: reset
|
||||||
|
reset:
|
||||||
|
st-flash reset
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: erase flash
|
install: erase flash reset
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.bin *.elf *.d *.map
|
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
|
||||||
|
|
|
@ -19,11 +19,12 @@ led_on() {
|
||||||
set_pin(GPIO_C, LED_PIN);
|
set_pin(GPIO_C, LED_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
*RCC |= (1 << 4); /* enable port C clock */
|
*RCC |= (1 << 4); /* enable port C clock */
|
||||||
output_mode(GPIO_C, LED_PIN, OUTPUT_GPP, OUTPUT_MAX_2MHZ);
|
output_mode(GPIO_C, LED_PIN, OUTPUT_GPP, OUTPUT_MAX_2MHZ);
|
||||||
|
led_on();
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
led_off();
|
led_off();
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
/* from https://github.com/satoshinm/pill_blink/ */
|
|
||||||
|
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
flash (rx) : ORIGIN = 0x00000000, LENGTH = 128K
|
||||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN(vector_table);
|
|
||||||
ENTRY(reset_handler);
|
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
.text : {
|
.text : { *(.text*) } > flash
|
||||||
*(.vectors)
|
.bss : { *(.bss*) } > sram
|
||||||
*(.text*)
|
|
||||||
. = ALIGN(4);
|
|
||||||
} >rom
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,24 +5,32 @@
|
||||||
* TODO: is the IRQv buffer actually needed right now?
|
* TODO: is the IRQv buffer actually needed right now?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
.cpu cortex-m3
|
||||||
|
.thumb
|
||||||
|
|
||||||
.globl vectors
|
.globl vectors
|
||||||
vectors:
|
vectors:
|
||||||
.align 2
|
.align 2
|
||||||
.long 0x100 /* best guess at stack pointer */
|
.long 0x20002000 /* best guess at stack pointer */
|
||||||
.long reset_handler /* reset handler */
|
.long reset_handler /* reset handler */
|
||||||
.long 0 /* NMI handler */
|
.long hang /* NMI handler */
|
||||||
.long 0 /* hard_fault_handler */
|
.long hang /* hard_fault_handler */
|
||||||
.long 0 /* memory management handler */
|
.long hang /* memory management handler */
|
||||||
.long 0 /* bus fault handler */
|
.long hang /* bus fault handler */
|
||||||
.long 0 /* usage fault handler */
|
.long hang /* usage fault handler */
|
||||||
.skip 0x20 /* reserved */
|
.skip 0x20 /* reserved */
|
||||||
.long 0 /* svcall handler */
|
.long hang /* svcall handler */
|
||||||
.long 0 /* debug handler */
|
.long hang /* debug handler */
|
||||||
.skip 4 /* reserved */
|
.skip 4 /* reserved */
|
||||||
.long 0 /* pendsv handler */
|
.long hang /* pendsv handler */
|
||||||
.long 0 /* systick handler */
|
.long hang /* systick handler */
|
||||||
.skip 0xf4 /* remaining / IRQ vectors */
|
.skip 0x100 /* remaining / IRQ vectors */
|
||||||
|
|
||||||
.globl reset_handler
|
|
||||||
|
.thumb_func
|
||||||
|
hang: b .
|
||||||
|
|
||||||
|
|
||||||
|
.thumb_func
|
||||||
reset_handler:
|
reset_handler:
|
||||||
bl main
|
bl main
|
||||||
|
|
|
@ -5,24 +5,32 @@
|
||||||
* TODO: is the IRQv buffer actually needed right now?
|
* TODO: is the IRQv buffer actually needed right now?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
.cpu cortex-m3
|
||||||
|
.thumb
|
||||||
|
|
||||||
.globl vectors
|
.globl vectors
|
||||||
vectors:
|
vectors:
|
||||||
.align 2
|
.align 2
|
||||||
.long 0x100 /* best guess at stack pointer */
|
.long 0x20002000 /* best guess at stack pointer */
|
||||||
.long reset_handler /* reset handler */
|
.long reset_handler /* reset handler */
|
||||||
.long 0 /* NMI handler */
|
.long hang /* NMI handler */
|
||||||
.long 0 /* hard_fault_handler */
|
.long hang /* hard_fault_handler */
|
||||||
.long 0 /* memory management handler */
|
.long hang /* memory management handler */
|
||||||
.long 0 /* bus fault handler */
|
.long hang /* bus fault handler */
|
||||||
.long 0 /* usage fault handler */
|
.long hang /* usage fault handler */
|
||||||
.skip 0x20 /* reserved */
|
.skip 0x20 /* reserved */
|
||||||
.long 0 /* svcall handler */
|
.long hang /* svcall handler */
|
||||||
.long 0 /* debug handler */
|
.long hang /* debug handler */
|
||||||
.skip 4 /* reserved */
|
.skip 4 /* reserved */
|
||||||
.long 0 /* pendsv handler */
|
.long hang /* pendsv handler */
|
||||||
.long 0 /* systick handler */
|
.long hang /* systick handler */
|
||||||
.skip 0xf4 /* remaining / IRQ vectors */
|
.skip 0x100 /* remaining / IRQ vectors */
|
||||||
|
|
||||||
.globl reset_handler
|
|
||||||
|
.thumb_func
|
||||||
|
hang: b .
|
||||||
|
|
||||||
|
|
||||||
|
.thumb_func
|
||||||
reset_handler:
|
reset_handler:
|
||||||
bl main
|
bl main
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
/* from https://github.com/satoshinm/pill_blink/ */
|
|
||||||
|
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
flash (rx) : ORIGIN = 0x00000000, LENGTH = 128K
|
||||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN(vector_table);
|
|
||||||
ENTRY(reset_handler);
|
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
.text : {
|
.text : { *(.text*) } > flash
|
||||||
*(.vectors)
|
.bss : { *(.bss*) } > sram
|
||||||
*(.text*)
|
|
||||||
. = ALIGN(4);
|
|
||||||
} >rom
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# configurables
|
# configurables
|
||||||
OBJS :=
|
OBJS := startup.o
|
||||||
TARGET :=
|
TARGET :=
|
||||||
OBJS += $(TARGET).o
|
OBJS += $(TARGET).o
|
||||||
|
|
||||||
# targets
|
# targets
|
||||||
ELF := $(TARGET).elf
|
ELF := $(TARGET).elf
|
||||||
|
@ -9,15 +9,16 @@ BIN := $(TARGET).bin
|
||||||
|
|
||||||
# toolchain setup
|
# toolchain setup
|
||||||
ARMTC := arm-none-eabi
|
ARMTC := arm-none-eabi
|
||||||
ARMCC := $(ARMTC)-gcc
|
CC := $(ARMTC)-gcc
|
||||||
CC := $(ARMCC)
|
LD := $(ARMTC)-gcc
|
||||||
LD := $(ARMCC)
|
AS := $(ARMTC)-as
|
||||||
ARMSIZE := $(ARMTC)-size
|
ARMSIZE := $(ARMTC)-size
|
||||||
OBJCOPY := $(ARMTC)-objcopy
|
OBJCOPY := $(ARMTC)-objcopy
|
||||||
|
PAGER ?= less
|
||||||
|
|
||||||
# compiler options
|
# compiler options
|
||||||
CPUFLAGS := -mcpu=cortex-m3 -mthumb
|
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
|
LDFLAGS := $(CPUFLAGS) -nostartfiles -Wl,-T,bluepill.ld
|
||||||
LDLIBS := -lc -lnosys
|
LDLIBS := -lc -lnosys
|
||||||
|
|
||||||
|
@ -30,8 +31,13 @@ STARTMEM := 0x8000000
|
||||||
all: $(BIN)
|
all: $(BIN)
|
||||||
|
|
||||||
$(ELF): $(OBJS)
|
$(ELF): $(OBJS)
|
||||||
$(ARMCC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
|
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
|
||||||
$(ARMSIZE) -A $@
|
$(ARMSIZE) $@
|
||||||
|
|
||||||
|
.PHONY: strip
|
||||||
|
strip: $(ELF)
|
||||||
|
$(ARMTC)-strip $(ELF)
|
||||||
|
$(ARMSIZE) $(ELF)
|
||||||
|
|
||||||
$(BIN): $(ELF)
|
$(BIN): $(ELF)
|
||||||
$(OBJCOPY) -O binary $< $@
|
$(OBJCOPY) -O binary $< $@
|
||||||
|
@ -44,10 +50,21 @@ flash: $(BIN)
|
||||||
erase:
|
erase:
|
||||||
st-flash erase
|
st-flash erase
|
||||||
|
|
||||||
|
.PHONY: reset
|
||||||
|
reset:
|
||||||
|
st-flash reset
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: erase flash
|
install: erase flash reset
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.bin *.elf *.d *.map
|
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,65 @@
|
||||||
|
#ifndef __BLUEPILL_H__
|
||||||
|
#define __BLUEPILL_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define PORTA (volatile unsigned int *)0x40010800
|
||||||
|
#define PORTB (volatile unsigned int *)0x40010c00
|
||||||
|
#define PORTC (volatile unsigned int *)0x40011000
|
||||||
|
#define PORTD (volatile unsigned int *)0x40011400
|
||||||
|
#define PORTE (volatile unsigned int *)0x40011800
|
||||||
|
|
||||||
|
#define RCC (volatile unsigned int *)0x40021000
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
40011000 CRL
|
||||||
|
40011004 CRH
|
||||||
|
40011008 IDR
|
||||||
|
4001100c ODR
|
||||||
|
40011010 BRR
|
||||||
|
40011012 LCKR
|
||||||
|
|
||||||
|
*/
|
||||||
|
typedef struct _GPIO {
|
||||||
|
uint32_t CRL; /* configuration register low */
|
||||||
|
uint32_t CRH; /* configuration register high */
|
||||||
|
uint32_t IDR; /* input data register */
|
||||||
|
uint32_t ODR; /* output data register */
|
||||||
|
uint32_t BSRR; /* bit set / reset register */
|
||||||
|
uint16_t BRR; /* reset register */
|
||||||
|
uint32_t LCKR; /* locking register */
|
||||||
|
} GPIO;
|
||||||
|
|
||||||
|
GPIO *GPIO_A = (GPIO *)PORTA;
|
||||||
|
GPIO *GPIO_B = (GPIO *)PORTB;
|
||||||
|
GPIO *GPIO_C = (GPIO *)PORTC;
|
||||||
|
GPIO *GPIO_D = (GPIO *)PORTD;
|
||||||
|
GPIO *GPIO_E = (GPIO *)PORTE;
|
||||||
|
|
||||||
|
const uint32_t OUTPUT_MAX_2MHZ = 2;
|
||||||
|
const uint32_t OUTPUT_MAX_10MHZ = 1;
|
||||||
|
const uint32_t OUTPUT_MAX_50MHZ = 3;
|
||||||
|
const uint32_t OUTPUT_GPP = 0;
|
||||||
|
const uint32_t OUTPUT_GOD = 1;
|
||||||
|
const uint32_t OUTPUT_APP = 2;
|
||||||
|
const uint32_t OUTPUT_AOD = 3;
|
||||||
|
|
||||||
|
void set_pin(GPIO *gpio, uint32_t pin) { gpio->BSRR |= ((1 << pin) << 16); }
|
||||||
|
void clear_pin(GPIO *gpio, uint32_t pin) { gpio->BSRR |= (1 << pin); }
|
||||||
|
void output_mode(GPIO *gpio, uint32_t pin, uint32_t mode, uint32_t max) {
|
||||||
|
if (pin > 7) {
|
||||||
|
pin = ((pin - 8) * 4);
|
||||||
|
gpio->CRH |= (max << pin);
|
||||||
|
gpio->CRH |= (mode << (pin + 2));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pin *= 4;
|
||||||
|
gpio->CRL |= (max << pin);
|
||||||
|
gpio->CRL |= (mode << (pin + 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __BLUEPILL_H__ */
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
# from https://github.com/satoshinm/pill_blink/
|
|
||||||
|
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
flash (rx) : ORIGIN = 0x00000000, LENGTH = 128K
|
||||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||||
}
|
}
|
||||||
|
|
||||||
EXTERN(vector_table);
|
|
||||||
ENTRY(reset_handler);
|
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
.text : {
|
.text : { *(.text*) } > flash
|
||||||
*(.vectors)
|
.bss : { *(.bss*) } > sram
|
||||||
*(.text*)
|
|
||||||
. = ALIGN(4);
|
|
||||||
} >rom
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Startup code for the STM32F103-based blue pill board.
|
||||||
|
*
|
||||||
|
* TODO: revisit stack pointer
|
||||||
|
* TODO: is the IRQv buffer actually needed right now?
|
||||||
|
*/
|
||||||
|
|
||||||
|
.globl vectors
|
||||||
|
vectors:
|
||||||
|
.align 2
|
||||||
|
.long 0x100 /* 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 */
|
||||||
|
.skip 0x20 /* reserved */
|
||||||
|
.long 0 /* svcall handler */
|
||||||
|
.long 0 /* debug handler */
|
||||||
|
.skip 4 /* reserved */
|
||||||
|
.long 0 /* pendsv handler */
|
||||||
|
.long 0 /* systick handler */
|
||||||
|
.skip 0xf4 /* remaining / IRQ vectors */
|
||||||
|
|
||||||
|
.globl reset_handler
|
||||||
|
reset_handler:
|
||||||
|
bl main
|
Loading…
Reference in New Issue