Optimised flash write, programming speed is now approx. 2x faster

This commit is contained in:
Richard Eoin Meadows 2014-07-06 17:31:49 +01:00 committed by Gareth McMullin
parent 02812b6bf1
commit e75798f201
1 changed files with 15 additions and 5 deletions

View File

@ -353,9 +353,6 @@ static int samd20_flash_erase(struct target_s *target, uint32_t addr, int len)
addr &= ~(SAMD20_ROW_SIZE - 1); addr &= ~(SAMD20_ROW_SIZE - 1);
len &= ~(SAMD20_ROW_SIZE - 1); len &= ~(SAMD20_ROW_SIZE - 1);
while (len) { while (len) {
/* Write address of first word in row to erase it */ /* Write address of first word in row to erase it */
/* Must be shifted right for 16-bit address, see Datasheet §20.8.8 Address */ /* Must be shifted right for 16-bit address, see Datasheet §20.8.8 Address */
@ -414,10 +411,16 @@ static int samd20_flash_write(struct target_s *target, uint32_t dest,
end_of_this_page = page + (SAMD20_PAGE_SIZE - 4); end_of_this_page = page + (SAMD20_PAGE_SIZE - 4);
if (addr > page || (page == last_page && end < end_of_this_page)) { if (addr > page || (page == last_page && end < end_of_this_page)) {
/* Setup write */
adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw |
ADIV5_AP_CSW_SIZE_WORD | ADIV5_AP_CSW_ADDRINC_SINGLE);
adiv5_ap_write(ap, ADIV5_AP_TAR, addr);
adiv5_dp_write(ap->dp, ADIV5_DP_SELECT,
((uint32_t)ap->apsel << 24)|(ADIV5_AP_DRW & 0xF0));
/* Partial, manual page write */ /* Partial, manual page write */
for (; addr <= MINIMUM(end, end_of_this_page); addr += 4, i++) { for (; addr <= MINIMUM(end, end_of_this_page); addr += 4, i++) {
adiv5_ap_mem_write(ap, addr, data[i]); adiv5_dp_write_ap(ap->dp, ADIV5_AP_DRW, data[i]);
} }
/* Unlock */ /* Unlock */
@ -433,9 +436,16 @@ static int samd20_flash_write(struct target_s *target, uint32_t dest,
/* Unlock */ /* Unlock */
samd20_unlock_current_address(target); samd20_unlock_current_address(target);
/* Set up write */
adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw |
ADIV5_AP_CSW_SIZE_WORD | ADIV5_AP_CSW_ADDRINC_SINGLE);
adiv5_ap_write(ap, ADIV5_AP_TAR, addr);
adiv5_dp_write(ap->dp, ADIV5_DP_SELECT,
((uint32_t)ap->apsel << 24)|(ADIV5_AP_DRW & 0xF0));
/* Full, automatic page write */ /* Full, automatic page write */
for (; addr < page + SAMD20_PAGE_SIZE; addr += 4, i++) { for (; addr < page + SAMD20_PAGE_SIZE; addr += 4, i++) {
adiv5_ap_mem_write(ap, addr, data[i]); adiv5_dp_write_ap(ap->dp, ADIV5_AP_DRW, data[i]);
} }
} }