Wrong read from settings_storage flash in nRF52840 and nRF Connect SDK 2.4.1

Hi,

I have an example based on v2.4.1\nrf\samples\bluetooth\peripheral_lbs

This is my prj.conf

# Flash
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# Bluetooth
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Intonavi"

# FOTA
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
CONFIG_SECURE_BOOT=y
CONFIG_SB_SIGNING_KEY_FILE="d:/NordicSemiconductor/apps/ble_ota2/priv-ecdsa.pem"

this is my pm_static.yml, this is copy from file: build/partitions.yml

EMPTY_0:
  address: 0x15200
  end_address: 0x16000
  placement:
    before:
    - s1_pad
  region: flash_primary
  size: 0xe00
EMPTY_1:
  address: 0x22200
  end_address: 0x23000
  placement:
    before:
    - mcuboot_pad
  region: flash_primary
  size: 0xe00
EMPTY_2:
  address: 0xf5000
  end_address: 0xf6000
  placement:
    after:
    - mcuboot_secondary
  region: flash_primary
  size: 0x1000
app:
  address: 0x23200
  end_address: 0x8c000
  region: flash_primary
  size: 0x68e00
app_image:
  address: 0x23200
  end_address: 0x8c000
  orig_span: &id001
  - app
  region: flash_primary
  size: 0x68e00
  span: *id001
b0:
  address: 0x0
  end_address: 0x8000
  placement:
    after:
    - start
  region: flash_primary
  size: 0x8000
b0_container:
  address: 0x0
  end_address: 0x9000
  orig_span: &id002
  - b0
  - provision
  region: flash_primary
  size: 0x9000
  span: *id002
mcuboot:
  address: 0x9200
  end_address: 0x15200
  placement:
    before:
    - mcuboot_primary
  region: flash_primary
  sharers: 0x1
  size: 0xc000
mcuboot_pad:
  address: 0x23000
  end_address: 0x23200
  placement:
    align:
      start: 0x1000
    before:
    - mcuboot_primary_app
  region: flash_primary
  sharers: 0x2
  size: 0x200
mcuboot_primary:
  address: 0x23000
  end_address: 0x8c000
  orig_span: &id003
  - mcuboot_pad
  - app
  region: flash_primary
  sharers: 0x1
  size: 0x69000
  span: *id003
mcuboot_primary_app:
  address: 0x23200
  end_address: 0x8c000
  orig_span: &id004
  - app
  region: flash_primary
  size: 0x68e00
  span: *id004
mcuboot_secondary:
  address: 0x8c000
  end_address: 0xf5000
  placement:
    after:
    - mcuboot_primary
    align:
      start: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_primary
  size: 0x69000
provision:
  address: 0x8000
  end_address: 0x9000
  placement:
    after:
    - b0
    align:
      start: 0x1000
  region: flash_primary
  size: 0x1000
s0:
  address: 0x9000
  end_address: 0x15200
  orig_span: &id005
  - s0_pad
  - mcuboot
  region: flash_primary
  size: 0xc200
  span: *id005
s0_image:
  address: 0x9200
  end_address: 0x15200
  orig_span: &id006
  - mcuboot
  region: flash_primary
  size: 0xc000
  span: *id006
s0_pad:
  address: 0x9000
  end_address: 0x9200
  placement:
    after:
    - b0_container
    align:
      start: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_pad
  size: 0x200
s1:
  address: 0x16000
  end_address: 0x22200
  orig_span: &id007
  - s1_pad
  - s1_image
  region: flash_primary
  size: 0xc200
  span: *id007
s1_image:
  address: 0x16200
  end_address: 0x22200
  placement:
    after:
    - s1_pad
    - s0
  region: flash_primary
  share_size:
  - mcuboot
  size: 0xc000
s1_pad:
  address: 0x16000
  end_address: 0x16200
  placement:
    after:
    - s0
    align:
      start: 0x1000
  region: flash_primary
  share_size:
  - mcuboot_pad
  size: 0x200
settings_storage:
  address: 0xf6000
  end_address: 0xf8000
  placement:
    align:
      start: 0x1000
  region: flash_primary
  size: 0x2000
sram_primary:
  address: 0x20000000
  end_address: 0x20040000
  region: sram_primary
  size: 0x40000
storage_partition:
  address: 0xf8000
  end_address: 0x100000
  region: flash_primary
  size: 0x8000

I init parametres for settings_storage of flash

#define DATA_PARTITION_OFFSET FIXED_PARTITION_OFFSET (settings_storage)
#define DATA_PARTITION_DEVICE FIXED_PARTITION_DEVICE (settings_storage)

Now i do the following:

Build, Flash, with flash_erease, flash_write and flash_read. This is my console log

Flash is ready
Test 1: Flash erase page at 0xf6000
Flash erase succeeded!
Attempted to write 12c at 0xf6000
Data read: 12c | 300, at 0xf6000
Attempted to write 64 at 0xf6004
Data read: 64 | 100, at 0xf6004
Attempted to write 1 at 0xf6008
Data read: 1 | 1, at 0xf6008
Attempted to write 2 at 0xf600c
Data read: 2 | 2, at 0xf600c

Next step. Comment flash_erease and flash_write, only flash_read is active. Build and Flash device. This is my console log

Flash is ready
Data read: b8397b06 | -1204192506, at 0xf6000
Data read: 689acd9a | 1754975642, at 0xf6004
Data read: 615433a5 | 1632908197, at 0xf6008
Data read: 4293d3ff | 1116984319, at 0xf600c

Why values are different?

When I use storage_partition and hard address 0xf8000 everyfing is ok, after write all next reads have corrected values.

Related