SAM4S: Erase flash in 8K instead of 16K chunks.

This commit is contained in:
David Lawrence 2015-02-04 15:45:52 -05:00
parent c731c6ece3
commit c8f469c868
1 changed files with 10 additions and 9 deletions

View File

@ -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); uint32_t base = sam3x_flash_base(target, addr, &offset);
/* The SAM4S is the only supported device with a page erase command. /* 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 * Erasing is done in 8-page chunks. arg[15:2] contains the page
* number and arg[1:0] contains 0x2, indicating 16-page chunks. * number and arg[1:0] contains 0x1, indicating 8-page chunks.
*/ */
if (strcmp(target->driver, "Atmel SAM4S") == 0) { if (strcmp(target->driver, "Atmel SAM4S") == 0) {
unsigned chunk = offset / SAM4_PAGE_SIZE; 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; 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. * In this case, we will erase a few extra pages at the end.
*/ */
while (len > 0) { 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)) if(sam3x_flash_cmd(target, base, EEFC_FCR_FCMD_EPA, arg))
return -1; return -1;
len -= SAM4_PAGE_SIZE * 16; len -= SAM4_PAGE_SIZE * 8;
addr += SAM4_PAGE_SIZE * 16; addr += SAM4_PAGE_SIZE * 8;
chunk += 16; chunk += 8;
} }
return 0; return 0;