Skip to content

Uploading with multiple programmers attached does not work #2254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
CreativeRobotics opened this issue Oct 10, 2023 · 2 comments
Closed
3 tasks done

Uploading with multiple programmers attached does not work #2254

CreativeRobotics opened this issue Oct 10, 2023 · 2 comments
Assignees
Labels
conclusion: off topic Off topic for this repository type: imperfection Perceived defect in any part of project

Comments

@CreativeRobotics
Copy link

CreativeRobotics commented Oct 10, 2023

Describe the problem

I have a setup with two boards, each with an embedded debugger (Curiosity Nano dev boards with ATTiny 3227 MCU and the Mega Tiny Core)
Both are recognised as comm ports and I can work with two IDE windows using both serial interfaces.
If I try and upload with "Upload using programmer" it will always use the same programmer regardless of which IDE window I am using.

To reproduce

Connect two curiosity nano boards
Open two different sketches with Arduino
Upload using programmer from one instance
Upload from the second instance

Expected behavior

This ought to behave the same way that it does when using two boards simultaniously with two sketches with USB or serial bootloaders.
Arduino should be able to recognise if multiple programmers are attached as USB devices, just as it recognises multiple COMM ports.
Multiple debugger/programmers should be selectable for each Arduino IDE window, as happens with COMM ports.

Arduino IDE version

2.2.1

Operating system

Windows

Operating system version

10

Additional context

I am developing a board to board comm system so it helps to have both boards connected. The devices are too small for bootloaders so I have to use the programmers. If they had serial bootloaders then this setup would work properly because each window would be connected to a different serial port.

*Edited because I realised that the IDE is a single instance, even when using multiple sketches.

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@CreativeRobotics CreativeRobotics added the type: imperfection Perceived defect in any part of project label Oct 10, 2023
@per1234 per1234 self-assigned this Oct 11, 2023
@per1234
Copy link
Contributor

per1234 commented Oct 11, 2023

Hi @CreativeRobotics. If you enable Show verbose output during: compilation in the Arduino IDE "Preferences" dialog and then attempt an upload to your Curiosity Nano board, you will see that the avrdude command doesn't even use the serial port. For example:

"C:\Users\per\AppData\Local\Arduino15\packages\DxCore\tools\avrdude\6.3.0-arduino17or18/bin/avrdude" "-CC:\Users\per\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10/avrdude.conf" -v -V -pattiny817 -ccuriosity_updi -Pusb "-Ufuse0:w:0b00000000:m" "-Ufuse2:w:0x02:m" "-Ufuse5:w:0b11000101:m" "-Ufuse6:w:0x04:m" "-Ufuse7:w:0x00:m" "-Ufuse8:w:0x00:m" "-Uflash:w:C:\Users\per\AppData\Local\Temp\arduino\sketches\42A552BDC21CE9BF12E4B456461B61AE/27.ino.hex:i"

