Memory footprint optimization
When developing an application, ROM and RAM footprint are important factors, especially when the firmware runs on the most resource-constrained devices like nRF52810 or nRF52811.
General recommendations
To reduce the memory footprint, ensure that your application uses the minimum required resources and tune the nRF Connect SDK configuration parameters. Complete the following actions to optimize your application:
Follow the guides for optimizing Zephyr. Also see the implementation of the Minimal footprint sample.
Analyze stack usage in each thread of your application by using the Thread analyzer. Reduce the stack sizes where possible.
Limit or disable debugging features, such as logging or asserts.
Go through each component and subsystem and turn off all peripherals and features that your application does not use.
The following subsections give more information on how to optimize specific subsystems.
Bluetooth
Besides applying General recommendations, you can also complete the following actions to optimize the Bluetooth® part of your application:
Disable features that your application does not use. For example, disable the following features:
Data Length Update
Extended Advertising
PHY Update
Security Manager Protocol (if no encryption and authentication is needed)
GATT Caching
GATT Service Changed
Reduce the stack sizes of the Bluetooth internal threads where possible. Use the Thread analyzer to analyze the stack usage.
The following configuration options affect the stack sizes of the Bluetooth threads:
Reduce the overall number and the sizes of the Bluetooth buffers, based on the expected data traffic in your application.
The following configuration options affect the Bluetooth buffers:
For reference, you can find minimal footprint configurations of the Bluetooth: Peripheral LBS sample in nrf/samples/bluetooth/peripheral_lbs/minimal.conf
and the Bluetooth: Peripheral UART sample in nrf/samples/bluetooth/peripheral_uart/minimal.conf
.
Gazell
To optimize the Gazell memory footprint, follow the General recommendations. Specifically, study the ISR stack size. If your application is in a pairing device, pay attention to the system workqueue stack size.
Do not enable features that your application does not use. The configuration options default to disabling optional features, such as:
Pairing
Pairing encryption
Pairing settings persistent storage
To reduce the logging level, set the CONFIG_GAZELL_LOG_LEVEL_CHOICE
Kconfig option.
Matter
Besides applying General recommendations, you can also complete the following actions to optimize the Matter part of your application:
Make sure Zephyr’s Shell is disabled for your application. Related configuration options are listed in a dedicated section in each Matter sample’s
prj.conf
file.Use
prj_release.conf
for building the application. The release configuration has a smaller memory footprint than the default, debug-enabledprj.conf
.If the logs in your application do not use the default log level, you can change the default log level of Zephyr modules from
info
towarning
by settingCONFIG_LOG_DEFAULT_LEVEL
to2
.Change the log level of the Matter logs from
debug
toinfo
by settingCONFIG_MATTER_LOG_LEVEL_INFO
toy
.Reduce the verbosity of assert messages by setting
CONFIG_ASSERT_VERBOSE
ton
.Check Thread memory footprint optimization actions, as the Matter application layer uses OpenThread.
NFC
The Near Field Communication (NFC) protocol implementation in the nRF Connect SDK provides some options for optimizing memory footprint for both the tag and the poller roles.
Tag
To optimize your application that supports the NFC tag functionality, follow the General recommendations. The NFC Type 2 Tag and Type 4 Tag libraries do not provide configuration options that have an effect on memory usage in an application. However, there are a few Kconfig configuration options you can use to optimize memory usage related to NFC.
CONFIG_NFC_PLATFORM_LOG_LEVEL_CHOICE
to reduce logging level in the NFC integration module.
For an application that uses the Type 4 Tag library, you can set the following options:
CONFIG_NDEF_FILE_SIZE
for the maximum NDEF file size, if the read-write mode is supported,CONFIG_NFC_TNEP_RX_MAX_RECORD_CNT
andCONFIG_NFC_TNEP_RX_MAX_RECORD_SIZE
for the maximum buffer size of NDEF message exchange, if the Tag NDEF Exchange Protocol (TNEP) is supported.
Poller
To optimize an application that supports the NFC poller functionality using the NFC Reader ST25R3911B library, you can set the following options:
CONFIG_ST25R3911B_LIB_LOG_LEVEL_CHOICE
and similar options to reduce the logging level of the NFC components used in the application.CONFIG_NFC_T4T_HL_PROCEDURE_CC_BUFFER_SIZE
andCONFIG_NFC_T4T_HL_PROCEDURE_APDU_BUF_SIZE
to adjust the buffer sizes in the NFC T4T protocol implementation of the poller side.
If the application supports the Tag NDEF Exchange Protocol (TNEP), you can set the following options:
CONFIG_NFC_TNEP_POLLER_RX_MAX_RECORD_CNT
for the maximum number of NDEF records in the received message.CONFIG_NFC_TNEP_CH_POLLER_RX_BUF_SIZE
for the Connection Handover receive buffer size of the poller mode, if the application uses the NFC TNEP Connection Handover library.
If the application uses the NFC TNEP protocol for the Bluetooth LE out-of-band pairing procedure (NFC TNEP Connection Handover), regardless of the role (tag or poller), you can set the following options:
Thread
The current Thread memory requirements are listed on the OpenThread memory requirements page.
Besides applying General recommendations, you can also complete the following actions to optimize the Thread part of your application:
Disable Thread features that your application does not use. For example, disable network shell and OpenThread CLI shell support (see Additional configuration options)
Reduce the stack sizes of the Thread internal threads where possible. Use the Thread analyzer to analyze the stack usage.
The following configuration options affect the stack sizes of the Thread threads:
Zigbee
The current Zigbee memory requirements are listed on the Zigbee memory requirements page.
Apply General recommendations to optimize the Zigbee part of your application.