Skip to content

Commit

Permalink
added Makefile, linker script, and include files for GCC
Browse files Browse the repository at this point in the history
  • Loading branch information
majbthrd committed Jan 18, 2020
1 parent fcc10ae commit 15c35fc
Show file tree
Hide file tree
Showing 68 changed files with 22,513 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ D11bootloader THUMB Release/*
D11bootloader THUMB Debug/*
D11bootloader THUMB Release/*
*.hzs
make/build/*

4 changes: 2 additions & 2 deletions Dx1bootloader.hzp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
arm_endian="Little"
arm_fpu_type="None"
arm_interwork="No"
arm_linker_heap_size="256"
arm_linker_heap_size="0"
arm_linker_process_stack_size="0"
arm_linker_stack_size="256"
arm_simulator_memory_simulation_filename="$(TargetsDir)/SAM_D/Simulator/SAM_D_SimulatorMemory_$(HostOS)_$(HostArch)$(HostDLLExt)"
Expand Down Expand Up @@ -83,7 +83,7 @@
arm_endian="Little"
arm_fpu_type="None"
arm_interwork="No"
arm_linker_heap_size="256"
arm_linker_heap_size="0"
arm_linker_process_stack_size="0"
arm_linker_stack_size="256"
arm_simulator_memory_simulation_filename="$(TargetsDir)/SAM_D/Simulator/SAM_D_SimulatorMemory_$(HostOS)_$(HostArch)$(HostDLLExt)"
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ The USBCRM mode should be universal, as it doesn't depend on optional external c

## Requirements for compiling

[Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) is presently needed to compile this code. With Crossworks for ARM v4.3.2, compiling v1.03 using the Clang 7.0.0 compiler produces a 1022 byte image. The more mainstream GCC does not appear to be optimized enough to produce an image that comes anywhere close to fitting into 1024 bytes.
Pre-compiled images are already available via this project's Releases tab.

There is no dependency in the code on the [Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) toolchain per se, but at this time I am not aware of any other ready-to-use Clang ARM cross-compiler package that I can readily point users to.
[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.6.1, compiling v1.05 using the Clang 9.0.1 compiler produces a 1003 byte image. The more mainstream GCC lags behind Clang, although more recent GCC versions produce code that is less overweight than in years past.

|bootloader variant|Clang 9.0.1 (-O1) |GNU Arm 2018-q3 (-Os) |GNU Arm 2019-q4 (-Os) |
|------------------|------------------|----------------------|----------------------|
| USE_DBL_TAP | 1003 bytes | 1044 bytes (too big!)| 1041 bytes (too big!)|
| GPIO input | 979 bytes | 1008 bytes | 1006 bytes |

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.

## Programming targets with bootloader

Expand Down
20 changes: 11 additions & 9 deletions bootloader.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* 1kByte USB DFU bootloader for Atmel SAMD11 microcontrollers
*
* Copyright (c) 2018, Peter Lawrence
* Copyright (c) 2016, Alex Taradov <[email protected]>
* Copyright (c) 2018-2020, Peter Lawrence
* derived from https://github.com/ataradov/vcp Copyright (c) 2016, Alex Taradov <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -44,6 +44,7 @@
#include "usb_descriptors.h"

/*- Definitions -------------------------------------------------------------*/
#define USE_DBL_TAP /* comment out to use GPIO input for bootloader entry */
#define USB_CMD(dir, rcpt, type) ((USB_##dir##_TRANSFER << 7) | (USB_##type##_REQUEST << 5) | (USB_##rcpt##_RECIPIENT << 0))
#define SIMPLE_USB_CMD(rcpt, type) ((USB_##type##_REQUEST << 5) | (USB_##rcpt##_RECIPIENT << 0))

Expand Down Expand Up @@ -145,7 +146,6 @@ static void USB_Service(void)

usb_request_t *request = (usb_request_t *)udc_ctrl_out_buf;
uint8_t type = request->wValue >> 8;
uint8_t index = request->wValue & 0xff;
uint16_t length = request->wLength;
static uint32_t *dfu_status = dfu_status_choices + 0;

Expand Down Expand Up @@ -213,7 +213,7 @@ static void USB_Service(void)
dfu_status = dfu_status_choices + 2;
dfu_addr = 0x400 + request->wValue * 64;
}
/* fall through to below */
/* fall through */
default: // DFU_UPLOAD & others
/* 0x00 == DFU_DETACH, 0x04 == DFU_CLRSTATUS, 0x06 == DFU_ABORT, and 0x01 == DFU_DNLOAD and 0x02 == DFU_UPLOAD */
if (!dfu_addr)
Expand All @@ -225,13 +225,15 @@ static void USB_Service(void)
}
}

extern int __RAM_segment_used_end__;
#define DBL_TAP_PTR (uint32_t *)(&__RAM_segment_used_end__)
#define DBL_TAP_MAGIC 0xf02669ef
#ifdef USE_DBL_TAP
extern int __RAM_segment_used_end__;
static volatile uint32_t *DBL_TAP_PTR = (volatile uint32_t *)(&__RAM_segment_used_end__);
#define DBL_TAP_MAGIC 0xf02669ef
#endif

void bootloader(void)
{
#ifndef DBL_TAP_MAGIC
#ifndef USE_DBL_TAP
/* configure PA15 (bootloader entry pin used by SAM-BA) as input pull-up */
PORT->Group[0].PINCFG[15].reg = PORT_PINCFG_PULLEN | PORT_PINCFG_INEN;
PORT->Group[0].OUTSET.reg = (1UL << 15);
Expand All @@ -250,7 +252,7 @@ void bootloader(void)
if (DSU->DATA.reg)
goto run_bootloader; /* CRC failed, so run bootloader */

#ifndef DBL_TAP_MAGIC
#ifndef USE_DBL_TAP
if (!(PORT->Group[0].IN.reg & (1UL << 15)))
goto run_bootloader; /* pin grounded, so run bootloader */

Expand Down
Loading

0 comments on commit 15c35fc

Please sign in to comment.