# Arduino cannot set lock\_bits and fuses from IDE

**URL:** <https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159>\
**Category:** Uploading\
**Created:** [September 21, 2022, 12:56pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159 "2022-09-21T12:56:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 21, 2022, 12:56pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/1 "2022-09-21T12:56:43Z")

</div>

I want to set the lock bit and fuses from inside the Arduino IDE, using an external programmer (Sparkfun's Pocket AVR Programmer).

For this example, let's focus only on the lockbit. I am using Arduino Pro Mini.  
Inside the `boards.txt` file, I have located the `Pro Mini` section and more specifically this line:

```cpp
pro.bootloader.lock_bits=0x0F

```

I have changed this to:

```cpp
pro.bootloader.lock_bits=0x00

```

What I did, is I changed the lock bit, so that the flash in unreadable.  
However, when I read the flash without the lock bit set and when I read it with the lock bit set, it is exactly the same. This means that the setting did not work.

Is there a way to make this work? I cannot understand why this does not work for me. Obviously, I select the `Upload Using External Programmer` option.

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 21, 2022, 1:17pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/2 "2022-09-21T13:17:41Z")

</div>

These are all the settings for this Arduino model:

```cpp
pro.name=Arduino Pro or Pro Mini

pro.upload.tool=avrdude
pro.upload.protocol=arduino

pro.bootloader.tool=avrdude
pro.bootloader.unlock_bits=0x3F
pro.bootloader.lock_bits=0x00

pro.build.board=AVR_PRO
pro.build.core=arduino
pro.build.variant=eightanaloginputs

```

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [September 21, 2022, 1:18pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/3 "2022-09-21T13:18:41Z")

</div>

and you changed `tools.avrdude.program.pattern` in platform.txt

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 21, 2022, 1:38pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/4 "2022-09-21T13:38:20Z")

</div>

Hello! Dejavu.  
These are the contents of the given parameter in `platform.txt`:

```cpp
tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" -e -Ulock:w:{bootloader.unlock_bits}:m -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m

```

Then this:

```cpp
tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" -e -Ulock:w:{bootloader.lock_bits}:m

```

And this...

```cpp
tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" -e -Ulock:w:{pro.bootloader.lock_bits}:m

```

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [September 21, 2022, 2:20pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/5 "2022-09-21T14:20:31Z")

</div>

what are the 3 versions?

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 21, 2022, 2:27pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/6 "2022-09-21T14:27:13Z")

</div>

Different things that i tried. Nothing worked. Tried every combination basically.

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [September 21, 2022, 4:14pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/7 "2022-09-21T16:14:56Z")

</div>

> [@nikolakos](#):
>
> I select the `Upload Using External Programmer` option.

I don't think the IDE will try to change the lock fuses when you upload. It sets the fuses when you burn a fresh bootloader.

I think that to lock the FLASH with your sketch installed you will need to learn how to use 'avrdude' outside the IDE.

I would start by turning on "verbose messages during upload" and burning a bootloader. That will show you the 'avrdude' commands used to upload the bootloader and set fuses. Start with the commands to set fuses and get them to work outside the IDE.

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [September 21, 2022, 4:43pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/8 "2022-09-21T16:43:42Z")

</div>

@johnwasser it is upload with programmer and the avrdude command executed by the IDE is modified to have the options for fuses.

the command is  
`avrdude -avrdude.conf -v -patmega328p -cusbtiny -Uflash:w:Blink.ino.hex:i -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m `

@nikolakos what prints avrdude when executing the command

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 11:16am UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/9 "2022-09-22T11:16:07Z")

</div>

What exactly does this command do?  
You want me to execute this and report the results?  
I am asking because the only thing i want to do, is modify the lock bit to 0x00.

Using this command for example:  
`avrdude -c usbtiny -p m328p -U lock:w:0x00:m`

in order to write the lock\_bit, I get:

```cpp

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "0x00"
avrdude: writing lock (1 bytes):

Writing | | 0% 0.00s ***failed;
Writing | ################################################## | 100% 0.04s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x00:

Reading | ################################################## | 100% 0.00s

avrdude: WARNING: ignoring mismatch in unused bits of "lock"
         (0xc0 != 0x00). To prevent this warning set unused bits
         to 1 when writing (double check with your datasheet first).
avrdude: 1 bytes of lock verified

avrdude done. Thank you.

```

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 11:44am UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/10 "2022-09-22T11:44:34Z")

</div>

I have tried every different combination in the `platforms.txt` file. What frustrates me the most is that it does not work, although it should be working!  
I don't know why nothing works. In any combination, I am still able to read the flash, which should not be possible, which means setting the lock bit failed.

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [September 22, 2022, 11:54am UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/11 "2022-09-22T11:54:03Z")

</div>

the command in my comment is one of the commands in your comment

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 11:58am UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/12 "2022-09-22T11:58:12Z")

</div>

I didn't try these values specifically.  
If you mean the first command, it is the first one i tried. Later, i removed all the fuses parts and kept the lock bits only.

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 12:01pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/13 "2022-09-22T12:01:58Z")

</div>

Let's look at the Arduino IDE output.  
When I use `tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" -Ulock:w:{pro.bootloader.unlock_bits}:m`

Then I get:

