Skip to content

Commit 10861ba

Browse files
author
rogerclarkmelbourne
committed
Updated Bootloader 2.0 to remove RAM upload option. RAM upload now returns DFU error errWRITE ( 0x03) and displays the initial message 'Bootloader 2.0 ERROR. Upload to RAM is not supported'. Ram upload code has been commented out, definitions have been added for DFU alt strings to make them easier to change, not javascript util has been added at the bottom usb_description.c which can be used to generate modified DFU ALT ID descriptor text if needed
1 parent 0631786 commit 10861ba

5 files changed

Lines changed: 119 additions & 71 deletions

File tree

usb_bootloader/STM32F1/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,20 @@ ELFSIZE = $(SIZE) -A $(TARGET).elf
113113

114114
# go!
115115
all: begin gccversion build sizeafter finished end
116-
maple-mini: begin gccversion build_maple-mini sizeafter finished end
116+
maple-mini: begin gccversion build_maple-mini sizeafter finished copy_maple_mini end
117117
maple-rev3: begin gccversion build_maple-rev3 sizeafter finished end
118118

119119
build: elf bin lss sym
120120

121121

122122
build_maple-mini: TARGETFLAGS= -DTARGET_MAPLE_MINI
123123
build_maple-mini: elf bin lss sym
124+
copy_maple_mini:
125+
@echo
126+
@echo "Copying to binaries folder"
127+
@echo
128+
cp $(TARGET).bin binaries/maple_mini_boot20.bin
129+
@echo
124130

125131
build_maple-rev3: TARGETFLAGS= -DTARGET_MAPLE_REV3
126132
build_maple-rev3: elf bin lss sym
-52 Bytes
Binary file not shown.

