finally fix #31 using erasing in advance and skip erase on the fly for nrf52832.

Note A small amount of delay (10 ms) is also added by adafruit-nrfutil
after each 4KB to be safe.
This commit is contained in:
hathach
2018-10-02 16:55:55 +07:00
parent f83e47c83b
commit 51411ff85d
6 changed files with 20 additions and 408 deletions

View File

@ -35,11 +35,10 @@
/**************************************************************************/
#include <string.h>
#include "nrf_sdm.h"
#include "flash_nrf5x.h"
#include "boards.h"
#include "nrf_sdm.h"
#define FLASH_PAGE_SIZE 4096
#define FLASH_CACHE_INVALID_ADDR 0xffffffff
@ -52,7 +51,14 @@ void flash_nrf5x_flush(void)
if ( memcmp(_fl_buf, (void *) _fl_addr, FLASH_PAGE_SIZE) != 0 )
{
#ifdef NRF52840_XXAA
// - nRF52832 dfu via uart can miss incoming byte when erasing because cpu is blocked for > 2ms.
// Since dfu_prepare_func_app_erase() already erase the page for us, we can skip it here.
//
// - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems. Note MSC uf2
// does not erase page in advance like dfu serial
nrf_nvmc_page_erase(_fl_addr);
#endif
nrf_nvmc_write_words(_fl_addr, (uint32_t *) _fl_buf, FLASH_PAGE_SIZE / 4);
}