Browse Source

simplified for only stm32f1/bluepill

master
Jan Koppe 2 years ago
parent
commit
b30bc37f30
Signed by: j GPG Key ID: BE935B0735A2129B
12 changed files with 15 additions and 363 deletions
  1. 9
      Makefile
  2. 28
      boards.efm32.mk
  3. 28
      boards.sam.mk
  4. 110
      boards.stm32.mk
  5. 37
      boards.ti.mk
  6. 16
      ld.efm32.basic
  7. 16
      ld.sam.basic
  8. 16
      ld.ti.basic
  9. 21
      template_efm32.c
  10. 30
      template_sam.c
  11. 31
      template_stm32.c
  12. 36
      template_ti.c

9
Makefile

@ -16,10 +16,7 @@ M3_FLAGS= $(SFLAGS) -mcpu=cortex-m3 -mthumb -msoft-float
M4FH_FLAGS= $(SFLAGS) -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
M7SP_FLAGS= $(SFLAGS) -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16
include boards.efm32.mk
include boards.sam.mk
include boards.stm32.mk
include boards.ti.mk
realall.really: outdir $(BOARDS_ELF) $(BOARDS_BIN) $(BOARDS_HEX)
@ -38,11 +35,11 @@ libopencm3/lib/libopencm3_%.a: libopencm3/Makefile
@#printf " OBJCOPY $(*).hex\n"
$(OBJCOPY) -Oihex $(*).elf $(*).hex
flash:
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "program bin/stm32/bluepill.elf verify reset exit"
outdir:
mkdir -p $(OD)/efm32
mkdir -p $(OD)/sam
mkdir -p $(OD)/stm32
mkdir -p $(OD)/ti
clean:
$(RM) $(BOARDS_ELF) $(BOARDS_BIN) $(BOARDS_HEX)

28
boards.efm32.mk

@ -1,28 +0,0 @@
# Instructions:
# 1) add a rule for your board to the bottom of this file
# 2) profit!
LFLAGS_EFM32=$(LFLAGS) template_efm32.c -T ld.efm32.basic
# EFM32HG starts up with HFRCO at 14Mhz
EFM32HG_CFLAGS=$(M0P_FLAGS) -DEFM32HG -DLITTLE_BIT=800000 $(LFLAGS_EFM32) -lopencm3_efm32hg
define RAWMakeBoard
$(CC) -DPORT_LED1=$(1) -DPIN_LED1=$(2) $(3) -o $(OD)/efm32/$(4)
endef
define MakeBoard
BOARDS_ELF+=$(OD)/efm32/$(1).elf
BOARDS_BIN+=$(OD)/efm32/$(1).bin
BOARDS_HEX+=$(OD)/efm32/$(1).hex
$(OD)/efm32/$(1).elf: template_efm32.c libopencm3/lib/libopencm3_$(5).a
@echo " $(5) -> Creating $(OD)/efm32/$(1).elf"
$(call RAWMakeBoard,$(2),$(3),$(4),$(1).elf)
endef
define efm32hgboard
$(call MakeBoard,$(1),$(2),$(3),$(EFM32HG_CFLAGS),efm32hg,$(4),$(5))
endef
# EFM32HG boards
$(eval $(call efm32hgboard,efm32hg-slstk3400a,GPIOF,GPIO4,GPIOF,GPIO5))

28
boards.sam.mk

@ -1,28 +0,0 @@
# Instructions:
# 1) add a rule for your board, following the style in place.
# This file should cover all the Atmel/Microchip Cortex-M parts
LFLAGS_SAM=$(LFLAGS) template_sam.c -T ld.sam.basic
# FIXME what are default clock speeds?
SAMD_CFLAGS=$(M0P_FLAGS) -DSAMD -DLITTLE_BIT=100000 $(LFLAGS_SAM) -lopencm3_samd
# FIXME - support led2
define RAWMakeBoard
$(CC) -DPORT_LED1=$(1) -DPIN_LED1=$(2) $(3) -o $(OD)/sam/$(4)
endef
define MakeBoard
BOARDS_ELF+=$(OD)/sam/$(1).elf
BOARDS_BIN+=$(OD)/sam/$(1).bin
BOARDS_HEX+=$(OD)/sam/$(1).hex
$(OD)/sam/$(1).elf: template_sam.c libopencm3/lib/libopencm3_$(5).a
@echo " $(5) -> Creating $(OD)/sam/$(1).elf"
$(call RAWMakeBoard,$(2),$(3),$(4),$(1).elf)
endef
define samdboard
$(call MakeBoard,$(1),$(2),$(3),$(SAMD_CFLAGS),samd)
endef
$(eval $(call samdboard,samd10-xplained-mini,PORTA,9))

