Creates an AVR project template for Unix/Linux systems based on a Makefile.
This project is inspired by the avr-proj program that is include in the CrossPack AVR software package for MacOS.
It offers a free alternative with improvements and extra options, which works with Linux operating systems in a simple but very useful program.
To install, dowload or clone this repository in your computer, then enter to the folder "apos" from the terminal and run the command "make" followed by the command "make install" as root: "sudo make install". It will install the program on your system:
$ git clone https://github.com/alfreedom/apos.git
$ cd apos
$ make
$ sudo make install
The default installation path is /opt/apos/. To check the installation run the command apos -?
$ apos --help
or
$ apos -v
You need to have installed the avr-gcc toolchain and the avrdude program to compile your AVR source code. To install it run someone of the commands below depending of your operating system.
$ sudo apt-get install gcc-avr binutils-avr avr-libc avrdude
$ sudo yum install avr-gcc avr-binutils avr-libc avrdude
$ sudo pacman -Sy avr-gcc avr-binutils avr-libc avrdude
$ brew tap osx-cross/avr
$ brew install avrdude avr-gcc avr-binutils
To use the hardware programmers with avrdude without root permissions, it is necessary to add the rules of programmers to the system. Depending of your Linux distribution, you must change the name of the group to which the device rules belong. For Debian and derivatives the "dialout" group is used, for Fedora it is "users" and for Arch it is "uucp".
The file must be created in the path "/etc/udev/rules.d/", with a name, for example, "90-avr.rules":
sudo nano /etc/udev/rules.d/90-avr.rules
And once the file is created, paste the following content by modifying the name of the group depending on the version of the operating system:
# Programmers for avrdude
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2104", GROUP="uucp", MODE="0660" # AVRISP mkII
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2107", GROUP="uucp", MODE="0660" # AVR-Dragon
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2103", GROUP="uucp", MODE="0660" # JTAG ICE mkII
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2106", GROUP="uucp", MODE="0660" # STK600
ATTR{idVendor}=="16c0", ATTR{idProduct}=="05dc", GROUP="uucp", MODE="0660" # USBASP von www.fischl.de
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2ffa", GROUP="uucp", MODE="0660" # AT90USB
ATTR{idVendor}=="10c4", ATTR{idProduct}=="ea60", GROUP="uucp", MODE="0660" # AVR910
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2105", GROUP="uucp", MODE="0660" # AVR ONE
ATTR{idVendor}=="03eb", ATTR{idProduct}=="210d", GROUP="uucp", MODE="0660" # Atmel XPLAIN CDC Gateway
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2ffb", GROUP="uucp", MODE="0660" # AT90USB AVR DFU bootloader
ATTR{idVendor}=="1781", ATTR{idProduct}=="0c9f", GROUP="uucp", MODE="0660" # usbtiny
To reload the device rules, execute the commands below:
sudo udevadm control --reload
sudo udevadm trigger --action=add
This help show you how to create a project, configure it, and also how to add your own code. To create a new project run the command "apos" followed by the name of the project.
This will create a folder containing the main.c file, the folders 'src', 'include' and the Makefile.
-b Creates a blink project template
-c Defines the avrdude programmer (e.g usbasp, usbtiny, dragon_isp, etc.)
-e Defines the Extended Fuse (2 digit hex format)
-f Define the CPU Frequency in Hz (default 16000000)
-g Initialize a GIT repository in the project folder
-h Defines the High Fuse (2 digit hex format)
-l Defines the Low Fuse (2 digit hex format)
-m Define the Microcontroller (default: atmega128)
-p Define the ABOS Loader serial port (default: /dev/ttyUSB0)
-s Define the ABOS Loader baudrate (default: 38400)
-v Shows the apos version
--help Show this help
To create a empty project, type in a terminal the command:
$ apos my_proyect
You can define another project params like the AVR Microcontroller model, the CPU Frequency, the fuses and the usb programmer. The program is able to create a blink example project and initialize the project with a Git repository.
To create a project for the ATmega328 that run at 16MHz and will be flashed with a USBtiny programmer, type in a terminal the command:
$ apos -m atmega328p -f 16000000 -c usbtiny my_proyect
If you want to create a git repository, add the "-g" option before the project name. In the same way add the "-b" option if you want to create the project with a blink program template.
To specify the abos loader serial port and baudrate add -p and -s respectively:
$ apos -m atmega128 -f 16000000 -c usbtiny -p /dev/ttyUSB0 -s 38400 my_proyect
If you need to change the microcontroller frequency, model, programmer, fuses or another configuration, edit the lines from 6 to 14 in Makefile.
5
6 PROJECT_NAME = my_project
7 DEVICE = atmega128
8 CLOCK = 16000000
9 FUSES = -U hfuse:w:0xD9:m -U lfuse:w:0xFF:m #-U efuse:w:0xFF:m
10 AVRDUDE_PROG = -c usbtiny -P usb
11 ABOS_PORT = /dev/tty.usbserial-1A12430
12 ABOS_BAUDRATE = 38400
13 AVRDUDE_OPS = -B 0.5
14 AVRDUDE = avrdude -p $(DEVICE) $(AVRDUDE_PROG) $(AVRDUDE_OPS)
15
To generate the .hex file, you need to open a terminal and go to the project folder, then type the command:
$ make
If all is ok, the compilation information will be shown in the terminal with usage data from the flash memory, ram and eeprom.
Adding you own hardware drivers and libraries is very simple, only put your header and source files in the 'lib' directory or another directory.
The final step is uncomment and copy the lines 15 and 19 of the 'Makefile' to add your source files and include paths.
15
16 OBJECT_FILES = main.o
17 #OBJECT_FILES += ./lib/mySource.o
18
19 INCLUDEPATHS = -I .
20 INCLUDEPATHS = -I ./lib
21 #INCLUDEPATHS += -I ./myFolder
22
Save changes and type "make" to compile your new code.
To compile the source code type the command:
$ make
or
$ make all
To clean (erase all compiled outputs) the project type the command:
$ make clean
To program the flash memory of the AVR with the .hex file and the avrdude programmer configurated, type the command:
$ make flash
To program the AVR usign ABOS Bootloader, type the command:
$ make abos
To erase the memories of the AVR type the command:
$ make erase
To reset the AVR microcontroller type the command:
$ make reset
To program the AVR fuses configurated in the makefile type the command:
$ make fuses
To program the AVR fuses, the .hex program and the .eep eeprom file type the command:
$ make install
To program the AVR EEPROM memory whit the generate .eep file type the command:
$ make eeprom
To read the contents of the flash memory type the command:
$ make read_flash
It will be generate a *.flash.bin file.
To read the contents of the eeprom memory type the command:
$ make read_eeprom
It will be generate a *.eeprom.bin file.
To disassemble the compiled .elf code type the command:
$ make disasm
Copyright © 2017-2023 Alfredo Orozco [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/