Skip to content

Commit 72f6d46

Browse files
committed
well, it compiles now!
1 parent 9b72387 commit 72f6d46

File tree

6 files changed

+469
-13
lines changed

6 files changed

+469
-13
lines changed

bootloaders/feather/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ else
6868
CFLAGS+=-Os -DDEBUG=0
6969
endif
7070

71-
CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x0B -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
71+
# Adafruit Feather Zero (0x239A 0x000B)
72+
#CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x0B -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
73+
# Adafruit Feather SAMR (0x239A 0x0014)
74+
CFLAGS_EXTRA?=-D__SAMR21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x14 -DUSB_VID_LOW=0x9A -DUSB_VID_HIGH=0x23
7275
# Arduino Zero (PID == 0x004D)
7376
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x4D -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
7477
# Genuino Zero (PID == 0x024D)
@@ -78,6 +81,9 @@ CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x00 -DUSB_PID_LOW=0x0B -DUSB_VID_
7881
# Genuino MKR1000 (PID == 0x024E)
7982
# CFLAGS_EXTRA?=-D__SAMD21G18A__ -DUSB_PID_HIGH=0x02 -DUSB_PID_LOW=0x4E -DUSB_VID_LOW=0x41 -DUSB_VID_HIGH=0x23
8083

84+
# samd or samr
85+
NAME=samr21_sam_ba
86+
8187
INCLUDES=-I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/CMSIS/Include/" -I"$(MODULE_PATH)/tools/CMSIS/4.0.0-atmel/Device/ATMEL/"
8288

8389
# -----------------------------------------------------------------------------
@@ -102,7 +108,6 @@ sam_ba_serial.c
102108
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
103109
DEPS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.d))
104110

105-
NAME=samd21_sam_ba
106111
ELF=$(NAME).elf
107112
BIN=$(NAME).bin
108113
HEX=$(NAME).hex

bootloaders/feather/board_driver_usb.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,22 @@ 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;
175+
176+
#ifdef __SAMR21G18A__
177+
pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1 = true;
178+
#else
176179
pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT |= (1<<1);
180+
#endif
181+
177182
/* Set the bank as ready */
178183
pUsb->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.bit.BK1RDY = true;
179184

180185
/* Wait for transfer to complete */
186+
#ifdef __SAMR21G18A__
187+
while ( (pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1) == 0 );
188+
#else
181189
while ( (pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT & (1<<1)) == 0 );
190+
#endif
182191

183192
return length;
184193
}
@@ -205,15 +214,22 @@ uint32_t USB_Read(Usb *pUsb, char *pData, uint32_t length)
205214
}
206215

207216
/* Check for Transfer Complete 0 flag */
217+
#ifdef __SAMR21G18A__
218+
if ( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 )
219+
#else
208220
if ( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0) )
221+
#endif
209222
{
210223
/* Set packet size */
211224
packetSize = SAM_BA_MIN(usb_endpoint_table[USB_EP_OUT].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT, length);
212225
/* Copy read data to user buffer */
213226
memcpy(pData, udd_ep_out_cache_buffer[USB_EP_OUT-1], packetSize);
214227
/* Clear the Transfer Complete 0 flag */
215-
//pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
228+
#ifdef __SAMR21G18A__
229+
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
230+
#else
216231
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT |= (1 << 0);
232+
#endif
217233
/* Clear the user flag */
218234
read_job = false;
219235
}
@@ -240,10 +256,16 @@ uint32_t USB_Read_blocking(Usb *pUsb, char *pData, uint32_t length)
240256
/* Clear the bank 0 ready flag */
241257
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPSTATUSCLR.bit.BK0RDY = true;
242258
/* Wait for transfer to complete */
259+
260+
#ifdef __SAMR21G18A__
261+
while (!( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 ));
262+
/* Clear Transfer complete 0 flag */
263+
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
264+
#else
243265
while (!( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0) ));
244266
/* Clear Transfer complete 0 flag */
245-
//pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
246267
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT |= (1 << 0);
268+
#endif
247269