110
boards.stm32.mk

@ -4,24 +4,8 @@
LFLAGS_STM32=$(LFLAGS) template_stm32.c -T ld.stm32.basic
# STM32F0 starts up with HSI at 8Mhz
STM32F0_CFLAGS=$(M0_FLAGS) -DSTM32F0 -DLITTLE_BIT=100000 $(LFLAGS_STM32) -lopencm3_stm32f0
# STM32F1 starts up with HSI at 8Mhz
STM32F1_CFLAGS=$(M3_FLAGS) -DSTM32F1 -DLITTLE_BIT=200000 $(LFLAGS_STM32) -lopencm3_stm32f1
# STM32F2 starts up with HSI at 16MHz
STM32F2_CFLAGS=$(M3_FLAGS) -DSTM32F2 -DLITTLE_BIT=400000 $(LFLAGS_STM32) -lopencm3_stm32f2
# STM32F3 starts up with HSI at 8MHz
STM32F3_CFLAGS=$(M4FH_FLAGS) -DSTM32F3 -DLITTLE_BIT=400000 $(LFLAGS_STM32) -lopencm3_stm32f3
# STM32F4 starts up with HSI at 16MHz
STM32F4_CFLAGS=$(M4FH_FLAGS) -DSTM32F4 -DLITTLE_BIT=800000 $(LFLAGS_STM32) -lopencm3_stm32f4
# STM32F7 starts up with HSI at 16MHz
STM32F7_CFLAGS=$(M7SP_FLAGS) -DSTM32F7 -DLITTLE_BIT=800000 $(LFLAGS_STM32) -lopencm3_stm32f7
# STM32L0 starts up with MSI at 2.1Mhz
STM32L0_CFLAGS=$(M0P_FLAGS) -DSTM32L0 -DLITTLE_BIT=50000 $(LFLAGS_STM32) -lopencm3_stm32l0
# STM32L1 starts up with MSI at 4MHz
STM32L1_CFLAGS=$(M3_FLAGS) -DSTM32L1 -DLITTLE_BIT=100000 $(LFLAGS_STM32) -lopencm3_stm32l1
# STM32L4 starts up with MSI at 4MHz
STM32L4_CFLAGS=$(M4FH_FLAGS) -DSTM32L4 -DLITTLE_BIT=100000 $(LFLAGS_STM32) -lopencm3_stm32l4
STM32F1_CFLAGS=$(M3_FLAGS) -DSTM32F1 -DLITTLE_BIT=800000 $(LFLAGS_STM32) -lopencm3_stm32f1
define RAWMakeBoard
$(CC) -DRCC_LED1=$(1) -DPORT_LED1=$(2) -DPIN_LED1=$(3) $(4) -o $(OD)/stm32/$(5)
@ -36,99 +20,9 @@ $(OD)/stm32/$(1).elf: template_stm32.c libopencm3/lib/libopencm3_$(5).a
$(call RAWMakeBoard,RCC_$(2),$(2),$(3),$(4),$(1).elf)
endef
define stm32f0board
$(call MakeBoard,$(1),$(2),$(3),$(STM32F0_CFLAGS),stm32f0)
endef
define stm32f1board
$(call MakeBoard,$(1),$(2),$(3),$(STM32F1_CFLAGS),stm32f1)
endef
define stm32f2board
$(call MakeBoard,$(1),$(2),$(3),$(STM32F2_CFLAGS),stm32f2)
endef
define stm32f3board
$(call MakeBoard,$(1),$(2),$(3),$(STM32F3_CFLAGS),stm32f3)
endef
define stm32f4board
$(call MakeBoard,$(1),$(2),$(3),$(STM32F4_CFLAGS),stm32f4)
endef
define stm32f7board
$(call MakeBoard,$(1),$(2),$(3),$(STM32F7_CFLAGS),stm32f7)
endef
define stm32l0board
$(call MakeBoard,$(1),$(2),$(3),$(STM32L0_CFLAGS),stm32l0)
endef
define stm32l1board
$(call MakeBoard,$(1),$(2),$(3),$(STM32L1_CFLAGS),stm32l1)
endef
define stm32l4board
$(call MakeBoard,$(1),$(2),$(3),$(STM32L4_CFLAGS),stm32l4)
endef
# STM32F0 boards
$(eval $(call stm32f0board,stm32f0-discovery,GPIOC,GPIO8))
$(eval $(call stm32f0board,nucleo-f030r8,GPIOA,GPIO5))
$(eval $(call stm32f0board,nucleo-f031k6,GPIOB,GPIO3))
$(eval $(call stm32f0board,nucleo-f042k6,GPIOB,GPIO3))
$(eval $(call stm32f0board,nucleo-f070rb,GPIOA,GPIO5))
$(eval $(call stm32f0board,nucleo-f072rb,GPIOA,GPIO5))
$(eval $(call stm32f0board,nucleo-f091rc,GPIOA,GPIO5))
# STM32F1 boards
$(eval $(call stm32f1board,stm32vldiscovery,GPIOC,GPIO8))
$(eval $(call stm32f1board,olimex-h103,GPIOC,GPIO12))
$(eval $(call stm32f1board,olimex-h107,GPIOC,GPIO6))
# make only for bluepill board :)
$(eval $(call stm32f1board,bluepill,GPIOC,GPIO13))
$(eval $(call stm32f1board,nucleo-f103rb,GPIOA,GPIO5))
$(eval $(call stm32f1board,lisa-m-1,GPIOC,GPIO13))
$(eval $(call stm32f1board,lisa-m-2,GPIOA,GPIO8))
$(eval $(call stm32f1board,st-mb525,GPIOC,GPIO6))
$(eval $(call stm32f1board,obldc,GPIOA,GPIO6))
$(eval $(call stm32f1board,obldc-strip,GPIOB,GPIO4))
$(eval $(call stm32f1board,leaflabs-maple,GPIOA,GPIO5))
$(eval $(call stm32f1board,waveshare-open103r,GPIOC,GPIO9))
$(eval $(call stm32f1board,olimex-p103,GPIOC,GPIO12))
# STM32F2 boards
$(eval $(call stm32f2board,jobygps,GPIOC,GPIO3))
# STM32F3 boards
$(eval $(call stm32f3board,stm32f3-discovery,GPIOE,GPIO8))
$(eval $(call stm32f3board,nucleo-f302r8,GPIOB,GPIO13))
$(eval $(call stm32f3board,nucleo-f303k8,GPIOB,GPIO3))
$(eval $(call stm32f3board,nucleo-f303re,GPIOA,GPIO5))
$(eval $(call stm32f3board,nucleo-f334r8,GPIOA,GPIO5))
# STM32F4 boards
# New product code for original f4 discovery board.
$(eval $(call stm32f4board,stm32f407g-disc1,GPIOD,GPIO12))
$(eval $(call stm32f4board,stm32f4discover,GPIOD,GPIO12))
$(eval $(call stm32f4board,nucleo-f411re,GPIOA,GPIO5))
$(eval $(call stm32f4board,nucleo-f401re,GPIOA,GPIO5))
$(eval $(call stm32f4board,stm32f429i-disc1,GPIOG,GPIO13))
$(eval $(call stm32f4board,nucleo-f410rb,GPIOA,GPIO5))
$(eval $(call stm32f4board,nucleo-f446re,GPIOA,GPIO5))
$(eval $(call stm32f4board,olimex-p405,GPIOC,GPIO12))
$(eval $(call stm32f4board,olimex-e407,GPIOC,GPIO13))
# STM32F7 boards
$(eval $(call stm32f7board,stm32f746g-disco,GPIOI,GPIO1))
# STM32L0 boards
$(eval $(call stm32l0board,stm32l0538-disco,GPIOB,GPIO4))
$(eval $(call stm32l0board,nucleo-l053r8,GPIOA,GPIO5))
$(eval $(call stm32l0board,nucleo-l073rz,GPIOA,GPIO5))
$(eval $(call stm32l0board,nucleo-l011k4,GPIOB,GPIO3))
$(eval $(call stm32l0board,nucleo-l031k6,GPIOB,GPIO3))
# STM32L1 boards
# New product code for original l1 discovery
$(eval $(call stm32l1board,32l152cdiscovery,GPIOB,GPIO6))
$(eval $(call stm32l1board,stm32l-discovery,GPIOB,GPIO6))
$(eval $(call stm32l1board,nucleo-l152re,GPIOA,GPIO5))
$(eval $(call stm32l1board,32l100cdiscovery,GPIOB,GPIO6))
# STM32L4 boards
$(eval $(call stm32l4board,stm32l476g-disco,GPIOE,GPIO8))
$(eval $(call stm32l4board,nucleo-stm32l432kc,GPIOB,GPIO3))
$(eval $(call stm32l4board,nucleo-stm32l476rg,GPIOA,GPIO5))
$(eval $(call stm32l4board,nucleo-l4r5zi,GPIOC,GPIO7,GPIOB,GPIO7))

