小言_互联网的博客

nrf 52832 内部flash读写

559人阅读  评论(0)

参考nrf官方资料 例子 peripheral\flashwrite

 

/** @brief Function for erasing a page in flash.
 * 擦除页函数
 * @param page_address Address of the first word in the page to be erased.
 */
static void flash_page_erase(uint32_t * page_address)
{
    // 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)page_address;

    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }

    // Turn off flash erase enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);

    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
}

/** @brief Function for filling a page in flash with a value.
 *  写flash数据
 * @param[in] address Address of the first word in the page to be filled.
 * @param[in] value Value to be written to flash.
 */
static void flash_word_write(uint32_t * address, uint32_t value)
{
    // Turn on flash write enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);

    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }

    *address = value;

    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }

    // Turn off flash write enable and wait until the NVMC is ready:
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);

    while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
    {
        // Do nothing.
    }
}

上述为例子里面的函数 未做修改

下面测试数据 

void write_flash(unsigned int save_value){
    uint32_t * addr;
    addr = (uint32_t *)(0x63000);     //擦除 页地址 0x63000 根据其他flash经验 擦除地址最小单位为 0x1000大小 这里没有测试从   0x63100 擦除之后会不会把0x63000的内容也擦除掉
    flash_page_erase(addr);
    nrf_delay_ms(5);
    addr = (uint32_t *)(0x63100);   //往地址0x63100 写入数据save_value 
    flash_word_write(addr,save_value);
}

读取数据

unsigned int read_flash(){
    uint32_t * addr;
    addr = (uint32_t *)(0x63100);
    return *addr;
}

 

以上就是nrf52832 内部flash数据存储与读写

 

 

 

 

 


转载:https://blog.csdn.net/s1187021637/article/details/102484416
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场