I have been able to read on many occasions that the arduino's flash memory space has 650 bytes of memory reserved for the Bootloader.
In my case, I am using an arduino Leonardo (32u4) and I don't use the integrated USB port. I dump the flash by ISP using the USBasp programmer. In this way I get the arduino program to run immediately when connecting it to the current, this is essential for my project.
I have the job finished and the code as optimized as possible, and it reaches 99% of the flash memory and it works perfectly.
Now I need to make a small expansion in my program to add a new functionality and I am missing a few bytes.
To the question of someone who said in other posts "do you really need 650bytes?", My answer would be "Yes, please ..."
I know that in theory it can be done, could I add that space reserved for the bootloader to use it for my program?
How could I do it?
When I compile from the arduino IDE, the IDE does not know how I am going to dump it, if by USB or by ISP and compiles it in the same way, leaving space for the bootloader and it says there is not enough memory.
Can't help you with your question but have one comment.
A powerup on a Leonardo should not cause a delay in startup; it will straight jump to your code. A reset (either by pressing the reset button or by resetting via serial) will give you the delay.
Yes, it is true that I had already verified that with the bootloader loaded in the flash, the reboots were also fast, but since I have designed the circuit without USB, I can take advantage of freeing up some space by not loading that part of the bootloader code.
In theory I should have more space, but since the compiler does not distinguish if you are going to use the bootloader or not, by default it calculates the most unfavorable percentage of flash needed and that is why it does not let me compile or export the .hex
Any other idea?
Any configuration that can be done with the arduino IDE?
Maybe with another compilation program I can do it?
I have been able to read on many occasions that the arduino's flash memory space has 650 bytes of memory reserved for the Bootloader.
Well, the Uno bootloader is less than 512 bytes. But the 32u4 leonardo bootloader has to do USB, so it's substantially bigger, at 4096 bytes.
All you should need to do is change the fuses so that you don't have a bootloader section defined, and change the board type so that it knows you have the extra space.; your bootloader is already empty because of the way you're programming it...
I don't know offhand of any setups that have that all pre-defined for you.
I think that you need to create a new board definition for a your board that defines the extended memory space.
The file should be boards.txt; I have not updated to a newer boards version, so I can find it in (windows system) C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt. Else it will probably be somewhere in C:\Users\yourUserName\AppData\Local\Arduino15.
Hope this helps a little; there are people that are more knowledgeable in this area (like @westfw above).
Thank you very much for this information westfw.
I am not used to using the fuses, so I have been reading the section and have been able to do several tests.
Having adjusted the fuses so that it does not save space for the bootloader, but still, when compiling it told me that it was spending 100% of the space.
Then I followed the recommendation of sterretje, which I also thank very much.
In the file "boards.txt" I made the modification in the memory space section, increasing it 4000bytes.
Great!! now the arduino IDE lets compile and I have plenty of space !!
In my case, the file I found in the path:
C:\Users\MyName\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
I put these parameter changes:
leonardo.upload.maximum_size=32672 (original was 28672)
leonardo.bootloader.high_fuses=0xd7 (original was 0xd8)
leonardo.bootloader.extended_fuses=0xcf (ogiginal was 0xcb)
my configuration is like this in "boards.txt" file:
westfw, Do you think the fuses are properly configured?
Besides freeing up the bootloader space, my intention is that when dumping, the eeprom data is not modified. I do not know if I have found the key, since I think they are also erased.
Having adjusted the fuses so that it does not save space for the bootloader, but still, when compiling it told me that it was spending 100% of the space.
Ah. I should have been clearer that you need BOTH the new fuses AND the boards.txt change.
The fuses control how the chip actually starts up, while the boards.txt change affects the IDE's "opinion" about how much space there is.
Your fuses look fine, though the extended fuse change seems to have changed the BOD behavior rather than boot behavior. I use AVR® Fuse Calculator – The Engbedded Blog
You have them set to preserve EEPROM, so I'm not sure why you're having problems there. (if your sketch has actual EEPROM variables, those could get uploaded each time, overwriting any previous contents. I'm not sure whether the IDE "upload using programmer" uploads EEPROM or not...
Also, in case it is not clear from this, simply putting the correct fuse settings in boards.txt is not alone sufficient. You have to explicitly change the fuses on the target mcu.
You can use avrdude for this. Even more confusingly, you can use the burn bootloader option in the Arduino ide, even though you don’t want a bootloader.