Iam implementing FATFS with USB mass storage on external flash(QSPI). it already having developed dfu in internal flash
********Overlay******* &qspi { status = "okay"; pinctrl-0 = <&qspi_default>; pinctrl-1 = <&qspi_sleep>; pinctrl-names = "default", "sleep"; p25q16h: p25q16h@0 { compatible = "nordic,qspi-nor"; reg = <0>; sck-frequency = <104000000>; quad-enable-requirements = "S2B1v1"; 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 ]; label = "qspi_flash"; // Optional size = <16777216>; //size is in bits has-dpd; t-enter-dpd = <3000>; t-exit-dpd = <8000>; partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; fatfs_part: partition@0 { label = "fatfs_storage"; reg = <0x00000000 0x00200000>; /* Start address and size = 2MB */ }; }; }; }; &flash0 { status = "okay"; partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; boot_partition: partition@0 { label = "mcuboot"; reg = <0x00000000 0x0000C000>; }; mcuboot_primary: partition@c000 { label = "image-0" ; //"mcuboot_primary"; reg = <0x0000C000 0x00076000>; }; mcuboot_secondary: partition@82000 { label = "image-1" ; //"mcuboot_secondary"; reg = <0x00082000 0x00076000>; }; /* * The flash starting at 0x000f8000 and ending at * 0x000fffff is reserved for use by the application. */ /* * Storage partition will be used by FCB/LittleFS/NVS * if enabled. */ storage_partition: partition@f8000 { label = "storage"; reg = <0x000f8000 0x00008000>; }; }; }; ***********pm_static.yaml************** fatfs_part: address: 0x00000000 size: 0x200000 device: p25q16h region: external_flash ******code************* static FATFS fat_fs; struct fs_file_t file; struct fs_dirent dirent; struct fs_mount_t fatfs_mnt = { .type = FS_FATFS, .fs_data = &fat_fs, .mnt_point = "/NAND", .storage_dev = (void *)FIXED_PARTITION_ID(fatfs_storage), }; int rc; rc = disk_access_init("FLASH"); if (rc != 0) { printf("Disk init failed (%d)\n", rc); } // Get disk status uint32_t sector_count, sector_size; rc = disk_access_ioctl("FLASH", DISK_IOCTL_GET_SECTOR_COUNT, §or_count); if (rc == 0) { printf("Sector count: %u,\n", sector_count); } else { printf("Failed to get sector count: %d\n", rc); } rc = disk_access_ioctl("FLASH", DISK_IOCTL_GET_SECTOR_SIZE, §or_size); if (rc == 0) { printf("Sector size: %u\n", sector_size); } else { printf("Failed to get sector size: %d\n", rc); } // Try to read first sector to verify disk access rc = disk_access_read("FLASH", test_buf, 0, 1); if (rc == 0) { printf("Disk read test successful\n"); } else { printf("Disk read test failed: %d\n", rc); //return 0; } rc = fs_mount(&fatfs_mnt); if (rc < 0) { printf("FATFS mount failed (%d), Attempting to format.\n", rc); // uintptr_t dev_id = (uintptr_t)FIXED_PARTITION_ID(fatfs_part); // rc = fs_mkfs(FS_FATFS, dev_id, NULL, 0); rc = fs_mkfs(FS_FATFS, "FLASH", NULL, 0); if (rc < 0) { printf("Format failed (%d)\n", rc); return 0; } rc = fs_mount(&fatfs_mnt); if (rc < 0) { printf("Mount failed after format (%d)\n", rc); return 0; } } printf("mount successfully....%s\n", fatfs_mnt.mnt_point);
***********build errors******************
D:/ncs/v2.9.0/nrf/include/flash_map_pm.h:47:22: error: 'PM_ext_fs_ID' undeclared here (not in a function) 47 | #define PM_ID(label) PM_##label##_ID | ^~~ D:/ncs/v2.9.0/nrf/include/flash_map_pm.h:52:35: note: in expansion of macro 'PM_ID' 52 | #define FIXED_PARTITION_ID(label) PM_ID(label) | ^~~~~ D:/FYZKS/Wearable_Steth/26_06_2025_WDS/src/pd_application.c:51:28: note: in expansion of macro 'FIXED_PARTITION_ID' 51 | .storage_dev = (void *)FIXED_PARTITION_ID(fatfs_part),