platform-atmelavr
platform-atmelavr copied to clipboard
Incorrect maximun size of Arduino Nano ATMega328 (new bootloader)
The new bootloader Optiboot is a quarter of the size of the default bootloader, freeing 1.5k of extra space. [(https://code.google.com/archive/p/optiboot/)]
Therefore the maximun ROM size available for program code is 32 256 bytes instead of 30 720 bytes that is set in nanoatmega328new.json.
With this change we could maximize the use of ROM memory of ATmega328P.
Unfortunately, there was a mistake when the production units switched over to optiboot, and the fuse bytes indicate it should be a 2K bootloader still :-/
This is why the Arduino core still references it like this : https://github.com/arduino/ArduinoCore-avr/blob/58081c05e548560d3a60050bbf260ebec5d1e867/boards.txt#L145
See this issue for more detail. https://github.com/arduino/ArduinoCore-avr/issues/10
So for now, you would not only need know that your board has optiboot, so you can access all 32256 bytes of flash, but would also need to ensure that the high fuse is set to 0xDE.
Then you can override this is in your platformio.ini via build_upload.maximum_size = 32256
or create a custom board definition. As well as setting board_bootloader.hfuse = 0xDE
if you need to set the fuses.