```cpp
avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Nikos Stolis\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port : usb
         Using Programmer : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
         AVR Part : ATmega328P
         Chip Erase delay : 9000 us
         PAGEL : PD7
         BS2 : PC2
         RESET disposition : dedicated
         RETRY pulse : SCK
         serial program mode : yes
         parallel program mode : yes
         Timeout : 200
         StabDelay : 100
         CmdexeDelay : 25
         SyncLoops : 32
         ByteDelay : 0
         PollIndex : 3
         PollValue : 0x53
         Memory Detail :

                                  Block Poll Page Polled
           Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
           flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
           lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
           hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
           efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
           lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
           calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
           signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

         Programmer Type : USBtiny
         Description : USBtiny simple USB programmer, https://learn.adafruit.com/usbtinyisp
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: Using SCK period of 10 usec
avrdude: reading input file "C:\Users\NIKOSS~1\AppData\Local\Temp\arduino_build_984948/Blink.ino.hex"
avrdude: writing flash (924 bytes):

Writing | ################################################## | 100% 1.05s

avrdude: 924 bytes of flash written
avrdude: verifying flash memory against C:\Users\NIKOSS~1\AppData\Local\Temp\arduino_build_984948/Blink.ino.hex:
avrdude: load data flash data from input file C:\Users\NIKOSS~1\AppData\Local\Temp\arduino_build_984948/Blink.ino.hex:
avrdude: input file C:\Users\NIKOSS~1\AppData\Local\Temp\arduino_build_984948/Blink.ino.hex contains 924 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.84s

avrdude: verifying ...
avrdude: 924 bytes of flash verified

avrdude done. Thank you.

```

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 12:04pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/14 "2022-09-22T12:04:05Z")

</div>

One thing that sticks out is this:

```cpp
avrdude: programmer operation not supported

```

Maybe some option in the System wide configuration file?

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [September 22, 2022, 1:25pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/15 "2022-09-22T13:25:05Z")

</div>

you have to restart the IDE to apply changes in platform.txt

copy here the executed command too

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 1:54pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/16 "2022-09-22T13:54:53Z")

</div>

I figured that out... I was restarting the IDE the whole time.  
I just realized that before the output, you get the command that is being used. I will try a new set of experiments and will post here.

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 2:10pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/17 "2022-09-22T14:10:00Z")

</div>

Ok. I reached a point - thanks to your help - where I realize that the generated command is not the correct.  
This is the command it generates:

```cpp
C:\Users\RandomUzer\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\RandomUzer\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cusbtiny -Uflash:w:C:\Users\RAND~1\AppData\Local\Temp\arduino_build_481636/Blink.ino.hex:i 

```

These are four different permutations of parameters that i used:

```cpp
tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" -Ulock:w:{bootloader.lock_bits}:m

tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" -Ulock:w:{pro.bootloader.lock_bits}:m

tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" "-Ulock:w:{bootloader.lock_bits}:m"

tools.avrdude.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} {program.verify} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i" "-Ulock:w:{pro.bootloader.lock_bits}:m"

```

Their differences are that I used both `bootloader.lock_bits` and `pro.bootloader.lock_bits`, as well as trying these with and without `" "` in the second parameter.  
Somehow, the last parameter is never injected in the actual command.

---

<div class="post-metadata">

**Author:** ![mrburnette](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mrburnette/32/702556_2.png) [@mrburnette](https://forum.arduino.cc/u/mrburnette)\
**Post date:** [September 22, 2022, 2:16pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/18 "2022-09-22T14:16:41Z")

</div>

> [@nikolakos](#):
>
> What frustrates me the most is that it does not work, although it should be working!

What is really frustrating **you** is you do not know what you are doing, so you are throwing garbage into the process trying to make sense out of nonsense.

Fuses can be set from the IDE, but **editing any of the .txt control files** is not smart. With just a little research and use of avrdude, you can do things correctly. Use an UNO configured as a programmer, or buy one, search for Arduino ICSP programmer.  
The UNO sketch is in the examples for the IDE, or use Nick Gammon's:  
[arduino\_sketches/Atmega\_Board\_Programmer.ino at master · nickgammon/arduino\_sketches · GitHub](https://github.com/nickgammon/arduino_sketches/blob/master/Atmega_Board_Programmer/Atmega_Board_Programmer.ino)

Command line script for Windows:  
[Copy 'n Paste Arduino Firmware - Community / Exhibition / Gallery - Arduino Forum](https://forum.arduino.cc/t/copy-n-paste-arduino-firmware/178469)

More:  
[Gammon Forum : Electronics : Microprocessors : Atmega bootloader programmer](https://www.gammon.com.au/bootloader)

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 2:25pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/19 "2022-09-22T14:25:50Z")

</div>

I know that I do not know what I am doing, this is why I am in a forum asking for help.  
I also don't know why you are being so aggressive and rude for asking a question... This is your issue.

I already know how to do this process with AVRDude. But thank you anyway.

---

<div class="post-metadata">

**Author:** ![nikolakos](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nikolakos](https://forum.arduino.cc/u/nikolakos)\
**Post date:** [September 22, 2022, 2:27pm UTC](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159/20 "2022-09-22T14:27:55Z")

</div>

@Juraj when I tried chaining commands together, adding more parameters to the AVRDude command, it worked.

```cpp
avrdude -c usbtiny -p m328p -U flash:w:MyProg.ino.hex -U lock:w:0x00:m

```

This works. It both uploads the code to the arduino and sets up the lock bit.  
I am not sure why the IDE fails to inject the second parameter to the actual command.

So still, no progress from the Arduino IDE...

[Next page](https://forum.arduino.cc/t/arduino-cannot-set-lock-bits-and-fuses-from-ide/1034159.md?page=2)
