<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Issue Erasing Flash Area on QSPI Flash with LittleFS in Zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114107/issue-erasing-flash-area-on-qspi-flash-with-littlefs-in-zephyr</link><description>Hi, I&amp;#39;m working on a project using Zephyr with LittleFS mounted on a QSPI flash device. However, I&amp;#39;m encountering an issue when trying to erase the flash area. Here are the details: 
 System Configuration: MCU: nRF52840 (Seeed studio xiao ble) Zephyr</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 22 Aug 2024 10:38:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114107/issue-erasing-flash-area-on-qspi-flash-with-littlefs-in-zephyr" /><item><title>RE: Issue Erasing Flash Area on QSPI Flash with LittleFS in Zephyr</title><link>https://devzone.nordicsemi.com/thread/499342?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2024 10:38:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79f09eb5-389e-4bb4-9d14-96298b8b9c91</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please also note that flash devices like&amp;nbsp;p25q16h etc have certain specific erase sizes like 4KB, 32KB or so. You need to make sure that&amp;nbsp;pfa-&amp;gt;fa_off (the start address) and pfa-&amp;gt;fa_size (the size to erase) are aligned to this block size.&lt;/p&gt;
&lt;p&gt;-Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue Erasing Flash Area on QSPI Flash with LittleFS in Zephyr</title><link>https://devzone.nordicsemi.com/thread/499262?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2024 18:54:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cda17c08-28f8-4247-ac42-f69c49c5a898</guid><dc:creator>sina008</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/turboj"&gt;Turbo J&lt;/a&gt;&amp;nbsp;Thank you for your help. I fixed the size issue but I am still getting the same error.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:00.296,386] &amp;lt;inf&amp;gt; littlefs: littlefs partition at /lfs1
[00:00:00.296,417] &amp;lt;inf&amp;gt; littlefs: LittleFS version 2.5, disk version 2.0
[00:00:00.296,508] &amp;lt;inf&amp;gt; littlefs: FS at p25q16h@0:0x0 is 512 0x1000-byte blocks with 512 cycle
[00:00:00.296,508] &amp;lt;inf&amp;gt; littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
[00:00:00.296,997] &amp;lt;inf&amp;gt; littlefs: Automount /lfs1 succeeded
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
[00:00:00.297,058] &amp;lt;inf&amp;gt; main: Sample program to r/w files on littlefs

Area 0 at 0x0 on p25q16h@0 for 2097152 bytes
[00:00:00.297,119] &amp;lt;err&amp;gt; qspi_nor: erase error: address or size exceeds expected values.Addr: 0x0 size 2097152
[00:00:00.297,119] &amp;lt;err&amp;gt; main: Erasing flash area ... -22
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is how I mount the partition:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define PARTITION_NODE DT_NODELABEL(lfs1)

#if DT_NODE_EXISTS(PARTITION_NODE)
FS_FSTAB_DECLARE_ENTRY(PARTITION_NODE);
#else /* PARTITION_NODE */
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
static struct fs_mount_t lfs_storage_mnt = {
	.type = FS_LITTLEFS,
	.fs_data = &amp;amp;storage,
	// .storage_dev = (void *)FIXED_PARTITION_ID(lfs1_part),
    .storage_dev= (void*)FLASH_AREA_ID(littlefs_storage);
	.mnt_point = &amp;quot;/lfs1&amp;quot;,
};
#endif /* PARTITION_NODE */

	struct fs_mount_t *mountpoint =
#if DT_NODE_EXISTS(PARTITION_NODE)
		&amp;amp;FS_FSTAB_ENTRY(PARTITION_NODE)
#else
		&amp;amp;lfs_storage_mnt
#endif
		;

