This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

save scan data in flash memory

Hi!

There are many questions about flash memory already.

But I could not find the question I wanted.

I want to save scan data to flash memory.

However, when you try to save the scan data, a system reset occurs.

Below is my code.


uint32_t * addr;
uint8_t    patwr;
uint8_t    patrd;
uint8_t    patold=0xFF;
uint32_t   i=0;
uint32_t   pg_size;
uint32_t   pg_num;

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 on_ble_evt(ble_evt_t * p_ble_evt) {

const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;

switch (p_ble_evt->header.evt_id)
{
    case BLE_GAP_EVT_ADV_REPORT:
    {
        const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
        const ble_gap_evt_scan_req_report_t * p_scan_report = &p_gap_evt->params.scan_req_report;
        

        for(int8_t i=0;i<BLE_GAP_ADV_MAX_SIZE;i++)
    {
	app_uart_put(p_adv_report->data[i]);

        }

        sd_ble_gap_scan_stop();
        patwr = p_adv_report->data[0];
        flash_word_write(addr,(uint32_t)patwr);


    }
    break; // BLE_GAP_EVT_ADV_REPORT
   default:
        break;
}   

}

int main(void) {

pg_size = NRF_FICR->CODEPAGESIZE;
pg_num  = NRF_FICR->CODESIZE - 1;  // Use last page in flash  

// Start address:
addr = (uint32_t *)(pg_size * pg_num);
  ble_scan_stack_init();
  sd_ble_gap_scan_start(&m_scan_params);

}


What's the problem? Please help me.

Thank you for your help all the time.

Related