Avr gcc toolchain linux

How to setup the AVR toolchain on Linux

This guide will help you get your environment set up to build projects on the Atmel AVR chips (e.g. ATmega328, ATtiny85, etc.) projects on Windows using Linux-based (Ubuntu) tools.

Tutorial Versions

  1. Windows-based AVR toolchain

    This options primarily uses Windows-based tools and has two variations depending on how you run make

    • Windows + GnuWin32
    • Windows + WSL
  2. WSL-based AVR toolchain

    This options primarily uses WSL-based linux tools and has two variations depending on how you program the chip – either WSL-based avrdude using usbip to access the USB programmer or Windows-based avrdude to natively access the USB programmer

    • WSL + usbip
    • WSL + Windows
  3. Linux-based AVR toolchain (this guide)

    This option uses all native linux-based tools on a native Linux installation.

Install the AVR tools

All the packages we need are already available in Ubuntu. Depending on your distribution release, the tools may not be the latest, but should be fine in most cases.

If you need the latest versions or need to do a manual install for some reason, follow this guide instead: How to manually install AVR tools on Linux (or WSL2)

We can install all the tools we need in a single command.

$ sudo apt install make gcc-avr avr-libc avrdude

Let’s run a quick check that all the tools are installed before we continue by running following commands:

make -v avr-gcc --version avrdude -v 

The output should look something like this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
$ make -v GNU Make 4.2.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later  This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $ avr-gcc --version avr-gcc (GCC) 5.4.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ avrdude -v avrdude: Version 6.3-20171130 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2014 Joerg Wunsch System wide configuration file is "/etc/avrdude.conf" User configuration file is "/home/tony/.avrduderc" User configuration file does not exist or is not a regular file, skipping avrdude: no programmer has been specified on the command line or the config file Specify a programmer using the -c option and try again 

If any of those produced an error or could not be found, you’ll need to re-visit the installation steps before continuing.

Читайте также:  Linux mint установить nouveau

Testing the AVR toolchain

To test that everything is working correctly, let’s try building a sample program and writing it to an Arduino. If you don’t have an Arduino handy, you can either skip the avrdude step or adjust the program and commands to fit your scenario.

In a new directory, create a new file named blink.c and paste the following program into it. This is a AVR implementation of the classic Arduino Blink sketch. If you load this to an Arduino it will make the built-in LED (pin 13/LED_BUILTIN) flash on and off every 500ms.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include  #include  int main()  // Set built-in LED pin as output DDRB |= (1  <DDB5); while (1)  PORTB |= (1  <PB5); // LED on _delay_ms(500); PORTB &= ~(1  <PB5); // LED off _delay_ms(500); > return 0; > 

In the directory you created the file, run the following commands. Make sure you plug in your Arduino before running avrdude and update the device port to match the one assigned to your Arduino.

avr-gcc blink.c -o blink.elf -mmcu=atmega328 -DF_CPU=16000000UL -Os avr-objcopy blink.elf -O ihex blink.hex avrdude -c arduino -p m328p -U flash:w:"blink.hex":a -P /dev/ttyACM0

If everything is working you should see something like.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
$ avr-gcc blink.c -o blink.elf -mmcu=atmega328 -DF_CPU=16000000UL -Os $ avr-objcopy blink.elf -O ihex blink.hex $ avrdude -c arduino -p m328p -U flash:w:"blink.hex":a -P /dev/ttyACM0 avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.00s avrdude: Device signature = 0x1e950f (probably m328p) avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "blink.hex" avrdude: input file blink.hex auto detected as Intel Hex avrdude: writing flash (176 bytes): Writing | ################################################## | 100% 0.04s avrdude: 176 bytes of flash written avrdude: verifying flash memory against blink.hex: avrdude: input file blink.hex auto detected as Intel Hex Reading | ################################################## | 100% 0.03s avrdude: 176 bytes of flash verified avrdude done. Thank you. 

Next Steps

That’s all there is to it. To continue setting up your development environment check out my other posts on building projects with a Makefile and configuring VS Code:

Troubleshooting

How do I find out what port my Arduino is using? TBD — Easiest is dmesg / lsusb How do I run avrdude without sudo? TBD — udev rule / plugdev group

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Prebuilt upstream avr-gcc for Linux

modm-io/avr-gcc

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Up-to-date AVR GNU GCC Toolchain from source

Download the latest modm-avr-gcc.tar.bz2 from Releases and unpack it to /opt :

tar xf modm-avr-gcc.tar.bz2 --directory /opt

Add the bin/ directory to your $PATH , e.g. by adding the following line to your ~/.bashrc file:

export PATH="/opt/avr-gcc/bin:$PATH"

Building locally with Docker

There is a Docker image with all prerequisites for building, created from the Dockerfile in this repository. Build the image from the local Dockerfile and start it:

docker build --tag avr-gcc-prerequisites:local . docker run -it avr-gcc-prerequisites:local

Inside the Docker container get this repository

git clone https://github.com/modm-io/avr-gcc.git

The toolchain will be in /opt/avr-gcc .

Building in Github Actions

There is a Github Actions job defined in .github/workflows/ which builds the toolchain. For tagged commits, a Github release will be created with the toolchain put into a downloadable .tar.bz2 at Releases.

About

Prebuilt upstream avr-gcc for Linux

Источник

Оцените статью
Adblock
detector