Regarding flash overflow when dfu is enabled

I am working on a module MS12SF1(nrf7002+nrf5340). I am using wifi,ble,sdcard,uart and https functionalities in my code. Currently my flash usage is 72.44%. I also want to use dfu through ble. If I enable the configurations of dfu, the flash overflows by 270940 bytes.

I don't know what else I should optimise to solve this.

I am using nrf sdk v2.6.1

This is my prj.conf file

# Wi-Fi
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
CONFIG_WPA_SUPP=y

# Wi-Fi credentials
CONFIG_WIFI_CREDENTIALS=y
CONFIG_WIFI_CREDENTIALS_STATIC=y
CONFIG_WIFI_CREDENTIALS_STATIC_SSID="UltraHuman-4th Floor"
CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="Ultra@Human$!"

# Networking Management API
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_INFO=y
CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_WIFI_MGMT_EXT=y


# DK library
CONFIG_DK_LIBRARY=n

# System settings
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_POSIX_MAX_FDS=12

CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_TCP=y
CONFIG_NET_DHCPV4=y
CONFIG_DNS_RESOLVER=y

# Memory
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=153600

CONFIG_NET_TCP_WORKQ_STACK_SIZE=2048
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096
CONFIG_NET_BUF_RX_COUNT=20
CONFIG_NET_BUF_TX_COUNT=20

CONFIG_NET_BUF_DATA_SIZE=256
CONFIG_NET_TC_TX_COUNT=0

# # HTTP
# STEP 1 -  Enable the HTTP client library
CONFIG_HTTP_CLIENT=y

CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG_PRINTK=y

CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_CBPRINTF_FP_SUPPORT=y

# Enable the UART driver
CONFIG_UART_ASYNC_API=y                             #to enable the asynchronous API of the serial driver.
CONFIG_NRFX_UARTE0=y
CONFIG_SERIAL=y                                     #to enable serial support in code like uart

CONFIG_GPIO=y

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

CONFIG_SETTINGS=y                                   #Enables the settings subsystem
CONFIG_FLASH=y                                      #Enables the flash drivers
CONFIG_FLASH_PAGE_LAYOUT=y                          #API for retrieving the layout of pages
CONFIG_FLASH_MAP=y                                  #Enables the flash map abstraction module
CONFIG_NVS=y                                       #Enables support for non-volatile storage




CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n
# CONFIG_SOC_ENABLE_LFXO=n 

#for system uptime
# CONFIG_TIMESLICING=y

#for sd card
CONFIG_DISK_ACCESS=y

CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y

# CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_DEBUG=n

CONFIG_SIZE_OPTIMIZATIONS=y

# CONFIG_NET_BUF_TX_COUNT=40
# CONFIG_NET_BUF_RX_COUNT=40
# CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y
# CONFIG_NET_RX_STACK_SIZE=4096
# CONFIG_NET_TCP_WORKQ_STACK_SIZE=2048

# CONFIG_NET_PKT_TX_COUNT=20
# CONFIG_NET_PKT_RX_COUNT=20

# CONFIG_NET_BUF_POOL_USAGE=y

# CONFIG_WIFI_LOG_LEVEL_DBG=y
# # Memory statistics and debugging
# CONFIG_THREAD_ANALYZER=y
# CONFIG_THREAD_ANALYZER_AUTO=y
# CONFIG_STACK_SENTINEL=y
# CONFIG_INIT_STACKS=y
# CONFIG_ASSERT=y
# CONFIG_ASSERT_LEVEL=2
# CONFIG_UART_0_NRF_HW_ASYNC=y

# CONFIG_SYS_HEAP_ALLOC_LOOPS=3
# CONFIG_SYS_HEAP_RUNTIME_STATS=y
# CONFIG_PM_DEVICE=n
# CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2
# CONFIG_UART_0_NRF_HW_ASYNC=y

# Microphone (PDM) configuration
CONFIG_NRFX_PDM=y
CONFIG_REBOOT=n

CONFIG_PSA_WANT_ALG_DETERMINISTIC_ECDSA=y
# CONFIG_PSA_WANT_ALG_ECDSA=y
# CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR=y
CONFIG_PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY=y

# CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC=n
CONFIG_PSA_WANT_ALG_HMAC=y


# CONFIG_PRINTK=y
CONFIG_FS_FATFS_LFN=y
CONFIG_TLS_CREDENTIALS=y


CONFIG_RESET_ON_FATAL_ERROR=n
CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y

CONFIG_WPA_SUPP_CRYPTO_PSA=y

# # TLS
# # STEP 1.1 - Enable the TLS library and security relevant configurations
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_TLS_CREDENTIALS=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_DHM_C=y 

