Skip to content

Commit

Permalink
Added the Firmware (that includes the Bootloader implementation).
Browse files Browse the repository at this point in the history
  • Loading branch information
filcarv committed Jul 12, 2020
1 parent 57ef8ef commit ee199e7
Show file tree
Hide file tree
Showing 28 changed files with 6,155 additions and 0 deletions.
100 changes: 100 additions & 0 deletions Firmware/Bootloader/Bootloader.cproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>6.2</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
<avrdevice>ATxmega128A4U</avrdevice>
<avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType>
<Language>C</Language>
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
<OutputFileExtension>.elf</OutputFileExtension>
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
<AssemblyName>Bootloader</AssemblyName>
<Name>Bootloader</Name>
<RootNamespace>Bootloader</RootNamespace>
<ToolchainFlavour>Native</ToolchainFlavour>
<KeepTimersRunning>true</KeepTimersRunning>
<OverrideVtor>false</OverrideVtor>
<CacheFlash>true</CacheFlash>
<ProgFlashFromRam>true</ProgFlashFromRam>
<RamSnippetAddress>0x20000000</RamSnippetAddress>
<UncachedRange />
<preserveEEPROM>true</preserveEEPROM>
<OverrideVtorValue>exception_table</OverrideVtorValue>
<BootSegment>2</BootSegment>
<eraseonlaunchrule>0</eraseonlaunchrule>
<AsfFrameworkConfig>
<framework-data xmlns="">
<options />
<configurations />
<files />
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.21.0" />
</dependencies>
</framework-data>
</AsfFrameworkConfig>
<avrtool>
</avrtool>
<avrtoolinterface>PDI</avrtoolinterface>
<com_atmel_avrdbg_tool_atmelice>
<ToolOptions>
<InterfaceProperties>
<PdiClock>4000000</PdiClock>
</InterfaceProperties>
<InterfaceName>PDI</InterfaceName>
</ToolOptions>
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
<ToolNumber>J41800031896</ToolNumber>
<ToolName>Atmel-ICE</ToolName>
</com_atmel_avrdbg_tool_atmelice>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.optimization.level>Optimize most (-O3)</avrgcc.compiler.optimization.level>
<avrgcc.linker.miscellaneous.LinkerFlags>-Wl,--section-start=.text=0x20000</avrgcc.linker.miscellaneous.LinkerFlags>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="parse.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="cpu.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="flash.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="main.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="sp_driver.S">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>
169 changes: 169 additions & 0 deletions Firmware/Bootloader/Debug/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################

SHELL := cmd.exe
RM := rm -rf

USER_OBJS :=

LIBS :=
PROJ :=

O_SRCS :=
C_SRCS :=
S_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
PREPROCESSING_SRCS :=
OBJS :=
OBJS_AS_ARGS :=
C_DEPS :=
C_DEPS_AS_ARGS :=
EXECUTABLES :=
OUTPUT_FILE_PATH :=
OUTPUT_FILE_PATH_AS_ARGS :=
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
QUOTE := "
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:=
LIB_DEP:=
LINKER_SCRIPT_DEP:=

# Every subdirectory with source files must be described here
SUBDIRS :=


# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../parse.c \
../cpu.c \
../flash.c \
../main.c


PREPROCESSING_SRCS += \
../sp_driver.S


ASM_SRCS +=


OBJS += \
parse.o \
cpu.o \
flash.o \
main.o \
sp_driver.o

OBJS_AS_ARGS += \
parse.o \
cpu.o \
flash.o \
main.o \
sp_driver.o

C_DEPS += \
parse.d \
cpu.d \
flash.d \
main.d \
sp_driver.d

C_DEPS_AS_ARGS += \
parse.d \
cpu.d \
flash.d \
main.d \
sp_driver.d

OUTPUT_FILE_PATH +=Bootloader.elf

OUTPUT_FILE_PATH_AS_ARGS +=Bootloader.elf

ADDITIONAL_DEPENDENCIES:=

OUTPUT_FILE_DEP:= ./makedep.mk

LIB_DEP+=

LINKER_SCRIPT_DEP+=


# AVR32/GNU C Compiler









