Flash Read Issue in NRF52

Hi All,

In Flash read am facing one issue .

Am writing some data to Flash and trying to read back, But when I read back I get some corrupted data or am not able to read in Flash .Am using this code to test flash read timings in Heart rate Sensor example in 11.0.0.2 alpha SDK with NRF52 DK . Here is my code snippet :

**// flash write**

    pg_size = NRF_FICR->CODEPAGESIZE;
    pg_num  = NRF_FICR->CODESIZE - 1;  // Use last page in flash
    addr = (uint32_t *)(pg_size * pg_num);
    printf("Page Size %d\r\n",pg_size);  // it is 4096 
    flash_page_erase(addr);
    printf("before flash write\r\n");
    for(i=0;i<4096;){
			i=i+4;
                        flash_word_write(addr,(uint32_t)'1');
                        ++addr;
    }
    printf("After flash write\r\n");

**// flash read**


   addr = (uint32_t *)(pg_size * pg_num); 

   for(i=0;i<4096;){
 
    addr++;

     printf("flash data:%d %c \r\n",i,*addr);

     i=i+4;

  }

First 32 (i=32) are coming properly but after that some random prints are coming , Am I doing anything wrong ??

I tried memcpy also that to have the same issue ,

  • Can you post the code for functions flash_page_erase and flash_word_write

  • Thanks for your quick response ................... !!

    static void flash_word_write(uint32_t * address, uint32_t value)
    {
        // Turn on flash write enable and wait until the NVMC is ready:
        NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
    
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
        {
            // Do nothing.
        }
    
        *address = value;
    
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
        {
            // Do nothing.
        }
    
        // Turn off flash write enable and wait until the NVMC is ready:
        NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
    
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
        {
            // Do nothing.
        }
    }
    
    static void flash_page_erase(uint32_t * page_address)
    {
        // Turn on flash erase enable and wait until the NVMC is ready:
        NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos);
    
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
        {
            // Do nothing.
        }
    
        // Erase page:
        NRF_NVMC->ERASEPAGE = (uint32_t)page_address;
    
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
        {
            // Do nothing.
        }
    
        // Turn off flash erase enable and wait until the NVMC is ready:
        NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
    
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
        {
            // Do nothing.
        }
    }
    
  • I see absolutely nothing wrong in your code except that in the last for loop where you are printing addr, you should increment addr after the printf.

    for(i=0;i<4096;){
         printf("flash data:%d %c \r\n",i,*addr);
        addr++;
         i=i+4;
      }
    

    Is softdevice enabled while you are doing this?

  • Yes Soft Device is enabled , am using s132 soft device . Am writing the Data before ble_stack_init() and reading after initialising services and connection parameters , and then reading .(When am reading device is neither advertising nor connected to any central, Only Initialisation is done)

    Hi, and I saw in documet that addres to read need to be word aligned, How can I ensure my address is word aligned ..

  • Hi Aryan,

    I saw below comments in one of your post that helped me fix the issue,

    Try to increase the value for UART_RX_BUF_SIZE and UART_TX_BUF_SIZE to a greater value so that fifo library has more space to buffer. I am not sure if this will solve the problem, but it will at least rule out insufficient buffer problem.

    But still I have one question , actually I am trying to print character by character but how this is affected by UART_TX_BUF_SIZE ...... If I need to have more logs do I need to increase the buffer still ? DOes this buffer will also consume my RAM?

    Thanks for your support !!

Related