From e8c5ed0fcdf77294b32ced0f4d4016cba1613bcd Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 14 Nov 2021 15:44:54 +0000 Subject: [PATCH] patch #9122: Fixed MISO sampling in ftdi_syncbb Submitted by Ivan Frederiks Fix MISO sampling on falling edge of SCK. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1474 81a1dc3b-b13d-400b-aceb-764788c761c2 --- NEWS | 2 ++ ft245r.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 0628ff63..d9b6f83a 100644 --- a/NEWS +++ b/NEWS @@ -107,6 +107,8 @@ Current: patch #9110: Let reserved fuse bits to be read as *don't care* patch #9253: Fix for giving terminal_mode commands more than 20 arguments patch #9320: fix TPI RESET in bitbang.c + patch #9079: Fix ftdi_syncbb teardown (supersedes #9893) + patch #9122: Fixed MISO sampling in ftdi_syncbb * Internals: - New avrdude.conf keyword "family_id", used to verify SIB attributes diff --git a/ft245r.c b/ft245r.c index b155e82e..6fea5aec 100644 --- a/ft245r.c +++ b/ft245r.c @@ -469,7 +469,8 @@ static inline int set_data(PROGRAMMER * pgm, unsigned char *buf, unsigned char d static inline unsigned char extract_data(PROGRAMMER * pgm, unsigned char *buf, int offset) { int j; - int buf_pos = 1; + int buf_pos = FT245R_CYCLES; /* MISO data is valid AFTER rising SCK edge, + i.e. in next clock cycle */ unsigned char bit = 0x80; unsigned char r = 0; @@ -845,6 +846,11 @@ static int ft245r_paged_write_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0); // sck down buf[buf_pos++] = ft245r_out; } + else { + /* stretch sequence to allow correct readout, see extract_data() */ + buf[buf_pos] = buf[buf_pos - 1]; + buf_pos++; + } ft245r_send(pgm, buf, buf_pos); put_request(addr_save, buf_pos, 0); //ft245r_sync(pgm); @@ -934,6 +940,11 @@ static int ft245r_paged_load_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0); // sck down buf[buf_pos++] = ft245r_out; } + else { + /* stretch sequence to allow correct readout, see extract_data() */ + buf[buf_pos] = buf[buf_pos - 1]; + buf_pos++; + } n = j; ft245r_send(pgm, buf, buf_pos); put_request(addr_save, buf_pos, n);