Hello,
I am using a custom board NRF52382, Softdevice 132_v2.0, SDK 11. Two power supply options are given, battery and USB.
I tried to rewrite UICR register with two implementation
1st.
uint32_t err_code = sd_softdevice_disable();
APP_ERROR_CHECK(err_code);
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
nrf_delay_ms(100);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
nrf_delay_ms(100);
*(uint32_t *)0x100010E4 = var_register[0] ;
*(uint32_t *)0x100010E8 = var_register[1] ;
*(uint32_t *)0x100010EC = var_register[2] ;
*(uint32_t *)0x100010F0 = var_register[3] ;
nrf_delay_ms(100);
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NVIC_SystemReset();
2nd
uint32_t err_code = sd_softdevice_disable();
APP_ERROR_CHECK(err_code);
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos;
nrf_delay_ms(100);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NRF_NVMC->ERASEUICR = 1;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
nrf_delay_ms(100);
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
nrf_delay_ms(100);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
nrf_delay_ms(100);
*(uint32_t *)0x100010E4 = var_register[0] ;
*(uint32_t *)0x100010E8 = var_register[1] ;
*(uint32_t *)0x100010EC = var_register[2] ;
*(uint32_t *)0x100010F0 = var_register[3] ;
nrf_delay_ms(100);
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
NVIC_SystemReset();
The first implementation was not allowing me to rewrite UICR register either some corrupted data or previously stored data were coming.
In the Second implementation, I first erased UICR register then rewrite those register, it works fine for me.
ISSUE). With the Second implementation, System is not resetting it is going in power off. Only possible way to do a reset is plug in USB, not working on battery independently and also causing problems if I try to do the soft reset.
I then have to erase the chip, program hex with DFU bootloader and do a firmware update over the air to see a soft reset is working.
This just explains that either soft device is forgetting that bootloader is present or erasing UICR register is erasing bootloader.
I tried to check also NRFFW register which is showing value 0xFFFFFFFF, in both scenarios.
From the first implementation, everything works fine but not rewrite of UICR register.
Need some explanation and how to move forward.
Thanks,