nrf52820 SRAM size reduction

Hi All!

    I am using Vscode studio, NCS SDK 2.0.2, and a peripheral Uart example. I need some guidelines regarding SRAM size reduction for nrf52820. Without adding my own code into this example SRAM size is  

SRAM:       32417 B        32 KB     98.93%

my prj_minimal.conf file is 

#
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Enable the UART driver
CONFIG_UART_ASYNC_API=y
CONFIG_NRFX_UARTE0=y
CONFIG_SERIAL=y

CONFIG_HEAP_MEM_POOL_SIZE=2048

CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1

# Enable the NUS service
CONFIG_BT_NUS=y

# Enable bonding
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

# Enable DK LED and Buttons library
CONFIG_DK_LIBRARY=y

# Drivers and peripherals
CONFIG_I2C=n
CONFIG_WATCHDOG=n
CONFIG_PINMUX=n
CONFIG_SPI=n
CONFIG_GPIO=n

# Power management
CONFIG_PM=n

# Interrupts
CONFIG_DYNAMIC_INTERRUPTS=n
CONFIG_IRQ_OFFLOAD=n

# Memory protection
CONFIG_THREAD_STACK_INFO=n
CONFIG_THREAD_CUSTOM_DATA=n
CONFIG_FPU=n

# Boot
CONFIG_BOOT_BANNER=n
CONFIG_BOOT_DELAY=0

# Console
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_STDOUT_CONSOLE=n
CONFIG_PRINTK=n
CONFIG_EARLY_CONSOLE=n

# Build
CONFIG_SIZE_OPTIMIZATIONS=y

# ARM
CONFIG_ARM_MPU=n

# In order to correctly tune the stack sizes for the threads the following
# Configurations can enabled to print the current use:
#CONFIG_THREAD_NAME=y
#CONFIG_THREAD_ANALYZER=y
#CONFIG_THREAD_ANALYZER_AUTO=y
#CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
#CONFIG_THREAD_ANALYZER_USE_PRINTK=y
#CONFIG_CONSOLE=y
#CONFIG_UART_CONSOLE=y
#CONFIG_SERIAL=y
#CONFIG_PRINTK=y

# Example output of thread analyzer
#SDC RX              : unused 800 usage 224 / 1024 (21 %)
#BT ECC              : unused 216 usage 888 / 1104 (80 %)
#BT RX               : unused 1736 usage 464 / 2200 (21 %)
#BT TX               : unused 1008 usage 528 / 1536 (34 %)
#ble_write_thread_id : unused 688 usage 336 / 1024 (32 %)
#sysworkq            : unused 1912 usage 136 / 2048 (6 %)
#MPSL signal         : unused 928 usage 96 / 1024 (9 %)
#idle 00             : unused 224 usage 96 / 320 (30 %)
#main                : unused 568 usage 456 / 1024 (44 %)
CONFIG_BT_CTLR_SDC_RX_STACK_SIZE=324
CONFIG_BT_RX_STACK_SIZE=1024
CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
CONFIG_BT_HCI_TX_STACK_SIZE=640
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
CONFIG_MPSL_WORK_STACK_SIZE=256
CONFIG_MAIN_STACK_SIZE=640
CONFIG_IDLE_STACK_SIZE=128
CONFIG_ISR_STACK_SIZE=1024
CONFIG_BT_NUS_THREAD_STACK_SIZE=512

# Disable features not needed
CONFIG_TIMESLICING=n
CONFIG_MINIMAL_LIBC_MALLOC=n
CONFIG_LOG=n
CONFIG_ASSERT=n

# Disable Bluetooth features not needed
CONFIG_BT_DEBUG_NONE=y
CONFIG_BT_ASSERT=n
CONFIG_BT_DATA_LEN_UPDATE=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_GATT_CACHING=n
CONFIG_BT_GATT_SERVICE_CHANGED=n
CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=n
CONFIG_BT_SETTINGS_CCC_LAZY_LOADING=y
CONFIG_BT_HCI_VS_EXT=n

