Esempio n. 1
0
void nrf_nvmc_write_word(uint32_t address, uint32_t value)
{
    // Enable write.
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
    __ISB();
    __DSB();

    *(uint32_t*)address = value;
    wait_for_flash_ready();

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
    __ISB();
    __DSB();
}
Esempio n. 2
0
void nrf_nvmc_page_erase(uint32_t address)
{
    // Enable erase.
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
    __ISB();
    __DSB();

    // Erase the page
    NRF_NVMC->ERASEPAGE = address;
    wait_for_flash_ready();

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
    __ISB();
    __DSB();
}
Esempio n. 3
0
void nrf_nvmc_write_word(uint32_t address, uint32_t value)
{
  /* Enable write */

  putreg32(NVMC_CONFIG_WEN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();

  /* Write the word */

  *(uint32_t *)address = value;
  wait_for_flash_ready();

  /* Return to read-only mode */

  putreg32(NVMC_CONFIG_REN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();
}
Esempio n. 4
0
void nrf_nvmc_page_erase(uint32_t address)
{
  /* Enable erase */

  putreg32(NVMC_CONFIG_EEN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();

  /* Erase the page */

  putreg32(address, NRF52_NVMC_ERASEPAGE);
  wait_for_flash_ready();

  /* Return to read-only mode */

  putreg32(NVMC_CONFIG_REN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();
}
Esempio n. 5
0
void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words)
{
    // Enable write.
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
    __ISB();
    __DSB();

    for (uint32_t i = 0; i < num_words; i++)
    {
        ((uint32_t*)address)[i] = src[i];
        wait_for_flash_ready();
    }

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
    __ISB();
    __DSB();
}
Esempio n. 6
0
void nrf_nvmc_write_byte(uint32_t address, uint8_t value)
{
    uint32_t byte_shift = address & (uint32_t)0x03;
    uint32_t address32 = address & ~byte_shift; // Address to the word this byte is in.
    uint32_t value32 = (*(uint32_t*)address32 & ~((uint32_t)0xFF << (byte_shift << (uint32_t)3)));
    value32 = value32 + ((uint32_t)value << (byte_shift << 3));

    // Enable write.
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
    __ISB();
    __DSB();

    *(uint32_t*)address32 = value32;
    wait_for_flash_ready();

    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
    __ISB();
    __DSB();
}
Esempio n. 7
0
void nrf_nvmc_write_words(uint32_t address, const uint32_t *src,
                          uint32_t num_words)
{
  uint32_t i;

  /* Enable write */

  putreg32(NVMC_CONFIG_WEN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();

  for (i = 0; i < num_words; i++)
    {
      ((uint32_t *)address)[i] = src[i];
      wait_for_flash_ready();
    }

  /* Return to read-only mode */

  putreg32(NVMC_CONFIG_REN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();
}
Esempio n. 8
0
void nrf_nvmc_write_byte(uint32_t address, uint8_t value)
{
  uint32_t byte_shift = address & (uint32_t)0x03;
  uint32_t address32  = address & ~byte_shift; /* Address to the word this byte is in.*/
  uint32_t value32    = (*(uint32_t *)address32 &
                         ~((uint32_t)0xFF << (byte_shift << (uint32_t)3)));
  value32             = value32 + ((uint32_t)value << (byte_shift << 3));

  /* Enable write */

  putreg32(NVMC_CONFIG_WEN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();

  /* Write the byte, needs to be a single 32-bit write operation */

  *(uint32_t *)address32 = value32;
  wait_for_flash_ready();

  /* Return to read-only mode */

  putreg32(NVMC_CONFIG_REN, NRF52_NVMC_CONFIG);
  nrf_mem_barrier();
}