Sloeber / arduino-eclipse-plugin

A plugin to make programming the arduino in eclipse easy
https://eclipse.baeyens.it/
420 stars 132 forks source link

After port reset the bossac upload fails because the device is not ready #124

Closed armband closed 10 years ago

armband commented 10 years ago

I have spent some time investigating the root cause of a problem that I raised on the DigiX forum a week or so ago. https://digistump.com/board/index.php?topic=1297.0

OS: Ubuntu Linux, Target: DigiX

Description: When I use the eclipse plugin to upload an image to the DigiX board, the result is generally a message stating "No device found on /dev/ttyACM0". I have dug into the plugin code and discovered two things. The first I have tracked by the previous issue I raised (the plugin is not honouring the Digix digix.upload.use_1200bps_touch=true board setting)

After making a code change to fix the first problem I discovered that the DigiX board also needs a couple of seconds of delay after the reset before the upload can be begin; I have confirmed this behaviour on Linux, but not tested it on Windows. Anyway, here is the section of code that I have altered in ArduinoSerial.java to make the whole thing work. Note, I have added a 2s delay after the reset.

Thanks.

if (boardName.equalsIgnoreCase("Arduino leonardo") || boardName.equalsIgnoreCase("Arduino Micro")
    || boardName.equalsIgnoreCase("Arduino Esplora") || boardName.startsWith("Arduino Due") || boardName.startsWith("Digistump DigiX") || use_1200bps_touch.equalsIgnoreCase("true")) {
    Vector<String> OriginalPorts = Serial.list();
    // OriginalPorts.remove(ComPort);
    if (!reset_Arduino_by_baud_rate(ComPort, 1200, 100) || boardName.startsWith("Arduino Due") || boardName.startsWith("Digistump DigiX")) {
        // Give the DUE/DigiX Atmel SAM-BA bootloader time to switch-in after the reset
        try {           
            Thread.sleep(2000);
        }
        catch (InterruptedException ex) {
        }
        return ComPort;
    }
    if (boardName.equalsIgnoreCase("Arduino leonardo") || boardName.equalsIgnoreCase("Arduino Micro")
        || boardName.equalsIgnoreCase("Arduino Esplora") || bwait_for_upload_port) {
        return wait_for_com_Port_to_appear(OriginalPorts, ComPort);
    }
}
jantje commented 10 years ago

I don't have a DigiX board so I can not comment mutch on this. I think the hard coded names are bad. However there is also use_1200bps_touch.equalsIgnoreCase("true") as a or condition so that should work without adding the name. I'd prefer that fixed to adding a name. The additional 2 seconds delay is another thing which will be needed to be added. Can you check why use_1200bps_touch.equalsIgnoreCase("true") is not working?

jantje commented 10 years ago

oeps Started at the top of my mail so didn't see the other issue. I'll fix the other issue and only include the 2 seconds part. after the nightly build you should be able to give it a test run.

jantje commented 10 years ago

Can you try whether this is fixed in the build 2014-02-03_02-07-24? You can download the product here http://eclipse.baeyens.it/download.php or use the nightly update site baeyens.it/eclipse/nightly Thanks

armband commented 10 years ago

Thank you for the quick turnaround. I will test the fixes and post the result. I aim to do this today or tomorrow.

On Feb 3, 2014, at 9:48 AM, jantje notifications@github.com wrote:

Can you try whether this is fixed in the build 2014-02-03_02-07-24? You can download the product here http://eclipse.baeyens.it/download.php or use the nightly update site baeyens.it/eclipse/nightly Thanks

— Reply to this email directly or view it on GitHub.

armband commented 10 years ago

Hi jantje, the update works well on Linux/Ubuntu 32-bit with Arduino IDE 1.5.5r2 using the DigiX board. Thank you again for the fixes. It did occur to me that it may be better to use the "build.mcu=" to identify the board type, rather than the name. i.e. if "build.mcu=cortex-m3", then wait for 2 seconds (caveat being I have not tried that code change myself). Using the mcu would future-proof your code a little more, and accommodate new ARM cortex board types that may be added in the future. Cheers! Graham

jantje commented 10 years ago

I don't like the hardcoded names myself. I proposed along time ago to the arduino team to open the way uploads are done like they did with the compilation. I even implemented that way in the plugin but boards.txt and arduino are not under my control. Using "build.mcu=" may be a good idea but I'm not expert enough to make that link so I prefer not to.

armband commented 10 years ago

I see your point. I have checked the aduino/avr/ arduino/sam and digix/sam boards.txt. Both the DUE & Digix sections specify properties upload.protocol=sam-ba, and upload.tool=bossac ... those would be a pretty safe bets to replace the DUE and Digix board name check ... anyway all is good for the time being, I appreciate your plugin, it is a fine piece of work and very useful. Thanks & Cheers!