Skip to content

Commit

Permalink
fix: increase speed of programmer by removing unnecessary checks for …
Browse files Browse the repository at this point in the history
…the web
  • Loading branch information
koen1711 committed Mar 25, 2024
1 parent fe7f4af commit 377be7b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 123 deletions.
115 changes: 0 additions & 115 deletions interface/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,121 +1490,6 @@ int main(int argc, char * argv [])

pmsg_info("AVR device initialized and ready to accept instructions\n");

/*
* Let's read the signature bytes to make sure there is at least a
* chip on the other end that is responding correctly. A check
* against 0xffffff / 0x000000 should ensure that the signature bytes
* are valid.
*/
if(!(p->prog_modes & PM_aWire)) { // not AVR32
int attempt = 0;
int waittime = 10000; /* 10 ms */

sig_again:
emscripten_sleep(waittime/1000); // replace usleep with emscripten_slee
if (init_ok) {
rc = avr_signature(pgm, p);
if (rc != LIBAVRDUDE_SUCCESS) {
if (rc == LIBAVRDUDE_SOFTFAIL && (p->prog_modes & PM_UPDI) && attempt < 1) {
attempt++;
if (pgm->read_sib) {
// Read SIB and compare FamilyID
char sib[AVR_SIBLEN + 1];
pgm->read_sib(pgm, p, sib);
pmsg_notice("System Information Block: %s\n", sib);
pmsg_info("received FamilyID: \"%.*s\"\n", AVR_FAMILYIDLEN, sib);
if (strncmp(p->family_id, sib, AVR_FAMILYIDLEN))
pmsg_error("expected FamilyID: \"%s\"\n", p->family_id);
}
if(erase) {
erase = 0;
if (uflags & UF_NOWRITE) {
pmsg_warning("conflicting -e and -n options specified, NOT erasing chip\n");
} else {
pmsg_info("erasing chip\n");
exitrc = avr_unlock(pgm, p);
if(exitrc)
goto main_exit;
goto sig_again;
}
}
if (!ovsigck) {
imsg_error("double check chip or use -F to override this check\n");
exitrc = 1;
goto main_exit;
}
}
pmsg_error("unable to read signature data, rc=%d\n", rc);
exitrc = 1;
goto main_exit;
}
}

sig = avr_locate_signature(p);
sig = NULL; // just force skip signature check
if (sig == NULL)
pmsg_warning("signature memory not defined for device %s\n", p->desc);

if (sig != NULL) {
int ff, zz;

pmsg_info("device signature = 0x");
ff = zz = 1;
for (i=0; i<sig->size; i++) {
msg_info("%02x", sig->buf[i]);
if (sig->buf[i] != 0xff)
ff = 0;
if (sig->buf[i] != 0x00)
zz = 0;
}

bool signature_matches =
sig->size == 3 &&
sig->buf[0] == p->signature[0] &&
sig->buf[1] == p->signature[1] &&
sig->buf[2] == p->signature[2];

if (quell_progress < 2) {
AVRPART *part;
if((part = locate_part_by_signature_pm(part_list, sig->buf, sig->size, pgm->prog_modes)) ||
(part = locate_part_by_signature(part_list, sig->buf, sig->size)))
msg_info(" (probably %s)", signature_matches? p->id: part->id);
}
if (ff || zz) {
if (++attempt < 3) {
waittime *= 5;
msg_info(" (retrying)\n");
goto sig_again;
}
msg_info("\n");
pmsg_error("Yikes! Invalid device signature.\n");
if (!ovsigck) {
pmsg_error("expected signature for %s is %02X %02X %02X\n", p->desc,
p->signature[0], p->signature[1], p->signature[2]);
imsg_error("Double check connections and try again, or use -F to override\n");
imsg_error("this check.\n\n");
exitrc = 1;
goto main_exit;
}
} else {
msg_info("\n");
}

if (!signature_matches) {
if (ovsigck) {
pmsg_warning("expected signature for %s is %02X %02X %02X\n", p->desc,
p->signature[0], p->signature[1], p->signature[2]);
} else {
pmsg_error("expected signature for %s is %02X %02X %02X\n", p->desc,
p->signature[0], p->signature[1], p->signature[2]);
imsg_error("double check chip or use -F to override this check\n");
exitrc = 1;
goto main_exit;
}
}
}
}

if (uflags & UF_AUTO_ERASE) {
if ((p->prog_modes & PM_PDI) && pgm->page_erase && lsize(updates) > 0) {
pmsg_info("Note: programmer supports page erase for Xmega devices.\n");
Expand Down
11 changes: 3 additions & 8 deletions libserial/LibSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ namespace {
let result = await Promise.race([receive(), timeout(timeoutMs)]);

if (result instanceof Uint8Array && result.length > 0) {
// check if it is twice the same data so check if the first half is the same as the second half if so remove the second half
let firstHalf = result.slice(0, result.length / 2);
let secondHalf = result.slice(result.length / 2, result.length);
if (firstHalf.every((value, index) => value === secondHalf[index])) {
result = firstHalf;
}

//console.log("Received: ", result);
// convert data into an readable string formated like this 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
const printResult = Array.from(result).join(",");
Expand Down Expand Up @@ -180,13 +173,15 @@ namespace {
await window.writeStream.write(data);
await window.writeStream.ready;
// delay for 100ms to make sure the data is sent
await new Promise(resolve => setTimeout(resolve, 300));
await new Promise(resolve => setTimeout(resolve, 250));
});

val generateSerialOptions(const std::map<std::string, int>& serialOptions) {
val&& serialOpts = val::object();
for (auto& [key, value] : serialOptions) {
if (key == "flowControl" || key == "parity" || key == "stopBits") {
printf("Not implemented yet\n");
printf("Key: %s, Value: %d\n", key.c_str(), value);
// Handle specific cases for flowControl, parity, and stopBits if needed
// ...
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/stk500.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,7 @@ static int stk500_setparm(const PROGRAMMER *pgm, unsigned parm, unsigned value)


static void stk500_display(const PROGRAMMER *pgm, const char *p) {
return; // No need to print these parameters
unsigned maj = 0, min = 0, hdw = 0, topcard = 0;

stk500_getparm(pgm, Parm_STK_HW_VER, &hdw);
Expand Down Expand Up @@ -1512,6 +1513,7 @@ static void stk500_display(const PROGRAMMER *pgm, const char *p) {


static void stk500_print_parms1(const PROGRAMMER *pgm, const char *p, FILE *fp) {
return; // No need to print parameters
unsigned vtarget = 0, vadjust = 0;
unsigned osc_pscale = 0, osc_cmatch = 0, sck_duration = 0;
const char *unit;
Expand Down
2 changes: 2 additions & 0 deletions src/stk500v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3707,6 +3707,7 @@ static const char *stk600_get_cardname(const struct carddata *table,


static void stk500v2_display(const PROGRAMMER *pgm, const char *p) {
return; // We don't want to display the programmer info
unsigned char maj = 0, min = 0, hdw = 0, topcard = 0,
maj_s1 = 0, min_s1 = 0, maj_s2 = 0, min_s2 = 0;
unsigned int rev = 0;
Expand Down Expand Up @@ -3903,6 +3904,7 @@ static double stk500v2_fosc_value(const PROGRAMMER *pgm) {


static void stk500v2_print_parms1(const PROGRAMMER *pgm, const char *p, FILE *fp) {
return; // We don't want to display the programmer info
double f;
int decimals;
const char *unit;
Expand Down

0 comments on commit 377be7b

Please sign in to comment.