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

How can I read bytes from flash?

developer.nordicsemi.com/.../a00935.html

The doc seems to provide only write functions. And, the flashwrite example doesn't show how to read from flash even after device rebooted. How can I read something later that has been stored in flash?

Parents
  • You do not need NVMC hardware or API to read the flash memory. Just read it like any other memory.

    for example, if you want to read 2 bytes of flash located at 0x21000 then the below code will do it

    #define STORAGE_ADR   0x21000
    uint16_t value = *(uint16_t *)ptr;
    

    or If you want to compare it with some thing then better would be to do like below

      if(*((uint16_t *)STORAGE_ADR) == 0xff)
      {
        do something;
      } 
    
Reply
  • You do not need NVMC hardware or API to read the flash memory. Just read it like any other memory.

    for example, if you want to read 2 bytes of flash located at 0x21000 then the below code will do it

    #define STORAGE_ADR   0x21000
    uint16_t value = *(uint16_t *)ptr;
    

    or If you want to compare it with some thing then better would be to do like below

      if(*((uint16_t *)STORAGE_ADR) == 0xff)
      {
        do something;
      } 
    
Children
Related