# # # STEP 1.2 - Enable support for server name indication (SNI)
CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y


CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_TLS_LIBRARY=y
CONFIG_TLS_CREDENTIALS_BACKEND_PROTECTED_STORAGE=y


CONFIG_POSIX_CLOCK=y

CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024

# CONFIG_BUILD_WITH_TFM=y

CONFIG_NORDIC_SECURITY_BACKEND=y
CONFIG_CC3XX_BACKEND=y
CONFIG_MBEDTLS_TLS_LIBRARY=y
CONFIG_MBEDTLS_ECDSA_DETERMINISTIC=n
CONFIG_MBEDTLS_SSL_SRV_C=n
CONFIG_MBEDTLS_X509_CSR_WRITE_C=y
CONFIG_MBEDTLS_X509_CREATE_C=y
CONFIG_MBEDTLS_PK_WRITE_C=y
CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y
CONFIG_MBEDTLS_PKCS1_V15=y

# For hardware crypto accelerator
CONFIG_PSA_CRYPTO_DRIVER_OBERON=n
CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y

CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=81920
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_MAC_SHA256_ENABLED=y
# CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=8192
CONFIG_MBEDTLS_TLS_LIBRARY=y
# CONFIG_MBEDTLS=y
# CONFIG_MBEDTLS_ENABLE_HEAP=y
# CONFIG_MBEDTLS_LEGACY_CRYPTO_C=y
# CONFIG_PSA_WANT_RSA_KEY_SIZE_4096=y

# CONFIG_CC3XX_BACKEND=y
# CONFIG_OBERON_BACKEND=n
# CONFIG_MBEDTLS_HEAP_SIZE=81920


#To enable BLE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="UH_112233445566"
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1
CONFIG_BT_SETTINGS=y
CONFIG_BT_HCI_IPC=y

# CONFIG_BT_SMP=y
CONFIG_BT_DEVICE_NAME_DYNAMIC=y

# Enable the NUS service
CONFIG_BT_NUS=y

# CONFIG_BT_ATT_PREPARE_COUNT=4
CONFIG_BT_L2CAP_TX_MTU=300
# CONFIG_BT_L2CAP_TX_BUF_COUNT=10
# CONFIG_BT_L2CAP_TX_FRAG_COUNT=15
CONFIG_BT_BUF_EVT_RX_SIZE=251
CONFIG_BT_BUF_CMD_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=300
# CONFIG_BT_BUF_ACL_TX_COUNT=15
# CONFIG_BT_BUF_ACL_TX_SIZE=251
# CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
# CONFIG_BT_CONN_TX_MAX=10

# CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP=y
CONFIG_BT_USER_DATA_LEN_UPDATE=y

CONFIG_BT_GATT_CLIENT=y

# CONFIG_BT_NUS_THREAD_STACK_SIZE= 4096


CONFIG_SNTP=y
CONFIG_NET_UDP=y

# CONFIG_HW_STACK_PROTECTION=y
# CONFIG_STACK_CANARIES=y
# CONFIG_STACK_SENTINEL=y
# CONFIG_INIT_STACKS=y
# CONFIG_THREAD_STACK_INFO=y

# CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=2048

# CONFIG_NET_SOCKETS_OFFLOAD=n
# Enable additional buffers
# CONFIG_DNS_RESOLVER_ADDITIONAL_BUF_CTR=5
# # # Enable additional queries
# CONFIG_DNS_RESOLVER_ADDITIONAL_QUERIES=2
# CONFIG_DNS_RESOLVER_MAX_SERVERS=4

CONFIG_NET_LOG=y

# CONFIG_DNS_NUM_CONCUR_QUERIES=2
# CONFIG_DNS_RESOLVER_AI_MAX_ENTRIES=4

# for dns logs
# CONFIG_DNS_RESOLVER_LOG_LEVEL_DBG=y
# CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
# # CONFIG_NET_SHELL=y

# CONFIG_NET_CONFIG_SCONFIG_NET_PING=y

# CONFIG_NFCT_PINS_AS_GPIOS=y
# CONFIG_NET_SOCKETS_DNS_TIMEOUT=8000

# # # # DFU THROUGH BLE
CONFIG_BOOTLOADER_MCUBOOT=y
# #Include MCUMGR and the dependencies in the build
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
# CONFIG_BT_DEBUG_LOG=n


This is my nrf7002dk_nrf5340_cpuapp.conf file

CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_SPI=y
CONFIG_DISK_DRIVERS=y

CONFIG_WIFI_CREDENTIALS_BACKEND_SETTINGS=y





