diff --git a/bootloader.c b/bootloader.c index 71cd22f..8265a4c 100644 --- a/bootloader.c +++ b/bootloader.c @@ -39,6 +39,7 @@ crc_t crc_prog, crc_data; // TODO: insert other definitions and declarations here char buff[256]; + int main(void) { uart_init(115200); while(1){ @@ -60,7 +61,8 @@ int main(void) { }else if(strcmp("DATA", cmd.argv[0])==0){ int size = uart_string_to_int(cmd.argv[1]); crc_t local_checksum = uart_string_to_int(cmd.argv[2]); - uart_commands_data(&status, size, &crc_data, local_checksum, offset_pointer); + //uart_commands_data(&status, size, &crc_data, local_checksum, offset_pointer); + uart_commands_data(&status, size, &crc_data, crc_data, offset_pointer); if(status == 0) offset_pointer += size; }else if(strcmp("CHECK", cmd.argv[0])==0){ diff --git a/iap.c b/iap.c index 2b2e22f..7bc2a32 100644 --- a/iap.c +++ b/iap.c @@ -92,8 +92,9 @@ uint32_t iap_read_part_id(error_code* status){ } void iap_copy_to_flash(error_code* status, int dst_flash, uint32_t* src_ram, int num_bytes){ - iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes); - //iap_prepare_sectors(2, 9); + //iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes); + //iap_erase_sectors(status, dst_flash, dst_flash+num_bytes); + //iap_prepare_sectors(status, dst_flash, dst_flash+num_bytes); command[0] = 51; command[1] = dst_flash; command[2] = *src_ram; diff --git a/uart.c b/uart.c index 5559b9c..a557570 100644 --- a/uart.c +++ b/uart.c @@ -45,21 +45,27 @@ void uart_send(char* buff, uint32_t length){ void uart_receive_command(char* chara){ char* curr = chara; + while(((LPC_UART0->LSR)&(1)) == 0); + *curr = LPC_UART0->RBR; //while(strncmp("\r\n",curr, 2) != 0){ while(*curr != '\n'){ + if((*curr != '\n')) curr++; while(((LPC_UART0->LSR)&(1)) == 0); *curr = LPC_UART0->RBR; //if(strncmp("\r\n",curr, 2) != 0) curr++; - if((*curr != '\n')) curr++; } } -void uart_receive_data(uint8_t* chara){ +void uart_receive_data(uint8_t* chara, int size){ //size parameter add while size != size_given uint8_t* curr = chara; - while(*curr != '\0'){ - while(((LPC_UART0->LSR)&(1)) == 0); - *curr = LPC_UART0->RBR; - curr++; + //while(((LPC_UART0->LSR)&(1)) == 0); + for(int i = 0; i < size/2; i++){ + while(((LPC_UART0->LSR)&(1)) == 0); + curr[2*i] = LPC_UART0->RBR; + while(((LPC_UART0->LSR)&(1)) == 0); + curr[2*i+1] = LPC_UART0->RBR; + //while(((LPC_UART0->LSR)&(1)) == 0); + //curr[2*i] = LPC_UART0->RBR; } } diff --git a/uart.h b/uart.h index c54416f..170ea80 100644 --- a/uart.h +++ b/uart.h @@ -44,7 +44,7 @@ void uart_send(char* buff, uint32_t length); void uart_receive_command(char* chara); -void uart_receive_data(uint8_t* chara); +void uart_receive_data(uint8_t* chara, int size); #define THRE (1<<5) diff --git a/uart_commands.c b/uart_commands.c index acce2bb..e32740e 100644 --- a/uart_commands.c +++ b/uart_commands.c @@ -28,39 +28,43 @@ void uart_commands_getserial(error_code* status){ } crc_t uart_commands_prog(void){ - return crc_init(); uart_send(OK, 5); + return crc_init(); } error_code uart_commands_data(error_code* status, int size, crc_t* checksum_global, crc_t checksum_loc, int offset){ - uart_receive_data(data); + uart_receive_data(data, size); crc_t checksum_tmp = crc_init(); checksum_tmp = crc_update(checksum_tmp, data, size); + checksum_tmp = crc_finalize(checksum_tmp); if(checksum_loc == checksum_tmp){ int tmp = size; - while(tmp > 4096){ - iap_copy_to_flash(status, offset, &checksum_loc, 4096); + 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); + while(tmp >= 4096){ + iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 4096); if(*status != ok){ uart_send(ERR, 6); } tmp = tmp - 4096; } - while(tmp > 1024){ - iap_copy_to_flash(status, offset, &checksum_loc, 1024); + while(tmp >= 1024){ + iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 1024); if(*status != ok){ uart_send(ERR, 6); } tmp = tmp - 1024; } - while(tmp > 512){ - iap_copy_to_flash(status, offset, &checksum_loc, 512); + while(tmp >= 512){ + iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 512); if(*status != ok){ uart_send(ERR, 6); } tmp = tmp - 512; } - while(tmp > 256){ - iap_copy_to_flash(status, offset, &checksum_loc, 256); + while(tmp >= 256){ + iap_copy_to_flash(status, offset/0x1000, &checksum_loc, 256); if(*status != ok){ uart_send(ERR, 6); } @@ -108,6 +112,6 @@ int uart_parse_command(char *user_input, cmd_t *cmd) { uint32_t uart_string_to_int(const char *str) { // Convert input in port number char* tmp; - unsigned long int hex = strtoul(str, tmp, 16); + unsigned long long int hex = strtoull(str, &tmp, 16); return hex; } diff --git a/uart_commands.h b/uart_commands.h index 29f959c..6cead02 100644 --- a/uart_commands.h +++ b/uart_commands.h @@ -6,7 +6,8 @@ #include "iap.h" #include "crc.h" -#define DELIMIERS ',' +#define DELIMIERS "," +#define APP_OFFSET 4