I am having trouble getting my ISP upgrades going. I can properly Sync, Prepare, Erase and Send a Write Command.
Synchronized
OK
10000
OK
U 23130
0
P 0 31
0
E 0 31
0
W 268436224 1200
0
When I try to write my 1200 bytes to the device followed by my checksum I get nothing.
Here is a high level description of my process.
struct uu_buffer {
uint8_t line;
uint8_t data[128];
};
struct uu_buffer uu_buffer[20];
lpc_request_isp();
lpc_synchronize();
while ((bytes_read = fread(buffer, 1, 45, fp)) > 0) { // read in 45 bytes at a time from my .bin
for(uint32_t i=0; i<buffer_len; i++) {
checksum += buffer[i];
}
uu_buffer[line_count].line = line_count;
uuencode_buffer(buffer, bytes_read, uu_buffer[line_count].data, &output_size);
transmit_size += bytes_read;
line_count++;
if((line_count == 20) || (bytes_read < READ_BUFFER_LEN)) {
isp_write(uu_buffer, 20, flash_addr, transmit_size);
if(bytes_read < READ_BUFFER_LEN) {
sprintf(checksum_buffer, "%u", transmit_size);
} else {
sprintf(checksum_buffer, "%u", checksum);
}
serial_tx(checksum_buffer, strlen(checksum_buffer));
bool response_ok = serial_response_received(ISP_OK);
bool response_resend = serial_response_received(ISP_RESEND_RESP);
// determine how to proceed
}
}
static void isp_write(struct uu_buffer *uu_buffer, uint32_t buffer_len, uint32_t start_flash_addr, uint32_t bytes_to_tx) {
char cmd[50] = {0};
cmd[0] = 'W';
cmd[1] = ' ';
uint32_t flash_addr = start_flash_addr;
uint32_t bytes_sent = 0;
sprintf(&cmd[2], "%u", flash_addr);
sprintf(&cmd[strlen(cmd)], " %u\r\n", bytes_to_tx);
serial_tx(cmd, strlen(cmd));
isp_cmd_response_enum response = parse_command_response(CMD_RESPONSE_TOKEN_COUNT);
if(response == RESPONSE_CMD_SUCCESS) {
for(uint32_t i=0; i<buffer_len; i++) {
bytes_sent += serial_tx(uu_buffer[i].data, strlen(uu_buffer[i].data));
}
}
printf("Device expects %d bytes, we send %d bytes", bytes_to_tx, bytes_sent);
}
My confusion and I think error lies in the number of bytes to send. The data sheet states we should send 20 uuencoded lines. Each line contains 45 bytes of data but 61 characters. So is my tx size 45*20 or 60*20? Neither of these seem to work.