./%.o: .././%.c
@echo Building file: $<
@echo Invoking: AVR/GNU C Compiler : 4.8.1
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -O3 -ffunction-sections -fdata-sections -mrelax -mmcu=atxmega128a4u -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<




# AVR32/GNU Preprocessing Assembler



# AVR32/GNU Assembler
./sp_driver.o: .././sp_driver.S
@echo Building file: $<
@echo Invoking: AVR32/GNU Assembler : 4.8.1
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -Wa,-gdwarf2 -x assembler-with-cpp -c -mmcu=atxmega128a4u -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -mrelax -o "$@" "$<"
@echo Finished building: $<



./%.o: .././%.S
@echo Building file: $<
@echo Invoking: AVR32/GNU Assembler : 4.8.1
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -Wa,-gdwarf2 -x assembler-with-cpp -c -mmcu=atxmega128a4u -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -mrelax -o "$@" "$<"
@echo Finished building: $<





ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

# Add inputs and outputs from these tool invocations to the build variables

# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)

$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
@echo Building target: $@
@echo Invoking: AVR/GNU Linker : 4.8.1
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="Bootloader.map" -Wl,--start-group -Wl,--end-group -Wl,--gc-sections -mrelax -mmcu=atxmega128a4u -Wl,--section-start=.text=0x20000
@echo Finished building target: $@
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "Bootloader.elf" "Bootloader.hex"
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "Bootloader.elf" "Bootloader.eep" || exit 0
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "Bootloader.elf" > "Bootloader.lss"
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "Bootloader.elf" "Bootloader.srec"
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-size.exe" "Bootloader.elf"







# Other Targets
clean:
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
-$(RM) $(C_DEPS_AS_ARGS)
rm -rf "Bootloader.elf" "Bootloader.a" "Bootloader.hex" "Bootloader.lss" "Bootloader.eep" "Bootloader.map" "Bootloader.srec" "Bootloader.usersignatures"

14 changes: 14 additions & 0 deletions Firmware/Bootloader/Debug/makedep.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
################################################################################
# Automatically-generated file. Do not edit or delete the file
################################################################################

parse.c

cpu.c

flash.c

main.c

sp_driver.S

59 changes: 59 additions & 0 deletions Firmware/Bootloader/binary_protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef _BINARY_PROTOCOL_H_
#define _BINARY_PROTOCOL_H_
#include <avr/io.h>

/*
== Bootloader Protocol ==
Master: [01] [02] [03] [Op Code] [Error] [Address (4 Bytes)] [Data Length (4 Bytes)] [[Data] (n)] [Checksum (16 bits)]
Slave: [01] [02] [03] [Op Code] [Error] [Address (4 Bytes)] [Data Length (4 Bytes)] [[Data] (n)] [Checksum (16 bits)]
Command
[00] Write Page
[01] Read Page (not implemented on firmware)
[02] Write EEPROM
[03] Read EEPROM
[66] Get Page Size of the device (the field Data is not used)
[77] Leave Bootloader and go to Application Code
Error
[00] No error
[01] Generic error
[02] Address not correct
[03] Data Length not correct
Data
The length of Data is fixed and depends on the microcontroller family.
-> ATXMega : 512 bytes
If the Data bytes are not all used, the used bytes should appear in the lowest index positions of the Data vector.
*/

/************************************************************************/
/* Protocol */
/************************************************************************/
#define OP_CODE_WRITE_PAGE 0x00
#define OP_CODE_WRITE_EEPROM 0x02
#define OP_CODE_READ_EEPROM 0x03
#define OP_CODE_GET_PAGE_SIZE 0x66
#define OP_CODE_LEAVE_BOOTLOADER 0x77

#define NO_ERROR 0
#define GENERIC_ERROR 1
#define ERROR_ON_ADDRESS 2
#define ERROR_ON_DATA_LENGTH 3

typedef struct
{
uint8_t header[3];
uint8_t op_code;
uint8_t error;
uint32_t address;
uint32_t data_length;
uint8_t data[SPM_PAGESIZE];
uint16_t checksum;
} protocol_t;

#endif /* _BINARY_PROTOCOL_H_ */
Loading

0 comments on commit ee199e7

Please sign in to comment.