ATMEL USB Programmer on Linux

I am an newbie at your tool. I am a Linux experts with the rules. I can use the programmer at userspace.

This work nice at my computer.

red@linux-qc1d:~> avrdude -c avrispmkII -p atmega32u4 
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)
avrdude done.  Thank you.
red@linux-qc1d:~> 

Now I want to use the same programmer inside PlatformIO.

[env:micro]
platform = atmelavr
board = leonardo
framework = arduino
lib_deps = 
	Arduino
	HID-Project
upload_flags = 
    -c
	avrispmkII
    -p
    atmega32u4
    -P
upload_command = avrdude -c avrispmkII -p atmega32u4 -U flash:w:$SOURCE:i

I got the message:

.debug_str                   881         0
Total                      11763
<lambda>(["upload"], [".pio/build/micro/firmware.hex"])
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
BeforeUpload(["upload"], [".pio/build/micro/firmware.hex"])

Warning! Please install `99-platformio-udev.rules`. 
More details: https://docs.platformio.org/page/faq.html#platformio-udev-rules

Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1
====================================================

I have no upload port at my configuration.
The USB programmer avrispmkII is detect at avrdude I does not set any port?

Maybe this helps: Atmel AVR — PlatformIO latest documentation

Also, your parameters:

upload_flags =
-c
avrispmkII
-p
atmega32u4
-P

Need to be indented with either a tab, or spaces. I use 4 spaces:

upload_flags =
    -c
    avrispmkII
    -p
    atmega32u4
    -P

Normally, when using my USBtiny programmer, I follow the settings given on the above link. I din’t need to use the options above in your example, then I use the program target rather tgan upload:

pio run --target program

That usually works fine.

Cheers,
Norm.

Thank s for your hint.
I see some more, but I have not success.

I see a missing config file with ubuntu in the path. I using opensuse. I do not understand why avrdude use a config file. I have never used a config-file. This is stupid command line tool.

avrdude -c avrispmkII -p atmega32u4 -U flash:w:.pio/build/micro/firmware.hex:i
avrdude: can’t open config file “/home/jenkins/workspace/avrdude/label/Ubuntu12.04x64/objdir/etc/avrdude.conf”: No such file or directory
avrdude: error reading system wide configuration file “/home/jenkins/workspace/avrdude/label/Ubuntu12.04x64/objdir/etc/avrdude.conf”
*** [program] Error 1

I get a similar error all the time in the Arduino IDE, but it still works. I have never used a config file either. I suspect however, that my system (Linux Mint) does have a global config file for avrdude – how does it know which boards use which communications etc?

I’m confused though, you are using OpenSuse, but the error relates to Ubuntu 12.04. Interesting. A quick Google shows that Jenkins runs in a container, that’s probably where the Ubuntu comes in.

My theory is that the Jenkins environment probably needs the avrdude global config file installing. Apparently, the Arduino version of avrdude is built on a Jenkins server and that hard codes the global config file into the avrdude executable.

On your linux box, try this command:

locate avrdude.conf | grep -i avrdude.conf$

That will find your various avrdude.conf files. You probably have at least one, somewhere in /etc I would think.

Tha Arduino IDE always passes the global config file during an upload, you need to do likewise. The option is -C /path/to/avrdude.conf with an upper case ‘C’. It seems that avrdude always needs a config file passing.

If you have the Arduino IDE, you will have a suitable one. Try an upload with the verbose option in settings enabled, then copy the filename and path for use in PlatformIO.

Alternatively, remove the upload_command from platformio.ini as the Arduino framework and toolchain used by PlatformIO, will know where to find its own config file.

Cheers,
Norm.

Hallo Norman,

I found different *.conf files.

/etc/avrdude.conf
/home/red/.platformio/packages/tool-avrdude/avrdude.conf
/home/red/.platformio/packages/framework-arduino-avr/bootloaders/gemma/avrdude.conf
/home/red/arduino/arduino-1.8.13-linux64/arduino-1.8.13/hardware/tools/avr/etc/avrdude.conf
/home/red/arduino/arduino-1.8 (1).13-linux64/arduino-1.8.13/hardware/tools/avr/etc/avrdude.conf
/home/red/arduino/arduino-1.8.13-linux64/arduino-1.8.13/hardware/arduino/avr/bootloaders/gemma/avrdude.conf
/home/red/arduino/arduino-1.8 (1).13-linux64/arduino-1.8.13/hardware/arduino/avr/bootloaders/gemma/avrdude.conf

My aim is :slight_smile:
That exists at the IDE a upload function in the status bar.
I want to click with the mouse the button and after the microcontroller is programmed.
How It is called “program” or “upload” this … . I need a working change to command behind the button in the IDE or I need a new button with my own command.

Good Evening Rene,

I suspect that they are all the same.

In your platformio.ini add:

   -C
   /etc/avrdude.conf

