]> git.gag.com Git - fw/openocd/commitdiff
Hacks to try and get SAMD21D17 working
authorKeith Packard <keithp@keithp.com>
Sun, 6 Nov 2022 03:39:01 +0000 (20:39 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 6 Nov 2022 03:39:01 +0000 (20:39 -0700)
Always use automatic mode.
Slow down, waiting 1ms before polling
Always clear page buffer

Change-Id: I9868ec52d91acc65abc506ebc4120b5aedd34aeb
Signed-off-by: Keith Packard <keithp@keithp.com>
src/flash/nor/at91samd.c

index 3b8893252a32d56ffd2467596424aa67abed1915..da2cfbb7a13e89e6b7828c5a374e62193b9d73dd 100644 (file)
@@ -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);
                }