Skip to content

Commit eb4edd9

Browse files
author
rogerclarkmelbourne
committed
Added usb_bootloader, taken from the latest files of https://github.com/jonatanolofsson/maple-bootloader commit id 5f09352278faf1b31b9e1bbef7c00f1469fb63b8, then checked out the maple mini (mini-boot) branch, as that branch seems to contain the most fixes and updates.
1 parent fddefc1 commit eb4edd9

42 files changed

Lines changed: 7782 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

usb_bootloader/STM32F1/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.dep
2+
TAGS
3+
tags
4+
cscope.out
5+
build
6+
*~

usb_bootloader/STM32F1/CREDITS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This is at least a partial credits-file of people that have
2+
contributed to the Maple bootloader. It is formatted the same way the
3+
Linux kernel CREDITS file is structured: sorted by name and formatted
4+
for easy processing.
5+
6+
The fields are: name (N), email (E), web-address (W), description (D).
7+
8+
----------
9+
10+
N: Tormod Volden
11+
E: debian.tormod@gmail.com
12+
D: Fixes for DFU compliance

usb_bootloader/STM32F1/Makefile

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# Makefile skeleton adapted from Peter Harrison's - www.micromouse.com
2+
3+
# MCU name and submodel
4+
MCU = cortex-m3
5+
SUBMDL = stm32f103
6+
7+
# toolchain (using code sourcery now)
8+
TCHAIN = arm-none-eabi
9+
THUMB = -mthumb
10+
THUMB_IW = -mthumb-interwork
11+
12+
# Target file name (without extension).
13+
BUILDDIR = build
14+
TARGET = $(BUILDDIR)/maple_boot
15+
16+
ST_LIB = stm32_lib
17+
ST_USB = usb_lib
18+
19+
# Optimization level [0,1,2,3,s]
20+
OPT ?= 0
21+
DEBUG =
22+
#DEBUG = dwarf-2
23+
24+
INCDIRS = ./$(ST_LIB) ./$(ST_USB)
25+
26+
CFLAGS = $(DEBUG)
27+
CFLAGS += -O$(OPT)
28+
CFLAGS += -ffunction-sections -fdata-sections
29+
CFLAGS += -Wall -Wimplicit
30+
CFLAGS += -Wcast-align
31+
CFLAGS += -Wpointer-arith -Wswitch
32+
CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wunused
33+
CFLAGS += -Wa,-adhlns=$(BUILDDIR)/$(subst $(suffix $<),.lst,$<)
34+
CFLAGS += $(patsubst %,-I%,$(INCDIRS))
35+
36+
# Aeembler Flags
37+
ASFLAGS = -Wa,-adhlns=$(BUILDDIR)/$(<:.s=.lst)#,--g$(DEBUG)
38+
39+
LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref,--gc-sections
40+
LDFLAGS += -lc -lgcc
41+
42+
# Set the linker script
43+
LDFLAGS +=-T$(ST_LIB)/c_only_md.ld
44+
45+
# Define programs and commands.
46+
SHELL = sh
47+
CC = $(TCHAIN)-gcc
48+
CPP = $(TCHAIN)-g++
49+
AR = $(TCHAIN)-ar
50+
OBJCOPY = $(TCHAIN)-objcopy
51+
OBJDUMP = $(TCHAIN)-objdump
52+
SIZE = $(TCHAIN)-size
53+
NM = $(TCHAIN)-nm
54+
REMOVE = rm -f
55+
REMOVEDIR = rm -r
56+
COPY = cp
57+
58+
# Define Messages
59+
# English
60+
MSG_ERRORS_NONE = Errors: none
61+
MSG_BEGIN = "-------- begin --------"
62+
MSG_ETAGS = Created TAGS File
63+
MSG_END = -------- end --------
64+
MSG_SIZE_BEFORE = Size before:
65+
MSG_SIZE_AFTER = Size after:
66+
MSG_FLASH = Creating load file for Flash:
67+
MSG_EXTENDED_LISTING = Creating Extended Listing:
68+
MSG_SYMBOL_TABLE = Creating Symbol Table:
69+
MSG_LINKING = Linking:
70+
MSG_COMPILING = Compiling C:
71+
MSG_ASSEMBLING = Assembling:
72+
MSG_CLEANING = Cleaning project:
73+
74+
# Combine all necessary flags and optional flags.
75+
# Add target processor to flags.
76+
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
77+
ALL_CFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. $(CFLAGS) $(GENDEPFLAGS)
78+
ALL_ASFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp $(ASFLAGS)
79+
80+
# --------------------------------------------- #
81+
# file management
82+
ASRC = $(ST_LIB)/c_only_startup.s $(ST_LIB)/cortexm3_macro.s
83+
84+
STM32SRCS =
85+
86+
_STM32USBSRCS = usb_regs.c \
87+
usb_int.c \
88+
usb_init.c \
89+
usb_core.c \
90+
usb_mem.c
91+
92+
STM32USBSRCS = $(patsubst %, $(ST_USB)/%,$(_STM32USBSRCS))
93+
94+
SRCS = usb.c usb_callbacks.c usb_descriptor.c main.c hardware.c dfu.c
95+
96+
97+
SRC = $(SRCS) $(STM32SRCS) $(STM32USBSRCS)
98+
99+
# Define all object files.
100+
_COBJ = $(SRC:.c=.o)
101+
_AOBJ = $(ASRC:.s=.o)
102+
COBJ = $(patsubst %, $(BUILDDIR)/%,$(_COBJ))
103+
AOBJ = $(patsubst %, $(BUILDDIR)/%,$(_AOBJ))
104+
105+
# Define all listing files.
106+
_LST = $(ASRC:.s=.lst)
107+
_LST += $(SRC:.c=.lst)
108+
LST = $(patsubst %, $(BUILDDIR)/%,$(_LST))
109+
110+
# Display size of file.
111+
HEXSIZE = $(SIZE) --target=binary $(TARGET).hex
112+
ELFSIZE = $(SIZE) -A $(TARGET).elf
113+
114+
# go!
115+
all: begin gccversion build sizeafter finished end
116+
build: elf bin lss sym
117+
118+
bin: $(TARGET).bin
119+
elf: $(TARGET).elf
120+
lss: $(TARGET).lss
121+
sym: $(TARGET).sym
122+
dfu: $(TARGET).bin
123+
sudo dfu-util -d 0110:1001 -a 0 -D $(TARGET).bin
124+
125+
begin:
126+
mkdir -p build/stm32_lib
127+
mkdir -p build/usb_lib
128+
@echo --
129+
@echo $(MSG_BEGIN)
130+
@echo $(COBJ)
131+
132+
finished:
133+
@echo $(MSG_ERRORS_NONE)
134+
tags:
135+
etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"`
136+
@echo $(MSG_ETAGS)
137+
end:
138+
@echo $(MSG_END)
139+
@echo
140+
sizeafter:
141+
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
142+
gccversion:
143+
@$(CC) --version
144+
145+
program:
146+
@echo "Flash-programming with OpenOCD"
147+
cp $(TARGET).bin flash/tmpflash.bin
148+
cd flash && openocd -f flash.cfg
149+
150+
program_serial:
151+
@echo "Flash-programming with stm32loader.py"
152+
./flash/stm32loader.py -p /dev/ttyUSB0 -evw build/maple_boot.bin
153+
154+
debug: $(TARGET).bin
155+
@echo "Flash-programming with OpenOCD - DEBUG"
156+
cp $(TARGET).bin flash/tmpflash.bin
157+
cd flash && openocd -f debug.cfg
158+
159+
install: $(TARGET).bin
160+
cp $(TARGET).bin build/main.bin
161+
openocd -f flash/perry_flash.cfg
162+
163+
run: $(TARGET).bin
164+
openocd -f flash/run.cfg
165+
166+
# Create final output file (.hex) from ELF output file.
167+
%.hex: %.elf
168+
@echo
169+
@echo $(MSG_FLASH) $@
170+
$(OBJCOPY) -O binary $< $@
171+
172+
# Create final output file (.bin) from ELF output file.
173+
%.bin: %.elf
174+
@echo
175+
@echo $(MSG_FLASH) $@
176+
$(OBJCOPY) -O binary $< $@
177+
178+
179+
# Create extended listing file from ELF output file.
180+
# testing: option -C
181+
%.lss: %.elf
182+
@echo
183+
@echo $(MSG_EXTENDED_LISTING) $@
184+
$(OBJDUMP) -h -S -D $< > $@
185+
186+
187+
# Create a symbol table from ELF output file.
188+
%.sym: %.elf
189+
@echo
190+
@echo $(MSG_SYMBOL_TABLE) $@
191+
$(NM) -n $< > $@
192+
193+
194+
# Link: create ELF output file from object files.
195+
.SECONDARY : $(TARGET).elf
196+
.PRECIOUS : $(COBJ) $(AOBJ)
197+
198+
%.elf: $(COBJ) $(AOBJ)
199+
@echo
200+
@echo $(MSG_LINKING) $@
201+
$(CC) $(THUMB) $(ALL_CFLAGS) $(AOBJ) $(COBJ) --output $@ $(LDFLAGS)
202+
203+
# Compile: create object files from C source files. ARM/Thumb
204+
$(COBJ) : $(BUILDDIR)/%.o : %.c
205+
@echo
206+
@echo $(MSG_COMPILING) $<
207+
$(CC) -c $(THUMB) $(ALL_CFLAGS) $< -o $@
208+
209+
# Assemble: create object files from assembler source files. ARM/Thumb
210+
$(AOBJ) : $(BUILDDIR)/%.o : %.s
211+
@echo
212+
@echo $(MSG_ASSEMBLING) $<
213+
$(CC) -c $(THUMB) $(ALL_ASFLAGS) $< -o $@
214+
215+
clean: begin clean_list finished end
216+
217+
clean_list :
218+
@echo
219+
@echo $(MSG_CLEANING)
220+
$(REMOVE) $(TARGET).hex
221+
$(REMOVE) $(TARGET).bin
222+
$(REMOVE) $(TARGET).obj
223+
$(REMOVE) $(TARGET).elf
224+
$(REMOVE) $(TARGET).map
225+
$(REMOVE) $(TARGET).obj
226+
$(REMOVE) $(TARGET).a90
227+
$(REMOVE) $(TARGET).sym
228+
$(REMOVE) $(TARGET).lnk
229+
$(REMOVE) $(TARGET).lss
230+
$(REMOVE) $(COBJ)
231+
$(REMOVE) $(AOBJ)
232+
$(REMOVE) $(LST)
233+
$(REMOVE) flash/tmpflash.bin
234+
# $(REMOVE) $(SRC:.c=.s)
235+
# $(REMOVE) $(SRC:.c=.d)
236+
$(REMOVE) .dep/*
237+
238+
# Include the dependency files.
239+
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
240+
241+
242+
# Listing of phony targets.
243+
.PHONY : all begin finish tags end sizeafter gccversion \
244+
build elf hex bin lss sym clean clean_list program cscope
245+
246+
cscope:
247+
rm -rf *.cscope
248+
find . -iname "*.[hcs]" | grep -v examples | xargs cscope -R -b
249+

usb_bootloader/STM32F1/README

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
FILES -------------------------------------------------------------------------
3+
4+
stm32lib/*
5+
- all the (possibly consolidated) stm32 lib and usb example code
6+
7+
usb.c
8+
- USB-specific hardware setup. Interrupts, clocks, etc. handling USB when
9+
not "Attached". some low-level callbacks (low power mode, init, reset,
10+
resume, etc).
11+
12+
usb_callbacks.c
13+
- aka endpoints: handling data transfer when "Configured". calls out to
14+
application specific callbacks (i.e. DFU).
15+
16+
usb_descriptor.c
17+
- aka application descriptor; big static struct and callbacks for sending
18+
the descriptor.
19+
20+
main.c
21+
- main loop and calling any hardware init stuff. timing hacks for EEPROM
22+
writes not to block usb interrupts. logic to handle 2 second timeout then
23+
jump to user code.
24+
25+
hardware.c
26+
- init routines to setup clocks, interrupts, also destructor functions.
27+
does not include USB stuff. EEPROM read/write functions.
28+
29+
dfu.c
30+
- mostly the giant FSM case switch, also some USB endpoint callbacks
31+
32+
TODO --------------------------------------------------------------------------
33+
34+
* pack the structs
35+
* use sizeof() for usb application descriptor once structs are packed

usb_bootloader/STM32F1/common.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* *****************************************************************************
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 LeafLabs LLC.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
* ****************************************************************************/
24+
25+
/**
26+
* @file common.h
27+
*
28+
* @brief toplevel include for bootloader source files
29+
*
30+
*
31+
*/
32+
33+
#ifndef __COMMON_H
34+
#define __COMMON_H
35+
36+
#include "config.h"
37+
#include "hardware.h"
38+
#include "stm32f10x_type.h"
39+
#include "cortexm3_macro.h"
40+
#include "usb.h"
41+
42+
typedef void (*FuncPtr)(void);
43+
44+
#endif

0 commit comments

Comments
 (0)