Selaa lähdekoodia

HFR 작업 내용 Download 완료 / Bank image 이름 업데이트

PYJ 5 vuotta sitten
vanhempi
commit
5d1a07edfd

+ 7 - 4
Bluecell_Src/Bluecell_operate.c

@@ -3070,7 +3070,7 @@ typedef enum{
3070 3070
         PrevMBIC_DL_ShutdownCount[i] = 0xFF;        
3071 3071
     }
3072 3072
 
3073
-  printf("Type %x  Ready....\r\n",bluecell_Currdatastatus.Type);
3073
+//  printf("Type %x  Ready....\r\n",bluecell_Currdatastatus.Type);
3074 3074
 
3075 3075
   //  printf("bluecell_Currdatastatus.Type : %02x \r\n",bluecell_Currdatastatus.Type);
3076 3076
 #if 1 // PYJ.2020.06.17_BEGIN -- 
@@ -3082,7 +3082,7 @@ typedef enum{
3082 3082
     
3083 3083
     HAL_GPIO_WritePin(PATH_EN_UL1_GPIO_Port,PATH_EN_UL1_Pin,bluecell_Currdatastatus.ATT_UL1_PATH);   
3084 3084
     HAL_GPIO_WritePin(PATH_EN_UL2_GPIO_Port,PATH_EN_UL2_Pin,bluecell_Currdatastatus.ATT_UL2_PATH);   
3085
-    printf("bluecell_Currdatastatus.ATT_UL2_PATH : %d \r\n",bluecell_Currdatastatus.ATT_UL2_PATH);
3085
+//    printf("bluecell_Currdatastatus.ATT_UL2_PATH : %d \r\n",bluecell_Currdatastatus.ATT_UL2_PATH);
3086 3086
     HAL_GPIO_WritePin(PATH_EN_UL3_GPIO_Port,PATH_EN_UL3_Pin,bluecell_Currdatastatus.ATT_UL3_PATH);   
3087 3087
     HAL_GPIO_WritePin(PATH_EN_UL4_GPIO_Port,PATH_EN_UL4_Pin,bluecell_Currdatastatus.ATT_UL4_PATH);   
3088 3088
 #endif // PYJ.2020.06.17_END -- 
@@ -3210,7 +3210,7 @@ uint32_t MBIC_DataSend(uint8_t* data){
3210 3210
     data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPUVERSION1;
3211 3211
     data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPUVERSION2;
3212 3212
     data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPUVERSION3;
3213
-    
3213
+//    printf("Version [3] : %x\r\n ",bluecell_Currdatastatus.CPUVERSION3);
3214 3214
 
3215 3215
 
3216 3216
     /*CPU_Current_Bank*/
@@ -3248,9 +3248,12 @@ uint32_t MBIC_DataSend(uint8_t* data){
3248 3248
     data[MBIC_PAYLOADSTART + i++] = CPU_Bank1_Image_Name;
3249 3249
     data[MBIC_PAYLOADSTART + i++] = 32; // LENGTH
3250 3250
     Length += 32;  
3251
+    uint8_t* tmpstr = &bluecell_Currdatastatus.CPU_Bank1_Image_Name;
3251 3252
     for(int a = 0; a < 32; a++){
3252 3253
         data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_Name[a];
3254
+//        printf("%x ",tmpstr[a]);
3253 3255
     }
3256
+//    printf("\r\n");
3254 3257
 
3255 3258
     /*CPU_Bank2_Image_Version*/
3256 3259
     data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
@@ -3325,7 +3328,7 @@ uint32_t MBIC_DataSend(uint8_t* data){
3325 3328
     data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
3326 3329
     Length += 1;
3327 3330
     data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Type;
3328
-    printf(" bluecell_Currdatastatus.Type : %x \r\n", bluecell_Currdatastatus.Type);
3331
+//    printf(" bluecell_Currdatastatus.Type : %x \r\n", bluecell_Currdatastatus.Type);
3329 3332
      /*PCB_Version*/
3330 3333
     data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
3331 3334
     data[MBIC_PAYLOADSTART + i++] = PCB_Version;

+ 110 - 18
Bluecell_Src/MBIC_Bootloader.c

@@ -14,7 +14,7 @@
14 14
 #include "CRC.h"
15 15
 #include "uart.h"
16 16
 
17
-extern __IO bool EraseInit;
17
+extern bool EraseInit;
18 18
 
19 19
 extern uint8_t Bank_Flash_write(uint8_t* data,uint32_t StartBankAddress);
20 20
 extern void MBIC_DataErase_Func(uint8_t bank_num);
@@ -211,14 +211,13 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
211 211
     static uint32_t Prev_Download_DataIndex = 0;    
212 212
     uint32_t TotalFrame = 0;
213 213
     uint32_t CurrFrame = 0;
214
-    uint32_t PrevFrame = 0 ;
215 214
     static uint32_t prevFrame = 0xFF;
216
-    
215
+     uint8_t* tmpstr;
217 216
     uint16_t DataLength = 0;
218 217
     uint16_t Crcret = 0;
219 218
     uint16_t RecvCrc = 0;
220 219
     uint32_t i = 0 ;
221
-    uint32_t FirmFile_Length  = 0;
220
+    int32_t FirmFile_Length  = 0;
222 221
     uint32_t  CurrApiAddress = 0,Bank1Address=0,Bank2Address = 0;
223 222
     static uint8_t BankNum = 0;
224 223
     static bool CRCERR = false;
@@ -249,14 +248,14 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
249 248
 //        printf("%c",*data++);
250 249
     switch(cmd){
251 250
         case MBIC_Notice_REQ:
251
+            EraseInit = false;
252 252
             Download_Option = 0;
253 253
             Curr_Download_DataIndex = 0;
254 254
             Prev_Download_DataIndex = 0;
255
-            
255
+            prevFrame = 0xFF;
256 256
             printf("MBIC DOWNLOAD REQUEST \r\n");
257 257
             cmd = MBIC_Notice_RSP;
258 258
             CRCERR = false;
259
-            EraseInit = false;
260 259
             /*TOTAL FRAME NUMBER*/
261 260
             data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];
262 261
             data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];        
@@ -274,7 +273,11 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
274 273
             data[MBIC_PAYLOADSTART + index++] = 0;
275 274
             data[MBIC_PAYLOADSTART + index++] = 0;
276 275
             data[MBIC_PAYLOADSTART + index++] = 0;
277
-           
276
+              if(bluecell_Currdatastatus.CPU_Current_Bank == HFR_BANK1){
277
+                BankNum = HFR_BANK2;
278
+              }else{
279
+                BankNum = HFR_BANK1;
280
+              }           
278 281
 //            MBIC_DataBankWrite(1);
279 282
             //if()
280 283
 //            MBIC_DataErase_Func(bluecell_Currdatastatus.CPU_Bank_Select);
@@ -319,18 +322,31 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
319 322
 #endif // PYJ.2020.06.24_END -- 
320 323
 //            printf("Data End\r\n");
321 324
 //            Bank_Flash_write(data,FLASH_USER_BANK1_START_ADDR);
322
-              if(Currdata[MBIC_BOOT_VERSION + 3] == Bank1data[MBIC_BOOT_VERSION + 3]){
323
-                BankNum = HFR_BANK2;
325
+
326
+              if(prevFrame != CurrFrame){
327
+                MBIC_APIFLASH_Func(&data[MBIC_PAYLOADSTART + 12],1024,BankNum);
324 328
               }else{
325
-                BankNum = HFR_BANK1;
329
+                if(MBIC_Address < FLASH_USER_BANK2_START_ADDR)
330
+                    MBIC_Address = FLASH_USER_BANK2_START_ADDR + (CurrFrame * 1024);
331
+                else
332
+                    MBIC_Address = FLASH_USER_BANK1_START_ADDR + (CurrFrame * 1024);
333
+                
334
+                printf("Frame Retry \r\n");
326 335
               }
327
-              MBIC_APIFLASH_Func(&data[MBIC_PAYLOADSTART + 12],1024,BankNum);
328
-              printf("Bank1data[MBIC_BOOT_MARK] : %d \r\n",Bank2data[MBIC_BOOT_MARK]);
336
+#if 0 // PYJ.2020.06.29_BEGIN -- 
337
+              if(BankNum == HFR_BANK1){
338
+                  printf("Bank1data[MBIC_BOOT_MARK] : %d \r\n",Bank1data[MBIC_BOOT_MARK]);
339
+              }else{
340
+
341
+                  printf("Bank1data[MBIC_BOOT_MARK] : %d \r\n",Bank2data[MBIC_BOOT_MARK]);
342
+              }
343
+              
344
+#endif // PYJ.2020.06.29_END -- 
329 345
 //              if(BankNum == HFR_BANK1)
330 346
 //                  Crcret = CRC16_Generate(&Bank1data[MBIC_BOOT_MARK], TotalFrame);
331 347
 //              else
332 348
 //                Crcret = CRC16_Generate(&Bank2data[MBIC_BOOT_MARK], TotalFrame);
333
-                printf("CurrFrame : %d ,FirmFile_Length : %d \r\n",CurrFrame,TotalFrame);
349
+                printf("CurrFrame : %d ,FirmFile_Length : %d \r\n",CurrFrame,TotalFrame - 1);
334 350
                 printf("FILE CRC RET : %x \r\n",Crcret);              
335 351
 
336 352
 //            HAL_Delay(100);
@@ -339,14 +355,17 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
339 355
 
340 356
             break;
341 357
         case MBIC_Download_Confirm_REQ:
342
-            EraseInit = true;
358
+            
359
+            printf("MBIC_Download_Confirm_REQ \r\n");
343 360
             cmd = MBIC_Download_Confirm_RSP;
344 361
             /*TOTAL FRAME NUMBER*/
362
+             
345 363
             if(BankNum == HFR_BANK1){
346 364
                 FirmFile_Length = (Bank1data[MBIC_BOOT_LENGTH + 0] << 24)
347 365
                                 | Bank1data[MBIC_BOOT_LENGTH + 1] << 16
348 366
                                 | Bank1data[MBIC_BOOT_LENGTH + 2] << 8
349 367
                                 | Bank1data[MBIC_BOOT_LENGTH + 3];
368
+                FirmFile_Length += 128;
350 369
                 Crcret = CRC16_Generate(&Bank1data[MBIC_BOOT_MARK], FirmFile_Length);
351 370
                 printf("Bank 1 CRC Calc\r\n");                
352 371
             }
@@ -354,13 +373,14 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
354 373
                  FirmFile_Length = (Bank2data[MBIC_BOOT_LENGTH + 0] << 24)
355 374
                                 | Bank2data[MBIC_BOOT_LENGTH + 1] << 16
356 375
                                 | Bank2data[MBIC_BOOT_LENGTH + 2] << 8
357
-                                | Bank2data[MBIC_BOOT_LENGTH + 3];           
358
-                Crcret = CRC16_Generate(&Bank2data[MBIC_BOOT_MARK], FirmFile_Length - 1);
376
+                                | Bank2data[MBIC_BOOT_LENGTH + 3];   
377
+                FirmFile_Length += 128;
378
+                Crcret = CRC16_Generate(&Bank2data[MBIC_BOOT_MARK], FirmFile_Length);
359 379
                 printf("Bank 2 CRC Calc\r\n");
360 380
             }
361 381
             RecvCrc = data[MBIC_PAYLOADSTART] << 8 | data[MBIC_PAYLOADSTART + 1];
362 382
 
363
-            printf("FirmFile_Length : %x \r\n",FirmFile_Length);
383
+            printf("FirmFile_Length : %x \r\n",FirmFile_Length + 128);
364 384
             printf("FILE CRC RET : %x \r\n",Crcret);
365 385
         
366 386
             data[MBIC_PAYLOADSTART + index++] = ((Crcret & 0xFF00) >> 8);
@@ -383,18 +403,90 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
383 403
             data[MBIC_PAYLOADSTART + index++] = 0;
384 404
             data[MBIC_PAYLOADSTART + index++] = 0;
385 405
             data[MBIC_PAYLOADSTART + index++] = 0;
406
+//         if(BankNum == HFR_BANK1){
407
+//            bluecell_Currdatastatus.CPUVERSION1 = Bank1data[MBIC_BOOT_VERSION];
408
+//            bluecell_Currdatastatus.CPUVERSION2 = Bank1data[MBIC_BOOT_VERSION + 1];
409
+//            bluecell_Currdatastatus.CPUVERSION3 = Bank1data[MBIC_BOOT_VERSION + 2];          
410
+//              printf("Bank1data[MBIC_BOOT_VERSION] : %d \r\n",Bank1data[MBIC_BOOT_VERSION + 2]);
411
+//          }else{
412
+//              bluecell_Currdatastatus.CPUVERSION1 = Bank2data[MBIC_BOOT_VERSION];
413
+//              bluecell_Currdatastatus.CPUVERSION2 = Bank2data[MBIC_BOOT_VERSION + 1];
414
+//              bluecell_Currdatastatus.CPUVERSION3 = Bank2data[MBIC_BOOT_VERSION + 2]; 
415
+//              printf("Bank2data[MBIC_BOOT_VERSION] : %d \r\n",Bank2data[MBIC_BOOT_VERSION + 2]);
416
+//          }   
417
+          bluecell_Currdatastatus.CPU_Bank1_Image_Version1 = Bank1data[MBIC_BOOT_VERSION];
418
+          bluecell_Currdatastatus.CPU_Bank1_Image_Version2 = Bank1data[MBIC_BOOT_VERSION + 1];
419
+          bluecell_Currdatastatus.CPU_Bank1_Image_Version3 = Bank1data[MBIC_BOOT_VERSION + 2];
420
+
421
+            bluecell_Currdatastatus.CPU_Bank2_Image_Version1 = Bank2data[MBIC_BOOT_VERSION];
422
+            bluecell_Currdatastatus.CPU_Bank2_Image_Version2 = Bank2data[MBIC_BOOT_VERSION + 1];
423
+            bluecell_Currdatastatus.CPU_Bank2_Image_Version3 = Bank2data[MBIC_BOOT_VERSION + 2];
424
+            
425
+             bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime1 = Bank1data[MBIC_BOOT_CREATION_TIME];
426
+            bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime2 = Bank1data[MBIC_BOOT_CREATION_TIME + 1];
427
+            bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime3 = Bank1data[MBIC_BOOT_CREATION_TIME + 2];         
428
+            bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime4 = Bank1data[MBIC_BOOT_CREATION_TIME + 3];         
429
+            bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime5 = Bank1data[MBIC_BOOT_CREATION_TIME + 4];         
430
+            bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime6 = Bank1data[MBIC_BOOT_CREATION_TIME + 5];   
386 431
 
432
+            
433
+             bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime1 = Bank2data[MBIC_BOOT_CREATION_TIME];
434
+            bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime2 = Bank2data[MBIC_BOOT_CREATION_TIME + 1];
435
+            bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime3 = Bank2data[MBIC_BOOT_CREATION_TIME + 2];         
436
+            bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime4 = Bank2data[MBIC_BOOT_CREATION_TIME + 3];         
437
+            bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime5 = Bank2data[MBIC_BOOT_CREATION_TIME + 4];         
438
+            bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime6 = Bank2data[MBIC_BOOT_CREATION_TIME + 5];   
439
+            tmpstr = &bluecell_Currdatastatus.CPU_Bank1_Image_Name;
440
+            for(int i = 0 ; i< 41; i++){
441
+                if(i < 32)
442
+                tmpstr[i] = Bank1data[MBIC_BOOT_FILENAME + i];
443
+                else
444
+                 tmpstr[i] = 0x20;
445
+                printf("%x",tmpstr[i]);
446
+            }  
447
+            tmpstr = &bluecell_Currdatastatus.CPU_Bank2_Image_Name;
448
+            for(int i = 0 ; i< 41; i++){
449
+                if(i < 32)
450
+                tmpstr[i] = Bank2data[MBIC_BOOT_FILENAME + i];
451
+                else
452
+                 tmpstr[i] = 0x20;
453
+
454
+                printf("%x",tmpstr[i]);
455
+            }               
456
+            printf("Curr Version : %02x.%02x.%02x \r\n",bluecell_Currdatastatus.CPUVERSION1,bluecell_Currdatastatus.CPUVERSION2,bluecell_Currdatastatus.CPUVERSION3);
457
+            printf("Bank1data Version : %02x.%02x.%02x \r\n", Bank1data[MBIC_BOOT_VERSION + 0], Bank1data[MBIC_BOOT_VERSION + 1], Bank1data[MBIC_BOOT_VERSION + 2]);
458
+            printf("Bank2data Version : %02x.%02x.%02x \r\n", Bank2data[MBIC_BOOT_VERSION + 0], Bank2data[MBIC_BOOT_VERSION + 1], Bank2data[MBIC_BOOT_VERSION + 2]);            
459
+        
387 460
         break;
388 461
         case MBIC_Complete_Notice_REQ_REQ:
462
+            printf("MBIC_Complete_Notice_REQ_REQ \r\n");
389 463
             cmd = MBIC_Complete_Notice_RSP;
390 464
             if(CRCERR == false){
391 465
                 data[MBIC_PAYLOADSTART + index++] = 1;  
392 466
             }else{
393 467
                 data[MBIC_PAYLOADSTART + index++] = 0;  
394 468
             }
395
-                data[MBIC_PAYLOADSTART + index++] = 1;              
469
+                data[MBIC_PAYLOADSTART + index++] = 1;    
470
+
471
+
472
+//          if(BankNum == HFR_BANK1){
473
+//            bluecell_Currdatastatus.CPUVERSION1 = Bank1data[MBIC_BOOT_VERSION];
474
+//            bluecell_Currdatastatus.CPUVERSION2 = Bank1data[MBIC_BOOT_VERSION + 1];
475
+//            bluecell_Currdatastatus.CPUVERSION3 = Bank1data[MBIC_BOOT_VERSION + 2];          
476
+//              printf("Bank1data[MBIC_BOOT_VERSION] : %d \r\n",Bank1data[MBIC_BOOT_VERSION]);
477
+//          }else{
478
+//              bluecell_Currdatastatus.CPUVERSION1 = Bank2data[MBIC_BOOT_VERSION];
479
+//              bluecell_Currdatastatus.CPUVERSION2 = Bank2data[MBIC_BOOT_VERSION + 1];
480
+//              bluecell_Currdatastatus.CPUVERSION3 = Bank2data[MBIC_BOOT_VERSION + 2]; 
481
+//
482
+//              printf("Bank1data[MBIC_BOOT_VERSION] : %d \r\n",Bank2data[MBIC_BOOT_VERSION]);
483
+//          }   
484
+            printf("Curr Version : %02x.%02x.%02x \r\n",bluecell_Currdatastatus.CPUVERSION1,bluecell_Currdatastatus.CPUVERSION2,bluecell_Currdatastatus.CPUVERSION3);
485
+            printf("Bank1data Version : %02x.%02x.%02x \r\n", Bank1data[MBIC_BOOT_VERSION + 0], Bank1data[MBIC_BOOT_VERSION + 1], Bank1data[MBIC_BOOT_VERSION + 2]);
486
+            printf("Bank2data Version : %02x.%02x.%02x \r\n", Bank2data[MBIC_BOOT_VERSION + 0], Bank2data[MBIC_BOOT_VERSION + 1], Bank2data[MBIC_BOOT_VERSION + 2]);
396 487
             break;
397 488
         case MBIC_Reboot_Notice_REQ:
489
+            printf("MBIC_Reboot_Notice_REQ\r\n");
398 490
             cmd = MBIC_Reboot_Notice_RSP;
399 491
             /*TOTAL FRAME NUMBER*/
400 492
             data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];

+ 5 - 5
Bluecell_Src/eeprom.c

@@ -90,10 +90,10 @@ void EEPROM_M24C08_Init(void){
90 90
     uint8_t* tmpdata;
91 91
     EEPROM_M24C08_Read(EEPROM_M24C08_ID,EEPROM_DET_DL4_TABLE_ADDRESDS,&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
92 92
     tmpdata = &Det_UL1.Table_Det_15_dBm_H;
93
-    for(int i =0; i < sizeof(DET_TABLEUL_st) ; i++){
94
-        printf("[%d]%f \r\n",i,(tmpdata[i * 2] << 8 | tmpdata[i*2+1])*0.001);
95
-    }
96
-    printf("");
93
+//    for(int i =0; i < sizeof(DET_TABLEUL_st) ; i++){
94
+//        printf("[%d]%f \r\n",i,(tmpdata[i * 2] << 8 | tmpdata[i*2+1])*0.001);
95
+//    }
96
+//    printf("");
97 97
     EEPROM_M24C08_Read(EEPROM_M24C08_ID,EEPROM_DET_UL1_TABLE_ADDRESDS,&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
98 98
 //    data = &Det_UL2.Table_Det_15_dBm_H;
99 99
 //    for(int i = 0; i < sizeof(DET_TABLEUL_st) ; i ++ ){
@@ -384,7 +384,7 @@ HAL_StatusTypeDef EEPROM_M24C08_write(uint8_t devid,uint16_t Address,uint8_t* da
384 384
           HAL_Delay(20);
385 385
         }
386 386
     }
387
-    printf("EEPROM WRITE\r\n");
387
+//    printf("EEPROM WRITE\r\n");
388 388
 
389 389
 #endif // PYJ.2020.04.25_END -- 
390 390
     return ret;

+ 50 - 72
Bluecell_Src/flash.c

@@ -74,14 +74,14 @@ void Flash_InitRead() // ?占쏙옙湲고븿?占쏙옙
74 74
     bluecell_Currdatastatus.CPUVERSION1 = Currdata[MBIC_BOOT_VERSION + 0];
75 75
     bluecell_Currdatastatus.CPUVERSION2 = Currdata[MBIC_BOOT_VERSION + 1];
76 76
     bluecell_Currdatastatus.CPUVERSION3 = Currdata[MBIC_BOOT_VERSION + 2];
77
+    for(int i =0; i < 3; i++)
78
+        printf("Bank1data[MBIC_BOOT_VERSION] : %d \r\n",Bank1data[MBIC_BOOT_VERSION + i]);
77 79
     
78
-    if(bluecell_Currdatastatus.CPUVERSION1 == Bank1data[MBIC_BOOT_VERSION + 0]
79
-    &&bluecell_Currdatastatus.CPUVERSION1 == Bank1data[MBIC_BOOT_VERSION + 1]
80
-    &&bluecell_Currdatastatus.CPUVERSION1 == Bank1data[MBIC_BOOT_VERSION + 2]){
80
+    if(bluecell_Currdatastatus.CPUVERSION3  == Bank1data[MBIC_BOOT_VERSION + 2]){
81 81
         bluecell_Currdatastatus.CPU_Current_Bank = HFR_BANK1_SEL;
82
-    }else if(bluecell_Currdatastatus.CPUVERSION1 == Bank2data[MBIC_BOOT_VERSION + 0]
83
-    &&bluecell_Currdatastatus.CPUVERSION1 == Bank2data[MBIC_BOOT_VERSION + 1]
84
-    &&bluecell_Currdatastatus.CPUVERSION1 == Bank2data[MBIC_BOOT_VERSION + 2]){
82
+    }
83
+    else 
84
+    {
85 85
         bluecell_Currdatastatus.CPU_Current_Bank = HFR_BANK2_SEL;
86 86
     }
87 87
     printf("Curr Version : %02x.%02x.%02x \r\n",bluecell_Currdatastatus.CPUVERSION1,bluecell_Currdatastatus.CPUVERSION2,bluecell_Currdatastatus.CPUVERSION3);
@@ -91,17 +91,32 @@ void Flash_InitRead() // ?占쏙옙湲고븿?占쏙옙
91 91
 
92 92
     
93 93
     printf("BANK1 IMAGE NAME : ");
94
-    for(int i = 0 ; i< 32; i++){
95
-        pdata[i] = Bank1data[MBIC_BOOT_FILENAME + i];
96
-        printf("%c",pdata[i]);
94
+    pdata = & bluecell_Currdatastatus.CPU_Bank1_Image_Name;
95
+    for(int i = 0 ; i< 41; i++){
96
+        if(i < 32){
97
+            pdata[i] = Bank1data[MBIC_BOOT_FILENAME + i];
98
+            printf("%c",pdata[i]);
99
+        }
100
+        else{
101
+         pdata[i] = 0x20;
102
+        }
103
+
97 104
     }
98 105
     printf("\r\n");
99 106
 
100 107
     
101 108
     pdata = & bluecell_Currdatastatus.CPU_Bank2_Image_Name;
102 109
     printf("BANK2 IMAGE NAME : ");
103
-    for(int i = 0 ; i< 32; i++){
104
-        pdata[i] = Bank2data[MBIC_BOOT_FILENAME + i];  
110
+    for(int i = 0 ; i< 41; i++){
111
+        if(i < 32){
112
+            pdata[i] = Bank2data[MBIC_BOOT_FILENAME + i];
113
+            printf("%c",pdata[i]);
114
+        }
115
+        else{
116
+         pdata[i] = 0x20;
117
+        }
118
+
119
+
105 120
         printf("%c",pdata[i]);
106 121
     }
107 122
     printf("\r\n");
@@ -275,7 +290,7 @@ uint8_t Bank_Flash_write(uint8_t* data,uint32_t StartBankAddress) // ?占쏙옙
275 290
 }
276 291
 #endif // PYJ.2020.06.24_END -- 
277 292
 #define DATA_32                 ((uint32_t)0x33333333)
278
-__IO bool EraseInit = false;
293
+bool EraseInit = false;
279 294
 
280 295
 #if 0 // PYJ.2020.06.24_BEGIN -- 
281 296
 void MBIC_APIFLASH_test(uint8_t* data,uint32_t size){
@@ -418,6 +433,7 @@ void MBIC_DataErase_Func(uint8_t bank_num){
418 433
     static uint32_t PAGEError = 0;
419 434
 
420 435
     if(EraseInit == false){
436
+        HAL_FLASH_Unlock();
421 437
 #if 0 // PYJ.2020.06.24_BEGIN -- 
422 438
         EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
423 439
         EraseInitStruct.PageAddress = FLASH_USER_BANK1_START_ADDR;
@@ -474,6 +490,19 @@ void MBIC_DataErase_Func(uint8_t bank_num){
474 490
         }
475 491
         EraseInit = true;
476 492
         printf("Erase End\r\n");
493
+         HAL_FLASH_Lock();
494
+    }
495
+    if(MBIC_Address == 0){
496
+        if(bluecell_Currdatastatus.CPU_Current_Bank == HFR_BANK1){
497
+            bank_num = HFR_BANK2;
498
+            MBIC_Address = FLASH_USER_BANK2_START_ADDR;
499
+            printf("Curr Bank BANK 1 I will download Bank2 \r\n");
500
+        }
501
+        else{
502
+            bank_num = HFR_BANK1;
503
+            MBIC_Address = FLASH_USER_BANK1_START_ADDR;
504
+            printf("Curr Bank BANK 2 I will download Bank1 \r\n");
505
+        }        
477 506
     }
478 507
 
479 508
 }
@@ -520,40 +549,8 @@ uint8_t MBIC_APIFLASH_Func(uint8_t* data,uint32_t size,uint8_t bank_num){
520 549
       (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
521 550
     
522 551
     /* Fill EraseInit structure*/
523
-#if 0 // PYJ.2020.06.24_BEGIN -- 
552
+#if 0 // PYJ.2020.06.29_BEGIN -- 
524 553
     if(EraseInit == false){
525
-        EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
526
-        EraseInitStruct.PageAddress = FLASH_USER_BANK1_START_ADDR;
527
-        EraseInitStruct.NbPages     = ((FLASH_USER_BANK1_START_ADDR + ((uint32_t)0xFFFF)) - FLASH_USER_BANK1_START_ADDR) / FLASH_PAGE_SIZE;
528
-        printf("Erase Start\r\n");
529
-        if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
530
-        {
531
-          /*
532
-            Error occurred while page erase.
533
-            User can add here some code to deal with this error.
534
-            PAGEError will contain the faulty page and then to know the code error on this page,
535
-            user can call function 'HAL_FLASH_GetError()'
536
-          */
537
-          /* Infinite loop */
538
-          while (1)
539
-          {
540
-            /* Make LED2 blink (100ms on, 2s off) to indicate error in Erase operation */
541
-            printf("HAL_FLASHEx_Erase Error\r\n");
542
-            HAL_Delay(2000);
543
-          }
544
-        }
545
-        EraseInit = true;
546
-        printf("Erase End\r\n");
547
-    }
548
-#else
549
-    if(EraseInit == false){
550
-#if 0 // PYJ.2020.06.24_BEGIN -- 
551
-        EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
552
-        EraseInitStruct.PageAddress = FLASH_USER_BANK1_START_ADDR;
553
-        printf("PageAddress : %x \r\n",FLASH_USER_BANK1_START_ADDR);
554
-//        EraseInitStruct.NbPages     = ((FLASH_USER_BANK1_START_ADDR + ((uint32_t)0xFFFF)) - FLASH_USER_BANK1_START_ADDR) / FLASH_PAGE_SIZE;
555
-        EraseInitStruct.NbPages     = (FLASH_USER_BANK1_START_ADDR - ((uint32_t)0xFFFF)) / FLASH_PAGE_SIZE;
556
-#else
557 554
     ret = bluecell_Currdatastatus.CPU_Current_Bank;
558 555
     if(bank_num == HFR_AUTO_SEL){
559 556
         if(ret == HFR_BANK2)
@@ -585,7 +582,6 @@ uint8_t MBIC_APIFLASH_Func(uint8_t* data,uint32_t size,uint8_t bank_num){
585 582
         printf("I will download Bank1 \r\n");        
586 583
         printf("Erase BANK 1 \r\n");        
587 584
     }
588
-#endif // PYJ.2020.06.24_END -- 
589 585
         printf("NbPages : %x \r\n",EraseInitStruct.NbPages );
590 586
         printf("EraseInitStruct.PageAddress : %x \r\n",EraseInitStruct.PageAddress);
591 587
 
@@ -609,38 +605,21 @@ uint8_t MBIC_APIFLASH_Func(uint8_t* data,uint32_t size,uint8_t bank_num){
609 605
         EraseInit = true;
610 606
         printf("Erase End\r\n");
611 607
     }
608
+#endif // PYJ.2020.06.29_END -- 
612 609
 
613
-#endif // PYJ.2020.06.24_END -- 
614 610
     /* Program the user Flash area word by word
615 611
       (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
616 612
     
617 613
 //    MBIC_Address = FLASH_USER_BANK1_START_ADDR;
618 614
     printf("HAL_FLASH_Program Start\r\n");
619 615
     DownloadIndex += size;
620
-#if 0 // PYJ.2020.06.24_BEGIN -- 
621
-    while (MBIC_Address <= ((FLASH_USER_BANK1_START_ADDR + DownloadIndex)))
622
-    {
623
-      writedata = data[dataindex + 0] ;
624
-      writedata += data[dataindex + 1] << 8 ;
625
-      writedata += data[dataindex + 2] << 16;
626
-      writedata += data[dataindex + 3] << 24;      
627
-      if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, MBIC_Address,writedata) == HAL_OK)
628
-      {
629
-        MBIC_Address +=  4;
630
-        dataindex  += 4;
631
-      }
632
-      else
633
-      {
634
-        /* Error occurred while writing data in Flash memory.
635
-           User can add here some code to deal with this error */
636
-        while (1)
637
-        {
638
-          printf("HAL_FLASH_Program Error\r\n");
639
-        }
640
-      }
641
-    }
642
-#else   
643 616
      printf("MBIC_Address : %x \r\n",MBIC_Address);
617
+     if(MBIC_Address == 0){
618
+        if(bank_num == HFR_BANK1)
619
+            MBIC_Address = FLASH_USER_BANK1_START_ADDR;
620
+        else
621
+           MBIC_Address = FLASH_USER_BANK2_START_ADDR;
622
+     }
644 623
      for(int downindex = 0; downindex < size; downindex+=4)
645 624
      {
646 625
        writedata = data[downindex + 0] ;
@@ -658,8 +637,7 @@ uint8_t MBIC_APIFLASH_Func(uint8_t* data,uint32_t size,uint8_t bank_num){
658 637
        }
659 638
      }
660 639
 
661
-#endif // PYJ.2020.06.24_END -- 
662
-     printf("HAL_FLASH_Program END\r\n");
640
+     printf("HAL_FLASH_Program END   %x \r\n",MBIC_Address);
663 641
     /* Lock the Flash to disable the flash control register access (recommended
664 642
        to protect the FLASH memory against possible unwanted operation) *********/
665 643
     HAL_FLASH_Lock();

+ 5 - 5
Bluecell_Src/uart.c

@@ -100,7 +100,7 @@ void GetDataFromUartQueue(UART_HandleTypeDef *huart)
100 100
 //        printf("data cnt zero !!!  \r\n");
101 101
         //RF_Ctrl_Main(&uart_buf[Header]);
102 102
 //        HAL_UART_Transmit(dst, &temp_buf[BLUECELL_HEADER00], 11, 3000);
103
-#if 1// PYJ.2019.07.15_BEGIN --
103
+#if 0// PYJ.2019.07.15_BEGIN --
104 104
             printf("\r\n[RX]");
105 105
             for(int i = 0; i < cnt; i++){
106 106
                 printf("%02x ",uart_buf[i]);
@@ -153,9 +153,9 @@ void Uart1_Data_Send(uint8_t* data,uint16_t size){
153 153
   //HAL_UART_Transmit_IT(&hTerminal, &data[0],size);
154 154
 //    printf("data[278] : %x \r\n",data[278]);
155 155
 ////    HAL_Delay(1);   
156
-//    printf("\r\n [TX] : {");
157
-//    for(int i = 0; i< size; i++)
158
-//        printf(",0x%02x ",data[i]);
156
+    printf("\r\n [TX] : ");
157
+    for(int i = 0; i< size; i++)
158
+        printf("%02x ",data[i]);
159 159
 //    printf("};\r\n\tCOUNT : %d \r\n",size);
160 160
 //    printf("\r\n");
161 161
 //    printf("\r\n [TX] : {");
@@ -164,7 +164,7 @@ void Uart1_Data_Send(uint8_t* data,uint16_t size){
164 164
 //        data[i] = 0;
165 165
 //    }
166 166
 //    printf("};\r\n\tCOUNT : %d \r\n",size);
167
-//    printf("\r\n");
167
+    printf("\r\n");
168 168
     
169 169
 }
170 170
 

+ 1 - 1
STM32F103ZET_JDASMBIC.elf.launch

@@ -57,5 +57,5 @@
57 57
 </listAttribute>
58 58
 <stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;&#13;&#10;"/>
59 59
 <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
60
-<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="uart_buf,0x08005000,0x8005000,Bank2data,data"/>
60
+<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="uart_buf,0x08005000,0x8005000,Bank2data,data,Currdata,Currdata[MBIC_BOOT_VERSION + 2],Bank1data"/>
61 61
 </launchConfiguration>

+ 40 - 15
Src/main.c

@@ -28,6 +28,7 @@
28 28
 #include "uart.h"
29 29
 #include "Bluecell_operate.h"
30 30
 #include "eeprom.h"
31
+#include "flash.h"
31 32
 /* USER CODE END Includes */
32 33
 
33 34
 /* Private typedef -----------------------------------------------------------*/
@@ -279,20 +280,43 @@ extern const uint16_t crc16_tab[256];
279 280
 
280 281
 
281 282
   setbuf(stdout, NULL);
282
-//  uint32_t CrcLength = 
283
-//    ((data2[MBIC_BOOT_LENGTH] << 24 ) 
284
-//    | data2[MBIC_BOOT_LENGTH + 1]<<16 
285
-//    | data2[MBIC_BOOT_LENGTH + 2]<<8   
286
-//    | data2[MBIC_BOOT_LENGTH + 3]);
287
-//  printf("CRC LENGTH : %d,CRC LENGTH : %X \r\n",CrcLength,CrcLength):
288
-//  uint16_t crcret = CRC16_Generate2(&data2[MBIC_PAYLOADSTART], CrcLength);
289
-//    
290
-//  printf("CRC : %x \r\n",data2[MBIC_BOOT_CRC + 0]);
291
-//  printf("data2 : %X size %d \r\n",crcret,CrcLength );  
292
-//      while(1);
293
-#if 1 // PYJ.2020.06.24_BEGIN -- 
294
-//  DataWriteTest();
295
-//    while(1);
283
+   uint32_t  CurrApiAddress = 0,Bank1Address=0,Bank2Address = 0;
284
+        int32_t CrcLength = 0;
285
+        
286
+        
287
+        
288
+        CurrApiAddress = FLASH_MBICUSER_START_ADDR;
289
+           Bank1Address = FLASH_USER_BANK1_START_ADDR;
290
+           Bank2Address = FLASH_USER_BANK2_START_ADDR;
291
+        
292
+           uint8_t* Currdata = (uint8_t*)CurrApiAddress;
293
+           uint8_t* Bank1data = (uint8_t*)Bank1Address;
294
+           uint8_t* Bank2data = (uint8_t*)Bank2Address;
295
+        
296
+        uint16_t crcret = 0;
297
+        
298
+        CrcLength=
299
+        ((Bank1data[MBIC_BOOT_LENGTH] << 24 ) 
300
+        | Bank1data[MBIC_BOOT_LENGTH + 1]<<16 
301
+        | Bank1data[MBIC_BOOT_LENGTH + 2]<<8   
302
+        | Bank1data[MBIC_BOOT_LENGTH + 3]);    
303
+
304
+        if(CrcLength > 0)
305
+            crcret = CRC16_Generate(Bank1data, CrcLength + 128);
306
+        CrcLength += 128;
307
+        printf("Bank 1 Crc ret : %x  Length : %x :  %d \r\n",crcret ,CrcLength,CrcLength);
308
+        
309
+        CrcLength=
310
+        ((Bank2data[MBIC_BOOT_LENGTH] << 24 ) 
311
+        | Bank2data[MBIC_BOOT_LENGTH + 1]<<16 
312
+        | Bank2data[MBIC_BOOT_LENGTH + 2]<<8   
313
+        | Bank2data[MBIC_BOOT_LENGTH + 3]);  
314
+        printf("address : %x \r\n",Bank2data[0]);
315
+        
316
+        printf("Bank 2 Crc ret : %x  Length : %x :  %d  \r\n", crcret,CrcLength,CrcLength );
317
+        CrcLength += 128;
318
+         crcret = CRC16_Generate(Bank2data, CrcLength );
319
+        printf("Bank 2 Crc ret : %x  Length : %x :  %d  \r\n", crcret,CrcLength,CrcLength );
296 320
 
297 321
   PE43711_PinInit();
298 322
   EEPROM_M24C08_Init();
@@ -305,7 +329,7 @@ extern const uint16_t crc16_tab[256];
305 329
   Booting_LedInit();
306 330
   Booting_LED_Check();
307 331
   InitUartQueue(&TerminalQueue);
308
-#endif // PYJ.2020.06.24_END -- 
332
+
309 333
 #if 0 // PYJ.2020.04.22_BEGIN -- 
310 334
   EEPROM_M24C08_write(0xA0,0,i2cTestData,1);
311 335
   printf("i2c Test Data1 %d\r\n",i2ctest[0]);
@@ -334,6 +358,7 @@ extern const uint16_t crc16_tab[256];
334 358
 
335 359
 //      while(1);
336 360
 #if 1 // PYJ.2020.05.06_BEGIN --
361
+     
337 362
       printf("****************************************\r\n");
338 363
       printf("MBIC Project\r\n");
339 364
       printf("Build at %s %s\r\n", __DATE__, __TIME__);