Interfacing FAT file system into WinbondW25Q02 using SPI-nor driver

Greetings,

I have been trying to integrate file system into Winbond W25Q02 NOR storage, Initially I tested the hardware by interfacing SPI communication between nrf 5340 and winbond and I was able to read JEDEC id, write characters into various pages and read back from them, so hardware is NOT the problem. Now I saw that zephyr allows us to integrate file system and there is a library called SPI nor, which is heavily inspired by Winbond. Before jumping into my storage for testing file system, I tested a "Mass" sample which I found in nordic SDK. it follows QSPI protocol, and I was able to mount the mx25r64 storage, which is already present inside nrf dk. Now when I use the same code, with modifications for communication (instead of QSPI, I need SPI),I get the error saying JEDEC id 00 00 00  does not match my given id in the overlay i.e ef 70 22. I just edited prj.config and overlay file in the mass sample for this purpose and I am really not sure if I need to make any changes on main.c or spi-nor.c driver for this. 

This is my overlay file

/*
 * Copyright (c) 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */
// / {
// 	aliases {
// 		spi-flash0 = &winbond;
// 	};
// };
/* Disable conflicting buttons and UART */
&button2 {
	status = "disabled";
};

&button3 {
	status = "disabled";
};

&gpio_fwd {
	status = "disabled";
};

&pinctrl {
		spi_master_default: spi_master_default {
				group1 {
						psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
										<NRF_PSEL(SPIM_MOSI, 0, 9)>,
										<NRF_PSEL(SPIM_MISO, 0, 3)>;
				};
		};

		spi_master_sleep: spi_master_sleep {
				group1 {
						psels = <NRF_PSEL(SPIM_SCK, 0, 2)>,
										<NRF_PSEL(SPIM_MOSI, 0, 9)>,
										<NRF_PSEL(SPIM_MISO, 0, 3)>;
						low-power-enable;
				};
		};
};

&spi4 {
		compatible = "nordic,nrf-spim";
		pinctrl-0 = <&spi_master_default>;
		pinctrl-1 = <&spi_master_sleep>;
		pinctrl-names = "default", "sleep";
		cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;	
		status = "okay";
		winbond:winbondw25q02@0 {
			compatible = "jedec,spi-nor";
			reg = <0>;
	//      irq-gpios = <&gpio0 21 0>;
			spi-max-frequency = <32000000>;
			//label = "WINBOND";
			jedec-id = [ ef 70 22 ];
			size = < 0x10000000 >;
			has-dpd;
			// 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
		 	// ];
		};
};

/delete-node/ &storage_partition;

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

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

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

This is my prj.config file

CONFIG_STDOUT_CONSOLE=y

#USB related configs
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr MSC sample"
CONFIG_USB_DEVICE_PID=0x0008
CONFIG_LOG=y
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=n
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_FLASH_JESD216_API=y
CONFIG_FLASH_LOG_LEVEL_DBG=y
CONFIG_SPI_LOG_LEVEL_DBG=y
CONFIG_SPI_NRFX=y
CONFIG_SPI_ASYNC=y
CONFIG_SPI_SLAVE=y


CONFIG_SPI=y
#CONFIG_SPI_4=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_SPI_NOR_IDLE_IN_DPD=y

#FLASH Config ##############################################
CONFIG_DISK_ACCESS=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_FS_FATFS_LFN=y

CONFIG_SETTINGS_FS=y

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_LOG_LEVEL_ERR=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_DISK_DRIVER_FLASH=y

This is my terminal

