Hi there,
I wanted to change the advertising name while running DFU bootloader (secure_bootloader_ble_s132_pca10040), so I basically added what I found here:
static bool dfu_is_writing_name = false;
void ble_dfu_buttonless_on_sys_evt(uint32_t sys_evt, void * p_context);
/**@brief Define functions for async interface to set new advertisement name for DFU mode. */
NRF_SVCI_ASYNC_FUNC_DEFINE(NRF_DFU_SVCI_SET_ADV_NAME, nrf_dfu_set_adv_name, nrf_dfu_adv_name_t);
// Register SoC observer for the Buttonless Secure DFU service
NRF_SDH_SOC_OBSERVER(m_dfu_buttonless_soc_obs, BLE_DFU_SOC_OBSERVER_PRIO, ble_dfu_buttonless_on_sys_evt, NULL);
uint32_t nrf_dfu_svci_vector_table_set(void);
uint32_t nrf_dfu_svci_vector_table_unset(void);
void dfu_init()
{
nrf_dfu_svci_vector_table_set();
nrf_dfu_set_adv_name_init();
nrf_dfu_svci_vector_table_unset();
}
void ble_dfu_buttonless_on_sys_evt(uint32_t sys_evt, void * p_context)
{
if (sys_evt != NRF_EVT_FLASH_OPERATION_ERROR && sys_evt != NRF_EVT_FLASH_OPERATION_SUCCESS)
return;
if (!dfu_is_writing_name)
return;
dfu_is_writing_name = false;
if (nrf_dfu_set_adv_name_is_initialized())
{
uint32_t err_code = nrf_dfu_set_adv_name_on_sys_evt(sys_evt);
if (err_code == NRF_SUCCESS)
{
// reboot into DFU mode
}
}
}
void write_dfu_adv_name(const char* inName)
{
static nrf_dfu_adv_name_t dfuAdvName;
dfuAdvName.crc = 0xFFFFFFFF;
dfuAdvName.len = strlen(inName);
memcpy(dfuAdvName.name, inName, dfuAdvName.len);
dfuAdvName.name[dfuAdvName.len] = '\0';
dfu_is_writing_name = true;
uint32_t err_code = nrf_dfu_set_adv_name(&dfuAdvName);
if (err_code == NRF_SUCCESS)
{
dfu_is_writing_name = false;
}
}
But I keep getting NRF_ERROR_INVALID_STATE from nrf_dfu_set_adv_name (line 51).
Here's my main:
int main(void)
{
uint32_t ret_val;
dfu_init();
write_dfu_adv_name("test_name");
// Must happen before flash protection is applied, since it edits a protected page.
nrf_bootloader_mbr_addrs_populate();
// Protect MBR and bootloader code from being overwritten.
ret_val = nrf_bootloader_flash_protect(0, MBR_SIZE);
APP_ERROR_CHECK(ret_val);
ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE);
APP_ERROR_CHECK(ret_val);
(void) NRF_LOG_INIT(nrf_bootloader_dfu_timer_counter_get);
NRF_LOG_DEFAULT_BACKENDS_INIT();
bootloader_board_init();
NRF_LOG_INFO("Inside main");
ret_val = nrf_bootloader_init(dfu_observer);
APP_ERROR_CHECK(ret_val);
NRF_LOG_FLUSH();
nrf_bootloader_app_start();
NRF_LOG_ERROR("After main, should never be reached.");
NRF_LOG_FLUSH();
APP_ERROR_CHECK_BOOL(false);
}
Any guesses about what is happening?
Setup:
OS: Windows 10
IDE: Segger Embedded Studio for ARM V5.34
Hardware: BL652-SA-01-T/R
SDK version: nRF5_SDK_17.0.2_d674dde
SoftDevice: S132