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

how to use sd_flash_write? SDK13

I want to write at the end of memory ROM data in address 0x7FFFF

uint8_t tst_arr[1] = {6};
sd_flash_write((uint32_t*)0x7FFFF, (uint32_t*) &tst_arr, 1);

Is it correct?

But if I made it, in a memory watch I can't see any changes from 0xFF to my data (6).

Parents
  • No you cannot do it like this, flash writes should be 32-bit aligned. So if you want to write 8-bits to address 0x7FFFF then you should read 24-bits from address 0x7FFFC, concatenate it with your 8-bits and write resulting 32-bits back to address 0x7FFFC. Alternatively you can skip reading and put 0xFFFFFF at the beginning if you are sure that flash is erased before your write (or if you simply don't care about these preceding 3 bytes).

  • Address for writing must be dividable modulo 4 without any reminder. E.g. 0x7FFFC / 4 = 131,071 + 0 while your suggested 0x7FFFB / 4 = 131,070 + 3. So 0x7FFFC is the right address (0x7FFFF is only the last offset in the flash memory, not the end).

    When it comes to erasing the memory it works with flash technology only page by page so you need to erase whole last 4kB (on nRF51 it was 1kB). Again offset can be easily computed by taking any offset in that page and doing modulo 4096 (so address of last page is 0x7F000).

Reply
  • Address for writing must be dividable modulo 4 without any reminder. E.g. 0x7FFFC / 4 = 131,071 + 0 while your suggested 0x7FFFB / 4 = 131,070 + 3. So 0x7FFFC is the right address (0x7FFFF is only the last offset in the flash memory, not the end).

    When it comes to erasing the memory it works with flash technology only page by page so you need to erase whole last 4kB (on nRF51 it was 1kB). Again offset can be easily computed by taking any offset in that page and doing modulo 4096 (so address of last page is 0x7F000).

Children
No Data
Related