数据是先放在0x20000,0x21000是备份区,0x22000是修改区
static void timer_cb(void){ // Disable HW RST on P0_0 so it can be used as SPI MOSI. GPIO_Disable_HW_Reset(); int8_t ret; uint32_t bytes_read; uint32_t bytes_written; uint8_t data_write[4] = { 0 }; ret = spi_flash_block_erase(0x20000, SPI_FLASH_OP_SE);// ret = spi_flash_read_data(data_write, 0x20000, 4, &bytes_read);// ȡ ret = spi_flash_block_erase(0x22000, SPI_FLASH_OP_SE);// ret = spi_flash_write_data(data_write, 0x22000, 4, &bytes_written);// // Reduce power consumption by putting flash into sleep mode */ spi_flash_power_down();
// Re-enable HW reset input (must be disabled if/when further operation on // external flash are performed) - must set as input first! GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_0, INPUT_PULLDOWN, PID_GPIO, false); GPIO_Enable_HW_Reset();
/* Restart the timer */ timer_id = app_easy_timer(100, timer_cb); //}
void user_app_init(void){ // Disable HW RST on P0_0 so it can be used as SPI MOSI. GPIO_Disable_HW_Reset(); int8_t ret; uint32_t bytes_read; ret = spi_flash_read_data(val, 0x20000, 1, &bytes_read);// ȡ if(val[0]==0xFF)//flashȫ { uint32_t bytes_written; uint8_t data_write[101][4] = { 0 }; ret = spi_flash_block_erase(0x20000, SPI_FLASH_OP_SE);// for(uint8_t i=0;i<101;i++) convert_to_8bit(NTC[i],i,data_write,false);// ȡԭʼ ret = spi_flash_write_data((uint8_t*)data_write, 0x20000, 404, &bytes_written);// ¹ ret = spi_flash_read_data(val, 0x20000, 404, &bytes_read);// ȡ ret = spi_flash_block_erase(0x21000, SPI_FLASH_OP_SE);// ret = spi_flash_write_data(val, 0x21000, 404, &bytes_written);// ± } // Reduce power consumption by putting flash into sleep mode */ spi_flash_power_down();
// Re-enable HW reset input (must be disabled if/when further operation on // external flash are performed) - must set as input first! GPIO_ConfigurePin(GPIO_PORT_0, GPIO_PIN_0, INPUT_PULLDOWN, PID_GPIO, false); GPIO_Enable_HW_Reset(); app_param_update_request_timer_used = EASY_TIMER_INVALID_TIMER; my_led_state = false; // Initialize Manufacturer Specific Data mnf_data_init();
// Initialize Advertising and Scan Response Data memcpy(stored_adv_data, USER_ADVERTISE_DATA, USER_ADVERTISE_DATA_LEN); stored_adv_data_len = USER_ADVERTISE_DATA_LEN; memcpy(stored_scan_rsp_data, USER_ADVERTISE_SCAN_RESPONSE_DATA, USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN); stored_scan_rsp_data_len = USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN; default_app_on_init();}