This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 FLASH Erase Error

nRF51822 DK. Keil can download program. But in my pragram, when receive a UART command to erase FLASH page 248, use ble_flash.c

static void flash_page_erase(uint32_t * p_page)
{
  // Turn on flash erase enable and wait until the NVMC is ready.
  NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos);
  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
  {
    // Do nothing.
  }
 
  // Erase page.
  NRF_NVMC->ERASEPAGE = (uint32_t)p_page;
  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
  {
    // Do nothing.
  }

  nrf_gpio_pin_clear(NRF6310_LED_4);

  // Turn off flash erase enable and wait until the NVMC is ready.
  NRF_NVMC->CONFIG &= ~(NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos);
  while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
  {
    // Do nothing
  }
}

can't execute to nrf_gpio_pin_clear(NRF6310_LED_4); also keil stop! **JLink Warning: T-bit of XPSR is 0 but should be 1. Changed to 1.

But in another project \nrf6310\flashwrite_example it's OK.

why?

Parents Reply Children
  • If you need to also erase pages while in a connection, you need to make sure the connection interval is sufficiently long for this to be possible, i.e. > 21 ms (most likely > (21 ms + some processing time)), and do the erase right after the radio event. The ble_radio_notification module from the SDK can be used to get a software interrupt both some time before and right after an event.

    If you have further questions on this, or can't get it working, it might make sense to post it as a separate question.

Related