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

Using Flash during Softdevice

Hi,

I am trying to store a buffer which i collect from ble connection. I have tried sd_flash functions first. I could not found any examples so page number or addresses might be wrong.

So i tried to test it with very easy code. These lines are in main function after all service and other Initializations.

uint32_t test_buffer = 1;
uint32_t test_buffer2 = 0;

sd_flash_page_erase(0);
sd_flash_write((uint32_t *)0, &test_buffer, 1);

memcpy(&test_buffer2, (uint32_t *)0x3e000, 4);

Neither erase or write is working. 

// where can i found the document about pages to erase and write ?

So i tried flash_fstorage example

static void nus_data_handler(ble_nus_evt_t * p_evt)
{
  uint8_t temp_buffer[50] = {0};
  uint32_t test_buffer;
  uint32_t ab = 2;

    ret_code_t rc;

  if (p_evt->type == BLE_NUS_EVT_RX_DATA)
  {
    memcpy(temp_buffer, p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    temp_buffer[p_evt->params.rx_data.length] = '\0';
    NRF_LOG_INFO("%s", temp_buffer);
    if(memcmp(temp_buffer, "123", 3) == 0)
    {
     // passkey_len = p_evt->params.rx_data.length - 3;
      NRF_LOG_INFO("Writing \"%x\" to flash.", ab);
      rc = nrf_fstorage_write(&fstorage, 0x3e100, &ab, sizeof(ab), NULL);
      APP_ERROR_CHECK(rc);

      wait_for_flash_ready(&fstorage);
      NRF_LOG_INFO("Done.");
      memcpy(&test_buffer, (uint32_t *)0x3e100, sizeof(test_buffer));
      NRF_LOG_INFO("%x", test_buffer);
    }
    /*else if(memcmp(p_evt->params.rx_data.p_data, "", ) == 0)
    {
    
    }*/
  }
}

But device can not even any log. I did everything according to the example. If i commenct out rc = nrf_fstorage_write(&fstorage, 0x3e100, &ab, sizeof(ab), NULL); i get all logs.

Parents Reply Children
Related