From 91948428a6ae84a5a3a9ef415b13d7665bdb3154 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 7 Nov 2021 20:10:24 +0000 Subject: [PATCH] Submitted by Martin Thierer: patch #10017: uspasp / tpi: Automatically clear configuration byte (fuse) before writing it * usbasp.c (usbasp_tpi_paged_write): clear fuse region before writing it git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1468 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 6 ++++++ NEWS | 1 + usbasp.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/ChangeLog b/ChangeLog index c933a6ef..9ca7cae8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-11-07 Joerg Wunsch + + Submitted by Martin Thierer: + patch #10017: uspasp / tpi: Automatically clear configuration byte (fuse) before writing it + * usbasp.c (usbasp_tpi_paged_write): clear fuse region before writing it + 2021-11-07 Joerg Wunsch Submitted by Michael Petersen: diff --git a/NEWS b/NEWS index 482c593f..11e50114 100644 --- a/NEWS +++ b/NEWS @@ -102,6 +102,7 @@ Current: patch #9744: Patch for ATMega324A support patch #10000: Add support for extended UPDI device context patch #9697: Add iseavrprog support + patch #10017: uspasp / tpi: Automatically clear configuration byte (fuse) before writing it * Internals: - New avrdude.conf keyword "family_id", used to verify SIB attributes diff --git a/usbasp.c b/usbasp.c index 101a4a3a..62483bc8 100644 --- a/usbasp.c +++ b/usbasp.c @@ -1156,6 +1156,24 @@ static int usbasp_tpi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, pr = addr + m->offset; writed = 0; + /* must erase fuse first */ + if(strcmp(m->desc, "fuse") == 0) + { + /* Set PR */ + usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0)); + usbasp_tpi_send_byte(pgm, (pr & 0xFF) | 1 ); + usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(1)); + usbasp_tpi_send_byte(pgm, (pr >> 8) ); + /* select SECTION_ERASE */ + usbasp_tpi_send_byte(pgm, TPI_OP_SOUT(NVMCMD)); + usbasp_tpi_send_byte(pgm, NVMCMD_SECTION_ERASE); + /* dummy write */ + usbasp_tpi_send_byte(pgm, TPI_OP_SST_INC); + usbasp_tpi_send_byte(pgm, 0x00); + + usbasp_tpi_nvm_waitbusy(pgm); + } + /* Set PR to flash */ usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0)); usbasp_tpi_send_byte(pgm, (pr & 0xFF) | 1 );