This is because nEDBG programmer that is used for the upload is a pure USB device, which is identified in the upload command only by using its VID/PID pair (03eb:2175) and AVRDUDE does not support identifying it using a serial port number (you will see the -P port flag is instead set to usb in the command. The problem is that every nEDBG has the same VID/PID pair, so this upload command doesn't give the AVRDUDE uploader tool any way to know which specific board to target when multiple devices exist on your system with that VID/PID pair.

There is sometimes a mechanism for uniquely identifying specific hardware instances. In the case of serial ports, this is a serial number. AVRDUDE supports the use of the serial number in the upload command via -Pusb:<serial number> flag:

https://avrdudes.github.io/avrdude/7.2/avrdude_3.html#Option-Descriptions:~:text=be%20specified%20as-,usb%5B%3Aserialno%5D,-.%20In%20that%20case

Modern versions of Arduino IDE do make the serial number associated with a selected serial port accessible for use in the upload command via the upload.port.properties.serialNumber property:

https://arduino.github.io/arduino-cli/latest/platform-specification/#pluggable-discovery

So in theory this change to the "megaTinyCore" platform could solve the problem of the avrdude command being ambiguous in regards to targeted board when multiple are connected to the computer:

diff --git a/megaavr/platform.txt b/megaavr/platform.txt
index bbf02bf7..c4de0e83 100644
--- a/megaavr/platform.txt
+++ b/megaavr/platform.txt
@@ -174,6 +174,15 @@ tools.avrdude.program.params.quiet=-q -q
 tools.avrdude.program.params.noverify=-V
 tools.avrdude.program.pattern={upload.prog_interlock}"{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Ufuse0:w:{bootloader.WDTCFG}:m" "-Ufuse2:w:{bootloader.OSCCFG}:m" "-Ufuse5:w:{bootloader.SYSCFG0}:m" "-Ufuse6:w:{bootloader.SYSCFG1}:m" "-Ufuse7:w:{bootloader.APPEND}:m" "-Ufuse8:w:{bootloader.BOOTEND}:m" "-Uflash:w:{build.path}/{build.project_name}.hex:i"
 
+## This tool targets the specific device instance with the serial number obtained via the selected serial port.
+tools.avrdude-with-sn.path={runtime.tools.avrdude.path}
+tools.avrdude-with-sn.cmd.path={path}/bin/avrdude
+tools.avrdude-with-sn.config.path={runtime.platform.path}/avrdude.conf
+tools.avrdude-with-sn.program.params.verbose=-v
+tools.avrdude-with-sn.program.params.quiet=-q -q
+tools.avrdude-with-sn.program.params.noverify=-V
+tools.avrdude-with-sn.program.pattern={upload.prog_interlock}"{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} -Pusb:{upload.port.properties.serialNumber} "-Ufuse0:w:{bootloader.WDTCFG}:m" "-Ufuse2:w:{bootloader.OSCCFG}:m" "-Ufuse5:w:{bootloader.SYSCFG0}:m" "-Ufuse6:w:{bootloader.SYSCFG1}:m" "-Ufuse7:w:{bootloader.APPEND}:m" "-Ufuse8:w:{bootloader.BOOTEND}:m" "-Uflash:w:{build.path}/{build.project_name}.hex:i"
+
 ## Used for "upload" through bootloader
 tools.avrdude.upload.params.verbose=-v
 tools.avrdude.upload.params.quiet=-q -q
diff --git a/megaavr/programmers.txt b/megaavr/programmers.txt
index cdc7aa20..ba497a59 100644
--- a/megaavr/programmers.txt
+++ b/megaavr/programmers.txt
@@ -59,7 +59,10 @@ nedbg.name=Curiosity Nano (nEDBG, debug chip: ATSAMD21E18)
 nedbg.communication=usb
 nedbg.protocol=curiosity_updi
 nedbg.program.protocol=curiosity_updi
+# This tool recipe will be used as a fallback by development tools that don't have pluggable discovery support.
 nedbg.program.tool=avrdude
+# This tool recipe will be used by development tools that do have pluggable discovery support.
+nedbg.program.tool.default=avrdude-with-sn
 nedbg.program.extra_params=-Pusb
 
 edbg.name=Xplained Pro (EDBG, debug chip: AT32UC3A4256)

I have used this successfully with other devices but I don't own an nEDBG device so I can't test it. I do own an ATtiny817 Xplained Mini, which has the mEDBG instead of the nEDBG. I tried applying the patch above to the "Xplained Mini (mEDBG, debug chip: ATmega32u4)" programmer of megaTinyCore. Unfortunately I find that the upload fails:

"C:\Users\per\AppData\Local\Arduino15\packages\DxCore\tools\avrdude\6.3.0-arduino17or18/bin/avrdude" "-CC:\Users\per\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10/avrdude.conf" -v -V -pattiny817 -cxplainedmini_updi -Pusb:ATML2658061800005922 "-Ufuse0:w:0b00000000:m" "-Ufuse2:w:0x02:m" "-Ufuse5:w:0b11000101:m" "-Ufuse6:w:0x04:m" "-Ufuse7:w:0x00:m" "-Ufuse8:w:0x00:m" "-Uflash:w:C:\Users\per\AppData\Local\Temp\arduino\sketches\F34C435C76C67097ECC296F9E74200AF/BareMinimum.ino.hex:i"

avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\per\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.10/avrdude.conf"

         Using Port                    : usb:ATML2658061800005922
         Using Programmer              : xplainedmini_updi
avrdude: usbhid_open(): invalid serial number "ATML2658061800005922"
avrdude: usbdev_open(): invalid serial number "ATML2658061800005922"
avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2145

It seems that the "ATML2658061800005922" serial number produced by the mEDBG is somehow not accepted by AVRDUDE, even though I have verified using operating system tools (lsusb -d 03eb:2145 -v) that is indeed the serial number produced by the USB device.

I don't know whether that same problem occurs with the nEDBG.

What I do know is that this has nothing to do with the Arduino IDE codebase hosted in this repository so I will close this as off topic. If you have any questions or would like to discuss the subject further, feel free to make a topic on Arduino Forum:

https://forum.arduino.cc/


Semi-related (but different since in this case we do have a discovered port that provides us with the serial number): arduino/arduino-cli#770

@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@per1234 per1234 added the conclusion: off topic Off topic for this repository label Oct 11, 2023
@CreativeRobotics
Copy link
Author

Thanks, I suspected this might be the case, but I thought it was worth posting an issue just in case there was a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: off topic Off topic for this repository type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants