NRF52832的FDS程式,參考非藍芽例程修改而來(需要增加DFU的基礎上只要增加如下程式即可解決)
阿新 • • 發佈:2020-09-09
/* Dummy configuration data. */ static configuration_t m_dummy_cfg = { .config1_on = false, .config2_on = true, .boot_count = 0x0, .device_name = "dummy", }; /* A record containing dummy configuration data. */ static fds_record_t const m_dummy_record = { .file_id = CONFIG_FILE, .key= CONFIG_REC_KEY, .data.p_data = &ucheck_v,//&m_dummy_cfg, /* The length of a record is always expressed in 4-byte units (words). */ .data.length_words = (sizeof(ucheck_v) + 3) / sizeof(uint32_t), }; /* Keep track of the progress of a delete_all operation. */ //static struct //{ // bool delete_next;//!< Delete next record. // bool pending; //!< Waiting for an fds FDS_EVT_DEL_RECORD event, to delete the next record. //} m_delete_all; void user_data_update(void) { ret_code_t rc; // NRF_LOG_INFO("Reading flash usage statistics..."); fds_stat_t stat = {0}; rc = fds_stat(&stat); APP_ERROR_CHECK(rc); NRF_LOG_INFO("Found %d valid records.", stat.valid_records); NRF_LOG_INFO("Found %d dirty records (ready to be garbage collected).", stat.dirty_records); fds_record_desc_t desc = {0}; fds_find_token_t tok = {0}; rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok); if (rc == FDS_SUCCESS) { /* A config file is in flash. Let's update it. */ fds_flash_record_t config = {0}; /* Open the record and read its contents. */ rc = fds_record_open(&desc, &config); APP_ERROR_CHECK(rc); /* Copy the configuration from flash into m_dummy_cfg. */ //memcpy(&ucheck_v, config.p_data, sizeof(check_V));//這裡是更新資料,所以不能把舊資料複製過來了 NRF_LOG_INFO("Config file found, updating boot count to %d.", ucheck_v.boot_count); /* Update boot count. */ ucheck_v.boot_count++; /* Close the record when done reading. */ rc = fds_record_close(&desc); APP_ERROR_CHECK(rc); /* Write the updated record to flash. */ rc = fds_record_update(&desc, &m_dummy_record); APP_ERROR_CHECK(rc); } else { /* System config not found; write a new one. */ NRF_LOG_INFO("Writing config file..."); rc = fds_record_write(&desc, &m_dummy_record); APP_ERROR_CHECK(rc); } //cli_start(); } void user_init_data_flash(void) { ret_code_t rc; fds_record_desc_t desc = {0}; fds_find_token_t tok = {0}; rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok); if (rc == FDS_SUCCESS) { /* A config file is in flash. Let's update it. */ fds_flash_record_t config = {0}; /* Open the record and read its contents. */ rc = fds_record_open(&desc, &config); APP_ERROR_CHECK(rc); /* Copy the configuration from flash into m_dummy_cfg. */ memcpy(&ucheck_v, config.p_data, sizeof(check_V)); NRF_LOG_INFO("Config file found, updating boot count to %d.", ucheck_v.boot_count); /* Update boot count. */ ucheck_v.boot_count++; /* Close the record when done reading. */ rc = fds_record_close(&desc); APP_ERROR_CHECK(rc); /* Write the updated record to flash. */ rc = fds_record_update(&desc, &m_dummy_record); APP_ERROR_CHECK(rc); } }
在增加了DFU之後的52832程式,只要增加如下程式就可以完成FDS的資料儲存