Skip to content

Commit 428433f

Browse files
committed
Merge branch 'bootloader-cmsis-fix'
2 parents 507a529 + 702d6b9 commit 428433f

15 files changed

+1940
-1983
lines changed
Binary file not shown.

bootloaders/mkr1000/samd21_sam_ba_arduino_mkr1000.hex

+380-386
Large diffs are not rendered by default.
Binary file not shown.

bootloaders/mkr1000/samd21_sam_ba_genuino_mkr1000.hex

+380-386
Large diffs are not rendered by default.
Binary file not shown.

bootloaders/mkrzero/samd21_sam_ba_arduino_mkrzero.hex

+380-386
Large diffs are not rendered by default.

bootloaders/zero/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ ELF=$(NAME).elf
7373
BIN=$(NAME).bin
7474
HEX=$(NAME).hex
7575

76-
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
76+
77+
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.5.0/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS-Atmel/1.0.0/CMSIS/Device/ATMEL/"
7778

7879
# -----------------------------------------------------------------------------
7980
# Linker options

bootloaders/zero/board_driver_usb.c

+11-17
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,12 @@ uint32_t USB_Write(Usb *pUsb, const char *pData, uint32_t length, uint8_t ep_num
172172
/* Set the multi packet size as zero for multi-packet transfers where length > ep size */
173173
usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.MULTI_PACKET_SIZE = 0;
174174
/* Clear the transfer complete flag */
175-
//pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1 = true;
176-
pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT |= (1<<1);
175+
pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
177176
/* Set the bank as ready */
178177
pUsb->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.bit.BK1RDY = true;
179178

180179
/* Wait for transfer to complete */
181-
while ( (pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT & (1<<1)) == 0 );
180+
while ( (pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1) == 0 );
182181

183182
return length;
184183
}
@@ -205,15 +204,14 @@ uint32_t USB_Read(Usb *pUsb, char *pData, uint32_t length)
205204
}
206205

207206
/* Check for Transfer Complete 0 flag */
208-
if ( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0) )
207+
if ( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 )
209208
{
210209
/* Set packet size */
211210
packetSize = SAM_BA_MIN(usb_endpoint_table[USB_EP_OUT].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT, length);
212211
/* Copy read data to user buffer */
213212
memcpy(pData, udd_ep_out_cache_buffer[USB_EP_OUT-1], packetSize);
214213
/* Clear the Transfer Complete 0 flag */
215-
//pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
216-
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT |= (1 << 0);
214+
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
217215
/* Clear the user flag */
218216
read_job = false;
219217
}
@@ -240,10 +238,9 @@ uint32_t USB_Read_blocking(Usb *pUsb, char *pData, uint32_t length)
240238
/* Clear the bank 0 ready flag */
241239
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPSTATUSCLR.bit.BK0RDY = true;
242240
/* Wait for transfer to complete */
243-
while (!( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0) ));
241+
while (!( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 ));
244242
/* Clear Transfer complete 0 flag */
245-
//pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
246-
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT |= (1 << 0);
243+
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
247244

248245
return length;
249246
}
@@ -259,7 +256,7 @@ uint8_t USB_IsConfigured(P_USB_CDC pCdc)
259256
if (pUsb->DEVICE.INTFLAG.reg & USB_DEVICE_INTFLAG_EORST)
260257
{
261258
/* Clear the flag */
262-
pUsb->DEVICE.INTFLAG.bit.EORST = true;
259+
pUsb->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST;
263260
/* Set Device address as 0 */
264261
pUsb->DEVICE.DADD.reg = USB_DEVICE_DADD_ADDEN | 0;
265262
/* Configure endpoint 0 */
@@ -303,14 +300,12 @@ void USB_SendStall(Usb *pUsb, bool direction_in)
303300
if (direction_in)
304301
{
305302
/* Set STALL request on IN direction */
306-
//pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
307-
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ = (1<<1);
303+
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ1 = 1;
308304
}
309305
else
310306
{
311307
/* Set STALL request on OUT direction */
312-
//pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
313-
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ = (1<<0);
308+
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ0 = 1;
314309
}
315310
}
316311

@@ -322,12 +317,11 @@ void USB_SendZlp(Usb *pUsb)
322317
/* Set the byte count as zero */
323318
usb_endpoint_table[0].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT = 0;
324319
/* Clear the transfer complete flag */
325-
//pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;
326-
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT |= (1 << 1);
320+
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
327321
/* Set the bank as ready */
328322
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.BK1RDY = true;
329323
/* Wait for transfer to complete */
330-
while (!( pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT & (1<<1) ));
324+
while (!( pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 ));
331325
}
332326

333327
/*----------------------------------------------------------------------------

bootloaders/zero/sam_ba_cdc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool cdc_is_rx_ready(/*P_USB_CDC pCdc*/void)
5555
return 0;
5656

5757
/* Return transfer complete 0 flag status */
58-
return (pCdc->pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0));
58+
return (pCdc->pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0);
5959
}
6060

6161
uint32_t cdc_write_buf(/*P_USB_CDC pCdc,*/ void const* data, uint32_t length)

bootloaders/zero/sam_ba_usb.c

+13-19
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
167167
static volatile uint16_t wValue, wIndex, wLength, wStatus;
168168

169169
/* Clear the Received Setup flag */
170-
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP = true;
170+
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_RXSTP;
171171

172172
/* Read the USB request parameters */
173173
bmRequestType = udd_ep_out_cache_buffer[0][0];
@@ -268,13 +268,11 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
268268
{
269269
if (dir)
270270
{
271-
//wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ1) ? 1 : 0;
272-
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<1)) ? 1 : 0;
271+
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ1) ? 1 : 0;
273272
}
274273
else
275274
{
276-
//wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ0) ? 1 : 0;
277-
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<0)) ? 1 : 0;
275+
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ0) ? 1 : 0;
278276
}
279277
/* Return current status of endpoint */
280278
USB_Write(pCdc->pUsb, (char *) &wStatus, sizeof(wStatus), USB_EP_CTRL);
@@ -304,13 +302,11 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
304302
/* Set STALL request for the endpoint */
305303
if (dir)
306304
{
307-
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
308-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.bit.STALLRQ = (1<<1);
305+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
309306
}
310307
else
311308
{
312-
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
313-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.bit.STALLRQ = (1<<0);
309+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
314310
}
315311

316312
/* Send ZLP */
@@ -342,29 +338,27 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
342338
{
343339
if (dir)
344340
{
345-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<1))
341+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ1)
346342
{
347343
// Remove stall request
348-
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1;
349-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.bit.STALLRQ = (1<<1);
350-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL & (1<<1))
344+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1;
345+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL1)
351346
{
352-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL = (1<<1);
347+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL1;
353348
// The Stall has occurred, then reset data toggle
354349
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSSET_DTGLIN;
355350
}
356351
}
357352
}
358353
else
359354
{
360-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<0))
355+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ0)
361356
{
362357
// Remove stall request
363-
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0;
364-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.bit.STALLRQ = (1<<0);
365-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL & (1<<0))
358+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0;
359+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL0)
366360
{
367-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL = (1<<0);
361+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL0;
368362
// The Stall has occurred, then reset data toggle
369363
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSSET_DTGLOUT;
370364
}

bootloaders/zero/samd21_sam_ba.bin

-104 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)