to your upload_flags. Then remove the upload_command as you already have the settings in the upload_flags, something like:

[env:micro]
platform = atmelavr
board = leonardo
framework = arduino
lib_deps = 
	Arduino
	HID-Project
upload_flags = 
    -c
	avrispmkII
    -p
    atmega32u4
    -P
    -C
    /etc/avrdude.conf

Now, when you click on the upload button, ->, in the VSCode editor’s PlatformIO toolbar, it should run a “pio run --target program” and upload via the USB device.

If not, open a new VSCode terminal, and type the command pio run --target program. If you have the terminal open in the directory where platformio.ini lives, it will program the board.

If that worked, then the VSCode is doing a pio run --target upload instead. I think adding:

upload_protocol = stk500v2

And an extra flag:

upload_flags =
    -Pusb 

to platformio.ini will force it to change target from upload to program, which is what youbwant.

Cheers,
Norm.

Hallo Norman,

your suggestion does not work.
What I have found.

The upload_flags added to the existing options.
I have changed the platformio.ini to

[env:micro]

platform = atmelavr
board = leonardo
framework = arduino
lib_deps =
Arduino
HID-Project
upload_flags =
-c
avrispmkII
-p
atmega32u4
-P
-C
/etc/avrdude.conf

I see the new option but there is an addtional option -C and overwride my declared config file.
([“program”], [“.pio/build/micro/firmware.hex”])
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
avrdude -c avrispmkII -p atmega32u4 -P -C /etc/avrdude.conf -v -p atmega32u4 -C /home/red/.platformio/packages/tool-avrdude/avrdude.conf -c avr109 -U flash:w:.pio/build/micro/firmware.hex:i

avrdude: Version 6.3, compiled on Sep 12 2016 at 15:21:49
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

I see also -c avr109 this is the wrong programmer.
This is the issue. An option -c avr109 is add always.

I assume that these options are indented? They should be.

Also, looking at the docs, there should be a USB after -P.

Interesting! I see that second config file option, sadly I have no idea where it comes from. :frowning_face:

I see that too. Again, I don’t know where it’s coming from either.

However, give the -P option a USB parameter, as above, and see if that makes any difference.

If it still gets extra config files, and protocols, I’m afraid to say that “I’m stumped”. :frowning_face:

Cheers,
Norm.

[env:micro]
platform = atmelavr
board = leonardo
framework = arduino
lib_deps =
Arduino
HID-Project
upload_protocol = avrispmkII

This works now:
pio run --target program -v

But upload does not work.

In the status bar is only a upload button but no program button.
I have to found out what is the difference between upload and program?

Upload = upload firmware to board using board’s bootloader.

Program = board’s bootloader is ignored, ICSP device used to upload firmware. On an Uno, for example, programming overwrites the bootloader so upload cannot be subsequently used until a bootloader is burned into the board, with the ICSP.

When pasting code, do it like this:

```
Your code here
```

Those are backticks by the way, not single quotes. That will format the code exactly as you copied it, including all indentations. Thanks. :wink:

Possibly, you have deleted the bootloader at some point? Using the ICSP device?

Quickest way is to load up the Arduino IDE, then tools->Burn Bootloader. Then try another upload.

You can pio run --target bootloader but you’ll need additional “stuff” in platformio.ini.

Click the “alien” bug’s head on the far left, then find the option to program in the list of allowable tasks. (I’m away from my laptop at present, so I’m saying that off the top of my head.)

Cheers,
Norm.

Thank you Norman.

I understand moe,

The mayor problem of arduino is this:

Configuring upload protocol...
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
Looking for upload port...
Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Error: Couldn't find a board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload.
*** [upload] Explicit exit, status 1
========================================================================================= [FAILED] Took 6.18 seconds =========================================================================================
The terminal process "platformio 'run', '--target', 'upload'" terminated with exit code: 1.

Does this work on your system?
I use the udev rules from platformIO but I have everytime the reconnecting of the serial port. I have read much but I could not solve It.

I only have an Arduino - Duemilanove, Uno, Mega2560 and my own designed, NormDuino (8 MHz, no crystal as seen at http://qdosmsq.dunbar-it.co.uk/blog/2019/02/atmega328p-8mhz-on-a-breadboard. All of the above can be easily programmed with my usbTiny programmer.

I believe that the Leonardo has to disconnect the current port in order to upload? I don’t know if it needs to change the port speed or not, but I believe that there is be a timeout setting you can change so that it waits a bit longer to detect the port reconnecting. Does this link help, it’s to a workaround someone else found/created which might also work for you, perhaps?

One other thing, does your USB cable work as a data cable for other stuff? Some cables are two wire only - these are used for charging phones etc and are no good for uploading musinc to a music player, or, in this case, for uploading code to a Leonardo!

Cheers,
Norm.