Skip to content

Commit 77fcfae

Browse files
committed
Merge pull request #70 from arduino/bootloader_gcc_build
Zero bootloader: Makefiles for arm-gcc
2 parents 29f1e97 + e01266e commit 77fcfae

21 files changed

+369
-2939
lines changed
-7.2 KB
Binary file not shown.
-143 KB
Binary file not shown.

bootloaders/zero/Debug/List/samd21_sam_ba.map

Lines changed: 0 additions & 377 deletions
This file was deleted.

bootloaders/zero/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
IDE_PATH="../../../../.."
2+
ARM_GCC_PATH=$(IDE_PATH)/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin
3+
CC=$(ARM_GCC_PATH)/arm-none-eabi-gcc
4+
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -g -Os -w -std=gnu99 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
5+
LDFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols
6+
BLD_EXTA_FLAGS=-D__SAMD21G18A__
7+
BUILD_PATH=build
8+
INCLUDES=-I$(IDE_PATH)/hardware/tools/CMSIS/CMSIS/Include/ -I$(IDE_PATH)/hardware/tools/CMSIS/Device/ATMEL/ -I./drivers/ -I./utils/ -I./utils/preprocessor/ -I./utils/interrupt
9+
SOURCES=main.c sam_ba_monitor.c startup_samd21.c usart_sam_ba.c drivers/cdc_enumerate.c drivers/uart_driver.c utils/interrupt/interrupt_sam_nvic.c
10+
OBJECTS=$(addprefix $(BUILD_PATH)/, $(SOURCES:.c=.o))
11+
12+
NAME=samd21_sam_ba
13+
EXECUTABLE=$(NAME).bin
14+
15+
SLASH=/
16+
BSLASH=$(EMPTY)\$(EMPTY)
17+
18+
all: $(SOURCES) $(EXECUTABLE)
19+
20+
$(EXECUTABLE): $(OBJECTS)
21+
$(CC) -L$(BUILD_PATH) $(LDFLAGS) -Os -Wl,--gc-sections -save-temps -Tsamd21j18a_flash.ld -Wl,-Map,$(BUILD_PATH)/$(NAME).map --specs=nano.specs --specs=nosys.specs -o $(BUILD_PATH)/$(NAME).elf $(OBJECTS) -Wl,--start-group -lm -Wl,--end-group
22+
$(ARM_GCC_PATH)/arm-none-eabi-objcopy -O binary $(BUILD_PATH)/$(NAME).elf $@
23+
24+
$(BUILD_PATH)/%.o: %.c
25+
-@mkdir -p $(@D)
26+
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@
27+
28+
clean:
29+
del $(EXECUTABLE) $(subst /,\,$(OBJECTS)) $(subst /,\,$(BUILD_PATH)/$(NAME).*)
-5.22 KB
Binary file not shown.
-31.2 KB
Binary file not shown.

bootloaders/zero/Release/List/samd21_sam_ba.map

Lines changed: 0 additions & 326 deletions
This file was deleted.

bootloaders/zero/drivers/cdc_enumerate.c

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void AT91F_InitUSB(void)
276276
/* Set the descriptor address */
277277
USB->HOST.DESCADD.reg = (uint32_t)(&usb_endpoint_table[0]);
278278
/* Set speed configuration to Full speed */
279-
USB->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_0_Val;
279+
USB->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_FS_Val;
280280
/* Attach to the USB host */
281281
USB->DEVICE.CTRLB.reg &= ~USB_DEVICE_CTRLB_DETACH;
282282

@@ -367,13 +367,14 @@ static uint32_t USB_Read(P_USB_CDC pCdc, char *pData, uint32_t length)
367367
}
368368

369369
/* Check for Transfer Complete 0 flag */
370-
if ( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT0 ) {
370+
if ( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0) ) {
371371
/* Set packet size */
372372
packetSize = MIN(usb_endpoint_table[USB_EP_OUT].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT, length);
373373
/* Copy read data to user buffer */
374374
memcpy(pData, udd_ep_out_cache_buffer[USB_EP_OUT-1], packetSize);
375375
/* Clear the Transfer Complete 0 flag */
376-
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
376+
//pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
377+
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT |= (1 << 0);
377378
/* Clear the user flag */
378379
read_job = false;
379380
}
@@ -401,9 +402,10 @@ static uint32_t USB_Read_blocking(P_USB_CDC pCdc, char *pData, uint32_t length)
401402
/* Clear the bank 0 ready flag */
402403
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPSTATUSCLR.bit.BK0RDY = true;
403404
/* Wait for transfer to complete */
404-
while (!( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT0 ));
405+
while (!( pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0) ));
405406
/* Clear Transfer complete 0 flag */
406-
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
407+
//pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
408+
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT |= (1 << 0);
407409

408410
return length;
409411

