trouble uploading code

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
pateco
 
Posts: 9
Joined: Mon Oct 11, 2021 11:19 pm

trouble uploading code

Post by pateco »

Hi,

I have a few M4 CAN boards and they all give me intermittent issues uploading. I notice this happens if the sketch has some bug in it that causes it to not run properly, maybe a segmentation fault or some memory issue. I don't have a debugger attached.

This is the output I get after uploading a buggy sketch:

Code: Select all

Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, /dev/ttyS4, } / {/dev/ttyACM0, /dev/ttyS4, } => {}
PORTS {/dev/ttyACM0, /dev/ttyS4, } / {/dev/ttyACM0, /dev/ttyS4, } => {}
...
PORTS {/dev/ttyACM0, /dev/ttyS4, } / {/dev/ttyACM0, /dev/ttyS4, } => {}
Uploading using selected port: /dev/ttyACM0
/home/pateco/.arduino15/packages/adafruit/tools/bossac/1.8.0-48-gb176eee/bossac -i -d --port=ttyACM0 -U -i --offset=0x4000 -w -v /tmp/arduino_build_162252/sketch_sep20a.ino.bin -R 
It just sits there for a couple of minutes and then fails

The only way I can fix it is by holding down the reset button on the board while pressing upload in arduino and then releasing the reset button. I'm not 100% of the right timing so it often takes a few tries. Uploads after this fix work fine until the next time I add a bug to the code.

Is there anything I can do to make uploading fool proof?

User avatar
adafruit_support_carter
 
Posts: 29158
Joined: Tue Nov 29, 2016 2:45 pm

Re: trouble uploading code

Post by adafruit_support_carter »

That general issue can happen and the only real fix is what you are already doing. If the sketch running prevents the board from being able to software reset (for whatever reason), then manually resetting and uploading must be done. If the same problematic sketch is re-uploaded, then the issue will simply reoccur.

If there were an actual hardware issue, then the behavior would be repeatable with a basic Blink sketch.

User avatar
pateco
 
Posts: 9
Joined: Mon Oct 11, 2021 11:19 pm

Re: trouble uploading code

Post by pateco »

okay it's too bad the bootloader can't be more robust. I guess if I wanted fool proof uploads I would need to use a j-link? Expensive though.

On a related note, when I try to run the upload command manually it doesn't work. It's the exact same command listed in the verbose output of the arduino editor.

Code: Select all

/home/pateco/.arduino15/packages/adafruit/tools/bossac/1.8.0-48-gb176eee/bossac -i -d --port=ttyACM1 -U -i --offset=0x4000 -w -v /tmp/arduino_build_71552/HelloWorld.pde.bin -R 
Set binary mode
Send auto-baud
Set binary mode
No device found on ttyACM1
I also tried using /dev/ttyACM1 as the port since that's what it actually is but same output.

How would I upload firwmare using the commandline instead of the editor?

User avatar
adafruit_support_carter
 
Posts: 29158
Joined: Tue Nov 29, 2016 2:45 pm

Re: trouble uploading code

Post by adafruit_support_carter »

It's not really a bootloader issue. It's the firmware misbehaving and preventing the bootloader from running at all. The board gets "stuck" due to the malformed firmware.

Code: Select all

No device found on ttyACM1
Verify which port the board is on.

User avatar
pateco
 
Posts: 9
Joined: Mon Oct 11, 2021 11:19 pm

Re: trouble uploading code

Post by pateco »

Okay, I could get the bossac command to upload correctly after I first ran

Code: Select all

stty --file /dev/ttyACM0 1200
The number at the end of ACM changes between 0, 1, and 2 but as long as it matches what is currently available in the /dev/ directory it seems to work.

I'm not 100% sure what this does, but after running it a drive named "FTHRCANBOOT" is mounted and the built in LED turns red then stays green. Apparently stty is used to "change and print terminal line settings", but that's not a helpful description to me. https://man7.org/linux/man-pages/man1/stty.1.html

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”