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

Erasing page between .isr_vector and .text

Hello. I'm developing an application with a custom bootloader and I'm using "settings" data structure placed in FLASH. Because we can erase only full pages, the first page of FLASH is for isr_vector, the second for "settings" and the third is for bootloader (".text" section). I prepared linker script which works like a charm. Bootloader starts normally and my "settings" structure is placed on the second page as I wished. The problem is that I cannot erase and write to my settings (using NVMC of course). I noticed that first page (with isr_vector) is also unerasable. I checked BPROT configuration too. When I erase/write to pages placed after application - it works. How can I unlock memory writing to page between .isr_vector and .text section?

Parents
  • Unless the BPROT peripheral has been explicitly enabled to block those pages for flash writes, then you should be able to use the NVMC to erase any flash page. Could you attatch the code snippet you're using to erase and write to the flash pages?

    Best regards

    Bjørn 

     

  • Thank you for response.

    Here is the code:

    bootloader_set_t new_set = settings;
    // Erase settings page
    nrf_nvmc_page_erase((uint32_t)&_flash_settings);
    
    uint8_t *dst = (uint8_t *)&_flash_settings;
    uint32_t *src = (uint32_t *)&new_set;
    // Enable write
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
    // Write to flash
    for (uint32_t i = 0; i < sizeof(new_set); i += 4, dst += 4, src += 1) {
    	((uint32_t *)dst)[0] = 0xFFFFFFFFUL & *src;
    	while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
    }
    // Disable write
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
    
    // check result
    if(memcmp(&_flash_settings, &new_set, sizeof(new_set)) != 0) {
    	Bootloader_SaveSettings();
    }

    I've replaced "_flash_settings" with other addresses and it worked for pages different than .isr_vector to .text.

    EDIT: So I created some example project to show the problem. I spent some time with the example and I found that some problems were with the linker scripts and/or with a memory monitor in my Eclipse. I used direct nrfjprog memory reading and it turned out that everything was working correctly. Excuse me for taking Your time and thank you for a concern Slight smile

Reply
  • Thank you for response.

    Here is the code:

    bootloader_set_t new_set = settings;
    // Erase settings page
    nrf_nvmc_page_erase((uint32_t)&_flash_settings);
    
    uint8_t *dst = (uint8_t *)&_flash_settings;
    uint32_t *src = (uint32_t *)&new_set;
    // Enable write
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
    // Write to flash
    for (uint32_t i = 0; i < sizeof(new_set); i += 4, dst += 4, src += 1) {
    	((uint32_t *)dst)[0] = 0xFFFFFFFFUL & *src;
    	while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
    }
    // Disable write
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
    
    // check result
    if(memcmp(&_flash_settings, &new_set, sizeof(new_set)) != 0) {
    	Bootloader_SaveSettings();
    }

    I've replaced "_flash_settings" with other addresses and it worked for pages different than .isr_vector to .text.

    EDIT: So I created some example project to show the problem. I spent some time with the example and I found that some problems were with the linker scripts and/or with a memory monitor in my Eclipse. I used direct nrfjprog memory reading and it turned out that everything was working correctly. Excuse me for taking Your time and thank you for a concern Slight smile

Children
No Data
Related