Cannot read/write in nvs when gatt,Bt is active?

Hi,

iam trying to write the data in nvs which i give input through GATT.i  can read and write in nvs when not using gatt,BT.

I have 2 codes,1 is working but without GATT and BT.

another 1 is not working with GATT and BT.

Working code prj.conf

CONFIG_FLASH=y

CONFIG_NVS=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_NVS_LOG_LEVEL_DBG=y
CONFIG_REBOOT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y


CONFIG_FLASH_MAP=y

CONFIG_CJSON_LIB=y

Non working code prj.conf


#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
#CONFIG_BOOTLOADER_MCUBOOT=n
#CONFIG_SRAM_SIZE=128
#CONFIG_SRAM_BASE_ADDRESS=0x20000000
#CONFIG_FLASH_SIZE=512
#CONFIG_FLASH_BASE_ADDRESS=0x00000000
#CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_BT=y
CONFIG_BT_LBS=y
CONFIG_BT_HCI=y
CONFIG_BT_ID_MAX=1
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_SMP=y
CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_SETTINGS_NVS=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y


CONFIG_BT_SETTINGS=y
CONFIG_BT_HCI_VS=y
CONFIG_FLASH=y                 # Ensure flash storage is enabled if you are storing settings in flash


CONFIG_BT_GATT_SERVICE_CHANGED=y

CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_BT_ATT_ERR_TO_STR=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y
CONFIG_JSON_LIBRARY=y
CONFIG_DK_LIBRARY=y

#CONFIG_PM=y
#CONFIG_PM_SINGLE_IMAGE=y
#CONFIG_PM_LOG_LEVEL_DBG=y
#CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_BT_GATT_DM=y
CONFIG_BT_GATT_DM_DATA_PRINT=y
#CONFIG_BT_ADV_PROV_TX_POWER=y
#bt Update Data Length and MTU
#CONFIG_BT_USER_DATA_LEN_UPDATE=y
#CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

#for import json
CONFIG_CJSON_LIB=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
#CONFIG_HEAP_MEM_POOL_SIZE=8192


#MTU update configurations
CONFIG_BT_USER_DATA_LEN_UPDATE=y
#CONFIG_BT_CTLR_DATA_LENGTH_MAX=100
#CONFIG_BT_BUF_ACL_RX_SIZE=251
#CONFIG_BT_BUF_ACL_TX_SIZE=251
#CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_PRIVACY=y


CONFIG_NVS=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_NVS_LOG_LEVEL_DBG=y
CONFIG_REBOOT=y
CONFIG_SETTINGS_NVS=y

CONFIG_FLASH_MAP=y
CONFIG_SETTINGS_NVS_SECTOR_COUNT=3

working code partitions.yml

app:
  address: 0x0
  end_address: 0x78000
  region: flash_primary
  size: 0x78000
nvs_storage:
  address: 0x7a000
  end_address: 0x80000
  placement:
    before:
    - end
  region: flash_primary
  size: 0x6000
settings_storage:
  address: 0x78000
  end_address: 0x7a000
  placement:
    align:
      start: 0x1000
    before:
    - end
  region: flash_primary
  size: 0x2000
sram_primary:
  address: 0x20000000
  end_address: 0x20020000
  region: sram_primary
  size: 0x20000

non working code partitions.yml

app:
  address: 0x0
  end_address: 0x7e000
  region: flash_primary
  size: 0x7e000
settings_storage:
  address: 0x7e000
  end_address: 0x80000
  placement:
    align:
      start: 0x1000
    before:
    - end
  region: flash_primary
  size: 0x2000
sram_primary:
  address: 0x20000000
  end_address: 0x20020000
  region: sram_primary
  size: 0x20000

while initialise the nvs i got the following error,

[00:00:00.059,661] <err> flash_nrf: invalid address: 0x00080ff8:8
Error: Failed to write JSON data to NVS, rc=-22

in wrking code there is a separate partition for nvs,but in non working code there is not.i use the same build config for both the codes.is it because of enabling the GATT and BT?Please someone guide

  • now i got the new issue..when receiving payload via gatt

    Bluetooth initialized
    GATT service registered successfully
    Advertising successfully started
    Connected
    MTU exchange successfulNew MTU: 244 bytes[00:00:25.039,489] <err> os: ***** MPU FAULT *****
    [00:00:25.045,227] <err> os:   Stacking error (context area might be not valid)
    [00:00:25.053,588] <err> os:   Data Access Violation
    [00:00:25.059,509] <err> os:   MMFAR Address: 0x200042f4
    [00:00:25.065,826] <err> os: r0/a1:  0x76958a95  r1/a2:  0xf2c261a7  r2/a3:  0x801356c8
    [00:00:25.074,981] <err> os: r3/a4:  0x21afe17a r12/ip:  0x59c23f4d r14/lr:  0x3fb7d555
    [00:00:25.084,136] <err> os:  xpsr:  0x259b6000
    [00:00:25.089,660] <err> os: Faulting instruction address (r15/pc): 0x41310686
    [00:00:25.097,930] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
    [00:00:25.106,231] <err> os: Current thread: 0x20001d88 (unknown)
    [00:00:25.113,372] <err> os: Halting system

  • i just increased the mtu size..after that only iam facing the above error

    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_L2CAP_TX_MTU=247

    CONFIG_BT_RX_STACK_SIZE=1024
    CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
    CONFIG_BT_HCI_TX_STACK_SIZE=640
    CONFIG_MAIN_STACK_SIZE=4096
  • i just increased the mtu size..after that only iam facing the above error

    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_L2CAP_TX_MTU=247

    CONFIG_BT_RX_STACK_SIZE=1024
    CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
    CONFIG_BT_HCI_TX_STACK_SIZE=640
    CONFIG_MAIN_STACK_SIZE=4096
  • after removing the below code,i can receive the gatt data...

    can you explain the suituation

    CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y
    CONFIG_BT_HCI_TX_STACK_SIZE=640
    CONFIG_MAIN_STACK_SIZE=4096
Related