37
boards.ti.mk

@ -1,37 +0,0 @@
# Instructions:
# 1) add a rule for your board, following the style in place.
# This file should cover all the TI boards, lm3s, lm4f, tiva, msp432
LFLAGS_TI=$(LFLAGS) template_ti.c -T ld.ti.basic
# FIXME what are default clock speeds?
LM3S_CFLAGS=$(M3_FLAGS) -DLM3S -DLITTLE_BIT=800000 $(LFLAGS_TI) -lopencm3_lm3s
LM4F_CFLAGS=$(M4FH_FLAGS) -DLM4F -DLITTLE_BIT=800000 $(LFLAGS_TI) -lopencm3_lm4f
# FIXME - support led2
define RAWMakeBoard
$(CC) -DRCC_LED1=$(1) -DPORT_LED1=$(2) -DPIN_LED1=$(3) $(4) -o $(OD)/ti/$(5)
endef
define MakeBoard
BOARDS_ELF+=$(OD)/ti/$(1).elf
BOARDS_BIN+=$(OD)/ti/$(1).bin
BOARDS_HEX+=$(OD)/ti/$(1).hex
$(OD)/ti/$(1).elf: template_ti.c libopencm3/lib/libopencm3_$(5).a
@echo " $(5) -> Creating $(OD)/ti/$(1).elf"
$(call RAWMakeBoard,RCC_$(2),$(2),$(3),$(4),$(1).elf)
endef
define lm3sboard
$(call MakeBoard,$(1),$(2),$(3),$(LM3S_CFLAGS),lm3s)
endef
define lm4fboard
$(call MakeBoard,$(1),$(2),$(3),$(LM4F_CFLAGS),lm4f)
endef
# If anyone actually has real lm3s hardware, they can file a bug.
#$(eval $(call lm3sboard,lm3s811-evb,GPIOC,GPIO5))
$(eval $(call lm4fboard,ek-lm4f120xl,GPIOF,GPIO1,GPIOF,GPIO2))
# PN1, PN0, PF4, PF0
$(eval $(call lm4fboard,ek-tm4c1294xl,GPION,GPIO0,GPIOF,GPIO4))

