aboutsummaryrefslogtreecommitdiff
path: root/src/sam3x.c
diff options
context:
space:
mode:
authorDavid Lawrence2015-02-04 15:45:52 -0500
committerDavid Lawrence2015-03-05 10:46:22 -0500
commitc8f469c868c63f21692a8d61733bf6305a92110f (patch)
treec6d78b0b10dc4419f6b351254f45f20bc857413a /src/sam3x.c
parentc731c6ece343c48296355b8cfde58067c2f44853 (diff)
SAM4S: Erase flash in 8K instead of 16K chunks.
Diffstat (limited to 'src/sam3x.c')
-rw-r--r--src/sam3x.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/sam3x.c b/src/sam3x.c
index ef99290..902f267 100644
--- a/src/sam3x.c
+++ b/src/sam3x.c
@@ -291,26 +291,27 @@ static int sam3x_flash_erase(struct target_s *target, uint32_t addr, int len)
uint32_t base = sam3x_flash_base(target, addr, &offset);
/* The SAM4S is the only supported device with a page erase command.
- * Erasing is done in 16-page chunks. arg[15:2] contains the page
- * number and arg[1:0] contains 0x2, indicating 16-page chunks.
+ * Erasing is done in 8-page chunks. arg[15:2] contains the page
+ * number and arg[1:0] contains 0x1, indicating 8-page chunks.
*/
if (strcmp(target->driver, "Atmel SAM4S") == 0) {
unsigned chunk = offset / SAM4_PAGE_SIZE;
- /* Fail if the start address is not 16-page-aligned. */
- if (chunk % 16 != 0)
+
+ /* Fail if the start address is not 8-page-aligned. */
+ if (chunk % 8 != 0)
return -1;
- /* Note that the length might not be a multiple of 16 pages.
+ /* Note that the length might not be a multiple of 8 pages.
* In this case, we will erase a few extra pages at the end.
*/
while (len > 0) {
- int16_t arg = (chunk << 2) | 0x2;
+ int16_t arg = chunk | 0x1;
if(sam3x_flash_cmd(target, base, EEFC_FCR_FCMD_EPA, arg))
return -1;
- len -= SAM4_PAGE_SIZE * 16;
- addr += SAM4_PAGE_SIZE * 16;
- chunk += 16;
+ len -= SAM4_PAGE_SIZE * 8;
+ addr += SAM4_PAGE_SIZE * 8;
+ chunk += 8;
}
return 0;