static int littlefs_mount(struct fs_mount_t *mp)
{
	int rc;

	rc = littlefs_flash_erase((uintptr_t)mp-&amp;gt;storage_dev);
	if (rc &amp;lt; 0) {
		return rc;
	}

	/* Do not mount if auto-mount has been enabled */
#if !DT_NODE_EXISTS(PARTITION_NODE) ||						\
	!(FSTAB_ENTRY_DT_MOUNT_FLAGS(PARTITION_NODE) &amp;amp; FS_MOUNT_FLAG_AUTOMOUNT)
	rc = fs_mount(mp);
	if (rc &amp;lt; 0) {
		LOG_PRINTK(&amp;quot;FAIL: mount id %&amp;quot; PRIuPTR &amp;quot; at %s: %d\n&amp;quot;,
		       (uintptr_t)mp-&amp;gt;storage_dev, mp-&amp;gt;mnt_point, rc);
		return rc;
	}
	LOG_PRINTK(&amp;quot;%s mount: %d\n&amp;quot;, mp-&amp;gt;mnt_point, rc);
#else
	LOG_PRINTK(&amp;quot;%s automounted\n&amp;quot;, mp-&amp;gt;mnt_point);
#endif

	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I modified the dts overlay as well since the partition label was the same as the board file definition:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/{
    chosen{
        nordic,pm-ext-flash=&amp;amp;p25q16h;
    };
};
/ {
    fstab {
        compatible = &amp;quot;zephyr,fstab&amp;quot;;
        lfs1: lfs1 {
            compatible = &amp;quot;zephyr,fstab,littlefs&amp;quot;;
            mount-point = &amp;quot;/lfs1&amp;quot;;
            partition = &amp;lt;&amp;amp;lfs1_part&amp;gt;;
            automount;
            read-size = &amp;lt;16&amp;gt;;
            prog-size = &amp;lt;16&amp;gt;;
            cache-size = &amp;lt;64&amp;gt;;
            lookahead-size = &amp;lt;32&amp;gt;;
            block-cycles = &amp;lt;512&amp;gt;;
        };
    };
};

&amp;amp;qspi {
    p25q16h: p25q16h@0 {
    partitions {
        compatible = &amp;quot;fixed-partitions&amp;quot;;
        #address-cells = &amp;lt;1&amp;gt;;
        #size-cells = &amp;lt;1&amp;gt;;

        lfs1_part: partition@0 {
            label = &amp;quot;littlefs_storage&amp;quot;;
            reg = &amp;lt;0x00000000 0x00200000&amp;gt;;  // 2 MiB partition for LittleFS
        };
    };

        size = &amp;lt;0x00200000&amp;gt;;
  };
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;These are the partitions from the board file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;qspi {
	status = &amp;quot;okay&amp;quot;;
	pinctrl-0 = &amp;lt;&amp;amp;qspi_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;qspi_sleep&amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
	p25q16h: p25q16h@0 {
		compatible = &amp;quot;nordic,qspi-nor&amp;quot;;
		reg = &amp;lt;0&amp;gt;;
		sck-frequency = &amp;lt;104000000&amp;gt;;
		quad-enable-requirements = &amp;quot;S2B1v1&amp;quot;;
		jedec-id = [85 60 15];
		sfdp-bfp = [
			e5 20 f1 ff  ff ff ff 00  44 eb 08 6b  08 3b 80 bb
			ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
			10 d8 08 81
		];
		size = &amp;lt;16777216&amp;gt;;
		has-dpd;
		t-enter-dpd = &amp;lt;3000&amp;gt;;
		t-exit-dpd = &amp;lt;8000&amp;gt;;
	};
};
&amp;amp;flash0 {
	partitions {
		compatible = &amp;quot;fixed-partitions&amp;quot;;
		#address-cells = &amp;lt;1&amp;gt;;
		#size-cells = &amp;lt;1&amp;gt;;

		sd_partition: partition@0 {
			label = &amp;quot;softdevice&amp;quot;;
			reg = &amp;lt;0x00000000 0x00027000&amp;gt;;
		};

		code_partition: partition@27000 {
			label = &amp;quot;code_partition&amp;quot;;
			reg = &amp;lt;0x00027000 0x000c5000&amp;gt;;
		};

		/*
		 * The flash starting at 0x000ec000 and ending at
		 * 0x000f3fff is reserved for use by the application.
		 *
		 * Storage partition will be used by FCB/LittleFS/NVS
		 * if enabled.
		 */
		storage_partition: partition@ec000 {
			label = &amp;quot;storage&amp;quot;;
			reg = &amp;lt;0x000ec000 0x00008000&amp;gt;;
		};

		boot_partition: partition@f4000 {
			label = &amp;quot;adafruit_boot&amp;quot;;
			reg = &amp;lt;0x000f4000 0x0000c000&amp;gt;;
		};
	};
};
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue Erasing Flash Area on QSPI Flash with LittleFS in Zephyr</title><link>https://devzone.nordicsemi.com/thread/499257?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2024 17:33:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcb2a9e6-356a-4dd5-b322-79c2e9aaddd7</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;That flash chip has 16 MBits or 2MBytes storage space. You are trying to erase 16MByte - obviously not possible.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>