diff --git a/Makefile b/Makefile index c714c5b..1dd4ae8 100644 --- a/Makefile +++ b/Makefile @@ -79,25 +79,32 @@ BINBIN=outp.bin MCFLAGS=-mcpu=cortex-m3 -march=armv7-m -mthumb -Wall -Wextra # COMPILE FLAGS -DEFS_HS=-DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -DHSE_VALUE=$(OSC) +DEFS_HS=-DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -DHSE_VALUE=$(OSC) -DVECT_TAB_OFFSET=0x0 +DEFS_HS_BL=-DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -DHSE_VALUE=$(OSC) -DVECT_TAB_OFFSET=0x2000 CFLAGS=-c $(MCFLAGS) $(INCLUDES) CXXFLAGS=-c $(MCFLAGS) $(INCLUDES) # LINKER FLAGS -LDSCRIPT=stm32f10x_link.ld -LDFLAGS =-T $(LDSCRIPT) $(MCFLAGS) --specs=nosys.specs $(INCLUDES_LIBS) $(LINK_LIBS) +LDSCRIPT=normal.ld +LDSCRIPT_BL=bootloader.ld +LDFLAGS=$(MCFLAGS) --specs=nosys.specs $(INCLUDES_LIBS) $(LINK_LIBS) # Build Rules -.PHONY: all release hs debug clean +.PHONY: all release hs bl debug clean all: hs -hs: CFLAGS+=$(DEFS_HS) -Os -MMD -ffunction-sections -fdata-sections -nostdlib -DCUSTOM_NEW -DNO_EXCEPTIONS -hs: CXXFLAGS+=$(DEFS_HS) -Os -MMD -fno-exceptions -ffunction-sections -fdata-sections -nostdlib -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS -hs: LDFLAGS+=-Os --specs=nano.specs +hs: CFLAGS+=$(DEFS_HS) -Os -ffunction-sections -fdata-sections -nostdlib -DCUSTOM_NEW -DNO_EXCEPTIONS +hs: CXXFLAGS+=$(DEFS_HS) -Os -fno-exceptions -ffunction-sections -fdata-sections -nostdlib -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS +hs: LDFLAGS+=-T $(LDSCRIPT_N) -Os --specs=nano.specs hs: release +bl: CFLAGS+=$(DEFS_HS_BL) -Os -ffunction-sections -fdata-sections -nostdlib -DCUSTOM_NEW -DNO_EXCEPTIONS +bl: CXXFLAGS+=$(DEFS_HS_BL) -Os -fno-exceptions -ffunction-sections -fdata-sections -nostdlib -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS +bl: LDFLAGS+=-T $(LDSCRIPT_BL) -Os --specs=nano.specs +bl: release + debug: CFLAGS+=-g $(DEFS_HS) debug: CXXFLAGS+=-g $(DEFS_HS) debug: LDFLAGS+=-g @@ -151,6 +158,22 @@ ifneq ($(wildcard /opt/openocd/bin/openocd),) /opt/openocd/bin/openocd -f /opt/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f1x.cfg -c "program bin/$(BINELF) verify reset exit" endif +stlink-bl: +ifneq ($(wildcard /usr/bin/openocd),) + /usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg -c "program STM32F10X_Lib/utils/bootloader/generic_boot20_pc13.bin verify reset exit 0x08002000" + /usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f1x.cfg -c "program bin/$(BINBIN) verify reset exit 0x08002000" +endif + +ifneq ($(wildcard /usr/local/bin/openocd),) + /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg -c "program STM32F10X_Lib/utils/bootloader/generic_boot20_pc13.bin verify reset exit 0x08002000" + /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg -c "program bin/$(BINBIN) verify reset exit 0x08002000" +endif + +ifneq ($(wildcard /opt/openocd/bin/openocd),) + /opt/openocd/bin/openocd -f /opt/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f1x.cfg -c "program STM32F10X_Lib/utils/bootloader/generic_boot20_pc13.bin verify reset exit 0x08002000" + /opt/openocd/bin/openocd -f /opt/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f1x.cfg -c "program bin/$(BINBIN) verify reset exit 0x08002000" +endif + serial: ifneq ($(wildcard /usr/local/bin/stm32flash),) /usr/local/bin/stm32flash -w bin/$(BINBIN) -g 0x0 $(devser) diff --git a/bootloader.ld b/bootloader.ld new file mode 100644 index 0000000..09a172e --- /dev/null +++ b/bootloader.ld @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2016 by Andy Uribe CA6JAU + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Memory areas */ +MEMORY +{ + ROM (rx) : ORIGIN = 0x08002000, LENGTH = 56K /* FLASH */ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K /* Main RAM */ +} + +INCLUDE stm32f10x_link.ld diff --git a/normal.ld b/normal.ld new file mode 100644 index 0000000..154f653 --- /dev/null +++ b/normal.ld @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2016 by Andy Uribe CA6JAU + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Memory areas */ +MEMORY +{ + ROM (rx) : ORIGIN = 0x08000000, LENGTH = 64K /* FLASH */ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K /* Main RAM */ +} + +INCLUDE stm32f10x_link.ld \ No newline at end of file diff --git a/stm32f10x_link.ld b/stm32f10x_link.ld index 8dc7a21..28047f0 100644 --- a/stm32f10x_link.ld +++ b/stm32f10x_link.ld @@ -23,13 +23,6 @@ _min_stack_size = 0x0800; /* The entry point in the interrupt vector table */ ENTRY(Reset_Handler) -/* Memory areas */ -MEMORY -{ - ROM (rx) : ORIGIN = 0x08000000, LENGTH = 64K /* FLASH */ - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K /* Main RAM */ -} - /* Stack start address (end of 20K RAM) */ _estack = ORIGIN(RAM) + LENGTH(RAM);