empty message
This commit is contained in:
parent
ae3e68c12b
commit
84caa2db3b
10
bootloader.c
10
bootloader.c
|
@ -21,10 +21,11 @@
|
||||||
|
|
||||||
error_code status;
|
error_code status;
|
||||||
|
|
||||||
char okk[4] = "OK\r\n";
|
/*
|
||||||
char errr[5] = "ERR\r\n";
|
is_even_assembly:
|
||||||
|
ldr sp, [r0]
|
||||||
|
ret
|
||||||
|
*/
|
||||||
|
|
||||||
char* argvs[3][10];
|
char* argvs[3][10];
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ int main(void) {
|
||||||
crc_prog = uart_string_to_int(cmd.argv[3]);
|
crc_prog = uart_string_to_int(cmd.argv[3]);
|
||||||
total_size = uart_string_to_int(cmd.argv[2]);
|
total_size = uart_string_to_int(cmd.argv[2]);
|
||||||
offset = uart_string_to_int(cmd.argv[1]);
|
offset = uart_string_to_int(cmd.argv[1]);
|
||||||
|
SCB->VTOR = offset;
|
||||||
crc_data = uart_commands_prog(&status, total_size);
|
crc_data = uart_commands_prog(&status, total_size);
|
||||||
offset_pointer = offset;
|
offset_pointer = offset;
|
||||||
|
|
||||||
|
|
118
uart_commands.c
118
uart_commands.c
|
@ -5,9 +5,103 @@ 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";
|
||||||
|
|
||||||
void digit_to_str(char* str, uint32_t number){
|
void digit_to_str(char* str, uint32_t number, int base){
|
||||||
itoa(number,str,16);
|
itoa(number,str,16);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
void digit_to_str(char* str, uint32_t number, int base){
|
||||||
|
char tmp_char[32];
|
||||||
|
uint32_t tmp = number;
|
||||||
|
int tmp_counter = 0;
|
||||||
|
for(int i = 0; i<32; i++);
|
||||||
|
switch (tmp & 15)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
tmp_char[tmp_counter] = '0';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
tmp_char[tmp_counter] = '1';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
tmp_char[tmp_counter] = '2';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
tmp_char[tmp_counter] = '3';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
tmp_char[tmp_counter] = '4';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
tmp_char[tmp_counter] = '5';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
tmp_char[tmp_counter] = '6';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
tmp_char[tmp_counter] = '7';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
tmp_char[tmp_counter] = '8';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
tmp_char[tmp_counter] = '9';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
tmp_char[tmp_counter] = 'a';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
tmp_char[tmp_counter] = 'b';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
tmp_char[tmp_counter] = 'c';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
tmp_char[tmp_counter] = 'd';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
tmp_char[tmp_counter] = 'e';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
tmp_char[tmp_counter] = 'f';
|
||||||
|
tmp_counter++;
|
||||||
|
tmp=tmp/base;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for(int i = 0; i<tmp_counter; i++){
|
||||||
|
str[i] = tmp_char[tmp_counter-i];
|
||||||
|
}
|
||||||
|
str[tmp_counter] = '\0';
|
||||||
|
}*/
|
||||||
|
|
||||||
int addr_to_sector(int addr){
|
int addr_to_sector(int addr){
|
||||||
int tmp = addr & 0xfffff;
|
int tmp = addr & 0xfffff;
|
||||||
|
@ -43,9 +137,9 @@ void uart_commands_getid(error_code* status){
|
||||||
char hex[15] = "0x26113f37\r\n";
|
char hex[15] = "0x26113f37\r\n";
|
||||||
//char hex[15];
|
//char hex[15];
|
||||||
uint32_t res = iap_read_part_id(status);
|
uint32_t res = iap_read_part_id(status);
|
||||||
//digit_to_str(hex+2, res);
|
//digit_to_str(hex+1, res, 16);
|
||||||
//hex[0]='0';
|
hex[0]='0';
|
||||||
//hex[1]='x';
|
hex[1]='x';
|
||||||
//sprintf(hex, "0x%x\r\n", res);
|
//sprintf(hex, "0x%x\r\n", res);
|
||||||
if(*status == 0){
|
if(*status == 0){
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
|
@ -58,6 +152,12 @@ void uart_commands_getserial(error_code* status){
|
||||||
char hex[40] = "0x8005018af27a5225a541628f50020c0\r\n";
|
char hex[40] = "0x8005018af27a5225a541628f50020c0\r\n";
|
||||||
uint32_t res[4];
|
uint32_t res[4];
|
||||||
iap_read_serial(status, res);
|
iap_read_serial(status, res);
|
||||||
|
/*digit_to_str(hex+1, res[0], 16);
|
||||||
|
digit_to_str(hex+9, res[1], 16);
|
||||||
|
digit_to_str(hex+17, res[2], 16);
|
||||||
|
digit_to_str(hex+25, res[3], 16);*/
|
||||||
|
hex[0]='0';
|
||||||
|
hex[1]='x';
|
||||||
//sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]);
|
//sprintf(hex, "0x%x%x%x%x\r\n", res[0], res[1], res[2], res[3]);
|
||||||
if(*status == 0){
|
if(*status == 0){
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
|
@ -74,19 +174,19 @@ crc_t uart_commands_prog(error_code* status, int size){
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
itoa(*status, &digit, 10);
|
itoa(*status, &digit, 10);
|
||||||
uart_send(digit, 1);
|
uart_send(&digit, 1);
|
||||||
}
|
}
|
||||||
iap_erase_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size));
|
iap_erase_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size));
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
itoa(*status, &digit, 10);
|
itoa(*status, &digit, 10);
|
||||||
uart_send(digit, 1);
|
uart_send(&digit, 1);
|
||||||
}
|
}
|
||||||
iap_prepare_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size));
|
iap_prepare_sectors(status, addr_to_sector(APP_OFFSET), addr_to_sector(APP_OFFSET+size));
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
itoa(*status, &digit, 10);
|
itoa(*status, &digit, 10);
|
||||||
uart_send(digit, 1);
|
uart_send(&digit, 1);
|
||||||
}
|
}
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
return crc_init();
|
return crc_init();
|
||||||
|
@ -115,7 +215,7 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob
|
||||||
if(*status != ok){
|
if(*status != ok){
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
itoa(*status, &digit, 10);
|
itoa(*status, &digit, 10);
|
||||||
uart_send(digit, 1);
|
uart_send(&digit, 1);
|
||||||
return *status;
|
return *status;
|
||||||
}
|
}
|
||||||
uart_send_ok();
|
uart_send_ok();
|
||||||
|
@ -123,7 +223,7 @@ error_code uart_commands_data(error_code* status, int size, crc_t* checksum_glob
|
||||||
}else{
|
}else{
|
||||||
uart_send_err();
|
uart_send_err();
|
||||||
itoa(*status, &digit, 10);
|
itoa(*status, &digit, 10);
|
||||||
uart_send(digit, 1);
|
uart_send(&digit, 1);
|
||||||
}
|
}
|
||||||
return local_checksum;
|
return local_checksum;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,6 @@ void uart_send_err();
|
||||||
|
|
||||||
int addr_to_sector(int addr);
|
int addr_to_sector(int addr);
|
||||||
|
|
||||||
void digit_to_str(char* str, uint32_t number);
|
void digit_to_str(char* str, uint32_t number, int base);
|
||||||
|
|
||||||
uint32_t uart_string_to_int(const char* str);
|
uint32_t uart_string_to_int(const char* str);
|
||||||
|
|
Loading…
Reference in New Issue