-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TychoJ/example
Example
- Loading branch information
Showing
4 changed files
with
216 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# makefile.xmega.mk | ||
# ^^^^^^^^^^^^^^^^^ | ||
# Author : TychoJ | ||
# Versie : 0.1 | ||
# | ||
# Inspired by : Edwin Boer | ||
# | ||
# File : make.avr.mk | ||
# Contains : The configurations for make.avr.mk | ||
|
||
# Source code folder | ||
SRCFOLDER = src/ | ||
# Object folder | ||
OBJFOLDER = obj/ | ||
# Binary folder | ||
BINFOLDER = bin/ | ||
# Path to the folder containing the bin/ folder of the AVR toolchain (Keep empty if avr-gcc is added to the $PATH) | ||
AVRFOLDER = | ||
# # Path to the folder containing avrdude (Keep empty if avrdude is added to the $PATH) | ||
DUDEFOLDER = | ||
|
||
# Project name | ||
PROJECTNAME = blink | ||
# The AVR microcontroller | ||
MICROCONTROLLER = atxmega256a3u | ||
# The AVR programmer (o.a. avrisp2 and ) | ||
# avrisp2 Atmel AVR ISP mkII | ||
# atmelice Atmel-ICE (ARM/AVR) in JTAG mode | ||
# atmelice_dw Atmel-ICE (ARM/AVR) in debugWIRE mode | ||
# atmelice_isp Atmel-ICE (ARM/AVR) in ISP mode | ||
# atmelice_pdi Atmel-ICE (ARM/AVR) in PDI mode | ||
# atmelice_updi Atmel-ICE (ARM/AVR) in UPDI mode | ||
PROGRAMMER = atmelice_isp | ||
# The (optional) port of the avr programmer (usb, /dev/tty.#) | ||
# PORT = usb | ||
# The fuse values: low, high and extended | ||
# See http://www.engbedded.com/fusecalc/ for fuse values of other microcontrollers | ||
FUSELOW = | ||
FUSEHIGH = | ||
FUSEEXT = | ||
# source code (without external libraries) | ||
SOURCE = blink.c | ||
# External source code library folders | ||
EXTFOLDER = | ||
# Compiler flags | ||
CFLAGS = -Wall | ||
|
||
# Execute the configurations | ||
include make.avr.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# makefile.xmega.mk | ||
# ^^^^^^^^^^^^^^^^^ | ||
# Author : TychoJ | ||
# Versie : 0.1 | ||
# | ||
# Inspired by : Edwin Boer | ||
# | ||
# File : make.avr.mk | ||
# Contains : The make process for building/flashing/debuging of AVR microcontrollers | ||
# The settings for this make file can be found in: Makefile | ||
|
||
# Generate a list of folders to be included | ||
INCLUDELIST := $(foreach dir, $(EXTFOLDER), -I$(dir)) | ||
# Generate a list of source code files relative of the source folder | ||
CLIST := $(foreach file, $(SOURCE), $(SRCFOLDER)$(file)) | ||
# Generate a list of library files | ||
EXTLIST := $(foreach dir, $(EXTFOLDER), $(wildcard $(SRCFOLDER)$(dir)/*.c)) | ||
# Generate a list of object files | ||
OBJLIST := $(patsubst %.c, %.o, $(CLIST)) $(patsubst %.c, %.o, $(EXTLIST)) | ||
# Generate a list of object files in the object(sub)folder | ||
OBJLIST2 := $(foreach file, $(OBJLIST), $(OBJFOLDER)$(file)) | ||
|
||
# Define all tools with standard settings | ||
TOOLC = $(AVRFOLDER)avr-gcc $(CFLAGS) -Os -mmcu=$(MICROCONTROLLER) | ||
TOOLCOPY = $(AVRFOLDER)avr-objcopy | ||
TOOLSIZE = $(AVRFOLDER)avr-size --format=avr --mcu=$(MICROCONTROLLER) | ||
TOOLDUMP = $(AVRFOLDER)avr-objdump | ||
ifdef PORT | ||
TOOLDUDE = $(DUDEFOLDER)avrdude -c $(PROGRAMMER) -p $(MICROCONTROLLER) -P $(PORT) | ||
else | ||
TOOLDUDE = $(DUDEFOLDER)avrdude -c $(PROGRAMMER) -p $(MICROCONTROLLER) | ||
endif | ||
|
||
# Public goals | ||
|
||
# Goal: make help | ||
help: _start _help1 _end | ||
|
||
_start: | ||
@echo | ||
@echo "#################################" | ||
@echo " > Start: make.avr.mk" | ||
|
||
_help1: | ||
@echo "_________________________________" | ||
@echo " > Possible options:" | ||
@echo " make := Show this help message." | ||
@echo " make help := Show this help message." | ||
@echo " make all := Compile and link the source code." | ||
@echo " make flash := Compile and link the source code and write the compiled hex-file to" | ||
@echo " the flash memory of the microcontroller" | ||
@echo " make test := Test the connection between the programmer and the microcontroller." | ||
@echo " make fuse := Write the fuse bytes to the mircrocontroller." | ||
@echo " make disasm := Disassemble the code for debugging." | ||
@echo " make clean := Delete all generated .hex, .elf, and .o files." | ||
|
||
_end: | ||
@echo | ||
@echo "#################################" | ||
@echo " > Finished :-)" | ||
@echo | ||
|
||
# Goal: make all | ||
all: _start _all1 $(BINFOLDER)$(PROJECTNAME).hex _end | ||
|
||
_all1: | ||
@echo " > Goal: Compile and link the source code." | ||
@echo " > Object folder: $(OBJFOLDER)" | ||
@echo " > Binary folder: $(BINFOLDER)" | ||
@mkdir -p $(OBJFOLDER) | ||
@mkdir -p $(BINFOLDER) | ||
|
||
# Goal: make flash | ||
flash: _start _flash1 $(BINFOLDER)$(PROJECTNAME).hex _flash2 _end | ||
|
||
_flash1: | ||
@echo " > Goal: Compile and link the source code and write the compiled hex-file to the flash memory of the microcontroller." | ||
@echo " > binaray folder: $(BINFOLDER)" | ||
@mkdir -p $(BINFOLDER) | ||
|
||
_flash2: | ||
@echo "_________________________________" | ||
@echo " > Start flash" | ||
$(TOOLDUDE) -e -U flash:w:$(BINFOLDER)$(PROJECTNAME).hex | ||
|
||
# Goal: make test | ||
test: _start _test1 _end | ||
|
||
_test1: | ||
@echo " > Goal: Test the connection between the programmer and the microcontroller." | ||
$(TOOLDUDE) -v | ||
|
||
# Goal: make fuse | ||
fuse: _start _fuse1 _end | ||
|
||
_fuse1: | ||
@echo " > Goal: Write the fuse bytes to the mircrocontroller." | ||
$(TOOLDUDE) -U lfuse:w:$(FUSELOW):m -U hfuse:w:$(FUSEHIGH):m -U efuse:w:$(FUSEEXT):m | ||
|
||
# Goal: make disasm | ||
disasm: _start _disasm1 $(BINFOLDER)/$(PROJECTNAME).elf _disasm2 _end | ||
|
||
_disasm1: | ||
@echo " > Goal: Disassemble the code for debugging." | ||
|
||
_disasm2: $(BINFOLDER)/$(PROJECTNAME).elf | ||
$(TOOLDUMP) -d $(BINFOLDER)$(PROJECTNAME).elf | ||
|
||
# Goal: make clean | ||
clean: _start _clean _end | ||
|
||
_clean: | ||
@echo " > Goal: Delete all generated .hex, .elf, and .o files." | ||
rm -f $(BINFOLDER)$(PROJECTNAME).hex | ||
rm -f $(BINFOLDER)$(PROJECTNAME).elf | ||
rm -f -r $(OBJFOLDER)$(SRCFOLDER) | ||
|
||
# Create specific file formats | ||
$(BINFOLDER)$(PROJECTNAME).hex: $(BINFOLDER)$(PROJECTNAME).elf | ||
@echo "_________________________________" | ||
@echo " > Generate hex-file" | ||
rm -f $(BINFOLDER)$(PROJECTNAME).hex | ||
$(TOOLCOPY) -j .text -j .data -O ihex $(BINFOLDER)$(PROJECTNAME).elf $(BINFOLDER)$(PROJECTNAME).hex | ||
@echo "_________________________________" | ||
@echo " > Memory usage" | ||
$(TOOLSIZE) $(BINFOLDER)$(PROJECTNAME).elf | ||
|
||
$(BINFOLDER)$(PROJECTNAME).elf: _compiler $(OBJLIST) | ||
@echo "_________________________________" | ||
@echo " > Start linker" | ||
$(TOOLC) -o $(BINFOLDER)$(PROJECTNAME).elf $(OBJLIST2) | ||
|
||
_compiler: | ||
@echo "OBJLIST: $(OBJLIST)" | ||
@echo "OBJLIST2: $(OBJLIST2)" | ||
@echo "_________________________________" | ||
@echo " > Start compiler" | ||
|
||
%.o: %.c | ||
@mkdir -p $(OBJFOLDER)$(dir $@) | ||
@echo "test" | ||
$(TOOLC) $(INCLUDELIST) -c -o $(OBJFOLDER)$@ $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//#define __ATxmega256A3U__ | ||
#define __AVR_ATxmega256A3U__ | ||
|
||
#define F_CPU 2000000UL // clock is running at 2MHz | ||
|
||
#include <avr/io.h> | ||
#include <util/delay.h> | ||
|
||
int main(void) { | ||
PORTC.DIRSET = PIN0_bm; // bit 0 port C is set, it is an output | ||
PORTF.DIRSET = PIN1_bm; // bit 0 port f is set, it is an output | ||
|
||
while (1) { | ||
PORTC.OUTSET = PIN0_bm; // bit 0 port C is high, led is on | ||
PORTF.OUTCLR = PIN1_bm; // bit 0 port f is low, led is off | ||
_delay_ms(250); | ||
PORTC.OUTCLR = PIN0_bm; // bit 0 port C is low, led is off | ||
PORTF.OUTSET = PIN1_bm; // bit 0 port f is high, led is on | ||
_delay_ms(250); | ||
} | ||
} |