diff --git a/build/targets.device.mak b/build/targets.device.mak index 0f2a14fad..e743b80d6 100644 --- a/build/targets.device.mak +++ b/build/targets.device.mak @@ -43,3 +43,6 @@ products += $(patsubst %.$(EXE),%.map,$(filter %.$(EXE),$(products))) .PHONY: openocd openocd: openocd -f build/device/openocd.cfg + +flasher.$(EXE): LDFLAGS = --gc-sections -T ion/src/device/usb/flasher.ld +flasher.$(EXE): $(objs) $(usb_objs) ion/src/device/usb/flasher.o diff --git a/ion/src/device/usb/Makefile b/ion/src/device/usb/Makefile index 1cd6c6792..82c5539c2 100644 --- a/ion/src/device/usb/Makefile +++ b/ion/src/device/usb/Makefile @@ -34,19 +34,19 @@ objs += $(usb_objs) else -usb_objs += liba/src/assert.o -usb_objs += liba/src/strlen.o -usb_objs += liba/src/strlcpy.o -usb_objs += liba/src/memset.o -usb_objs += liba/src/memcpy.o -usb_objs += libaxx/src/cxxabi/pure_virtual.o -usb_objs += ion/src/device/usb/boot.o -usb_objs += ion/src/device/keyboard.o -usb_objs += ion/src/device/device.o -usb_objs += ion/src/device/usb.o +dfu_objs += liba/src/assert.o +dfu_objs += liba/src/strlen.o +dfu_objs += liba/src/strlcpy.o +dfu_objs += liba/src/memset.o +dfu_objs += liba/src/memcpy.o +dfu_objs += libaxx/src/cxxabi/pure_virtual.o +dfu_objs += ion/src/device/usb/boot.o +dfu_objs += ion/src/device/keyboard.o +dfu_objs += ion/src/device/device.o +dfu_objs += ion/src/device/usb.o -ion/src/device/usb/dfu.elf: LDFLAGS = --gc-sections -T ion/src/device/boot/dfu.ld -ion/src/device/usb/dfu.elf: $(usb_objs) +ion/src/device/usb/dfu.elf: LDFLAGS = --gc-sections -T ion/src/device/usb/dfu.ld +ion/src/device/usb/dfu.elf: $(usb_objs) $(dfu_objs) ion/src/device/usb/dfu.o: ion/src/device/usb/dfu.bin @echo "OBJCOPY $@" diff --git a/ion/src/device/boot/dfu.ld b/ion/src/device/usb/dfu.ld similarity index 100% rename from ion/src/device/boot/dfu.ld rename to ion/src/device/usb/dfu.ld diff --git a/ion/src/device/usb/flasher.cpp b/ion/src/device/usb/flasher.cpp new file mode 100644 index 000000000..d670ad8d7 --- /dev/null +++ b/ion/src/device/usb/flasher.cpp @@ -0,0 +1,8 @@ +#include "../regs/regs.h" +#include "../usb/calculator.h" + +void ion_main(int argc, char * argv[]) { + while (!OTG.GINTSTS()->getENUMDNE()) { + } + Ion::USB::Device::Calculator::Poll(); +} diff --git a/ion/src/device/usb/flasher.ld b/ion/src/device/usb/flasher.ld new file mode 100644 index 000000000..2ba52ecfa --- /dev/null +++ b/ion/src/device/usb/flasher.ld @@ -0,0 +1,68 @@ +/* Create a flash bridge. + * Load it at address 0x20004000 and execute it from there + * TODO: Explain the 16K offset (ST's DFU ROMed bootloader) + */ + +MEMORY { + RAM_BUFFER (rw) : ORIGIN = 0x20000000 + 16K, LENGTH = 256K - 16K +} + +STACK_SIZE = 4K; + +SECTIONS { + .isr_vector_table ORIGIN(RAM_BUFFER) : { + KEEP(*(.isr_vector_table)) + } >RAM_BUFFER + + .text : { + . = ALIGN(4); + *(.text) + *(.text.*) + } >RAM_BUFFER + + .init_array : { + . = ALIGN(4); + _init_array_start = .; + KEEP (*(.init_array*)) + _init_array_end = .; + } >RAM_BUFFER + + .rodata : { + . = ALIGN(4); + *(.rodata) + *(.rodata.*) + } >RAM_BUFFER + + .data : { + . = ALIGN(4); + *(.data) + *(.data.*) + } >RAM_BUFFER + + .bss : { + . = ALIGN(4); + _bss_section_start_ram = .; + *(.bss) + *(.bss.*) + *(COMMON) + _bss_section_end_ram = .; + } >RAM_BUFFER + + .stack : { + . = ALIGN(8); + _stack_end = .; + . += (STACK_SIZE - 8); + . = ALIGN(8); + _stack_start = .; + } >RAM_BUFFER + + .phony : { + /* We won't do dynamic memory allocation */ + _heap_start = .; + _heap_end = .; + /* Effectively bypass copying .data to RAM */ + _data_section_start_flash = .; + _data_section_start_ram = .; + _data_section_end_ram = .; + } >RAM_BUFFER +}