0

I am doing a project where I want to write some info to the MT25Q (MT25QL512ABB1EW9-0SIT) flash device from Micron Technology. But when I try to write and read from the first few pages (0-13) I get trash data back. I thought there might be a protected area in the flash so I checked the value of the corresponding bits in the status register and the value corresponds to none of the sectors being protected. Plus none of possible ranges for protected sector correspond to this value either. I am using zephyr-os which supports the flash device. Here is my code:

#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;
}

For the the first 15 iterations of the loop I read back some garbage string. And afterwards it works as expected. The device is byte-writeable.

Can someone help me understand why this is happening ? I hope I posted all the required info but just in case:

total_pages = 256 myflash.size = 131072

acevans
  • 13
  • 4
  • Have you checked the return values of all your lines in the loop? I assume the errno of the first problem will be more useful that just observing the garbage strings. – EdmCoff Nov 02 '20 at 23:09
  • @EdmCoff I did. Returns a zero (success) as long as i is between 0 and 255. – acevans Nov 02 '20 at 23:51
  • All 3 commands (flash_get_page_info_by_idx, flash_write, flash_read) in the loop return 0? – EdmCoff Nov 03 '20 at 15:39
  • Yeah. All 3 of them returned a 0 for every iteration of the loop. And I miswrote. On the 15 iteration (i = 14) I can read the string "test" from the flash. When I write to page index 0, I get "P @". After that it is always an empty string until i = 14 or greater. – acevans Nov 03 '20 at 17:16

0 Answers0