Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit f1e4bda

Browse files
committed
added reboot after download feature and revised bcdDevice version
1 parent a7d18ba commit f1e4bda

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,22 @@ The USBCRM mode should be universal, as it doesn't depend on optional external c
4848

4949
Pre-compiled images are already available via this project's Releases tab.
5050

51-
[Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) is presently suggested to compile this code, as it includes support for Clang; at this time, I am not aware of any other ready-to-use (and multi-OS to boot) Clang ARM cross-compiler package that I can readily point users to. With Crossworks for ARM v4.8.1, compiling v1.06 using the Clang 11.1.0 compiler produces a 995 byte image. The more mainstream GCC lags behind Clang, although more recent GCC versions produce code that is less overweight than in years past.
51+
[Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) is suggested to compile this code, as it includes support for Clang; at this time, I am not aware of any other ready-to-use (and multi-OS to boot) Clang ARM cross-compiler package that I can readily point users to. The more mainstream GCC lags behind Clang, although more recent GCC versions produce code that is less overweight than in years past.
5252

53-
|bootloader variant|Clang 9.0.1 (-O1) |Clang 11.1.0 (-O1) |GNU Arm 2018-q3 (-Os) |GNU Arm 2019-q4 (-Os) |
54-
|------------------|------------------|-------------------|----------------------|----------------------|
55-
| USE_DBL_TAP | 1003 bytes | 995 bytes | 1044 bytes (too big!)| 1041 bytes (too big!)|
56-
| GPIO input | 979 bytes | 975 bytes | 1008 bytes | 1006 bytes |
53+
|bootloader variant |Clang 11.1.0 (-O1) |Clang 13.0.0 (-O1) |GNU Arm 2019-q4 (-Os) |
54+
|-----------------------------------|-------------------|-------------------|------------------------|
55+
| USE_DBL_TAP+REBOOT_AFTER_DOWNLOAD | 999 bytes | 999 bytes | 1024 bytes (just fits!)|
56+
| USE_DBL_TAP | 983 bytes | 983 bytes | 1012 bytes |
57+
| GPIO input+REBOOT_AFTER_DOWNLOAD | 979 bytes | 979 bytes | 996 bytes |
58+
| GPIO input | 963 bytes | 963 bytes | 984 bytes |
5759

5860
A Makefile supporting GCC is provided, but even if you have the latest GCC, it may not be able to output a version within the 1024 bytes available. The latest GCC for ARM can be here: [GNU Arm Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm). Note that if you are adapting the Makefile for use with clang, try replacing the "-Os" argument in CFLAGS with something like "-O1" if the output size is larger than expected.
5961

6062
## Programming targets with bootloader
6163

6264
[OpenOCD](http://openocd.org/) is open-source and freely available. Given a debug unit interfaced to the target, it will not only program the flash but it also has built-in support for setting the BOOTPROT bits to provide write-protection of the bootloader.
6365

64-
Testing was done with OpenOCD v0.10.0 using both the debug units built-in to the ATSAMD11-XPRO and ATSAMD21-XPRO as well as the [Dapper Miser CMSIS-DAP](https://github.com/majbthrd/DapperMiser) debug unit.
66+
Testing was done with OpenOCD v0.10.0 using both the debug units built-in to the ATSAMD11-XPRO and ATSAMD21-XPRO as well as the [Dapper Miser CMSIS-DAP](https://github.com/majbthrd/DapperMiser) and [Dapper Mime CMSIS-DAP](https://github.com/majbthrd/DapperMime) debug units.
6567

6668
Your mileage may vary, particularly with earlier releases of OpenOCD. (The wisdom of the Internet implies earlier versions of OpenOCD had bugs with setting the BOOTPROT bits.) You don't have to use the BOOTPROT bits, but adding write-protection to the bootloader is generally a desirable attribute.
6769

bootloader.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
/*- Definitions -------------------------------------------------------------*/
4747
#define USE_DBL_TAP /* comment out to use GPIO input for bootloader entry */
48+
#define REBOOT_AFTER_DOWNLOAD /* comment out to prevent boot into app after it has been downloaded */
4849
#define USB_CMD(dir, rcpt, type) ((USB_##dir##_TRANSFER << 7) | (USB_##type##_REQUEST << 5) | (USB_##rcpt##_RECIPIENT << 0))
4950
#define SIMPLE_USB_CMD(rcpt, type) ((USB_##type##_REQUEST << 5) | (USB_##rcpt##_RECIPIENT << 0))
5051

@@ -210,6 +211,14 @@ static void __attribute__((noinline)) USB_Service(void)
210211
dfu_status = dfu_status_choices + 2;
211212
dfu_addr = 0x400 + request->wValue * 64;
212213
}
214+
#ifdef REBOOT_AFTER_DOWNLOAD
215+
else
216+
{
217+
/* the download has now finished, so now reboot */
218+
WDT->CONFIG.reg = WDT_CONFIG_PER_8 | WDT_CONFIG_WINDOW_8;
219+
WDT->CTRL.reg = WDT_CTRL_ENABLE;
220+
}
221+
#endif
213222
/* fall through */
214223
default: // DFU_UPLOAD & others
215224
/* 0x00 == DFU_DETACH, 0x04 == DFU_CLRSTATUS, 0x06 == DFU_ABORT, and 0x01 == DFU_DNLOAD and 0x02 == DFU_UPLOAD */

usb_descriptors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ usb_device_descriptor_t usb_device_descriptor __attribute__ ((aligned (4))) = /*
4545
.bMaxPacketSize0 = 64,
4646
.idVendor = 0x1209,
4747
.idProduct = 0x2003,
48-
.bcdDevice = 0x0105,
48+
.bcdDevice = 0x0107,
4949

5050
.iManufacturer = USB_STR_ZERO,
5151
.iProduct = USB_STR_ZERO,

0 commit comments

Comments
 (0)