-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] Marlin ARM binary size reduction (with proposed solution) #19427
Comments
Marlin is already very good at sorting unused code out. But sometimes you can squeeze a little more kB if you remove some (unused) object files from the linker statement. You may also gain some bytes if you advise the linker to remove debugging information .. put this to the linker script
Few bytes could be also gained by removing arguments to function calls and using global variables instead. But this may make the code more unreadable and more difficult to maintain. I found out that giving CFLAGS CXXFLAGS LDFLAGS IMPORTANT
I was using gcc version 9.3.1 and building for BigTreeTech SKR v1.4 Turbo with LPC1769. |
Thanks for adding that... To be more specific regarding newlib vs newlib-nano, using my custom but otherwise identical Marlin configuration resulting in 261316 - 199072 = 62244 bytes size reduction. |
It's not really a Marlin issue but a libmapple (which is used for HAL STM32F1) |
@jmz52 unless I'm looking at the wrong thing, it's the same difference, it seems STM32 uses newlib nano by default |
We are beginning to transition STM32F1 boards over to the STM32 HAL. We are very near feature parity between the two, and two MKS Robin boards have environments in available for both HALs. It likely won't be worth investing effort into improving the Maple-based STM32F1 builds, since our intent is to discontinue use of that framework, since it is deprecated by PlatformIO. |
Hi, |
We just updated to use a new Maple version which reduces FLASH usage by ~30kB, similar to this recommendation. At this point we don't want to invest additional effort into more Maple improvements. We need to focus on migrating our STM32F1 boards into HAL/STM32, so that the Maple dependency can be eliminated entirely. For this reason I'm going to close this out, even if there might be some potential for further improvements. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
The size of an ARM compiled binary tends to be fairly large, especially for a full featured Marlin build.
Marlin 2.0.6.1 for an SKR Mini E3 builds to roughly 261K (with additional features enabled) which in itself doesn't fit into the official 256K of supported flash the STM32F103RC has, let alone the 28K of bootloader at the start, and 4K of EEPROM emulation at the end.
While there's 512K mode for the STM32F103RC chip, which mitigates this a little bit, it essentially means we're using an area of the flash that the vendor does not warrant to be properly functional, even if it seems so. In practical terms, even if there's problems in that second 256K block of flash, as long as the last 4K are fine, and the first few tens of K are fine, most people won't have issues with Marlin. Still it's not a particularly great solution.
So initially I was looking for compiler flags to reduce the binary size, but quickly found out that there were few gains to be made, however at the bottom of this article, there was a little gem however:
https://thborges.github.io/blog/marlin/2019/01/07/reducing-marlin-binary-size.html
Proposed Solution
I've tested this specifically for my SKR Mini E3 V1.2, like so:
This reduces the resulting binary by several tens of K, where a featureful Marlin build can easily fit in 256K of flash with bootloader and EEPROM emulation accounted for.
And it seems to work just fine, since I've completed a few prints already. Though further broader testing is still needed.
Additional Info
Though looking a bit further it may not actually be that surprising why it works as seemingly flawlessly as it does, given that newlib-nano is a blend of two libraries that Marlin actually uses separately, specifically newlib and avr-libc:
https://keithp.com/newlib-nano/
I would love to hear your thoughts on newlib-nano, and more specifically consider it as the new (future) standard libc for ARM boards, as it may benefit boards other than the SKR mini E3 as well. And if all goes well (fingers crossed), possibly might not even have few if any tangible disadvantages.
The text was updated successfully, but these errors were encountered: