crycode-de / mcp-can-boot

CAN bus bootloader for AVR microcontrollers attached to an MCP2515 CAN controller.
Other
33 stars 12 forks source link

optimizations to reduce bootloader size #8

Closed hankedan000 closed 1 year ago

hankedan000 commented 1 year ago

@crycode-de I was able to reduce the size of the bootloader with these commits. It saved ~600bytes of flash memory, which isn't too much, but I thought it was worth checking out. From my usage/testing, I haven't noticed any issue with these changes (so far).

Usage Before (main branch built for ATmega328P)

RAM:   [=         ]   9.4% (used 192 bytes from 2048 bytes)
Flash: [=         ]  11.5% (used 3698 bytes from 32256 bytes)

Usage After (size-optimization branch built for ATmega328P)

RAM:   [=         ]   8.2% (used 168 bytes from 2048 bytes)
Flash: [=         ]   9.6% (used 3084 bytes from 32256 bytes)

In the title of each commit message, I included how many bytes each change saved. Let me know what you think. Maybe you'll only want to take a few of the commits.

crycode-de commented 1 year ago

Really good job!

One thing left in my opinion: Can you also move the fixed usage of TXB0 into the sendMessage method so it's similar to the readMessage implementation?

crycode-de commented 1 year ago

Thank you again!

Using the default config, we (you!) were able save 724 to 770 bytes depending on the used MCU. 🎉

MCU Size before Size after Diff
ATmega32 3640 2916 724
ATmega328P 3698 2974 724
ATmega64 3698 2974 724
ATmega644P 3700 2976 724
ATmega128 3778 3020 758
ATmega1284P 3816 3058 758
ATmega2560 3954 3184 770

That's perfekt!

This saving makes it possible to finally include the (optional) bitrate detection support into the main branch without needing 4k words bootloader section.