diff --git a/usb_bootloader/STM32F1/Makefile b/usb_bootloader/STM32F1/Makefile index c3f85c5..ce17743 100644 --- a/usb_bootloader/STM32F1/Makefile +++ b/usb_bootloader/STM32F1/Makefile @@ -113,7 +113,7 @@ ELFSIZE = $(SIZE) -A $(TARGET).elf # go! all: begin gccversion build sizeafter finished end -maple-mini: begin gccversion build_maple-mini sizeafter finished end +maple-mini: begin gccversion build_maple-mini sizeafter finished copy_maple_mini end maple-rev3: begin gccversion build_maple-rev3 sizeafter finished end build: elf bin lss sym @@ -121,6 +121,12 @@ build: elf bin lss sym build_maple-mini: TARGETFLAGS= -DTARGET_MAPLE_MINI build_maple-mini: elf bin lss sym +copy_maple_mini: + @echo + @echo "Copying to binaries folder" + @echo + cp $(TARGET).bin binaries/maple_mini_boot20.bin + @echo build_maple-rev3: TARGETFLAGS= -DTARGET_MAPLE_REV3 build_maple-rev3: elf bin lss sym diff --git a/usb_bootloader/STM32F1/binaries/maple_mini_boot20.bin b/usb_bootloader/STM32F1/binaries/maple_mini_boot20.bin index b5bff46..b28cfcb 100644 Binary files a/usb_bootloader/STM32F1/binaries/maple_mini_boot20.bin and b/usb_bootloader/STM32F1/binaries/maple_mini_boot20.bin differ diff --git a/usb_bootloader/STM32F1/dfu.c b/usb_bootloader/STM32F1/dfu.c index e3754e9..14eef74 100644 --- a/usb_bootloader/STM32F1/dfu.c +++ b/usb_bootloader/STM32F1/dfu.c @@ -85,10 +85,13 @@ bool dfuUpdateByRequest(void) { dfuAppStatus.bState = dfuDNLOAD_SYNC; switch(pInformation->Current_AlternateSetting) { + /* + Roger Clark. removed upload to RAM option case 0: userAppAddr = USER_CODE_RAM; userUploadType = DFU_UPLOAD_RAM; break; + */ case 1: userAppAddr = USER_CODE_FLASH0X8005000; userUploadType = DFU_UPLOAD_FLASH_0X8005000; @@ -107,8 +110,9 @@ bool dfuUpdateByRequest(void) { flashUnlock(); break; default: - userAppAddr = USER_CODE_RAM; - userUploadType = DFU_UPLOAD_RAM; + // Roger Clark. Report error + dfuAppStatus.bState = dfuERROR; + dfuAppStatus.bStatus = errWRITE; break; } } else { @@ -125,9 +129,11 @@ bool dfuUpdateByRequest(void) { userFirmwareLen = uploadBlockLen * pInformation->USBwValue; switch(pInformation->Current_AlternateSetting) { + /* case 0: userAppAddr = USER_CODE_RAM; userAppEnd = RAM_END; + */ case 1: userAppAddr = USER_CODE_FLASH0X8005000; userAppEnd = FLASH_END; @@ -137,8 +143,11 @@ bool dfuUpdateByRequest(void) { userAppEnd = FLASH_END; break; default: - userAppAddr = USER_CODE_RAM; - userAppEnd = RAM_END; + // Roger Clark. + // Changed this to report error that its unable to write to this memory + // However the code should never get here as only AlternateSetting 1 and 2 are allowed (see above) + dfuAppStatus.bState = dfuERROR; + dfuAppStatus.bStatus = errWRITE; break; } } else if (pInformation->USBbRequest == DFU_ABORT) { @@ -158,10 +167,14 @@ bool dfuUpdateByRequest(void) { if (pInformation->USBbRequest == DFU_GETSTATUS) { /* todo, add routine to wait for last block write to finish */ - if (userUploadType == DFU_UPLOAD_RAM) { + + /* Roger Clark. Commented out code associated with RAM upload + + if (userUploadType == DFU_UPLOAD_RAM) + { if (code_copy_lock == WAIT) { code_copy_lock = BEGINNING; - dfuAppStatus.bwPollTimeout0 = 0x20; /* 32 ms */ + dfuAppStatus.bwPollTimeout0 = 0x20; // 32 ms dfuAppStatus.bwPollTimeout1 = 0x00; dfuAppStatus.bState = dfuDNBUSY; @@ -177,7 +190,10 @@ bool dfuUpdateByRequest(void) { dfuAppStatus.bState = dfuDNLOAD_IDLE; } - } else { + } + else + */ + { dfuAppStatus.bState = dfuDNLOAD_IDLE; dfuCopyBufferToExec(); } @@ -383,17 +399,21 @@ u8 *dfuCopyUPLOAD(u16 length) { void dfuCopyBufferToExec() { int i; u32 *userSpace; + +/* Roger Clark. + Commented out code associated with upload to RAM if (userUploadType == DFU_UPLOAD_RAM) { 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 */ + // 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 +*/ { if (userUploadType == DFU_UPLOAD_FLASH_0X8005000) { @@ -429,8 +449,15 @@ bool dfuUploadStarted() { } void dfuFinishUpload() { - while (1) { - if (userUploadType==DFU_UPLOAD_RAM) { + while (1) + { + __asm("nop"); + +/* Roger Clark. + Commented out code associated with upload to RAM + + if (userUploadType==DFU_UPLOAD_RAM) + { if (code_copy_lock == BEGINNING) { code_copy_lock = MIDDLE; strobePin(LED_BANK, LED, 2, 0x1000); @@ -439,6 +466,9 @@ void dfuFinishUpload() { code_copy_lock = END; } } + +*/ + /* otherwise do nothing, dfu state machine resets itself */ } } diff --git a/usb_bootloader/STM32F1/main.c b/usb_bootloader/STM32F1/main.c index 78585ca..494dd2b 100644 --- a/usb_bootloader/STM32F1/main.c +++ b/usb_bootloader/STM32F1/main.c @@ -61,31 +61,24 @@ int main() } } - if (userUploadType==DFU_UPLOAD_RAM) + + if (checkUserCode(USER_CODE_FLASH0X8002000)) { - // if we have just uploaded to RAM, then run whats in RAM - jumpToUser(USER_CODE_RAM); - } - else + jumpToUser(USER_CODE_FLASH0X8002000); + } + else { - // This may be an upload to flash or a cold boot - - if (checkUserCode(USER_CODE_FLASH0X8002000)) + if (checkUserCode(USER_CODE_FLASH0X8005000)) { - jumpToUser(USER_CODE_FLASH0X8002000); + jumpToUser(USER_CODE_FLASH0X8005000); } - else + else { - if (checkUserCode(USER_CODE_FLASH0X8005000)) - { - jumpToUser(USER_CODE_FLASH0X8005000); - } - else - { - // Nothing to execute in either Flash or RAM - strobePin(LED_BANK, LED, 5, BLINK_FAST); - systemHardReset(); - } + // Nothing to execute in either Flash or RAM + strobePin(LED_BANK, LED, 5, BLINK_FAST); + systemHardReset(); } } + + return 0;// Added to please the compiler } \ No newline at end of file diff --git a/usb_bootloader/STM32F1/usb_descriptor.c b/usb_bootloader/STM32F1/usb_descriptor.c index 14131b2..7883700 100644 --- a/usb_bootloader/STM32F1/usb_descriptor.c +++ b/usb_bootloader/STM32F1/usb_descriptor.c @@ -152,66 +152,85 @@ ONE_DESCRIPTOR usbConfigDescriptorDFU = { u8_usbConfigDescriptorDFU_LENGTH }; -u8 u8_usbStringLangId[0x04] = { - 0x04, +#define USB_STR_LANG_ID_LEN 0x04 +u8 u8_usbStringLangId[USB_STR_LANG_ID_LEN] = { + USB_STR_LANG_ID_LEN, 0x03, 0x09, 0x04 /* LangID = 0x0409: U.S. English */ }; - -u8 u8_usbStringVendor[0x12] = { - 0x12, +#define USB_VENDOR_STR_LEN 0x12 +u8 u8_usbStringVendor[USB_VENDOR_STR_LEN] = { + USB_VENDOR_STR_LEN, 0x03, 'L', 0, 'e', 0, 'a', 0, 'f', 0, 'L', 0, 'a', 0, 'b', 0, 's', 0 }; - -u8 u8_usbStringProduct[0x14] = { - 0x14, +#define USB_PRODUCT_STR_LEN 0x14 +u8 u8_usbStringProduct[USB_PRODUCT_STR_LEN] = { + USB_PRODUCT_STR_LEN, 0x03, 'M', 0, 'a', 0, 'p', 0, 'l', 0, 'e', 0, ' ', 0, '0', 0, '0', 0, '3', 0 }; - -u8 u8_usbStringSerial[0x10] = { - 0x10, +#define USB_SERIAL_STR_LEN 0x10 +u8 u8_usbStringSerial[USB_SERIAL_STR_LEN] = { + USB_SERIAL_STR_LEN, 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 +#define ALT0_STR_LEN 0x6A +u8 u8_usbStringAlt0[ALT0_STR_LEN] = { +ALT0_STR_LEN, +0x03, +'B',0,'o',0,'o',0,'t',0,'l',0,'o',0,'a',0,'d',0,'e',0,'r',0,' ',0,'2',0,'.',0,'0',0,' ',0,'E',0,'R',0,'R',0,'O',0,'R',0,'.',0,' ',0,'U',0,'p',0,'l',0,'o',0,'a',0,'d',0,' ',0,'t',0,'o',0,' ',0,'R',0,'A',0,'M',0,' ',0,'i',0,'s',0,' ',0,'n',0,'o',0,'t',0,' ',0,'s',0,'u',0,'p',0,'p',0,'o',0,'r',0,'t',0,'e',0,'d',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 +#define ALT1_STR_LEN 0x62 +u8 u8_usbStringAlt1[ALT1_STR_LEN] = { +ALT1_STR_LEN, +0x03, +'B',0,'o',0,'o',0,'t',0,'l',0,'o',0,'a',0,'d',0,'e',0,'r',0,' ',0,'2',0,'.',0,'0',0,' ',0,'U',0,'p',0,'l',0,'o',0,'a',0,'d',0,' ',0,'t',0,'o',0,' ',0,'F',0,'l',0,'a',0,'s',0,'h',0,' ',0,'a',0,'d',0,'d',0,'r',0,'e',0,'s',0,'s',0,' ',0,'0',0,'x',0,'8',0,'0',0,'0',0,'5',0,'0',0,'0',0,'0',0 }; -u8 u8_usbStringAlt2[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, '2', 0, '0', 0, '0', 0, - '0', 0 +#define ALT2_STR_LEN 0x62 +u8 u8_usbStringAlt2[ALT2_STR_LEN] = { +ALT2_STR_LEN, +0x03, +'B',0,'o',0,'o',0,'t',0,'l',0,'o',0,'a',0,'d',0,'e',0,'r',0,' ',0,'2',0,'.',0,'0',0,' ',0,'U',0,'p',0,'l',0,'o',0,'a',0,'d',0,' ',0,'t',0,'o',0,' ',0,'F',0,'l',0,'a',0,'s',0,'h',0,' ',0,'a',0,'d',0,'d',0,'r',0,'e',0,'s',0,'s',0,' ',0,'0',0,'x',0,'8',0,'0',0,'0',0,'2',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 }, - { (u8 *)u8_usbStringAlt2, 0x3A } + { (u8 *)u8_usbStringLangId, USB_STR_LANG_ID_LEN }, + { (u8 *)u8_usbStringVendor, USB_VENDOR_STR_LEN }, + { (u8 *)u8_usbStringProduct, USB_PRODUCT_STR_LEN }, + { (u8 *)u8_usbStringSerial, USB_SERIAL_STR_LEN }, + { (u8 *)u8_usbStringAlt0, ALT0_STR_LEN }, + { (u8 *)u8_usbStringAlt1, ALT1_STR_LEN }, + { (u8 *)u8_usbStringAlt2, ALT2_STR_LEN } }; - +/* + Roger. + Javascript utility to make new ALT ID text structs + + + + +*/