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 GUNO,

    I couldn't get into your technical details yet. However, I know that FAT FS is not working correctly with the Partition Manager at the moment. Since you see the mass storage got the wrong flash region, it could be the same issue.

    Please refer to this ticket:  Mass Example with External Flash not working with CONFIG_BOOTLOADER_MCUBOOT=y.

    There you will see the details of the issue, as well as a workaround explained by Julian, and details of a future fix that you can cherry pick and try out.

    Hieu

  • Hi, 

    Thanks for the replay, sorry for the delay on my part.

    The ticket you linked seems to have a work around for placing the settings storage in the external mem. And thus, in lack of better words, fool the api to return the correct partition?

    The cherry-pick looks promising, i will look into this today.

    When one uses BLE, is it correct that the nvs settings block has to be present for the ble to store persistent data?

    if so, the first workaround would not work if you also need the nvs, correct?  

  • Hi,

    I will be out of office for a week+ in a little bit, so right now I cannot review Julian's workaround to answer your question about it, sorry. 

    Shall we see how well cherry-picking the official fix works first? The pull request is already merged into sdk-nrf latest branch, so if will be eventually released in the next NCS release.

    Let me know if you are more interested on the workaround method. Either one of our engineers can help you with that during my absent, or I can look into it when I return.

Reply
  • Hi,

    I will be out of office for a week+ in a little bit, so right now I cannot review Julian's workaround to answer your question about it, sorry. 

    Shall we see how well cherry-picking the official fix works first? The pull request is already merged into sdk-nrf latest branch, so if will be eventually released in the next NCS release.

    Let me know if you are more interested on the workaround method. Either one of our engineers can help you with that during my absent, or I can look into it when I return.

Children
  • Hi I cherry-picked the 2 commits and added your implementation and kconfig defines.

    I still get the same issues that the flash-controller partition is selected.
    Im not sure if i missing something in my settings from my initial post? but it doesnt seem to make a difference for me.

    *** Booting Zephyr OS build v3.3.99-ncs1 ***
    I: Initialize device NAND
    I: offset 0, sector size 512, page size 4096, volume size 131072
    start
    Area 2 at 0x10000 on flash-controller@39000 for 262144 bytes
    I: Initialize device NAND
    I: offset 0, sector size 512, page size 4096, volume size 131072
    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
    E: failed to create directory (-17)
    E: Failed to create dir /NAND:/some
    /NAND: opendir: 0
    D 0 SYSTEM~1

  • Hi I have now gotten this to work, but it required me to disable BT relevant things (LBS sample merge).

    It seems that the PM doesnt solve using nvs with bluetooth together with fatfs for msc, im not sure why, but there seems to be something there. Maybe you could offer me some insight?

Related