16
ld.efm32.basic

@ -1,16 +0,0 @@
/*
* Generic linker script that works for ~all EFM32
* ~all EFM devices have flash at 0x0 and at least 8K
* ~all EFM devices have ram at 0x200000000 and at least 4K
*
* This is enough for miniblink, but if you try and copy this to your own
* projects, "You're gonna have a bad day"
*/
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 8K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
}
INCLUDE ./cortex-m-generic.ld

16
ld.sam.basic

@ -1,16 +0,0 @@
/*
* Generic linker script that works for ~all Atmel/Microchip SAM devices
* ~all devices have flash at 0x0 and at least 8K
* ~all devices have ram at 0x200000000 and at least 4K
*
* This is enough for miniblink, but if you try and copy this to your own
* projects, "You're gonna have a bad day"
*/
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 8K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
}
INCLUDE ./cortex-m-generic.ld

16
ld.ti.basic

@ -1,16 +0,0 @@
/*
* Generic linker script that works for ~all TI devices
* ~all TI devices have flash at 0x0 and at least 8K
* ~all TI devices have ram at 0x200000000 and at least 4K
*
* This is enough for miniblink, but if you try and copy this to your own
* projects, "You're gonna have a bad day"
*/
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 8K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
}
INCLUDE ./cortex-m-generic.ld

21
template_efm32.c