*** Booting Zephyr OS build 28a3fca7da5c ***
[00:00:00.257,751] <err> flashdisk: Flash area 0 open error -19
[00:00:00.257,751] <err> usb_msc: Storage init ERROR !!!! - Aborting USB init
[00:00:00.257,781] <err> os: ***** BUS FAULT *****
[00:00:00.257,812] <err> os:   Precise data bus error
[00:00:00.257,812] <err> os:   BFAR Address: 0xef8008f3
[00:00:00.257,843] <err> os: r0/a1:  0x00000000  r1/a2:  0x00013384  r2/a3:  0x00000000
[00:00:00.257,843] <err> os: r3/a4:  0xef8008f3 r12/ip:  0xfffffffc r14/lr:  0x00000883
[00:00:00.257,873] <err> os:  xpsr:  0x69000000
[00:00:00.257,873] <err> os: Faulting instruction address (r15/pc): 0x0000f6c0
[00:00:00.257,904] <err> os: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0
[00:00:00.257,965] <err> os: Current thread: 0x20000b30 (unknown)
[00:00:00.257,110] <dbg> spi_nrfx_spim: spi_context_update_tx: tx buf/len (nil)/0
[00:00:00.257,110] <dbg> spi_nrfx_spim: finish_transaction: Transaction finished with status 0
--- 17 messages dropped ---
[00:00:00.257,141] <dbg> spi_nrfx_spim: spi_context_buffers_setup: tx_bufs 0x20005418 - rx_bufs 0x20005420 - 1
[00:00:00.257,171] <dbg> spi_nrfx_spim: spi_context_buffers_setup: current_tx 0x20005428 (2), current_rx 0x20005428 (2), tx buf/len 0x20005410/1, rx buf/len 0x20005410/1
[00:00:00.257,171] <dbg> spi_nrfx_spim: spi_context_update_tx: tx buf/len 0x20005478/3
[00:00:00.257,202] <dbg> spi_nrfx_spim: spi_context_update_rx: rx buf/len 0x20005478/3
[00:00:00.257,232] <dbg> spi_nrfx_spim: spi_context_update_tx: tx buf/len (nil)/0
[00:00:00.257,232] <dbg> spi_nrfx_spim: spi_context_update_rx: rx buf/len (nil)/0
[00:00:00.257,263] <dbg> spi_nrfx_spim: finish_transaction: Transaction finished with status 0
[00:00:00.257,293] <dbg> spi_nrfx_spim: spi_context_buffers_setup: tx_bufs 0x200053f8 - rx_bufs (nil) - 1
[00:00:00.257,293] <dbg> spi_nrfx_spim: spi_context_buffers_setup: current_tx 0x20005408 (1), current_rx (nil) (0), tx buf/len 0x200053f0/1, rx buf/len (nil)/0
[00:00:00.257,324] <dbg> spi_nrfx_spim: spi_context_update_tx: tx buf/len (nil)/0
[00:00:00.257,354] <dbg> spi_nrfx_spim: finish_transaction: Transaction finished with status 0
[00:00:00.257,385] <err> spi_nor: Device id 00 00 00 does not match config ef 70 22

file:///C:/Users/DELL/Desktop/datasheet/W25Q02JV_DTR_RevB_04192021-2329042.pdf

This is the link to winbond datasheet that I am using. Any help would be much appreciated!

