ATMEGA32U4 (Adafruit feather) programming

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
TSMroz
Posts: 15
Joined: Wed Apr 19, 2017 2:54 pm
Been thanked: 2 times
Contact:

ATMEGA32U4 (Adafruit feather) programming

Post by TSMroz »

Hi, I'm trying to use this target in a project but getting errors trying to program a blink example:

Launching the programmer...
C:\Program Files (x86)\Flowcode\Common\Compilers\avr\batchfiles\avrc_usbtiny.bat AVRDUDE m32u4 atmega32u4 "C:\Users\thoma\DOWNLO~1\Flowcode1.hex" "Flowcode1.hex" 0 3 255 255 255

C:\Users\thoma\DOWNLO~1>"C:\PROGRA~2\Flowcode\Common\COMPIL~1\avr\BATCHF~1\..\bin\avrdude.exe" -p m32u4 -P usb -c usbtiny -U flash:w:"Flowcode1.hex"
avrdude.exe: Error: Could not find USBtiny device (0x1781/0xc9f)


I can upload the blink example to the target with no issues using the Arduino IDE (using COM9). In looking at the AVRDUDE output, I see it's using:

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -PCOM9 -b57600 -D -Uflash:w:C:\Users\thoma\AppData\Local\Temp\arduino_build_596634/file.ino.hex:i


What Location and Parameters fields do I need to change in Flowcode 8 in order to be able to program similarly in Flowcode using usb? I'm pretty new to avrdude usage, so not really sure what config changes are needed.


Thanks,
Tom

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ATMEGA32U4 (Adafruit feather) programming

Post by Benj »

Hi Tom,

It might be worth trying Avrdudess to get the right settings. It's basically a GUI for AVRdude to allow you to try various settings. Once you have a setup that works then let us know and we will create a new Flowcode definition for the device.

Or you can tweak the FCDX definition file yourself using a text editor. You can find the definition file here.

C:\ProgramData\MatrixTSL\FlowcodeV8\FCD\ARD

Paste the path into your file explorer address bar as the ProgramData folder is hidden by default.

Remember to restart Flowcode after making any changes to the file, and maybe make a backup so you can go back if you need to.


Just looked at your post again and it looks like you're using the standard AVR device rather than an Arduino target, maybe try the various Arduino targets that use the same chip and this should default the programmer to AVRdude. Different Arduino devices have different settings so maybe try various devices and one may simply work as is.

TSMroz
Posts: 15
Joined: Wed Apr 19, 2017 2:54 pm
Been thanked: 2 times
Contact:

Re: ATMEGA32U4 (Adafruit feather) programming

Post by TSMroz »

Thanks Ben. I didn't have the Arduino license, so I just purchased it. Unfortunately, I still can't upload a test program to the 32U4 feather. this is the board I'm working with: https://www.adafruit.com/product/2771

I did try changing the target to an Arduino micro 8 since that looked close hardware wise. The error I get now is:

Launching the programmer...
C:\Program Files (x86)\Flowcode\Common\Compilers\avr\batchfiles\avrc_arduinoA.bat atmega32u4 avr109 com7 57600 "C:\Users\thoma\DOWNLO~1\test.hex"

C:\Users\thoma\DOWNLO~1>"C:\PROGRA~2\Flowcode\Common\COMPIL~1\avr\BATCHF~1\..\bin\avrdude.exe" -p atmega32u4 -P com7 -b 57600 -c avr109 -D -U flash:w:"test.hex"
avrdude.exe: ser_open(): can't open device "\\.\com7": The system cannot find the file specified.


I do notice that the com port changes between the loaded test program (COM2) and in bootloader mode (COM7), which changes to this immediately after pressing the board's reset. I'm not sure if it's expecting a different type of bootloader since it's not actually the Arduino micro 8.

I'll keep trying a few more things in the meantime. This should work with only a USB cable connected directly to the board, correct? Or is flowcode expecting to see a dedicated programmer attached to the chip's SPI pins?

TSMroz
Posts: 15
Joined: Wed Apr 19, 2017 2:54 pm
Been thanked: 2 times
Contact:

Re: ATMEGA32U4 (Adafruit feather) programming

Post by TSMroz »

Ok, so fiddling around with things more...

Downloaded AVRdudess.. got the config options to match what I see in the Arduino IDE for when AVRdude actually executes.. Received the same error as my last post above ("\\.\com7"). I notice that devman shows com2 as the connected target. So I press board reset to get into bootload mode, where the port changes over to COM7. If timed correctly, I can then use Avrdudess to program the 32U4 using the Flowcode hex file..

So on a hunch, I tried to do the same from within Flowcode - When I click 'Compile to chip, there is a message to "Connect your Arduino".. If I wait roughly 20seconds for this message to timeout, I can manually reset the board, and if timed correctly, the feather will then take the program from within Flowcode no problem.

I notice that the Arduino IDE seems to take care of all this by first sending a soft reset via COM2 just before launching Avrdude. This forces the port change from COM2 to COM7 (IE from running code to bootloader):

"Global variables use 149 bytes of dynamic memory.
Forcing reset using 1200bps open/close on port COM2"

Perhaps if I can figure out what usb commands they're sending, we could add the same to flowcode? Unless there's some much easier solution.. I've tried force manipulating the ports from within Windows to be the same, but it didn't work.

EDIT: I forgot to add that I also had to change the "Project Options - Programmer Port:" to COM7, but this also required very tricky timing as I had to press board reset, open the project options, change to COM7 and save before the bootload mode timed out and went back to running the code.. You only get a few seconds to do all this.

EDIT EDIT: Apparently, you simply open and then close a serial connection at 1200bps to the COM port that is running user code to perform a soft reset and get the chip into bootloader mode. You then have about 8 seconds to initiate programming under the port that shows up during bootload. I was able to simulate this using teraterm and verified that the ports changed..

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ATMEGA32U4 (Adafruit feather) programming

Post by Benj »

Hello,

Wow sounds like you're really making some good progress there. I've spoken to the Flowcode engine programmer regardng this and it sounds doable. Though whether or not we can squeeze this in for you so Flowcode will allow you to do this automatically is up in the air at the moment. It sounds easy enough but is also potentially a can of worms to do it well.

We do have a further update of Flowcode 8 to release so we will consider it for this release.

TSMroz
Posts: 15
Joined: Wed Apr 19, 2017 2:54 pm
Been thanked: 2 times
Contact:

Re: ATMEGA32U4 (Adafruit feather) programming

Post by TSMroz »

If I were voting for a change from what I know so far, I would change the "Project options" section so that I can manually select a com port that I know for certain is associated with the device's bootload mode. As of now, that com port doesn't show up since it only detects the serial device running the user code. This is why I had to do the tricky timing thing.

I wouldn't focus too much on the soft reset stuff initially and here's why. That only works if you can connect to the device's com port running the user code, which is fine if you had just uploaded a hex file from the Arduino environment. I noticed that after flashing a hex file from Flowcode, you then lose the com port associated with the running code. So Arduino IDE must be loading some additional USB related code into the chip along with the user's code in the hex file? Not sure. Only after flashing from Arduino IDE, does the other com port return..

At anyrate, using the board's reset button would still allow a user to get into bootloader and we could still use Flowcode to upload a hex file from the IDE. Assuming the current 20 second message window was changed as well. Simply changing the timeout delay message to polling for the bootload mode's com port would probably be sufficient.

Post Reply