Reduce source code size for Kinetis Series MKL03

cancel
Showing results for 
Search instead for 
Did you mean: 

Reduce source code size for Kinetis Series MKL03

323 Views
tomazlov
Contributor II

In our design we are using Kinetis MKL03Z8 with only 8KB of flash. We have been able to program needed application from peripheral examples on test board FRDM-KL03Z (LPUART and I2C + using VLLS modes) but firmware is to large to fit into 8KB. I also try barebone SDK (v2.3.1) minimalistic example ("demo_apps->hello_world")  inside MCUExpresso, but I could not get below 9KB PROGRAM_FLASH, even with optimization level for size (-Os). How can i further reduce program size (I assume examples have some ballast) or where I get driver/example files (e.g. MWE) with smallest footprint possible for LPUART, I2C master peripheral to fit into 8KB region space?

2 Replies

100 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Tomaz Lovrencic ,

Try to disable “printf()”, also don't include <stdio.h>, then the size of bare board project is almost 2k,

and you can also reduce the codes in drivers that don't use.

pastedImage_1.png

Hope it helps,


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

100 Views
tomazlov
Contributor II

Alice_Yang, thanks for the suggestion. If anyone will find this useful, I ended up with these modification steps (also including Alice_Yang suggestion), which greatly improves code size of the examples:

- use baremetal example and manually pasting only needed driver/other files,

- use Redlib(none) semihosting option,

- exclude <stdio.h> and printf() functions. For production stage use LPUART_WriteBlocking() for strings and LPUART_WriteByte() for bytes with LPUART_IRQHandler() for RX,

- remove preprocessor compiler directives: DEBUG, PRINTF_FLOAT_ENABLE, CR_INTEGER_PRINTF, PRINTF_ADVANCED_ENABLE. Instead use NDEBUG which supresses asserts and printfs throughout the whole project,

- set optimization level for size (-Os),

- debug level to None.

This way I managed to get down to 6KB including needed peripheral drivers and my code.

0 Kudos