question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extra script for setting fuses and burning bootloader

See original GitHub issue

Hi!

As a developer working with AVRs I feel like the last thing missing from PlatformIO now is the ability to set the correct fuse bits and burn the correct bootloader based on the information given in platformio.ini.

MightyCore, MiniCore, and MegaCore (all supported by PlatformIO) comes with a bunch of pre-compiled bootloaders where all shares the same file names rules.

As long as board, board_build.f_cpu, and board_upload.speed is present in platformio.ini Is it possible for a script to figure out the correct fuse bits and load the correct bootloader hex file.

Preferably there should be three flags, one to only set the fuse bits, one to only burn the bootloader and one for doing both. Since the name and path of the bootloader are so extensive, we can check if the user entered a valid board_build.f_cpu, and board_upload.speed by checking if a bootloader with these values exists.

A bootloader for a >=64kB device is named like this:

bootloaders/atmega1284p/16000000L/optiboot_flash_atmega1284p_UART0_1000000_16000000L_BIGBOOT.hex

A bootloader for a <=32kB device is named like this:

bootloaders/atmega328p/16000000L/optiboot_flash_atmega328p_UART0_115200_16000000L.hex

By adding a new parameter to platformio.ini (board_upload.uart_port maybe?) we can specify if UART0, UART1 or UARTn should be used for uploading. Again, this decides what bootloader hex file is loaded.

Another fuse related feature is the ability to set the brownout detection level. This is possible in Arduino IDE through a separate menu option. Something like board_fuses.bod = 2.7V?

The last option should be to manually set fuses and override everything. My idea here would be to check if board_fuses.high, board_fuses.low and board_fuses.extended is present. If one or more is present, then this fuse is overridden by whatever value the particular boards_fuses fields holds

I have very little experience with python, but I think this should be doable, even for me if someone points me in the right direction. I also haven’t worked with PlatformIO advanced scripting before, so forgive me if some of the following questions are silly to some.

  • Can a script like this be ran separately, and not when “regular” code is compiled and uploaded?
  • Is a command similar to these realistic?
    • pio extra_script -f or pio extra_script --fuses
    • pio extra_script -b or pio extra_script --bootloader
    • pio extra_script -f -b or pio extra_script --fuses --bootloader
  • Does there exist any examples I can look to learn how this may me implemented?

EDIT: It seems like boards_mightycore.txt boards_minicore.txt and boards_megacore.txt already exist in my .platformio folder. Maybe these files can be parsed to make this job a little easier?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:102 (97 by maintainers)

github_iconTop GitHub Comments

2reactions
ivankravetscommented, Nov 25, 2019
1reaction
MCUdudecommented, Sep 24, 2019

My recommendation is that we add 0x0F + -e to all targets that have a bootloader area.

We can make a list of all target that does not have a bootloader. It’s ATmega48/48P + all ATtinys except ATtiny828.These should have the lock fuse set to 0xff.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Extra script for setting fuses and burning bootloader -
Hi! As a developer working with AVRs I feel like the last thing missing from PlatformIO now is the ability to set the...
Read more >
How to Change Fuse Bits of AVR Atmega328p - Instructables
1. Hardware: A microcontroller that you are going to change the fuses. (may be any AVR Atmega-8bit microcontroller.) 1 x Breadboard. Few Breadboard jumpers. 1 ... 2....
Read more >
Programming Arduino Fuses and Bootloader on ... - YouTube
Quick video showing how to program the Arduino Fuses and Boot-loader on brand new ATmega328PB chips. This method works well for custom ...
Read more >
Extended Fuses Settings, 0x05=0xFF - Arduino Forum
Fuses can be chaged during the bootloading e.g. (Tools -> Burn Bootloader), or non lama user can do it via avrdude tool from...
Read more >
How to set fuses [file] - PlatformIO Community
Hello, When I run platformio.exe run --target fuses, ... to override default fuse with custom fuse settings use an extra script
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found