//Erase NRF and blink every 50ms in the process static void nrf_Emergency_Erase(){ //make sure SWD is initialized if (!swd_init_debug()) { return; } blinkLED(); //Set NVMC->CONFIG on NRF to 2 if (!swd_write_ap(AP_TAR, 0x4001E000 + 0x504)) { return; } if (!swd_write_ap(AP_DRW, 2)) { return; } blinkLED(); blinkLED(); //Set NVMC->ERASEALL on NRF to 1 to start chip erase if (!swd_write_ap(AP_TAR, 0x4001E000 + 0x50C)) { return; } if (!swd_write_ap(AP_DRW, 1)) { return; } blinkLED(); blinkLED(); blinkLED(); blinkLED(); //Set NVMC->CONFIG on NRF to 0 if (!swd_write_ap(AP_TAR, 0x4001E000 + 0x504)) { return; } if (!swd_write_ap(AP_DRW, 0)) { return; } blinkLED(); blinkLED(); //swd_set_target_state(RESET_PROGRAM); //target_flash_init(SystemCoreClock); //target_flash_program_page(0,(uint8_t *)nrfBlinkyApp,800); }
static uint8_t target_set_state_by_board(TARGET_RESET_STATE state) { if( state == RESET_PROGRAM ) { do { swd_set_target_reset(1); osDelay(2); swd_set_target_reset(0); osDelay(2); } while(!swd_init_debug()); } return 1; }
void swd_set_target_reset(uint8_t asserted) { if (asserted) { swd_init_debug(); //Set POWER->RESET on NRF to 1 if(!swd_write_ap(AP_TAR, 0x40000000 + 0x544)) { return; } if(!swd_write_ap(AP_DRW, 1)){ return; } //Hold RESET and SWCLK low for a minimum of 100us PIN_SWCLK_TCK_CLR(); PIN_SWDIO_TMS_CLR(); //os_dly_wait(1); } else { PIN_SWCLK_TCK_SET(); PIN_SWDIO_TMS_SET(); } }