Fuses with Arduino Leonardo ATmega32U4 - Write protect for production

Hope you can help me in bringing my Arduino setup into little "production".

I am using these small Beetle boards that are Arduino Leonardo based (ATmega32U4) and currently I have developed just a Arduino sketch that I upload directly over the board USB interface.

So I currently have not burned any fuses, any bootloader or any full bare metal software and I want evaluate my possibilitys for producing multiple write protected devices.

As far as I see the "normal" way would be to go bare metal and using an additional programming adapter. This device has to be connected with multiple pins on the current production board. Then I could burn a new bootloader or manipulate fuses (, I guess).
However for me the big disadvantage is that I have to connect (maybe solder) the device with the foreseen pins for every board. It would be much more comfortable if I could use the already established USB connection of the board itself.

So the question is:

  1. Can I burn fuse bits from my Arduino embedded software itself? Let's say by building a serial command that enables or disables programming? I read from third party boodloaders that are made for OTA updates but maybe it is much simpler and I can somehow manipulate fuses from the application code.
  2. Is it possible to burn fuses from the normal Arduino tooling and over the build in USB interface, without using an additional bare metal programming adapter?
  3. If not, I guess I can programm one of my Leonardos to act as a programmer and then directly connect it with the production boards?

What I have is:
Fuse calc
Good video of burining a custom bootloader from IDE
I also have a USB to Serial adapter that I use for flashing Sonoff Wifi Power Plugs. It has connectors like GND, VCC (5V or 3.3V), RX, TX,DTR, CTS. Maybe I can use this device but I am not sure how to connect it to my production board? Maybe just connect 3.3V, GND and cross TX and RX? do I need to connect DTR and CTS?
Currently I have nothing Leonardo specific or my board specific.

Any help or ressources are appreciated.

Thank you very much.

Q1 and Q2
AFAIK, It isn't possible to change the fuse bit without an external programming tool.
This is the same whether it is a bootloader or a user application.

Q3
It is possible.

Other question

It is possible to use the serial adapter as an external programming tool, but the Arduino IDE doesn't support it, so you'll need to use another tool.
EDIT:
However, this is only when the serial adapter supports bit banging, such as FTDI.
Also, if there is no problem even if the writing is very very slow, any serial adapter with RTS and DTR probably can be used as a programming tool...

1 Like

Thank you for reply.

This is my serial programmer.

It seems to support FTDI and uses the chip FT232RL. And the programmer can be jumpered to 3.3V or 5V.

So now the next challange is how to connect the programmer pins with the production board.

Here are the pins:
Programmer: DTR, RXD, TXD, VCC, CTS, GND
Production Board: 3V3, GND, SCL, SDA, RX, TX, D11, D10, D9, A0, A1, A2, 5V, GND, RES, SCK, MO, MI

I am thinking of giving it a try with the following connection at 5V:
GND -> GND
VCC -> 5V
RXD -> TX
TXD -> RX

I would test the connection with the program AVRDUDESS.
It has two programmer configurations that seem to be promissing:
"alias for arduino-ft232r" and
"Arduino: FT232R connected to ISP"

For programming the Sonoff I also just needed those 4 pins and as far as I know Sonoff devices also use Arduino compatible atmega chips?!

What do you think?

Good chip! :wink:
Use avrdude -c ft232r option.

And connection is...

FT232RL : Your board
    VCC : 5V
    GND : GND
    TXD : SCK
    RXD : MI
    RTS : MO
    DTR : RES

This is use ICSP protocol, not serial programming, and no bootloader required.
In other words, you can also set the fuse bit and lock bit.

ATTENTION!
The fuse bit can be changed.
Be careful of board brick.
Please just test the read from signature bytes first.

@fpdragon
hey! I'm so sorry to you! :astonished:
I misread the circuit diagram with different version of Leonardo.
The pin map is mistaked, so please use the modified that one!

