data works! ok doesn't!

This commit is contained in:
yul 2022-05-22 23:44:17 +02:00
parent 8ee6dff899
commit 3672c0f986
3 changed files with 19 additions and 11 deletions

5
iap.c
View File

@ -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); //iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes);
command[0] = 51; command[0] = 51;
command[1] = dst_flash; command[1] = dst_flash;
command[2] = *src_ram; command[2] = src_ram;
command[3] = num_bytes; command[3] = num_bytes;
command[4] = 100000;
iap_entry_wrapped(); iap_entry_wrapped();
if(output[0] == IAP_CMD_SUCCESS) { if(output[0] == IAP_CMD_SUCCESS) {
iap_everything_is_alright(); iap_everything_is_alright();
*status = 0; *status = 0;
}else{ }else{
iap_something_went_wrong(output[0]); iap_something_went_wrong(output[0]);
*status = -1; *status = output[0];
} }
} }

7
uart.c
View File

@ -34,11 +34,12 @@ void uart_init(uint32_t baudrate){
void uart_send(char* buff, uint32_t length){ void uart_send(char* buff, uint32_t length){
int tmp; int tmp;
while (length-- != 0 ){ 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 while(((LPC_UART0->LSR)&(1<<5)) == 0);//stuck in while when U1THR contains valid data
LPC_UART0->THR = *buff++;
tmp = LPC_UART0->RBR; tmp = LPC_UART0->RBR;
LPC_GPIO2->FIOCLR = 0xff; //LPC_GPIO2->FIOCLR = 0xff;
LPC_GPIO2->FIOSET = tmp; //LPC_GPIO2->FIOSET = tmp;
} }
} }

View File

@ -1,6 +1,6 @@
#include "uart_commands.h" #include "uart_commands.h"
static uint8_t data[4096]; static uint8_t data[1024];
char OK[5] = "OK\r\n"; char OK[5] = "OK\r\n";
char ERR[6] = "ERR\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_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
iap_erase_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); iap_prepare_sectors(status, APP_OFFSET, APP_OFFSET+size/4095+1);
*checksum_global = crc_update(*checksum_global, data, size);
while(tmp >= 4096){ 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){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
return *status;
} }
tmp = tmp - 4096; tmp = tmp - 4096;
} }
while(tmp >= 1024){ 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){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
return *status;
} }
tmp = tmp - 1024; tmp = tmp - 1024;
} }
while(tmp >= 512){ 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){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
return *status;
} }
tmp = tmp - 512; tmp = tmp - 512;
} }
while(tmp >= 256){ 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){ if(*status != ok){
uart_send(ERR, 6); uart_send(ERR, 6);
return *status;
} }
tmp = tmp - 256; tmp = tmp - 256;
} }
*checksum_global = crc_update(*checksum_global, data, size); uart_send(OK, 4);
return ok; return ok;
}else{ }else{
uart_send(ERR, 6); uart_send(ERR, 6);