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

HOW do I erase SDK5.2 version of flash and read not, in SDK4.2 can.

Hello: Why do I erase SDK5.2 version of flash and read not, in SDK4.2 can. I tested nrf51_sdk_v5_2_0_39364\nrf51822\Board\nrf6310\flashwrite_example is a good example.However, I use the store will not work inside BLE,This is a screenshot of my DEBUG can come in here。Figure 1。 But running less flash = 0x03。 nrf_gpio_pin_clear(IPHONE_LED1_PIN_NO); nrf_gpio_pin_clear(IPHONE_LED2_PIN_NO); my_flash_page_erase(FLASH_PAGE);//DEBUG can Run here flash=0x03;// But not here nrf_delay_us(300); flash_word_write_app(FLASH_ADDR, (uint32_t)flash); nrf_gpio_pin_set(IPHONE_LED1_PIN_NO); nrf_gpio_pin_set(IPHONE_LED2_PIN_NO); nrf_delay_us(300); flash_word_read_app(FLASH_ADDR,id_data,1); flash=id_data[0]; Here is my code:

#define FLASH_PAGE (BLE_FLASH_PAGE_END-1) #define FLASH_ADDR ((uint32_t *)(BLE_FLASH_PAGE_SIZE * FLASH_PAGE))

uint32_t my_flash_page_erase(uint8_t page_num) { uint32_t * p_page = (uint32_t *)(BLE_FLASH_PAGE_SIZE * page_num);
flash_page_erase(p_page);

return NRF_SUCCESS;

} 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) { } // Erase page: NRF_NVMC->ERASEPAGE = (uint32_t)page_address; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { } // 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) { } }

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) { } *address = value; // 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) { } } void flash_word_read(uint32_t *address,uint8_t *p, uint16_t n) { // Turn on 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) { } if(n==0) return; while(n--) { *p++=(uint8_t)*address++; } // patrd = (uint8_t)*address; // 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) { } } Here are my settings KEIL: Figure 2 Thank you

1.jpg

2.jpg

Related