FT232RL : Your board
    VCC : 5V
    GND : GND
    TXD : SCK
    RXD : MI
    RTS : MO
    DTR : RES
1 Like

Thank you very much!

I will give it a try later and let you know if it works.

Another question:

Is CTS and RTS the same?

Hmmm... I get an error message:

avrdude.exe: error: no pthread support. Please compile again with pthread installed. See http://sourceware.org/pthreads-win32/.

Ok, I guess I made progress, somehow.

I found an old Arduino Uno R3 and loaded the sketch:
File -> Examples -> ArduinoISP -> ArduinoISP

Then I connected the Arduino Uno Programmer with my production board:
GND -> GND
5V -> 5V
10 (Reset) -> RES
11 (MOSI) -> MO
12 (MISO) -> MI
13 (SCK) -> SCK

Then I started AVRDUDESS 2.13 (avrdude 6.3).
Selected Programmer: Arduino
COM Port ...
Pressed MCU "Detect"
And the tool detected the ID 1E950F as a ATmega328P which seems to be wrong for my target board.
I am totally sure that I have only ATmega32U4 boards in use.
I tested the same with two other boards but the same result.

I tried to read the fuse bits and it returned always 0x00 for all.
Then I dumped the EEPROM and I am pretty sure that I know that most of the EEPROM memory should be cleared to 0x00. But the dumped file has random data...

Then I forced the avrdude with -F to treat the target as ATmega32U4. Same results.

Then I noticed that the Arduino Uno, that shall act as programming adapter, has a ATmega328P. So it seems that the tool tries to read from the programmer's controller instead of the real target.

And here I am currently stuck. I don't know why but the Arduino Uno seems to currently not act as a programmer. That's at least how it looks like for me.

Any ideas?

Thank you.

I got it working with the Arduino Uno as a programmer.

I had to enable the USE_OLD_STYLE_WIRING precompile switch in the programmer sketch.
Then I had to set te boud rate to 19200.
And third, I had to fix a contact problem for some pins.

Now the AVRDUDESS detects the correct MCU and is also able to dump the EEPROM data.

I guess I am now ready to program the device permanently by disabling
SPIEN
Enable Serial programming and Data Downloading

Or I try an alternative bootloader with additional update features.

Thank you for the help!

I'm glad that the uC program was finally possible.
You used Uno, I see.

I'll Answer some you questions.

No, not the same.
This is an image from the product link you provided.


But you can use CTS instead of RTS, but you need to modify avrdude.conf.

This is not a FTDI programmer error, and the programming application hasn't been able to run before that.

This 328P is running as a programming tool and it not try to read itself.

But, well... finally solved. :blush:

1 Like

I know your question is answered but in case you want to go for production, you need to make a programming jig with pogo pins that line up with the spi pins of your blank board. Google programming jigs. How do you think the beatle board got its bootloader flashed to it? :wink:

I have an old post on jigs:

https://liudr.wordpress.com/2015/04/23/making-your-programming-jig/

I think I finally will go with the Arduino Uno programming solution.

The FT232R was a promising solution but it seems to much pain to get rid of all the problems.
First, it seems that I would need to build the avrdude on my own to include licensed pthread libraries. These are used with the FTDI FT232R chip.
Second, it's not said that it will work afterwards since I read that there are problems with FTDI Sync bitbang and Win10 and I don't want to setup an old notebook for just this purpose.
Third, there are some badly rated youtube vids that are claiming to explain how to fix the FTDI drivers on a Win10 machine. No good sign in my opinion.

But I am fine and happy with the Arduino Uno solution I currently have. I build a pinhead adapter cable that fits exactly on my production boards without soldering. So I can program the devices before the production boards are placed into the housings.

Thank you again for the good help!

1 Like

Yeah, everything's clear. :+1:

avrdude has serial port bitbanging without SyncFTDI, called "dasa" option.
This is very slow but may work...
But if you have Uno now, you probably don't need that.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.