Go Down

Topic: LoseAVR - An Updated Version of WinAVR (Read 3848 times) previous topic - next topic


Jul 04, 2018, 11:44 pm Last Edit: Aug 09, 2018, 08:06 pm by MultipleMonomials
LoseAVR - because sometimes you WinAVR, other times you LoseAVR

We all know that WinAVR is getting kind of old.  It's been eight years since its last update, and it's getting to the point where many things don't work properly with its antiquated versions of GCC and AVRDUDE.  So, I made a new version!  Compiled for Win64 using MinGW, it replicates the functionality of WinAVR, with updated versions of its constituent programs.  It also fixes WinAVR's issues with USB drivers, and contains prebuilt core libraries for all Arduino variants, so you can skip all that fiddling around and get straight to developing Arduino programs.


• Up-to-date versions of AVR-GCC and all toolchain programs
• Ready for debugging with GDB and AVaRICE
• AVRDUDE and AVaRICE are built with full USB support
• Uses libusb 1.0 for USB communication instead of the deprecated libusb-win32.  This means that you never have to disable driver signature enforcement
• Includes CMake toolchain file for easily building AVR/Arduino programs with CMake
• Includes prebuilt Arduino cores for each board
• Small download size at 24MB

Included Programs

• Compilation:
○ avr-binutils 2.30 (https://sourceware.org/binutils/)
○ avr-gcc 7.3.0 (https://gcc.gnu.org/)
○ avr-libc 2.0.0 (https://www.nongnu.org/avr-libc/)
○ Arduino core libraries (https://github.com/arduino/Arduino) (+ my custom builder)

• Upload:
○ AVRDUDE 6.3 (https://www.nongnu.org/avrdude/)
○ AVRDUDESS 2.4 (http://blog.zakkemble.co.uk/avrdudess-a-gui-for-avrdude/)
○ Zadig 2.2 (http://zadig.akeo.ie)

• Debugging:
○ avr-gdb 8.1 (https://www.gnu.org/software/gdb/)
○ AVaRICE 2.13 (patched for modern GCC) (http://avarice.sourceforge.net/)
○ simulavr 1.0.0 (https://www.nongnu.org/simulavr/)

• Libraries (dependencies of other things):
○ libftdi1 1.4 (https://www.intra2net.com/en/developer/libftdi/)
○ libusb 1.0.22 (http://libusb.info/)
○ libusb-compat 0.1.6  (https://github.com/libusb/libusb-compat-0.1)


Current version: LoseAVR-20180312-Win64.7z
You will need 7-Zip or another archive program to uncompress this.

Technical Notes

• I attempted to build the insight GUI for GDB, but could not get it working, so it has been left out of LoseAVR
• AVaRICE is not ported to Windows, so it was built against MSYS2's runtime (msys-2.0.dll).  All other programs are straight Windows applications compiled with MinGW
• I rewrote AVaRICE's shell scripts as batch files, so they are now usable under Windows

Known Issues
• When a USB device has the wrong driver set up, AVRDUDE may report the wrong error message, "Function not implemented".  It should say something like "Incorrect driver installed!"
• There might be some sort of problem with temporary files and parallel builds in this GCC version.  If you get random compile errors that do not recur when building in parallel, try building with only one process, or using the "-pipe" option to GCC.

Appendix A: Installing USB drivers

LoseAVR makes it a LOT easier to get USB-based programmers working with AVRDUDE & AVaRICE.  The libusb-1.0 library that LoseAVR uses can use Windows' built-in generic driver, instead of making you disable driver signature enforcement and install a special libusb filter driver.

To set up a programmer, follow these steps:
1. Plug it in to a USB port.
2. Open zadig-2.2.exe from the LoseAVR root folder
3. Change the pull-down menu to your programmer.  You may have to check Options>Show All Devices for it to show up.
4. Make sure that the box on the right says "WinUSB".  You can also change it to "libusb-win32" if you want your device to work with WinAVR and the Arduino IDE, but you might have to disable driver signature enforcement for this to work.

5. Hit the install button.
6. Done!  Now you can use it with AVRDUDE and AVaRICE!

Appendix B: Using CMake to Build AVR Programs

Once you get your toolchain set up, the next problem is figuring out how to actually build your code.  The traditional solution has always been to use Makefiles or an IDE, but these can be kind of a pain to set up, especially on Windows and when you need to use the Arduino core libraries.

LoseAVR includes another solution: build files allowing you to use CMake to build Arduino programs.  To use it, first install CMake from here and add it to your PATH.  Next, simply write a regular CMake buildfile in your source folder, like this:

Code: [Select]

cmake_minimum_required(VERSION 3.1)

# set AVR build properties
set(AVR_UPLOAD_TOOL avrdude)
set(AVR_PROGRAMMER arduino)
set(AVR_MCU atmega328p)
set(MCU_SPEED "16000000")

# find Arduino core library
# note: the toolchain file sets CMAKE_FIND_ROOT_PATH to point to the LoseAVR root directory
set(ARDUINO_CORE_LIBRARIES ${CMAKE_FIND_ROOT_PATH}/arduino_cores/mega/atmega2560/lib/libarduino-core.a)

# source list
set(FOO_SOURCES foo.cpp bar.c)

# add the executable
add_avr_executable(foo ${FOO_SOURCES})
target_link_libraries(foo.elf ${ARDUINO_CORE_LIBRARIES})

Now, create a separate build folder, and open a command prompt there.  Run CMake, passing the path to your source directory:

cmake "-GMinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=C:\LoseAVR\share\cmake\generic-gcc-avr.cmake <path to source folder>

Next, run make to build your code:


Finally, run make to upload your code:

mingw32-make upload_foo

It's fast, easy, and runs natively to Windows!



Yes it does, I added mingw32-make, a version of Make that has been ported to handle Windows file paths.


Random comments:

We all know that WinAVR is getting kind of old.  It's been eight years since its last update
Were you aware that Atmel (now Microchip) has been distributing a CLI toolchain for Windows, Linux, and MacOS, for several years now, that mostly replaces WinAVR.  http://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-(c-compilers)
They're only at avr-gcc 5.4 or so, but they have patches and "packs" to support the latest chips.

Speaking of which: why avr-gcc 7.2?  It seems that the latest is 8.1 (http://blog.zakkemble.co.uk/avr-gcc-builds/) (seems to have bugs with -flto, though.)

7zip?  Does it really make that much of a difference?  I had to download a new app from the windows store, and it was really slow...  (huh.  I recompressed the dir with windows' standard tool.   THREE TIMES bigger than the 7zip version.  That's pretty impressive!)

32bit executables would work on both 32bit and 64bit windows.
At least, I assume that's the problem causing the
This version of C:\Users\billw\Downloads\LoseAVR\bin\simulavr.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
errors that I get, even on mingw32-make (doesn't that name imply 32bit?)  (what a useless error message!)

What are your ongoing plans?  I mean, it's nice of you to have put together a package with recent builds of the useful tools, but thing with Winavr is (well, "WAS") that supposedly someone was committed to making sure it got updates as tools (and windows) changed, and updates were "needed."

Nov 05, 2018, 12:22 pm Last Edit: Nov 07, 2018, 10:49 pm by ocsav
Please, can we have more info about this subject ?
I'd like to have a 'light' alternative to arduino ide, and by light let's say it is not the Atmel Studio way.
I have installed a VM with linux only to be able to make my flimsy sketches with vi and program them with tinyISP but I'd prefer to be able to do that from windows, but using a shell instead of cmd.exe (something like cygwin).

Is this the way to go?

hummm, some guidance about how to set this up would be a good thing too.
You never learn anything by doing it right.


Hi MultipleMonomials,

thanks for the effort, highly appreciated.

Works nice together with code::blocks!

Do you plan to keep this up-to-date orat least publish the source tree and build scripts/instructions ?




Please update avr-gcc to avr-gcc 7.4.0


Okay, to answer some questions:

Were you aware that Atmel (now Microchip) has been distributing a CLI toolchain?

No, I wasn't.  This all feels a bit pointless now...

A long time ago, I needed an up-to-date Windows toolchain so I could use my AVR Dragon JTAG unit, and this project started from there.  Finally made the current version because I was so sick of having to disable driver signature enforcement (to use my programmer via libusb-win32) and having it reenabled with each Windows update breaking everything.

why avr-gcc 7.2?

That... was the current version when I started the project.  It took a while to actually get things working, especially with all the fiddling around with Insight and Tcl trying to get that to work.

32bit executables would work on both 32bit and 64bit windows.

Honestly I kind of forgot that 32-bit windows was still in use.  At the moment all of my toolchains and dependency libraries are all 64-bit, so it would be an immense amount of work to produce 32-bit builds.

What are your ongoing plans?

I'm not really sure.  If I get a chance, I'll try to make an updated build soon.  Because of all the cajoling it took to get each and every program built, my build process was extremely manual.  The only parts I have scripted are building all the arduino cores (linked above) and making the zip file out of the installation prefix folder.

I'd like to have a 'light' alternative to arduino ide, and by light let's say it is not the Atmel Studio way.

That was 100% what I was going for with this project!  It gives you everything you need to write Arduino programs in just one 24MB package (plus optionally installing CMake). 

hummm, some guidance about how to set this up would be a good thing too.

I do talk about that, in Appendix B of the main post.  While you can use the AVR Makefile tool if you want, the CMake toolchain file I provided is the best and most efficient way to use this toolchain.  It gives you a lightweight way to manage your project that is still powerful and works on every platform.

Go Up