littlefs not mount to external flash winbond w25q256

am trying to mount little fs example with my external flash  winbond w25q256  but my nrf52840 board taking internal memory and am using  qspi 

it get automount and writing in  internal memory (mx25r64) and this is my overlay
i have tried with little fs example

/ {
aliases {
qspi-flash0 = &w25q256;
ext-flash = &w25q256;
};

chosen {
zephyr,flash-controller = &w25q256;
};

fstab {
compatible = "zephyr,fstab";
lfs1: lfs1 {
compatible = "zephyr,fstab,littlefs";
mount-point = "/lfs";
partition = <&lfs1_part>;
automount;
read-size = <16>;
prog-size = <16>;
cache-size = <64>;
lookahead-size = <32>;
block-cycles = <512>;
};
};
};

/delete-node/ &storage_partition;
/delete-node/ &mx25r64;

&qspi {
status = "okay";
pinctrl-0 = <&qspi_custom>;
pinctrl-1 = <&qspi_sleep_custom>;
pinctrl-names = "default", "sleep";

w25q256: w25q256@0 {
compatible = "nordic,qspi-nor";
reg = <0>;
size = <DT_SIZE_M(32)>;
sck-frequency = <8000000>;
writeoc = "pp4o";
readoc = "read4io";

jedec-id = [ef 40 19];
has-dpd;
t-enter-dpd = <3000>;
t-exit-dpd = <30000>;

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

/* Raw flash area for test writes (0-2MB) */
test_partition: partition@0 {
label = "test-area";
reg = <0x00000000 DT_SIZE_M(2)>;
};

/* LittleFS partition (2MB-4MB) */
lfs1_part: partition@200000 {
label = "littlefs-storage";
reg = <0x00200000 DT_SIZE_M(2)>;
};

/* Reserve remaining space for future use (4MB-32MB) */
storage_partition: partition@400000 {
label = "storage";
reg = <0x00400000 DT_SIZE_M(28)>;
};
};
};
};

&pinctrl {
qspi_custom: qspi_custom {
group1 {
psels = <NRF_PSEL(QSPI_SCK, 0, 19)>,
<NRF_PSEL(QSPI_IO0, 0, 14)>,
<NRF_PSEL(QSPI_IO1, 0, 23)>,
<NRF_PSEL(QSPI_IO2, 0, 11)>,
<NRF_PSEL(QSPI_IO3, 1, 0)>,
<NRF_PSEL(QSPI_CSN, 0, 16)>;
nordic,drive-mode = <NRF_DRIVE_H0H1>;
};
};

qspi_sleep_custom: qspi_sleep_custom {
group1 {
psels = <NRF_PSEL(QSPI_SCK, 0, 19)>,
<NRF_PSEL(QSPI_IO0, 0, 14)>,
<NRF_PSEL(QSPI_IO1, 0, 23)>,
<NRF_PSEL(QSPI_IO2, 0, 11)>,
<NRF_PSEL(QSPI_IO3, 1, 0)>,
<NRF_PSEL(QSPI_CSN, 0, 16)>;
low-power-enable;
};
};
};
prj.conf
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3

# Enable flash subsystem
CONFIG_FLASH=y

# Enable QSPI NOR flash driver
CONFIG_SPI=y
CONFIG_NORDIC_QSPI_NOR=y

# Enable flash page layout
CONFIG_FLASH_PAGE_LAYOUT=y

# Increase stack sizes for continuous operations
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Enable Nordic specific configurations
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16

# Optimize for reliability
CONFIG_NORDIC_QSPI_NOR_INIT_PRIORITY=80

# Debug options
CONFIG_DEBUG=y
CONFIG_DEBUG_INFO=y

# Optimize for continuous operation
CONFIG_SIZE_OPTIMIZATIONS=y

# Increase logging buffers
CONFIG_LOG_BUFFER_SIZE=4096
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=2048

# Enable file system support
CONFIG_FILE_SYSTEM=y

# Enable LittleFS
CONFIG_FILE_SYSTEM_LITTLEFS=y

