前几页写入Micron MT25Q闪存设备失败

时间:2020-11-02 19:59:01

标签: c embedded-linux zephyr-rtos

我正在做一个项目,我想向美光科技的MT25Q(MT25QL512ABB1EW9-0SIT)闪存设备写入一些信息。但是,当我尝试从前几页(0-13)进行读写时,我会得到垃圾数据。我以为闪存中可能有一个受保护的区域,所以我检查了状态寄存器中相应位的值,该值与任何受保护的扇区都不对应。另外,受保护扇区的任何可能范围都不与此值相对应。 我正在使用支持闪存设备的zephyr-os。这是我的代码:

#include "MT25Q.h"
#include <flash.h>

    struct device *dev = device_get_binding("MT25Q");
    struct flash_pages_info myflash;
    flash_get_page_info_by_idx(dev, 0, &myflash);
    char *test_line = malloc(5);
    char *buf = malloc(5);
    strcpy(test_line, "test");
    size_t page_count = flash_get_page_count(dev);
  
    flash_write_protection_set(dev, false);
    for(long i = 0; i < total_pages; i++) {
        returnval = flash_get_page_info_by_idx(dev, i, &myflash);
        flash_write(dev, myflash.start_offset, test_line, 5);
        flash_read(dev, myflash.start_offset, buf, 5);
        printk("%s\n", buf);
    }
    flash_write_protection_set(dev, true);
    free(buf);
    free(test_line);
    return 0;
}

对于循环的前15个迭代,我读了一些垃圾字符串。之后,它会按预期工作。该设备是字节可写的。

有人可以帮助我了解为什么会这样吗?我希望我发布了所有必需的信息,但以防万一:

总页数= 256 myflash.size = 131072

0 个答案:

没有答案