USB Mass Storage Sample Application and external SPI NOR flash device

I'm working to implement a USB Mass Storage device which uses an external flash memory to store my application's data. I have an nrf52833 DK and a W25Q64FV NOR flash memory. My work started from the USB Mass Storage sample in the NCS v1.9.1 (ncs\v1.9.1\zephyr\samples\subsys\usb\mass).

I'm newbie with the NCS environment so tell me if I'm saying nosense. 

In this sample I can chose the storage device in the Kconfig so I select the flash adding the permanent configuration APP_MSC_STORAGE_FLASH_FATFS=y to the prj.conf file. Since I'm working on the nrf52833 DK, which has not an external flash device, the sample uses by default the internal flash described in the devicetree as storage_partition node labeled as "storage"

flash_controller: flash-controller@4001e000 {
	compatible = "nordic,nrf52-flash-controller";
	reg = < 0x4001e000 0x1000 >;
	#address-cells = < 0x1 >;
	#size-cells = < 0x1 >;
	label = "NRF_FLASH_DRV_NAME";
	flash0: flash@0 {
		compatible = "soc-nv-flash";
		label = "NRF_FLASH";
		erase-block-size = < 0x1000 >;
		write-block-size = < 0x4 >;
		reg = < 0x0 0x80000 >;
		partitions {
			compatible = "fixed-partitions";
			#address-cells = < 0x1 >;
			#size-cells = < 0x1 >;
			boot_partition: partition@0 {
				label = "mcuboot";
				reg = < 0x0 0xc000 >;
			};
			slot0_partition: partition@c000 {
				label = "image-0";
				reg = < 0xc000 0x32000 >;
			};
			slot1_partition: partition@3e000 {
				label = "image-1";
				reg = < 0x3e000 0x32000 >;
			};
			scratch_partition: partition@70000 {
				label = "image-scratch";
				reg = < 0x70000 0xa000 >;
			};
			storage_partition: partition@7a000 {
				label = "storage";
				reg = < 0x7a000 0x6000 >;
			};
		};
	};
};