# Enable filesystem formatting support
CONFIG_FILE_SYSTEM_MKFS=y

# LittleFS configuration
CONFIG_FS_LITTLEFS_NUM_FILES=10
CONFIG_FS_LITTLEFS_NUM_DIRS=5
CONFIG_FS_LITTLEFS_CACHE_SIZE=4096
CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE=32
CONFIG_FS_LITTLEFS_BLOCK_CYCLES=512
CONFIG_FS_LITTLEFS_FMP_DEV=y

# Flash map support for LittleFS
CONFIG_FLASH_MAP=y

# Increase heap for filesystem operations
CONFIG_HEAP_MEM_POOL_SIZE=16384

# Remove problematic POSIX configurations that cause build errors
# CONFIG_POSIX_API=n

# Additional memory for LittleFS operations
CONFIG_IDLE_STACK_SIZE=1024
Parents
  • Hello,

    Thank you for attaching this. For future references, please use the insert -> code functionality to make it easier to review the contents of your reply (such as I've edited your reply to show):

    Is this the sample you've based your application on?

    There should be a sample that you can use directly for the nrf52840dk with the qspi external flash overlay set up https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.overlay which should work out of the box if you add a pm_static.yml as well as modify the overlay to use your winbound external flash instead of the mx25

    Kind regards,
    Andreas

  • #include <stdio.h>
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/fs/fs.h>
    #include <zephyr/fs/littlefs.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/storage/flash_map.h>
    #include <zephyr/drivers/flash.h>
    
    
    LOG_MODULE_REGISTER(main);
    
    #define MAX_PATH_LEN 255
    #define DATA_BLOCK_SIZE 406
    #define WRITE_INTERVAL_MS 1000  // 1 second
    #define MAX_FILE_SIZE_MB 10     // Very conservative 10MB limit per file
    #define MAX_TOTAL_USAGE_MB 25   // Stop writing when 25MB total is used
    #define MAX_FILE_SIZE_BYTES (MAX_FILE_SIZE_MB * 1024 * 1024)
    #define MAX_TOTAL_USAGE_BYTES (MAX_TOTAL_USAGE_MB * 1024 * 1024)
    
    static uint8_t data_buffer[DATA_BLOCK_SIZE];
    static uint32_t write_counter = 0;
    static uint32_t total_bytes_written = 0;
    static uint32_t current_file_size = 0;
    
    static void generate_data_pattern(uint8_t *buffer, uint32_t sequence_num)
    {
    	// Create a header with metadata (16 bytes)
    	struct data_header {
    		uint32_t sequence;      // 4 bytes - sequence number
    		uint64_t timestamp;     // 8 bytes - system uptime
    		uint32_t checksum;      // 4 bytes - simple checksum
    	} __packed;
    
    	struct data_header *header = (struct data_header *)buffer;
    	
    	// Fill header
    	header->sequence = sequence_num;
    	header->timestamp = k_uptime_get();
    	
    	// Fill remaining 390 bytes with pattern
    	uint8_t *data_section = buffer + sizeof(struct data_header);
    	uint16_t remaining_bytes = DATA_BLOCK_SIZE - sizeof(struct data_header);
    	
    	// Create pattern: repeating sequence with variations
    	for (int i = 0; i < remaining_bytes; i++) {
    		if (i % 16 == 0) {
    			// Every 16th byte: sequence-dependent value
    			data_section[i] = (sequence_num + i) & 0xFF;
    		} else if (i % 8 == 0) {
    			// Every 8th byte: timestamp-dependent value
    			data_section[i] = (header->timestamp >> (i % 32)) & 0xFF;
    		} else {
    			// Other bytes: mixed pattern
    			data_section[i] = (0x55 ^ (i & 0xFF) ^ (sequence_num & 0xFF));
    		}
    	}
    	
    	// Calculate simple checksum (sum of all data bytes)
    	uint32_t checksum = 0;
    	for (int i = sizeof(struct data_header); i < DATA_BLOCK_SIZE; i++) {
    		checksum += buffer[i];
    	}
    	header->checksum = checksum;
    }
    static int write_406_bytes_continuous(char *fname, struct fs_mount_t *mp)
    {
        struct fs_file_t file;
        int rc, ret;
        struct fs_statvfs sbuf;
        struct fs_dirent entry;
    
        // Get current file size before writing
        rc = fs_stat(fname, &entry);
        if (rc == 0) {
            current_file_size = entry.size;  // Update with actual file size
        } else if (rc != -ENOENT) {
            LOG_ERR("Failed to stat file %s: %d", fname, rc);
            return rc;
        }
    
        // Check total usage limit FIRST
        if (total_bytes_written > MAX_TOTAL_USAGE_BYTES) {
            LOG_ERR("Total usage limit reached (%u MB) - stopping all writes", MAX_TOTAL_USAGE_MB);
            return -ENOSPC;
        }
    
        // Check file size limit BEFORE writing
        if (current_file_size + DATA_BLOCK_SIZE > MAX_FILE_SIZE_BYTES) {
            LOG_WRN("File size limit reached (%u MB) - need new file", MAX_FILE_SIZE_MB);
            return -EFBIG;
        }
    
        // Rest of function remains the same...
        fs_file_t_init(&file);
        
        rc = fs_open(&file, fname, FS_O_CREATE | FS_O_APPEND | FS_O_WRITE);
        if (rc < 0) {
            LOG_ERR("FAIL: open %s: %d", fname, rc);
            return rc;
        }
    
        generate_data_pattern(data_buffer, write_counter);
    
        rc = fs_write(&file, data_buffer, DATA_BLOCK_SIZE);
        if (rc < 0) {
            LOG_ERR("FAIL: write %s: %d", fname, rc);
            goto out;
        }
    
        if (rc != DATA_BLOCK_SIZE) {
            LOG_WRN("Partial write: expected %d, wrote %d bytes", DATA_BLOCK_SIZE, rc);
        }
    
        total_bytes_written += rc;
        current_file_size += rc;
        
        // Improved logging with better formatting
        LOG_PRINTK("Write #%u: %d bytes (File: %u KB, Total: %u KB = %.2f MB)\n", 
                   write_counter, rc, current_file_size / 1024, 
                   total_bytes_written / 1024, (float)total_bytes_written / (1024.0 * 1024.0));
    
    out:
        ret = fs_close(&file);
        if (ret < 0) {
            LOG_ERR("FAIL: close %s: %d", fname, ret);
            return ret;
        }
    
        return (rc < 0 ? rc : 0);
    }
    
    // static int write_406_bytes_continuous(char *fname, struct fs_mount_t *mp)
    // {
    // 	struct fs_file_t file;
    // 	int rc, ret;
    // 	struct fs_statvfs sbuf;
    
    // 	// Check total usage limit FIRST
    // 	if (total_bytes_written > MAX_TOTAL_USAGE_BYTES) {
    // 		LOG_ERR("Total usage limit reached (%u MB) - stopping all writes", MAX_TOTAL_USAGE_MB);
    // 		return -ENOSPC;
    // 	}
    
    // 	// Check file size limit BEFORE writing
    // 	if (current_file_size + DATA_BLOCK_SIZE > MAX_FILE_SIZE_BYTES) {
    // 		LOG_WRN("File size limit reached (%u MB) - need new file", MAX_FILE_SIZE_MB);
    // 		return -EFBIG;  // File too big error
    // 	}
    
    // 	// Check available space before writing
    // 	rc = fs_statvfs(mp->mnt_point, &sbuf);
    // 	if (rc == 0) {
    // 		uint32_t used_kb = ((sbuf.f_blocks - sbuf.f_bfree) * sbuf.f_frsize) / 1024;
    // 		if (used_kb > (MAX_TOTAL_USAGE_MB * 1024)) {
    // 			LOG_ERR("Usage limit exceeded: %u KB used (max %u KB)", 
    // 			        used_kb, MAX_TOTAL_USAGE_MB * 1024);
    // 			return -ENOSPC;
    // 		}
    // 	}
    
    // 	fs_file_t_init(&file);
    	
    // 	// Open file in append mode to continuously add data
    // 	rc = fs_open(&file, fname, FS_O_CREATE | FS_O_APPEND | FS_O_WRITE);
    // 	if (rc < 0)
    // 	{
    // 		LOG_ERR("FAIL: open %s: %d", fname, rc);
    // 		return rc;
    // 	}
    
    // 	// Generate the 406-byte data pattern
    // 	generate_data_pattern(data_buffer, write_counter);
    
    // 	// Write exactly 406 bytes
    // 	rc = fs_write(&file, data_buffer, DATA_BLOCK_SIZE);
    // 	if (rc < 0)
    // 	{
    // 		LOG_ERR("FAIL: write %s: %d", fname, rc);
    // 		goto out;
    // 	}
    
    // 	if (rc != DATA_BLOCK_SIZE) {
    // 		LOG_WRN("Partial write: expected %d, wrote %d bytes", DATA_BLOCK_SIZE, rc);
    // 	}
    
    // 	total_bytes_written += rc;
    // 	current_file_size += rc;
    	
    // 	LOG_PRINTK("Write #%u: %d bytes (File: %u KB, Total: %u MB)\n", 
    // 		   write_counter, rc, current_file_size / 1024, 
    // 		   total_bytes_written / (1024 * 1024));
    
    // out:
    // 	ret = fs_close(&file);
    // 	if (ret < 0)
    // 	{
    // 		LOG_ERR("FAIL: close %s: %d", fname, ret);
    // 		return ret;
    // 	}
    
    // 	return (rc < 0 ? rc : 0);
    // }
    
    static int lsdir(const char *path)
    {
    	int res;
    	struct fs_dir_t dirp;
    	static struct fs_dirent entry;
    
    	fs_dir_t_init(&dirp);
    
    	res = fs_opendir(&dirp, path);
    	if (res)
    	{
    		LOG_ERR("Error opening dir %s [%d]\n", path, res);
    		return res;
    	}
    
    	LOG_PRINTK("\nListing dir %s ...\n", path);
    	for (;;)
    	{
    		res = fs_readdir(&dirp, &entry);
    
    		if (res || entry.name[0] == 0)
    		{
    			if (res < 0)
    			{
    				LOG_ERR("Error reading dir [%d]\n", res);
    			}
    			break;
    		}
    
    		if (entry.type == FS_DIR_ENTRY_DIR)
    		{
    			LOG_PRINTK("[DIR ] %s\n", entry.name);
    		}
    		else
    		{
    			LOG_PRINTK("[FILE] %s (size = %zu)\n",
    					   entry.name, entry.size);
    		}
    	}
    
    	fs_closedir(&dirp);
    	return res;
    }
    
    #ifdef CONFIG_APP_LITTLEFS_STORAGE_FLASH
    static int littlefs_flash_erase(unsigned int id)
    {
        const struct flash_area *pfa;
        int rc;
    
        rc = flash_area_open(id, &pfa);
        if (rc < 0) {
            LOG_ERR("FAIL: unable to find flash area %u: %d\n", id, rc);
            return rc;
        }
    
        LOG_PRINTK("=== FLASH AREA INFO ===\n");
        LOG_PRINTK("Area ID: %u\n", id);
        LOG_PRINTK("Offset: 0x%x\n", (unsigned int)pfa->fa_off);
        LOG_PRINTK("Size: %u bytes (%u KB)\n", 
                   (unsigned int)pfa->fa_size, (unsigned int)pfa->fa_size / 1024);
        LOG_PRINTK("Device: %s\n", pfa->fa_dev->name);
        
        if (strstr(pfa->fa_dev->name, "w25q") != NULL ||
            strstr(pfa->fa_dev->name, "qspi") != NULL) {
            LOG_PRINTK("âś“ Using EXTERNAL QSPI flash\n");
        } else {
            LOG_PRINTK("âš  Using INTERNAL flash\n");
        }
        LOG_PRINTK("=====================\n");
    
        if (IS_ENABLED(CONFIG_APP_WIPE_STORAGE)) {
            rc = flash_area_flatten(pfa, 0, pfa->fa_size);
            LOG_PRINTK("Erasing flash area ... %d\n", rc);
        }
    	LOG_PRINTK("flash area flatten ... \n");
        flash_area_close(pfa);
        return rc;
    }
    
    #define PARTITION_NODE DT_NODELABEL(lfs1)
    
    #if DT_NODE_EXISTS(PARTITION_NODE)
    FS_FSTAB_DECLARE_ENTRY(PARTITION_NODE);	
    #else
    FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
    static struct fs_mount_t lfs_storage_mnt = {
    	.type = FS_LITTLEFS,
    	.fs_data = &storage,
    	.storage_dev = (void *)PM_LITTLEFS_STORAGE_ID,
    	.mnt_point = "/lfs",
    };
    #endif
    
    struct fs_mount_t *mountpoint =
    #if DT_NODE_EXISTS(PARTITION_NODE)
    	&FS_FSTAB_ENTRY(PARTITION_NODE)
    #else
    	&lfs_storage_mnt
    #endif
    	;
    
    static int littlefs_mount(struct fs_mount_t *mp)
    {
    	int rc;
    
    	rc = littlefs_flash_erase((uintptr_t)mp->storage_dev);
    	if (rc < 0)
    	{
    		return rc;
    	}
        
        LOG_PRINTK("storage device ID to: %u\n", (unsigned int)(uintptr_t)mp->storage_dev);
    
    #if !DT_NODE_EXISTS(PARTITION_NODE) || \
    	!(FSTAB_ENTRY_DT_MOUNT_FLAGS(PARTITION_NODE) & FS_MOUNT_FLAG_AUTOMOUNT)
    	rc = fs_mount(mp);
    	if (rc < 0)
    	{
    		LOG_PRINTK("FAIL: mount id %" PRIuPTR " at %s: %d\n",
    				   (uintptr_t)mp->storage_dev, mp->mnt_point, rc);
    		return rc;
    	}
    	LOG_PRINTK("manual mounted\n" );
    	LOG_PRINTK("%s mount: %d\n", mp->mnt_point, rc);
    #else
    	LOG_PRINTK("%s automounted\n", mp->mnt_point);
    #endif
    
    	return 0;
    }
    #endif
    
    static void print_flash_info(void)
    {
        const struct device *flash_dev;
        const struct device *qspi_dev;
    
        flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
        if (device_is_ready(flash_dev)) {
            LOG_PRINTK("Flash controller: %s\n", flash_dev->name);
            LOG_PRINTK("Flash device ready: %s\n", device_is_ready(flash_dev) ? "YES" : "NO");
        }
    
        qspi_dev = DEVICE_DT_GET(DT_NODELABEL(w25q256));
        if (device_is_ready(qspi_dev)) {
            LOG_PRINTK("QSPI device: %s\n", qspi_dev->name);
            LOG_PRINTK("QSPI device ready: %s\n", device_is_ready(qspi_dev) ? "YES" : "NO");
        }
    
        if (strstr(flash_dev->name, "w25q") != NULL ||
            strstr(flash_dev->name, "qspi") != NULL) {
            LOG_PRINTK("âś“ Using external QSPI flash\n");
        } else {
            LOG_PRINTK("Using internal flash\n");
        }
    }
    
    static void print_filesystem_stats(void)
    {
        struct fs_statvfs sbuf;
        int rc;
    
        rc = fs_statvfs(mountpoint->mnt_point, &sbuf);
        if (rc < 0) {
            LOG_ERR("FAIL: statvfs: %d\n", rc);
            return;
        }
    
        uint32_t total_kb = (sbuf.f_blocks * sbuf.f_frsize) / 1024;
        uint32_t free_kb = (sbuf.f_bfree * sbuf.f_frsize) / 1024;
        uint32_t used_kb = total_kb - free_kb;
    
        LOG_PRINTK("=== FILESYSTEM STATS ===\n");
        LOG_PRINTK("Total: %u KB, Used: %u KB, Free: %u KB\n", 
                   total_kb, used_kb, free_kb);
        LOG_PRINTK("Data written: %u KB (%u MB)\n",
                   total_bytes_written / 1024, total_bytes_written / (1024 * 1024));
        LOG_PRINTK("========================\n");
    }
    
    
    
    int main(void)
    {
    	char fname_data[MAX_PATH_LEN];
    	int rc;
    	uint32_t file_number = 1;
    
    	LOG_PRINTK("=== 406 Byte Continuous Write Demo ===\n");
    	LOG_PRINTK("Writing %d bytes to external flash every %d ms\n", 
    	           DATA_BLOCK_SIZE, WRITE_INTERVAL_MS);
    	LOG_PRINTK("Max file size: %d MB, Max total usage: %d MB\n", 
    	           MAX_FILE_SIZE_MB, MAX_TOTAL_USAGE_MB);
    	LOG_PRINTK("Using mount point: %s\n", mountpoint->mnt_point);
    	LOG_PRINTK("Storage device ID: %u\n", (unsigned int)(uintptr_t)mountpoint->storage_dev);
    	
    	print_flash_info();
    	
    	rc = littlefs_mount(mountpoint);
    	if (rc < 0)
    	{
    		LOG_ERR("Failed to mount LittleFS: %d\n", rc);
    		return 0;
    	}
    
    	// Setup initial file name
    	snprintf(fname_data, sizeof(fname_data), "%s/data406_%03u.bin", 
    	         mountpoint->mnt_point, file_number);
    
    	// Delete existing files to start fresh
    	LOG_PRINTK("Cleaning up old files...\n");
    	for (int i = 1; i <= 10; i++) {
    		char temp_fname[MAX_PATH_LEN];
    		snprintf(temp_fname, sizeof(temp_fname), "%s/data406_%03u.bin", 
    		         mountpoint->mnt_point, i);
    		// fs_unlink(temp_fname);  // Remove old files (ignore errors)
    	}
    
    	// Initial file system status
    	print_filesystem_stats();
    	lsdir(mountpoint->mnt_point);
    
    	LOG_PRINTK("\n=== Starting continuous 406-byte write loop ===\n");
    	LOG_PRINTK("Current file: %s\n", fname_data);
    
    	// Continuous write loop
    	while (1) {
    		write_counter++;
    		
    		LOG_PRINTK("\n--- Write cycle #%u ---\n", write_counter);
    
    		// Write exactly 406 bytes to data file
    		rc = write_406_bytes_continuous(fname_data, mountpoint);
    		
    		if (rc == -EFBIG) {
    			// File size limit reached - create new file
    			file_number++;
    			snprintf(fname_data, sizeof(fname_data), "%s/data406_%03u.bin", 
    			         mountpoint->mnt_point, file_number);
    			current_file_size = 0;  // Reset file size counter
    			LOG_PRINTK("Rotating to new file: %s\n", fname_data);
    			
    			// Try writing to new file
    			rc = write_406_bytes_continuous(fname_data, mountpoint);
    		}
    		
    		if (rc == -ENOSPC) {
    			LOG_ERR("Storage space exhausted - stopping writes");
    			break;
    		}
    		
    		if (rc < 0) {
    			LOG_ERR("Failed to write 406 bytes: %d\n", rc);
    			// Continue trying instead of stopping
    		}
    
    		// Print filesystem stats every 100 writes
    		if (write_counter % 100 == 0) {
    			print_filesystem_stats();
    			lsdir(mountpoint->mnt_point);
    		}
    
    		// Calculate and show data rate every 10 writes
    		if (write_counter % 10 == 0) {
    			uint64_t uptime_ms = k_uptime_get();
    			if (uptime_ms > 0) {
    				uint32_t bytes_per_sec = (total_bytes_written * 1000ULL) / uptime_ms;
    				LOG_PRINTK("Data rate: %u bytes/sec (%u KB/sec)\n", 
    				           bytes_per_sec, bytes_per_sec / 1024);
    			}
    		}
    
    		// Wait for next write cycle
    		k_msleep(WRITE_INTERVAL_MS);
    	}
    
    	LOG_PRINTK("Write loop terminated\n");
    	return 0;
    }


    #
    # Copyright (c) 2019 Peter Bigot Consulting, LLC
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    # Optionally force the file system to be recreated
    # CONFIG_APP_WIPE_STORAGE=y
    
    # fs_dirent structures are big.
    CONFIG_MAIN_STACK_SIZE=4096
    
    # Let __ASSERT do its job
    CONFIG_DEBUG=y
    
    CONFIG_LOG=y
    CONFIG_LOG_MODE_MINIMAL=y
    
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    CONFIG_NORDIC_QSPI_NOR=y
    
    CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=65536
    CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16
    CONFIG_APP_LITTLEFS_STORAGE_FLASH=y
    
    
    
    CONFIG_LOG_DEFAULT_LEVEL=3
    CONFIG_UART_CONSOLE=n
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_APP_WIPE_STORAGE=n
    
    CONFIG_PARTITION_MANAGER_ENABLED=y
    # CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
    


    / {
    aliases {
    qspi-flash0 = &w25q256;
    };
    
    chosen {
    // zephyr,flash-controller = &w25q256;
    // zephyr,flash = &w25q256;
    nordic,pm-ext-flash = &w25q256;
    
    };
    
    // fstab {
    // compatible = "zephyr,fstab";
    // lfs1: lfs1 {
    // compatible = "zephyr,fstab,littlefs";
    // mount-point = "/lfs";
    // partition = <&lfs1_part>;
    // // automount;
    // read-size = <16>;
    // prog-size = <16>;
    // cache-size = <64>;
    // lookahead-size = <32>;
    // block-cycles = <512>;
    // };
    // };
    };
    
    
    /delete-node/ &storage_partition;
    /delete-node/ &mx25r64;
    
    &qspi {
    status = "okay";
    pinctrl-0 = <&qspi_custom>;
    pinctrl-1 = <&qspi_sleep_custom>;
    pinctrl-names = "default", "sleep";
    
    w25q256: w25q256ve@0 {
    compatible = "nordic,qspi-nor";
    reg = <0>;
    size = <DT_SIZE_M(32)>;
    sck-frequency = <32000000>;
    writeoc = "pp4o";
    readoc = "read4io";
    
    jedec-id = [ ef 40 19 ];
    has-dpd;
    t-enter-dpd = <3000>;
    t-exit-dpd = <30000>;
    // address-size-32;
    // partitions {
    // compatible = "fixed-partitions";
    // #address-cells = <1>;
    // #size-cells = <1>;
    
    // /* LittleFS partition (0-4MB) - CHANGED: Larger partition */
    // lfs1_part: partition@0 {
    // label = "littlefs_storage";
    // reg = <0x00000000 DT_SIZE_M(4)>;
    // };
    
    // /* Test area (4MB-8MB) */
    // test_partition: partition@400000 {
    // label = "test_area";
    // reg = <0x00400000 DT_SIZE_M(4)>;
    // };
    
    // external_storage_partition: partition@800000 {
    // label = "external_storage";
    // reg = <0x00800000 DT_SIZE_M(24)>;
    // };
    // };
    };
    };
    
    &pinctrl {
    qspi_custom: qspi_custom {
    group1 {
    psels = <NRF_PSEL(QSPI_SCK, 0, 19)>,
    <NRF_PSEL(QSPI_IO0, 0, 14)>,
    <NRF_PSEL(QSPI_IO1, 0, 23)>,
    <NRF_PSEL(QSPI_IO2, 0, 11)>,
    <NRF_PSEL(QSPI_IO3, 1, 0)>,
    <NRF_PSEL(QSPI_CSN, 0, 16)>;
    nordic,drive-mode = <NRF_DRIVE_H0H1>;
    };
    };
    
    qspi_sleep_custom: qspi_sleep_custom {
    group1 {
    psels = <NRF_PSEL(QSPI_SCK, 0, 19)>,
    <NRF_PSEL(QSPI_IO0, 0, 14)>,
    <NRF_PSEL(QSPI_IO1, 0, 23)>,
    <NRF_PSEL(QSPI_IO2, 0, 11)>,
    <NRF_PSEL(QSPI_IO3, 1, 0)>,
    <NRF_PSEL(QSPI_CSN, 0, 16)>;
    low-power-enable;
    };
    };
    };
    


    pm_static.yml 
    littlefs_storage:
    address: 0x0
    size: 0x00400000
    device: w25q256ve@0
    region: external_flash


     if i changed 4mb size to 8mb size in pm_static.yml ,it through error, if i gave 4mbit doesnt through any error it write in flash
    
    00> *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    00> *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    00> === 406 Byte Continuous Write Demo ===
    00> Writing 406 bytes to external flash every 1000 ms
    00> Max file size: 10 MB, Max total usage: 25 MB
    00> Using mount point: /lfs
    00> Storage device ID: 1
    00> Flash controller: flash-controller@4001e000
    00> Flash device ready: YES
    00> QSPI device: w25q256ve@0
    00> QSPI device ready: YES
    00> Using internal flash
    00> === FLASH AREA INFO ===
    00> Area ID: 1
    00> Offset: 0x0
    00> Size: 8388608 bytes (8192 KB)
    00> Device: w25q256ve@0
    00> ✓ Using EXTERNAL QSPI flash
    00> =====================
    00> flash area flatten ...
    00> storage device ID to: 1
    00> I: LittleFS version 2.9, disk version 2.1
    00> I: FS at w25q256ve@0:0x0 is 128 0x10000-byte blocks with 512 cycle
    00> I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    00> E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:4531: Invalid block count (64 != 128)
    00> W: can't mount (LFS -22); formatting
    00> I: /lfs mounted
    00> manual mounted
    00> /lfs mount: 0
    00> Cleaning up old files...
    00> === FILESYSTEM STATS ===
    00> Total: 8192 KB, Used: 128 KB, Free: 8064 KB
    00> Data writ
    00> --- Write cycle #5 ---
    00> E: erase error: address or size exceeds expected values.Addr: 0x480000 size 65536
    00> E: file write error (-22)
    00> E: FAIL: write /lfs/data406_001.bin: -22
    00> E: Failed to write 406 bytes: -22
    00>
    00>
    00> --- Write cycle #6 ---
    00> E: erase error: address or size exceeds expected values.Addr: 0x490000 size 65536
    00> E: file write error (-22)
    00> E: FAIL: write /lfs/data406_001.bin: -22
    00> E: Failed to write 406 bytes: -22
    00>
    00>
    00> --- Write cycle #7 ---
    00> E: erase error: address or size exceeds expected values.Addr: 0x4a0000 size 65536
    00> E: file write error (-22)
    00> E: FAIL: write /lfs/data406_001.bin: -22
    00> E: Failed to write 406 bytes: -22
    00>
    00>
    00> --- Write cycle #8 ---
    00> E: erase error: address or size exceeds expected values.Addr: 0x4b0000 size 65536
    00> E: file write error (-22)
    00> E: FAIL: write /lfs/data406_001.bin: -22
    00> E: Failed to write 406 bytes: -22
    00>
    (Connection lost)
  • Hi,

    You're query is incomprehensive. Please use the insert code boxes that I mentioned. I've edited your reply yet again to use those.

    Your device initializes, but as the error states

    "Erase error: address or size exceeds expected values.Addr: 0x480000 size 65536"

    Seems to me that you are writing out of bounds.

    Kind regards,
    Andreas

Reply Children
No Data
Related