diff --git a/bootloader.c b/bootloader.c index 078405a..fe0b44f 100644 --- a/bootloader.c +++ b/bootloader.c @@ -105,6 +105,7 @@ void manage_bootloader(){ cmd.argv = (char**)argvs; int var = 1; char digit; + set_colour(GREEN); while(var){ uart_receive_command(buff); uart_parse_command(buff, &cmd); diff --git a/iap.c b/iap.c index 714fde9..924e8e2 100644 --- a/iap.c +++ b/iap.c @@ -18,7 +18,7 @@ unsigned int command[5]; unsigned int output[5]; IAP iap_entry =(IAP) IAP_LOCATION; -int addr_to_sector(int addr){ +int addr_to_sector(unsigned long int addr){ int tmp = addr & 0xfffff; tmp = tmp >> 12; if(tmp <= 15) return tmp; @@ -46,6 +46,7 @@ int addr_to_sector(int addr){ else if(tmp >= 0x70 && tmp <= 0x77) return 28; else if(tmp >= 0x78 && tmp <= 0x7f) return 29; } + return -1; } void iap_entry_wrapped(void){ @@ -94,11 +95,11 @@ uint32_t iap_read_part_id(error_code* status){ } } -void iap_copy_to_flash(error_code* status, long unsigned int * dst_flash, long unsigned int* src_ram, int num_bytes){ - iap_prepare_sectors(status, addr_to_sector(dst_flash), addr_to_sector(dst_flash+num_bytes)); +void iap_copy_to_flash(error_code* status, long unsigned int* dst_flash, uint8_t* src_ram, int num_bytes){ + iap_prepare_sectors(status, addr_to_sector((long unsigned int)dst_flash), addr_to_sector((long unsigned int)dst_flash+num_bytes)); command[0] = 51; - command[1] = dst_flash; - command[2] = src_ram; + command[1] = (unsigned int)dst_flash; + command[2] = (unsigned int)src_ram; command[3] = num_bytes; command[4] = IAP_CLOCK_100M; iap_entry_wrapped(); @@ -124,14 +125,3 @@ void iap_read_serial(error_code* status, uint32_t* res){ } } -// TODO: insert other include files here - -// TODO: insert other definitions and declarations here -/* -int main(void) { - LPC_PINCON->PINSEL4 &= ~0xFF; //Configure the PORT2 Pins as GPIO; - LPC_GPIO2->FIODIR = 0xff; //Configure the PORT2 pins as OUTPUT; - iap_read_part_id(); - iap_erase_sectors(2, 9); - iap_copy_to_flash(0x8000,(uint8_t*)test, 4); -}*/ diff --git a/iap.h b/iap.h index 5a584c7..eace88d 100644 --- a/iap.h +++ b/iap.h @@ -34,10 +34,10 @@ void iap_prepare_sectors(error_code* status, int start, int end); void iap_erase_sectors(error_code* status, int start, int end); -void iap_copy_to_flash(error_code* status, long unsigned int * dst_flash, long unsigned int* src_ram, int num_bytes); +void iap_copy_to_flash(error_code* status, long unsigned int * dst_flash, uint8_t* src_ram, int num_bytes); uint32_t iap_read_part_id(error_code* status); void iap_read_serial(error_code* status, uint32_t* res); -int addr_to_sector(int addr); +int addr_to_sector(unsigned long int addr); diff --git a/uart.c b/uart.c index 9e34a0e..4baefc2 100644 --- a/uart.c +++ b/uart.c @@ -32,14 +32,12 @@ void uart_init(uint32_t baudrate){ } void uart_send(char* buff, uint32_t length){ - int tmp; + //int tmp; while (length-- != 0 ){ //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; + //tmp = LPC_UART0->RBR; } } diff --git a/uart_commands.c b/uart_commands.c index 438fceb..bd8e6ab 100644 --- a/uart_commands.c +++ b/uart_commands.c @@ -57,8 +57,6 @@ void uart_commands_getserial(error_code* status){ crc_t uart_commands_prog(error_code* status, int size){ char digit; - int start = addr_to_sector(APP_OFFSET); - int end = addr_to_sector(APP_OFFSET+size); iap_prepare_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size)); if(*status != ok){ uart_send_err(); @@ -87,16 +85,14 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob crc_t checksum_tmp = crc_init(); checksum_tmp = crc_update(checksum_tmp, data, size); checksum_tmp = crc_finalize(checksum_tmp); - int offset_counter = offset; if(checksum_loc == checksum_tmp){ - int tmp = size; iap_prepare_sectors(status, addr_to_sector(offset), addr_to_sector(offset+size)+1); *checksum_global = crc_update(*checksum_global, data, size); //verify if size == 4095 if smaller if(size == 0x0400) - iap_copy_to_flash(status, offset, data, size); + iap_copy_to_flash(status, (long unsigned int *)offset, data, size); else{ - iap_copy_to_flash(status, offset, data, 0x400); + iap_copy_to_flash(status, (long unsigned int *)offset, data, 0x400); *checksum_global = crc_finalize(*checksum_global); } if(*status != ok){