# Disable Bluetooth controller features not needed
CONFIG_BT_CTLR_PRIVACY=n
CONFIG_BT_CTLR_PHY_2M=n

# Reduce Bluetooth buffers
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1
CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=43
CONFIG_BT_BUF_EVT_RX_COUNT=2

CONFIG_BT_CONN_TX_MAX=2
CONFIG_BT_L2CAP_TX_BUF_COUNT=2
CONFIG_BT_CTLR_RX_BUFFERS=1
CONFIG_BT_BUF_ACL_TX_COUNT=3
CONFIG_BT_BUF_ACL_TX_SIZE=27

my prj.conf file is 

#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_I2C=y
# Enable the UART driver
CONFIG_UART_ASYNC_API=y
CONFIG_NRFX_UARTE0=y
CONFIG_SERIAL=y

CONFIG_GPIO=y

# Make sure printk is printing to the UART console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_HEAP_MEM_POOL_SIZE=2048

CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1

# Enable the NUS service
CONFIG_BT_NUS=y

# Enable bonding
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

# Enable DK LED and Buttons library
CONFIG_DK_LIBRARY=y

# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Config logger
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n

CONFIG_ASSERT=y

# i added these 3 lines from child image of coded phy uart pheripheral
CONFIG_BT_EXT_ADV=y
CONFIG_BT_CTLR_ADV_EXT=y
CONFIG_BT_CTLR_PHY_CODED=y

#CONFIG_BT_USER_PHY_UPDATE=y

When I disabled the # Config logger part then code size was reduced to 3732 B . I need to reduce it at least 10 - 15kb  

Thanks in advance!

Best Regards,

Parents
  • Hi,

    I have not looked at the details of all your configurations, but the numbers seems to match a debug build. When I build the unmodified Bluetooth peripheral UART sample from SDK 2.0.2 with prj.conf I get this memory usage with debug optimizations enabled:

    Memory region         Used Size  Region Size  %age Used
               FLASH:      257156 B       256 KB     98.10%
                SRAM:       31728 B        32 KB     96.83%
            IDT_LIST:          0 GB         2 KB      0.00%

    With minimal confiiguration (prj_minimal.conf) with debug I get this memory usage:

    Memory region         Used Size  Region Size  %age Used
               FLASH:      157276 B       256 KB     60.00%
                SRAM:       21052 B        32 KB     64.25%
            IDT_LIST:          0 GB         2 KB      0.00%

    And with minimal configuration and without debug I get this memory usage:

    Memory region         Used Size  Region Size  %age Used
               FLASH:      138124 B       256 KB     52.69%
                SRAM:       20618 B        32 KB     62.92%
            IDT_LIST:          0 GB         2 KB      0.00%

    So the first thing is to make sure you don't enable debug options. Also, in case it is not clear, you should not use prj.conf and prj_minimal.conf. If you want a minimal build, use just prj_minimal.conf.

Reply
  • Hi,

    I have not looked at the details of all your configurations, but the numbers seems to match a debug build. When I build the unmodified Bluetooth peripheral UART sample from SDK 2.0.2 with prj.conf I get this memory usage with debug optimizations enabled:

    Memory region         Used Size  Region Size  %age Used
               FLASH:      257156 B       256 KB     98.10%
                SRAM:       31728 B        32 KB     96.83%
            IDT_LIST:          0 GB         2 KB      0.00%

    With minimal confiiguration (prj_minimal.conf) with debug I get this memory usage:

    Memory region         Used Size  Region Size  %age Used
               FLASH:      157276 B       256 KB     60.00%
                SRAM:       21052 B        32 KB     64.25%
            IDT_LIST:          0 GB         2 KB      0.00%

    And with minimal configuration and without debug I get this memory usage:

    Memory region         Used Size  Region Size  %age Used
               FLASH:      138124 B       256 KB     52.69%
                SRAM:       20618 B        32 KB     62.92%
            IDT_LIST:          0 GB         2 KB      0.00%

    So the first thing is to make sure you don't enable debug options. Also, in case it is not clear, you should not use prj.conf and prj_minimal.conf. If you want a minimal build, use just prj_minimal.conf.

Children
Related