Hi dear forum members,
I’m working on a firmware project for the NRF52840 that utilizes BLE, DFU, I2C, WDT, some cryptographic libraries, and a few sensor libraries. However, despite having 1MB of flash memory, I’m hitting the limits of this configuration, because my flash is separated for DFU.
Flash organization (very simplified, in fact I have less memory in slot1 and 2)
Coming from a bare-metal development background, where 1MB is considered a substantial amount of memory, this feels quite unusual to me.
My own code occupies less than 8% of the total build, meaning over 92% of the memory footprint comes from Zephyr/NCS.
In my honest opinion, that’s pretty astonishing.
Look, NCS 2.6.2 is taking 135Kb of flash, whouah !
Is there a way to reduce this ?
My project conf file###############################################################################
# Project Config for running on nrf52840
###############################################################################
#
# ***IMPORTANT*** => disable these for PRODUCTION
CONFIG_SERIAL=n
CONFIG_LOG=n
CONFIG_BOOT_BANNER=n
#
# Firmware config
#
CONFIG_FIRMWARE_PRODUCTION=y
CONFIG_INSOLE_SIDE_RIGHT=y
CONFIG_TEMPERATURE_SENSORS_CONNECTED=y
CONFIG_I2C_POWER_PIN=y
CONFIG_ACCELEROMETER_CONNECTED=y
CONFIG_ACCELEROMETER_PEDOMETER_ENABLE=n
CONFIG_BATTERY_VOLTAGE_SENSING=y
CONFIG_REBOOT=y
CONFIG_HWINFO=y
#
# Watchdog
#
CONFIG_WATCHDOG=y
CONFIG_WDT_DISABLE_AT_BOOT=y
CONFIG_WATCHDOG_PERIOD=10000
#
# Uart/Serial Terminal
#
CONFIG_WANT_UART=y
CONFIG_WANT_UART_POWER_CTRL=n
CONFIG_LOG_COMMAND_IO=n
#
# BLUETOOTH Connection Monitoring
#
CONFIG_BLE_CONNECTION_MONITORING=y
CONFIG_BLE_CONNECTION_MONITORING_INTERVAL=250
CONFIG_BLE_CONNECTION_MONITORING_COMMAND_TIMEOUT=10000
CONFIG_BLE_CONNECTION_MONITORING_REBOOT_TIMEOUT=2000
CONFIG_BLE_CONNECTION_MONITORING_DFU_TIMEOUT=20000
#
# FOTA
#
CONFIG_PARTITION_MANAGER_ENABLED=y
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP=y
CONFIG_BT_CTLR_DATA_LENGTH_MAX=247
CONFIG_MCUMGR_TRANSPORT_BT_REASSEMBLY=y
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=2475
CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS=y
CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS=y
CONFIG_MCUMGR_GRP_IMG_UPLOAD_CHECK_HOOK=y
CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS=y
#
# Debugging Tasks
#
CONFIG_WANT_ALLPURPOSE_GPIO=n
#
# CONFIG CPP / LIBC
#
CONFIG_CPP=y
CONFIG_REQUIRES_FULL_LIBCPP=y # Because we use map and set, we must require FULL libc
#CONFIG_GLIBCXX_LIBCPP=y
#CONFIG_MINIMAL_LIBCPP=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_CBPRINTF_N_SPECIFIER=y
CONFIG_CBPRINTF_FULL_INTEGRAL=y
#
# STACK
#
CONFIG_MAIN_STACK_SIZE=3584
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=5120
#CONFIG_THREAD_ANALYZER=y
#CONFIG_THREAD_ANALYZER_AUTO_STACK_SIZE=2048
#CONFIG_THREAD_ANALYZER_AUTO=y
#CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=30
#CONFIG_THREAD_ANALYZER_USE_LOG=y
#
# Power Management
#
CONFIG_POWEROFF=y
CONFIG_PM_DEVICE=y
# https://devzone.nordicsemi.com/f/nordic-q-a/103764/getting-low-power-consumption-with-external-sensors
CONFIG_PM_DEVICE_RUNTIME=y
#
# DEBUGGING
#
CONFIG_DEBUG_OPTIMIZATIONS=n #CONFIG_DEBUG_OPTIMIZATIONS=y leads to crash the thread creation in qemu_x86
CONFIG_DEBUG_THREAD_INFO=n
CONFIG_EXCEPTION_STACK_TRACE=n
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_COREDUMP=n
#
# CONSOLE (enable the Terminal)
#
CONFIG_UART_USE_RUNTIME_CONFIGURE=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETLINE=y
CONFIG_CONSOLE_INPUT_MAX_LINE_LEN=100
#
# LOGGING
#
#CONFIG_LOG=n
#CONFIG_LOG_OVERRIDE_LEVEL=3
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_MODE_DEFERRED=y
#CONFIG_LOG_RUNTIME_FILTERING=n
CONFIG_LOG_BUFFER_SIZE=2048
CONFIG_LOG_PRINTK=y
#CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=0
#CONFIG_COVERAGE=n
#CONFIG_LOG_TAG_MAX_LEN=8
##### RTT SEGGER LOG ####
#CONFIG_LOG_MODE_IMMEDIATE=n
CONFIG_LOG_BACKEND_RTT=n
#CONFIG_USE_SEGGER_RTT=y
#CONFIG_RTT_CONSOLE=y
#CONFIG_LOG_BACKEND_UART=n
#CONFIG_UART_CONSOLE=n
#CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE=32
##### UART LOG ####
CONFIG_LOG_BACKEND_UART=y
#
# BLUETOOTH
#
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=16
#768 = Thermometer
CONFIG_BT_DEVICE_APPEARANCE=768
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1
CONFIG_BT_NUS=y
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_BUF_ACL_TX_COUNT=3
CONFIG_BT_BUF_ACL_TX_SIZE=247
#this one control the MTU for sending (yes, it's strange, RX ?!)
CONFIG_BT_BUF_ACL_RX_SIZE=247
#tx power stuff
CONFIG_BT_CTLR_TX_PWR_0=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y
#
# I2C
#
CONFIG_I2C=y
CONFIG_I2C_LOG_LEVEL_OFF=y
CONFIG_I2C_DUMP_MESSAGES=n
#
# ADC
#
CONFIG_ADC=y
#
# LittleFS / Flash
#
CONFIG_LITTLEFS_USE_FLASH=y
CONFIG_LITTLEFS_WIPE_AT_BOOT=n
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_FILE_SYSTEM_MAX_FILE_NAME=16
#CONFIG_FS_LITTLEFS_NUM_DIRS=1
#
# Assert
#
CONFIG_ASSERT=y
#
# CRC
#
CONFIG_CRC=y
#
# BASE64
#
CONFIG_BASE64=y
#
# Crypto
#
CONFIG_CRYPTO=y
CONFIG_CRYPTO_MBEDTLS_SHIM=y
CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y
CONFIG_CRYPTO_LOG_LEVEL_OFF=y
#
# RAM power down
#
CONFIG_RAM_POWER_DOWN_LIBRARY=y
Thank you very much.
Vincent