From: Keith Packard Date: Sun, 6 Nov 2022 03:39:01 +0000 (-0700) Subject: Hacks to try and get SAMD21D17 working X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=52da034c2e6c5e22b6eed9522a7bea7de410fed1;p=fw%2Fopenocd Hacks to try and get SAMD21D17 working Always use automatic mode. Slow down, waiting 1ms before polling Always clear page buffer Change-Id: I9868ec52d91acc65abc506ebc4120b5aedd34aeb Signed-off-by: Keith Packard --- diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index 3b8893252..da2cfbb7a 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -830,13 +830,37 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer, else manual_wp = false; - res = samd_issue_nvmctrl_command(bank->target, SAMD_NVM_CMD_PBC); - if (res != ERROR_OK) { - LOG_ERROR("%s: %d", __func__, __LINE__); - return res; - } + if (manual_wp) { + LOG_WARNING("manual write mode detected"); + nvm_ctrlb &= ~SAMD_NVM_CTRLB_MANW; + res = target_write_u32(bank->target, SAMD_NVMCTRL + SAMD_NVMCTRL_CTRLB, nvm_ctrlb); + if (res != ERROR_OK) { + LOG_ERROR("select automatic mode write_u32 failed"); + return res; + } + + res = target_read_u32(bank->target, SAMD_NVMCTRL + SAMD_NVMCTRL_CTRLB, &nvm_ctrlb); + + if (res != ERROR_OK) + return res; + + if (nvm_ctrlb & SAMD_NVM_CTRLB_MANW) { + LOG_ERROR("select automatic mode failed"); + return ERROR_FAIL; + } + + manual_wp = false; + } else + LOG_WARNING("automatic write mode detected"); while (count) { + + res = samd_issue_nvmctrl_command(bank->target, SAMD_NVM_CMD_PBC); + if (res != ERROR_OK) { + LOG_ERROR("%s: %d", __func__, __LINE__); + return res; + } + nb = chip->page_size - offset % chip->page_size; if (count < nb) nb = count; @@ -889,7 +913,7 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer, res = samd_issue_nvmctrl_command(bank->target, SAMD_NVM_CMD_WP); } else { /* Access through AHB is stalled while flash is being programmed */ - usleep(200); + usleep(1000); res = samd_check_error(bank->target); }