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.
Features
• 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 (GNU Binutils)
○ avr-gcc 7.3.0 (https://gcc.gnu.org/)
○ avr-libc 2.0.0 (AVR Libc Home Page)
○ Arduino core libraries (GitHub - arduino/Arduino: Arduino IDE 1.x) (+ my custom builder)
• Upload:
○ AVRDUDE 6.3 (AVRDUDE - AVR Downloader/UploaDEr)
○ AVRDUDESS 2.4 (AVRDUDESS – A GUI for AVRDUDE | Zak’s Electronics Blog ~*)
○ 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 (Overview — Simulavr homepage)
• Libraries (dependencies of other things):
○ libftdi1 1.4 (libFTDI » FTDI USB driver with bitbang mode)
○ libusb 1.0.22 (http://libusb.info/)
○ libusb-compat 0.1.6 (GitHub - libusb/libusb-compat-0.1: Working tree for libusb-compat-0.1)
Download
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:
- Plug it in to a USB port.
- Open zadig-2.2.exe from the LoseAVR root folder
- Change the pull-down menu to your programmer. You may have to check Options>Show All Devices for it to show up.
- 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.
- Hit the install button.
- 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:
cmake_minimum_required(VERSION 3.1)
# set AVR build properties
set(AVR_UPLOAD_TOOL avrdude)
set(AVR_PROGRAMMER arduino)
set(AVR_UPLOAD_PORT COM3)
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)
include_directories(${CMAKE_FIND_ROOT_PATH}/arduino_cores/mega/atmega2560/include)
add_definitions(-DARDUINO=106)
# 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:
mingw32-make
Finally, run make to upload your code:
mingw32-make upload_foo
It's fast, easy, and runs natively to Windows!