Mass USB Storage on External QSPI Flash in Non-secure build with TFM

Hi,
I have been experimenting with an NRF5340dk for the past few days around the application of emulating a Mass USB storage device when connected to a PC.

I came across the Mass Storage Sample outlined here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/zephyr/samples/subsys/usb/mass/README.html
Building and running the application works without issue and I am able to see the dev kit as a USB drive on the PC where I can add and remove files etc.

To take this sample a step further I wanted to achieve the same application but to build with the non-secure board: nrf5340dk_nrf5340_cpuapp_ns to take advantage of TFM.

I have read through the documentation available for the NRF Connect SDK and have yet to have some success with getting the application to build and run correctly. I initially tried modifying the application by doing the following:
- Adding an nrf5340dk_nrf5340_cpuapp_ns.overlay containing the same contents as the included nrf5340dk_nrf5340_cpuapp.overlay.
- Adding the following KConfig arguments:
CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y
CONFIG_BUILD_WITH_TFM=y
CONFIG_TFM_PROFILE_TYPE_MINIMAL=y
CONFIG_TFM_BL2=n

However this had no success as I was receiving the following error in the build process:


error: 'PM_storage_partition_ID' undeclared (first use in this function)
41 | #define PM_ID(label) PM_##label##_ID


I believe this is due to the fact that the partition manager is not adding the "storage_partition" in external flash to the "nonsecure_storage" region required when building with TFM. This is observed in this line in the build output:
Dropping partition 'nonsecure_storage' since it is empty.
I then found out that the ncs v2.2.0 has a known issue regarding multiple partitions in "nonsecure_storage" on external flash when building with TFM as per this page:
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/known_issues.html

A workaround is suggested by setting partition size to a multiple of CONFIG_NRF_SPU_FLASH_REGION_SIZE (which I am already doing) or
using a static flash layout. I opted to attempt the static flash layout where I updated the project to include a pm_static.yaml file based off the partitions.yaml produced with dynamic partitioning and following the instruction defined in these locations for using external flash and the "nonsecure_storage" partition. However I am now getting the error shown in the image regarding packing of partitions.

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/scripts/partition_manager/partition_manager.html 

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/ug_tfm.html 

I have attached the project as a zip file, showing this result.5025.mass.zip

 

In further testing I noticed that If I create an EMPTY_0 region that fills up the remainder of the external flash region, it will now build, but the partitions.yaml in the build folder is incorrect with partitions having negative starting addresses or sizes.mass(builds).zip

These are the versions of hardware and sdk I am using:

NRF Connect SDK Version: v2.2.0
Nrf5340dk Version: 0.11.0

If someone could please assist me in determining what might be causing this issue and how to correctly set up the example project in the desired way that would be much appreciated.

Thanks in advance for the assistance.



  • Hi Liam

    Took another look at the partition file, and just came to think that having the same name for the partition "ext_flash" and the region "ext_flash" might not be the best idea, so can you try giving these different names so we're sure there is no conflict during build time with using the addresses for partitions and regions that end up as negative values in the partitions.yml file?

    Best regards,

    Simon

Related