Parents
  • Hi,

    The pins you've selected (P0.02 and P0.03) are among the few GPIOs are reserved for NFC. If you consult with the pin assignment in the product specification you can see which pins you can use for general purpose input that you can select yourself and which are reserved for others: https://docs.nordicsemi.com/bundle/ps_nrf5340/page/chapters/pin.html

    Try with for instance P0.07 and P0.08 instead (or any other available that you want to use)

    Kind regards,
    Andreas

  • Hi,

    Actually I am using Fanstel BT 40F which has nrf 5340 soc. I have tested that those two pins works fine as a GPIO. Like I mentioned above, I have done basic reading, writing and erasing using spi communication with this storage on those pins. It is the file system inplementation that I am not able to do.

    Regards,

    Barsha

  • Barsa said:

    However I used this 

    CONFIG_NFCT_PINS_AS_GPIOS=y

    That's also a valid solution! :) 

    Barsa said:
    Could you help me with this?

    I'll have a look. Could you verify if this is the device you're trying to set up? https://www.winbond.com/hq/product/code-storage-flash-memory/serial-nor-flash/?__locale=en&partNo=W25Q02NW_DTR 

    Discussing this out loud with you: The size parameter in your spi instance is given in bytes represented as int and the Winbounds size is 2 Gigabits. Have you validated that you've entered the correct size?

    Moving on to fault: I see the error is on "flashdisk": Is this corresponding to the msc_disc0 nand disc-name that you've created in the partition? I'm curious to where the NAND-partition comes in on the SPI-nor type winbound device. Could you expand on this?

    Barsa said:
    I am not able to see my storage as a USB device in my PC after i plug it in, I get this error and it reboots

    You'll get the stack overflow errors whenever your stack sizes are too small (which I assume you also find obvious, but stating it nonetheless), but finding out which stack that's too small might vary from fault to fault. In this case I believe it is your main stack that might bee too small, which you set to 2k in your prj.conf i.e CONFIG_MAIN_STACK_SIZE=2048. Try to set it to 4k or 8k and see if this removes the stack overflow issue,

    Kind regards,
    Andreas

  • Hi AHaug,

    This is the storage that I am using:

    About the size of my storage: 

    size = < 268435456 >;
    this is 256Mega Byte (2 giga bit converted into bytes)
    You mentioned error about flash disk: I know winbond is a NOR flash memory. But I have been using the usb mass example which is using mx25r64 storage: (which is also a serial NOR), so I took the same overlay that has been used on the sample code. Here is the overlay for mass sample:
    /*
     * 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>;
    		};
    	};
    };
    
    / {
    	msc_disk0 {
    		compatible = "zephyr,flash-disk";
    		partition = <&storage_partition>;
    		disk-name = "NAND";
    		cache-size = <4096>;
    	};
    };
    
    So I am a little confused here as they are using NAND as a label in their overlay. do I need to make any changes for serial NOR?
    When I increase stack size: I do not get the stack overflow error but i still get this:
      

  • Hi,

    Barsa said:

    About the size of my storage: 

    size = < 268435456 >;
    this is 256Mega Byte (2 giga bit converted into bytes)

    Perfect, I agree. 

    Barsa said:
    . But I have been using the usb mass example which is using mx25r64 storage

    Ah, that explains why there's a NAND partition listed in the dts. I'll have a closer look into that sample myself.

    Barsa said:
    When I increase stack size: I do not get the stack overflow error but i still get this:

    Great, then we only have to see why it's not recognized. First we need to verify that it's not because of your other hardware or lacking software setup

    1. J-link firmware version or USB cable:
      1. Have you checked with different USB cables? Micro usb's are cheap and tend to break making them effectively only usable for charging and not data transfer which may lead to "USB device not recognized". 
      2. Your J-Link version may be incorrect. Which version of Segger-JLink are you
    2. Do you see the same warning when testing other samples, or is it just the mas storage sample?
    3. This discussion is not directly relevant, but posting it here since it's a good discussion regarding the sample you're using: https://devzone.nordicsemi.com/f/nordic-q-a/98797/mass-example-with-external-flash-not-working-with-config_bootloader_mcuboot-y 

    Kind regards,
    Andreas

  • hinAhaug,

    I tried using different USB the problem still persists. I am using JLink Edu V10.10. Since the USB wasn't working, I tried using Bluetooth to read my stored data, but I realized that we use 

    CONFIG_DISK_DRIVER_FLASH=y to mount our storage and when I try to add CONFIG_BT=y in my prj.config, it gives me built error. I guess those two config doesn't go along with each other.
    so I am kind off stuck here. I can't use USB, neither bluetooth. 
    your help would be highly appreciated. 
  • Hi,

    Barsa said:
    I am using JLink Edu V10.10

    I was referring to the Segger J-link installation from this step: https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/installation/install_ncs.html#install_prerequisites 

    Barsa said:
    it gives me built error.

    I've been out of office the past 3 weeks. Could you state if you've resolved this issue in the other cases you've opened since this reply?

    Kind regards,
    Andras

Reply Children
Related