samd: Remove low level ADIv5 calls an favour of target_mem_write.
This commit is contained in:
parent
018d9cce80
commit
0bf7778759
29
src/samd.c
29
src/samd.c
|
@ -508,7 +508,6 @@ static int samd_flash_erase(struct target_s *target, uint32_t addr, size_t len)
|
||||||
static int samd_flash_write(struct target_s *target, uint32_t dest,
|
static int samd_flash_write(struct target_s *target, uint32_t dest,
|
||||||
const uint8_t *src, size_t len)
|
const uint8_t *src, size_t len)
|
||||||
{
|
{
|
||||||
ADIv5_AP_t *ap = adiv5_target_ap(target);
|
|
||||||
/* Find the size of our 32-bit data buffer */
|
/* Find the size of our 32-bit data buffer */
|
||||||
uint32_t offset = dest % 4;
|
uint32_t offset = dest % 4;
|
||||||
uint32_t words = (offset + len + 3) / 4;
|
uint32_t words = (offset + len + 3) / 4;
|
||||||
|
@ -534,17 +533,9 @@ static int samd_flash_write(struct target_s *target, uint32_t dest,
|
||||||
end_of_this_page = page + (SAMD_PAGE_SIZE - 4);
|
end_of_this_page = page + (SAMD_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++) {
|
target_mem_write(target, addr, &data[i],
|
||||||
adiv5_dp_write(ap->dp, ADIV5_AP_DRW, data[i]);
|
MINIMUM(end, end_of_this_page));
|
||||||
}
|
|
||||||
|
|
||||||
/* Unlock */
|
/* Unlock */
|
||||||
samd_unlock_current_address(target);
|
samd_unlock_current_address(target);
|
||||||
|
@ -554,22 +545,14 @@ static int samd_flash_write(struct target_s *target, uint32_t dest,
|
||||||
SAMD_CTRLA_CMD_KEY | SAMD_CTRLA_CMD_WRITEPAGE);
|
SAMD_CTRLA_CMD_KEY | SAMD_CTRLA_CMD_WRITEPAGE);
|
||||||
} else {
|
} else {
|
||||||
/* Write first word to set address */
|
/* Write first word to set address */
|
||||||
target_mem_write32(target, addr, data[i]); addr += 4; i++;
|
target_mem_write32(target, addr, data[i]);
|
||||||
|
addr += 4; i++;
|
||||||
|
|
||||||
/* Unlock */
|
/* Unlock */
|
||||||
samd_unlock_current_address(target);
|
samd_unlock_current_address(target);
|
||||||
|
|
||||||
/* Set up write */
|
target_mem_write(target, addr, &data[i],
|
||||||
adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw |
|
MINIMUM(end, end_of_this_page));
|
||||||
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 */
|
|
||||||
for (; addr < page + SAMD_PAGE_SIZE; addr += 4, i++) {
|
|
||||||
adiv5_dp_write(ap->dp, ADIV5_AP_DRW, data[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Poll for NVM Ready */
|
/* Poll for NVM Ready */
|
||||||
|
|
Loading…
Reference in New Issue