Author Topic: Fix for Linux micronucleus upload issue  (Read 3698 times)

psychogenic

  • Newbie
  • *
  • Posts: 4
Fix for Linux micronucleus upload issue
« on: February 19, 2013, 11:23:30 am »
Greetings all,

I was having a terrible time trying to get passed the
 
 
Quote
Abort mission! error has occured ...

error message, which always appeared at the 66% (during or after erase) when trying to upload under Linux.  It wasn't the USB connection, nor permissions, and was really frustrating.

So I finally found a dual-boot machine where Linux was having the same problem, but no issue under Windows.  I did notice this message, though:

Quote
  Eep! Connection to device lost during erase! Not to worry
 This happens on some computers - reconnecting...

Aha... short version is that it seems we need to re-interpret the Linux error code (-84), from

Quote
  usbfs: USBDEVFS_CONTROL failed cmd micronucleus rqt 192 rq 2 len 0 ret -84

 to something the micronucleus program can grok so it will automagically reconnect after the erase.

I've made the change and a pull request for the micronucleus mod (pull request here)
but in case in doesn't go through and/or for the impatient I'm including the diff file for the minor change, here.

I've successfully uploaded to the digispark using this modified micronucleus, and get messages like this now:

Quote
Binary sketch size: 756 bytes (of a 6,010 byte maximum)
Running Digispark Uploader...
Plug in device now...
> Please plug in the device ...
> Press CTRL+C to terminate the program.
> Device is found!
connecting: 40% complete
> Available space for user application: 6010 bytes
> Suggested sleep time between sending pages: 8ms
> Whole page count: 94
> Erase function sleep duration: 752ms
parsing: 60% complete
> Erasing the memory ...
erasing: 79% complete
>> Eep! Connection to device lost during erase! Not to worry
>> This happens on some computers - reconnecting...
erasing: 80% complete
> Starting to upload ...
writing: 100% complete
>> Micronucleus done. Thank you!

Regards,
PatD

lstep

  • Newbie
  • *
  • Posts: 2
Re: Fix for Linux micronucleus upload issue
« Reply #1 on: February 20, 2013, 07:31:38 am »

Your patch didn't solve my problem.


Code: [Select]
Plug in device now...
> Please plug in the device ...
> Press CTRL+C to terminate the program.
> Device is found!
connecting: 40% complete
> Available space for user application: 6010 bytes
> Suggested sleep time between sending pages: 8ms
> Whole page count: 94
> Erase function sleep duration: 752ms
parsing: 60% complete
> Erasing the memory ...
erasing: 79% complete
erasing: 80% complete
> Starting to upload ...
writing: 80% complete
>> Abort mission! An error has occured ...
>> Please unplug the device and restart the program.


As you can see, it didn't continue/restart. I successfully patched the micronucleus_lib.c file (I did it manually), did a "make clean" then make, and copied the generated micronucleus binary file to the arduino directory (arduino-1.0.3/hardware/tools/)

Where did you find the error message: "usbfs: USBDEVFS_CONTROL failed cmd micronucleus rqt 192 rq 2 len 0 ret -84" ?
I looked into my /var/log/syslog, but no usbfs message, in fact I did a grep in the /var/log directory, without anything (except the boot) related to usbfs :(


Thanks

psychogenic

  • Newbie
  • *
  • Posts: 4
Re: Fix for Linux micronucleus upload issue
« Reply #2 on: February 20, 2013, 12:45:04 pm »
Aloha lstep,

Yeah, your abort seems to be happening later down the line (during write, rather than during erase).  Though it may be the same disconnect issue, the patch I provided only handles the problem during the eraseFlash call so wouldn't be of assistance in this case.

Even if it is a similar problem, I'm not certain you could apply the same fix in micronucleus_writeFlash() as it may be different/more sensitive.

The first step is to isolate the issue, so I would suggest:
  • Upping udev logging, either by running
Code: [Select]
# udevadm control --log-priority=debug
    or by editing udev.conf and restarting udev.[/li]
       
  • Maybe you could crank up the information output by micronucleus itself, so we can actually see what the issue being reported is.
This patch should be a good start (untested):


Code: [Select]
diff --git a/commandline/examples/micronucleus.c b/commandline/examples/micronucleus.c
index e5fc355..085ecf7 100644
--- a/commandline/examples/micronucleus.c
+++ b/commandline/examples/micronucleus.c
@@ -245,7 +245,7 @@ int main(int argc, char **argv) {
   setProgressData("writing", 5);
   res = micronucleus_writeFlash(my_device, endAddress, dataBuffer, printProgress);
   if (res != 0) {
-    printf(">> Abort mission! An error has occured ...\n");
+    printf(">> Abort mission! An error has occured (%d)...\n", res);
     printf(">> Please unplug the device and restart the program.\n");
     return EXIT_FAILURE;
   }
diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c
index 462190b..f456898 100644
--- a/commandline/library/micronucleus_lib.c
+++ b/commandline/library/micronucleus_lib.c
@@ -142,7 +142,7 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz
     // give microcontroller enough time to write this page and come back online
     delay(deviceHandle->write_sleep);
     
-    if (res != 64) return -1;
+    if (res != 64) return res != 0 ? res : -1;
   }
   
   // call progress update callback with completion status


Lemme know if I can be of further assistance.
Cheers,
PatD