]> git.gag.com Git - fw/openocd/commitdiff
at91samd: Force manual flash writing mode
authorKeith Packard <keithp@keithp.com>
Sun, 6 Nov 2022 04:16:36 +0000 (21:16 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 6 Nov 2022 04:16:36 +0000 (21:16 -0700)
Change-Id: Ie0bc43e62cfb985c1a7bd1cac3c52d34132c4492
Signed-off-by: Keith Packard <keithp@keithp.com>
src/flash/nor/at91samd.c

index 8c9bacc5bb513daa22cebcb3dfd22f6604151bc3..45386dcba29d3e9544c8fcac8ab64190213cec43 100644 (file)
@@ -832,10 +832,12 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer,
 
        if (manual_wp) {
                LOG_WARNING("manual write mode detected");
-               nvm_ctrlb &= ~SAMD_NVM_CTRLB_MANW;
+       } else {
+               LOG_WARNING("automatic 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");
+                       LOG_ERROR("select manual mode write_u32 failed");
                        return res;
                }
 
@@ -844,14 +846,14 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer,
                if (res != ERROR_OK)
                        return res;
 
-               if (nvm_ctrlb & SAMD_NVM_CTRLB_MANW) {
-                       LOG_ERROR("select automatic mode failed");
+               if ((nvm_ctrlb & SAMD_NVM_CTRLB_MANW) == 0) {
+                       LOG_ERROR("select manual mode failed");
                        return ERROR_FAIL;
                }
 
-               manual_wp = false;
-       } else
-               LOG_WARNING("automatic write mode detected");
+               LOG_INFO("manual write mode selected");
+               manual_wp = true;
+       }
 
        uint32_t nvm_param;