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

Commit

Permalink
added D21 project file
Browse files Browse the repository at this point in the history
  • Loading branch information
majbthrd committed Apr 28, 2018
1 parent 1441712 commit 81d9965
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 90 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.bak
D11bootloader THUMB Debug\*
D11bootloader THUMB Release\*
D11bootloader THUMB Debug/*
D11bootloader THUMB Release/*
D11bootloader THUMB Debug/*
D11bootloader THUMB Release/*
*.hzs
79 changes: 0 additions & 79 deletions D11bootloader.hzp

This file was deleted.

123 changes: 123 additions & 0 deletions Dx1bootloader.hzp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!DOCTYPE CrossStudio_Project_File>
<solution Name="Dx1bootloader" target="8" version="2">
<project Name="D11bootloader">
<configuration
Name="Common"
Placement="Flash"
Target="ATSAMD11D14AM"
arm_architecture="v6M"
arm_core_type="Cortex-M0+"
arm_endian="Little"
arm_fpu_type="None"
arm_interwork="No"
arm_linker_heap_size="256"
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)"
arm_simulator_memory_simulation_parameter="SAM D,SAM D11;FLASH,0x00000000,0x00004000,ROM;RAM,0x20000000,0x00001000,RAM"
arm_target_debug_interface_type="ADIv5"
arm_target_interface_type="SWD"
arm_target_loader_applicable_loaders="Flash"
arm_target_loader_default_loader="Flash"
c_user_include_directories="$(DeviceIncludePath);$(PackagesDir)/CMSIS_4/CMSIS/Include;$(TargetsDir)/SAM_D/CMSIS/Device/Include;$(ProjectDir)"
debug_initial_breakpoint="bootloader"
debug_register_definition_file="$(DeviceRegisterDefinitionFile)"
gcc_entry_point="Reset_Handler"
linker_memory_map_file="$(DeviceMemoryMapFile)"
linker_section_placement_file="$(StudioDir)/targets/Cortex_M/flash_placement.xml"
macros="DeviceIncludePath=$(TargetsDir)/SAM_D/CMSIS/Device/SAMD11/Include;DeviceLoaderFile=$(TargetsDir)/SAM_D/Loader/SAM_D11_Loader.elf;DeviceMemoryMapFile=$(TargetsDir)/SAM_D/XML/ATSAMD11D14AM_MemoryMap.xml;DeviceRegisterDefinitionFile=$(TargetsDir)/SAM_D/XML/ATSAMD11D14AM_Registers.xml;DeviceFamily=SAM D;DeviceSubFamily=SAM D11"
package_dependencies="SAM_D"
project_directory=""
project_type="Executable"
property_groups_file_path="$(TargetsDir)/SAM_D/XML/property_groups.xml"
target_get_partname_script="GetPartName()"
target_match_partname_script="MatchPartName(&quot;$(Target)&quot;)"
target_reset_script="Reset();"
target_script_file="$(TargetsDir)/SAM_D/Scripts/SAM_D_Target.js"
target_trace_initialize_script="EnableTrace(&quot;$(TraceInterfaceType)&quot;)" />
<configuration
Name="Flash"
arm_target_flash_loader_file_path="$(DeviceLoaderFile)" />
<folder Name="Source Files">
<configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" />
<file file_name="bootloader.c" />
<file file_name="usb_descriptors.c" />
<file file_name="startup.s" />
</folder>
<configuration Name="Release" linker_output_format="srec" />
</project>
<configuration Name="THUMB Debug" inherited_configurations="THUMB;Debug" />
<configuration
Name="THUMB"
Platform="ARM"
arm_instruction_set="Thumb"
arm_library_instruction_set="Thumb"
c_preprocessor_definitions="__THUMB"
hidden="Yes" />
<configuration
Name="Debug"
c_preprocessor_definitions="DEBUG"
gcc_debugging_level="Level 3"
gcc_omit_frame_pointer="Yes"
gcc_optimization_level="None"
hidden="Yes" />
<configuration
Name="THUMB Release"
inherited_configurations="THUMB;Release" />
<configuration
Name="Release"
c_preprocessor_definitions="NDEBUG"
gcc_debugging_level="Level 3"
gcc_omit_frame_pointer="Yes"
gcc_optimization_level="Level 1"
hidden="Yes" />
<configuration Name="Common" arm_compiler_variant="clang" />
<project Name="D21bootloader">
<configuration
CMSIS_CORE="Yes"
Name="Common"
Placement="Flash"
Target="ATSAMD21J18A"
arm_architecture="v6M"
arm_core_type="Cortex-M0+"
arm_endian="Little"
arm_fpu_type="None"
arm_interwork="No"
arm_linker_heap_size="256"
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)"
arm_simulator_memory_simulation_parameter="SAM D,SAM D21;FLASH,0x00000000,0x00040000,ROM;RAM,0x20000000,0x00008000,RAM"
arm_target_debug_interface_type="ADIv5"
arm_target_device_name="ATSAMD21J18A"
arm_target_interface_type="SWD"
arm_target_loader_applicable_loaders="Flash"
arm_target_loader_default_loader="Flash"
c_user_include_directories="$(DeviceIncludePath);$(TargetsDir)/SAM_D/CMSIS/Device/Include"
debug_initial_breakpoint="bootloader"
debug_register_definition_file="$(DeviceRegisterDefinitionFile)"
gcc_entry_point="Reset_Handler"
linker_memory_map_file="$(DeviceMemoryMapFile)"
linker_section_placement_file="$(StudioDir)/targets/Cortex_M/flash_placement.xml"
macros="DeviceIncludePath=$(TargetsDir)/SAM_D/CMSIS/Device/SAMD21/Include;DeviceLoaderFile=$(TargetsDir)/SAM_D/Loader/SAM_D21_Loader.elf;DeviceMemoryMapFile=$(TargetsDir)/SAM_D/XML/ATSAMD21J18A_MemoryMap.xml;DeviceRegisterDefinitionFile=$(TargetsDir)/SAM_D/XML/ATSAMD21J18A_Registers.xml;DeviceFamily=SAM D;DeviceSubFamily=SAM D21"
package_dependencies="SAM_D"
project_directory=""
project_type="Executable"
property_groups_file_path="$(TargetsDir)/SAM_D/XML/property_groups.xml"
target_get_partname_script="GetPartName()"
target_match_partname_script="MatchPartName(&quot;$(Target)&quot;)"
target_reset_script="Reset();"
target_script_file="$(TargetsDir)/SAM_D/Scripts/SAM_D_Target.js"
target_trace_initialize_script="EnableTrace(&quot;$(TraceInterfaceType)&quot;)" />
<configuration
Name="Flash"
arm_target_flash_loader_file_path="$(DeviceLoaderFile)" />
<configuration Name="Release" gcc_debugging_level="None" />
<folder Name="Source Files">
<file file_name="bootloader.c" />
<file file_name="startup.s" />
<file file_name="usb_descriptors.c" />
</folder>
<configuration Name="Release" linker_output_format="srec" />
</project>
</solution>
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
USB DFU Bootloader for SAMD11
=============================
USB DFU Bootloader for SAMD11 / SAMD21
======================================

Bootloaders are a dime a dozen, but existing USB bootloaders for the Atmel/Microchip SAMD11 all seem to be 4kBytes in size. To spent 25% of the SAMD11's flash on the bootloader seems excessive.
Bootloaders are a dime a dozen, but existing USB bootloaders for the Atmel/Microchip SAMDx1 all seem to be 4kBytes in size. To spent 25% of the SAMD11's flash on the bootloader seems quite excessive.

This bootloader is only 1kBytes and implements the industry-standard [DFU protocol](http://www.usb.org/developers/docs/devclass_docs/DFU_1.1.pdf) that is supported under multiple Operating Systems via existing tools such as [dfu-util](http://dfu-util.sourceforge.net/).

The linker memory map of the user application must be modified to have an origin at 0x0000_0400 rather than at 0x0000_0000. This bootloader resides at 0x0000_0000.

When booting, the bootloader checks whether a GPIO pin (nominally PA15) is connected to ground. If so, it runs the bootloader instead of the user application.

When branching to the user application, the bootloader includes functionality to update the [VTOR (Vector Table Offset Register)](http://infocenter.arm.com/help/topic/com.arm.doc.dui0662a/Ciheijba.html) and update the stack pointer to suit the value in the user application's vector table.
It is a much more space efficient alternative to the 4kB Atmel/Microchip [AN_42366](http://www.microchip.com//wwwAppNotes/AppNotes.aspx?appnote=en591491) SAM-BA Bootloader.

## Usage

Expand All @@ -19,6 +15,14 @@ Downloading can be accomplished with the existing [dfu-util](http://dfu-util.sou
dfu-util -D write.bin
```

## Specifics

The linker memory map of the user application must be modified to have an origin at 0x0000_0400 rather than at 0x0000_0000. This bootloader resides at 0x0000_0000.

When booting, the bootloader checks whether a GPIO pin (nominally PA15) is connected to ground. If so, it runs the bootloader instead of the user application.

When branching to the user application, the bootloader includes functionality to update the [VTOR (Vector Table Offset Register)](http://infocenter.arm.com/help/topic/com.arm.doc.dui0662a/Ciheijba.html) and update the stack pointer to suit the value in the user application's vector table.

## 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.1.1, using the Clang 5.0.1 compiler produces an 1010 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.
Expand Down
2 changes: 1 addition & 1 deletion bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/*- Includes ----------------------------------------------------------------*/
#include <stdbool.h>
#include <string.h>
#include <samd11.h>
#include <sam.h>
#include "usb.h"
#include "nvm_data.h"
#include "usb_descriptors.h"
Expand Down

0 comments on commit 81d9965

Please sign in to comment.