@@ -439,12 +441,13 @@ static uint32_t USB_Write(P_USB_CDC pCdc, const char *pData, uint32_t length, ui
439441
/* Set the multi packet size as zero for multi-packet transfers where length > ep size */
440442
usb_endpoint_table[ep_num].DeviceDescBank[1].PCKSIZE.bit.MULTI_PACKET_SIZE = 0;
441443
/* Clear the transfer complete flag */
442-
pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1 = true;
444+
//pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1 = true;
445+
pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT |= (1 << 1);
443446
/* Set the bank as ready */
444447
pUsb->DEVICE.DeviceEndpoint[ep_num].EPSTATUSSET.bit.BK1RDY = true;
445448

446449
/* Wait for transfer to complete */
447-
while (!( pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1 ));
450+
while (!( pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT & (1<<1) ));
448451

449452
return length;
450453
}
@@ -468,11 +471,12 @@ void AT91F_USB_SendZlp(Usb *pUsb)
468471
/* Set the byte count as zero */
469472
usb_endpoint_table[0].DeviceDescBank[1].PCKSIZE.bit.BYTE_COUNT = 0;
470473
/* Clear the transfer complete flag */
471-
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;
474+
//pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;
475+
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT |= (1 << 1);
472476
/* Set the bank as ready */
473477
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.BK1RDY = true;
474478
/* Wait for transfer to complete */
475-
while (!( pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT1 ));
479+
while (!( pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT & (1<<1) ));
476480
}
477481

478482
//*----------------------------------------------------------------------------
@@ -484,10 +488,12 @@ void AT91F_USB_SendStall(Usb *pUsb, bool direction_in)
484488
/* Check the direction */
485489
if (direction_in) {
486490
/* Set STALL request on IN direction */
487-
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
491+
//pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
492+
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ = (1<<1);
488493
} else {
489494
/* Set STALL request on OUT direction */
490-
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
495+
//pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
496+
pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.bit.STALLRQ = (1<<0);
491497
}
492498
}
493499

@@ -579,9 +585,11 @@ void AT91F_CDC_Enumerate(P_USB_CDC pCdc)
579585
wIndex &= 0x0F;
580586
if (wIndex <= 3) {
581587
if (dir) {
582-
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ1) ? 1 : 0;
588+
//wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ1) ? 1 : 0;
589+
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<1)) ? 1 : 0;
583590
} else {
584-
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ0) ? 1 : 0;
591+
//wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ0) ? 1 : 0;
592+
wStatus = (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<0)) ? 1 : 0;
585593
}
586594
/* Return current status of endpoint */
587595
AT91F_USB_SendData(pCdc, (char *) &wStatus, sizeof(wStatus));
@@ -604,9 +612,11 @@ void AT91F_CDC_Enumerate(P_USB_CDC pCdc)
604612
if ((wValue == 0) && wIndex && (wIndex <= 3)) {
605613
/* Set STALL request for the endpoint */
606614
if (dir) {
607-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
615+
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
616+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.bit.STALLRQ = (1<<1);
608617
} else {
609-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
618+
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
619+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSSET.bit.STALLRQ = (1<<0);
610620
}
611621
/* Send ZLP */
612622
AT91F_USB_SendZlp(pUsb);
@@ -628,21 +638,23 @@ void AT91F_CDC_Enumerate(P_USB_CDC pCdc)
628638
wIndex &= 0x0F;
629639
if ((wValue == 0) && wIndex && (wIndex <= 3)) {
630640
if (dir) {
631-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ1) {
641+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<1)) {
632642
// Remove stall request
633-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1;
634-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_STALL1) {
635-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL1;
643+
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1;
644+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.bit.STALLRQ = (1<<1);
645+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL & (1<<1)) {
646+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL = (1<<1);
636647
// The Stall has occurred, then reset data toggle
637648
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSSET_DTGLIN;
638649
}
639650
}
640651
} else {
641-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.reg & USB_DEVICE_EPSTATUSSET_STALLRQ0) {
652+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUS.bit.STALLRQ & (1<<0)) {
642653
// Remove stall request
643-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0;
644-
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_STALL0) {
645-
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_STALL0;
654+
//pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0;
655+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.bit.STALLRQ = (1<<0);
656+
if (pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL & (1<<0)) {
657+
pUsb->DEVICE.DeviceEndpoint[wIndex].EPINTFLAG.bit.STALL = (1<<0);
646658
// The Stall has occurred, then reset data toggle
647659
pUsb->DEVICE.DeviceEndpoint[wIndex].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSSET_DTGLOUT;
648660
}
@@ -711,7 +723,7 @@ bool cdc_is_rx_ready(void)
711723
return 0;
712724

713725
/* Return transfer complete 0 flag status */
714-
return (pCdc.pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_TRCPT0);
726+
return (pCdc.pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT & (1<<0));
715727
}
716728

717729
uint32_t cdc_write_buf(void const* data, uint32_t length)

bootloaders/zero/drivers/cdc_enumerate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#ifndef CDC_ENUMERATE_H
3131
#define CDC_ENUMERATE_H
3232

33-
#include "iosamd21.h"
33+
#include "sam.h"
3434
#include "stdbool.h"
3535

3636
#define USB_EP_OUT 2

bootloaders/zero/drivers/uart_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#ifndef UART_DRIVER_H
3131
#define UART_DRIVER_H
3232
#include <stdio.h>
33-
#include "iosamd21.h"
33+
#include "sam.h"
3434
#include <stdbool.h>
3535

3636
#define PINMUX_UNUSED 0xFFFFFFFF

0 commit comments

Comments
 (0)