Can only mount and write in the address range from 0x00 -> 0x0200000(2mb) on w25q128jv

I'm writing a wav file from the nrf52840 board to the nor flash w25q128jv with a capacity of 16mb but it seems that I can only operate on the first 2mb, even when dividing the partition, if the starting address is over 2mb, the file mount will fail, and if starting from 0x00, the file can only be written to about 2mb and then I will encounter "file write error (-22)". This is my overlay, do I have any problems with my configuration? i am stuck with it for a long time hope someone can save me from this mess

overlay :

&spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";
    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
    clock-frequency = <8000000>;
    mx25r6435f: w25q128jv@0 {
        compatible = "jedec,spi-nor";
        reg = <0>;
        spi-max-frequency = <8000000>;
        status = "okay";
        size = <0x1000000>;  // 16MB
        jedec-id = [ ef 40 18  ]; // mã JEDEC của W25Q128JV
        has-dpd;
        t-enter-dpd = <10000>;
        t-exit-dpd = <30000>;
    };
};
&mx25r6435f {

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

        lfs1_part: partition@0 {
            label = "lfs1_storage";
            // only 8MB for lfs1(mount error -22)
            reg = <0x800000 0x800000>;
            // 16MB and mount success but if write more than 2mb will "file write error -5"
            // reg = <0x000000 0x1000000>;
        };
    };
};

mount config : 

static struct fs_littlefs lfs1_data = {
    .cfg =
        {
            // .alignment = 4,
            .read_size = 256,
            .prog_size = 256,
            .cache_size = 256,
            .lookahead_size = 16,
            .block_size = THE_FS_BLOCK_SIZE,   // 4096
            .block_count = THE_FS_BLOCK_COUNT, // 2048
            .block_cycles = 512,               // Use default value
        },
};

static struct fs_mount_t lfs_mnt = {
    .type = FS_LITTLEFS,
    .mnt_point = "/lfs1",
    .fs_data = &lfs1_data,
    .flags = 0,
    .storage_dev = (void *)FLASH_AREA_ID(lfs1_storage),
};

Parents
  • Hi Tai, 
    I'm sorry for the late reply. 

    I think I may know what's wrong here. The size of the SPI flash is count in mega bit :) 
    You can see the name of your flash is w25q128jv. 
    So the size in mx25r6435f: w25q128jv@0 {  should not be 

    size = <0x1000000> 


    Instead it should be 
    size = <134217728>;
    or 
    size = <0x8000000>;

    This explains why you can not access anything above 2MB because 2MB = 16 Mbit . You were setting the size of your flash to 16Mb instead of 128Mb (16MB).

Reply
  • Hi Tai, 
    I'm sorry for the late reply. 

    I think I may know what's wrong here. The size of the SPI flash is count in mega bit :) 
    You can see the name of your flash is w25q128jv. 
    So the size in mx25r6435f: w25q128jv@0 {  should not be 

    size = <0x1000000> 


    Instead it should be 
    size = <134217728>;
    or 
    size = <0x8000000>;

    This explains why you can not access anything above 2MB because 2MB = 16 Mbit . You were setting the size of your flash to 16Mb instead of 128Mb (16MB).

Children
Related