usb_bootloader/STM32F1/dfu.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ bool dfuUpdateByRequest(void) {
8585
dfuAppStatus.bState = dfuDNLOAD_SYNC;
8686
switch(pInformation->Current_AlternateSetting)
8787
{
88+
/*
89+
Roger Clark. removed upload to RAM option
8890
case 0:
8991
userAppAddr = USER_CODE_RAM;
9092
userUploadType = DFU_UPLOAD_RAM;
9193
break;
94+
*/
9295
case 1:
9396
userAppAddr = USER_CODE_FLASH0X8005000;
9497
userUploadType = DFU_UPLOAD_FLASH_0X8005000;
@@ -107,8 +110,9 @@ bool dfuUpdateByRequest(void) {
107110
flashUnlock();
108111
break;
109112
default:
110-
userAppAddr = USER_CODE_RAM;
111-
userUploadType = DFU_UPLOAD_RAM;
113+
// Roger Clark. Report error
114+
dfuAppStatus.bState = dfuERROR;
115+
dfuAppStatus.bStatus = errWRITE;
112116
break;
113117
}
114118
} else {
@@ -125,9 +129,11 @@ bool dfuUpdateByRequest(void) {
125129
userFirmwareLen = uploadBlockLen * pInformation->USBwValue;
126130
switch(pInformation->Current_AlternateSetting)
127131
{
132+
/*
128133
case 0:
129134
userAppAddr = USER_CODE_RAM;
130135
userAppEnd = RAM_END;
136+
*/
131137
case 1:
132138
userAppAddr = USER_CODE_FLASH0X8005000;
133139
userAppEnd = FLASH_END;
@@ -137,8 +143,11 @@ bool dfuUpdateByRequest(void) {
137143
userAppEnd = FLASH_END;
138144
break;
139145
default:
140-
userAppAddr = USER_CODE_RAM;
141-
userAppEnd = RAM_END;
146+
// Roger Clark.
147+
// Changed this to report error that its unable to write to this memory
148+
// However the code should never get here as only AlternateSetting 1 and 2 are allowed (see above)
149+
dfuAppStatus.bState = dfuERROR;
150+
dfuAppStatus.bStatus = errWRITE;
142151
break;
143152
}
144153
} else if (pInformation->USBbRequest == DFU_ABORT) {
@@ -158,10 +167,14 @@ bool dfuUpdateByRequest(void) {
158167

159168
if (pInformation->USBbRequest == DFU_GETSTATUS) {
160169
/* todo, add routine to wait for last block write to finish */
161-
if (userUploadType == DFU_UPLOAD_RAM) {
170+
171+
/* Roger Clark. Commented out code associated with RAM upload
172+
173+
if (userUploadType == DFU_UPLOAD_RAM)
174+
{
162175
if (code_copy_lock == WAIT) {
163176
code_copy_lock = BEGINNING;
164-
dfuAppStatus.bwPollTimeout0 = 0x20; /* 32 ms */
177+
dfuAppStatus.bwPollTimeout0 = 0x20; // 32 ms
165178
dfuAppStatus.bwPollTimeout1 = 0x00;
166179
dfuAppStatus.bState = dfuDNBUSY;
167180
@@ -177,7 +190,10 @@ bool dfuUpdateByRequest(void) {
177190
dfuAppStatus.bState = dfuDNLOAD_IDLE;
178191
}
179192
180-
} else {
193+
}
194+
else
195+
*/
196+
{
181197
dfuAppStatus.bState = dfuDNLOAD_IDLE;
182198
dfuCopyBufferToExec();
183199
}
@@ -383,17 +399,21 @@ u8 *dfuCopyUPLOAD(u16 length) {
383399
void dfuCopyBufferToExec() {
384400
int i;
385401
u32 *userSpace;
402+
403+
/* Roger Clark.
404+
Commented out code associated with upload to RAM
386405
387406
if (userUploadType == DFU_UPLOAD_RAM)
388407
{
389408
userSpace = (u32 *)(USER_CODE_RAM + userFirmwareLen);
390-
/* we dont need to handle when thisBlock len is not divisible by 4,
391-
since the linker will align everything to 4B anyway */
409+
// we dont need to handle when thisBlock len is not divisible by 4,
410+
// since the linker will align everything to 4B anyway
392411
for (i = 0; i < thisBlockLen; i = i + 4) {
393412
*userSpace++ = *(u32 *)(recvBuffer + i);
394413
}
395414
}
396415
else
416+
*/
397417
{
398418
if (userUploadType == DFU_UPLOAD_FLASH_0X8005000)
399419
{
@@ -429,8 +449,15 @@ bool dfuUploadStarted() {
429449
}
430450

431451
void dfuFinishUpload() {
432-
while (1) {
433-
if (userUploadType==DFU_UPLOAD_RAM) {
452+
while (1)
453+
{
454+
__asm("nop");
455+
456+
/* Roger Clark.
457+
Commented out code associated with upload to RAM
458+
459+
if (userUploadType==DFU_UPLOAD_RAM)
460+
{
434461
if (code_copy_lock == BEGINNING) {
435462
code_copy_lock = MIDDLE;
436463
strobePin(LED_BANK, LED, 2, 0x1000);
@@ -439,6 +466,9 @@ void dfuFinishUpload() {
439466
code_copy_lock = END;
440467
}
441468
}
469+
470+
*/
471+
442472
/* otherwise do nothing, dfu state machine resets itself */
443473
}
444474
}

usb_bootloader/STM32F1/main.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,24 @@ int main()
6161
}
6262
}
6363

64-
if (userUploadType==DFU_UPLOAD_RAM)
64+
65+
if (checkUserCode(USER_CODE_FLASH0X8002000))
6566
{
66-
// if we have just uploaded to RAM, then run whats in RAM
67-
jumpToUser(USER_CODE_RAM);
68-
}
69-
else
67+
jumpToUser(USER_CODE_FLASH0X8002000);
68+
}
69+
else
7070
{
71-
// This may be an upload to flash or a cold boot
72-
73-
if (checkUserCode(USER_CODE_FLASH0X8002000))
71+
if (checkUserCode(USER_CODE_FLASH0X8005000))
7472
{
75-
jumpToUser(USER_CODE_FLASH0X8002000);
73+
jumpToUser(USER_CODE_FLASH0X8005000);
7674
}
77-
else
75+
else
7876
{
79-
if (checkUserCode(USER_CODE_FLASH0X8005000))
80-
{
81-
jumpToUser(USER_CODE_FLASH0X8005000);
82-
}
83-
else
84-
{
85-
// Nothing to execute in either Flash or RAM
86-
strobePin(LED_BANK, LED, 5, BLINK_FAST);
87-
systemHardReset();
88-
}
77+
// Nothing to execute in either Flash or RAM
78+
strobePin(LED_BANK, LED, 5, BLINK_FAST);
79+
systemHardReset();
8980
}
9081
}
82+
83+
return 0;// Added to please the compiler
9184
}

usb_bootloader/STM32F1/usb_descriptor.c

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -152,66 +152,85 @@ ONE_DESCRIPTOR usbConfigDescriptorDFU = {
152152
u8_usbConfigDescriptorDFU_LENGTH
153153
};
154154

155-
u8 u8_usbStringLangId[0x04] = {
156-
0x04,
155+
#define USB_STR_LANG_ID_LEN 0x04
156+
u8 u8_usbStringLangId[USB_STR_LANG_ID_LEN] = {
157+
USB_STR_LANG_ID_LEN,
157158
0x03,
158159
0x09,
159160
0x04 /* LangID = 0x0409: U.S. English */
160161
};
161-
162-
u8 u8_usbStringVendor[0x12] = {
163-
0x12,
162+
#define USB_VENDOR_STR_LEN 0x12
163+
u8 u8_usbStringVendor[USB_VENDOR_STR_LEN] = {
164+
USB_VENDOR_STR_LEN,
164165
0x03,
165166
'L', 0, 'e', 0, 'a', 0, 'f', 0, 'L', 0, 'a', 0, 'b', 0, 's', 0
166167
};
167-
168-
u8 u8_usbStringProduct[0x14] = {
169-
0x14,
168+
#define USB_PRODUCT_STR_LEN 0x14
169+
u8 u8_usbStringProduct[USB_PRODUCT_STR_LEN] = {
170+
USB_PRODUCT_STR_LEN,
170171
0x03,
171172
'M', 0, 'a', 0, 'p', 0, 'l', 0, 'e', 0, ' ', 0, '0', 0, '0', 0, '3', 0
172173
};
173-
174-
u8 u8_usbStringSerial[0x10] = {
175-
0x10,
174+
#define USB_SERIAL_STR_LEN 0x10
175+
u8 u8_usbStringSerial[USB_SERIAL_STR_LEN] = {
176+
USB_SERIAL_STR_LEN,
176177
0x03,
177178
'L', 0, 'L', 0, 'M', 0, ' ', 0, '0', 0, '0', 0, '3', 0
178179
};
179180

180-
u8 u8_usbStringAlt0[0x36] = {
181-
0x36,
182-
0x03,
183-
'D', 0, 'F', 0, 'U', 0, ' ', 0, 'P', 0, 'r', 0, 'o', 0, 'g', 0, 'r', 0,
184-
'a', 0, 'm', 0, ' ', 0, 'R', 0, 'A', 0, 'M', 0, ' ', 0, '0', 0, 'x', 0,
185-
'2', 0, '0', 0, '0', 0, '0', 0, '0', 0, 'C', 0, '0', 0, '0', 0
181+
#define ALT0_STR_LEN 0x6A
182+
u8 u8_usbStringAlt0[ALT0_STR_LEN] = {
183+
ALT0_STR_LEN,
184+
0x03,
185+
'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
186186
};
187187

188-
u8 u8_usbStringAlt1[0x3A] = {
189-
0x3A,
190-
0x03,
191-
'D', 0, 'F', 0, 'U', 0, ' ', 0, 'P', 0, 'r', 0, 'o', 0, 'g', 0, 'r', 0,
192-
'a', 0, 'm', 0, ' ', 0, 'F', 0, 'L', 0, 'A', 0, 'S', 0, 'H', 0, ' ', 0,
193-
'0', 0, 'x', 0, '0', 0, '8', 0, '0', 0, '0', 0, '5', 0, '0', 0, '0', 0,
194-
'0', 0
188+
#define ALT1_STR_LEN 0x62
189+
u8 u8_usbStringAlt1[ALT1_STR_LEN] = {
190+
ALT1_STR_LEN,
191+
0x03,
192+
'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
195193
};
196194

197-
u8 u8_usbStringAlt2[0x3A] = {
198-
0x3A,
199-
0x03,
200-
'D', 0, 'F', 0, 'U', 0, ' ', 0, 'P', 0, 'r', 0, 'o', 0, 'g', 0, 'r', 0,
201-
'a', 0, 'm', 0, ' ', 0, 'F', 0, 'L', 0, 'A', 0, 'S', 0, 'H', 0, ' ', 0,
202-
'0', 0, 'x', 0, '0', 0, '8', 0, '0', 0, '0', 0, '2', 0, '0', 0, '0', 0,
203-
'0', 0
195+
#define ALT2_STR_LEN 0x62
196+
u8 u8_usbStringAlt2[ALT2_STR_LEN] = {
197+
ALT2_STR_LEN,
198+
0x03,
199+
'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
204200
};
205201

206202
u8 u8_usbStringInterface = NULL;
207203

208204
ONE_DESCRIPTOR usbStringDescriptor[STR_DESC_LEN] = {
209-
{ (u8 *)u8_usbStringLangId, 0x04 },
210-
{ (u8 *)u8_usbStringVendor, 0x12 },
211-
{ (u8 *)u8_usbStringProduct, 0x20 },
212-
{ (u8 *)u8_usbStringSerial, 0x10 },
213-
{ (u8 *)u8_usbStringAlt0, 0x36 },
214-
{ (u8 *)u8_usbStringAlt1, 0x3A },
215-
{ (u8 *)u8_usbStringAlt2, 0x3A }
205+
{ (u8 *)u8_usbStringLangId, USB_STR_LANG_ID_LEN },
206+
{ (u8 *)u8_usbStringVendor, USB_VENDOR_STR_LEN },
207+
{ (u8 *)u8_usbStringProduct, USB_PRODUCT_STR_LEN },
208+
{ (u8 *)u8_usbStringSerial, USB_SERIAL_STR_LEN },
209+
{ (u8 *)u8_usbStringAlt0, ALT0_STR_LEN },
210+
{ (u8 *)u8_usbStringAlt1, ALT1_STR_LEN },
211+
{ (u8 *)u8_usbStringAlt2, ALT2_STR_LEN }
216212
};
217-
213+
/*
214+
Roger.
215+
Javascript utility to make new ALT ID text structs
216+
217+
<html>
218+
<script>
219+
function convertText(txt,idNum)
220+
{
221+
222+
var txt2 ="#define ALT"+idNum+"_STR_LEN 0x"+(txt.length*2 + 2).toString(16).toUpperCase()+"<br/>u8 u8_usbStringAlt"+idNum+"[ALT"+idNum+"_STR_LEN] = {<br/>ALT"+idNum+"_STR_LEN,<br/>0x03,<br/>";
223+
for (var i=0;i<txt.length;i++)
224+
{
225+
txt2+="'"+txt[i]+"',0,";
226+
}
227+
return txt2.substring(0,txt2.length-1)+"<br/>};<br/>";
228+
}
229+
document.write("<pre>");
230+
document.write(convertText("Bootloader 2.0 ERROR. Upload to RAM is not supported",0)+"<br/>");
231+
document.write(convertText("Bootloader 2.0 Upload to Flash address 0x8005000",1)+"<br/>");
232+
document.write(convertText("Bootloader 2.0 Upload to Flash address 0x8002000",2)+"<br/>");
233+
document.write("</pre>");
234+
</script>
235+
</html>
236+
*/

0 commit comments

Comments
 (0)