@ -1,21 +0,0 @@
#include <libopencm3/efm32/cmu.h>
#include <libopencm3/efm32/gpio.h>
int main(void) {
cmu_periph_clock_enable(CMU_GPIO);
gpio_mode_setup(PORT_LED1, GPIO_MODE_PUSH_PULL, PIN_LED1);
gpio_set(PORT_LED1, PIN_LED1);
#if defined(PORT_LED2)
gpio_mode_setup(PORT_LED2, GPIO_MODE_PUSH_PULL, PIN_LED2);
#endif
while(1) {
/* wait a little bit */
for (int i = 0; i < LITTLE_BIT; i++) {
__asm__("nop");
}
gpio_toggle(PORT_LED1, PIN_LED1);
#if defined(PORT_LED2)
gpio_toggle(PORT_LED2, PIN_LED2);
#endif
}
}

30
template_sam.c

@ -1,30 +0,0 @@
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/d/port.h>
static void gpio_setup(void)
{
PORT_DIR(PORT_LED1) = (1<<PIN_LED1);
PORT_PINCFG(PORT_LED1, PIN_LED1) = 0;
#if defined PORT_LED2
PORT_DIR(PORT_LED2) = (1<<PIN_LED2);
PORT_PINCFG(PORT_LED2, PIN_LED2) = 0;
#endif
}
int main(void)
{
gpio_setup();
PORT_OUTTGL(PORT_LED1) = 1<<PIN_LED1;
while (1) {
PORT_OUTTGL(PORT_LED1) = 1<<PIN_LED1;
#if defined PORT_LED2
PORT_OUTTGL(PORT_LED2) = 1<<PIN_LED2;
#endif
/* wait a little bit */
for (int i = 0; i < LITTLE_BIT; i++) {
__asm__("nop");
}
}
return 0;
}

31
template_stm32.c

@ -2,25 +2,14 @@
#include <libopencm3/stm32/gpio.h>
int main(void) {
rcc_periph_clock_enable(RCC_LED1);
#if defined(STM32F1) /* F1 is a precious snowflake */
gpio_set_mode(PORT_LED1, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, PIN_LED1);
#else /* everyone else is sane */
gpio_mode_setup(PORT_LED1, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED1);
#endif
gpio_set(PORT_LED1, PIN_LED1);
#if defined(RCC_LED2)
rcc_periph_clock_enable(RCC_LED2);
gpio_mode_setup(PORT_LED2, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED2);
#endif
while(1) {
/* wait a little bit */
for (int i = 0; i < LITTLE_BIT; i++) {
__asm__("nop");
}
gpio_toggle(PORT_LED1, PIN_LED1);
#if defined(RCC_LED2)
gpio_toggle(PORT_LED2, PIN_LED2);
#endif
}
rcc_periph_clock_enable(RCC_LED1);
gpio_set_mode(PORT_LED1, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, PIN_LED1);
gpio_set(PORT_LED1, PIN_LED1);
while(1) {
/* wait a little bit */
for (int i = 0; i < LITTLE_BIT; i++) {
__asm__("nop");
}
gpio_toggle(PORT_LED1, PIN_LED1);
}
}

36
template_ti.c

@ -1,36 +0,0 @@
#if defined(LM3S)
#error "LM3S is very poorly supported file a ticket if you actually have this hw"
#include <libopencm3/lm3s/rcc.h>
#include <libopencm3/lm3s/gpio.h>
#elif defined(LM4F)
#include <libopencm3/lm4f/rcc.h>
#include <libopencm3/lm4f/gpio.h>
#else
#error "Unknown TI family!"
#endif
int main(void) {
gpio_enable_ahb_aperture();
periph_clock_enable(RCC_LED1);
/* FIXME - may need to gpio_unlock_commit(port,pin)! */
gpio_mode_setup(PORT_LED1, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED1);
gpio_set_output_config(PORT_LED1, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, PIN_LED1);
gpio_set(PORT_LED1, PIN_LED1);
#if defined(RCC_LED2)
periph_clock_enable(RCC_LED2);
gpio_mode_setup(PORT_LED2, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED2);
gpio_set_output_config(PORT_LED2, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, PIN_LED2);
#endif
while(1) {
/* wait a little bit */
for (int i = 0; i < LITTLE_BIT; i++) {
__asm__("nop");
}
gpio_toggle(PORT_LED1, PIN_LED1);
#if defined(RCC_LED2)
gpio_toggle(PORT_LED2, PIN_LED2);
#endif
}
}
Loading…
Cancel
Save