Adding NVS in zigbee sample

We are making ZigBee product. The base we have took is from nrf connect sdk samples light_switch and coordniator example. everything works fine but we need to keep some information stored in NVS/flash.

Mainly for device list in network so that we can relate mac and short address and update it when rejoins. so that when coordinator  restarts it has network device list.

Issue we are facing is that when we add nvs sample code it gives error 

*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
[00:00:00.020,416] <err> flash_nrf: invalid address: 0x00100ff8:8
[00:00:00.037,841] <inf> fs_nvs: 3 Sectors of 4096 bytes
[00:00:00.038,604] <inf> fs_nvs: alloc wra: 0, fe8
[00:00:00.039,306] <inf> fs_nvs: data wra: 0, 0
[00:00:00.040,039] <err> flash_nrf: invalid address: 0x00100ff8:8
No address found, adding 192.168.1.1 at id 1
[00:00:00.041,351] <err> flash_nrf: invalid address: 0x00100ff8:8
[00:00:00.042,236] <err> flash_nrf: invalid address: 0x00100ff8:8
No key found, adding it at id 2

After research found its due to multi build 
The nRF Connect SDK build system enables sysbuild by default, while Zephyr build system does not. You can select the build system default or choose to explicitly use --sysbuild or --no-sysbuild for your build configuration. 

