Piles more delay, plus check by reading after write at91samd-hacks
authorKeith Packard <keithp@keithp.com>
Sun, 6 Nov 2022 04:44:19 +0000 (21:44 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 6 Nov 2022 04:44:19 +0000 (21:44 -0700)
Change-Id: I551d366475c53491377cff671ead4081a72004c1
Signed-off-by: Keith Packard <keithp@keithp.com>
src/flash/nor/at91samd.c

index cef84e5eba16cffe0a659d2a32c2064a53b07518..8e56b33fde4498f57e4d990891c1a662622618e7 100644 (file)
@@ -548,6 +548,8 @@ static int samd_issue_nvmctrl_command(struct target *target, uint16_t cmd)
        if (res != ERROR_OK)
                return res;
 
+       usleep(100000);
+
        /* Check to see if the NVM command resulted in an error condition. */
        return samd_check_error(target);
 }
@@ -916,6 +918,19 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer,
                        assert(pg_offset + 4 * nw <= chip->page_size);
 
                        /* Word aligned data, use direct write from buffer */
+
+                       uint32_t n;
+                       for (n = 0; n < nw; n++) {
+                               uint32_t value;
+
+                               memcpy(&value, buffer + n * 4, 4);
+                               res = target_write_u32(bank->target, address + n * 4, value);
+
+                               if (res != ERROR_OK)
+                                       LOG_ERROR("%s: %d", __func__, __LINE__);
+                               usleep(1000);
+                       }
+
                        res = target_write_memory(bank->target, address, 4, nw, buffer);
                }
                if (res != ERROR_OK) {
@@ -942,6 +957,27 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer,
                /* Access through AHB is stalled while flash is being programmed */
                usleep(100000);
 
+               /* Verify write */
+
+               {
+                       uint32_t n;
+
+                       for (n = 0; n < nb; n += 4) {
+                               uint32_t got, should;
+
+                               memcpy(&should, buffer + n, 4);
+                               res = target_read_u32(bank->target, address + n, &got);
+
+                               if (res != ERROR_OK)
+                                       LOG_ERROR("%s: %d", __func__, __LINE__);
+
+                               if (got != should) {
+                                       LOG_ERROR("address 0x%08" PRIx32 " wrote 0x%08" PRIx32 " got 0x%08x" PRIx32,
+                                                 address + n, should, got);
+                               }
+                       }
+               }
+
                /* We're done with the page contents */
                count -= nb;
                offset += nb;