From 3672c0f986d46f64873306d2f18b93d88ef52325 Mon Sep 17 00:00:00 2001 From: yul Date: Sun, 22 May 2022 23:44:17 +0200 Subject: [PATCH] data works! ok doesn't! --- iap.c | 5 +++-- uart.c | 7 ++++--- uart_commands.c | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/iap.c b/iap.c index 7bc2a32..8b17925 100644 --- a/iap.c +++ b/iap.c @@ -97,15 +97,16 @@ void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int //iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes); command[0] = 51; command[1] = dst_flash; - command[2] = *src_ram; + command[2] = src_ram; command[3] = num_bytes; + command[4] = 100000; iap_entry_wrapped(); if(output[0] == IAP_CMD_SUCCESS) { iap_everything_is_alright(); *status = 0; }else{ iap_something_went_wrong(output[0]); - *status = -1; + *status = output[0]; } } diff --git a/uart.c b/uart.c index a557570..eb655d5 100644 --- a/uart.c +++ b/uart.c @@ -34,11 +34,12 @@ void uart_init(uint32_t baudrate){ void uart_send(char* buff, uint32_t length){ int tmp; while (length-- != 0 ){ - LPC_UART0->THR = *buff++; + //LPC_UART0->THR = *buff++; while(((LPC_UART0->LSR)&(1<<5)) == 0);//stuck in while when U1THR contains valid data + LPC_UART0->THR = *buff++; tmp = LPC_UART0->RBR; - LPC_GPIO2->FIOCLR = 0xff; - LPC_GPIO2->FIOSET = tmp; + //LPC_GPIO2->FIOCLR = 0xff; + //LPC_GPIO2->FIOSET = tmp; } } diff --git a/uart_commands.c b/uart_commands.c index e32740e..7128988 100644 --- a/uart_commands.c +++ b/uart_commands.c @@ -1,6 +1,6 @@ #include "uart_commands.h" -static uint8_t data[4096]; +static uint8_t data[1024]; char OK[5] = "OK\r\n"; char ERR[6] = "ERR\r\n"; @@ -42,35 +42,41 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1); iap_erase_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1); iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1); + *checksum_global = crc_update(*checksum_global, data, size); while(tmp >= 4096){ - iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 4096); + iap_copy_to_flash(status, offset/0x1000, checksum_global, 4096); if(*status != ok){ uart_send(ERR, 6); + return *status; } tmp = tmp - 4096; } while(tmp >= 1024){ - iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 1024); + //iap_copy_to_flash(status, offset/0x1000, checksum_global, 1024); + iap_copy_to_flash(status, offset, checksum_global, 1024); if(*status != ok){ uart_send(ERR, 6); + return *status; } tmp = tmp - 1024; } while(tmp >= 512){ - iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 512); + iap_copy_to_flash(status, offset/0x1000, checksum_global, 512); if(*status != ok){ uart_send(ERR, 6); + return *status; } tmp = tmp - 512; } while(tmp >= 256){ - iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 256); + iap_copy_to_flash(status, offset/0x1000, checksum_global, 256); if(*status != ok){ uart_send(ERR, 6); + return *status; } tmp = tmp - 256; } - *checksum_global = crc_update(*checksum_global, data, size); + uart_send(OK, 4); return ok; }else{ uart_send(ERR, 6);