This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Erasing Flash memory with application loaded via open serial bootloader

Hello,

we are using an nRF52833 for our application with the open serial uart bootloader and MBR programmed in it. What we would like to do is:

1) program the application via serial bootloader with a temporary firmware (the firmware uses soft device)

2) run the firmware, then enter DFU mode

3) Load the device with a new firmware (erasing firmware) which will erase the previous application, the soft device and itself, but leave the bootloader and MBR, so as to leave the device in its previous condition (only bootloader and MBR loaded in the device).

If possible we would like to interact only via UART with the device (no j-link attached)

The problem lies in step 3. The firmware in step 3 is not using the soft device or any of the Nordic header files. We used GCC toolchain.

Here is what we tried so far, and some questions: 
 3.1) We programmed an empty device without a bootloader with the erasing firmware (Flash set to start at address 0x0) to test if it could erase itself and it could. The erasing function was set to run from RAM. We also tried it with the erasing function not run from RAM and it also worked, which is a bit confusing, we expected this not to work since when the page was erased, it was in use(?) 

3.2) The device was loaded with bootloader, MBR and the temporary firmware(normal case). The erasing firmware was set to run from RAM, using:

__attribute__((used, long_call, section(".ramfun"))) void fun(void)
 

we loaded the firmware in the device using uart. We tried two things with this setup. Only opening a LED (via function loaded in RAM memory), which worked ok (so the function was called). Then in the same function, we added code to erase the memory after the LED opens, and then close the LED when erasing is complete. This did not work (not even the LED opened). Any clues why this could happen? Does the bootloader use something at that time, that prevents the memory from been erased? If that is the case can we do something about this?

Another strange thing happened when using Segger Embedded Studio:
3.3) The function to erase firmware was set to run from RAM again. When the device is loaded with MBR, bootloader and the temporary firmware:
- if we program the erasing firmware via a J-Link debugger through embedded studio, the memory (soft device etc, previous application and the erasing firmware) is erased, leaving the bootloader intact. (in other words it works as it should)
- When the device is programmed via uart using the bootloader, it does not work (it seems to stop when writing to NVMC erase register.

Do you have any idea how/ if something like this can be achieved (program an application via uart bootloader to erase anything but the bootloader and MBR)? 

Related