This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issues Reading from Flash

I am running flash_fstorage_example on the nRF52840 DK with SDK 15.0.0

I am having some problems with the example, as below:

1. When I run the example and use the shell, I can read 0xBADC0FFE from address 0x3e000 with command `read hex 3e000 4`.
I tried the command `write 3e000 DEADBEEF` but when I read again, I got a value 0x44 0x5 0x40 0x0, or 0x00400544. I read in other posts that writing to flash can only set bits to 0, and not 1 - so I also tried erasing with `erase 3e000 4`. This successfully erased all values to F. Then, I tried writing DEADBEEF and reading it again, but I get 0x44 0x45 0x41 0x44, or 0x44414544. How can I make sure that I'm reading and writing correctly from the shell with the example? 
2. Additionally, I tried to change the code in the project to read the flash after writing to it (before starting the command line process). After "hello world" is written to flash in the example, I added
uint32_t read_data;
NRF_LOG_INFO("Reading bad coffee from flash");
rc = nrf_fstorage_read(&fstorage, 0x3e000, &read_data, sizeof(read_data));
APP_ERROR_CHECK(rc);

wait_for_flash_ready(&fstorage);
NRF_LOG_INFO("Data: %x", read_data);
However, I don't see the second log message. In fact, even when running the example without modifications, I only see the last out of the following log messages printed out on the console
    NRF_LOG_INFO("Use 'read' to read bytes from the flash.");
    NRF_LOG_INFO("Use 'write' to write bytes to the flash.");
    NRF_LOG_INFO("Use 'erase' to erase flash pages.");
    NRF_LOG_INFO("Use 'flasharea' to print and configure the flash read boundaries.");
Is my above code the correct way to read from flash? If so, why can't I see any of the log messages?
Thank you.
Parents
  • Hello,

    It is correct as you say, you can only write from 1 to 0, and need to erase in between. 

    Try to write "write -h". It says that you write ASCII bytes to the flash. In hex values, the ASCII string DEADBEEF is 0x44:45:41:44:42:45:45:46. You can find the ASCII table e.g. here.

    If you write the commands:

    erase 0x3E000 1
    write 0x3E000 DEADBEEF
    read str 0x3E000 8

    It will print DEADBEEF, because it reads the string, and prints ascii symbols.

Reply
  • Hello,

    It is correct as you say, you can only write from 1 to 0, and need to erase in between. 

    Try to write "write -h". It says that you write ASCII bytes to the flash. In hex values, the ASCII string DEADBEEF is 0x44:45:41:44:42:45:45:46. You can find the ASCII table e.g. here.

    If you write the commands:

    erase 0x3E000 1
    write 0x3E000 DEADBEEF
    read str 0x3E000 8

    It will print DEADBEEF, because it reads the string, and prints ascii symbols.

Children
Related