aboutsummaryrefslogtreecommitdiff
path: root/Arduino_STM32-MIDI/other/maple-bootloader
diff options
context:
space:
mode:
authormadias123 <matthias.lichtenegger@gmail.com>2015-03-23 23:42:57 +0100
committermadias123 <matthias.lichtenegger@gmail.com>2015-03-23 23:42:57 +0100
commit488f6212a01e82a9430392b3bdd6af369d1d95cf (patch)
tree1ab1599c89e4fb0298492872aacbd21e7d829178 /Arduino_STM32-MIDI/other/maple-bootloader
test
test
Diffstat (limited to 'Arduino_STM32-MIDI/other/maple-bootloader')
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/CREDITS12
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/Makefile249
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/README35
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/common.h44
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/config.h59
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/dfu.c409
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/dfu.h121
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/flash/debug.cfg83
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/flash/flash.cfg91
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/flash/openocd.cfg73
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/flash/stm32.cfg72
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/flash/stm32loader.py435
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/hardware.c304
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/hardware.h190
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/main.c70
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/readme.md5
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md.ld172
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md_RAM.ld169
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup.s367
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup_user.s128
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.h53
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.s312
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/stm32_lib/stm32f10x_type.h80
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb.c503
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb.h132
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_callbacks.c31
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.c193
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.h40
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_conf.h86
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.c1013
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.h247
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_def.h80
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.c64
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.h49
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.c192
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.h33
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_lib.h37
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.c73
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.h32
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.c748
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.h619
-rwxr-xr-xArduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_type.h72
42 files changed, 7777 insertions, 0 deletions
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/CREDITS b/Arduino_STM32-MIDI/other/maple-bootloader/CREDITS
new file mode 100755
index 0000000..4318fff
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/CREDITS
@@ -0,0 +1,12 @@
+This is at least a partial credits-file of people that have
+contributed to the Maple bootloader. It is formatted the same way the
+Linux kernel CREDITS file is structured: sorted by name and formatted
+for easy processing.
+
+The fields are: name (N), email (E), web-address (W), description (D).
+
+----------
+
+N: Tormod Volden
+E: debian.tormod@gmail.com
+D: Fixes for DFU compliance
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/Makefile b/Arduino_STM32-MIDI/other/maple-bootloader/Makefile
new file mode 100755
index 0000000..4318bd9
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/Makefile
@@ -0,0 +1,249 @@
+# Makefile skeleton adapted from Peter Harrison's - www.micromouse.com
+
+# MCU name and submodel
+MCU = cortex-m3
+SUBMDL = stm32f103
+
+# toolchain (using code sourcery now)
+TCHAIN = arm-none-eabi
+THUMB = -mthumb
+THUMB_IW = -mthumb-interwork
+
+# Target file name (without extension).
+BUILDDIR = build
+TARGET = $(BUILDDIR)/maple_boot
+
+ST_LIB = stm32_lib
+ST_USB = usb_lib
+
+# Optimization level [0,1,2,3,s]
+OPT ?= 0
+DEBUG =
+#DEBUG = dwarf-2
+
+INCDIRS = ./$(ST_LIB) ./$(ST_USB)
+
+CFLAGS = $(DEBUG)
+CFLAGS += -O$(OPT)
+CFLAGS += -ffunction-sections -fdata-sections
+CFLAGS += -Wall -Wimplicit
+CFLAGS += -Wcast-align
+CFLAGS += -Wpointer-arith -Wswitch
+CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wunused
+CFLAGS += -Wa,-adhlns=$(BUILDDIR)/$(subst $(suffix $<),.lst,$<)
+CFLAGS += $(patsubst %,-I%,$(INCDIRS))
+
+# Aeembler Flags
+ASFLAGS = -Wa,-adhlns=$(BUILDDIR)/$(<:.s=.lst)#,--g$(DEBUG)
+
+LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref,--gc-sections
+LDFLAGS += -lc -lgcc
+
+# Set the linker script
+LDFLAGS +=-T$(ST_LIB)/c_only_md.ld
+
+# Define programs and commands.
+SHELL = sh
+CC = $(TCHAIN)-gcc
+CPP = $(TCHAIN)-g++
+AR = $(TCHAIN)-ar
+OBJCOPY = $(TCHAIN)-objcopy
+OBJDUMP = $(TCHAIN)-objdump
+SIZE = $(TCHAIN)-size
+NM = $(TCHAIN)-nm
+REMOVE = rm -f
+REMOVEDIR = rm -r
+COPY = cp
+
+# Define Messages
+# English
+MSG_ERRORS_NONE = Errors: none
+MSG_BEGIN = "-------- begin --------"
+MSG_ETAGS = Created TAGS File
+MSG_END = -------- end --------
+MSG_SIZE_BEFORE = Size before:
+MSG_SIZE_AFTER = Size after:
+MSG_FLASH = Creating load file for Flash:
+MSG_EXTENDED_LISTING = Creating Extended Listing:
+MSG_SYMBOL_TABLE = Creating Symbol Table:
+MSG_LINKING = Linking:
+MSG_COMPILING = Compiling C:
+MSG_ASSEMBLING = Assembling:
+MSG_CLEANING = Cleaning project:
+
+# Combine all necessary flags and optional flags.
+# Add target processor to flags.
+GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
+ALL_CFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. $(CFLAGS) $(GENDEPFLAGS)
+ALL_ASFLAGS = -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp $(ASFLAGS)
+
+# --------------------------------------------- #
+# file management
+ASRC = $(ST_LIB)/c_only_startup.s $(ST_LIB)/cortexm3_macro.s
+
+STM32SRCS =
+
+_STM32USBSRCS = usb_regs.c \
+usb_int.c \
+usb_init.c \
+usb_core.c \
+usb_mem.c
+
+STM32USBSRCS = $(patsubst %, $(ST_USB)/%,$(_STM32USBSRCS))
+
+SRCS = usb.c usb_callbacks.c usb_descriptor.c main.c hardware.c dfu.c
+
+
+SRC = $(SRCS) $(STM32SRCS) $(STM32USBSRCS)
+
+# Define all object files.
+_COBJ = $(SRC:.c=.o)
+_AOBJ = $(ASRC:.s=.o)
+COBJ = $(patsubst %, $(BUILDDIR)/%,$(_COBJ))
+AOBJ = $(patsubst %, $(BUILDDIR)/%,$(_AOBJ))
+
+# Define all listing files.
+_LST = $(ASRC:.s=.lst)
+_LST += $(SRC:.c=.lst)
+LST = $(patsubst %, $(BUILDDIR)/%,$(_LST))
+
+# Display size of file.
+HEXSIZE = $(SIZE) --target=binary $(TARGET).hex
+ELFSIZE = $(SIZE) -A $(TARGET).elf
+
+# go!
+all: begin gccversion build sizeafter finished end
+build: elf bin lss sym
+
+bin: $(TARGET).bin
+elf: $(TARGET).elf
+lss: $(TARGET).lss
+sym: $(TARGET).sym
+dfu: $(TARGET).bin
+ sudo dfu-util -d 0110:1001 -a 0 -D $(TARGET).bin
+
+begin:
+ mkdir -p build/stm32_lib
+ mkdir -p build/usb_lib
+ @echo --
+ @echo $(MSG_BEGIN)
+ @echo $(COBJ)
+
+finished:
+ @echo $(MSG_ERRORS_NONE)
+tags:
+ etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"`
+ @echo $(MSG_ETAGS)
+end:
+ @echo $(MSG_END)
+ @echo
+sizeafter:
+ @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
+gccversion:
+ @$(CC) --version
+
+program:
+ @echo "Flash-programming with OpenOCD"
+ cp $(TARGET).bin flash/tmpflash.bin
+ cd flash && openocd -f flash.cfg
+
+program_serial:
+ @echo "Flash-programming with stm32loader.py"
+ ./flash/stm32loader.py -p /dev/ttyUSB0 -evw build/maple_boot.bin
+
+debug: $(TARGET).bin
+ @echo "Flash-programming with OpenOCD - DEBUG"
+ cp $(TARGET).bin flash/tmpflash.bin
+ cd flash && openocd -f debug.cfg
+
+install: $(TARGET).bin
+ cp $(TARGET).bin build/main.bin
+ openocd -f flash/perry_flash.cfg
+
+run: $(TARGET).bin
+ openocd -f flash/run.cfg
+
+# Create final output file (.hex) from ELF output file.
+%.hex: %.elf
+ @echo
+ @echo $(MSG_FLASH) $@
+ $(OBJCOPY) -O binary $< $@
+
+# Create final output file (.bin) from ELF output file.
+%.bin: %.elf
+ @echo
+ @echo $(MSG_FLASH) $@
+ $(OBJCOPY) -O binary $< $@
+
+
+# Create extended listing file from ELF output file.
+# testing: option -C
+%.lss: %.elf
+ @echo
+ @echo $(MSG_EXTENDED_LISTING) $@
+ $(OBJDUMP) -h -S -D $< > $@
+
+
+# Create a symbol table from ELF output file.
+%.sym: %.elf
+ @echo
+ @echo $(MSG_SYMBOL_TABLE) $@
+ $(NM) -n $< > $@
+
+
+# Link: create ELF output file from object files.
+.SECONDARY : $(TARGET).elf
+.PRECIOUS : $(COBJ) $(AOBJ)
+
+%.elf: $(COBJ) $(AOBJ)
+ @echo
+ @echo $(MSG_LINKING) $@
+ $(CC) $(THUMB) $(ALL_CFLAGS) $(AOBJ) $(COBJ) --output $@ $(LDFLAGS)
+
+# Compile: create object files from C source files. ARM/Thumb
+$(COBJ) : $(BUILDDIR)/%.o : %.c
+ @echo
+ @echo $(MSG_COMPILING) $<
+ $(CC) -c $(THUMB) $(ALL_CFLAGS) $< -o $@
+
+# Assemble: create object files from assembler source files. ARM/Thumb
+$(AOBJ) : $(BUILDDIR)/%.o : %.s
+ @echo
+ @echo $(MSG_ASSEMBLING) $<
+ $(CC) -c $(THUMB) $(ALL_ASFLAGS) $< -o $@
+
+clean: begin clean_list finished end
+
+clean_list :
+ @echo
+ @echo $(MSG_CLEANING)
+ $(REMOVE) $(TARGET).hex
+ $(REMOVE) $(TARGET).bin
+ $(REMOVE) $(TARGET).obj
+ $(REMOVE) $(TARGET).elf
+ $(REMOVE) $(TARGET).map
+ $(REMOVE) $(TARGET).obj
+ $(REMOVE) $(TARGET).a90
+ $(REMOVE) $(TARGET).sym
+ $(REMOVE) $(TARGET).lnk
+ $(REMOVE) $(TARGET).lss
+ $(REMOVE) $(COBJ)
+ $(REMOVE) $(AOBJ)
+ $(REMOVE) $(LST)
+ $(REMOVE) flash/tmpflash.bin
+# $(REMOVE) $(SRC:.c=.s)
+# $(REMOVE) $(SRC:.c=.d)
+ $(REMOVE) .dep/*
+
+# Include the dependency files.
+-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
+
+
+# Listing of phony targets.
+.PHONY : all begin finish tags end sizeafter gccversion \
+build elf hex bin lss sym clean clean_list program cscope
+
+cscope:
+ rm -rf *.cscope
+ find . -iname "*.[hcs]" | grep -v examples | xargs cscope -R -b
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/README b/Arduino_STM32-MIDI/other/maple-bootloader/README
new file mode 100755
index 0000000..4aaac53
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/README
@@ -0,0 +1,35 @@
+
+FILES -------------------------------------------------------------------------
+
+stm32lib/*
+ - all the (possibly consolidated) stm32 lib and usb example code
+
+usb.c
+ - USB-specific hardware setup. Interrupts, clocks, etc. handling USB when
+ not "Attached". some low-level callbacks (low power mode, init, reset,
+ resume, etc).
+
+usb_callbacks.c
+ - aka endpoints: handling data transfer when "Configured". calls out to
+ application specific callbacks (i.e. DFU).
+
+usb_descriptor.c
+ - aka application descriptor; big static struct and callbacks for sending
+ the descriptor.
+
+main.c
+ - main loop and calling any hardware init stuff. timing hacks for EEPROM
+ writes not to block usb interrupts. logic to handle 2 second timeout then
+ jump to user code.
+
+hardware.c
+ - init routines to setup clocks, interrupts, also destructor functions.
+ does not include USB stuff. EEPROM read/write functions.
+
+dfu.c
+ - mostly the giant FSM case switch, also some USB endpoint callbacks
+
+TODO --------------------------------------------------------------------------
+
+ * pack the structs
+ * use sizeof() for usb application descriptor once structs are packed
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/common.h b/Arduino_STM32-MIDI/other/maple-bootloader/common.h
new file mode 100755
index 0000000..ba322df
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/common.h
@@ -0,0 +1,44 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @file common.h
+ *
+ * @brief toplevel include for bootloader source files
+ *
+ *
+ */
+
+#ifndef __COMMON_H
+#define __COMMON_H
+
+#include "config.h"
+#include "hardware.h"
+#include "stm32f10x_type.h"
+#include "cortexm3_macro.h"
+#include "usb.h"
+
+typedef void (*FuncPtr)(void);
+
+#endif
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/config.h b/Arduino_STM32-MIDI/other/maple-bootloader/config.h
new file mode 100755
index 0000000..79247bb
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/config.h
@@ -0,0 +1,59 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @file config.h
+ *
+ * @brief bootloader settings and macro defines
+ *
+ *
+ */
+
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+#include "common.h"
+
+#define LED_BANK GPIOB
+#define LED 1
+#define BLINK_FAST 0x50000
+#define BLINK_SLOW 0x100000
+
+#define BUTTON_BANK GPIOB
+#define BUTTON 8
+
+#define STARTUP_BLINKS 5
+#define BOOTLOADER_WAIT 6
+
+#define USER_CODE_RAM ((u32)0x20000C00)
+#define RAM_END ((u32)0x20005000)
+#define USER_CODE_FLASH ((u32)0x08005000)
+#define FLASH_END ((u32)0x08020000)
+
+#define VEND_ID0 0xAF
+#define VEND_ID1 0x1E
+#define PROD_ID0 0x03
+#define PROD_ID1 0x00
+
+#endif
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/dfu.c b/Arduino_STM32-MIDI/other/maple-bootloader/dfu.c
new file mode 100755
index 0000000..a5ec00b
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/dfu.c
@@ -0,0 +1,409 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @file dfu.c
+ *
+ * @brief The principle dfu state machine as well as the data
+ * transfer callbacks accessed by the usb library
+ *
+ *
+ */
+
+#include "dfu.h"
+#include "usb.h"
+
+/* DFU globals */
+static volatile u32 userAppAddr = USER_CODE_RAM; /* default RAM user code location */
+static volatile u32 userAppEnd = RAM_END;
+static volatile DFUStatus dfuAppStatus; /* includes state */
+static volatile bool userFlash = FALSE;
+volatile bool dfuBusy = FALSE;
+
+static volatile u8 recvBuffer[wTransferSize] __attribute__((aligned(4)));
+static volatile u32 userFirmwareLen = 0;
+static volatile u16 thisBlockLen = 0;
+static volatile u16 uploadBlockLen = 0;
+
+
+volatile PLOT code_copy_lock;
+
+/* todo: force dfu globals to be singleton to avoid re-inits? */
+void dfuInit(void) {
+ dfuAppStatus.bStatus = OK;
+ dfuAppStatus.bwPollTimeout0 = 0x00;
+ dfuAppStatus.bwPollTimeout1 = 0x00;
+ dfuAppStatus.bwPollTimeout2 = 0x00;
+ dfuAppStatus.bState = dfuIDLE;
+ dfuAppStatus.iString = 0x00; /* all strings must be 0x00 until we make them! */
+ userFirmwareLen = 0;
+ thisBlockLen = 0;;
+ userAppAddr = USER_CODE_RAM; /* default RAM user code location */
+ userAppEnd = RAM_END;
+ userFlash = FALSE;
+ code_copy_lock = WAIT;
+ dfuBusy = FALSE;
+}
+
+bool dfuUpdateByRequest(void) {
+ /* were using the global pInformation struct from usb_lib here,
+ see comment in maple_dfu.h around DFUEvent struct */
+ dfuBusy = TRUE;
+
+ u8 startState = dfuAppStatus.bState;
+ dfuAppStatus.bStatus = OK;
+ /* often leaner to nest if's then embed a switch/case */
+ if (startState == dfuIDLE) {
+ /* device running inside DFU mode */
+ dfuBusy = TRUE; // signals the main loop to defer to the dfu write-loop
+
+ if (pInformation->USBbRequest == DFU_DNLOAD) {
+
+ if (pInformation->USBwLengths.w > 0) {
+ userFirmwareLen = 0;
+ dfuAppStatus.bState = dfuDNLOAD_SYNC;
+
+ if (pInformation->Current_AlternateSetting == 1) {
+ userAppAddr = USER_CODE_FLASH;
+ userFlash = TRUE;
+
+ /* make sure the flash is setup properly, unlock it */
+ setupFLASH();
+ flashUnlock();
+
+ } else {
+ userAppAddr = USER_CODE_RAM;
+ userFlash = FALSE;
+ }
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errNOTDONE;
+ }
+ } else if (pInformation->USBbRequest == DFU_UPLOAD) {
+ dfuAppStatus.bState = dfuUPLOAD_IDLE;
+ /* record length of first block for calculating target
+ address from wValue in consecutive blocks */
+ uploadBlockLen = pInformation->USBwLengths.w;
+ thisBlockLen = uploadBlockLen; /* for this first block as well */
+ /* calculate where the data should be copied from */
+ userFirmwareLen = uploadBlockLen * pInformation->USBwValue;
+ if (pInformation->Current_AlternateSetting == 1) {
+ userAppAddr = USER_CODE_FLASH;
+ userAppEnd = FLASH_END;
+ } else {
+ userAppAddr = USER_CODE_RAM;
+ userAppEnd = RAM_END;
+ }
+ } else if (pInformation->USBbRequest == DFU_ABORT) {
+ dfuAppStatus.bState = dfuIDLE;
+ dfuAppStatus.bStatus = OK; /* are we really ok? we were just aborted */
+ } else if (pInformation->USBbRequest == DFU_GETSTATUS) {
+ dfuAppStatus.bState = dfuIDLE;
+ } else if (pInformation->USBbRequest == DFU_GETSTATE) {
+ dfuAppStatus.bState = dfuIDLE;
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errSTALLEDPKT;
+ }
+
+ } else if (startState == dfuDNLOAD_SYNC) {
+ /* device received block, waiting for DFU_GETSTATUS request */
+
+ if (pInformation->USBbRequest == DFU_GETSTATUS) {
+ /* todo, add routine to wait for last block write to finish */
+ if (userFlash) {
+ if (code_copy_lock == WAIT) {
+ code_copy_lock = BEGINNING;
+ dfuAppStatus.bwPollTimeout0 = 0x20; /* 32 ms */
+ dfuAppStatus.bwPollTimeout1 = 0x00;
+ dfuAppStatus.bState = dfuDNBUSY;
+
+ } else if (code_copy_lock == BEGINNING) {
+ dfuAppStatus.bState = dfuDNLOAD_SYNC;
+
+ } else if (code_copy_lock == MIDDLE) {
+ dfuAppStatus.bState = dfuDNLOAD_SYNC;
+
+ } else if (code_copy_lock == END) {
+ dfuAppStatus.bwPollTimeout0 = 0x00;
+ code_copy_lock = WAIT;
+ dfuAppStatus.bState = dfuDNLOAD_IDLE;
+ }
+
+ } else {
+ dfuAppStatus.bState = dfuDNLOAD_IDLE;
+ dfuCopyBufferToExec();
+ }
+
+ } else if (pInformation->USBbRequest == DFU_GETSTATE) {
+ dfuAppStatus.bState = dfuDNLOAD_SYNC;
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errSTALLEDPKT;
+ }
+
+ } else if (startState == dfuDNBUSY) {
+ /* if were actually done writing, goto sync, else stay busy */
+ if (code_copy_lock == END) {
+ dfuAppStatus.bwPollTimeout0 = 0x00;
+ code_copy_lock = WAIT;
+ dfuAppStatus.bState = dfuDNLOAD_IDLE;
+ } else {
+ dfuAppStatus.bState = dfuDNBUSY;
+ }
+
+ } else if (startState == dfuDNLOAD_IDLE) {
+ /* device is expecting dfu_dnload requests */
+ if (pInformation->USBbRequest == DFU_DNLOAD) {
+ if (pInformation->USBwLengths.w > 0) {
+ dfuAppStatus.bState = dfuDNLOAD_SYNC;
+ } else {
+ /* todo, support "disagreement" if device expects more data than this */
+ dfuAppStatus.bState = dfuMANIFEST_SYNC;
+
+ /* relock the flash */
+ flashLock();
+ }
+ } else if (pInformation->USBbRequest == DFU_ABORT) {
+ dfuAppStatus.bState = dfuIDLE;
+ } else if (pInformation->USBbRequest == DFU_GETSTATUS) {
+ dfuAppStatus.bState = dfuIDLE;
+ } else if (pInformation->USBbRequest == DFU_GETSTATE) {
+ dfuAppStatus.bState = dfuIDLE;
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errSTALLEDPKT;
+ }
+
+ } else if (startState == dfuMANIFEST_SYNC) {
+ /* device has received last block, waiting DFU_GETSTATUS request */
+
+ if (pInformation->USBbRequest == DFU_GETSTATUS) {
+ dfuAppStatus.bState = dfuMANIFEST_WAIT_RESET;
+ dfuAppStatus.bStatus = OK;
+ } else if (pInformation->USBbRequest == DFU_GETSTATE) {
+ dfuAppStatus.bState = dfuMANIFEST_SYNC;
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errSTALLEDPKT;
+ }
+
+ } else if (startState == dfuMANIFEST) {
+ /* device is in manifestation phase */
+
+ /* should never receive request while in manifest! */
+ dfuAppStatus.bState = dfuMANIFEST_WAIT_RESET;
+ dfuAppStatus.bStatus = OK;
+
+ } else if (startState == dfuMANIFEST_WAIT_RESET) {
+ /* device has programmed new firmware but needs external
+ usb reset or power on reset to run the new code */
+
+ /* consider timing out and self-resetting */
+ dfuAppStatus.bState = dfuMANIFEST_WAIT_RESET;
+
+ } else if (startState == dfuUPLOAD_IDLE) {
+ /* device expecting further dfu_upload requests */
+
+ if (pInformation->USBbRequest == DFU_UPLOAD) {
+ if (pInformation->USBwLengths.w > 0) {
+ /* check that this is not the last possible block */
+ userFirmwareLen = uploadBlockLen * pInformation->USBwValue;
+ if (userAppAddr + userFirmwareLen + uploadBlockLen <= userAppEnd) {
+ thisBlockLen = uploadBlockLen;
+ dfuAppStatus.bState = dfuUPLOAD_IDLE;
+ } else {
+ /* if above comparison was just equal, thisBlockLen becomes zero
+ next time when USBWValue has been increased by one */
+ thisBlockLen = userAppEnd - userAppAddr - userFirmwareLen;
+ /* check for overflow due to USBwValue out of range */
+ if (thisBlockLen >= pInformation->USBwLengths.w) {
+ thisBlockLen = 0;
+ }
+ dfuAppStatus.bState = dfuIDLE;
+ }
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errNOTDONE;
+ }
+ } else if (pInformation->USBbRequest == DFU_ABORT) {
+ dfuAppStatus.bState = dfuIDLE;
+ } else if (pInformation->USBbRequest == DFU_GETSTATUS) {
+ dfuAppStatus.bState = dfuUPLOAD_IDLE;
+ } else if (pInformation->USBbRequest == DFU_GETSTATE) {
+ dfuAppStatus.bState = dfuUPLOAD_IDLE;
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errSTALLEDPKT;
+ }
+
+
+ } else if (startState == dfuERROR) {
+ /* status is in error, awaiting DFU_CLRSTATUS request */
+
+ if (pInformation->USBbRequest == DFU_GETSTATUS) {
+ /* todo, add routine to wait for last block write to finish */
+ dfuAppStatus.bState = dfuERROR;
+ } else if (pInformation->USBbRequest == DFU_GETSTATE) {
+ dfuAppStatus.bState = dfuERROR;
+ } else if (pInformation->USBbRequest == DFU_CLRSTATUS) {
+ /* todo handle any cleanup we need here */
+ dfuAppStatus.bState = dfuIDLE;
+ dfuAppStatus.bStatus = OK;
+ } else {
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errSTALLEDPKT;
+ }
+
+ } else {
+ /* some kind of error... */
+ dfuAppStatus.bState = dfuERROR;
+ dfuAppStatus.bStatus = errSTALLEDPKT;
+ }
+
+ if (dfuAppStatus.bStatus == OK) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+void dfuUpdateByReset(void) {
+ u8 startState = dfuAppStatus.bState;
+ userFirmwareLen = 0;
+
+ if (startState == appDETACH) {
+ dfuAppStatus.bState = dfuIDLE;
+ dfuAppStatus.bStatus = OK;
+
+ nvicDisableInterrupts();
+ usbEnbISR();
+
+ } else if (startState == appIDLE || startState == dfuIDLE) {
+ /* do nothing...might be normal usb bus activity */
+ } else {
+ /* we reset from the dfu, reset everything and startover,
+ which is the correct operation if this is an erroneous
+ event or properly following a MANIFEST */
+ dfuAppStatus.bState = dfuIDLE;
+ dfuAppStatus.bStatus = OK;
+
+ systemHardReset();
+ }
+}
+
+void dfuUpdateByTimeout(void) {
+}
+
+u8 *dfuCopyState(u16 length) {
+ if (length == 0) {
+ pInformation->Ctrl_Info.Usb_wLength = 1;
+ return NULL;
+ } else {
+ return (&(dfuAppStatus.bState));
+ }
+}
+
+u8 *dfuCopyStatus(u16 length) {
+ if (length == 0) {
+ pInformation->Ctrl_Info.Usb_wLength = 6;
+ return NULL;
+ } else {
+ return (u8*)(&dfuAppStatus);
+ }
+}
+
+
+u8 *dfuCopyDNLOAD(u16 length) {
+ if (length == 0) {
+ pInformation->Ctrl_Info.Usb_wLength = pInformation->USBwLengths.w - pInformation->Ctrl_Info.Usb_wOffset;
+ thisBlockLen = pInformation->USBwLengths.w;
+ return NULL;
+ } else {
+ return ((u8 *)recvBuffer + pInformation->Ctrl_Info.Usb_wOffset);
+ }
+}
+
+u8 *dfuCopyUPLOAD(u16 length) {
+ if (length == 0) {
+ pInformation->Ctrl_Info.Usb_wLength = thisBlockLen - pInformation->Ctrl_Info.Usb_wOffset;
+ return NULL;
+ } else {
+ return((u8*) userAppAddr + userFirmwareLen + pInformation->Ctrl_Info.Usb_wOffset);
+ }
+}
+
+void dfuCopyBufferToExec() {
+ int i;
+ u32 *userSpace;
+
+ if (!userFlash) {
+ userSpace = (u32 *)(USER_CODE_RAM + userFirmwareLen);
+ /* we dont need to handle when thisBlock len is not divisible by 4,
+ since the linker will align everything to 4B anyway */
+ for (i = 0; i < thisBlockLen; i = i + 4) {
+ *userSpace++ = *(u32 *)(recvBuffer + i);
+ }
+ } else {
+ userSpace = (u32 *)(USER_CODE_FLASH + userFirmwareLen);
+
+ flashErasePage((u32)(userSpace));
+
+ for (i = 0; i < thisBlockLen; i = i + 4) {
+ flashWriteWord((u32)(userSpace++), *(u32 *)(recvBuffer +i));
+ }
+
+ }
+ userFirmwareLen += thisBlockLen;
+
+ thisBlockLen = 0;
+}
+
+u8 dfuGetState(void) {
+ return dfuAppStatus.bState;
+}
+
+void dfuSetState(u8 newState) {
+ dfuAppStatus.bState = newState;
+}
+
+bool dfuUploadStarted() {
+ return dfuBusy;
+}
+
+void dfuFinishUpload() {
+ while (1) {
+ if (userFlash) {
+ if (code_copy_lock == BEGINNING) {
+ code_copy_lock = MIDDLE;
+ strobePin(LED_BANK, LED, 2, 0x1000);
+ dfuCopyBufferToExec();
+ strobePin(LED_BANK, LED, 2, 0x500);
+ code_copy_lock = END;
+ }
+ }
+ /* otherwise do nothing, dfu state machine resets itself */
+ }
+}
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/dfu.h b/Arduino_STM32-MIDI/other/maple-bootloader/dfu.h
new file mode 100755
index 0000000..4ebd0b3
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/dfu.h
@@ -0,0 +1,121 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+#ifndef __DFU_H
+#define __DFU_H
+
+#include "common.h"
+
+/* exposed types */
+typedef u8 *(*ClassReqCB)(u16);
+
+/* exposed structs */
+typedef struct _DFUStatus {
+ u8 bStatus;
+ u8 bwPollTimeout0;
+ u8 bwPollTimeout1;
+ u8 bwPollTimeout2;
+ u8 bState; /* state of device at the time the host receives the message! */
+ u8 iString;
+} DFUStatus;
+
+typedef enum _PLOT {
+ BEGINNING,
+ MIDDLE,
+ END,
+ WAIT
+} PLOT;
+
+
+/*** DFU bRequest Values ******/
+/* bmRequestType, wValue, wIndex, wLength, Data */
+#define DFU_DETACH 0x00 /* 0x21, wTimeout, Interface, Zero, None */
+#define DFU_DNLOAD 0x01 /* 0x21, wBlockNum, Interface, Length, Firmware */
+#define DFU_UPLOAD 0x02 /* 0xA1, Zero, Interface, Length, Firmware */
+#define DFU_GETSTATUS 0x03 /* 0xA1, Zero, Interface, 6, Status */
+#define DFU_CLRSTATUS 0x04 /* 0x21, Zero, Interface, Zero, None */
+#define DFU_GETSTATE 0x05 /* 0xA1, Zero, Interface, 1, State */
+#define DFU_ABORT 0x06 /* 0x21, Zero, Interface, Zero, None */
+
+/*** DFU Status Values ******/
+#define OK 0x00 /* No error */
+#define errTARGET 0x01 /* File is not appropriate for this device */
+#define errFILE 0x02 /* File fails some vendor tests */
+#define errWRITE 0x03 /* Device is unable to write memory */
+#define errERASE 0x04 /* Memory erase failed */
+#define errCHECK_ERASED 0x05 /* Memory erase check failed */
+#define errPROG 0x06 /* Program memory function failed */
+#define errVERIFY 0x07 /* Written program failed verification */
+#define errADDRESS 0x08 /* address out of range */
+#define errNOTDONE 0x09 /* received DNLOAD with wLength=0, but firmware seems incomplete */
+#define errFIRMWARE 0x0A /* Runtime firmware corrupt, cannot return to non-dfu operations! */
+#define errVENDOR 0x0B /* vendor specific error */
+#define errUSBR 0x0C /* Unexpected usb reset! */
+#define errPOR 0x0D /* Unexpected power on reset */
+#define errUNKNOWN 0x0E /* Unknown error */
+#define errSTALLEDPKT 0x0F /* device stalled unexpected request */
+/***************************/
+
+/*** DFU State Values **************/
+#define appIDLE 0x00
+#define appDETACH 0x01
+#define dfuIDLE 0x02
+#define dfuDNLOAD_SYNC 0x03
+#define dfuDNBUSY 0x04
+#define dfuDNLOAD_IDLE 0x05
+#define dfuMANIFEST_SYNC 0x06
+#define dfuMANIFEST 0x07
+#define dfuMANIFEST_WAIT_RESET 0x08
+#define dfuUPLOAD_IDLE 0x09
+#define dfuERROR 0x0A
+/***********************************/
+
+
+
+extern volatile bool dfuBusy;
+
+/* exposed functions */
+void dfuInit(void); /* singleton dfu initializer */
+
+/* should consume dfuEvent type, but for now we can use pInfo (see comment above) */
+bool dfuUpdateByRequest(void); /* returns if new status is OK */
+void dfuUpdateByReset(void);
+void dfuUpdateByTimeout(void);
+
+/* usb callbacks */
+u8 *dfuCopyState(u16);
+u8 *dfuCopyStatus(u16);
+u8 *dfuCopyDNLOAD(u16);
+u8 *dfuCopyUPLOAD(u16);
+
+void dfuCopyBufferToExec(void);
+bool checkTestFile(void);
+
+u8 dfuGetState(void);
+void dfuSetState(u8);
+bool dfuUploadStarted();
+void dfuFinishUpload();
+
+
+#endif
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/flash/debug.cfg b/Arduino_STM32-MIDI/other/maple-bootloader/flash/debug.cfg
new file mode 100755
index 0000000..bf2e4d6
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/flash/debug.cfg
@@ -0,0 +1,83 @@
+# script for stm32
+
+interface ft2232
+ft2232_device_desc "Olimex OpenOCD JTAG"
+ft2232_layout olimex-jtag
+ft2232_vid_pid 0x15ba 0x0003
+
+if { [info exists CHIPNAME] } {
+ set _CHIPNAME $CHIPNAME
+} else {
+ set _CHIPNAME stm32
+}
+
+if { [info exists ENDIAN] } {
+ set _ENDIAN $ENDIAN
+} else {
+ set _ENDIAN little
+}
+
+# jtag speed
+jtag_khz 600
+
+#use combined on interfaces or targets that can't set TRST/SRST separately
+reset_config trst_and_srst
+
+#jtag scan chain
+if { [info exists CPUTAPID ] } {
+ set _CPUTAPID $CPUTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.3
+ set _CPUTAPID 0x3ba00477
+}
+jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
+
+if { [info exists BSTAPID ] } {
+ set _BSTAPID $BSTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.2
+ # Medium Density RevA
+ set _BSTAPID 0x06410041
+ # Rev B and Rev Z
+ set _BSTAPID 0x16410041
+ # High Density Devices, Rev A
+#set _BSTAPID 0x06414041
+}
+jtag newtap $_CHIPNAME bs -irlen 5 -ircapture 0x1 -irmask 0x1 -expected-id $_BSTAPID
+
+set _TARGETNAME [format "%s.cpu" $_CHIPNAME]
+target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME
+
+$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 0x5000 -work-area-backup 0
+#$_TARGETNAME configure -event halted halt_handle
+
+#flash bank stm32x 0 0 0 0 0
+
+
+#target create cortex_m3 -endian little
+#run_and_halt_time 0 30
+
+#working_area 0 0x20000000 0x4000 nobackup
+
+flash bank stm32x 0x08000000 0x00010000 0 0 0
+
+# For more information about the configuration files, take a look at:
+# openocd.texi
+
+#script flash.script
+
+proc halt_handle {} {
+ resume
+}
+
+proc flash_test {} {
+ puts "Entering DEBUG wait"
+ sleep 100
+# reset run
+# sleep 500
+}
+
+init
+flash_test
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/flash/flash.cfg b/Arduino_STM32-MIDI/other/maple-bootloader/flash/flash.cfg
new file mode 100755
index 0000000..dff972c
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/flash/flash.cfg
@@ -0,0 +1,91 @@
+# script for stm32
+
+interface ft2232
+ft2232_device_desc "Olimex OpenOCD JTAG"
+ft2232_layout olimex-jtag
+ft2232_vid_pid 0x15ba 0x0003
+
+if { [info exists CHIPNAME] } {
+ set _CHIPNAME $CHIPNAME
+} else {
+ set _CHIPNAME stm32
+}
+
+if { [info exists ENDIAN] } {
+ set _ENDIAN $ENDIAN
+} else {
+ set _ENDIAN little
+}
+
+# jtag speed
+jtag_khz 600
+
+#use combined on interfaces or targets that can't set TRST/SRST separately
+reset_config trst_and_srst
+
+#jtag scan chain
+if { [info exists CPUTAPID ] } {
+ set _CPUTAPID $CPUTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.3
+ set _CPUTAPID 0x3ba00477
+}
+jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
+
+if { [info exists BSTAPID ] } {
+ set _BSTAPID $BSTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.2
+ # Medium Density RevA
+ set _BSTAPID 0x06410041
+ # Rev B and Rev Z
+ set _BSTAPID 0x16410041
+ # High Density Devices, Rev A
+#set _BSTAPID 0x06414041
+}
+jtag newtap $_CHIPNAME bs -irlen 5 -ircapture 0x1 -irmask 0x1 -expected-id $_BSTAPID
+
+set _TARGETNAME [format "%s.cpu" $_CHIPNAME]
+target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME
+
+$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 0x5000 -work-area-backup 0
+#$_TARGETNAME configure -event halted halt_handle
+
+#flash bank stm32x 0 0 0 0 0
+
+
+#target create cortex_m3 -endian little
+#run_and_halt_time 0 30
+
+#working_area 0 0x20000000 0x4000 nobackup
+
+flash bank stm32x 0x08000000 0x00010000 0 0 0
+
+# For more information about the configuration files, take a look at:
+# openocd.texi
+
+#script flash.script
+
+proc halt_handle {} {
+ resume
+}
+
+proc flash_test {} {
+ puts "Trying to flash"
+ sleep 100
+ halt
+ sleep 300
+ stm32x mass_erase 0
+ sleep 20
+ flash write_bank 0 tmpflash.bin 0
+ sleep 50
+# reset run
+# sleep 500
+ reset run
+ shutdown
+}
+
+init
+flash_test
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/flash/openocd.cfg b/Arduino_STM32-MIDI/other/maple-bootloader/flash/openocd.cfg
new file mode 100755
index 0000000..c343de6
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/flash/openocd.cfg
@@ -0,0 +1,73 @@
+# script for stm32
+
+interface ft2232
+ft2232_device_desc "Olimex OpenOCD JTAG"
+ft2232_layout olimex-jtag
+ft2232_vid_pid 0x15ba 0x0003
+
+if { [info exists CHIPNAME] } {
+ set _CHIPNAME $CHIPNAME
+} else {
+ set _CHIPNAME stm32
+}
+
+if { [info exists ENDIAN] } {
+ set _ENDIAN $ENDIAN
+} else {
+ set _ENDIAN little
+}
+
+# jtag speed
+jtag_khz 500
+
+jtag_nsrst_delay 200
+jtag_ntrst_delay 200
+
+#use combined on interfaces or targets that can't set TRST/SRST separately
+reset_config trst_and_srst
+
+#jtag scan chain
+if { [info exists CPUTAPID ] } {
+ set _CPUTAPID $CPUTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.3
+ set _CPUTAPID 0x3ba00477
+}
+
+jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
+
+if { [info exists BSTAPID ] } {
+ set _BSTAPID $BSTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.2
+ # Medium Density RevA
+ set _BSTAPID 0x06410041
+ # Rev B and Rev Z
+ set _BSTAPID 0x16410041
+ # High Density Devices, Rev A
+#set _BSTAPID 0x06414041
+}
+
+jtag newtap $_CHIPNAME bs -irlen 5 -ircapture 0x1 -irmask 0x1 -expected-id $_BSTAPID
+
+set _TARGETNAME [format "%s.cpu" $_CHIPNAME]
+target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME
+
+$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 0x5000 -work-area-backup 0
+
+flash bank stm32x 0x08000000 0x00010000 0 0 0
+
+init
+
+halt
+sleep 1000
+stm32x unlock 0
+flash erase_sector 0 0 0
+sleep 1000
+flash write_bank 0 tmpflash.bin 0
+sleep 3000
+reset
+sleep 3000
+shutdown
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/flash/stm32.cfg b/Arduino_STM32-MIDI/other/maple-bootloader/flash/stm32.cfg
new file mode 100755
index 0000000..15edaad
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/flash/stm32.cfg
@@ -0,0 +1,72 @@
+# script for stm32
+
+interface ft2232
+ft2232_device_desc "Olimex OpenOCD JTAG"
+ft2232_layout olimex-jtag
+ft2232_vid_pid 0x15ba 0x0003
+
+if { [info exists CHIPNAME] } {
+ set _CHIPNAME $CHIPNAME
+} else {
+ set _CHIPNAME stm32
+}
+
+if { [info exists ENDIAN] } {
+ set _ENDIAN $ENDIAN
+} else {
+ set _ENDIAN little
+}
+
+# jtag speed
+jtag_khz 500
+
+jtag_nsrst_delay 100
+jtag_ntrst_delay 100
+
+#use combined on interfaces or targets that can't set TRST/SRST separately
+reset_config trst_and_srst
+
+#jtag scan chain
+if { [info exists CPUTAPID ] } {
+ set _CPUTAPID $CPUTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.3
+ set _CPUTAPID 0x3ba00477
+}
+jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
+
+if { [info exists BSTAPID ] } {
+ set _BSTAPID $BSTAPID
+} else {
+ # See STM Document RM0008
+ # Section 26.6.2
+ # Medium Density RevA
+ set _BSTAPID 0x06410041
+ # Rev B and Rev Z
+ set _BSTAPID 0x16410041
+ # High Density Devices, Rev A
+#set _BSTAPID 0x06414041
+}
+jtag newtap $_CHIPNAME bs -irlen 5 -ircapture 0x1 -irmask 0x1 -expected-id $_BSTAPID
+
+set _TARGETNAME [format "%s.cpu" $_CHIPNAME]
+target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME
+
+$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 16384 -work-area-backup 0
+
+#flash bank stm32x 0 0 0 0 0
+
+
+target create cortex_m3 -endian little
+#run_and_halt_time 0 30
+
+#working_area 0 0x20000000 0x4000 nobackup
+
+#flash bank stm32x 0x08000000 0x00010000 0 0 0
+reset
+sleep 3000
+shutdown
+# For more information about the configuration files, take a look at:
+# openocd.texi
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/flash/stm32loader.py b/Arduino_STM32-MIDI/other/maple-bootloader/flash/stm32loader.py
new file mode 100755
index 0000000..67ab8d2
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/flash/stm32loader.py
@@ -0,0 +1,435 @@
+#!/usr/bin/env python
+
+# -*- coding: utf-8 -*-
+# vim: sw=4:ts=4:si:et:enc=utf-8
+
+# Author: Ivan A-R <ivan@tuxotronic.org>
+# Project page: http://tuxotronic.org/wiki/projects/stm32loader
+#
+# This file is part of stm32loader.
+#
+# stm32loader 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 3, or (at your option) any later
+# version.
+#
+# stm32loader 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 stm32loader; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+import sys, getopt
+import serial
+import time
+
+try:
+ from progressbar import *
+ usepbar = 1
+except:
+ usepbar = 0
+
+# Verbose level
+QUIET = 20
+
+def mdebug(level, message):
+ if(QUIET >= level):
+ print >> sys.stderr , message
+
+
+class CmdException(Exception):
+ pass
+
+class CommandInterface:
+ def open(self, aport='/dev/tty.usbserial-FTD3TMCH', abaudrate=115200) :
+ self.sp = serial.Serial(
+ port=aport,
+ baudrate=abaudrate, # baudrate
+ bytesize=8, # number of databits
+ parity=serial.PARITY_EVEN,
+ stopbits=1,
+ xonxoff=0, # enable software flow control
+ rtscts=0, # disable RTS/CTS flow control
+ timeout=5 # set a timeout value, None for waiting forever
+ )
+
+
+ def _wait_for_ask(self, info = ""):
+ # wait for ask
+ try:
+ ask = ord(self.sp.read())
+ except:
+ raise CmdException("Can't read port or timeout")
+ else:
+ if ask == 0x79:
+ # ACK
+ return 1
+ else:
+ if ask == 0x1F:
+ # NACK
+ raise CmdException("NACK "+info)
+ else:
+ # Unknow responce
+ raise CmdException("Unknow response. "+info+": "+hex(ask))
+
+
+ def reset(self):
+ self.sp.setDTR(0)
+ time.sleep(0.1)
+ self.sp.setDTR(1)
+ time.sleep(0.5)
+
+ def initChip(self):
+ # Set boot
+ self.sp.setRTS(0)
+ self.reset()
+
+ self.sp.write("\x7F") # Syncro
+ return self._wait_for_ask("Syncro")
+
+ def releaseChip(self):
+ self.sp.setRTS(1)
+ self.reset()
+
+ def cmdGeneric(self, cmd):
+ self.sp.write(chr(cmd))
+ self.sp.write(chr(cmd ^ 0xFF)) # Control byte
+ return self._wait_for_ask(hex(cmd))
+
+ def cmdGet(self):
+ if self.cmdGeneric(0x00):
+ mdebug(10, "*** Get command");
+ len = ord(self.sp.read())
+ version = ord(self.sp.read())
+ mdebug(10, " Bootloader version: "+hex(version))
+ dat = map(lambda c: hex(ord(c)), self.sp.read(len))
+ mdebug(10, " Available commands: "+str(dat))
+ self._wait_for_ask("0x00 end")
+ return version
+ else:
+ raise CmdException("Get (0x00) failed")
+
+ def cmdGetVersion(self):
+ if self.cmdGeneric(0x01):
+ mdebug(10, "*** GetVersion command")
+ version = ord(self.sp.read())
+ self.sp.read(2)
+ self._wait_for_ask("0x01 end")
+ mdebug(10, " Bootloader version: "+hex(version))
+ return version
+ else:
+ raise CmdException("GetVersion (0x01) failed")
+
+ def cmdGetID(self):
+ if self.cmdGeneric(0x02):
+ mdebug(10, "*** GetID command")
+ len = ord(self.sp.read())
+ id = self.sp.read(len+1)
+ self._wait_for_ask("0x02 end")
+ return id
+ else:
+ raise CmdException("GetID (0x02) failed")
+
+
+ def _encode_addr(self, addr):
+ byte3 = (addr >> 0) & 0xFF
+ byte2 = (addr >> 8) & 0xFF
+ byte1 = (addr >> 16) & 0xFF
+ byte0 = (addr >> 24) & 0xFF
+ crc = byte0 ^ byte1 ^ byte2 ^ byte3
+ return (chr(byte0) + chr(byte1) + chr(byte2) + chr(byte3) + chr(crc))
+
+
+ def cmdReadMemory(self, addr, lng):
+ assert(lng <= 256)
+ if self.cmdGeneric(0x11):
+ mdebug(10, "*** ReadMemory command")
+ self.sp.write(self._encode_addr(addr))
+ self._wait_for_ask("0x11 address failed")
+ N = (lng - 1) & 0xFF
+ crc = N ^ 0xFF
+ self.sp.write(chr(N) + chr(crc))
+ self._wait_for_ask("0x11 length failed")
+ return map(lambda c: ord(c), self.sp.read(lng))
+ else:
+ raise CmdException("ReadMemory (0x11) failed")
+
+
+ def cmdGo(self, addr):
+ if self.cmdGeneric(0x21):
+ mdebug(10, "*** Go command")
+ self.sp.write(self._encode_addr(addr))
+ self._wait_for_ask("0x21 go failed")
+ else:
+ raise CmdException("Go (0x21) failed")
+
+
+ def cmdWriteMemory(self, addr, data):
+ assert(len(data) <= 256)
+ if self.cmdGeneric(0x31):
+ mdebug(10, "*** Write memory command")
+ self.sp.write(self._encode_addr(addr))
+ self._wait_for_ask("0x31 address failed")
+ #map(lambda c: hex(ord(c)), data)
+ lng = (len(data)-1) & 0xFF
+ mdebug(10, " %s bytes to write" % [lng+1]);
+ self.sp.write(chr(lng)) # len really
+ crc = 0xFF
+ for c in data:
+ crc = crc ^ c
+ self.sp.write(chr(c))
+ self.sp.write(chr(crc))
+ self._wait_for_ask("0x31 programming failed")
+ mdebug(10, " Write memory done")
+ else:
+ raise CmdException("Write memory (0x31) failed")
+
+
+ def cmdEraseMemory(self, sectors = None):
+ if self.cmdGeneric(0x43):
+ mdebug(10, "*** Erase memory command")
+ if sectors is None:
+ # Global erase
+ self.sp.write(chr(0xFF))
+ self.sp.write(chr(0x00))
+ else:
+ # Sectors erase
+ self.sp.write(chr((len(sectors)-1) & 0xFF))
+ crc = 0xFF
+ for c in sectors:
+ crc = crc ^ c
+ self.sp.write(chr(c))
+ self.sp.write(chr(crc))
+ self._wait_for_ask("0x43 erasing failed")
+ mdebug(10, " Erase memory done")
+ else:
+ raise CmdException("Erase memory (0x43) failed")
+
+ def cmdWriteProtect(self, sectors):
+ if self.cmdGeneric(0x63):
+ mdebug(10, "*** Write protect command")
+ self.sp.write(chr((len(sectors)-1) & 0xFF))
+ crc = 0xFF
+ for c in sectors:
+ crc = crc ^ c
+ self.sp.write(chr(c))
+ self.sp.write(chr(crc))
+ self._wait_for_ask("0x63 write protect failed")
+ mdebug(10, " Write protect done")
+ else:
+ raise CmdException("Write Protect memory (0x63) failed")
+
+ def cmdWriteUnprotect(self):
+ if self.cmdGeneric(0x73):
+ mdebug(10, "*** Write Unprotect command")
+ self._wait_for_ask("0x73 write unprotect failed")
+ self._wait_for_ask("0x73 write unprotect 2 failed")
+ mdebug(10, " Write Unprotect done")
+ else:
+ raise CmdException("Write Unprotect (0x73) failed")
+
+ def cmdReadoutProtect(self):
+ if self.cmdGeneric(0x82):
+ mdebug(10, "*** Readout protect command")
+ self._wait_for_ask("0x82 readout protect failed")
+ self._wait_for_ask("0x82 readout protect 2 failed")
+ mdebug(10, " Read protect done")
+ else:
+ raise CmdException("Readout protect (0x82) failed")
+
+ def cmdReadoutUnprotect(self):
+ if self.cmdGeneric(0x92):
+ mdebug(10, "*** Readout Unprotect command")
+ self._wait_for_ask("0x92 readout unprotect failed")
+ self._wait_for_ask("0x92 readout unprotect 2 failed")
+ mdebug(10, " Read Unprotect done")
+ else:
+ raise CmdException("Readout unprotect (0x92) failed")
+
+
+# Complex commands section
+
+ def readMemory(self, addr, lng):
+ data = []
+ if usepbar:
+ widgets = ['Reading: ', Percentage(),', ', ETA(), ' ', Bar()]
+ pbar = ProgressBar(widgets=widgets,maxval=lng, term_width=79).start()
+
+ while lng > 256:
+ if usepbar:
+ pbar.update(pbar.maxval-lng)
+ else:
+ mdebug(5, "Read %(len)d bytes at 0x%(addr)X" % {'addr': addr, 'len': 256})
+ data = data + self.cmdReadMemory(addr, 256)
+ addr = addr + 256
+ lng = lng - 256
+ if usepbar:
+ pbar.update(pbar.maxval-lng)
+ pbar.finish()
+ else:
+ mdebug(5, "Read %(len)d bytes at 0x%(addr)X" % {'addr': addr, 'len': 256})
+ data = data + self.cmdReadMemory(addr, lng)
+ return data
+
+ def writeMemory(self, addr, data):
+ lng = len(data)
+ if usepbar:
+ widgets = ['Writing: ', Percentage(),' ', ETA(), ' ', Bar()]
+ pbar = ProgressBar(widgets=widgets, maxval=lng, term_width=79).start()
+
+ offs = 0
+ while lng > 256:
+ if usepbar:
+ pbar.update(pbar.maxval-lng)
+ else:
+ mdebug(5, "Write %(len)d bytes at 0x%(addr)X" % {'addr': addr, 'len': 256})
+ self.cmdWriteMemory(addr, data[offs:offs+256])
+ offs = offs + 256
+ addr = addr + 256
+ lng = lng - 256
+ if usepbar:
+ pbar.update(pbar.maxval-lng)
+ pbar.finish()
+ else:
+ mdebug(5, "Write %(len)d bytes at 0x%(addr)X" % {'addr': addr, 'len': 256})
+ self.cmdWriteMemory(addr, data[offs:offs+lng] + ([0xFF] * (256-lng)) )
+
+
+
+
+ def __init__(self) :
+ pass
+
+
+def usage():
+ print """Usage: %s [-hqVewvr] [-l length] [-p port] [-b baud] [-a addr] [file.bin]
+ -h This help
+ -q Quiet
+ -V Verbose
+ -e Erase
+ -w Write
+ -v Verify
+ -r Read
+ -l length Length of read
+ -p port Serial port (default: /dev/tty.usbserial-ftCYPMYJ)
+ -b baud Baud speed (default: 115200)
+ -a addr Target address
+
+ ./stm32loader.py -e -w -v example/main.bin
+
+ """ % sys.argv[0]
+
+
+if __name__ == "__main__":
+
+ # Import Psyco if available
+ try:
+ import psyco
+ psyco.full()
+ print "Using Psyco..."
+ except ImportError:
+ pass
+
+ conf = {
+ 'port': '/dev/tty.usbserial-FTD3TMCH',
+ 'baud': 115200,
+ 'address': 0x08000000,
+ 'erase': 0,
+ 'write': 0,
+ 'verify': 0,
+ 'read': 0,
+ 'len': 1000,
+ 'fname':'',
+ }
+
+# http://www.python.org/doc/2.5.2/lib/module-getopt.html
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "hqVewvrp:b:a:l:")
+ except getopt.GetoptError, err:
+ # print help information and exit:
+ print str(err) # will print something like "option -a not recognized"
+ usage()
+ sys.exit(2)
+
+ QUIET = 5
+
+ for o, a in opts:
+ if o == '-V':
+ QUIET = 10
+ elif o == '-q':
+ QUIET = 0
+ elif o == '-h':
+ usage()
+ sys.exit(0)
+ elif o == '-e':
+ conf['erase'] = 1
+ elif o == '-w':
+ conf['write'] = 1
+ elif o == '-v':
+ conf['verify'] = 1
+ elif o == '-r':
+ conf['read'] = 1
+ elif o == '-p':
+ conf['port'] = a
+ elif o == '-b':
+ conf['baud'] = eval(a)
+ elif o == '-a':
+ conf['address'] = eval(a)
+ elif o == '-l':
+ conf['len'] = eval(a)
+# elif o == '-f':
+# conf['fname'] = a
+ else:
+ assert False, "unhandled option"
+
+ cmd = CommandInterface()
+ cmd.open(conf['port'], conf['baud'])
+ mdebug(10, "Open port %(port)s, baud %(baud)d" % {'port':conf['port'], 'baud':conf['baud']})
+ try:
+ try:
+ cmd.initChip()
+ except:
+ print "Can't init. Ensure that BOOT0 is enabled and reset device"
+
+ bootversion = cmd.cmdGet()
+ mdebug(0, "Bootloader version %X" % bootversion)
+ mdebug(0, "Chip id `%s'" % str(map(lambda c: hex(ord(c)), cmd.cmdGetID())))
+# cmd.cmdGetVersion()
+# cmd.cmdGetID()
+# cmd.cmdReadoutUnprotect()
+# cmd.cmdWriteUnprotect()
+# cmd.cmdWriteProtect([0, 1])
+
+ if (conf['write'] or conf['verify']):
+ data = map(lambda c: ord(c), file(args[0]).read())
+
+ if conf['erase']:
+ cmd.cmdEraseMemory()
+
+ if conf['write']:
+ cmd.writeMemory(conf['address'], data)
+
+ if conf['verify']:
+ verify = cmd.readMemory(conf['address'], len(data))
+ if(data == verify):
+ print "Verification OK"
+ else:
+ print "Verification FAILED"
+ print str(len(data)) + ' vs ' + str(len(verify))
+ for i in xrange(0, len(data)):
+ if data[i] != verify[i]:
+ print hex(i) + ': ' + hex(data[i]) + ' vs ' + hex(verify[i])
+
+ if not conf['write'] and conf['read']:
+ rdata = cmd.readMemory(conf['address'], conf['len'])
+# file(conf['fname'], 'wb').write(rdata)
+ file(args[0], 'wb').write(''.join(map(chr,rdata)))
+
+# cmd.cmdGo(addr + 0x04)
+ finally:
+ cmd.releaseChip()
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/hardware.c b/Arduino_STM32-MIDI/other/maple-bootloader/hardware.c
new file mode 100755
index 0000000..aaa139e
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/hardware.c
@@ -0,0 +1,304 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @file hardware.c
+ *
+ * @brief init routines to setup clocks, interrupts, also destructor functions.
+ * does not include USB stuff. EEPROM read/write functions.
+ *
+ */
+
+#include "hardware.h"
+
+void setPin(u32 bank, u8 pin) {
+ u32 pinMask = 0x1 << (pin);
+ SET_REG(GPIO_BSRR(bank), pinMask);
+}
+
+void resetPin(u32 bank, u8 pin) {
+ u32 pinMask = 0x1 << (16 + pin);
+ SET_REG(GPIO_BSRR(bank), pinMask);
+}
+
+bool readPin(u32 bank, u8 pin) {
+ // todo, implement read
+ if (GET_REG(GPIO_IDR(bank)) & (0x01 << pin)) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+void strobePin(u32 bank, u8 pin, u8 count, u32 rate) {
+ resetPin(bank, pin);
+
+ u32 c;
+ while (count-- > 0) {
+ for (c = rate; c > 0; c--) {
+ asm volatile("nop");
+ }
+ setPin(bank, pin);
+ for (c = rate; c > 0; c--) {
+ asm volatile("nop");
+ }
+ resetPin(bank, pin);
+ }
+}
+
+void systemReset(void) {
+ SET_REG(RCC_CR, GET_REG(RCC_CR) | 0x00000001);
+ SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xF8FF0000);
+ SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFEF6FFFF);
+ SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFFFBFFFF);
+ SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xFF80FFFF);
+
+ SET_REG(RCC_CIR, 0x00000000); /* disable all RCC interrupts */
+}
+
+void setupCLK(void) {
+ /* enable HSE */
+ SET_REG(RCC_CR, GET_REG(RCC_CR) | 0x00010001);
+ while ((GET_REG(RCC_CR) & 0x00020000) == 0); /* for it to come on */
+
+ /* enable flash prefetch buffer */
+ SET_REG(FLASH_ACR, 0x00000012);
+
+ /* Configure PLL */
+ SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001D0400); /* pll=72Mhz,APB1=36Mhz,AHB=72Mhz */
+ SET_REG(RCC_CR, GET_REG(RCC_CR) | 0x01000000); /* enable the pll */
+ while ((GET_REG(RCC_CR) & 0x03000000) == 0); /* wait for it to come on */
+
+ /* Set SYSCLK as PLL */
+ SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x00000002);
+ while ((GET_REG(RCC_CFGR) & 0x00000008) == 0); /* wait for it to come on */
+}
+
+void setupLED(void) {
+ // todo, swap out hardcoded pin/bank with macro
+ u32 rwmVal; /* read-write-modify place holder var */
+
+ /* Setup APB2 (GPIOB) */
+ rwmVal = GET_REG(RCC_APB2ENR);
+ rwmVal |= 0x00000008;
+ SET_REG(RCC_APB2ENR, rwmVal);
+
+ /* Setup GPIOB Pin 1 as PP Out */
+ SET_REG(GPIO_CRL(GPIOB), 0x00000010);
+
+ rwmVal = GET_REG(GPIO_CRL(GPIOB));
+ rwmVal &= 0xFFFFFF0F;
+ rwmVal |= 0x00000010;
+ SET_REG(GPIO_CRL(GPIOB), rwmVal);
+
+ setPin(GPIOB, 1);
+}
+
+void setupBUTTON(void) {
+ // todo, swap out hardcoded pin/bank with macro
+ u32 rwmVal; /* read-write-modify place holder var */
+
+ /* Setup APB2 (GPIOB) */
+ rwmVal = GET_REG(RCC_APB2ENR);
+ rwmVal |= 0x00000008;
+ SET_REG(RCC_APB2ENR, rwmVal);
+
+ /* Setup GPIOB Pin 8 as PP Out */
+ rwmVal = GET_REG(GPIO_CRH(GPIOB));
+ rwmVal &= 0xFFFFFFF0;
+ rwmVal |= 0x00000004;
+ SET_REG(GPIO_CRH(GPIOB), rwmVal);
+
+}
+
+void setupFLASH() {
+ /* configure the HSI oscillator */
+ if ((pRCC->CR & 0x01) == 0x00) {
+ u32 rwmVal = pRCC->CR;
+ rwmVal |= 0x01;
+ pRCC->CR = rwmVal;
+ }
+
+ /* wait for it to come on */
+ while ((pRCC->CR & 0x02) == 0x00) {}
+}
+
+bool checkUserCode(u32 usrAddr) {
+ u32 sp = *(vu32 *) usrAddr;
+
+ if ((sp & 0x2FFE0000) == 0x20000000) {
+ return (TRUE);
+ } else {
+ return (FALSE);
+ }
+}
+
+void jumpToUser(u32 usrAddr) {
+ typedef void (*funcPtr)(void);
+
+ u32 jumpAddr = *(vu32 *)(usrAddr + 0x04); /* reset ptr in vector table */
+ funcPtr usrMain = (funcPtr) jumpAddr;
+
+ /* tear down all the dfu related setup */
+ // disable usb interrupts, clear them, turn off usb, set the disc pin
+ // todo pick exactly what we want to do here, now its just a conservative
+ flashLock();
+ usbDsbISR();
+ nvicDisableInterrupts();
+ setPin(GPIOB, 9); // disconnect usb from host. todo, macroize pin
+ systemReset(); // resets clocks and periphs, not core regs
+
+
+ __MSR_MSP(*(vu32 *) usrAddr); /* set the users stack ptr */
+
+ usrMain(); /* go! */
+}
+
+void nvicInit(NVIC_InitTypeDef *NVIC_InitStruct) {
+ u32 tmppriority = 0x00;
+ u32 tmpreg = 0x00;
+ u32 tmpmask = 0x00;
+ u32 tmppre = 0;
+ u32 tmpsub = 0x0F;
+
+ SCB_TypeDef *rSCB = (SCB_TypeDef *) SCB_BASE;
+ NVIC_TypeDef *rNVIC = (NVIC_TypeDef *) NVIC_BASE;
+
+
+ /* Compute the Corresponding IRQ Priority --------------------------------*/
+ tmppriority = (0x700 - (rSCB->AIRCR & (u32)0x700)) >> 0x08;
+ tmppre = (0x4 - tmppriority);
+ tmpsub = tmpsub >> tmppriority;
+
+ tmppriority = (u32)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
+ tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
+
+ tmppriority = tmppriority << 0x04;
+ tmppriority = ((u32)tmppriority) << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
+
+ tmpreg = rNVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)];
+ tmpmask = (u32)0xFF << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
+ tmpreg &= ~tmpmask;
+ tmppriority &= tmpmask;
+ tmpreg |= tmppriority;
+
+ rNVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg;
+
+ /* Enable the Selected IRQ Channels --------------------------------------*/
+ rNVIC->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
+ (u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
+}
+
+void nvicDisableInterrupts() {
+ NVIC_TypeDef *rNVIC = (NVIC_TypeDef *) NVIC_BASE;
+ rNVIC->ICER[0] = 0xFFFFFFFF;
+ rNVIC->ICER[1] = 0xFFFFFFFF;
+ rNVIC->ICPR[0] = 0xFFFFFFFF;
+ rNVIC->ICPR[1] = 0xFFFFFFFF;
+
+ SET_REG(STK_CTRL, 0x04); /* disable the systick, which operates separately from nvic */
+}
+
+void systemHardReset(void) {
+ SCB_TypeDef *rSCB = (SCB_TypeDef *) SCB_BASE;
+
+ /* Reset */
+ rSCB->AIRCR = (u32)AIRCR_RESET_REQ;
+
+ /* should never get here */
+ while (1) {
+ asm volatile("nop");
+ }
+}
+
+bool flashErasePage(u32 pageAddr) {
+ u32 rwmVal = GET_REG(FLASH_CR);
+ rwmVal = FLASH_CR_PER;
+ SET_REG(FLASH_CR, rwmVal);
+
+ while (GET_REG(FLASH_SR) & FLASH_SR_BSY) {}
+ SET_REG(FLASH_AR, pageAddr);
+ SET_REG(FLASH_CR, FLASH_CR_START | FLASH_CR_PER);
+ while (GET_REG(FLASH_SR) & FLASH_SR_BSY) {}
+
+ /* todo: verify the page was erased */
+
+ rwmVal = 0x00;
+ SET_REG(FLASH_CR, rwmVal);
+
+ return TRUE;
+}
+bool flashErasePages(u32 pageAddr, u16 n) {
+ while (n-- > 0) {
+ if (!flashErasePage(pageAddr + 0x400 * n)) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+bool flashWriteWord(u32 addr, u32 word) {
+ vu16 *flashAddr = (vu16 *)addr;
+ vu32 lhWord = (vu32)word & 0x0000FFFF;
+ vu32 hhWord = ((vu32)word & 0xFFFF0000) >> 16;
+
+ u32 rwmVal = GET_REG(FLASH_CR);
+ SET_REG(FLASH_CR, FLASH_CR_PG);
+
+ /* apparently we need not write to FLASH_AR and can
+ simply do a native write of a half word */
+ while (GET_REG(FLASH_SR) & FLASH_SR_BSY) {}
+ *(flashAddr + 0x01) = (vu16)hhWord;
+ while (GET_REG(FLASH_SR) & FLASH_SR_BSY) {}
+ *(flashAddr) = (vu16)lhWord;
+ while (GET_REG(FLASH_SR) & FLASH_SR_BSY) {}
+
+ rwmVal &= 0xFFFFFFFE;
+ SET_REG(FLASH_CR, rwmVal);
+
+ /* verify the write */
+ if (*(vu32 *)addr != word) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void flashLock() {
+ /* take down the HSI oscillator? it may be in use elsewhere */
+
+ /* ensure all FPEC functions disabled and lock the FPEC */
+ SET_REG(FLASH_CR, 0x00000080);
+}
+
+void flashUnlock() {
+ /* unlock the flash */
+ SET_REG(FLASH_KEYR, FLASH_KEY1);
+ SET_REG(FLASH_KEYR, FLASH_KEY2);
+}
+
+
+
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/hardware.h b/Arduino_STM32-MIDI/other/maple-bootloader/hardware.h
new file mode 100755
index 0000000..ec447a6
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/hardware.h
@@ -0,0 +1,190 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+#ifndef __HARDWARE_H
+#define __HARDWARE_H
+
+#include "stm32f10x_type.h"
+#include "cortexm3_macro.h"
+#include "common.h"
+
+/* macro'd register and peripheral definitions */
+#define RCC ((u32)0x40021000)
+#define FLASH ((u32)0x40022000)
+#define GPIOA ((u32)0x40010800)
+#define GPIOB ((u32)0x40010C00)
+#define GPIOC ((u32)0x40011000)
+
+#define RCC_CR RCC
+#define RCC_CFGR (RCC + 0x04)
+#define RCC_CIR (RCC + 0x08)
+#define RCC_AHBENR (RCC + 0x14)
+#define RCC_APB2ENR (RCC + 0x18)
+#define RCC_APB1ENR (RCC + 0x1C)
+
+#define FLASH_ACR (FLASH + 0x00)
+#define FLASH_KEYR (FLASH + 0x04)
+#define FLASH_OPTKEYR (FLASH + 0x08)
+#define FLASH_SR (FLASH + 0x0C)
+#define FLASH_CR (FLASH + 0x10)
+#define FLASH_AR (FLASH + 0x14)
+#define FLASH_OBR (FLASH + 0x1C)
+#define FLASH_WRPR (FLASH + 0x20)
+
+#define FLASH_KEY1 0x45670123
+#define FLASH_KEY2 0xCDEF89AB
+#define FLASH_RDPRT 0x00A5
+#define FLASH_SR_BSY 0x01
+#define FLASH_CR_PER 0x02
+#define FLASH_CR_PG 0x01
+#define FLASH_CR_START 0x40
+
+#define GPIO_CRL(port) port
+#define GPIO_CRH(port) (port+0x04)
+#define GPIO_IDR(port) (port+0x08)
+#define GPIO_ODR(port) (port+0x0c)
+#define GPIO_BSRR(port) (port+0x10)
+
+#define SCS_BASE ((u32)0xE000E000)
+#define NVIC_BASE (SCS_BASE + 0x0100)
+#define SCB_BASE (SCS_BASE + 0x0D00)
+
+
+#define SCS 0xE000E000
+#define NVIC (SCS+0x100)
+#define SCB (SCS+0xD00)
+#define STK (SCS+0x10)
+
+#define SCB_VTOR (SCB+0x08)
+#define STK_CTRL (STK+0x00)
+
+#define TIM1_APB2_ENB ((u32)0x00000800)
+#define TIM1 ((u32)0x40012C00)
+#define TIM1_PSC (TIM1+0x28)
+#define TIM1_ARR (TIM1+0x2C)
+#define TIM1_RCR (TIM1+0x30)
+#define TIM1_CR1 (TIM1+0x00)
+#define TIM1_CR2 (TIM1+0x04)
+#define TIM1_DIER (TIM1+0x0C)
+#define TIM1_UP_IRQ_Channel ((u8)0x19)
+
+#define USB_HP_IRQ ((u8)0x13)
+#define USB_LP_IRQ ((u8)0x14)
+#define TIM2_IRQ ((u8)0x1C)
+
+
+/* AIRCR */
+#define AIRCR_RESET 0x05FA0000
+#define AIRCR_RESET_REQ (AIRCR_RESET | (u32)0x04);
+
+/* temporary copyage of example from kiel */
+#define __VAL(__TIMCLK, __PERIOD) ((__TIMCLK/1000000UL)*__PERIOD)
+#define __PSC(__TIMCLK, __PERIOD) (((__VAL(__TIMCLK, __PERIOD)+49999UL)/50000UL) - 1)
+#define __ARR(__TIMCLK, __PERIOD) ((__VAL(__TIMCLK, __PERIOD)/(__PSC(__TIMCLK, __PERIOD)+1)) - 1)
+
+#define SET_REG(addr,val) do { *(vu32*)(addr)=val; } while(0)
+#define GET_REG(addr) (*(vu32*)(addr))
+
+
+/* todo: there must be some major misunderstanding in how we access
+ regs. The direct access approach (GET_REG) causes the usb init to
+ fail upon trying to activate RCC_APB1 |= 0x00800000. However, using
+ the struct approach from ST, it works fine...temporarily switching
+ to that approach */
+typedef struct {
+ vu32 CR;
+ vu32 CFGR;
+ vu32 CIR;
+ vu32 APB2RSTR;
+ vu32 APB1RSTR;
+ vu32 AHBENR;
+ vu32 APB2ENR;
+ vu32 APB1ENR;
+ vu32 BDCR;
+ vu32 CSR;
+} RCC_RegStruct;
+#define pRCC ((RCC_RegStruct *) RCC)
+
+typedef struct {
+ vu32 ISER[2];
+ u32 RESERVED0[30];
+ vu32 ICER[2];
+ u32 RSERVED1[30];
+ vu32 ISPR[2];
+ u32 RESERVED2[30];
+ vu32 ICPR[2];
+ u32 RESERVED3[30];
+ vu32 IABR[2];
+ u32 RESERVED4[62];
+ vu32 IPR[15];
+} NVIC_TypeDef;
+
+typedef struct {
+ u8 NVIC_IRQChannel;
+ u8 NVIC_IRQChannelPreemptionPriority;
+ u8 NVIC_IRQChannelSubPriority;
+ bool NVIC_IRQChannelCmd; /* TRUE for enable */
+} NVIC_InitTypeDef;
+
+typedef struct {
+ vuc32 CPUID;
+ vu32 ICSR;
+ vu32 VTOR;
+ vu32 AIRCR;
+ vu32 SCR;
+ vu32 CCR;
+ vu32 SHPR[3];
+ vu32 SHCSR;
+ vu32 CFSR;
+ vu32 HFSR;
+ vu32 DFSR;
+ vu32 MMFAR;
+ vu32 BFAR;
+ vu32 AFSR;
+} SCB_TypeDef;
+
+
+void setPin(u32 bank, u8 pin);
+void resetPin(u32 bank, u8 pin);
+bool readPin(u32 bank, u8 pin);
+void strobePin(u32 bank, u8 pin, u8 count, u32 rate);
+
+void systemHardReset(void);
+void systemReset(void);
+void setupCLK(void);
+void setupLED(void);
+void setupFLASH(void);
+void setupBUTTON(void);
+bool checkUserCode(u32 usrAddr);
+void jumpToUser(u32 usrAddr);
+
+bool flashWriteWord(u32 addr, u32 word);
+bool flashErasePage(u32 addr);
+bool flashErasePages(u32 addr, u16 n);
+void flashLock(void);
+void flashUnlock(void);
+void nvicInit(NVIC_InitTypeDef *);
+void nvicDisableInterrupts(void);
+
+#endif
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/main.c b/Arduino_STM32-MIDI/other/maple-bootloader/main.c
new file mode 100755
index 0000000..5c06617
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/main.c
@@ -0,0 +1,70 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @file main.c
+ *
+ * @brief main loop and calling any hardware init stuff. timing hacks for EEPROM
+ * writes not to block usb interrupts. logic to handle 2 second timeout then
+ * jump to user code.
+ *
+ */
+
+#include "common.h"
+
+int main() {
+ systemReset(); // peripherals but not PC
+ setupCLK();
+ setupLED();
+ setupUSB();
+ setupBUTTON();
+ setupFLASH();
+
+ strobePin(LED_BANK, LED, STARTUP_BLINKS, BLINK_FAST);
+
+ /* wait for host to upload program or halt bootloader */
+ bool no_user_jump = !checkUserCode(USER_CODE_FLASH) && !checkUserCode(USER_CODE_RAM) || readPin(BUTTON_BANK, BUTTON);
+ int delay_count = 0;
+
+ while ((delay_count++ < BOOTLOADER_WAIT)
+ || no_user_jump) {
+
+ strobePin(LED_BANK, LED, 1, BLINK_SLOW);
+
+ if (dfuUploadStarted()) {
+ dfuFinishUpload(); // systemHardReset from DFU once done
+ }
+ }
+
+ if (checkUserCode(USER_CODE_RAM)) {
+ jumpToUser(USER_CODE_RAM);
+ } else if (checkUserCode(USER_CODE_FLASH)) {
+ jumpToUser(USER_CODE_FLASH);
+ } else {
+ // some sort of fault occurred, hard reset
+ strobePin(LED_BANK, LED, 5, BLINK_FAST);
+ systemHardReset();
+ }
+
+}
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/readme.md b/Arduino_STM32-MIDI/other/maple-bootloader/readme.md
new file mode 100755
index 0000000..6ec6b77
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/readme.md
@@ -0,0 +1,5 @@
+Modified version of maple bootloader which includes DFU read functionality
+
+Modifications were made by Tim Schuerewegen
+
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md.ld b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md.ld
new file mode 100755
index 0000000..43073a7
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md.ld
@@ -0,0 +1,172 @@
+/*
+Default linker script for STM32F10x_128K_20K
+Original Copyright RAISONANCE S.A.S. 2008
+Modified P Harrison May 2009
+*/
+
+/*
+ * Default stack sizes.
+ *
+ * These are used by the startup in order to allocate stacks for the different modes.
+ * PROVIDE" allows to easily override these values from an object file or the commmand line.
+ */
+
+__Stack_Size = 1024 ;
+PROVIDE ( _Stack_Size = __Stack_Size ) ;
+__Stack_Init = _estack - __Stack_Size ;
+PROVIDE ( _Stack_Init = __Stack_Init ) ;
+
+/*
+ *There will be a link error if there is not this amount of RAM free at the end.
+ */
+_Minimum_Stack_Size = 0x100 ;
+
+
+MEMORY
+{
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
+ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
+}
+
+/* higher address of the user mode stack */
+_estack = 0x20005000;
+
+SECTIONS
+{
+/*
+ * for Cortex devices, the beginning of the startup code is stored in the .isr_vector section,
+ * which goes to FLASH
+ */
+ .isr_vector :
+ {
+ . = ALIGN(4);
+ KEEP(*(.isr_vector)) /* Startup code */
+ . = ALIGN(4);
+ } >FLASH
+
+/*
+ * for some STRx devices, the beginning of the startup code is stored in the .flashtext section,
+ * which goes to FLASH
+ */
+ .flashtext :
+ {
+ . = ALIGN(4);
+ KEEP (*(.flashtext)) /* Startup code */
+ . = ALIGN(4);
+ } >FLASH
+
+ /*
+ * the program code is stored in the .text section, which goes to Flash
+ */
+ .text :
+ {
+ . = ALIGN(4);
+ *(.text) /* remaining code */
+ *(.text.*) /* remaining code */
+ *(.rodata) /* read-only data (constants) */
+ *(.rodata*)
+ *(.glue_7)
+ *(.glue_7t)
+ . = ALIGN(4);
+ _etext = .;
+ _sidata = _etext;
+ } >FLASH
+
+/*
+ * This is the initialized data section. It is stored in RAM but the initial values
+ * are held in flash and copied to RAM by the startup code
+ */
+
+/* we copy the important program globals vector in RAM as well, so that users can fool with it */
+ .data : AT ( _sidata ) /* AT makes the LMA follow on in the binary image */
+ {
+ . = ALIGN(4);
+ _sdata = . ; /* Used by the startup in order to initialize the .data section */
+ KEEP( *(.data) )
+ KEEP( *(.data.*) )
+ . = ALIGN(4);
+ _edata = . ; /* Used by the startup in order to initialize the .data section */
+ } >RAM
+
+
+
+/*
+ * This is the uninitialized data section. Date here is stored in RAM and will be
+ * set to zero by the startup code.
+ */
+ .bss :
+ {
+ . = ALIGN(4);
+ _sbss = .; /* Used by the startup in order to initialize the .bss section */
+ *(.bss)
+ *(COMMON)
+ . = ALIGN(4);
+ _ebss = . ; /* Used by the startup in order to initialize the .bss section */
+ } >RAM
+
+PROVIDE ( end = _ebss );
+PROVIDE ( _end = _ebss );
+
+/*
+ * This is the user stack section
+ * This is just to check that there is enough RAM left for the User mode stack
+ * It should generate an error if it's full.
+ */
+ ._usrstack :
+ {
+ . = ALIGN(4);
+ _susrstack = . ;
+ . = . + _Minimum_Stack_Size ;
+ . = ALIGN(4);
+ _eusrstack = . ;
+ } >RAM
+
+/*
+ * after that it's only debugging information.
+ */
+
+/* remove the debugging information from the standard libraries */
+DISCARD :
+ {
+ libc.a ( * )
+ libm.a ( * )
+ libgcc.a ( * )
+ }
+
+/* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+/*
+ * DWARF debug sections.
+ * Symbols in the DWARF debugging sections are relative to the beginning
+ * of the section so we begin them at 0.
+ */
+
+/* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+/* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+/* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+/* DWARF 2 */
+ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+/* SGI/MIPS DWARF 2 extensions */
+ .debug_weaknames 0 : { *(.debug_weaknames) }
+ .debug_funcnames 0 : { *(.debug_funcnames) }
+ .debug_typenames 0 : { *(.debug_typenames) }
+ .debug_varnames 0 : { *(.debug_varnames) }
+}
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md_RAM.ld b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md_RAM.ld
new file mode 100755
index 0000000..0ed3a67
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_md_RAM.ld
@@ -0,0 +1,169 @@
+/*
+Default linker script for STM32F10x_128K_20K
+Original Copyright RAISONANCE S.A.S. 2008
+Modified P Harrison May 2009
+*/
+
+/*
+ * Default stack sizes.
+ *
+ * These are used by the startup in order to allocate stacks for the different modes.
+ * PROVIDE" allows to easily override these values from an object file or the commmand line.
+ */
+
+__Stack_Size = 1024 ;
+PROVIDE ( _Stack_Size = __Stack_Size ) ;
+__Stack_Init = _estack - __Stack_Size ;
+PROVIDE ( _Stack_Init = __Stack_Init ) ;
+
+/*
+ *There will be a link error if there is not this amount of RAM free at the end.
+ */
+_Minimum_Stack_Size = 0x100 ;
+
+
+MEMORY
+{
+ RAM (xrw) : ORIGIN = 0x20000C00, LENGTH = 17K
+}
+
+/* higher address of the user mode stack */
+_estack = 0x20005000;
+_magicRate = 0x5000;
+SECTIONS
+{
+/*
+ * for Cortex devices, the beginning of the startup code is stored in the .isr_vector section,
+ * which goes to FLASH
+ */
+ .isr_vector :
+ {
+ . = ALIGN(4);
+ KEEP(*(.isr_vector)) /* Startup code */
+ . = ALIGN(4);
+ } >RAM
+
+/*
+ * for some STRx devices, the beginning of the startup code is stored in the .flashtext section,
+ * which goes to FLASH
+ */
+ .flashtext :
+ {
+ . = ALIGN(4);
+ KEEP (*(.flashtext)) /* Startup code */
+ . = ALIGN(4);
+ } >RAM
+
+ /*
+ * the program code is stored in the .text section, which goes to Flash
+ */
+ .text :
+ {
+ . = ALIGN(4);
+ *(.text) /* remaining code */
+ *(.text.*) /* remaining code */
+ *(.rodata) /* read-only data (constants) */
+ *(.rodata*)
+ *(.glue_7)
+ *(.glue_7t)
+ . = ALIGN(4);
+ _etext = .;
+ _sidata = _etext; /* Uused by the startup in order to initialize the .data secion */
+ } >RAM
+
+/*
+ * This is the initialized data section. It is stored in RAM but the initial values
+ * are held in flash and copied to RAM by the startup code
+ */
+ .data : AT ( _sidata ) /* AT makes the LMA follow on in the binary image */
+ {
+ . = ALIGN(4);
+ _sdata = . ; /* Used by the startup in order to initialize the .data section */
+ KEEP( *(.data) )
+ KEEP( *(.data.*) )
+ . = ALIGN(4);
+ _edata = . ; /* Used by the startup in order to initialize the .data section */
+ } >RAM
+
+
+
+/*
+ * This is the uninitialized data section. Date here is stored in RAM and will be
+ * set to zero by the startup code.
+ */
+ .bss :
+ {
+ . = ALIGN(4);
+ _sbss = .; /* Used by the startup in order to initialize the .bss section */
+ *(.bss)
+ *(COMMON)
+ . = ALIGN(4);
+ _ebss = . ; /* Used by the startup in order to initialize the .bss section */
+ } >RAM
+
+PROVIDE ( end = _ebss );
+PROVIDE ( _end = _ebss );
+
+/*
+ * This is the user stack section
+ * This is just to check that there is enough RAM left for the User mode stack
+ * It should generate an error if it's full.
+ */
+ ._usrstack :
+ {
+ . = ALIGN(4);
+ _susrstack = . ;
+ . = . + _Minimum_Stack_Size ;
+ . = ALIGN(4);
+ _eusrstack = . ;
+ } >RAM
+
+/*
+ * after that it's only debugging information.
+ */
+
+/* remove the debugging information from the standard libraries */
+DISCARD :
+ {
+ libc.a ( * )
+ libm.a ( * )
+ libgcc.a ( * )
+ }
+
+/* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+/*
+ * DWARF debug sections.
+ * Symbols in the DWARF debugging sections are relative to the beginning
+ * of the section so we begin them at 0.
+ */
+
+/* DWARF 1 */
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+/* GNU DWARF 1 extensions */
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+/* DWARF 1.1 and DWARF 2 */
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+/* DWARF 2 */
+ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+/* SGI/MIPS DWARF 2 extensions */
+ .debug_weaknames 0 : { *(.debug_weaknames) }
+ .debug_funcnames 0 : { *(.debug_funcnames) }
+ .debug_typenames 0 : { *(.debug_typenames) }
+ .debug_varnames 0 : { *(.debug_varnames) }
+}
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup.s b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup.s
new file mode 100755
index 0000000..02c578b
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup.s
@@ -0,0 +1,367 @@
+/**
+ ******************************************************************************
+ * @file startup_stm32f10x_md.s
+ * @author MCD Application Team
+ * @version V3.1.0
+ * @date 06/19/2009
+ * @brief STM32F10x Medium Density Devices vector table for RIDE7 toolchain.
+ * This module performs:
+ * - Set the initial SP
+ * - Set the initial PC == Reset_Handler,
+ * - Set the vector table entries with the exceptions ISR address
+ * - Branches to main in the C library (which eventually
+ * calls main()).
+ * After Reset the Cortex-M3 processor is in Thread mode,
+ * priority is Privileged, and the Stack is set to Main.
+ *******************************************************************************
+ * @copy
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
+ */
+
+ .syntax unified
+ .cpu cortex-m3
+ .fpu softvfp
+ .thumb
+
+.global g_pfnVectors
+.global SystemInit_ExtMemCtl_Dummy
+.global Default_Handler
+
+/* start address for the initialization values of the .data section.
+defined in linker script */
+.word _sidata
+/* start address for the .data section. defined in linker script */
+.word _sdata
+/* end address for the .data section. defined in linker script */
+.word _edata
+/* start address for the .bss section. defined in linker script */
+.word _sbss
+/* end address for the .bss section. defined in linker script */
+.word _ebss
+
+.equ BootRAM, 0xF108F85F
+/**
+ * @brief This is the code that gets called when the processor first
+ * starts execution following a reset event. Only the absolutely
+ * necessary set is performed, after which the application
+ * supplied main() routine is called.
+ * @param None
+ * @retval : None
+*/
+
+ .section .text.Reset_Handler
+ .weak Reset_Handler
+ .type Reset_Handler, %function
+Reset_Handler:
+
+/* Copy the data segment initializers from flash to SRAM */
+ movs r1, #0
+ b LoopCopyDataInit
+
+CopyDataInit:
+ ldr r3, =_sidata
+ ldr r3, [r3, r1]
+ str r3, [r0, r1]
+ adds r1, r1, #4
+
+LoopCopyDataInit:
+ ldr r0, =_sdata
+ ldr r3, =_edata
+ adds r2, r0, r1
+ cmp r2, r3
+ bcc CopyDataInit
+ ldr r2, =_sbss
+ b LoopFillZerobss
+/* Zero fill the bss segment. */
+FillZerobss:
+ movs r3, #0
+ str r3, [r2], #4
+
+LoopFillZerobss:
+ ldr r3, = _ebss
+ cmp r2, r3
+ bcc FillZerobss
+/* Call the application's entry point.*/
+ bl main
+ bx lr
+.size Reset_Handler, .-Reset_Handler
+
+/**
+ * @brief This is the code that gets called when the processor receives an
+ * unexpected interrupt. This simply enters an infinite loop, preserving
+ * the system state for examination by a debugger.
+ *
+ * @param None
+ * @retval : None
+*/
+ .section .text.Default_Handler,"ax",%progbits
+Default_Handler:
+Infinite_Loop:
+ b Infinite_Loop
+ .size Default_Handler, .-Default_Handler
+/******************************************************************************
+*
+* The minimal vector table for a Cortex M3. Note that the proper constructs
+* must be placed on this to ensure that it ends up at physical address
+* 0x0000.0000.
+*
+******************************************************************************/
+ .section .isr_vector,"a",%progbits
+ .type g_pfnVectors, %object
+ .size g_pfnVectors, .-g_pfnVectors
+
+
+g_pfnVectors:
+ .word _estack
+ .word Reset_Handler
+ .word NMI_Handler
+ .word HardFault_Handler
+ .word MemManage_Handler
+ .word BusFault_Handler
+ .word UsageFault_Handler
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word SVC_Handler
+ .word DebugMon_Handler
+ .word 0
+ .word PendSV_Handler
+ .word SysTick_Handler
+ .word WWDG_IRQHandler
+ .word PVD_IRQHandler
+ .word TAMPER_IRQHandler
+ .word RTC_IRQHandler
+ .word FLASH_IRQHandler
+ .word RCC_IRQHandler
+ .word EXTI0_IRQHandler
+ .word EXTI1_IRQHandler
+ .word EXTI2_IRQHandler
+ .word EXTI3_IRQHandler
+ .word EXTI4_IRQHandler
+ .word DMA1_Channel1_IRQHandler
+ .word DMA1_Channel2_IRQHandler
+ .word DMA1_Channel3_IRQHandler
+ .word DMA1_Channel4_IRQHandler
+ .word DMA1_Channel5_IRQHandler
+ .word DMA1_Channel6_IRQHandler
+ .word DMA1_Channel7_IRQHandler
+ .word ADC1_2_IRQHandler
+ .word USB_HP_CAN1_TX_IRQHandler
+ .word USB_LP_CAN1_RX0_IRQHandler
+ .word CAN1_RX1_IRQHandler
+ .word CAN1_SCE_IRQHandler
+ .word EXTI9_5_IRQHandler
+ .word TIM1_BRK_IRQHandler
+ .word TIM1_UP_IRQHandler
+ .word TIM1_TRG_COM_IRQHandler
+ .word TIM1_CC_IRQHandler
+ .word TIM2_IRQHandler
+ .word TIM3_IRQHandler
+ .word TIM4_IRQHandler
+ .word I2C1_EV_IRQHandler
+ .word I2C1_ER_IRQHandler
+ .word I2C2_EV_IRQHandler
+ .word I2C2_ER_IRQHandler
+ .word SPI1_IRQHandler
+ .word SPI2_IRQHandler
+ .word USART1_IRQHandler
+ .word USART2_IRQHandler
+ .word USART3_IRQHandler
+ .word EXTI15_10_IRQHandler
+ .word RTCAlarm_IRQHandler
+ .word USBWakeUp_IRQHandler
+/*
+ .word TIM8_BRK
+ .word TIM8_UP
+ .word TIM8_TRG_COM
+ .word TIM8_CC
+ .word ADC3
+ .word FSMC
+ .word SDIO
+ .word TIM5
+ .word SPI3
+ .word UART4
+ .word UART5
+ .word TIM6
+ .word TIM7
+ .word DMA2_Channel1
+ .word DMA2_Channel2
+ .word DMA2_Channel3
+ .word DMA2_Channel5
+*/
+ .word BootRAM /* @0x108. This is for boot in RAM mode for
+ STM32F10x Medium Density devices. */
+
+/*******************************************************************************
+*
+* Provide weak aliases for each Exception handler to the Default_Handler.
+* As they are weak aliases, any function with the same name will override
+* this definition.
+*
+*******************************************************************************/
+
+ .weak NMI_Handler
+ .thumb_set NMI_Handler,Default_Handler
+
+ .weak HardFault_Handler
+ .thumb_set HardFault_Handler,Default_Handler
+
+ .weak MemManage_Handler
+ .thumb_set MemManage_Handler,Default_Handler
+
+ .weak BusFault_Handler
+ .thumb_set BusFault_Handler,Default_Handler
+
+ .weak UsageFault_Handler
+ .thumb_set UsageFault_Handler,Default_Handler
+
+ .weak SVC_Handler
+ .thumb_set SVC_Handler,Default_Handler
+
+ .weak DebugMon_Handler
+ .thumb_set DebugMon_Handler,Default_Handler
+
+ .weak PendSV_Handler
+ .thumb_set PendSV_Handler,Default_Handler
+
+ .weak SysTick_Handler
+ .thumb_set SysTick_Handler,Default_Handler
+
+ .weak WWDG_IRQHandler
+ .thumb_set WWDG_IRQHandler,Default_Handler
+
+ .weak PVD_IRQHandler
+ .thumb_set PVD_IRQHandler,Default_Handler
+
+ .weak TAMPER_IRQHandler
+ .thumb_set TAMPER_IRQHandler,Default_Handler
+
+ .weak RTC_IRQHandler
+ .thumb_set RTC_IRQHandler,Default_Handler
+
+ .weak FLASH_IRQHandler
+ .thumb_set FLASH_IRQHandler,Default_Handler
+
+ .weak RCC_IRQHandler
+ .thumb_set RCC_IRQHandler,Default_Handler
+
+ .weak EXTI0_IRQHandler
+ .thumb_set EXTI0_IRQHandler,Default_Handler
+
+ .weak EXTI1_IRQHandler
+ .thumb_set EXTI1_IRQHandler,Default_Handler
+
+ .weak EXTI2_IRQHandler
+ .thumb_set EXTI2_IRQHandler,Default_Handler
+
+ .weak EXTI3_IRQHandler
+ .thumb_set EXTI3_IRQHandler,Default_Handler
+
+ .weak EXTI4_IRQHandler
+ .thumb_set EXTI4_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel1_IRQHandler
+ .thumb_set DMA1_Channel1_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel2_IRQHandler
+ .thumb_set DMA1_Channel2_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel3_IRQHandler
+ .thumb_set DMA1_Channel3_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel4_IRQHandler
+ .thumb_set DMA1_Channel4_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel5_IRQHandler
+ .thumb_set DMA1_Channel5_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel6_IRQHandler
+ .thumb_set DMA1_Channel6_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel7_IRQHandler
+ .thumb_set DMA1_Channel7_IRQHandler,Default_Handler
+
+ .weak ADC1_2_IRQHandler
+ .thumb_set ADC1_2_IRQHandler,Default_Handler
+
+ .weak USB_HP_CAN1_TX_IRQHandler
+ .thumb_set USB_HP_CAN1_TX_IRQHandler,Default_Handler
+
+ .weak USB_LP_CAN1_RX0_IRQHandler
+ .thumb_set USB_LP_CAN1_RX0_IRQHandler,Default_Handler
+
+ .weak CAN1_RX1_IRQHandler
+ .thumb_set CAN1_RX1_IRQHandler,Default_Handler
+
+ .weak CAN1_SCE_IRQHandler
+ .thumb_set CAN1_SCE_IRQHandler,Default_Handler
+
+ .weak EXTI9_5_IRQHandler
+ .thumb_set EXTI9_5_IRQHandler,Default_Handler
+
+ .weak TIM1_BRK_IRQHandler
+ .thumb_set TIM1_BRK_IRQHandler,Default_Handler
+
+ .weak TIM1_UP_IRQHandler
+ .thumb_set TIM1_UP_IRQHandler,Default_Handler
+
+ .weak TIM1_TRG_COM_IRQHandler
+ .thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler
+
+ .weak TIM1_CC_IRQHandler
+ .thumb_set TIM1_CC_IRQHandler,Default_Handler
+
+ .weak TIM2_IRQHandler
+ .thumb_set TIM2_IRQHandler,Default_Handler
+
+ .weak TIM3_IRQHandler
+ .thumb_set TIM3_IRQHandler,Default_Handler
+
+ .weak TIM4_IRQHandler
+ .thumb_set TIM4_IRQHandler,Default_Handler
+
+ .weak I2C1_EV_IRQHandler
+ .thumb_set I2C1_EV_IRQHandler,Default_Handler
+
+ .weak I2C1_ER_IRQHandler
+ .thumb_set I2C1_ER_IRQHandler,Default_Handler
+
+ .weak I2C2_EV_IRQHandler
+ .thumb_set I2C2_EV_IRQHandler,Default_Handler
+
+ .weak I2C2_ER_IRQHandler
+ .thumb_set I2C2_ER_IRQHandler,Default_Handler
+
+ .weak SPI1_IRQHandler
+ .thumb_set SPI1_IRQHandler,Default_Handler
+
+ .weak SPI2_IRQHandler
+ .thumb_set SPI2_IRQHandler,Default_Handler
+
+ .weak USART1_IRQHandler
+ .thumb_set USART1_IRQHandler,Default_Handler
+
+ .weak USART2_IRQHandler
+ .thumb_set USART2_IRQHandler,Default_Handler
+
+ .weak USART3_IRQHandler
+ .thumb_set USART3_IRQHandler,Default_Handler
+
+ .weak EXTI15_10_IRQHandler
+ .thumb_set EXTI15_10_IRQHandler,Default_Handler
+
+ .weak RTCAlarm_IRQHandler
+ .thumb_set RTCAlarm_IRQHandler,Default_Handler
+
+ .weak USBWakeUp_IRQHandler
+ .thumb_set USBWakeUp_IRQHandler,Default_Handler
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup_user.s b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup_user.s
new file mode 100755
index 0000000..dc758fd
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/c_only_startup_user.s
@@ -0,0 +1,128 @@
+/**
+ ******************************************************************************
+ * @file startup_stm32f10x_md.s
+ * @author MCD Application Team
+ * @version V3.1.0
+ * @date 06/19/2009
+ * @brief STM32F10x Medium Density Devices vector table for RIDE7 toolchain.
+ * This module performs:
+ * - Set the initial SP
+ * - Set the initial PC == Reset_Handler,
+ * - Set the vector table entries with the exceptions ISR address
+ * - Branches to main in the C library (which eventually
+ * calls main()).
+ * After Reset the Cortex-M3 processor is in Thread mode,
+ * priority is Privileged, and the Stack is set to Main.
+ *******************************************************************************
+ * @copy
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
+ */
+
+ .syntax unified
+ .cpu cortex-m3
+ .fpu softvfp
+ .thumb
+
+.global g_pfnVectors
+.global SystemInit_ExtMemCtl_Dummy
+.global Default_Handler
+
+/* start address for the initialization values of the .data section.
+defined in linker script */
+.word _sidata
+/* start address for the .data section. defined in linker script */
+.word _sdata
+/* end address for the .data section. defined in linker script */
+.word _edata
+/* start address for the .bss section. defined in linker script */
+.word _sbss
+/* end address for the .bss section. defined in linker script */
+.word _ebss
+.word _magicRate
+
+.equ BootRAM, 0xF108F85F
+/**
+ * @brief This is the code that gets called when the processor first
+ * starts execution following a reset event. Only the absolutely
+ * necessary set is performed, after which the application
+ * supplied main() routine is called.
+ * @param None
+ * @retval : None
+*/
+
+ .section .text.Reset_Handler
+ .weak Reset_Handler
+ .type Reset_Handler, %function
+Reset_Handler:
+
+/* Copy the data segment initializers from flash to SRAM */
+ movs r1, #0
+ b LoopCopyDataInit
+
+CopyDataInit:
+ ldr r3, =_sidata
+ ldr r3, [r3, r1]
+ str r3, [r0, r1]
+ adds r1, r1, #4
+
+LoopCopyDataInit:
+ ldr r0, =_sdata
+ ldr r3, =_edata
+ adds r2, r0, r1
+ cmp r2, r3
+ bcc CopyDataInit
+ ldr r2, =_sbss
+ b LoopFillZerobss
+/* Zero fill the bss segment. */
+FillZerobss:
+ movs r3, #0
+ str r3, [r2], #4
+
+LoopFillZerobss:
+ ldr r3, = _ebss
+ cmp r2, r3
+ bcc FillZerobss
+/* Call the application's entry point.*/
+ bl main
+ bx lr
+.size Reset_Handler, .-Reset_Handler
+
+/**
+ * @brief This is the code that gets called when the processor receives an
+ * unexpected interrupt. This simply enters an infinite loop, preserving
+ * the system state for examination by a debugger.
+ *
+ * @param None
+ * @retval : None
+*/
+ .section .text.Default_Handler,"ax",%progbits
+Default_Handler:
+Infinite_Loop:
+ b Infinite_Loop
+ .size Default_Handler, .-Default_Handler
+/******************************************************************************
+*
+* The minimal vector table for a Cortex M3. Note that the proper constructs
+* must be placed on this to ensure that it ends up at physical address
+* 0x0000.0000.
+*
+******************************************************************************/
+ .section .isr_vector,"a",%progbits
+ .type g_pfnVectors, %object
+ .size g_pfnVectors, .-g_pfnVectors
+
+
+g_pfnVectors:
+ .word _estack
+ .word Reset_Handler
+ .word _magicRate
+
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.h b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.h
new file mode 100755
index 0000000..6adbc3b
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.h
@@ -0,0 +1,53 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : cortexm3_macro.h
+* Author : MCD Application Team
+* Version : V2.0.3
+* Date : 09/22/2008
+* Description : Header file for cortexm3_macro.s.
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __CORTEXM3_MACRO_H
+#define __CORTEXM3_MACRO_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f10x_type.h"
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void __WFI(void);
+void __WFE(void);
+void __SEV(void);
+void __ISB(void);
+void __DSB(void);
+void __DMB(void);
+void __SVC(void);
+u32 __MRS_CONTROL(void);
+void __MSR_CONTROL(u32 Control);
+u32 __MRS_PSP(void);
+void __MSR_PSP(u32 TopOfProcessStack);
+u32 __MRS_MSP(void);
+void __MSR_MSP(u32 TopOfMainStack);
+void __RESETPRIMASK(void);
+void __SETPRIMASK(void);
+u32 __READ_PRIMASK(void);
+void __RESETFAULTMASK(void);
+void __SETFAULTMASK(void);
+u32 __READ_FAULTMASK(void);
+void __BASEPRICONFIG(u32 NewPriority);
+u32 __GetBASEPRI(void);
+u16 __REV_HalfWord(u16 Data);
+u32 __REV_Word(u32 Data);
+
+#endif /* __CORTEXM3_MACRO_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.s b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.s
new file mode 100755
index 0000000..a6eb4bc
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/cortexm3_macro.s
@@ -0,0 +1,312 @@
+# 1 "./stm32_lib/cortexm3_macro.S"
+# 1 "<built-in>"
+# 1 "<command-line>"
+# 1 "./stm32_lib/cortexm3_macro.S"
+# 16 "./stm32_lib/cortexm3_macro.S"
+ .cpu cortex-m3
+.fpu softvfp
+.syntax unified
+.thumb
+.text
+
+
+ .globl __WFI
+ .globl __WFE
+ .globl __SEV
+ .globl __ISB
+ .globl __DSB
+ .globl __DMB
+ .globl __SVC
+ .globl __MRS_CONTROL
+ .globl __MSR_CONTROL
+ .globl __MRS_PSP
+ .globl __MSR_PSP
+ .globl __MRS_MSP
+ .globl __MSR_MSP
+ .globl __RESETPRIMASK
+ .globl __SETPRIMASK
+ .globl __READ_PRIMASK
+ .globl __RESETFAULTMASK
+ .globl __SETFAULTMASK
+ .globl __READ_FAULTMASK
+ .globl __BASEPRICONFIG
+ .globl __GetBASEPRI
+ .globl __REV_HalfWord
+ .globl __REV_Word
+
+
+
+
+
+
+
+.thumb_func
+__WFI:
+
+ WFI
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__WFE:
+
+ WFE
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__SEV:
+
+ SEV
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__ISB:
+
+ ISB
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__DSB:
+
+ DSB
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__DMB:
+
+ DMB
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__SVC:
+
+ SVC 0x01
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__MRS_CONTROL:
+
+ MRS r0,control
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__MSR_CONTROL:
+
+ MSR control, r0
+ ISB
+ BX r14
+
+
+
+
+
+
+.thumb_func
+__MRS_PSP:
+
+ MRS r0, psp
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__MSR_PSP:
+
+ MSR psp, r0
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__MRS_MSP:
+
+ MRS r0, msp
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__MSR_MSP:
+
+ MSR msp, r0
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__RESETPRIMASK:
+
+ CPSIE i
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__SETPRIMASK:
+
+ CPSID i
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__READ_PRIMASK:
+
+ MRS r0, PRIMASK
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__RESETFAULTMASK:
+
+ CPSIE f
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__SETFAULTMASK:
+
+ CPSID f
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__READ_FAULTMASK:
+
+ MRS r0, FAULTMASK
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__BASEPRICONFIG:
+
+ MSR basepri, r0
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__GetBASEPRI:
+
+ MRS r0, basepri_max
+ BX r14
+
+
+
+
+
+
+.thumb_func
+__REV_HalfWord:
+
+ REV16 r0, r0
+ BX r14
+
+
+
+
+
+
+
+.thumb_func
+__REV_Word:
+
+ REV r0, r0
+ BX r14
+
+.end
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/stm32f10x_type.h b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/stm32f10x_type.h
new file mode 100755
index 0000000..5563de3
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/stm32_lib/stm32f10x_type.h
@@ -0,0 +1,80 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : stm32f10x_type.h
+* Author : MCD Application Team
+* Version : V2.0.3
+* Date : 09/22/2008
+* Description : This file contains all the common data types used for the
+* STM32F10x firmware library.
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F10x_TYPE_H
+#define __STM32F10x_TYPE_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+typedef signed long s32;
+typedef signed short s16;
+typedef signed char s8;
+
+typedef signed long const sc32; /* Read Only */
+typedef signed short const sc16; /* Read Only */
+typedef signed char const sc8; /* Read Only */
+
+typedef volatile signed long vs32;
+typedef volatile signed short vs16;
+typedef volatile signed char vs8;
+
+typedef volatile signed long const vsc32; /* Read Only */
+typedef volatile signed short const vsc16; /* Read Only */
+typedef volatile signed char const vsc8; /* Read Only */
+
+typedef unsigned long u32;
+typedef unsigned short u16;
+typedef unsigned char u8;
+
+typedef unsigned long const uc32; /* Read Only */
+typedef unsigned short const uc16; /* Read Only */
+typedef unsigned char const uc8; /* Read Only */
+
+typedef volatile unsigned long vu32;
+typedef volatile unsigned short vu16;
+typedef volatile unsigned char vu8;
+
+typedef volatile unsigned long const vuc32; /* Read Only */
+typedef volatile unsigned short const vuc16; /* Read Only */
+typedef volatile unsigned char const vuc8; /* Read Only */
+
+typedef enum {FALSE = 0, TRUE = !FALSE} bool;
+
+typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
+
+typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
+#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
+
+typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
+
+#define U8_MAX ((u8)255)
+#define S8_MAX ((s8)127)
+#define S8_MIN ((s8)-128)
+#define U16_MAX ((u16)65535u)
+#define S16_MAX ((s16)32767)
+#define S16_MIN ((s16)-32768)
+#define U32_MAX ((u32)4294967295uL)
+#define S32_MAX ((s32)2147483647)
+#define S32_MIN ((s32)-2147483648)
+
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+#endif /* __STM32F10x_TYPE_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb.c
new file mode 100755
index 0000000..b2314f0
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb.c
@@ -0,0 +1,503 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @file usb.c
+ *
+ * @brief usb-specific hardware setup, NVIC, clocks, and usb activities
+ * in the pre-attached state. includes some of the lower level callbacks
+ * needed by the usb library, like suspend,resume,init,etc
+ */
+
+#include "usb.h"
+#include "dfu.h"
+
+void setupUSB(void) {
+ u32 rwmVal; /* read-write-modify place holder var */
+
+ /* Setup the USB DISC Pin */
+ rwmVal = GET_REG(RCC_APB2ENR);
+ rwmVal |= 0x00000008;
+ SET_REG(RCC_APB2ENR, rwmVal);
+
+ // todo, macroize usb_disc pin
+ /* Setup GPIOB Pin 9 as OD out */
+ rwmVal = GET_REG(GPIO_CRH(GPIOB));
+ rwmVal &= 0xFFFFFF0F;
+ rwmVal |= 0x00000050;
+ setPin(GPIOB, 9);
+ SET_REG(GPIO_CRH(GPIOB), rwmVal);
+
+ pRCC->APB1ENR |= 0x00800000;
+
+ /* initialize the usb application */
+ resetPin(GPIOB, 9); /* present ourselves to the host */
+ usbAppInit();
+
+}
+
+vu32 bDeviceState = UNCONNECTED;
+
+/* tracks sequential behavior of the ISTR */
+vu16 wIstr;
+vu8 bIntPackSOF = 0;
+
+DEVICE Device_Table = {
+ NUM_ENDPTS,
+ 1
+};
+
+DEVICE_PROP Device_Property = {
+ usbInit,
+ usbReset,
+ usbStatusIn,
+ usbStatusOut,
+ usbDataSetup,
+ usbNoDataSetup,
+ usbGetInterfaceSetting,
+ usbGetDeviceDescriptor,
+ usbGetConfigDescriptor,
+ usbGetStringDescriptor,
+ usbGetFunctionalDescriptor,
+ 0,
+ bMaxPacketSize
+};
+
+USER_STANDARD_REQUESTS User_Standard_Requests = {
+ usbGetConfiguration,
+ usbSetConfiguration,
+ usbGetInterface,
+ usbSetInterface,
+ usbGetStatus,
+ usbClearFeature,
+ usbSetEndpointFeature,
+ usbSetDeviceFeature,
+ usbSetDeviceAddress
+};
+
+void (*pEpInt_IN[7])(void) = {
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+};
+
+void (*pEpInt_OUT[7])(void) = {
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+ nothingProc,
+};
+
+struct {
+ volatile RESUME_STATE eState;
+ volatile u8 bESOFcnt;
+} ResumeS;
+
+/* dummy proc */
+void nothingProc(void) {
+}
+
+/* Function Definitions */
+void usbAppInit(void) {
+ /* hook in to usb_core, depends on all those damn
+ non encapsulated externs! */
+ USB_Init();
+}
+
+void usbSuspend(void) {
+ u16 wCNTR;
+ wCNTR = _GetCNTR();
+ wCNTR |= CNTR_FSUSP | CNTR_LPMODE;
+ _SetCNTR(wCNTR);
+
+ /* run any power reduction handlers */
+ bDeviceState = SUSPENDED;
+}
+
+void usbResumeInit(void) {
+ u16 wCNTR;
+
+ /* restart any clocks that had been stopped */
+
+ wCNTR = _GetCNTR();
+ wCNTR &= (~CNTR_LPMODE);
+ _SetCNTR(wCNTR);
+
+ /* undo power reduction handlers here */
+
+ _SetCNTR(ISR_MSK);
+}
+
+void usbResume(RESUME_STATE eResumeSetVal) {
+ u16 wCNTR;
+
+ if (eResumeSetVal != RESUME_ESOF)
+ ResumeS.eState = eResumeSetVal;
+
+ switch (ResumeS.eState) {
+ case RESUME_EXTERNAL:
+ usbResumeInit();
+ ResumeS.eState = RESUME_OFF;
+ break;
+ case RESUME_INTERNAL:
+ usbResumeInit();
+ ResumeS.eState = RESUME_START;
+ break;
+ case RESUME_LATER:
+ ResumeS.bESOFcnt = 2;
+ ResumeS.eState = RESUME_WAIT;
+ break;
+ case RESUME_WAIT:
+ ResumeS.bESOFcnt--;
+ if (ResumeS.bESOFcnt == 0)
+ ResumeS.eState = RESUME_START;
+ break;
+ case RESUME_START:
+ wCNTR = _GetCNTR();
+ wCNTR |= CNTR_RESUME;
+ _SetCNTR(wCNTR);
+ ResumeS.eState = RESUME_ON;
+ ResumeS.bESOFcnt = 10;
+ break;
+ case RESUME_ON:
+ ResumeS.bESOFcnt--;
+ if (ResumeS.bESOFcnt == 0) {
+ wCNTR = _GetCNTR();
+ wCNTR &= (~CNTR_RESUME);
+ _SetCNTR(wCNTR);
+ ResumeS.eState = RESUME_OFF;
+ }
+ break;
+ case RESUME_OFF:
+ case RESUME_ESOF:
+ default:
+ ResumeS.eState = RESUME_OFF;
+ break;
+ }
+}
+
+RESULT usbPowerOn(void) {
+ u16 wRegVal;
+
+ wRegVal = CNTR_FRES;
+ _SetCNTR(wRegVal);
+
+ wInterrupt_Mask = 0;
+ _SetCNTR(wInterrupt_Mask);
+ _SetISTR(0);
+ wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM; /* the bare minimum */
+ _SetCNTR(wInterrupt_Mask);
+
+ return USB_SUCCESS;
+}
+
+RESULT usbPowerOff(void) {
+ _SetCNTR(CNTR_FRES);
+ _SetISTR(0);
+ _SetCNTR(CNTR_FRES + CNTR_PDWN);
+
+ /* note that all weve done here is powerdown the
+ usb peripheral. we have no disabled the clocks,
+ pulled the usb_disc pin back up, or reset the
+ application state machines */
+
+ return USB_SUCCESS;
+}
+
+void usbInit(void) {
+ dfuInit();
+
+ pInformation->Current_Configuration = 0;
+ usbPowerOn();
+
+ _SetISTR(0);
+ wInterrupt_Mask = ISR_MSK;
+ _SetCNTR(wInterrupt_Mask);
+
+ usbEnbISR(); /* configure the cortex M3 private peripheral NVIC */
+ bDeviceState = UNCONNECTED;
+}
+
+void usbReset(void) {
+ dfuUpdateByReset();
+
+ pInformation->Current_Configuration = 0;
+ pInformation->Current_Feature = usbConfigDescriptorDFU.Descriptor[7];
+
+ _SetBTABLE(BTABLE_ADDRESS);
+
+ /* setup the ctrl endpoint */
+ _SetEPType(ENDP0, EP_CONTROL);
+ _SetEPTxStatus(ENDP0, EP_TX_STALL);
+
+ _SetEPRxAddr(ENDP0, ENDP0_RXADDR);
+ _SetEPTxAddr(ENDP0, ENDP0_TXADDR);
+
+ Clear_Status_Out(ENDP0);
+
+ SetEPRxCount(ENDP0, pProperty->MaxPacketSize);
+ // SetEPTxCount(ENDP0, pProperty->MaxPacketSize);
+ SetEPRxValid(ENDP0);
+
+ bDeviceState = ATTACHED;
+ SetDeviceAddress(0); /* different than usbSetDeviceAddr! comes from usb_core */
+}
+
+void usbStatusIn(void) {
+}
+
+void usbStatusOut(void) {
+}
+
+RESULT usbDataSetup(u8 request) {
+ u8 *(*CopyRoutine)(u16);
+ CopyRoutine = NULL;
+
+ /* handle dfu class requests */
+ if ((pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT)) == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
+ if (dfuUpdateByRequest()) {
+ /* successfull state transition, handle the request */
+ switch (request) {
+ case(DFU_GETSTATUS):
+ CopyRoutine = dfuCopyStatus;
+ break;
+ case(DFU_GETSTATE):
+ CopyRoutine = dfuCopyState;
+ break;
+ case(DFU_DNLOAD):
+ CopyRoutine = dfuCopyDNLOAD;
+ break;
+ case(DFU_UPLOAD):
+ CopyRoutine = dfuCopyUPLOAD;
+ break;
+ default:
+ /* leave copy routine null */
+ break;
+ }
+ }
+ }
+
+ if (CopyRoutine != NULL) {
+ pInformation->Ctrl_Info.CopyData = CopyRoutine;
+ pInformation->Ctrl_Info.Usb_wOffset = 0;
+ (*CopyRoutine)(0);
+
+ return USB_SUCCESS;
+ }
+
+ return USB_UNSUPPORT;
+}
+
+RESULT usbNoDataSetup(u8 request) {
+ if ((pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT)) == (CLASS_REQUEST | INTERFACE_RECIPIENT)) {
+ /* todo, keep track of the destination interface, often stored in wIndex */
+ if (dfuUpdateByRequest()) {
+ return USB_SUCCESS;
+ }
+ }
+ return USB_UNSUPPORT;
+}
+
+RESULT usbGetInterfaceSetting(u8 interface, u8 altSetting) {
+ /* alt setting 0 -> program RAM, alt setting 1 -> FLASH */
+ if (interface > NUM_ALT_SETTINGS) {
+ return USB_UNSUPPORT;
+ } else {
+ return USB_SUCCESS;
+ }
+}
+
+u8 *usbGetDeviceDescriptor(u16 len) {
+ return Standard_GetDescriptorData(len, &usbDeviceDescriptorDFU);
+}
+
+u8 *usbGetConfigDescriptor(u16 len) {
+ return Standard_GetDescriptorData(len, &usbConfigDescriptorDFU);
+}
+
+u8 *usbGetStringDescriptor(u16 len) {
+ u8 strIndex = pInformation->USBwValue0;
+ if (strIndex > STR_DESC_LEN) {
+ return NULL;
+ } else {
+ return Standard_GetDescriptorData(len, &usbStringDescriptor[strIndex]);
+ }
+}
+
+u8 *usbGetFunctionalDescriptor(u16 len) {
+ return Standard_GetDescriptorData(len, &usbFunctionalDescriptor);
+}
+
+
+
+/***** start of USER STANDARD REQUESTS ******
+ *
+ * These are the USER STANDARD REQUESTS, they are handled
+ * in the core but we are given these callbacks at the
+ * application level
+ *******************************************/
+
+void usbGetConfiguration(void) {
+ /* nothing process */
+}
+
+void usbSetConfiguration(void) {
+ if (pInformation->Current_Configuration != 0) {
+ bDeviceState = CONFIGURED;
+ }
+}
+
+void usbGetInterface(void) {
+ /* nothing process */
+}
+
+void usbSetInterface(void) {
+ /* nothing process */
+}
+
+void usbGetStatus(void) {
+ /* nothing process */
+}
+
+void usbClearFeature(void) {
+ /* nothing process */
+}
+
+void usbSetEndpointFeature(void) {
+ /* nothing process */
+}
+
+void usbSetDeviceFeature(void) {
+ /* nothing process */
+}
+
+void usbSetDeviceAddress(void) {
+ bDeviceState = ADDRESSED;
+}
+/***** end of USER STANDARD REQUESTS *****/
+
+
+void usbEnbISR(void) {
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+
+ NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = TRUE;
+ nvicInit(&NVIC_InitStructure);
+}
+
+void usbDsbISR(void) {
+ NVIC_InitTypeDef NVIC_InitStructure;
+ NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = FALSE;
+ nvicInit(&NVIC_InitStructure);
+}
+
+void USB_LP_CAN1_RX0_IRQHandler(void) {
+ wIstr = _GetISTR();
+
+ /* go nuts with the preproc switches since this is an ISTR and must be FAST */
+#if (ISR_MSK & ISTR_RESET)
+ if (wIstr & ISTR_RESET & wInterrupt_Mask) {
+ _SetISTR((u16)CLR_RESET);
+ Device_Property.Reset();
+ }
+#endif
+
+
+#if (ISR_MSK & ISTR_DOVR)
+ if (wIstr & ISTR_DOVR & wInterrupt_Mask) {
+ _SetISTR((u16)CLR_DOVR);
+ }
+#endif
+
+
+#if (ISR_MSK & ISTR_ERR)
+ if (wIstr & ISTR_ERR & wInterrupt_Mask) {
+ _SetISTR((u16)CLR_ERR);
+ }
+#endif
+
+
+#if (ISR_MSK & ISTR_WKUP)
+ if (wIstr & ISTR_WKUP & wInterrupt_Mask) {
+ _SetISTR((u16)CLR_WKUP);
+ usbResume(RESUME_EXTERNAL);
+ }
+#endif
+
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (ISR_MSK & ISTR_SUSP)
+ if (wIstr & ISTR_SUSP & wInterrupt_Mask) {
+
+ /* check if SUSPEND is possible */
+ if (F_SUSPEND_ENABLED) {
+ usbSuspend();
+ } else {
+ /* if not possible then resume after xx ms */
+ usbResume(RESUME_LATER);
+ }
+ /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
+ _SetISTR((u16)CLR_SUSP);
+ }
+#endif
+
+
+#if (ISR_MSK & ISTR_SOF)
+ if (wIstr & ISTR_SOF & wInterrupt_Mask) {
+ _SetISTR((u16)CLR_SOF);
+ bIntPackSOF++;
+ }
+#endif
+
+
+#if (ISR_MSK & ISTR_ESOF)
+ if (wIstr & ISTR_ESOF & wInterrupt_Mask) {
+ _SetISTR((u16)CLR_ESOF);
+ /* resume handling timing is made with ESOFs */
+ usbResume(RESUME_ESOF); /* request without change of the machine state */
+ }
+#endif
+
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (ISR_MSK & ISTR_CTR)
+ if (wIstr & ISTR_CTR & wInterrupt_Mask) {
+ /* servicing of the endpoint correct transfer interrupt */
+ /* clear of the CTR flag into the sub */
+ CTR_LP(); /* low priority ISR defined in the usb core lib */
+ }
+#endif
+
+}
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb.h
new file mode 100755
index 0000000..6026511
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb.h
@@ -0,0 +1,132 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+#ifndef __USB_H
+#define __USB_H
+
+#include "common.h"
+#include "usb_lib.h"
+#include "usb_descriptor.h"
+
+/* USB configuration params */
+#define BTABLE_ADDRESS 0x00
+#define ENDP0_RXADDR 0x40
+#define ENDP0_TXADDR 0x80 /* gives 64 bytes i/o buflen */
+#define ENDP1_TXADDR 0xC0
+#define ENDP2_TXADDR 0x100
+#define ENDP3_RXADDR 0x110
+
+#define bMaxPacketSize 0x40 /* 64B, maximum for usb FS devices */
+#define wTransferSize 0x0400 /* 1024B, want: maxpacket < wtransfer < 10KB (to ensure everything can live in ram */
+
+#define NUM_ENDPTS 0x01
+
+/* do we gracefully implement usb suspend? */
+#define F_SUSPEND_ENABLED 1
+
+/* defines which interrupts are handled */
+#define ISR_MSK (CNTR_CTRM | \
+ CNTR_WKUPM | \
+ CNTR_SUSPM | \
+ CNTR_ERRM | \
+ CNTR_SOFM | \
+ CNTR_ESOFM | \
+ CNTR_RESETM \
+ )
+
+typedef enum _RESUME_STATE {
+ RESUME_EXTERNAL,
+ RESUME_INTERNAL,
+ RESUME_LATER,
+ RESUME_WAIT,
+ RESUME_START,
+ RESUME_ON,
+ RESUME_OFF,
+ RESUME_ESOF
+} RESUME_STATE;
+
+typedef enum _DEVICE_STATE {
+ UNCONNECTED,
+ ATTACHED,
+ POWERED,
+ SUSPENDED,
+ ADDRESSED,
+ CONFIGURED
+} DEVICE_STATE;
+
+void setupUSB(void);
+void usbAppInit(void); /* singleton usb initializer */
+
+void usbSuspend(void);
+void usbResumeInit(void);
+void usbResume(RESUME_STATE state);
+RESULT usbPowerOn(void);
+RESULT usbPowerOff(void);
+
+/* internal functions (as per the usb_core pProperty structure) */
+void usbInit(void);
+void usbReset(void);
+void usbStatusIn(void);
+void usbStatusOut(void);
+
+RESULT usbDataSetup(u8 request);
+RESULT usbNoDataSetup(u8 request);
+RESULT usbGetInterfaceSetting(u8, u8);
+
+u8 *usbGetDeviceDescriptor(u16 length);
+u8 *usbGetConfigDescriptor(u16 length);
+u8 *usbGetStringDescriptor(u16 length);
+u8 *usbGetFunctionalDescriptor(u16 length);
+
+/* internal callbacks to respond to standard requests */
+void usbGetConfiguration(void);
+void usbSetConfiguration(void);
+void usbGetInterface(void);
+void usbSetInterface(void);
+void usbGetStatus(void);
+void usbClearFeature(void);
+void usbSetEndpointFeature(void);
+void usbSetDeviceFeature(void);
+void usbSetDeviceAddress(void);
+
+/* the small number of comm emulator functions to
+ eventually be migrated into their own usart sources
+*/
+u8 *vcomGetLineCoding(u16 length);
+u8 *vcomSetLineCoding(u16 length);
+void vcomEp1In(void);
+void vcomEp3Out(void);
+
+/* Interrupt setup/handling exposed only so that
+ its obvious from main what interrupts are overloaded
+ from c_only_startup.s (see the top of main.c) */
+void usbDsbISR(void);
+void usbEnbISR(void);
+
+/* override the weakly defined isr in linker */
+void USB_LP_CAN1_RX0_IRQHandler(void);
+
+
+void nothingProc(void);
+
+#endif
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_callbacks.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb_callbacks.c
new file mode 100755
index 0000000..6881efe
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_callbacks.c
@@ -0,0 +1,31 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @file usb_callbacks.c
+ *
+ * @brief aka endpoints: handling data transfer when "Configured". calls out to
+ * application specific callbacks (eg DFU)
+ *
+ */
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.c
new file mode 100755
index 0000000..3a0c7f0
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.c
@@ -0,0 +1,193 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+
+/**
+ * @file usb_descriptor.c
+ *
+ * @brief aka application descriptor; big static struct and callbacks for sending
+ * the descriptor.
+ *
+ */
+
+
+#include "usb_descriptor.h"
+
+u8 u8_usbDeviceDescriptorDFU[18] = {
+ 0x12, /* bLength */
+ 0x01, /* bDescriptorType */
+ 0x00, /* bcdUSB, version 1.00 */
+ 0x01,
+ 0x00, /* bDeviceClass : See interface */
+ 0x00, /* bDeviceSubClass : See interface*/
+ 0x00, /* bDeviceProtocol : See interface */
+ bMaxPacketSize, /* bMaxPacketSize0 0x40 = 64 */
+ VEND_ID0, /* idVendor (0110) */
+ VEND_ID1,
+
+ PROD_ID0, /* idProduct (0x1001 or 1002) */
+ PROD_ID1,
+
+ 0x01, /* bcdDevice*/
+ 0x02,
+ 0x01, /* iManufacturer : index of string Manufacturer */
+ 0x02, /* iProduct : index of string descriptor of product*/
+ 0x03, /* iSerialNumber : index of string serial number*/
+ 0x01 /*bNumConfigurations */
+};
+
+ONE_DESCRIPTOR usbDeviceDescriptorDFU = {
+ u8_usbDeviceDescriptorDFU,
+ 0x12
+};
+
+u8 u8_usbFunctionalDescriptor[9] = {
+ /******************** DFU Functional Descriptor********************/
+ 0x09, /*blength = 7 Bytes*/
+ 0x21, /* DFU Functional Descriptor*/
+ 0x03, /*bmAttributes, bitCanDnload | bitCanUpload */
+ 0xFF, /*DetachTimeOut= 255 ms*/
+ 0x00,
+ (wTransferSize & 0x00FF),
+ (wTransferSize & 0xFF00) >> 8, /* TransferSize = 1024 Byte*/
+ 0x10, /* bcdDFUVersion = 1.1 */
+ 0x01
+};
+
+ONE_DESCRIPTOR usbFunctionalDescriptor = {
+ u8_usbFunctionalDescriptor,
+ 0x09
+};
+
+
+u8 u8_usbConfigDescriptorDFU[36] = {
+ 0x09, /* bLength: Configuation Descriptor size */
+ 0x02, /* bDescriptorType: Configuration */
+ 0x24, /* wTotalLength: Bytes returned */
+ 0x00,
+ 0x01, /* bNumInterfaces: 1 interface */
+ 0x01, /* bConfigurationValue: */
+ 0x00, /* iConfiguration: */
+ 0x80, /* bmAttributes: */
+ 0x32, /* MaxPower 100 mA */
+ /* 09 */
+
+ /************ Descriptor of DFU interface 0 Alternate setting 0 *********/
+ 0x09, /* bLength: Interface Descriptor size */
+ 0x04, /* bDescriptorType: */
+ 0x00, /* bInterfaceNumber: Number of Interface */
+ 0x00, /* bAlternateSetting: Alternate setting */
+ 0x00, /* bNumEndpoints*/
+ 0xFE, /* bInterfaceClass: DFU */
+ 0x01, /* bInterfaceSubClass */
+
+ 0x02, /* nInterfaceProtocol, switched to 0x02 while in dfu_mode */
+
+ 0x04, /* iInterface: */
+
+ /************ Descriptor of DFU interface 0 Alternate setting 1 *********/
+ 0x09, /* bLength: Interface Descriptor size */
+ 0x04, /* bDescriptorType: */
+ 0x00, /* bInterfaceNumber: Number of Interface */
+ 0x01, /* bAlternateSetting: Alternate setting */
+ 0x00, /* bNumEndpoints*/
+ 0xFE, /* bInterfaceClass: DFU */
+ 0x01, /* bInterfaceSubClass */
+
+ 0x02, /* nInterfaceProtocol, switched to 0x02 while in dfu_mode */
+
+ 0x05, /* iInterface: */
+
+ /******************** DFU Functional Descriptor********************/
+ 0x09, /*blength = 7 Bytes*/
+ 0x21, /* DFU Functional Descriptor*/
+ 0x03, /*bmAttributes, bitCanDnload | bitCanUpload */
+ 0xFF, /*DetachTimeOut= 255 ms*/
+ 0x00,
+ (wTransferSize & 0x00FF),
+ (wTransferSize & 0xFF00) >> 8, /* TransferSize = 1024 Byte*/
+ 0x10, /* bcdDFUVersion = 1.1 */
+ 0x01
+ /***********************************************************/
+ /*36*/
+};
+
+ONE_DESCRIPTOR usbConfigDescriptorDFU = {
+ u8_usbConfigDescriptorDFU,
+ 0x24
+};
+
+u8 u8_usbStringLangId[0x04] = {
+ 0x04,
+ 0x03,
+ 0x09,
+ 0x04 /* LangID = 0x0409: U.S. English */
+};
+
+u8 u8_usbStringVendor[0x12] = {
+ 0x12,
+ 0x03,
+ 'L', 0, 'e', 0, 'a', 0, 'f', 0, 'L', 0, 'a', 0, 'b', 0, 's', 0
+};
+
+u8 u8_usbStringProduct[0x14] = {
+ 0x14,
+ 0x03,
+ 'M', 0, 'a', 0, 'p', 0, 'l', 0, 'e', 0, ' ', 0, '0', 0, '0', 0, '3', 0
+};
+
+u8 u8_usbStringSerial[0x10] = {
+ 0x10,
+ 0x03,
+ 'L', 0, 'L', 0, 'M', 0, ' ', 0, '0', 0, '0', 0, '3', 0
+};
+
+u8 u8_usbStringAlt0[0x36] = {
+ 0x36,
+ 0x03,
+ 'D', 0, 'F', 0, 'U', 0, ' ', 0, 'P', 0, 'r', 0, 'o', 0, 'g', 0, 'r', 0,
+ 'a', 0, 'm', 0, ' ', 0, 'R', 0, 'A', 0, 'M', 0, ' ', 0, '0', 0, 'x', 0,
+ '2', 0, '0', 0, '0', 0, '0', 0, '0', 0, 'C', 0, '0', 0, '0', 0
+};
+
+u8 u8_usbStringAlt1[0x3A] = {
+ 0x3A,
+ 0x03,
+ 'D', 0, 'F', 0, 'U', 0, ' ', 0, 'P', 0, 'r', 0, 'o', 0, 'g', 0, 'r', 0,
+ 'a', 0, 'm', 0, ' ', 0, 'F', 0, 'L', 0, 'A', 0, 'S', 0, 'H', 0, ' ', 0,
+ '0', 0, 'x', 0, '0', 0, '8', 0, '0', 0, '0', 0, '5', 0, '0', 0, '0', 0,
+ '0', 0
+};
+
+u8 u8_usbStringInterface = NULL;
+
+ONE_DESCRIPTOR usbStringDescriptor[STR_DESC_LEN] = {
+ { (u8 *)u8_usbStringLangId, 0x04 },
+ { (u8 *)u8_usbStringVendor, 0x12 },
+ { (u8 *)u8_usbStringProduct, 0x20 },
+ { (u8 *)u8_usbStringSerial, 0x10 },
+ { (u8 *)u8_usbStringAlt0, 0x36 },
+ { (u8 *)u8_usbStringAlt1, 0x3A }
+};
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.h
new file mode 100755
index 0000000..963f480
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_descriptor.h
@@ -0,0 +1,40 @@
+/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+#ifndef __MAPLE_USB_DESC_H
+#define __MAPLE_USB_DESC_H
+
+#include "common.h"
+#include "usb_lib.h"
+#include "usb.h"
+
+#define NUM_ALT_SETTINGS 2
+#define STR_DESC_LEN 6
+
+extern ONE_DESCRIPTOR usbDeviceDescriptorDFU;
+extern ONE_DESCRIPTOR usbConfigDescriptorDFU;
+extern ONE_DESCRIPTOR usbStringDescriptor[6];
+extern ONE_DESCRIPTOR usbFunctionalDescriptor;
+
+#endif
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_conf.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_conf.h
new file mode 100755
index 0000000..e17fc7a
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_conf.h
@@ -0,0 +1,86 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_conf.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Device Firmware Upgrade (DFU) configuration file
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_CONF_H
+#define __USB_CONF_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+/* External variables --------------------------------------------------------*/
+/*-------------------------------------------------------------*/
+/* EP_NUM */
+/* defines how many endpoints are used by the device */
+/*-------------------------------------------------------------*/
+#define EP_NUM (1)
+
+/*-------------------------------------------------------------*/
+/* -------------- Buffer Description Table -----------------*/
+/*-------------------------------------------------------------*/
+/* buffer table base address */
+/* buffer table base address */
+#define BTABLE_ADDRESS (0x00)
+
+/* EP0 */
+/* rx/tx buffer base address */
+#define ENDP0_RXADDR (0x10)
+#define ENDP0_TXADDR (0x50)
+
+
+/*-------------------------------------------------------------*/
+/* ------------------- ISTR events -------------------------*/
+/*-------------------------------------------------------------*/
+/* IMR_MSK */
+/* mask defining which events has to be handled */
+/* by the device application software */
+#define IMR_MSK (CNTR_CTRM | \
+ CNTR_WKUPM | \
+ CNTR_SUSPM | \
+ CNTR_ERRM | \
+ CNTR_SOFM | \
+ CNTR_ESOFM | \
+ CNTR_RESETM \
+ )
+
+/* CTR service routines */
+/* associated to defined endpoints */
+#define EP1_IN_Callback NOP_Process
+#define EP2_IN_Callback NOP_Process
+#define EP3_IN_Callback NOP_Process
+#define EP4_IN_Callback NOP_Process
+#define EP5_IN_Callback NOP_Process
+#define EP6_IN_Callback NOP_Process
+#define EP7_IN_Callback NOP_Process
+
+
+#define EP1_OUT_Callback NOP_Process
+#define EP2_OUT_Callback NOP_Process
+#define EP3_OUT_Callback NOP_Process
+#define EP4_OUT_Callback NOP_Process
+#define EP5_OUT_Callback NOP_Process
+#define EP6_OUT_Callback NOP_Process
+#define EP7_OUT_Callback NOP_Process
+
+
+#endif /*__USB_CONF_H*/
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+
+
+
+
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.c
new file mode 100755
index 0000000..50f5111
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.c
@@ -0,0 +1,1013 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_core.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Standard protocol processing (USB v2.0)
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+#define ValBit(VAR,Place) (VAR & (1 << Place))
+#define SetBit(VAR,Place) (VAR |= (1 << Place))
+#define ClrBit(VAR,Place) (VAR &= ((1 << Place) ^ 255))
+
+#define Send0LengthData() { _SetEPTxCount(ENDP0, 0); \
+ vSetEPTxStatus(EP_TX_VALID); \
+ }
+
+#define vSetEPRxStatus(st) (SaveRState = st)
+#define vSetEPTxStatus(st) (SaveTState = st)
+
+#define USB_StatusIn() Send0LengthData()
+#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
+
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+u16_u8 StatusInfo;
+bool Data_Mul_MaxPacketSize = FALSE;
+/* Private function prototypes -----------------------------------------------*/
+static void DataStageOut(void);
+static void DataStageIn(void);
+static void NoData_Setup0(void);
+static void Data_Setup0(void);
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : Standard_GetConfiguration.
+* Description : Return the current configuration variable address.
+* Input : Length - How many bytes are needed.
+* Output : None.
+* Return : Return 1 , if the request is invalid when "Length" is 0.
+* Return "Buffer" if the "Length" is not 0.
+*******************************************************************************/
+u8 *Standard_GetConfiguration(u16 Length)
+{
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength =
+ sizeof(pInformation->Current_Configuration);
+ return 0;
+ }
+ pUser_Standard_Requests->User_GetConfiguration();
+ return (u8 *)&pInformation->Current_Configuration;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetConfiguration.
+* Description : This routine is called to set the configuration value
+* Then each class should configure device themself.
+* Input : None.
+* Output : None.
+* Return : Return USB_SUCCESS, if the request is performed.
+* Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetConfiguration(void)
+{
+
+ if ((pInformation->USBwValue0 <=
+ Device_Table.Total_Configuration) && (pInformation->USBwValue1 == 0)
+ && (pInformation->USBwIndex == 0)) /*call Back usb spec 2.0*/
+ {
+ pInformation->Current_Configuration = pInformation->USBwValue0;
+ pUser_Standard_Requests->User_SetConfiguration();
+ return USB_SUCCESS;
+ }
+ else
+ {
+ return USB_UNSUPPORT;
+ }
+}
+
+/*******************************************************************************
+* Function Name : Standard_GetInterface.
+* Description : Return the Alternate Setting of the current interface.
+* Input : Length - How many bytes are needed.
+* Output : None.
+* Return : Return 0, if the request is invalid when "Length" is 0.
+* Return "Buffer" if the "Length" is not 0.
+*******************************************************************************/
+u8 *Standard_GetInterface(u16 Length)
+{
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength =
+ sizeof(pInformation->Current_AlternateSetting);
+ return 0;
+ }
+ pUser_Standard_Requests->User_GetInterface();
+ return (u8 *)&pInformation->Current_AlternateSetting;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetInterface.
+* Description : This routine is called to set the interface.
+* Then each class should configure the interface them self.
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetInterface(void)
+{
+ RESULT Re;
+ /*Test if the specified Interface and Alternate Setting are supported by
+ the application Firmware*/
+ Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, pInformation->USBwValue0);
+
+ if (pInformation->Current_Configuration != 0)
+ {
+ if ((Re != USB_SUCCESS) || (pInformation->USBwIndex1 != 0)
+ || (pInformation->USBwValue1 != 0))
+ {
+ return USB_UNSUPPORT;
+ }
+ else if (Re == USB_SUCCESS)
+ {
+ pUser_Standard_Requests->User_SetInterface();
+ pInformation->Current_Interface = pInformation->USBwIndex0;
+ pInformation->Current_AlternateSetting = pInformation->USBwValue0;
+ return USB_SUCCESS;
+ }
+
+ }
+
+ return USB_UNSUPPORT;
+}
+
+/*******************************************************************************
+* Function Name : Standard_GetStatus.
+* Description : Copy the device request data to "StatusInfo buffer".
+* Input : - Length - How many bytes are needed.
+* Output : None.
+* Return : Return 0, if the request is at end of data block,
+* or is invalid when "Length" is 0.
+*******************************************************************************/
+u8 *Standard_GetStatus(u16 Length)
+{
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength = 2;
+ return 0;
+ }
+
+ StatusInfo.w = 0;
+ /* Reset Status Information */
+
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ /*Get Device Status */
+ u8 Feature = pInformation->Current_Feature;
+
+ /* Remote Wakeup enabled */
+ if (ValBit(Feature, 5))
+ {
+ SetBit(StatusInfo0, 1);
+ }
+
+ /* Bus-powered */
+ if (ValBit(Feature, 6))
+ {
+ ClrBit(StatusInfo0, 0);
+ }
+ else /* Self-powered */
+ {
+ SetBit(StatusInfo0, 0);
+ }
+ }
+ /*Interface Status*/
+ else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ {
+ return (u8 *)&StatusInfo;
+ }
+ /*Get EndPoint Status*/
+ else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {
+ u8 Related_Endpoint;
+ u8 wIndex0 = pInformation->USBwIndex0;
+
+ Related_Endpoint = (wIndex0 & 0x0f);
+ if (ValBit(wIndex0, 7))
+ {
+ /* IN endpoint */
+ if (_GetTxStallStatus(Related_Endpoint))
+ {
+ SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
+ }
+ }
+ else
+ {
+ /* OUT endpoint */
+ if (_GetRxStallStatus(Related_Endpoint))
+ {
+ SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
+ }
+ }
+
+ }
+ else
+ {
+ return NULL;
+ }
+ pUser_Standard_Requests->User_GetStatus();
+ return (u8 *)&StatusInfo;
+}
+
+/*******************************************************************************
+* Function Name : Standard_ClearFeature.
+* Description : Clear or disable a specific feature.
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_ClearFeature(void)
+{
+ u32 Type_Rec = Type_Recipient;
+ u32 Status;
+
+
+ if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {/*Device Clear Feature*/
+ ClrBit(pInformation->Current_Feature, 5);
+ return USB_SUCCESS;
+ }
+ else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {/*EndPoint Clear Feature*/
+ DEVICE* pDev;
+ u32 Related_Endpoint;
+ u32 wIndex0;
+ u32 rEP;
+
+ if ((pInformation->USBwValue != ENDPOINT_STALL)
+ || (pInformation->USBwIndex1 != 0))
+ {
+ return USB_UNSUPPORT;
+ }
+
+ pDev = &Device_Table;
+ wIndex0 = pInformation->USBwIndex0;
+ rEP = wIndex0 & ~0x80;
+ Related_Endpoint = ENDP0 + rEP;
+
+ if (ValBit(pInformation->USBwIndex0, 7))
+ {
+ /*Get Status of endpoint & stall the request if the related_ENdpoint
+ is Disabled*/
+ Status = _GetEPTxStatus(Related_Endpoint);
+ }
+ else
+ {
+ Status = _GetEPRxStatus(Related_Endpoint);
+ }
+
+ if ((rEP >= pDev->Total_Endpoint) || (Status == 0)
+ || (pInformation->Current_Configuration == 0))
+ {
+ return USB_UNSUPPORT;
+ }
+
+
+ if (wIndex0 & 0x80)
+ {
+ /* IN endpoint */
+ if (_GetTxStallStatus(Related_Endpoint ))
+ {
+ ClearDTOG_TX(Related_Endpoint);
+ SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
+ }
+ }
+ else
+ {
+ /* OUT endpoint */
+ if (_GetRxStallStatus(Related_Endpoint))
+ {
+ if (Related_Endpoint == ENDP0)
+ {
+ /* After clear the STALL, enable the default endpoint receiver */
+ SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
+ _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
+ }
+ else
+ {
+ ClearDTOG_RX(Related_Endpoint);
+ _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
+ }
+ }
+ }
+ pUser_Standard_Requests->User_ClearFeature();
+ return USB_SUCCESS;
+ }
+
+ return USB_UNSUPPORT;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetEndPointFeature
+* Description : Set or enable a specific feature of EndPoint
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetEndPointFeature(void)
+{
+ u32 wIndex0;
+ u32 Related_Endpoint;
+ u32 rEP;
+ u32 Status;
+
+ wIndex0 = pInformation->USBwIndex0;
+ rEP = wIndex0 & ~0x80;
+ Related_Endpoint = ENDP0 + rEP;
+
+ if (ValBit(pInformation->USBwIndex0, 7))
+ {
+ /* get Status of endpoint & stall the request if the related_ENdpoint
+ is Disabled*/
+ Status = _GetEPTxStatus(Related_Endpoint);
+ }
+ else
+ {
+ Status = _GetEPRxStatus(Related_Endpoint);
+ }
+
+ if (Related_Endpoint >= Device_Table.Total_Endpoint
+ || pInformation->USBwValue != 0 || Status == 0
+ || pInformation->Current_Configuration == 0)
+ {
+ return USB_UNSUPPORT;
+ }
+ else
+ {
+ if (wIndex0 & 0x80)
+ {
+ /* IN endpoint */
+ _SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
+ }
+
+ else
+ {
+ /* OUT endpoint */
+ _SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
+ }
+ }
+ pUser_Standard_Requests->User_SetEndPointFeature();
+ return USB_SUCCESS;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetDeviceFeature.
+* Description : Set or enable a specific feature of Device.
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetDeviceFeature(void)
+{
+ SetBit(pInformation->Current_Feature, 5);
+ pUser_Standard_Requests->User_SetDeviceFeature();
+ return USB_SUCCESS;
+}
+
+/*******************************************************************************
+* Function Name : Standard_GetDescriptorData.
+* Description : Standard_GetDescriptorData is used for descriptors transfer.
+* : This routine is used for the descriptors resident in Flash
+* or RAM
+* pDesc can be in either Flash or RAM
+* The purpose of this routine is to have a versatile way to
+* response descriptors request. It allows user to generate
+* certain descriptors with software or read descriptors from
+* external storage part by part.
+* Input : - Length - Length of the data in this transfer.
+* - pDesc - A pointer points to descriptor struct.
+* The structure gives the initial address of the descriptor and
+* its original size.
+* Output : None.
+* Return : Address of a part of the descriptor pointed by the Usb_
+* wOffset The buffer pointed by this address contains at least
+* Length bytes.
+*******************************************************************************/
+u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
+{
+ u32 wOffset;
+
+ wOffset = pInformation->Ctrl_Info.Usb_wOffset;
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
+ return 0;
+ }
+
+ return pDesc->Descriptor + wOffset;
+}
+
+/*******************************************************************************
+* Function Name : DataStageOut.
+* Description : Data stage of a Control Write Transfer.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void DataStageOut(void)
+{
+ ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
+ u32 save_rLength;
+
+ save_rLength = pEPinfo->Usb_rLength;
+
+ if (pEPinfo->CopyData && save_rLength)
+ {
+ u8 *Buffer;
+ u32 Length;
+
+ Length = pEPinfo->PacketSize;
+ if (Length > save_rLength)
+ {
+ Length = save_rLength;
+ }
+
+ Buffer = (*pEPinfo->CopyData)(Length);
+ pEPinfo->Usb_rLength -= Length;
+ pEPinfo->Usb_rOffset += Length;
+
+ PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length);
+ }
+
+ if (pEPinfo->Usb_rLength != 0)
+ {
+ vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */
+ SetEPTxCount(ENDP0, 0);
+ vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */
+ }
+ /* Set the next State*/
+ if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
+ {
+ pInformation->ControlState = OUT_DATA;
+ }
+ else
+ {
+ if (pEPinfo->Usb_rLength > 0)
+ {
+ pInformation->ControlState = LAST_OUT_DATA;
+ }
+ else if (pEPinfo->Usb_rLength == 0)
+ {
+ pInformation->ControlState = WAIT_STATUS_IN;
+ USB_StatusIn();
+ }
+ }
+}
+
+/*******************************************************************************
+* Function Name : DataStageIn.
+* Description : Data stage of a Control Read Transfer.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void DataStageIn(void)
+{
+ ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
+ u32 save_wLength = pEPinfo->Usb_wLength;
+ u32 ControlState = pInformation->ControlState;
+
+ u8 *DataBuffer;
+ u32 Length;
+
+ if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
+ {
+ if(Data_Mul_MaxPacketSize == TRUE)
+ {
+ /* No more data to send and empty packet */
+ Send0LengthData();
+ ControlState = LAST_IN_DATA;
+ Data_Mul_MaxPacketSize = FALSE;
+ }
+ else
+ {
+ /* No more data to send so STALL the TX Status*/
+ ControlState = WAIT_STATUS_OUT;
+ vSetEPTxStatus(EP_TX_STALL);
+ }
+
+ goto Expect_Status_Out;
+ }
+
+ Length = pEPinfo->PacketSize;
+ ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
+
+ if (Length > save_wLength)
+ {
+ Length = save_wLength;
+ }
+
+ DataBuffer = (*pEPinfo->CopyData)(Length);
+
+ UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
+
+ SetEPTxCount(ENDP0, Length);
+
+ pEPinfo->Usb_wLength -= Length;
+ pEPinfo->Usb_wOffset += Length;
+ vSetEPTxStatus(EP_TX_VALID);
+
+ USB_StatusOut();/* Expect the host to abort the data IN stage */
+
+Expect_Status_Out:
+ pInformation->ControlState = ControlState;
+}
+
+/*******************************************************************************
+* Function Name : NoData_Setup0.
+* Description : Proceed the processing of setup request without data stage.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void NoData_Setup0(void)
+{
+ RESULT Result = USB_UNSUPPORT;
+ u32 RequestNo = pInformation->USBbRequest;
+ u32 ControlState;
+
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ /* Device Request*/
+ /* SET_CONFIGURATION*/
+ if (RequestNo == SET_CONFIGURATION)
+ {
+ Result = Standard_SetConfiguration();
+ }
+
+ /*SET ADDRESS*/
+ else if (RequestNo == SET_ADDRESS)
+ {
+ if ((pInformation->USBwValue0 > 127) || (pInformation->USBwValue1 != 0)
+ || (pInformation->USBwIndex != 0)
+ || (pInformation->Current_Configuration != 0))
+ /* Device Address should be 127 or less*/
+ {
+ ControlState = STALLED;
+ goto exit_NoData_Setup0;
+ }
+ else
+ {
+ Result = USB_SUCCESS;
+ }
+ }
+ /*SET FEATURE for Device*/
+ else if (RequestNo == SET_FEATURE)
+ {
+ if ((pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP)
+ && (pInformation->USBwIndex == 0)
+ && (ValBit(pInformation->Current_Feature, 5)))
+ {
+ Result = Standard_SetDeviceFeature();
+ }
+ else
+ {
+ Result = USB_UNSUPPORT;
+ }
+ }
+ /*Clear FEATURE for Device */
+ else if (RequestNo == CLEAR_FEATURE)
+ {
+ if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
+ && pInformation->USBwIndex == 0
+ && ValBit(pInformation->Current_Feature, 5))
+ {
+ Result = Standard_ClearFeature();
+ }
+ else
+ {
+ Result = USB_UNSUPPORT;
+ }
+ }
+
+ }
+
+ /* Interface Request*/
+ else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ {
+ /*SET INTERFACE*/
+ if (RequestNo == SET_INTERFACE)
+ {
+ Result = Standard_SetInterface();
+ }
+ }
+
+ /* EndPoint Request*/
+ else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {
+ /*CLEAR FEATURE for EndPoint*/
+ if (RequestNo == CLEAR_FEATURE)
+ {
+ Result = Standard_ClearFeature();
+ }
+ /* SET FEATURE for EndPoint*/
+ else if (RequestNo == SET_FEATURE)
+ {
+ Result = Standard_SetEndPointFeature();
+ }
+ }
+ else
+ {
+ Result = USB_UNSUPPORT;
+ }
+
+
+ if (Result != USB_SUCCESS)
+ {
+ Result = (*pProperty->Class_NoData_Setup)(RequestNo);
+ if (Result == USB_NOT_READY)
+ {
+ ControlState = PAUSE;
+ goto exit_NoData_Setup0;
+ }
+ }
+
+ if (Result != USB_SUCCESS)
+ {
+ ControlState = STALLED;
+ goto exit_NoData_Setup0;
+ }
+
+ ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */
+
+ USB_StatusIn();
+
+exit_NoData_Setup0:
+ pInformation->ControlState = ControlState;
+ return;
+}
+
+/*******************************************************************************
+* Function Name : Data_Setup0.
+* Description : Proceed the processing of setup request with data stage.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Data_Setup0(void)
+{
+ u8 *(*CopyRoutine)(u16);
+ RESULT Result;
+ u32 Request_No = pInformation->USBbRequest;
+
+ u32 Related_Endpoint, Reserved;
+ u32 wOffset, Status;
+
+
+
+ CopyRoutine = NULL;
+ wOffset = 0;
+
+ if (Request_No == GET_DESCRIPTOR)
+ {
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ u8 wValue1 = pInformation->USBwValue1;
+ if (wValue1 == DEVICE_DESCRIPTOR)
+ {
+ CopyRoutine = pProperty->GetDeviceDescriptor;
+ }
+ else if (wValue1 == CONFIG_DESCRIPTOR)
+ {
+ CopyRoutine = pProperty->GetConfigDescriptor;
+ }
+ else if (wValue1 == STRING_DESCRIPTOR)
+ {
+ CopyRoutine = pProperty->GetStringDescriptor;
+ } else if (wValue1 == 0x21) /* added to support functional descriptors */
+ {
+ CopyRoutine = pProperty->GetFunctionalDescriptor;
+ } /* End of GET_DESCRIPTOR */
+ }
+ }
+
+ /*GET STATUS*/
+ else if ((Request_No == GET_STATUS) && (pInformation->USBwValue == 0)
+ && (pInformation->USBwLength == 0x0002)
+ && (pInformation->USBwIndex1 == 0))
+ {
+ /* GET STATUS for Device*/
+ if ((Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ && (pInformation->USBwIndex == 0))
+ {
+ CopyRoutine = Standard_GetStatus;
+ }
+
+ /* GET STATUS for Interface*/
+ else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ {
+ if (((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS)
+ && (pInformation->Current_Configuration != 0))
+ {
+ CopyRoutine = Standard_GetStatus;
+ }
+ }
+
+ /* GET STATUS for EndPoint*/
+ else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {
+ Related_Endpoint = (pInformation->USBwIndex0 & 0x0f);
+ Reserved = pInformation->USBwIndex0 & 0x70;
+
+ if (ValBit(pInformation->USBwIndex0, 7))
+ {
+ /*Get Status of endpoint & stall the request if the related_ENdpoint
+ is Disabled*/
+ Status = _GetEPTxStatus(Related_Endpoint);
+ }
+ else
+ {
+ Status = _GetEPRxStatus(Related_Endpoint);
+ }
+
+ if ((Related_Endpoint < Device_Table.Total_Endpoint) && (Reserved == 0)
+ && (Status != 0))
+ {
+ CopyRoutine = Standard_GetStatus;
+ }
+ }
+
+ }
+
+ /*GET CONFIGURATION*/
+ else if (Request_No == GET_CONFIGURATION)
+ {
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ CopyRoutine = Standard_GetConfiguration;
+ }
+ }
+ /*GET INTERFACE*/
+ else if (Request_No == GET_INTERFACE)
+ {
+ if ((Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ && (pInformation->Current_Configuration != 0) && (pInformation->USBwValue == 0)
+ && (pInformation->USBwIndex1 == 0) && (pInformation->USBwLength == 0x0001)
+ && ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS))
+ {
+ CopyRoutine = Standard_GetInterface;
+ }
+
+ }
+
+ if (CopyRoutine)
+ {
+ pInformation->Ctrl_Info.Usb_wOffset = wOffset;
+ pInformation->Ctrl_Info.CopyData = CopyRoutine;
+ /* sb in the original the cast to word was directly */
+ /* now the cast is made step by step */
+ (*CopyRoutine)(0);
+ Result = USB_SUCCESS;
+ }
+ else
+ {
+ Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest);
+ if (Result == USB_NOT_READY)
+ {
+ pInformation->ControlState = PAUSE;
+ return;
+ }
+ }
+
+ if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF)
+ {
+ /* Data is not ready, wait it */
+ pInformation->ControlState = PAUSE;
+ return;
+ }
+ if ((Result == USB_UNSUPPORT) || (pInformation->Ctrl_Info.Usb_wLength == 0))
+ {
+ /* Unsupported request */
+ pInformation->ControlState = STALLED;
+ return;
+ }
+
+
+ if (ValBit(pInformation->USBbmRequestType, 7))
+ {
+ /* Device ==> Host */
+ vu32 wLength = pInformation->USBwLength;
+
+ /* Restrict the data length to be the one host asks */
+ if (pInformation->Ctrl_Info.Usb_wLength > wLength)
+ {
+ pInformation->Ctrl_Info.Usb_wLength = wLength;
+ }
+
+ else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength)
+ {
+ if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize)
+ {
+ Data_Mul_MaxPacketSize = FALSE;
+ }
+ else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0)
+ {
+ Data_Mul_MaxPacketSize = TRUE;
+ }
+ }
+
+ pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
+ DataStageIn();
+ }
+ else
+ {
+ pInformation->ControlState = OUT_DATA;
+ vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */
+ }
+
+ return;
+}
+
+/*******************************************************************************
+* Function Name : Setup0_Process
+* Description : Get the device request data and dispatch to individual process.
+* Input : None.
+* Output : None.
+* Return : Post0_Process.
+*******************************************************************************/
+u8 Setup0_Process(void)
+{
+
+ union
+ {
+ u8* b;
+ u16* w;
+ } pBuf;
+
+ pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
+
+ if (pInformation->ControlState != PAUSE)
+ {
+ pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
+ pInformation->USBbRequest = *pBuf.b++; /* bRequest */
+ pBuf.w++; /* word not accessed because of 32 bits addressing */
+ pInformation->USBwValue = *pBuf.w++; /* wValue in Little Endian */
+ pBuf.w++; /* word not accessed because of 32 bits addressing */
+ pInformation->USBwIndex = *pBuf.w++; /* wIndex in Little Endian */
+ pBuf.w++; /* word not accessed because of 32 bits addressing */
+ pInformation->USBwLength = *pBuf.w; /* wLength in Little Endian */
+ }
+
+ pInformation->ControlState = SETTING_UP;
+ if (pInformation->USBwLength == 0)
+ {
+ /* Setup with no data stage */
+ NoData_Setup0();
+ }
+ else
+ {
+ /* Setup with data stage */
+ Data_Setup0();
+ }
+ return Post0_Process();
+}
+
+/*******************************************************************************
+* Function Name : In0_Process
+* Description : Process the IN token on all default endpoint.
+* Input : None.
+* Output : None.
+* Return : Post0_Process.
+*******************************************************************************/
+u8 In0_Process(void)
+{
+ u32 ControlState = pInformation->ControlState;
+
+ if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
+ {
+ DataStageIn();
+ /* ControlState may be changed outside the function */
+ ControlState = pInformation->ControlState;
+ }
+
+ else if (ControlState == WAIT_STATUS_IN)
+ {
+ if ((pInformation->USBbRequest == SET_ADDRESS) &&
+ (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)))
+ {
+ SetDeviceAddress(pInformation->USBwValue0);
+ pUser_Standard_Requests->User_SetDeviceAddress();
+ }
+ (*pProperty->Process_Status_IN)();
+ ControlState = STALLED;
+ }
+
+ else
+ {
+ ControlState = STALLED;
+ }
+
+ pInformation->ControlState = ControlState;
+
+ return Post0_Process();
+}
+
+/*******************************************************************************
+* Function Name : Out0_Process
+* Description : Process the OUT token on all default endpoint.
+* Input : None.
+* Output : None.
+* Return : Post0_Process.
+*******************************************************************************/
+u8 Out0_Process(void)
+{
+ u32 ControlState = pInformation->ControlState;
+
+ if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
+ {
+ DataStageOut();
+ ControlState = pInformation->ControlState; /* may be changed outside the function */
+ }
+
+ else if (ControlState == WAIT_STATUS_OUT)
+ {
+ (*pProperty->Process_Status_OUT)();
+ ControlState = STALLED;
+ }
+
+ else if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
+ {
+ /* host aborts the transfer before finish */
+ ControlState = STALLED;
+ }
+
+ /* Unexpect state, STALL the endpoint */
+ else
+ {
+ ControlState = STALLED;
+ }
+
+ pInformation->ControlState = ControlState;
+
+ return Post0_Process();
+}
+
+/*******************************************************************************
+* Function Name : Post0_Process
+* Description : Stall the Endpoint 0 in case of error.
+* Input : None.
+* Output : None.
+* Return : - 0 if the control State is in PAUSE
+* - 1 if not.
+*******************************************************************************/
+u8 Post0_Process(void)
+{
+ SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
+
+ if (pInformation->ControlState == STALLED)
+ {
+ vSetEPRxStatus(EP_RX_STALL);
+ vSetEPTxStatus(EP_TX_STALL);
+ }
+
+ return (pInformation->ControlState == PAUSE);
+}
+
+/*******************************************************************************
+* Function Name : SetDeviceAddress.
+* Description : Set the device and all the used Endpoints addresses.
+* Input : - Val: device adress.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetDeviceAddress(u8 Val)
+{
+ u32 i;
+ u32 nEP = Device_Table.Total_Endpoint;
+
+ /* set address in every used endpoint */
+ for (i = 0; i < nEP; i++)
+ {
+ _SetEPAddress((u8)i, (u8)i);
+ } /* for */
+ _SetDADDR(Val | DADDR_EF); /* set device address and enable function */
+}
+
+/*******************************************************************************
+* Function Name : NOP_Process
+* Description : No operation function.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void NOP_Process(void)
+{
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.h
new file mode 100755
index 0000000..4a5e0df
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_core.h
@@ -0,0 +1,247 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_core.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Standard protocol processing functions prototypes
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_CORE_H
+#define __USB_CORE_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+typedef enum _CONTROL_STATE
+{
+ WAIT_SETUP, /* 0 */
+ SETTING_UP, /* 1 */
+ IN_DATA, /* 2 */
+ OUT_DATA, /* 3 */
+ LAST_IN_DATA, /* 4 */
+ LAST_OUT_DATA, /* 5 */
+ WAIT_STATUS_IN, /* 7 */
+ WAIT_STATUS_OUT, /* 8 */
+ STALLED, /* 9 */
+ PAUSE /* 10 */
+} CONTROL_STATE; /* The state machine states of a control pipe */
+
+typedef struct OneDescriptor
+{
+ u8 *Descriptor;
+ u16 Descriptor_Size;
+}
+ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
+/* All the request process routines return a value of this type
+ If the return value is not SUCCESS or NOT_READY,
+ the software will STALL the correspond endpoint */
+typedef enum _RESULT
+{
+ USB_SUCCESS = 0, /* Process sucessfully */
+ USB_ERROR,
+ USB_UNSUPPORT,
+ USB_NOT_READY /* The process has not been finished, endpoint will be
+ NAK to further rquest */
+} RESULT;
+
+
+/*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/
+typedef struct _ENDPOINT_INFO
+{
+ /* When send data out of the device,
+ CopyData() is used to get data buffer 'Length' bytes data
+ if Length is 0,
+ CopyData() returns the total length of the data
+ if the request is not supported, returns 0
+ (NEW Feature )
+ if CopyData() returns -1, the calling routine should not proceed
+ further and will resume the SETUP process by the class device
+ if Length is not 0,
+ CopyData() returns a pointer to indicate the data location
+ Usb_wLength is the data remain to be sent,
+ Usb_wOffset is the Offset of original data
+ When receive data from the host,
+ CopyData() is used to get user data buffer which is capable
+ of Length bytes data to copy data from the endpoint buffer.
+ if Length is 0,
+ CopyData() returns the available data length,
+ if Length is not 0,
+ CopyData() returns user buffer address
+ Usb_rLength is the data remain to be received,
+ Usb_rPointer is the Offset of data buffer
+ */
+ u16 Usb_wLength;
+ u16 Usb_wOffset;
+ u16 PacketSize;
+ u8 *(*CopyData)(u16 Length);
+}ENDPOINT_INFO;
+
+/*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/
+
+typedef struct _DEVICE
+{
+ u8 Total_Endpoint; /* Number of endpoints that are used */
+ u8 Total_Configuration;/* Number of configuration available */
+}
+DEVICE;
+
+typedef union
+{
+ u16 w;
+ struct BW
+ {
+ /* Little Endian */
+ u8 bb0;
+ u8 bb1;
+ }
+ bw;
+} u16_u8;
+
+typedef struct _DEVICE_INFO
+{
+ u8 USBbmRequestType; /* bmRequestType */
+ u8 USBbRequest; /* bRequest */
+ u16_u8 USBwValues; /* wValue */
+ u16_u8 USBwIndexs; /* wIndex */
+ u16_u8 USBwLengths; /* wLength */
+
+ u8 ControlState; /* of type CONTROL_STATE */
+ u8 Current_Feature;
+ u8 Current_Configuration; /* Selected configuration */
+ u8 Current_Interface; /* Selected interface of current configuration */
+ u8 Current_AlternateSetting;/* Selected Alternate Setting of current
+ interface*/
+
+ ENDPOINT_INFO Ctrl_Info;
+}DEVICE_INFO;
+
+typedef struct _DEVICE_PROP
+{
+ void (*Init)(void); /* Initialize the device */
+ void (*Reset)(void); /* Reset routine of this device */
+
+ /* Device dependent process after the status stage */
+ void (*Process_Status_IN)(void);
+ void (*Process_Status_OUT)(void);
+
+ /* Procedure of process on setup stage of a class specified request with data stage */
+ /* All class specified requests with data stage are processed in Class_Data_Setup
+ Class_Data_Setup()
+ responses to check all special requests and fills ENDPOINT_INFO
+ according to the request
+ If IN tokens are expected, then wLength & wOffset will be filled
+ with the total transferring bytes and the starting position
+ If OUT tokens are expected, then rLength & rOffset will be filled
+ with the total expected bytes and the starting position in the buffer
+
+ If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT
+
+ CAUTION:
+ Since GET_CONFIGURATION & GET_INTERFACE are highly related to
+ the individual classes, they will be checked and processed here.
+ */
+ RESULT (*Class_Data_Setup)(u8 RequestNo);
+
+ /* Procedure of process on setup stage of a class specified request without data stage */
+ /* All class specified requests without data stage are processed in Class_NoData_Setup
+ Class_NoData_Setup
+ responses to check all special requests and perform the request
+
+ CAUTION:
+ Since SET_CONFIGURATION & SET_INTERFACE are highly related to
+ the individual classes, they will be checked and processed here.
+ */
+ RESULT (*Class_NoData_Setup)(u8 RequestNo);
+
+ /*Class_Get_Interface_Setting
+ This function is used by the file usb_core.c to test if the selected Interface
+ and Alternate Setting (u8 Interface, u8 AlternateSetting) are supported by
+ the application.
+ This function is writing by user. It should return "SUCCESS" if the Interface
+ and Alternate Setting are supported by the application or "UNSUPPORT" if they
+ are not supported. */
+
+ RESULT (*Class_Get_Interface_Setting)(u8 Interface, u8 AlternateSetting);
+
+ u8* (*GetDeviceDescriptor)(u16 Length);
+ u8* (*GetConfigDescriptor)(u16 Length);
+ u8* (*GetStringDescriptor)(u16 Length);
+ u8* (*GetFunctionalDescriptor)(u16 Length);
+
+ u8* RxEP_buffer;
+ u8 MaxPacketSize;
+
+}DEVICE_PROP;
+
+typedef struct _USER_STANDARD_REQUESTS
+{
+ void (*User_GetConfiguration)(void); /* Get Configuration */
+ void (*User_SetConfiguration)(void); /* Set Configuration */
+ void (*User_GetInterface)(void); /* Get Interface */
+ void (*User_SetInterface)(void); /* Set Interface */
+ void (*User_GetStatus)(void); /* Get Status */
+ void (*User_ClearFeature)(void); /* Clear Feature */
+ void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */
+ void (*User_SetDeviceFeature)(void); /* Set Device Feature */
+ void (*User_SetDeviceAddress)(void); /* Set Device Address */
+}
+USER_STANDARD_REQUESTS;
+
+/* Exported constants --------------------------------------------------------*/
+#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
+
+#define Usb_rLength Usb_wLength
+#define Usb_rOffset Usb_wOffset
+
+#define USBwValue USBwValues.w
+#define USBwValue0 USBwValues.bw.bb0
+#define USBwValue1 USBwValues.bw.bb1
+#define USBwIndex USBwIndexs.w
+#define USBwIndex0 USBwIndexs.bw.bb0
+#define USBwIndex1 USBwIndexs.bw.bb1
+#define USBwLength USBwLengths.w
+#define USBwLength0 USBwLengths.bw.bb0
+#define USBwLength1 USBwLengths.bw.bb1
+#define StatusInfo0 StatusInfo.bw.bb0
+#define StatusInfo1 StatusInfo.bw.bb1
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+u8 Setup0_Process(void);
+u8 Post0_Process(void);
+u8 Out0_Process(void);
+u8 In0_Process(void);
+
+RESULT Standard_SetEndPointFeature(void);
+RESULT Standard_SetDeviceFeature(void);
+
+u8 *Standard_GetConfiguration(u16 Length);
+RESULT Standard_SetConfiguration(void);
+u8 *Standard_GetInterface(u16 Length);
+RESULT Standard_SetInterface(void);
+u8 *Standard_GetDescriptorData(u16 Length, PONE_DESCRIPTOR pDesc);
+
+u8 *Standard_GetStatus(u16 Length);
+RESULT Standard_ClearFeature(void);
+void SetDeviceAddress(u8);
+void NOP_Process(void);
+
+extern DEVICE_PROP Device_Property;
+extern USER_STANDARD_REQUESTS User_Standard_Requests;
+extern DEVICE Device_Table;
+extern DEVICE_INFO Device_Info;
+
+/* cells saving status during interrupt servicing */
+extern u16 SaveRState;
+extern u16 SaveTState;
+
+#endif /* __USB_CORE_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_def.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_def.h
new file mode 100755
index 0000000..cfc551c
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_def.h
@@ -0,0 +1,80 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_def.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Definitions related to USB Core
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_DEF_H
+#define __USB_DEF_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+typedef enum _RECIPIENT_TYPE
+{
+ DEVICE_RECIPIENT, /* Recipient device */
+ INTERFACE_RECIPIENT, /* Recipient interface */
+ ENDPOINT_RECIPIENT, /* Recipient endpoint */
+ OTHER_RECIPIENT
+} RECIPIENT_TYPE;
+
+
+typedef enum _STANDARD_REQUESTS
+{
+ GET_STATUS = 0,
+ CLEAR_FEATURE,
+ RESERVED1,
+ SET_FEATURE,
+ RESERVED2,
+ SET_ADDRESS,
+ GET_DESCRIPTOR,
+ SET_DESCRIPTOR,
+ GET_CONFIGURATION,
+ SET_CONFIGURATION,
+ GET_INTERFACE,
+ SET_INTERFACE,
+ TOTAL_sREQUEST, /* Total number of Standard request */
+ SYNCH_FRAME = 12
+} STANDARD_REQUESTS;
+
+/* Definition of "USBwValue" */
+typedef enum _DESCRIPTOR_TYPE
+{
+ DEVICE_DESCRIPTOR = 1,
+ CONFIG_DESCRIPTOR,
+ STRING_DESCRIPTOR,
+ INTERFACE_DESCRIPTOR,
+ ENDPOINT_DESCRIPTOR
+} DESCRIPTOR_TYPE;
+
+/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */
+typedef enum _FEATURE_SELECTOR
+{
+ ENDPOINT_STALL,
+ DEVICE_REMOTE_WAKEUP
+} FEATURE_SELECTOR;
+
+/* Exported constants --------------------------------------------------------*/
+/* Definition of "USBbmRequestType" */
+#define REQUEST_TYPE 0x60 /* Mask to get request type */
+#define STANDARD_REQUEST 0x00 /* Standard request */
+#define CLASS_REQUEST 0x20 /* Class request */
+#define VENDOR_REQUEST 0x40 /* Vendor request */
+
+#define RECIPIENT 0x1F /* Mask to get recipient */
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+#endif /* __USB_DEF_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.c
new file mode 100755
index 0000000..679dabe
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.c
@@ -0,0 +1,64 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_init.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Initialization routines & global variables
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* The number of current endpoint, it will be used to specify an endpoint */
+ u8 EPindex;
+/* The number of current device, it is an index to the Device_Table */
+/* u8 Device_no; */
+/* Points to the DEVICE_INFO structure of current device */
+/* The purpose of this register is to speed up the execution */
+DEVICE_INFO *pInformation;
+/* Points to the DEVICE_PROP structure of current device */
+/* The purpose of this register is to speed up the execution */
+DEVICE_PROP *pProperty;
+/* Temporary save the state of Rx & Tx status. */
+/* Whenever the Rx or Tx state is changed, its value is saved */
+/* in this variable first and will be set to the EPRB or EPRA */
+/* at the end of interrupt process */
+u16 SaveState ;
+u16 wInterrupt_Mask;
+DEVICE_INFO Device_Info;
+USER_STANDARD_REQUESTS *pUser_Standard_Requests;
+
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : USB_Init
+* Description : USB system initialization
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void USB_Init(void)
+{
+ pInformation = &Device_Info;
+ pInformation->ControlState = 2;
+ pProperty = &Device_Property;
+ pUser_Standard_Requests = &User_Standard_Requests;
+ /* Initialize devices one by one */
+
+ pProperty->Init();
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.h
new file mode 100755
index 0000000..7e8487d
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_init.h
@@ -0,0 +1,49 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_init.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Initialization routines & global variables
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_INIT_H
+#define __USB_INIT_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void USB_Init(void);
+
+/* External variables --------------------------------------------------------*/
+/* The number of current endpoint, it will be used to specify an endpoint */
+extern u8 EPindex;
+/* The number of current device, it is an index to the Device_Table */
+/*extern u8 Device_no; */
+/* Points to the DEVICE_INFO structure of current device */
+/* The purpose of this register is to speed up the execution */
+extern DEVICE_INFO* pInformation;
+/* Points to the DEVICE_PROP structure of current device */
+/* The purpose of this register is to speed up the execution */
+extern DEVICE_PROP* pProperty;
+/* Temporary save the state of Rx & Tx status. */
+/* Whenever the Rx or Tx state is changed, its value is saved */
+/* in this variable first and will be set to the EPRB or EPRA */
+/* at the end of interrupt process */
+extern USER_STANDARD_REQUESTS *pUser_Standard_Requests;
+
+extern u16 SaveState ;
+extern u16 wInterrupt_Mask;
+
+#endif /* __USB_INIT_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.c
new file mode 100755
index 0000000..28f80ce
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.c
@@ -0,0 +1,192 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_int.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Endpoint CTR (Low and High) interrupt's service routines
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+u16 SaveRState;
+u16 SaveTState;
+
+/* Extern variables ----------------------------------------------------------*/
+extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
+extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
+
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : CTR_LP.
+* Description : Low priority Endpoint Correct Transfer interrupt's service
+* routine.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void CTR_LP(void)
+{
+ u32 wEPVal = 0;
+ /* stay in loop while pending ints */
+ while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
+ {
+ _SetISTR((u16)CLR_CTR); /* clear CTR flag */
+ /* extract highest priority endpoint number */
+ EPindex = (u8)(wIstr & ISTR_EP_ID);
+ if (EPindex == 0)
+ {
+ /* Decode and service control endpoint interrupt */
+ /* calling related service routine */
+ /* (Setup0_Process, In0_Process, Out0_Process) */
+
+ /* save RX & TX status */
+ /* and set both to NAK */
+ SaveRState = _GetEPRxStatus(ENDP0);
+ SaveTState = _GetEPTxStatus(ENDP0);
+ _SetEPRxStatus(ENDP0, EP_RX_NAK);
+ _SetEPTxStatus(ENDP0, EP_TX_NAK);
+
+
+ /* DIR bit = origin of the interrupt */
+
+ if ((wIstr & ISTR_DIR) == 0)
+ {
+ /* DIR = 0 */
+
+ /* DIR = 0 => IN int */
+ /* DIR = 0 implies that (EP_CTR_TX = 1) always */
+
+
+ _ClearEP_CTR_TX(ENDP0);
+ In0_Process();
+
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+ else
+ {
+ /* DIR = 1 */
+
+ /* DIR = 1 & CTR_RX => SETUP or OUT int */
+ /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
+
+ wEPVal = _GetENDPOINT(ENDP0);
+ if ((wEPVal & EP_CTR_TX) != 0)
+ {
+ _ClearEP_CTR_TX(ENDP0);
+ In0_Process();
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+ else if ((wEPVal &EP_SETUP) != 0)
+ {
+ _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
+ Setup0_Process();
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+
+ else if ((wEPVal & EP_CTR_RX) != 0)
+ {
+ _ClearEP_CTR_RX(ENDP0);
+ Out0_Process();
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+ }
+ }/* if(EPindex == 0) */
+ else
+ {
+ /* Decode and service non control endpoints interrupt */
+
+ /* process related endpoint register */
+ wEPVal = _GetENDPOINT(EPindex);
+ if ((wEPVal & EP_CTR_RX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_RX(EPindex);
+
+ /* call OUT service function */
+ (*pEpInt_OUT[EPindex-1])();
+
+ } /* if((wEPVal & EP_CTR_RX) */
+
+ if ((wEPVal & EP_CTR_TX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_TX(EPindex);
+
+ /* call IN service function */
+ (*pEpInt_IN[EPindex-1])();
+ } /* if((wEPVal & EP_CTR_TX) != 0) */
+
+ }/* if(EPindex == 0) else */
+
+ }/* while(...) */
+}
+
+/*******************************************************************************
+* Function Name : CTR_HP.
+* Description : High Priority Endpoint Correct Transfer interrupt's service
+* routine.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void CTR_HP(void)
+{
+ u32 wEPVal = 0;
+
+ while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
+ {
+ _SetISTR((u16)CLR_CTR); /* clear CTR flag */
+ /* extract highest priority endpoint number */
+ EPindex = (u8)(wIstr & ISTR_EP_ID);
+ /* process related endpoint register */
+ wEPVal = _GetENDPOINT(EPindex);
+ if ((wEPVal & EP_CTR_RX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_RX(EPindex);
+
+ /* call OUT service function */
+ (*pEpInt_OUT[EPindex-1])();
+
+ } /* if((wEPVal & EP_CTR_RX) */
+ else if ((wEPVal & EP_CTR_TX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_TX(EPindex);
+
+ /* call IN service function */
+ (*pEpInt_IN[EPindex-1])();
+
+
+ } /* if((wEPVal & EP_CTR_TX) != 0) */
+
+ }/* while(...) */
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.h
new file mode 100755
index 0000000..ddc8b33
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_int.h
@@ -0,0 +1,33 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_int.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Endpoint CTR (Low and High) interrupt's service routines
+* prototypes
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_INT_H
+#define __USB_INT_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void CTR_LP(void);
+void CTR_HP(void);
+
+/* External variables --------------------------------------------------------*/
+
+#endif /* __USB_INT_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_lib.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_lib.h
new file mode 100755
index 0000000..4437b8d
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_lib.h
@@ -0,0 +1,37 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_lib.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : USB library include files
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_LIB_H
+#define __USB_LIB_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_type.h"
+#include "usb_regs.h"
+#include "usb_def.h"
+#include "usb_core.h"
+#include "usb_init.h"
+#include "usb_mem.h"
+#include "usb_int.h"
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+/* External variables --------------------------------------------------------*/
+
+#endif /* __USB_LIB_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.c
new file mode 100755
index 0000000..b72778c
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.c
@@ -0,0 +1,73 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_mem.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Utility functions for memory transfers to/from PMA
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+/*******************************************************************************
+* Function Name : UserToPMABufferCopy
+* Description : Copy a buffer from user memory area to packet memory area (PMA)
+* Input : - pbUsrBuf: pointer to user memory area.
+* - wPMABufAddr: address into PMA.
+* - wNBytes: no. of bytes to be copied.
+* Output : None.
+* Return : None .
+*******************************************************************************/
+void UserToPMABufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
+{
+ u32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
+ u32 i, temp1, temp2;
+ u16 *pdwVal;
+ pdwVal = (u16 *)(wPMABufAddr * 2 + PMAAddr);
+ for (i = n; i != 0; i--)
+ {
+ temp1 = (u16) * pbUsrBuf;
+ pbUsrBuf++;
+ temp2 = temp1 | (u16) * pbUsrBuf << 8;
+ *pdwVal++ = temp2;
+ pdwVal++;
+ pbUsrBuf++;
+ }
+}
+/*******************************************************************************
+* Function Name : PMAToUserBufferCopy
+* Description : Copy a buffer from user memory area to packet memory area (PMA)
+* Input : - pbUsrBuf = pointer to user memory area.
+* - wPMABufAddr = address into PMA.
+* - wNBytes = no. of bytes to be copied.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
+{
+ u32 n = (wNBytes + 1) >> 1;/* /2*/
+ u32 i;
+ u32 *pdwVal;
+ pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr);
+ for (i = n; i != 0; i--)
+ {
+ *(u16*)pbUsrBuf++ = *pdwVal++;
+ pbUsrBuf++;
+ }
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.h
new file mode 100755
index 0000000..f726b49
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_mem.h
@@ -0,0 +1,32 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_mem.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Utility prototypes functions for memory/PMA transfers
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_MEM_H
+#define __USB_MEM_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void UserToPMABufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes);
+void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes);
+
+/* External variables --------------------------------------------------------*/
+
+#endif /*__USB_MEM_H*/
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.c b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.c
new file mode 100755
index 0000000..b36bff3
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.c
@@ -0,0 +1,748 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_regs.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Interface functions to USB cell registers
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : SetCNTR.
+* Description : Set the CNTR register value.
+* Input : wRegValue: new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetCNTR(u16 wRegValue)
+{
+ _SetCNTR(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetCNTR.
+* Description : returns the CNTR register value.
+* Input : None.
+* Output : None.
+* Return : CNTR register Value.
+*******************************************************************************/
+u16 GetCNTR(void)
+{
+ return(_GetCNTR());
+}
+
+/*******************************************************************************
+* Function Name : SetISTR.
+* Description : Set the ISTR register value.
+* Input : wRegValue: new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetISTR(u16 wRegValue)
+{
+ _SetISTR(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetISTR
+* Description : Returns the ISTR register value.
+* Input : None.
+* Output : None.
+* Return : ISTR register Value
+*******************************************************************************/
+u16 GetISTR(void)
+{
+ return(_GetISTR());
+}
+
+/*******************************************************************************
+* Function Name : GetFNR
+* Description : Returns the FNR register value.
+* Input : None.
+* Output : None.
+* Return : FNR register Value
+*******************************************************************************/
+u16 GetFNR(void)
+{
+ return(_GetFNR());
+}
+
+/*******************************************************************************
+* Function Name : SetDADDR
+* Description : Set the DADDR register value.
+* Input : wRegValue: new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetDADDR(u16 wRegValue)
+{
+ _SetDADDR(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetDADDR
+* Description : Returns the DADDR register value.
+* Input : None.
+* Output : None.
+* Return : DADDR register Value
+*******************************************************************************/
+u16 GetDADDR(void)
+{
+ return(_GetDADDR());
+}
+
+/*******************************************************************************
+* Function Name : SetBTABLE
+* Description : Set the BTABLE.
+* Input : wRegValue: New register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetBTABLE(u16 wRegValue)
+{
+ _SetBTABLE(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetBTABLE.
+* Description : Returns the BTABLE register value.
+* Input : None.
+* Output : None.
+* Return : BTABLE address.
+*******************************************************************************/
+u16 GetBTABLE(void)
+{
+ return(_GetBTABLE());
+}
+
+/*******************************************************************************
+* Function Name : SetENDPOINT
+* Description : Setthe Endpoint register value.
+* Input : bEpNum: Endpoint Number.
+* wRegValue.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetENDPOINT(u8 bEpNum, u16 wRegValue)
+{
+ _SetENDPOINT(bEpNum, wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetENDPOINT
+* Description : Return the Endpoint register value.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint register value.
+*******************************************************************************/
+u16 GetENDPOINT(u8 bEpNum)
+{
+ return(_GetENDPOINT(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : SetEPType
+* Description : sets the type in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* wType: type definition.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPType(u8 bEpNum, u16 wType)
+{
+ _SetEPType(bEpNum, wType);
+}
+
+/*******************************************************************************
+* Function Name : GetEPType
+* Description : Returns the endpoint type.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Type
+*******************************************************************************/
+u16 GetEPType(u8 bEpNum)
+{
+ return(_GetEPType(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : SetEPTxStatus
+* Description : Set the status of Tx endpoint.
+* Input : bEpNum: Endpoint Number.
+* wState: new state.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxStatus(u8 bEpNum, u16 wState)
+{
+ _SetEPTxStatus(bEpNum, wState);
+}
+
+/*******************************************************************************
+* Function Name : SetEPRxStatus
+* Description : Set the status of Rx endpoint.
+* Input : bEpNum: Endpoint Number.
+* wState: new state.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxStatus(u8 bEpNum, u16 wState)
+{
+ _SetEPRxStatus(bEpNum, wState);
+}
+
+/*******************************************************************************
+* Function Name : SetDouBleBuffEPStall
+* Description : sets the status for Double Buffer Endpoint to STALL
+* Input : bEpNum: Endpoint Number.
+* bDir: Endpoint direction.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetDouBleBuffEPStall(u8 bEpNum, u8 bDir)
+{
+ u16 Endpoint_DTOG_Status;
+ Endpoint_DTOG_Status = GetENDPOINT(bEpNum);
+ if (bDir == EP_DBUF_OUT)
+ { /* OUT double buffered endpoint */
+ _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1);
+ }
+ else if (bDir == EP_DBUF_IN)
+ { /* IN double buffered endpoint */
+ _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1);
+ }
+}
+
+/*******************************************************************************
+* Function Name : GetEPTxStatus
+* Description : Returns the endpoint Tx status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint TX Status
+*******************************************************************************/
+u16 GetEPTxStatus(u8 bEpNum)
+{
+ return(_GetEPTxStatus(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : GetEPRxStatus
+* Description : Returns the endpoint Rx status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint RX Status
+*******************************************************************************/
+u16 GetEPRxStatus(u8 bEpNum)
+{
+ return(_GetEPRxStatus(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : SetEPTxValid
+* Description : Valid the endpoint Tx Status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxValid(u8 bEpNum)
+{
+ _SetEPTxStatus(bEpNum, EP_TX_VALID);
+}
+
+/*******************************************************************************
+* Function Name : SetEPRxValid
+* Description : Valid the endpoint Rx Status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxValid(u8 bEpNum)
+{
+ _SetEPRxStatus(bEpNum, EP_RX_VALID);
+}
+
+/*******************************************************************************
+* Function Name : SetEP_KIND
+* Description : Clear the EP_KIND bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEP_KIND(u8 bEpNum)
+{
+ _SetEP_KIND(bEpNum);
+}
+
+/*******************************************************************************
+* Function Name : ClearEP_KIND
+* Description : set the EP_KIND bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEP_KIND(u8 bEpNum)
+{
+ _ClearEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : Clear_Status_Out
+* Description : Clear the Status Out of the related Endpoint
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Clear_Status_Out(u8 bEpNum)
+{
+ _ClearEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : Set_Status_Out
+* Description : Set the Status Out of the related Endpoint
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Set_Status_Out(u8 bEpNum)
+{
+ _SetEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : SetEPDoubleBuff
+* Description : Enable the double buffer feature for the endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDoubleBuff(u8 bEpNum)
+{
+ _SetEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearEPDoubleBuff
+* Description : Disable the double buffer feature for the endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEPDoubleBuff(u8 bEpNum)
+{
+ _ClearEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : GetTxStallStatus
+* Description : Returns the Stall status of the Tx endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Tx Stall status.
+*******************************************************************************/
+u16 GetTxStallStatus(u8 bEpNum)
+{
+ return(_GetTxStallStatus(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetRxStallStatus
+* Description : Returns the Stall status of the Rx endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx Stall status.
+*******************************************************************************/
+u16 GetRxStallStatus(u8 bEpNum)
+{
+ return(_GetRxStallStatus(bEpNum));
+}
+/*******************************************************************************
+* Function Name : ClearEP_CTR_RX
+* Description : Clear the CTR_RX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEP_CTR_RX(u8 bEpNum)
+{
+ _ClearEP_CTR_RX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearEP_CTR_TX
+* Description : Clear the CTR_TX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEP_CTR_TX(u8 bEpNum)
+{
+ _ClearEP_CTR_TX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ToggleDTOG_RX
+* Description : Toggle the DTOG_RX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ToggleDTOG_RX(u8 bEpNum)
+{
+ _ToggleDTOG_RX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ToggleDTOG_TX
+* Description : Toggle the DTOG_TX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ToggleDTOG_TX(u8 bEpNum)
+{
+ _ToggleDTOG_TX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearDTOG_RX.
+* Description : Clear the DTOG_RX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearDTOG_RX(u8 bEpNum)
+{
+ _ClearDTOG_RX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearDTOG_TX.
+* Description : Clear the DTOG_TX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearDTOG_TX(u8 bEpNum)
+{
+ _ClearDTOG_TX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : SetEPAddress
+* Description : Set the endpoint address.
+* Input : bEpNum: Endpoint Number.
+* bAddr: New endpoint address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPAddress(u8 bEpNum, u8 bAddr)
+{
+ _SetEPAddress(bEpNum, bAddr);
+}
+/*******************************************************************************
+* Function Name : GetEPAddress
+* Description : Get the endpoint address.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint address.
+*******************************************************************************/
+u8 GetEPAddress(u8 bEpNum)
+{
+ return(_GetEPAddress(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPTxAddr
+* Description : Set the endpoint Tx buffer address.
+* Input : bEpNum: Endpoint Number.
+* wAddr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxAddr(u8 bEpNum, u16 wAddr)
+{
+ _SetEPTxAddr(bEpNum, wAddr);
+}
+/*******************************************************************************
+* Function Name : SetEPRxAddr
+* Description : Set the endpoint Rx buffer address.
+* Input : bEpNum: Endpoint Number.
+* wAddr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxAddr(u8 bEpNum, u16 wAddr)
+{
+ _SetEPRxAddr(bEpNum, wAddr);
+}
+/*******************************************************************************
+* Function Name : GetEPTxAddr
+* Description : Returns the endpoint Tx buffer address.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx buffer address.
+*******************************************************************************/
+u16 GetEPTxAddr(u8 bEpNum)
+{
+ return(_GetEPTxAddr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPRxAddr.
+* Description : Returns the endpoint Rx buffer address.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx buffer address.
+*******************************************************************************/
+u16 GetEPRxAddr(u8 bEpNum)
+{
+ return(_GetEPRxAddr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPTxCount.
+* Description : Set the Tx count.
+* Input : bEpNum: Endpoint Number.
+* wCount: new count value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxCount(u8 bEpNum, u16 wCount)
+{
+ _SetEPTxCount(bEpNum, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPCountRxReg.
+* Description : Set the Count Rx Register value.
+* Input : *pdwReg: point to the register.
+* wCount: the new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPCountRxReg(u32 *pdwReg, u16 wCount)
+{
+ _SetEPCountRxReg(dwReg, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPRxCount
+* Description : Set the Rx count.
+* Input : bEpNum: Endpoint Number.
+* wCount: the new count value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxCount(u8 bEpNum, u16 wCount)
+{
+ _SetEPRxCount(bEpNum, wCount);
+}
+/*******************************************************************************
+* Function Name : GetEPTxCount
+* Description : Get the Tx count.
+* Input : bEpNum: Endpoint Number.
+* Output : None
+* Return : Tx count value.
+*******************************************************************************/
+u16 GetEPTxCount(u8 bEpNum)
+{
+ return(_GetEPTxCount(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPRxCount
+* Description : Get the Rx count.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx count value.
+*******************************************************************************/
+u16 GetEPRxCount(u8 bEpNum)
+{
+ return(_GetEPRxCount(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuffAddr
+* Description : Set the addresses of the buffer 0 and 1.
+* Input : bEpNum: Endpoint Number.
+* wBuf0Addr: new address of buffer 0.
+* wBuf1Addr: new address of buffer 1.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuffAddr(u8 bEpNum, u16 wBuf0Addr, u16 wBuf1Addr)
+{
+ _SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf0Addr
+* Description : Set the Buffer 1 address.
+* Input : bEpNum: Endpoint Number
+* wBuf0Addr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf0Addr(u8 bEpNum, u16 wBuf0Addr)
+{
+ _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf1Addr
+* Description : Set the Buffer 1 address.
+* Input : bEpNum: Endpoint Number
+* wBuf1Addr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf1Addr(u8 bEpNum, u16 wBuf1Addr)
+{
+ _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf0Addr
+* Description : Returns the address of the Buffer 0.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+u16 GetEPDblBuf0Addr(u8 bEpNum)
+{
+ return(_GetEPDblBuf0Addr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf1Addr
+* Description : Returns the address of the Buffer 1.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Address of the Buffer 1.
+*******************************************************************************/
+u16 GetEPDblBuf1Addr(u8 bEpNum)
+{
+ return(_GetEPDblBuf1Addr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuffCount
+* Description : Set the number of bytes for a double Buffer
+* endpoint.
+* Input : bEpNum,bDir, wCount
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuffCount(u8 bEpNum, u8 bDir, u16 wCount)
+{
+ _SetEPDblBuffCount(bEpNum, bDir, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf0Count
+* Description : Set the number of bytes in the buffer 0 of a double Buffer
+* endpoint.
+* Input : bEpNum, bDir, wCount
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf0Count(u8 bEpNum, u8 bDir, u16 wCount)
+{
+ _SetEPDblBuf0Count(bEpNum, bDir, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf1Count
+* Description : Set the number of bytes in the buffer 0 of a double Buffer
+* endpoint.
+* Input : bEpNum, bDir, wCount
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf1Count(u8 bEpNum, u8 bDir, u16 wCount)
+{
+ _SetEPDblBuf1Count(bEpNum, bDir, wCount);
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf0Count
+* Description : Returns the number of byte received in the buffer 0 of a double
+* Buffer endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Buffer 0 count
+*******************************************************************************/
+u16 GetEPDblBuf0Count(u8 bEpNum)
+{
+ return(_GetEPDblBuf0Count(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf1Count
+* Description : Returns the number of data received in the buffer 1 of a double
+* Buffer endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Buffer 1 count.
+*******************************************************************************/
+u16 GetEPDblBuf1Count(u8 bEpNum)
+{
+ return(_GetEPDblBuf1Count(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPDblBufDir
+* Description : gets direction of the double buffered endpoint
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : EP_DBUF_OUT, EP_DBUF_IN,
+* EP_DBUF_ERR if the endpoint counter not yet programmed.
+*******************************************************************************/
+EP_DBUF_DIR GetEPDblBufDir(u8 bEpNum)
+{
+ if ((u16)(*_pEPRxCount(bEpNum) & 0xFC00) != 0)
+ return(EP_DBUF_OUT);
+ else if (((u16)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0)
+ return(EP_DBUF_IN);
+ else
+ return(EP_DBUF_ERR);
+}
+/*******************************************************************************
+* Function Name : FreeUserBuffer
+* Description : free buffer used from the application realizing it to the line
+ toggles bit SW_BUF in the double buffered endpoint register
+* Input : bEpNum, bDir
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void FreeUserBuffer(u8 bEpNum, u8 bDir)
+{
+ if (bDir == EP_DBUF_OUT)
+ { /* OUT double buffered endpoint */
+ _ToggleDTOG_TX(bEpNum);
+ }
+ else if (bDir == EP_DBUF_IN)
+ { /* IN double buffered endpoint */
+ _ToggleDTOG_RX(bEpNum);
+ }
+}
+
+/*******************************************************************************
+* Function Name : ToWord
+* Description : merge two byte in a word.
+* Input : bh: byte high, bl: bytes low.
+* Output : None.
+* Return : resulted word.
+*******************************************************************************/
+u16 ToWord(u8 bh, u8 bl)
+{
+ u16 wRet;
+ wRet = (u16)bl | ((u16)bh << 8);
+ return(wRet);
+}
+/*******************************************************************************
+* Function Name : ByteSwap
+* Description : Swap two byte in a word.
+* Input : wSwW: word to Swap.
+* Output : None.
+* Return : resulted word.
+*******************************************************************************/
+u16 ByteSwap(u16 wSwW)
+{
+ u8 bTemp;
+ u16 wRet;
+ bTemp = (u8)(wSwW & 0xff);
+ wRet = (wSwW >> 8) | ((u16)bTemp << 8);
+ return(wRet);
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.h
new file mode 100755
index 0000000..6927f6e
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_regs.h
@@ -0,0 +1,619 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_regs.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Interface prototype functions to USB cell registers
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_REGS_H
+#define __USB_REGS_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+typedef enum _EP_DBUF_DIR
+{
+ /* double buffered endpoint direction */
+ EP_DBUF_ERR,
+ EP_DBUF_OUT,
+ EP_DBUF_IN
+}EP_DBUF_DIR;
+
+/* endpoint buffer number */
+enum EP_BUF_NUM
+{
+ EP_NOBUF,
+ EP_BUF0,
+ EP_BUF1
+};
+
+/* Exported constants --------------------------------------------------------*/
+#define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */
+#define PMAAddr (0x40006000L) /* USB_IP Packet Memory Area base address */
+
+/******************************************************************************/
+/* General registers */
+/******************************************************************************/
+
+/* Control register */
+#define CNTR ((volatile unsigned *)(RegBase + 0x40))
+/* Interrupt status register */
+#define ISTR ((volatile unsigned *)(RegBase + 0x44))
+/* Frame number register */
+#define FNR ((volatile unsigned *)(RegBase + 0x48))
+/* Device address register */
+#define DADDR ((volatile unsigned *)(RegBase + 0x4C))
+/* Buffer Table address register */
+#define BTABLE ((volatile unsigned *)(RegBase + 0x50))
+/******************************************************************************/
+/* Endpoint registers */
+/******************************************************************************/
+#define EP0REG ((volatile unsigned *)(RegBase)) /* endpoint 0 register address */
+
+/* endpoints enumeration */
+#define ENDP0 ((u8)0)
+#define ENDP1 ((u8)1)
+#define ENDP2 ((u8)2)
+#define ENDP3 ((u8)3)
+#define ENDP4 ((u8)4)
+#define ENDP5 ((u8)5)
+#define ENDP6 ((u8)6)
+#define ENDP7 ((u8)7)
+/******************************************************************************/
+/* ISTR interrupt events */
+/******************************************************************************/
+#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
+#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */
+#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */
+#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */
+#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */
+#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */
+#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */
+#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */
+
+
+#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */
+#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */
+
+#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */
+#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/
+#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */
+#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */
+#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */
+#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */
+#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */
+#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */
+
+/******************************************************************************/
+/* CNTR control register bits definitions */
+/******************************************************************************/
+#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */
+#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */
+#define CNTR_ERRM (0x2000) /* ERRor Mask */
+#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */
+#define CNTR_SUSPM (0x0800) /* SUSPend Mask */
+#define CNTR_RESETM (0x0400) /* RESET Mask */
+#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */
+#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */
+
+
+#define CNTR_RESUME (0x0010) /* RESUME request */
+#define CNTR_FSUSP (0x0008) /* Force SUSPend */
+#define CNTR_LPMODE (0x0004) /* Low-power MODE */
+#define CNTR_PDWN (0x0002) /* Power DoWN */
+#define CNTR_FRES (0x0001) /* Force USB RESet */
+
+/******************************************************************************/
+/* FNR Frame Number Register bit definitions */
+/******************************************************************************/
+#define FNR_RXDP (0x8000) /* status of D+ data line */
+#define FNR_RXDM (0x4000) /* status of D- data line */
+#define FNR_LCK (0x2000) /* LoCKed */
+#define FNR_LSOF (0x1800) /* Lost SOF */
+#define FNR_FN (0x07FF) /* Frame Number */
+/******************************************************************************/
+/* DADDR Device ADDRess bit definitions */
+/******************************************************************************/
+#define DADDR_EF (0x80)
+#define DADDR_ADD (0x7F)
+/******************************************************************************/
+/* Endpoint register */
+/******************************************************************************/
+/* bit positions */
+#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */
+#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */
+#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */
+#define EP_SETUP (0x0800) /* EndPoint SETUP */
+#define EP_T_FIELD (0x0600) /* EndPoint TYPE */
+#define EP_KIND (0x0100) /* EndPoint KIND */
+#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */
+#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */
+#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */
+#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */
+
+/* EndPoint REGister MASK (no toggle fields) */
+#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD)
+
+/* EP_TYPE[1:0] EndPoint TYPE */
+#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */
+#define EP_BULK (0x0000) /* EndPoint BULK */
+#define EP_CONTROL (0x0200) /* EndPoint CONTROL */
+#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
+#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
+#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK)
+
+
+/* EP_KIND EndPoint KIND */
+#define EPKIND_MASK (~EP_KIND & EPREG_MASK)
+
+/* STAT_TX[1:0] STATus for TX transfer */
+#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */
+#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */
+#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */
+#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */
+#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */
+#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */
+#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
+
+/* STAT_RX[1:0] STATus for RX transfer */
+#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */
+#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */
+#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */
+#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */
+#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */
+#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */
+#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)
+/* Exported macro ------------------------------------------------------------*/
+/* SetCNTR */
+#define _SetCNTR(wRegValue) (*CNTR = (u16)wRegValue)
+
+/* SetISTR */
+#define _SetISTR(wRegValue) (*ISTR = (u16)wRegValue)
+
+/* SetDADDR */
+#define _SetDADDR(wRegValue) (*DADDR = (u16)wRegValue)
+
+/* SetBTABLE */
+#define _SetBTABLE(wRegValue)(*BTABLE = (u16)(wRegValue & 0xFFF8))
+
+/* GetCNTR */
+#define _GetCNTR() ((u16) *CNTR)
+
+/* GetISTR */
+#define _GetISTR() ((u16) *ISTR)
+
+/* GetFNR */
+#define _GetFNR() ((u16) *FNR)
+
+/* GetDADDR */
+#define _GetDADDR() ((u16) *DADDR)
+
+/* GetBTABLE */
+#define _GetBTABLE() ((u16) *BTABLE)
+
+/* SetENDPOINT */
+#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
+ (u16)wRegValue)
+
+/* GetENDPOINT */
+#define _GetENDPOINT(bEpNum) ((u16)(*(EP0REG + bEpNum)))
+
+/*******************************************************************************
+* Macro Name : SetEPType
+* Description : sets the type in the endpoint register(bits EP_TYPE[1:0])
+* Input : bEpNum: Endpoint Number.
+* wType
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
+ ((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType)))
+
+/*******************************************************************************
+* Macro Name : GetEPType
+* Description : gets the type in the endpoint register(bits EP_TYPE[1:0])
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Type
+*******************************************************************************/
+#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
+
+/*******************************************************************************
+* Macro Name : SetEPTxStatus
+* Description : sets the status for tx transfer (bits STAT_TX[1:0]).
+* Input : bEpNum: Endpoint Number.
+* wState: new state
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxStatus(bEpNum,wState) {\
+ register u16 _wRegVal; \
+ _wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
+ /* toggle first bit ? */ \
+ if((EPTX_DTOG1 & wState)!= 0) \
+ _wRegVal ^= EPTX_DTOG1; \
+ /* toggle second bit ? */ \
+ if((EPTX_DTOG2 & wState)!= 0) \
+ _wRegVal ^= EPTX_DTOG2; \
+ _SetENDPOINT(bEpNum, _wRegVal); \
+ } /* _SetEPTxStatus */
+
+/*******************************************************************************
+* Macro Name : SetEPRxStatus
+* Description : sets the status for rx transfer (bits STAT_TX[1:0])
+* Input : bEpNum: Endpoint Number.
+* wState: new state.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPRxStatus(bEpNum,wState) {\
+ register u16 _wRegVal; \
+ \
+ _wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
+ /* toggle first bit ? */ \
+ if((EPRX_DTOG1 & wState)!= 0) \
+ _wRegVal ^= EPRX_DTOG1; \
+ /* toggle second bit ? */ \
+ if((EPRX_DTOG2 & wState)!= 0) \
+ _wRegVal ^= EPRX_DTOG2; \
+ _SetENDPOINT(bEpNum, _wRegVal); \
+ } /* _SetEPRxStatus */
+/*******************************************************************************
+* Macro Name : GetEPTxStatus / GetEPRxStatus
+* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0]
+* /STAT_RX[1:0])
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : status .
+*******************************************************************************/
+#define _GetEPTxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPTX_STAT)
+
+#define _GetEPRxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPRX_STAT)
+
+/*******************************************************************************
+* Macro Name : SetEPTxValid / SetEPRxValid
+* Description : sets directly the VALID tx/rx-status into the enpoint register
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
+
+#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
+
+/*******************************************************************************
+* Macro Name : GetTxStallStatus / GetRxStallStatus.
+* Description : checks stall condition in an endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : TRUE = endpoint in stall condition.
+*******************************************************************************/
+#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
+ == EP_TX_STALL)
+#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
+ == EP_RX_STALL)
+
+/*******************************************************************************
+* Macro Name : SetEP_KIND / ClearEP_KIND.
+* Description : set & clear EP_KIND bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
+ (_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))
+#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
+ (_GetENDPOINT(bEpNum) & EPKIND_MASK)))
+
+/*******************************************************************************
+* Macro Name : Set_Status_Out / Clear_Status_Out.
+* Description : Sets/clears directly STATUS_OUT bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
+#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
+
+/*******************************************************************************
+* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff.
+* Description : Sets/clears directly EP_KIND bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
+#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
+
+/*******************************************************************************
+* Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX.
+* Description : Clears bit CTR_RX / CTR_TX in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
+ _GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
+#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
+ _GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
+
+/*******************************************************************************
+* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX .
+* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
+ EP_DTOG_RX | _GetENDPOINT(bEpNum) & EPREG_MASK))
+#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
+ EP_DTOG_TX | _GetENDPOINT(bEpNum) & EPREG_MASK))
+
+/*******************************************************************************
+* Macro Name : ClearDTOG_RX / ClearDTOG_TX.
+* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
+ _ToggleDTOG_RX(bEpNum)
+#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
+ _ToggleDTOG_TX(bEpNum)
+/*******************************************************************************
+* Macro Name : SetEPAddress.
+* Description : Sets address in an endpoint register.
+* Input : bEpNum: Endpoint Number.
+* bAddr: Address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
+ _GetENDPOINT(bEpNum) & EPREG_MASK | bAddr)
+
+/*******************************************************************************
+* Macro Name : GetEPAddress.
+* Description : Gets address in an endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _GetEPAddress(bEpNum) ((u8)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
+
+#define _pEPTxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
+#define _pEPTxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
+#define _pEPRxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
+#define _pEPRxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
+
+/*******************************************************************************
+* Macro Name : SetEPTxAddr / SetEPRxAddr.
+* Description : sets address of the tx/rx buffer.
+* Input : bEpNum: Endpoint Number.
+* wAddr: address to be set (must be word aligned).
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
+#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
+
+/*******************************************************************************
+* Macro Name : GetEPTxAddr / GetEPRxAddr.
+* Description : Gets address of the tx/rx buffer.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : address of the buffer.
+*******************************************************************************/
+#define _GetEPTxAddr(bEpNum) ((u16)*_pEPTxAddr(bEpNum))
+#define _GetEPRxAddr(bEpNum) ((u16)*_pEPRxAddr(bEpNum))
+
+/*******************************************************************************
+* Macro Name : SetEPCountRxReg.
+* Description : Sets counter of rx buffer with no. of blocks.
+* Input : pdwReg: pointer to counter.
+* wCount: Counter.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
+ wNBlocks = wCount >> 5;\
+ if((wCount & 0x1f) == 0)\
+ wNBlocks--;\
+ *pdwReg = (u32)((wNBlocks << 10) | 0x8000);\
+ }/* _BlocksOf32 */
+
+#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
+ wNBlocks = wCount >> 1;\
+ if((wCount & 0x1) != 0)\
+ wNBlocks++;\
+ *pdwReg = (u32)(wNBlocks << 10);\
+ }/* _BlocksOf2 */
+
+#define _SetEPCountRxReg(dwReg,wCount) {\
+ u16 wNBlocks;\
+ if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
+ else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
+ }/* _SetEPCountRxReg */
+
+
+
+#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
+ u32 *pdwReg = _pEPTxCount(bEpNum); \
+ _SetEPCountRxReg(pdwReg, wCount);\
+ }
+/*******************************************************************************
+* Macro Name : SetEPTxCount / SetEPRxCount.
+* Description : sets counter for the tx/rx buffer.
+* Input : bEpNum: endpoint number.
+* wCount: Counter value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
+#define _SetEPRxCount(bEpNum,wCount) {\
+ u32 *pdwReg = _pEPRxCount(bEpNum); \
+ _SetEPCountRxReg(pdwReg, wCount);\
+ }
+/*******************************************************************************
+* Macro Name : GetEPTxCount / GetEPRxCount.
+* Description : gets counter of the tx buffer.
+* Input : bEpNum: endpoint number.
+* Output : None.
+* Return : Counter value.
+*******************************************************************************/
+#define _GetEPTxCount(bEpNum)((u16)(*_pEPTxCount(bEpNum)) & 0x3ff)
+#define _GetEPRxCount(bEpNum)((u16)(*_pEPRxCount(bEpNum)) & 0x3ff)
+
+/*******************************************************************************
+* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr.
+* Description : Sets buffer 0/1 address in a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* : wBuf0Addr: buffer 0 address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);}
+#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);}
+
+/*******************************************************************************
+* Macro Name : SetEPDblBuffAddr.
+* Description : Sets addresses in a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* : wBuf0Addr: buffer 0 address.
+* : wBuf1Addr = buffer 1 address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \
+ _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\
+ _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\
+ } /* _SetEPDblBuffAddr */
+
+/*******************************************************************************
+* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr.
+* Description : Gets buffer 0/1 address of a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum))
+#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum))
+
+/*******************************************************************************
+* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count.
+* Description : Gets buffer 0/1 address of a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* : bDir: endpoint dir EP_DBUF_OUT = OUT
+* EP_DBUF_IN = IN
+* : wCount: Counter value
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \
+ if(bDir == EP_DBUF_OUT)\
+ /* OUT endpoint */ \
+ {_SetEPRxDblBuf0Count(bEpNum,wCount);} \
+ else if(bDir == EP_DBUF_IN)\
+ /* IN endpoint */ \
+ *_pEPTxCount(bEpNum) = (u32)wCount; \
+ } /* SetEPDblBuf0Count*/
+
+#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
+ if(bDir == EP_DBUF_OUT)\
+ /* OUT endpoint */ \
+ {_SetEPRxCount(bEpNum,wCount);}\
+ else if(bDir == EP_DBUF_IN)\
+ /* IN endpoint */\
+ *_pEPRxCount(bEpNum) = (u32)wCount; \
+ } /* SetEPDblBuf1Count */
+
+#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
+ _SetEPDblBuf0Count(bEpNum, bDir, wCount); \
+ _SetEPDblBuf1Count(bEpNum, bDir, wCount); \
+ } /* _SetEPDblBuffCount */
+
+/*******************************************************************************
+* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count.
+* Description : Gets buffer 0/1 rx/tx counter for double buffering.
+* Input : bEpNum: endpoint number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum))
+#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum))
+
+
+/* External variables --------------------------------------------------------*/
+extern volatile u16 wIstr; /* ISTR register last read value */
+
+/* Exported functions ------------------------------------------------------- */
+void SetCNTR(u16 /*wRegValue*/);
+void SetISTR(u16 /*wRegValue*/);
+void SetDADDR(u16 /*wRegValue*/);
+void SetBTABLE(u16 /*wRegValue*/);
+u16 GetCNTR(void);
+u16 GetISTR(void);
+u16 GetFNR(void);
+u16 GetDADDR(void);
+u16 GetBTABLE(void);
+void SetENDPOINT(u8 /*bEpNum*/, u16 /*wRegValue*/);
+u16 GetENDPOINT(u8 /*bEpNum*/);
+void SetEPType(u8 /*bEpNum*/, u16 /*wType*/);
+u16 GetEPType(u8 /*bEpNum*/);
+void SetEPTxStatus(u8 /*bEpNum*/, u16 /*wState*/);
+void SetEPRxStatus(u8 /*bEpNum*/, u16 /*wState*/);
+void SetDouBleBuffEPStall(u8 /*bEpNum*/, u8 bDir);
+u16 GetEPTxStatus(u8 /*bEpNum*/);
+u16 GetEPRxStatus(u8 /*bEpNum*/);
+void SetEPTxValid(u8 /*bEpNum*/);
+void SetEPRxValid(u8 /*bEpNum*/);
+u16 GetTxStallStatus(u8 /*bEpNum*/);
+u16 GetRxStallStatus(u8 /*bEpNum*/);
+void SetEP_KIND(u8 /*bEpNum*/);
+void ClearEP_KIND(u8 /*bEpNum*/);
+void Set_Status_Out(u8 /*bEpNum*/);
+void Clear_Status_Out(u8 /*bEpNum*/);
+void SetEPDoubleBuff(u8 /*bEpNum*/);
+void ClearEPDoubleBuff(u8 /*bEpNum*/);
+void ClearEP_CTR_RX(u8 /*bEpNum*/);
+void ClearEP_CTR_TX(u8 /*bEpNum*/);
+void ToggleDTOG_RX(u8 /*bEpNum*/);
+void ToggleDTOG_TX(u8 /*bEpNum*/);
+void ClearDTOG_RX(u8 /*bEpNum*/);
+void ClearDTOG_TX(u8 /*bEpNum*/);
+void SetEPAddress(u8 /*bEpNum*/, u8 /*bAddr*/);
+u8 GetEPAddress(u8 /*bEpNum*/);
+void SetEPTxAddr(u8 /*bEpNum*/, u16 /*wAddr*/);
+void SetEPRxAddr(u8 /*bEpNum*/, u16 /*wAddr*/);
+u16 GetEPTxAddr(u8 /*bEpNum*/);
+u16 GetEPRxAddr(u8 /*bEpNum*/);
+void SetEPCountRxReg(u32 * /*pdwReg*/, u16 /*wCount*/);
+void SetEPTxCount(u8 /*bEpNum*/, u16 /*wCount*/);
+void SetEPRxCount(u8 /*bEpNum*/, u16 /*wCount*/);
+u16 GetEPTxCount(u8 /*bEpNum*/);
+u16 GetEPRxCount(u8 /*bEpNum*/);
+void SetEPDblBuf0Addr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/);
+void SetEPDblBuf1Addr(u8 /*bEpNum*/, u16 /*wBuf1Addr*/);
+void SetEPDblBuffAddr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/, u16 /*wBuf1Addr*/);
+u16 GetEPDblBuf0Addr(u8 /*bEpNum*/);
+u16 GetEPDblBuf1Addr(u8 /*bEpNum*/);
+void SetEPDblBuffCount(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
+void SetEPDblBuf0Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
+void SetEPDblBuf1Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
+u16 GetEPDblBuf0Count(u8 /*bEpNum*/);
+u16 GetEPDblBuf1Count(u8 /*bEpNum*/);
+EP_DBUF_DIR GetEPDblBufDir(u8 /*bEpNum*/);
+void FreeUserBuffer(u8 bEpNum/*bEpNum*/, u8 bDir);
+u16 ToWord(u8, u8);
+u16 ByteSwap(u16);
+
+#endif /* __USB_REGS_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_type.h b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_type.h
new file mode 100755
index 0000000..a40be61
--- /dev/null
+++ b/Arduino_STM32-MIDI/other/maple-bootloader/usb_lib/usb_type.h
@@ -0,0 +1,72 @@
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_type.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Type definitions used by the USB Library
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_TYPE_H
+#define __USB_TYPE_H
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#ifndef __STM32F10x_TYPE_H
+
+typedef signed long s32;
+typedef signed short s16;
+typedef signed char s8;
+
+typedef volatile signed long vs32;
+typedef volatile signed short vs16;
+typedef volatile signed char vs8;
+
+typedef unsigned long u32;
+typedef unsigned short u16;
+typedef unsigned char u8;
+
+typedef unsigned long const uc32; /* Read Only */
+typedef unsigned short const uc16; /* Read Only */
+typedef unsigned char const uc8; /* Read Only */
+
+typedef volatile unsigned long vu32;
+typedef volatile unsigned short vu16;
+typedef volatile unsigned char vu8;
+
+typedef volatile unsigned long const vuc32; /* Read Only */
+typedef volatile unsigned short const vuc16; /* Read Only */
+typedef volatile unsigned char const vuc8; /* Read Only */
+
+
+typedef enum
+{
+ FALSE = 0, TRUE = !FALSE
+}
+bool;
+
+typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus;
+
+typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
+
+typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
+#endif
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+/* External variables --------------------------------------------------------*/
+
+#endif /* __USB_TYPE_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/