hi, i made ble app with nRF51822 (s110), sdk 6.1.0
and i put this code after a pstorage_store() function to wait finishing of this function.
uint32_t err_code, count;
do {
app_sched_execute();
err_code = pstorage_access_status_get(&count);
APP_ERROR_CHECK(err_code);
} while(count != 0);
but, my code is stuck in this loop. also I added scheduler_init function.
now, i can't find out how can fix this problem. please help. thanks:)
--- Edit ---
-
on_ble_evt:
case BLE_GAP_EVT_DISCONNECTED: dfu_state = (((*(volatile unsigned char *)(get_block_db() + FLASH_BLOCK_DFU_OFFSET)) == APP_DFU) ? false : true); m_conn_handle = BLE_CONN_HANDLE_INVALID; err_code = ble_store(); APP_ERROR_CHECK(err_code); nrf_gpio_pin_set(LED_0); do { app_sched_execute(); err_code = pstorage_access_status_get(&count); APP_ERROR_CHECK(err_code); } while (count != 0); nrf_gpio_pin_clear(LED_0); application_timers_stop(); if (!dfu_state) { advertising_start(); } else { err_code = sd_power_gpregret_clr(0xFF); APP_ERROR_CHECK(err_code); err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); APP_ERROR_CHECK(err_code); sd_nvic_SystemReset(); } break;
-
ble_store() and ble_clear()
uint32_t ble_store(void) { ble_clear(); uint32_t err_code; err_code = pstorage_store(&m_flash_handle, (uint8_t *)m_block_db, FLASH_BLOCK_SIZE * sizeof(uint8_t), 0); return err_code; } uint32_t ble_clear(void) { return pstorage_clear(&m_flash_handle, (FLASH_BLOCK_SIZE * sizeof(uint8_t))); }
Thank you Nikita. This is my code before the loop.
first, clear pstorage.
second, store new value to pstorage.
third, wait finishing of the pstorage operation before advertising start.
Isn't this procedure correct?