high RAM consumption for a BLE app

Hi all!

I have created a simple application that only turns on a led and power it off using BLE in NRF52810. The thing is that simple app uses a huge RAM (~85%) and flash. There is a way to reduce the consumption of RAM? I have seen a post were configuring some parameters to reduce the consumption, I have tried it, but it led to some errors when using BLE.

Best regards

Parents
  • What do you mean by not having a Kconfig file? By default the peripheral_lbs sample project has a Kconfig file already looking like this:

     

    Is that not the case in your project, have you removed it? You will nee to edit the prj_minimal.conf to include what configurations you want it to use, like the PWM (and its dependencies, see the link in my last reply). With the PWM enabled and dependencies in your config file, you should be able to get past this error message.

    Best regards,

    Simon

Reply
  • What do you mean by not having a Kconfig file? By default the peripheral_lbs sample project has a Kconfig file already looking like this:

     

    Is that not the case in your project, have you removed it? You will nee to edit the prj_minimal.conf to include what configurations you want it to use, like the PWM (and its dependencies, see the link in my last reply). With the PWM enabled and dependencies in your config file, you should be able to get past this error message.

    Best regards,

    Simon

Children
  • Yes, that project has it, but I was talking about another project of mine that I don't have the kconfig.

    What I wanted to tell was that I have a project, like peripheral_lbs but with more functions and I have a working prj.config. If I want that to be minimal, only changing the name is enough? because after doing that the project does not compile anymore.

    Best regards

  • Hi

    clake said:
    If I want that to be minimal, only changing the name is enough

    Do you mean that you only change the name of prj.conf to prj_minimal.conf without making any changes to the config file at all? If so, that's not enough. If you look at the prj_minimal.conf (uploaded below) file that is used in the peripheral_lbs sample project, you can see that there are multiple configs set here in order to optimize the project to use as few resources as possible. If you have "more functions" you need to make sure the necessary configs are enabled, but then as many as possible should be disabled as in the minimal config file. The file's name does note really matter.

    # BEGIN Configurations from basic/minimal
    
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_LBS"
    
    # Enable the LBS service
    CONFIG_BT_LBS=y
    CONFIG_BT_LBS_POLL_BUTTON=y
    CONFIG_DK_LIBRARY=y
    
    # Drivers and peripherals
    CONFIG_I2C=n
    CONFIG_WATCHDOG=n
    CONFIG_GPIO=n
    CONFIG_PINMUX=n
    CONFIG_SPI=n
    CONFIG_SERIAL=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
    # END Configurations from basic/minimal
    
    # 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 816 usage 208 / 1024 (20 %)
    # BT RX               : unused 1784 usage 416 / 2200 (18 %)
    # BT TX               : unused 992 usage 544 / 1536 (35 %)
    # thread_analyzer     : unused 136 usage 376 / 512 (73 %)
    # sysworkq            : unused 1824 usage 224 / 2048 (10 %)
    # MPSL signal         : unused 520 usage 504 / 1024 (49 %)
    # idle 00             : unused 192 usage 64 / 256 (25 %)
    # main                : unused 136 usage 888 / 1024 (86 %)
    # Configurations set based on thread analyzer output.
    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=256
    CONFIG_MPSL_WORK_STACK_SIZE=640
    CONFIG_MAIN_STACK_SIZE=1024
    CONFIG_IDLE_STACK_SIZE=128
    CONFIG_ISR_STACK_SIZE=1024
    
    # 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
    

    Best regards,

    Simon

  • Hi Simon,

    yes, I'm actually using that minimal config for mi prj.conf also adding the PWM and so on, but if the name doesn't matter, why when I change prj.conf to prj_minimal.conf the build fails?

    using prj.conf I get

    [202/202] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      117472 B       192 KB     59.75%
                SRAM:       22932 B        24 KB     93.31%
            IDT_LIST:          0 GB         2 KB      0.00%

    After changing only the name to prj_minimal.conf I get:

    [51/163] Linking C static library zephyr/arch/common/libisr_tables.a
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /Documents/master/build

    With the error of no adding the PWM:

    modules/hal/nordic/nrfx/drivers/include/nrfx_pwm.h:62:35: error: 'NRFX_PWM0_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_PWM_INSTANCE'?
       62 |     .drv_inst_idx = NRFX_CONCAT_3(NRFX_PWM, id, _INST_IDX), \

    I also attach my prj.config that is the same as the prj_minimal.conf with other settings

    CONFIG_GPIO=y
    
    # PWM
    CONFIG_PWM_NRFX=y
    CONFIG_NRFX_PWM0=y
    
    # power off
    CONFIG_PM=y
    # Required to disable default behavior of deep sleep on timeout
    CONFIG_PM_DEVICE=y
    
    
    
    # BEGIN Configurations from basic/minimal
    
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_LBS"
    
    # Enable the LBS service
    CONFIG_BT_LBS=y
    CONFIG_BT_LBS_POLL_BUTTON=y
    CONFIG_DK_LIBRARY=y
    
    # Drivers and peripherals
    CONFIG_I2C=n
    CONFIG_WATCHDOG=n
    CONFIG_PINMUX=n
    CONFIG_SPI=n
    CONFIG_SERIAL=y
    
    # 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=y
    CONFIG_UART_CONSOLE=y
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_PRINTK=y
    CONFIG_EARLY_CONSOLE=y
    
    # Build
    CONFIG_SIZE_OPTIMIZATIONS=y
    
    # ARM
    CONFIG_ARM_MPU=y
    # END Configurations from basic/minimal
    
    # 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
    
    # Example output of thread analyzer
    # SDC RX              : unused 816 usage 208 / 1024 (20 %)
    # BT RX               : unused 1784 usage 416 / 2200 (18 %)
    # BT TX               : unused 992 usage 544 / 1536 (35 %)
    # thread_analyzer     : unused 136 usage 376 / 512 (73 %)
    # sysworkq            : unused 1824 usage 224 / 2048 (10 %)
    # MPSL signal         : unused 520 usage 504 / 1024 (49 %)
    # idle 00             : unused 192 usage 64 / 256 (25 %)
    # main                : unused 136 usage 888 / 1024 (86 %)
    # Configurations set based on thread analyzer output.
    # 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=256
    # CONFIG_MPSL_WORK_STACK_SIZE=640
    # CONFIG_MAIN_STACK_SIZE=1024
    # CONFIG_IDLE_STACK_SIZE=128
    # CONFIG_ISR_STACK_SIZE=1024
    
    # 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

    So as far I can see, when I want to build with prj.conf I get 202 setps, with the prj_minimal.conf I get 163 and the file is exactly the same. That is why I asked if only changing the name the NCS does something below to get a minimal config only with the name of the file.

    Best regards

Related