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

Writing Data to Flash without Pstorage module

Hello Guys,

I am newbie to nrf51822 programming. Currently using nrf51822 (raytac's MDBT40) with S130, SDK11. I am programming the nrf51822 using arduino IDE using this github repo: github.com/.../arduino-nRF5

I want to store data such that even if I update the application, the data should not get erase. There are two options : UICR or flash. I tried using customer register, but it cannot be rewritten unless entire memory is erased. Based on memory map of nrf51822 (infocenter.nordicsemi.com/.../bledfu_memory.html , I can write data to upper part of flash just below the bootloader at page address: 0x3C000. Since NVMC has restricted use (infocenter.nordicsemi.com/index.jsp so I using SD API ( sd_flash_page_erase(60); sd_flash_write(addrloc,dataloc, 8);

When I am printing data at location: printd.printIntDataln(*(uint32_t )addr); printd.printIntDataln((uint32_t *)patwr); Output is : "-1" Data is not getting written to location: 0x3c000. Am I doing something wrong? Is the above mentioned method correct.

complete code snippet I am trying:

    uint32_t patwr=0x0FF0;
     uint32_t *addrloc;
     const uint32_t *dataloc;
     addr = (uint32_t) 0x3C000; //(uint32_t *)(pg_size * pg_num);
     addrloc = &addr;
     dataloc = &patwr;
     sd_flash_page_erase(60);
     sd_flash_write(addrloc,dataloc, 8);


Another try:

pg_size = NRF_FICR->CODEPAGESIZE;
 pg_num  = NRF_FICR->CODESIZE - 5;  // Use last page in flash
  addr = (uint32_t *)(pg_size * pg_num);
 dataloc = &patwr;
 
    sd_flash_page_erase(pg_num);
    /* addr points to the first byte in the last page */
    sd_flash_write(addr, dataloc,  pg_size / sizeof(uint32_t));

 patrd = (uint8_t)*(addr-1);


  printd.printIntDataln(pg_size);
   printd.printIntDataln(pg_num);
  printd.printIntDataln(patrd);
Related