Parents Reply Children
  • Yes, so the maximum size of CONFIG_DOWNLOAD_CLIENT_BUF_SIZE and CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE is 4096 as per defined in the Kconfig file but the size of binary file which I need to download is of size 740kb 
    For this do I need to add one more size value in the Kconfig like 8192?

    The issue is that it doesn't reconnects again why is that 

  • The CONFIG_DOWNLOAD_CLIENT_BUF_SIZE and CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE parameters in the Kconfig file are not directly related to the total size of the file you want to download. They define the size of the buffer used for each fragment of the download and the maximum size of each HTTP fragment respectively.

    For " <err> download_client: Unable to connect, errno 2" in your log, see my colleague's reply in this post and this pot

    In the log, <err> fota: Error -117 means the Host is down. 

  • But how is that possible that after every 204800 bytes only the downloading stops, if the buffer size is 2048 ? If I suppose decrease the buffer size to 512 also the downloading stops at 51200 bytes, something related with 100
    Do u know what that could be? Also I am attaching my prj.conf file for better understanding

    # Wi-Fi
    CONFIG_WIFI=y
    CONFIG_WIFI_NRF700X=y
    CONFIG_WPA_SUPP=y
    
    # Wi-Fi credentials
    CONFIG_WIFI_CREDENTIALS=y
    CONFIG_WIFI_CREDENTIALS_STATIC=y
    CONFIG_WIFI_CREDENTIALS_STATIC_SSID="UltraHuman-4th Floor"
    CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="Ultra@Human$!"
    
    # Networking Management API
    CONFIG_NET_MGMT=y
    CONFIG_NET_MGMT_EVENT=y
    CONFIG_NET_MGMT_EVENT_INFO=y
    CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096
    CONFIG_NET_CONNECTION_MANAGER=y
    CONFIG_WIFI_MGMT_EXT=y
    
    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_POSIX_MAX_FDS=12
    
    CONFIG_NET_L2_ETHERNET=y
    CONFIG_NET_IPV4=y
    CONFIG_NET_IPV6=n
    CONFIG_NET_TCP=y
    CONFIG_NET_DHCPV4=y
    CONFIG_DNS_RESOLVER=y
    
    # Memory
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_HEAP_MEM_POOL_SIZE=153600
    
    CONFIG_NET_TCP_WORKQ_STACK_SIZE=2048
    CONFIG_NET_TX_STACK_SIZE=4096
    CONFIG_NET_RX_STACK_SIZE=4096
    CONFIG_NET_BUF_RX_COUNT=20
    CONFIG_NET_BUF_TX_COUNT=20
    
    CONFIG_NET_BUF_DATA_SIZE=256
    CONFIG_NET_TC_TX_COUNT=0
    
    # # HTTP
    # STEP 1 -  Enable the HTTP client library
    CONFIG_HTTP_CLIENT=y
    
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    CONFIG_LOG_PRINTK=y
    
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_CBPRINTF_FP_SUPPORT=y
    
    CONFIG_SETTINGS=y                                   #Enables the settings subsystem
    CONFIG_FLASH=y                                      #Enables the flash drivers
    CONFIG_FLASH_PAGE_LAYOUT=y                          #API for retrieving the layout of pages
    CONFIG_FLASH_MAP=y                                  #Enables the flash map abstraction module
    CONFIG_NVS=y                                       #Enables support for non-volatile storage
    CONFIG_SETTINGS_NVS=y
    
    CONFIG_WPA_SUPP_CRYPTO_PSA=y
    
    # # TLS
    # # STEP 1.1 - Enable the TLS library and security relevant configurations
    CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
    CONFIG_TLS_CREDENTIALS=y
    CONFIG_MBEDTLS_RSA_C=y
    CONFIG_MBEDTLS_DHM_C=y 
    
    # # # STEP 1.2 - Enable support for server name indication (SNI)
    CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y
    
    
    CONFIG_MBEDTLS=y
    CONFIG_MBEDTLS_TLS_LIBRARY=y
    CONFIG_TLS_CREDENTIALS_BACKEND_PROTECTED_STORAGE=y
    
    
    CONFIG_POSIX_CLOCK=y
    
    CONFIG_NET_CONNECTION_MANAGER=y
    CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024
    
    # CONFIG_BUILD_WITH_TFM=y
    
    CONFIG_NORDIC_SECURITY_BACKEND=y
    CONFIG_CC3XX_BACKEND=y
    CONFIG_MBEDTLS_TLS_LIBRARY=y
    CONFIG_MBEDTLS_ECDSA_DETERMINISTIC=n
    CONFIG_MBEDTLS_SSL_SRV_C=n
    CONFIG_MBEDTLS_X509_CSR_WRITE_C=y
    CONFIG_MBEDTLS_X509_CREATE_C=y
    CONFIG_MBEDTLS_PK_WRITE_C=y
    CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y
    CONFIG_MBEDTLS_PKCS1_V15=y
    
    # For hardware crypto accelerator
    CONFIG_PSA_CRYPTO_DRIVER_OBERON=n
    CONFIG_PSA_CRYPTO_DRIVER_CC3XX=y
    
    CONFIG_MBEDTLS_PSA_CRYPTO_C=y
    CONFIG_MBEDTLS_ENABLE_HEAP=y
    CONFIG_MBEDTLS_HEAP_SIZE=81920
    CONFIG_MBEDTLS_ENABLE_HEAP=y
    CONFIG_MBEDTLS_MAC_SHA256_ENABLED=y
    # CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=8192
    CONFIG_MBEDTLS_TLS_LIBRARY=y
    
    #FOTA
    # CONFIG_FOTA_DOWNLOAD=y
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    
    # DFU Target
    # CONFIG_DFU_TARGET=y
    
    # # Application Upgrade support
    # CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_DOWNLOAD_CLIENT_LOG_HEADERS=y
    CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_DBG=y
    # CONFIG_FOTA_DOWNLOAD_LOG_LEVEL_DBG=y
    
    
    CONFIG_LOG_BUFFER_SIZE=8192
    

  • Hi, 

    We setup nginx web server serving both http and https a big file (1 MB size). Then tested the download_client library using the samples/net/download/ sample application and everything worked fine for both http and https connections, there was no issue with the download_client library.

    The following setup was used in the test:

    west build -p -b native_sim samples/net/download/ -d ../build/fota-download -- \
    -DCONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD="\"gnome-terminal -- screen %s\"" \
    -DCONFIG_NET_SHELL=y \
    -DCONFIG_SAMPLE_FILE_CUSTOM=y \
    -DCONFIG_SAMPLE_FILE_URL="\"https://192.0.2.2/big-file.txt\\"" \
    -DCONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_DBG=y \
    -DCONFIG_DOWNLOAD_CLIENT_LOG_HEADERS=y \
    -DCONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y \
    -DCONFIG_LOG=y -DCONFIG_NET_LOG=y \
    -DCONFIG_NET_CONTEXT_RCVTIMEO=y \
    -DCONFIG_NET_CONTEXT_SNDTIMEO=y \
    -DCONFIG_MBEDTLS_DEBUG=y CONFIG_MBEDTLS_LOG_LEVEL_DBG=y \
    -DCONFIG_NET_SOCKETS_POLL_MAX=10 \
    -DCONFIG_MBEDTLS=y \
    -DCONFIG_MBEDTLS_ENABLE_HEAP=y \
    -DCONFIG_MBEDTLS_HEAP_SIZE=220000 \
    -DCONFIG_MBEDTLS_TLS_VERSION_1_2=y \
    -DCONFIG_MBEDTLS_BUILTIN=y \
    -DCONFIG_MBEDTLS_CIPHER_CHACHA20_ENABLED=y \
    -DCONFIG_MBEDTLS_KEY_EXCHANGE_ALL_ENABLED=y \
    -DCONFIG_MBEDTLS_CIPHER_ALL_ENABLED=y \
    -DCONFIG_MBEDTLS_ECP_ALL_ENABLED=y \
    -DCONFIG_MBEDTLS_HASH_ALL_ENABLED=y \
    -DCONFIG_MBEDTLS_GENPRIME_ENABLED=y \
    -DCONFIG_MBEDTLS_HMAC_DRBG_ENABLED=y \
    -DCONFIG_MBEDTLS_ECDH_C=y \
    -DCONFIG_MBEDTLS_ECDSA_C=y \
    -DCONFIG_MBEDTLS_ECJPAKE_C=y \
    -DCONFIG_MBEDTLS_ECP_C=y \
    -DCONFIG_MBEDTLS_MAC_POLY1305_ENABLED=y \
    -DCONFIG_MBEDTLS_MAC_ALL_ENABLED=y

    If the above cannot help, could you test with nRF7002DK and provide the project for nRF7002DK?

  • Hey Amanda

    So when I enabled the extra configurations which u mentioned above the issue is that I am using CONFIG_MBEDTLS_HEAP_SIZE=81920 and u used 220000 which is quite large and is overflowing the ram 
    Wanted to know that does increasing this value has some impact on the downloading procedure?
    The previous results which I provided was of nrf7002DK only

    Also wanted to know that why does after a certain size which I mentioned in my above configurations also, the response which I receive is of connection: close and it is always happening after sending 100 GET requests

Related