I am not sure how to fix it still
Any suggestion idea will be helpful!

  • Hi,

     

    Thank you for sharing this, I was able to reproduce the scenario.

    The problem is that ZIGBEE_SCENES uses settings, which uses NVS as the backend.

    The application must then setup a specific storage partition that does not overlap with this settings partition. This can be done by setting a dedicated partition, lets name this "second_storage" here for simplicity:

    // Comment out "original" partition name
    //#define NVS_PARTITION       storage_partition
    #define NVS_PARTITION       second_storage

    Then we adjust the flash by placing this in the myproject/pm_static.yml:

    app:
      address: 0x0
      end_address: 0xf3000
      region: flash_primary
      size: 0xf3000
    settings_storage:
      address: 0xfe000
      end_address: 0x100000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
    zboss_nvram:
      address: 0xf5000
      end_address: 0xfd000
      placement:
        after:
        - app
        align:
          start: 0x1000
      region: flash_primary
      size: 0x8000
    zboss_product_config:
      address: 0xfd000
      end_address: 0xfe000
      placement:
        after:
        - zboss_nvram
      region: flash_primary
      size: 0x1000
    second_storage:
      address: 0xf3000
      end_address: 0xf5000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x2000
    

    Ran your on a nrf52840dk_nrf52840 board:

     

    *** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
    *** Using Zephyr OS v3.7.99-0bc3393fb112 ***
    I: Starting ZBOSS Light Switch example
    I: 3 Sectors of 4096 bytes
    I: alloc wra: 0, bf8
    I: data wra: 0, 280
    Id: 1, Address: 192.168.1.1
    Id: 2, Key: ff fe fd fc fb fa f9 f8 
    Id: 3, Reboot_counter: 120
    Id: 5, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 2 
    Reboot counter history: ...120...119...118...117...116...115...114...113...112...111...110...109...108...107...106...105...0
    Oldest reboot counter: 0
    Rebooting in ...5...4...3...2...1
    

    Remember to delete your build folder and regenerate the project when changing the partition layout.

     

    Could you try this and report back?

     

    Kind regards,

    Håkon

  • Hi Hakon 

    this worked but partially If I compile same in mac it gives compilation error second_storage undefined

  • Hi,

     

    Dhaval Dalvadi said:
    this worked but partially If I compile same in mac it gives compilation error second_storage undefined

    I am not sure I understand, did the proposed fix work on one machine and not another?

    Can you share a bit more details on what works and what does not ?

     

    Please note that you have to delete your build folder when explicitly creating a new pm_static.yml file.

     

    Kind regards,

    Håkon

  • Hi 
    It worked in windows system but in mac it gives error as mentioned above 

    had already deleted build folder and have confirmed pm_static.yml there with code you have provided and confirmed in windows that it works fine

  • Thank you for explaining.

    Can you share the full output? including the cmake configuration?

     

    It should look similar to this (tested on a macbook):

    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: /Library/Developer/CommandLineTools/usr/bin/python3 (found suitable version "3.9.6", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /Users/hkn/Library/Caches/zephyr
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52840dk, qualifiers: nrf52840
    Parsing /opt/ncs/nrf/samples/zigbee/light_bulb/Kconfig.sysbuild
    Loaded configuration '/opt/ncs/nrf/samples/zigbee/light_bulb/build/_sysbuild/empty.conf'
    Merged configuration '/opt/ncs/nrf/samples/zigbee/light_bulb/build/_sysbuild/empty.conf'
    Configuration saved to '/opt/ncs/nrf/samples/zigbee/light_bulb/build/zephyr/.config'
    Kconfig header saved to '/opt/ncs/nrf/samples/zigbee/light_bulb/build/_sysbuild/autoconf.h'
    -- 
       ********************************
       * Running CMake for light_bulb *
       ********************************
    
    Loading Zephyr default modules (Zephyr base).
    -- Application: /opt/ncs/nrf/samples/zigbee/light_bulb
    -- CMake version: 3.30.2
    -- Found Python3: /usr/bin/python3 (found suitable version "3.9.6", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: /Users/hkn/Library/Caches/zephyr
    -- Zephyr version: 3.6.99 (/opt/ncs/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52840dk, qualifiers: nrf52840
    -- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
    -- Found host-tools: zephyr 0.16.8 (/opt/zephyr-sdk-0.16.8)
    -- Found toolchain: zephyr 0.16.8 (/opt/zephyr-sdk-0.16.8)
    -- Found Dtc: /opt/homebrew/bin/dtc (found suitable version "1.7.1", minimum required is "1.4.6")
    -- Found BOARD.dts: /opt/ncs/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: /opt/ncs/nrf/samples/zigbee/light_bulb/boards/nrf52840dk_nrf52840.overlay
    -- Generated zephyr.dts: /opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb/zephyr/dts.cmake
    Parsing /opt/ncs/zephyr/Kconfig
    Loaded configuration '/opt/ncs/zephyr/boards/nordic/nrf52840dk/nrf52840dk_nrf52840_defconfig'
    Merged configuration '/opt/ncs/nrf/samples/zigbee/light_bulb/prj.conf'
    Merged configuration '/opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb/zephyr/.config.sysbuild'
    Configuration saved to '/opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb/zephyr/.config'
    Kconfig header saved to '/opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: /opt/zephyr-sdk-0.16.8/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    -- Using ccache: /opt/homebrew/bin/ccache
    CMake Warning at /opt/ncs/zephyr/CMakeLists.txt:2027 (message):
      __ASSERT() statements are globally ENABLED
    
    
    -- Configuring done (4.1s)
    -- Generating done (0.2s)
    -- Build files have been written to: /opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb
    -- Found partition manager static configuration : /opt/ncs/nrf/samples/zigbee/light_bulb/pm_static.yml
    Partition 'settings_storage' is not included in the dynamic resolving since it is statically defined.
    Partition 'zboss_nvram' is not included in the dynamic resolving since it is statically defined.
    Partition 'zboss_product_config' is not included in the dynamic resolving since it is statically defined.
    -- Configuring done (6.1s)
    -- Generating done (0.0s)
    -- Build files have been written to: /opt/ncs/nrf/samples/zigbee/light_bulb/build
    -- west build: building application
    [5/10] Performing build step for 'light_bulb'
    [1/363] Preparing syscall dependency handling
    
    [6/363] Generating include/generated/version.h
    -- Zephyr version: 3.6.99 (/opt/ncs/zephyr), build: v3.6.99-ncs2
    [356/363] Building C object CMakeFiles/app.dir/src/main.c.obj
    [363/363] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      374960 B       972 KB     37.67%
                 RAM:       59504 B       256 KB     22.70%
            IDT_LIST:          0 GB        32 KB      0.00%
    Generating files from /opt/ncs/nrf/samples/zigbee/light_bulb/build/light_bulb/zephyr/zephyr.elf for board: nrf52840dk
    [10/10] Generating ../merged.hex

     

    Kind regards,

    Håkon

Related