In the sample there is an overlay file for the nrf52840 DK which has an external QSPI NOR flash MX25R64 so I suppose that I can create my own overlay file for my nrf52833 DK (which doesn't support QSPI). Coping from the final devicetree of the nrf52840 DK build, I wrote this overlay

/delete-node/ &storage_partition;

&spi1 {
	cs-gpios = <&gpio0 27 GPIO_ACTIVE_LOW>;

	w25q64fv: w25q64fv@0 {
		compatible = "jedec,spi-nor";
		reg = < 0x0 >;
		spi-max-frequency = < 0x7a1200 >;
		label = "W25Q64FV";
		jedec-id = [ C2 28 17 ];
		sfdp-bfp = [ E5 20 F1 FF FF FF FF 03 44 EB 08 6B 08 3B 04 BB EE FF FF FF FF FF 00 FF FF FF 00 FF 0C 20 0F 52 10 D8 00 FF 23 72 F5 00 82 ED 04 CC 44 83 68 44 30 B0 30 B0 F7 C4 D5 5C 00 BE 29 FF F0 D0 FF FF ];
		size = < 0x4000000 >;
		has-dpd;
		t-enter-dpd = < 0x2710 >;
		t-exit-dpd = < 0x88b8 >;
		partitions {
			compatible = "fixed-partitions";
			#address-cells = < 0x1 >;
			#size-cells = < 0x1 >;
			partition@0 {
				label = "storage";
				reg = < 0x0 0x20000 >;
			};
		};
	};
};

Not knowing what to choose I changed the "compatible" property of w25q64fv node with the "jedec,spi-nor" value cause I think that the last value "nordic,qspi-nor" is specific for the QSPI NOR flash. But if I compile it I get errors:

Building mass
west build --build-dir c:\ncsapps\test\mass\build c:\ncsapps\test\mass --pristine --board nrf52833dk_nrf52833 -- -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DBOARD_ROOT:STRING="c:/ncsapps/test/mass" -DCONFIG_DEBUG_OPTIMIZATIONS:STRING="y" -DCONFIG_DEBUG_THREAD_INFO:STRING="y" -DDTC_OVERLAY_FILE:STRING="c:/ncsapps/test/mass/boards/nrf52833dk_nrf52833.overlay" -DCONF_FILE:STRING="c:/ncsapps/test/mass/prj.conf"

-- west build: generating a build system
Including boilerplate (Zephyr base): C:/ncs/v1.9.1/zephyr/cmake/app/boilerplate.cmake
-- Application: C:/ncsapps/test/mass
-- Zephyr version: 2.7.99 (C:/ncs/v1.9.1/zephyr), build: v2.7.99-ncs1-1
-- Found Python3: C:/ncs/v1.9.1/toolchain/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter 
-- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
-- Board: nrf52833dk_nrf52833
-- Cache files will be written to: C:/ncs/v1.9.1/zephyr/.cache
-- Found dtc: C:/ncs/v1.9.1/toolchain/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (c:/ncs/v1.9.1/toolchain/opt)
-- Found BOARD.dts: C:/ncs/v1.9.1/zephyr/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts
-- Found devicetree overlay: c:/ncsapps/test/mass/boards/nrf52833dk_nrf52833.overlay
-- Generated zephyr.dts: C:/ncsapps/test/mass/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: C:/ncsapps/test/mass/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: C:/ncsapps/test/mass/build/zephyr/include/generated/device_extern.h
-- Including generated dts.cmake file: C:/ncsapps/test/mass/build/zephyr/dts.cmake
Parsing C:/ncsapps/test/mass/Kconfig
Loaded configuration 'C:/ncs/v1.9.1/zephyr/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig'
Merged configuration 'c:/ncsapps/test/mass/prj.conf'
Merged configuration 'C:/ncsapps/test/mass/build/zephyr/misc/generated/extra_kconfig_options.conf'
Configuration saved to 'C:/ncsapps/test/mass/build/zephyr/.config'
Kconfig header saved to 'C:/ncsapps/test/mass/build/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/ncs/v1.9.1/toolchain/opt/bin/arm-none-eabi-gcc.exe
CMake Warning at C:\ncs\v1.9.1\zephyr\subsys\usb\CMakeLists.txt:22 (message):
  CONFIG_USB_DEVICE_VID has default value 0x2FE3.

  This value is only for testing and MUST be configured for USB products.


-- Configuring done
-- Generating done
-- Build files have been written to: C:/ncsapps/test/mass/build
-- west build: building application
[1/195] Generating misc/generated/syscalls.json, misc/generated/struct_tags.json
[2/195] Generating include/generated/driver-validation.h
[3/195] Generating include/generated/kobj-types-enum.h, include/generated/otype-to-str.h, include/generated/otype-to-size.h
[4/195] Generating include/generated/syscall_dispatch.c, include/generated/syscall_list.h
[5/195] Building C object zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.obj
[6/195] Generating include/generated/offsets.h
[7/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/nmi_on_reset.S.obj
[8/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/cpu_idle.S.obj
[9/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/swap_helper.S.obj
[10/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/isr_wrapper.S.obj
[11/195] Building C object zephyr/arch/common/CMakeFiles/isr_tables.dir/isr_tables.c.obj
[12/195] Generating linker_zephyr_pre1.cmd
[13/195] Generating linker_zephyr_pre0.cmd
[14/195] Building C object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/prep_c.c.obj
[15/195] Building C object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/irq_manage.c.obj
[16/195] Building C object zephyr/arch/common/CMakeFiles/arch__common.dir/sw_isr_common.c.obj
[17/195] Building C object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/swap.c.obj
[18/195] Building C object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/nmi.c.obj
[19/195] Building C object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/thread.c.obj
[20/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/fault_s.S.obj
[21/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/exc_exit.S.obj
[22/195] Building C object zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj
[23/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/vector_table.S.obj
[24/195] Building C object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/fatal.c.obj
[25/195] Building ASM object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/reset.S.obj
[26/195] Building C object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/irq_init.c.obj
[27/195] Building C object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/fpu.c.obj
[28/195] Linking C static library zephyr\arch\common\libisr_tables.a
[29/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/atoi.c.obj
[30/195] Building C object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/thread_abort.c.obj
[31/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/bsearch.c.obj
[32/195] Linking C static library zephyr\arch\arch\arm\core\aarch32\libarch__arm__core__aarch32.a
[33/195] Building C object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/scb.c.obj
[34/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/strtol.c.obj
[35/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/abort.c.obj
[36/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/strtoul.c.obj
[37/195] Linking C static library zephyr\arch\common\libarch__common.a
[38/195] Building C object zephyr/arch/arch/arm/core/aarch32/mpu/CMakeFiles/arch__arm__core__aarch32__mpu.dir/arm_core_mpu.c.obj
[39/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strstr.c.obj
[40/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/qsort.c.obj
[41/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strncasecmp.c.obj
[42/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/fprintf.c.obj
[43/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/string.c.obj
[44/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/malloc.c.obj
[45/195] Building C object zephyr/arch/arch/arm/core/aarch32/mpu/CMakeFiles/arch__arm__core__aarch32__mpu.dir/arm_mpu.c.obj
[46/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strspn.c.obj
[47/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/stdout_console.c.obj
[48/195] Building C object zephyr/arch/arch/arm/core/aarch32/cortex_m/CMakeFiles/arch__arm__core__aarch32__cortex_m.dir/fault.c.obj
[49/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/exit.c.obj
[50/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/sprintf.c.obj
[51/195] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/time/gmtime.c.obj
[52/195] Building C object zephyr/soc/arm/common/cortex_m/CMakeFiles/soc__arm__common__cortex_m.dir/arm_mpu_regions.c.obj
[53/195] Linking C static library zephyr\arch\arch\arm\core\aarch32\mpu\libarch__arm__core__aarch32__mpu.a
[54/195] Building C object zephyr/lib/posix/CMakeFiles/lib__posix.dir/pthread_common.c.obj
[55/195] Building C object zephyr/lib/posix/CMakeFiles/lib__posix.dir/nanosleep.c.obj
[56/195] Linking C static library zephyr\arch\arch\arm\core\aarch32\cortex_m\libarch__arm__core__aarch32__cortex_m.a
[57/195] Linking C static library zephyr\soc\arm\common\cortex_m\libsoc__arm__common__cortex_m.a
[58/195] Building C object zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj
FAILED: zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj 
C:\ncs\v1.9.1\toolchain\opt\bin\arm-none-eabi-gcc.exe -DBUILD_VERSION=v2.7.99-ncs1-1 -DKERNEL -DNRF52833_XXAA -DUSE_PARTITION_MANAGER=0 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -IC:/ncs/v1.9.1/zephyr/include -Izephyr/include/generated -IC:/ncs/v1.9.1/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v1.9.1/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v1.9.1/zephyr/subsys/usb -IC:/ncs/v1.9.1/nrf/include -IC:/ncs/v1.9.1/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v1.9.1/modules/hal/nordic/nrfx -IC:/ncs/v1.9.1/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v1.9.1/modules/hal/nordic/nrfx/mdk -IC:/ncs/v1.9.1/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v1.9.1/modules/debug/segger/SEGGER -IC:/ncs/v1.9.1/modules/debug/segger/Config -IC:/ncs/v1.9.1/zephyr/modules/segger/. -isystem C:/ncs/v1.9.1/zephyr/lib/libc/minimal/include -isystem c:/ncs/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/include -isystem c:/ncs/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/include-fixed -Og -imacros C:/ncsapps/test/mass/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -imacros C:/ncs/v1.9.1/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/ncsapps/test/mass=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v1.9.1/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v1.9.1=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj -MF zephyr\drivers\disk\CMakeFiles\drivers__disk.dir\flashdisk.c.obj.d -o zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj -c C:/ncs/v1.9.1/zephyr/drivers/disk/flashdisk.c
In file included from <command-line>:
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:22:43: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
   22 | static uint8_t __aligned(4) read_copy_buf[CONFIG_DISK_ERASE_BLOCK_SIZE];
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v1.9.1/zephyr/drivers/disk/flashdisk.c: In function 'disk_flash_access_read':
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:77:37: error: expected expression before ';' token
   77 |  len = CONFIG_DISK_FLASH_MAX_RW_SIZE;
      |                                     ^
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:27:45: error: expected expression before ')' token
   27 |  ((total_size + block_size - 1) / block_size)
      |                                             ^
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:79:13: note: in expansion of macro 'GET_NUM_BLOCK'
   79 |  num_read = GET_NUM_BLOCK(remaining, CONFIG_DISK_FLASH_MAX_RW_SIZE);
      |             ^~~~~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:82:48: error: expected expression before ')' token
   82 |   if (remaining < CONFIG_DISK_FLASH_MAX_RW_SIZE) {
      |                                                ^
In file included from <command-line>:
C:/ncs/v1.9.1/zephyr/drivers/disk/flashdisk.c: In function 'read_copy_flash_block':
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:12:43: error: invalid suffix "x" on integer constant
   12 | #define CONFIG_DISK_FLASH_ERASE_ALIGNMENT 0x
      |                                           ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:108:20: note: in expansion of macro 'CONFIG_DISK_FLASH_ERASE_ALIGNMENT'
  108 |  if (start_addr & (CONFIG_DISK_FLASH_ERASE_ALIGNMENT - 1)) {
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:12:43: error: invalid suffix "x" on integer constant
   12 | #define CONFIG_DISK_FLASH_ERASE_ALIGNMENT 0x
      |                                           ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:109:26: note: in expansion of macro 'CONFIG_DISK_FLASH_ERASE_ALIGNMENT'
  109 |   offset = start_addr & (CONFIG_DISK_FLASH_ERASE_ALIGNMENT - 1);
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:10:
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:12:43: error: invalid suffix "x" on integer constant
   12 | #define CONFIG_DISK_FLASH_ERASE_ALIGNMENT 0x
      |                                           ^~
C:\ncs\v1.9.1\zephyr\include\sys\util.h:163:42: note: in definition of macro 'ROUND_DOWN'
  163 |  ((unsigned long)(x) & ~((unsigned long)(align) - 1))
      |                                          ^~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:113:35: note: in expansion of macro 'CONFIG_DISK_FLASH_ERASE_ALIGNMENT'
  113 |  fl_addr = ROUND_DOWN(start_addr, CONFIG_DISK_FLASH_ERASE_ALIGNMENT);
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:27:4: note: in definition of macro 'GET_NUM_BLOCK'
   27 |  ((total_size + block_size - 1) / block_size)
      |    ^~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:115:27: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  115 |  num_read = GET_NUM_BLOCK(CONFIG_DISK_ERASE_BLOCK_SIZE,
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:27:45: error: expected expression before ')' token
   27 |  ((total_size + block_size - 1) / block_size)
      |                                             ^
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:115:13: note: in expansion of macro 'GET_NUM_BLOCK'
  115 |  num_read = GET_NUM_BLOCK(CONFIG_DISK_ERASE_BLOCK_SIZE,
      |             ^~~~~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:123:46: error: invalid type argument of unary '*' (have 'uint32_t' {aka 'unsigned int'})
  123 |     fl_addr + (CONFIG_DISK_FLASH_MAX_RW_SIZE * i),
      |                                              ^~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:124:48: error: invalid type argument of unary '*' (have 'uint32_t' {aka 'unsigned int'})
  124 |     dest_buff + (CONFIG_DISK_FLASH_MAX_RW_SIZE * i),
      |                                                ^~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:125:34: error: expected expression before ')' token
  125 |     CONFIG_DISK_FLASH_MAX_RW_SIZE);
      |                                  ^
In file included from <command-line>:
C:/ncs/v1.9.1/zephyr/drivers/disk/flashdisk.c: In function 'update_flash_block':
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:147:13: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  147 |  if (size < CONFIG_DISK_ERASE_BLOCK_SIZE) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:10:
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:12:43: error: invalid suffix "x" on integer constant
   12 | #define CONFIG_DISK_FLASH_ERASE_ALIGNMENT 0x
      |                                           ^~
C:\ncs\v1.9.1\zephyr\include\sys\util.h:163:42: note: in definition of macro 'ROUND_DOWN'
  163 |  ((unsigned long)(x) & ~((unsigned long)(align) - 1))
      |                                          ^~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:160:35: note: in expansion of macro 'CONFIG_DISK_FLASH_ERASE_ALIGNMENT'
  160 |  fl_addr = ROUND_DOWN(start_addr, CONFIG_DISK_FLASH_ERASE_ALIGNMENT);
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from <command-line>:
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:162:38: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  162 |  if (flash_erase(flash_dev, fl_addr, CONFIG_DISK_ERASE_BLOCK_SIZE)
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:27:4: note: in definition of macro 'GET_NUM_BLOCK'
   27 |  ((total_size + block_size - 1) / block_size)
      |    ^~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:168:28: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  168 |  num_write = GET_NUM_BLOCK(CONFIG_DISK_ERASE_BLOCK_SIZE,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:27:45: error: expected expression before ')' token
   27 |  ((total_size + block_size - 1) / block_size)
      |                                             ^
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:168:14: note: in expansion of macro 'GET_NUM_BLOCK'
  168 |  num_write = GET_NUM_BLOCK(CONFIG_DISK_ERASE_BLOCK_SIZE,
      |              ^~~~~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:173:34: error: expected expression before ')' token
  173 |     CONFIG_DISK_FLASH_MAX_RW_SIZE) != 0) {
      |                                  ^
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:177:43: error: expected expression before ';' token
  177 |   fl_addr += CONFIG_DISK_FLASH_MAX_RW_SIZE;
      |                                           ^
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:178:39: error: expected expression before ';' token
  178 |   src += CONFIG_DISK_FLASH_MAX_RW_SIZE;
      |                                       ^
In file included from <command-line>:
C:/ncs/v1.9.1/zephyr/drivers/disk/flashdisk.c: In function 'disk_flash_access_write':
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:12:43: error: invalid suffix "x" on integer constant
   12 | #define CONFIG_DISK_FLASH_ERASE_ALIGNMENT 0x
      |                                           ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:195:17: note: in expansion of macro 'CONFIG_DISK_FLASH_ERASE_ALIGNMENT'
  195 |  if (fl_addr & (CONFIG_DISK_FLASH_ERASE_ALIGNMENT - 1)) {
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:200:25: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  200 |   block_bnd = fl_addr + CONFIG_DISK_ERASE_BLOCK_SIZE;
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:201:29: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  201 |   block_bnd = block_bnd & ~(CONFIG_DISK_ERASE_BLOCK_SIZE - 1);
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:30:3: note: in definition of macro 'GET_SIZE_TO_BOUNDARY'
   30 |  (block_size - (start & (block_size - 1)))
      |   ^~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:212:7: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  212 |       CONFIG_DISK_ERASE_BLOCK_SIZE);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:30:26: note: in definition of macro 'GET_SIZE_TO_BOUNDARY'
   30 |  (block_size - (start & (block_size - 1)))
      |                          ^~~~~~~~~~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:212:7: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  212 |       CONFIG_DISK_ERASE_BLOCK_SIZE);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from <command-line>:
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:228:19: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  228 |   if (remaining < CONFIG_DISK_ERASE_BLOCK_SIZE) {
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:232:36: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  232 |   rc = update_flash_block(fl_addr, CONFIG_DISK_ERASE_BLOCK_SIZE,
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:238:14: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  238 |   fl_addr += CONFIG_DISK_ERASE_BLOCK_SIZE;
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:239:16: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  239 |   remaining -= CONFIG_DISK_ERASE_BLOCK_SIZE;
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:240:11: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  240 |   buff += CONFIG_DISK_ERASE_BLOCK_SIZE;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v1.9.1/zephyr/drivers/disk/flashdisk.c: In function 'disk_flash_access_ioctl':
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:10:33: error: invalid suffix "x" on integer constant
   10 | #define CONFIG_DISK_VOLUME_SIZE 0x
      |                                 ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:259:23: note: in expansion of macro 'CONFIG_DISK_VOLUME_SIZE'
  259 |   *(uint32_t *)buff = CONFIG_DISK_VOLUME_SIZE / SECTOR_SIZE;
      |                       ^~~~~~~~~~~~~~~~~~~~~~~
C:\ncsapps\test\mass\build\zephyr\include\generated\autoconf.h:13:38: error: invalid suffix "x" on integer constant
   13 | #define CONFIG_DISK_ERASE_BLOCK_SIZE 0x
      |                                      ^~
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:265:23: note: in expansion of macro 'CONFIG_DISK_ERASE_BLOCK_SIZE'
  265 |   *(uint32_t *)buff = CONFIG_DISK_ERASE_BLOCK_SIZE / SECTOR_SIZE;
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
At top level:
C:\ncs\v1.9.1\zephyr\drivers\disk\flashdisk.c:22:29: warning: 'read_copy_buf' defined but not used [-Wunused-variable]
   22 | static uint8_t __aligned(4) read_copy_buf[CONFIG_DISK_ERASE_BLOCK_SIZE];
      |                             ^~~~~~~~~~~~~
[59/195] Building C object zephyr/subsys/fs/CMakeFiles/subsys__fs.dir/fat_fs.c.obj
[60/195] Building C object zephyr/soc/arm/nordic_nrf/nrf52/CMakeFiles/soc__arm__nordic_nrf__nrf52.dir/soc.c.obj
[61/195] Building C object zephyr/soc/arm/nordic_nrf/nrf52/CMakeFiles/soc__arm__nordic_nrf__nrf52.dir/power.c.obj
[62/195] Linking C static library zephyr\lib\libc\minimal\liblib__libc__minimal.a
[63/195] Building C object zephyr/subsys/fs/CMakeFiles/subsys__fs.dir/fs_impl.c.obj
[64/195] Linking C static library zephyr\lib\posix\liblib__posix.a
[65/195] Building C object zephyr/drivers/console/CMakeFiles/drivers__console.dir/uart_console.c.obj
[66/195] Building C object zephyr/drivers/clock_control/CMakeFiles/drivers__clock_control.dir/clock_control_nrf.c.obj
[67/195] Building C object zephyr/drivers/hwinfo/CMakeFiles/drivers__hwinfo.dir/hwinfo_nrf.c.obj
[68/195] Building C object zephyr/drivers/hwinfo/CMakeFiles/drivers__hwinfo.dir/hwinfo_weak_impl.c.obj
[69/195] Building C object zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_nrfx.c.obj
[70/195] Building C object zephyr/subsys/fs/CMakeFiles/subsys__fs.dir/fs.c.obj
[71/195] Building C object zephyr/drivers/usb/device/CMakeFiles/drivers__usb__device.dir/usb_dc_nrfx.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'c:\ncs\v1.9.1\toolchain\opt\bin\cmake.EXE' --build 'c:\ncsapps\test\mass\build'

I suppose that the matter lies in the Kconfig file which configure the application for the QSPI flash:

config USB_DEVICE_PID
	default USB_PID_MASS_SAMPLE

config APP_WIPE_STORAGE
	bool "Option to clear the flash area before mounting"
	help
	  Use this to force an existing file system to be created.

choice
	prompt "Storage and file system type used by the application"
	default APP_MSC_STORAGE_NONE
	help
	  Specify the type of storage and file system.

config APP_MSC_STORAGE_NONE
	bool "Use RAM disk as block device"
	imply DISK_DRIVER_RAM

config APP_MSC_STORAGE_RAM
	bool "Use RAM disk and FAT file system"
	imply DISK_DRIVER_RAM
	imply FILE_SYSTEM
	imply FAT_FILESYSTEM_ELM

config APP_MSC_STORAGE_FLASH_FATFS
	bool "Use FLASH disk and FAT file system"
	imply DISK_DRIVER_FLASH
	imply FILE_SYSTEM
	imply FAT_FILESYSTEM_ELM

config APP_MSC_STORAGE_FLASH_LITTLEFS
	bool "Use FLASH disk and LittleFS"
	imply DISK_DRIVER_FLASH
	imply FILE_SYSTEM
	imply FILE_SYSTEM_LITTLEFS

config APP_MSC_STORAGE_SDCARD
	bool "Use SDHC and FAT file system"
	imply DISK_DRIVER_SDMMC
	imply FILE_SYSTEM
	imply FAT_FILESYSTEM_ELM

endchoice

config DISK_RAM_VOLUME_SIZE
	default 32 if APP_MSC_STORAGE_NONE

config MASS_STORAGE_DISK_NAME
	default "NAND" if DISK_DRIVER_FLASH
	default "RAM" if DISK_DRIVER_RAM
	default "SD" if DISK_DRIVER_SDMMC

if DISK_DRIVER_FLASH

config FLASH_MAP
	default y

config FLASH_PAGE_LAYOUT
	default y

config DISK_FLASH_START
	default 0x0

config FLASH_LOG_LEVEL
	default 3

DT_COMPAT_QSPI_NOR := nordic,qspi-nor

config NORDIC_QSPI_NOR
	default $(dt_compat_enabled,$(DT_COMPAT_QSPI_NOR))

if NORDIC_QSPI_NOR

config NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE
	default 4096

config DISK_FLASH_DEV_NAME
	default "MX25R64" if "$(dt_nodelabel_enabled,mx25r64)"
	default "GD25Q16" if "$(dt_nodelabel_enabled,gd25q16)"

config DISK_VOLUME_SIZE
	default 0x20000

config DISK_FLASH_MAX_RW_SIZE
	default 4096

config DISK_FLASH_ERASE_ALIGNMENT
	default 0x1000

config DISK_ERASE_BLOCK_SIZE
	default 0x1000

endif # NORDIC_QSPI_NOR

endif # DISK_DRIVER_FLASH

source "Kconfig.zephyr"

So I thought to add theese lines

if JEDEC_SPI_NOR

config NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE
	default 4096

config DISK_FLASH_DEV_NAME
	default "W25Q64FV" if "$(dt_nodelabel_enabled,w25q64fv)"

config DISK_VOLUME_SIZE
	default 0x20000

config DISK_FLASH_MAX_RW_SIZE
	default 4096

config DISK_FLASH_ERASE_ALIGNMENT
	default 0x1000

config DISK_ERASE_BLOCK_SIZE
	default 0x1000

endif # JEDEC_SPI_NOR

But I have strong doubt on the NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE entry which is hardly linked to the QSPI.

Without making it too long, am I on the right way? Is it possible to use the sample with any external flash device, SPI or QSPI? Can you give me some suggestions?

I have another importan question. I asked and read on this forum about the flash memory support in the NCS and someone responsed me that the NCS supports only QSPI NOR flash memory and not NAND. But I didn't understand if I can use every SPI flash device, both NOR or NAND, or not. All the helps I can find on the web are about old SDK that I know to be deeply different form the new NCS.

  • Hi Andrea

    It should be possible to use your SPI NOR device by using the "jedec,spi-nor" driver, like you do in your overlay. 

    The circuitdojo_feather_nrf9160 board is doing something similar (see here), as it has a W25Q32JV flash device (should be comparable to the one you are using). 

    I was able to get the mass example to build by using your overlay, setting CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y in the project configuration file, and by removing the "if NORDIC_QSPI_NOR" and corresponding "endif" in the Kconfig file. 

    The NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE configuration is not used by the SPI NOR driver, and you should be able to just remove this from the Kconfig file. 

    I asked and read on this forum about the flash memory support in the NCS and someone responsed me that the NCS supports only QSPI NOR flash memory and not NAND.

    The QSPI interface in the nRF devices supports the NOR instruction set only, not the instructions used by NAND devices, and this is the main reason there is no support for NAND devices in NCS. 

    NAND devices require a more complex driver as you can not access data as easily as for NOR devices, and you need algorithms for error correction since NAND devices are inherently less reliable. 

    Over SPI it is technically possible to access NAND devices (if the NAND device supports SPI), but you would need a driver for it. 

    Best regards
    Torbjørn

Related