248270
return length;
249271
}
@@ -303,14 +325,20 @@ void USB_SendStall(Usb *pUsb, bool direction_in)
303325
if (direction_in)
304326
{
305327
/* Set STALL request on IN direction */
306-
//pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
328+
#ifdef __SAMR21G18A__
329+
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
330+
#else
307331
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ = (1<<1);
332+
#endif
308333
}
309334
else
310335
{
311336
/* Set STALL request on OUT direction */
312-
//pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
337+
#ifdef __SAMR21G18A__
338+
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
339+
#else
313340
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ = (1<<0);
341+
#endif
314342
}
315343
}
316344

@@ -322,12 +350,19 @@ void USB_SendZlp(Usb *pUsb)
322350
/* Set the byte count as zero */
323351
usb_endpoint_table[0].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT = 0;
324352
/* Clear the transfer complete flag */
325-
//pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;
353+
#ifdef __SAMR21G18A__
354+
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;
355+
#else
326356
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT |= (1 << 1);
357+
#endif
327358
/* Set the bank as ready */
328359
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.BK1RDY = true;
329360
/* Wait for transfer to complete */
361+
#ifdef __SAMR21G18A__
362+
while (!( pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 ));
363+
#else
330364
while (!( pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT & (1<<1) ));
365+
#endif
331366
}
332367

333368
/*----------------------------------------------------------------------------

bootloaders/feather/sam_ba_cdc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ bool cdc_is_rx_ready(/*P_USB_CDC pCdc*/void)
5555
return 0;
5656

5757
/* Return transfer complete 0 flag status */
58+
#ifdef __SAMR21G18A__
59+
return (pCdc->pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0);
60+
#else
5861
return (pCdc->pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0));
62+
#endif
5963
}
6064

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

bootloaders/feather/sam_ba_usb.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,19 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
279279
{
280280
if (dir)
281281
{
282-
//wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ1) ? 1 : 0;
282+
#ifdef __SAMR21G18A__
283+
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ1) ? 1 : 0;
284+
#else
283285
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<1)) ? 1 : 0;
286+
#endif
284287
}
285288
else
286289
{
287-
//wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ0) ? 1 : 0;
290+
#ifdef __SAMR21G18A__
291+
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ0) ? 1 : 0;
292+
#else
288293
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<0)) ? 1 : 0;
294+
#endif
289295
}
290296
/* Return current status of endpoint */
291297
USB_Write(pCdc->pUsb, (char *) &wStatus, sizeof(wStatus), USB_EP_CTRL);
@@ -315,13 +321,19 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
315321
/* Set STALL request for the endpoint */
316322
if (dir)
317323
{
318-
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
324+
#ifdef __SAMR21G18A__
325+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
326+
#else
319327
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.bit.STALLRQ = (1<<1);
328+
#endif
320329
}
321330
else
322331
{
323-
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
332+
#ifdef __SAMR21G18A__
333+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
334+
#else
324335
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.bit.STALLRQ = (1<<0);
336+
#endif
325337
}
326338

327339
/* Send ZLP */
@@ -353,21 +365,40 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
353365
{
354366
if (dir)
355367
{
368+
#ifdef __SAMR21G18A__
369+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ1)
370+
{
371+
// Remove stall request
372+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1;
373+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL1)
374+
{
375+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL1 = 1;
376+
#else
377+
356378
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<1))
357379
{
358380
// Remove stall request
359-
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1;
360381
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.bit.STALLRQ = (1<<1);
361382
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL & (1<<1))
362383
{
363384
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL = (1<<1);
385+
#endif
364386
// The Stall has occurred, then reset data toggle
365387
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSSET_DTGLIN;
366388
}
367389
}
368390
}
369391
else
370392
{
393+
#ifdef __SAMR21G18A__
394+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ0)
395+
{
396+
// Remove stall request
397+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0;
398+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL0)
399+
{
400+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL0 = 1;
401+
#else
371402
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<0))
372403
{
373404
// Remove stall request
@@ -376,6 +407,7 @@ void sam_ba_usb_CDC_Enumerate(P_USB_CDC pCdc)
376407
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL & (1<<0))
377408
{
378409
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL = (1<<0);
410+
#endif
379411
// The Stall has occurred, then reset data toggle
380412
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSSET_DTGLOUT;
381413
}

bootloaders/feather/samr21_sam_ba.bin

5.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)