Extra script for setting fuses and burning bootloader
See original GitHub issueHi!
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
orpio extra_script --fuses
pio extra_script -b
orpio extra_script --bootloader
pio extra_script -f -b
orpio 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:
- Created 4 years ago
- Comments:102 (97 by maintainers)
Top GitHub Comments
Thanks for the amazing work!
2.0.0 is out! https://github.com/platformio/platform-atmelavr/releases/tag/v2.0.0
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.