mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-14 10:17:55 -06:00
avrdude: add file offset to update operation spec, refactoring
This commit is contained in:
parent
7863412687
commit
15f943938b
6 changed files with 118 additions and 83 deletions
|
@ -80,6 +80,49 @@ static int arduino_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m)
|
|||
return 3;
|
||||
}
|
||||
|
||||
static int prusa_init_external_flash(PROGRAMMER * pgm)
|
||||
{
|
||||
// Note: send/receive as in _the firmare_ send & receives
|
||||
const char entry_magic_send [] = "start\n";
|
||||
const char entry_magic_receive[] = "w25x20cl_enter\n";
|
||||
const char entry_magic_cfm [] = "w25x20cl_cfm\n";
|
||||
const size_t buffer_len = 32; // Should be large enough for the above messages
|
||||
|
||||
int res;
|
||||
size_t recv_size;
|
||||
char *buffer = alloca(buffer_len);
|
||||
|
||||
// 1. receive the "start" command
|
||||
recv_size = sizeof(entry_magic_send) - 1;
|
||||
res = serial_recv(&pgm->fd, buffer, recv_size);
|
||||
if (res < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: prusa_init_external_flash(): MK3 printer did not boot up on time or serial communication failed\n", progname);
|
||||
return -1;
|
||||
} else if (strncmp(buffer, entry_magic_send, recv_size) != 0) {
|
||||
avrdude_message(MSG_INFO, "%s: prusa_init_external_flash(): MK3 printer emitted incorrect start code\n", progname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 2. Send the external flash programmer enter command
|
||||
if (serial_send(&pgm->fd, entry_magic_receive, sizeof(entry_magic_receive) - 1) < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: prusa_init_external_flash(): Failed to send command to the printer\n",progname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 3. Receive the entry confirmation command
|
||||
recv_size = sizeof(entry_magic_cfm) - 1;
|
||||
res = serial_recv(&pgm->fd, buffer, recv_size);
|
||||
if (res < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: prusa_init_external_flash(): MK3 printer did not boot up on time or serial communication failed\n", progname);
|
||||
return -1;
|
||||
} else if (strncmp(buffer, entry_magic_cfm, recv_size) != 0) {
|
||||
avrdude_message(MSG_INFO, "%s: prusa_init_external_flash(): MK3 printer emitted incorrect start code\n", progname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int arduino_open(PROGRAMMER * pgm, char * port)
|
||||
{
|
||||
union pinfo pinfo;
|
||||
|
@ -102,56 +145,10 @@ static int arduino_open(PROGRAMMER * pgm, char * port)
|
|||
*/
|
||||
stk500_drain(pgm, 0);
|
||||
|
||||
{
|
||||
//FIXME initialization sequence for programming the external FLASH.
|
||||
const char entry_magic_send [] = "start\n";
|
||||
const char entry_magic_receive[] = "w25x20cl_enter\n";
|
||||
const char entry_magic_cfm [] = "w25x20cl_cfm\n";
|
||||
const char *entry_magic_ptr = entry_magic_send;
|
||||
struct timeval tv;
|
||||
double tstart, tnow;
|
||||
char c;
|
||||
gettimeofday(&tv, NULL);
|
||||
tstart = tv.tv_sec;
|
||||
while (*entry_magic_ptr != 0) {
|
||||
if (serial_recv(&pgm->fd, &c, 1) < 0)
|
||||
goto timedout;
|
||||
printf("Received: %c (%d)\n", c, (int)c);
|
||||
if (c != *entry_magic_ptr ++) {
|
||||
avrdude_message(MSG_INFO, "%s: stk500v2_recv(): MK3 printer emited incorrect start code\n", progname);
|
||||
return -1;
|
||||
}
|
||||
gettimeofday(&tv, NULL);
|
||||
tnow = tv.tv_sec;
|
||||
if (tnow-tstart > 2.) { // wuff - signed/unsigned/overflow
|
||||
timedout:
|
||||
avrdude_message(MSG_INFO, "%s: stk500v2_recv(): MK3 printer did not boot up on time\n", progname);
|
||||
return -1;
|
||||
}
|
||||
// Initialization sequence for programming the external FLASH on the Prusa MK3
|
||||
if (prusa_init_external_flash(pgm) < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: arduino_open(): Failed to initialize MK3 external flash programming mode\n", progname);
|
||||
}
|
||||
if (serial_send(&pgm->fd, entry_magic_receive, strlen(entry_magic_receive)) < 0) {
|
||||
avrdude_message(MSG_INFO, "%s: stk500v2_send(): failed to send command to serial port\n",progname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
entry_magic_ptr = entry_magic_cfm;
|
||||
while (*entry_magic_ptr != 0) {
|
||||
if (serial_recv(&pgm->fd, &c, 1) < 0)
|
||||
goto timedout2;
|
||||
printf("Received: %c (%d)\n", c, (int)c);
|
||||
if (c != *entry_magic_ptr++) {
|
||||
avrdude_message(MSG_INFO, "%s: stk500v2_recv(): MK3 printer emited incorrect start code\n", progname);
|
||||
return -1;
|
||||
}
|
||||
gettimeofday(&tv, NULL);
|
||||
tnow = tv.tv_sec;
|
||||
if (tnow - tstart > 2.) { // wuff - signed/unsigned/overflow
|
||||
timedout2:
|
||||
avrdude_message(MSG_INFO, "%s: stk500v2_recv(): MK3 printer did not boot up on time\n", progname);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stk500_getsync(pgm) < 0)
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue