NRF5340 Mass storage using partition manager points to wrong device.

Hi, Im working with a 5340 dk, where i want to add a fatfs msc on the external flash togther with ble. From what i gather from ble examples uses pm and nvs to function.

So in this example https://docs.zephyrproject.org/latest/samples/subsys/usb/mass/README.html 

The device tree storage partition is replaced in the overlay, however with the ble example this wont work since its using the PM.

So firstly i tried to modify the example to use PM instead, the overlay would be changed to use nordic,pm-ext-flash but then the application seem to fetch the wrong partition

Area 2 at 0x10000 on flash-controller@39000 for 262144 bytes and creates the filesystem on the internal flash?

Below are code snippets with changes to go from device tree to pm.

I have two questions.

1. How do i fix so that the external flash is targeted?

2. If i want to use ble and msc, how do i keep nvs params in internal flash(not deleting storage_partition?) and put the filesystem on the external flash?

3. The reference storage_partition seems to be static in zephyr, is it possible to add another or should one add the external flash as an id under this partition to be able to reference it in code as its done in the mass example?

Thanks!

/*
 * Copyright (c) 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/delete-node/ &storage_partition;

&mx25r64 {
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		storage_partition: partition@0 {
			label = "storage";
			reg = <0x00000000 0x00020000>;
		};
	};
};

/{
	chosen
	{
		nordic,pm-ext-flash = &mx25r64;

	};

	msc_disk0 {
		compatible = "zephyr,flash-disk";
		partition = <&storage_partition>;
		disk-name = "NAND";
		cache-size = <4096>;
	};
};

Then a pm_static.yml added to the project as follows.

external_flash:
  address: 0x0
  end_address: 0x4000000
  size: 0x04000000
  device: mx25r64
  region: external_flash

storage_partition:
  address: 0x0
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0x400000
  placement:
    after:
    - start
  region: external_flash
  size: 0x0400000

With these changes the software now builds and runs but it seems to fetch the wrong partition in the mass example.

Area 2 at 0x10000 on flash-controller@39000 for 262144 bytes

partitions.yaml clearly adds the new partition

app:
  address: 0x0
  end_address: 0x100000
  region: flash_primary
  size: 0x100000
external_flash:
  address: 0x0
  device: mx25r64
  end_address: 0x4000000
  region: external_flash
  size: 0x4000000
otp:
  address: 0xff8100
  end_address: 0xff83fc
  region: otp
  size: 0x2fc
sram_primary:
  address: 0x20000000
  end_address: 0x20080000
  region: sram_primary
  size: 0x80000
storage_partition:
  address: 0x0
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0x400000
  placement:
    after:
    - start
  region: external_flash
  size: 0x400000

The generated devicetree states partitions on the qspi driver

 *   11  /soc/peripheral@50000000
 *   12  /soc/peripheral@50000000/qspi@2b000
 *   13  /soc/peripheral@50000000/qspi@2b000/mx25r6435f@0
 *   14  /soc/peripheral@50000000/qspi@2b000/mx25r6435f@0/partitions
 *   15  /soc/peripheral@50000000/qspi@2b000/mx25r6435f@0/partitions/partition@0
 ....
  *   129 /soc/peripheral@50000000/flash-controller@39000
 *   130 /soc/peripheral@50000000/flash-controller@39000/flash@0
 *   131 /soc/peripheral@50000000/flash-controller@39000/flash@0/partitions
 *   132 /soc/peripheral@50000000/flash-controller@39000/flash@0/partitions/partition@0
 *   133 /soc/peripheral@50000000/flash-controller@39000/flash@0/partitions/partition@10000
 *   134 /soc/peripheral@50000000/flash-controller@39000/flash@0/partitions/partition@50000
 *   135 /soc/peripheral@50000000/flash-controller@39000/flash@0/partitions/partition@80000
 *   136 /soc/peripheral@50000000/flash-controller@39000/flash@0/partitions/partition@c0000

Parents
  • Hi Gustav

    I'm taking over this case for Hieu while he's out of office.

    What external flash device is it you're trying to use here? I see the logs repeatedly mentioning a NAND device. Our QSPI peripheral only supports NOR flash devices by default, as NAND flashes are much more complicated to set up, and the driver functions we have aren't designed for them.

    By "I have now gotten this to work", does that mean you have an acceptable workaround or just that you were able to create a directory for your FatFS and MSC? At the moment I can't think of why the BLE controller would block the file system from setting up correctly, unless you're trying to set it up while the Bluetooth is running some operations that takes precedence perhaps...

    Best regards,

    Simon

  • Hi Simon.

    Thanks for taking over, im using the 5340 devkit, nand is just the default mount name given in zephyr/nrfs code. 

    "I have now gotten this to work" is referring to cherrypicking the two commits linked in the post by Hieu. There are two commits that are included in the 2.4.99-dev2 that changes a bit how pm affiliate disks..  

    https://github.com/nrfconnect/sdk-nrf/pull/11802/commits

    then integration part of
    https://github.com/sigvartmh/fw-nrfconnect-nrf-1/pull/38/commits/386b811dfb177a898269124af981c2b8c12214b7

    This works on the devkit and targets the flash

    *** Booting Zephyr OS build v3.3.99-ncs1 ***
    I: Initialize device NAND
    I: offset 0, sector size 512, page size 4096, volume size 524288
    start
    Area 0 at 0x0 on mx25r6435f@0 for 524288 bytes
    I: Initialize device NAND
    I: offset 0, sector size 512, page size 4096, volume size 524288
    Mount /NAND:: 0
    /NAND:: bsize = 512 ; frsize = 512 ; blocks = 216 ; bfree = 210
    PATH: : /NAND:/tester
    I: Creating some dir entries in /NAND:
    PATH create: : /NAND:/some.dat

    However if I add the following to my prj.conf

    CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_LBS"
    
    CONFIG_GPIO=y
    # Enable the LBS service
    CONFIG_BT_LBS=y
    CONFIG_BT_LBS_POLL_BUTTON=y
    CONFIG_DK_LIBRARY=y
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
     
    And the following to my Kconfig, these are then whats selected in a different ble example. when i try to combine some ble features with the msc. it bricks the build and the flash controller is targeted instead of the flash driver above.
    menu "Nordic LED-Button BLE GATT service sample"
    
    config BT_LBS_SECURITY_ENABLED
        bool "Enable security"
        default y
        select BT_SMP
        select BT_SETTINGS
        select FLASH
        select FLASH_PAGE_LAYOUT
        select FLASH_MAP
        select NVS
        select SETTINGS
        help
          "Enable BLE security for the LED-Button service"
    endmenu

    - - - - - - - - - - - - - - - - - TARGET RESET - - - - - - - - - - - - - - - - -
    *** Booting Zephyr OS build v3.3.99-ncs1 ***
    I: Initialize device NAND
    I: offset 0, sector size 512, page size 4096, volume size 524288
    start
    Area 4 at 0xf0000 on flash-controller@39000 for 65536 bytes
    I: Initialize device NAND
    I: offset 0, sector size 512, page size 4096, volume size 524288
    I: Initialize device NAND
    I: offset 0, sector size 512, page size 4096, volume size 524288

    This is why i made the connection, i would guess that enabling NVS (which i assume is non volatile storage for the ble to use, maybe im wrong and it doesnt need this at all?), might mess up the ifdef case in flash_map_pm.h where storage macros are used.

    I was thinking that enabling nvs and also the msc could mess up macros in the flash_map_pm.h file

    #if (CONFIG_SETTINGS_FCB || CONFIG_SETTINGS_NVS || defined(PM_SETTINGS_STORAGE_ID))
    #define storage settings_storage
    #define storage_partition settings_storage
    #elif CONFIG_FILE_SYSTEM_LITTLEFS
    #define storage littlefs_storage
    #define storage_partition littlefs_storage
    #elif CONFIG_NVS
    #define storage nvs_storage
    #define storage_partition nvs_storage
    #endif

Reply Children
No Data
Related