Procházet zdrojové kódy

BootLoader API 연동 / flash.h 파일 추가 / Uart Init System 시작 직전 하도록 수정

MBIC Bootloader STM32 1.8.0에서도 동작하도록 수정.
CRC32 추가
PYJ před 5 roky
rodič
revize
742ab9513e

+ 14 - 0
Bluecell_Inc/Bluecell_operate.h

@@ -68,6 +68,20 @@ typedef struct{
68 68
     uint8_t High_bit;
69 69
     uint8_t Low_bit;
70 70
 }OneByteToTwoByte;
71
+typedef enum{
72
+  MBIC_Notice_REQ = 0x10,
73
+  MBIC_Download_DATA_REQ,
74
+  MBIC_Download_Confirm_REQ,
75
+  MBIC_Complete_Notice_REQ_REQ,
76
+  MBIC_Reboot_Notice_REQ,
77
+}MBIC_Download_Req_L;
78
+typedef enum{
79
+  MBIC_Notice_RSP = 0x90,
80
+  MBIC_Download_DATA_RSP,
81
+  MBIC_Download_Confirm_RSP,
82
+  MBIC_Complete_Notice_RSP,
83
+  MBIC_Reboot_Notice_RSP,
84
+}MBIC_Download_Rsp_L;
71 85
 
72 86
 typedef enum{
73 87
 	MBIC_PREAMBLE_0 = 0,

+ 56 - 0
Bluecell_Inc/MBIC_Bootloader.h

@@ -0,0 +1,56 @@
1
+/*
2
+ * MBIC_Bootloader.h
3
+ *
4
+ *  Created on: 2020. 5. 18.
5
+ *      Author: parkyj
6
+ */
7
+
8
+#ifndef MBIC_BOOTLOADER_H_
9
+#define MBIC_BOOTLOADER_H_
10
+
11
+
12
+
13
+#define MBIC_HEADER_SIZE 22
14
+#define MBIC_TAIL_SIZE 3
15
+
16
+#define MBIC_PREAMBLE0 0x16
17
+#define MBIC_PREAMBLE1 0x16
18
+#define MBIC_PREAMBLE2 0x16
19
+#define MBIC_PREAMBLE3 0x16
20
+#define MBIC_SUBUID0 0x00
21
+#define MBIC_SUBUID1 0xF1
22
+#define MBIC_RCODE
23
+#define MBIC_TRID
24
+#define MBIC_SEQNUM
25
+#define MBIC_TTL
26
+#define MBIC_TIME
27
+#define MBIC_ERRRESPONSE 0x00
28
+#define MBIC_CMD
29
+#define MBIC_LENGTH
30
+#define MBIC_CHECKSHUM_INDEX MBIC_HEADER_SIZE - 1 //CheckSUM REMOVE INDEX
31
+#define MBIC_ETX 0x03
32
+#define MBIC_NODE_MU 0x80
33
+#define MARK_START_POSITION						0
34
+#define TYPE_START_POSITION						9	
35
+#define FILE_TYPE_START_POSITION				10
36
+#define VERSION_START_POSITION					11
37
+#define FILENAME_START_POSITION					14
38
+#define CREATION_TIME_START_POSITION			55
39
+#define LENGTH_START_POSITION					61
40
+#define CRC_START_POSITION						65
41
+#define RESERVED_START_POSITION					69
42
+
43
+
44
+
45
+
46
+
47
+typedef struct{
48
+    uint16_t Length;
49
+    uint16_t Crcchk;
50
+    bool FileChk;
51
+}BootLoaderDataCheck_st;
52
+
53
+
54
+
55
+
56
+#endif /* MBIC_BOOTLOADER_H_ */

+ 34 - 0
Bluecell_Inc/flash.h

@@ -0,0 +1,34 @@
1
+/*
2
+ * flash.h
3
+ *
4
+ *  Created on: 2019. 7. 4.
5
+ *      Author: parkyj
6
+ */
7
+
8
+#ifndef FLASH_H_
9
+#define FLASH_H_
10
+
11
+#include "main.h"
12
+#include "CRC.h"
13
+
14
+#define FLASH_USER_START_ADDR ((uint32_t)0x08005000)
15
+#define FLASH_USER_END_ADDR     FLASH_USER_START_ADDR + ((uint32_t)0x000FFFF)   /* End @ of user Flash area */
16
+#define APPLICATION_ADDRESS     (uint32_t)0x08005000      /* Start user code address: ADDR_FLASH_PAGE_8 */
17
+
18
+
19
+#define FLASH_USER_BANK1_START_ADDR ((uint32_t)0x08015000)
20
+#define FLASH_USER_BANK2_START_ADDR ((uint32_t)0x08025000)
21
+#define FLASH_USER_TEMPBANK_START_ADDR ((uint32_t)0x08035000)
22
+
23
+
24
+
25
+
26
+
27
+#define FirmwareUpdataAck  0x11
28
+#define FirmwareUpdataNak  0x22
29
+
30
+#define FirmwareUpdateDelay 50
31
+
32
+
33
+
34
+#endif /* FLASH_H_ */

+ 53 - 47
Bluecell_Src/Bluecell_operate.c

@@ -151,7 +151,7 @@ void Booting_LED_Check(void){
151 151
         HAL_GPIO_TogglePin(BOOT_LED_GPIO_Port,BOOT_LED_Pin);
152 152
         HAL_GPIO_TogglePin(LED_ACT_GPIO_Port,LED_ACT_Pin);
153 153
         HAL_GPIO_TogglePin(LED_FAIL_GPIO_Port,LED_FAIL_Pin);
154
-        HAL_Delay(1000);
154
+        HAL_Delay(500);
155 155
     }
156 156
 }
157 157
 
@@ -365,59 +365,59 @@ void Bluecell_AttenInitialize(){
365 365
 
366 366
 
367 367
 
368
-            bluecell_Prevdatastatus.ATT_UL1_H = bluecell_Currdatastatus.ATT_UL1_H;
369
-            bluecell_Prevdatastatus.ATT_UL1_L = bluecell_Currdatastatus.ATT_UL1_L;
370
-            bluecell_Prevdatastatus.bluecell_User_UL1_H = bluecell_Currdatastatus.bluecell_User_UL1_H;
371
-            bluecell_Prevdatastatus.bluecell_User_UL1_L = bluecell_Currdatastatus.bluecell_User_UL1_L;
372
-            MBIC_Val = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
373
-            MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL1_H << 8 | bluecell_Currdatastatus.bluecell_User_UL1_L;
374
-            val = MBIC_PE43711_Calc(&Att_UL1.Table_0_0_dBm, // Table Offset
375
-                                MBIC_Val,
376
-                               MBIC_UserVal);// User Atten Low Bit
377
-
378
-    //        printf("%d val = %x \r\n",__LINE__,val);
379
-            PE43711_atten_ctrl(ALL_ATT.ATT_UL1,val);
368
+    bluecell_Prevdatastatus.ATT_UL1_H = bluecell_Currdatastatus.ATT_UL1_H;
369
+    bluecell_Prevdatastatus.ATT_UL1_L = bluecell_Currdatastatus.ATT_UL1_L;
370
+    bluecell_Prevdatastatus.bluecell_User_UL1_H = bluecell_Currdatastatus.bluecell_User_UL1_H;
371
+    bluecell_Prevdatastatus.bluecell_User_UL1_L = bluecell_Currdatastatus.bluecell_User_UL1_L;
372
+    MBIC_Val = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
373
+    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL1_H << 8 | bluecell_Currdatastatus.bluecell_User_UL1_L;
374
+    val = MBIC_PE43711_Calc(&Att_UL1.Table_0_0_dBm, // Table Offset
375
+                        MBIC_Val,
376
+                       MBIC_UserVal);// User Atten Low Bit
380 377
 
381
-                        bluecell_Prevdatastatus.ATT_UL2_H = bluecell_Currdatastatus.ATT_UL2_H;
382
-            bluecell_Prevdatastatus.ATT_UL2_L = bluecell_Currdatastatus.ATT_UL2_L;
383
-            bluecell_Prevdatastatus.bluecell_User_UL2_H = bluecell_Currdatastatus.bluecell_User_UL2_H;
384
-            bluecell_Prevdatastatus.bluecell_User_UL2_L = bluecell_Currdatastatus.bluecell_User_UL2_L;
385
-            MBIC_Val = bluecell_Currdatastatus.ATT_UL2_H << 8 | bluecell_Currdatastatus.ATT_UL2_L;
386
-            MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL2_H << 8 | bluecell_Currdatastatus.bluecell_User_UL2_L;
387
-            val = MBIC_PE43711_Calc(&Att_UL1.Table_0_0_dBm, // Table Offset
388
-                                MBIC_Val,
389
-                               MBIC_UserVal);// User Atten Low Bit
378
+//        printf("%d val = %x \r\n",__LINE__,val);
379
+    PE43711_atten_ctrl(ALL_ATT.ATT_UL1,val);
380
+
381
+                bluecell_Prevdatastatus.ATT_UL2_H = bluecell_Currdatastatus.ATT_UL2_H;
382
+    bluecell_Prevdatastatus.ATT_UL2_L = bluecell_Currdatastatus.ATT_UL2_L;
383
+    bluecell_Prevdatastatus.bluecell_User_UL2_H = bluecell_Currdatastatus.bluecell_User_UL2_H;
384
+    bluecell_Prevdatastatus.bluecell_User_UL2_L = bluecell_Currdatastatus.bluecell_User_UL2_L;
385
+    MBIC_Val = bluecell_Currdatastatus.ATT_UL2_H << 8 | bluecell_Currdatastatus.ATT_UL2_L;
386
+    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL2_H << 8 | bluecell_Currdatastatus.bluecell_User_UL2_L;
387
+    val = MBIC_PE43711_Calc(&Att_UL1.Table_0_0_dBm, // Table Offset
388
+                        MBIC_Val,
389
+                       MBIC_UserVal);// User Atten Low Bit
390 390
 
391
-    //        printf("%d val = %x \r\n",__LINE__,val);
392
-            PE43711_atten_ctrl(ALL_ATT.ATT_UL2,val);
391
+//        printf("%d val = %x \r\n",__LINE__,val);
392
+    PE43711_atten_ctrl(ALL_ATT.ATT_UL2,val);
393 393
 
394 394
 
395
-                        bluecell_Prevdatastatus.ATT_UL3_H = bluecell_Currdatastatus.ATT_UL3_H;
396
-            bluecell_Prevdatastatus.ATT_UL3_L = bluecell_Currdatastatus.ATT_UL3_L;
397
-            bluecell_Prevdatastatus.bluecell_User_UL3_H = bluecell_Currdatastatus.bluecell_User_UL3_H;
398
-            bluecell_Prevdatastatus.bluecell_User_UL3_L = bluecell_Currdatastatus.bluecell_User_UL3_L;
399
-            MBIC_Val = bluecell_Currdatastatus.ATT_UL3_H << 8 | bluecell_Currdatastatus.ATT_UL3_L;
400
-            MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL3_H << 8 | bluecell_Currdatastatus.bluecell_User_UL3_L;
401
-            val = MBIC_PE43711_Calc(&Att_UL3.Table_0_0_dBm, // Table Offset
402
-                                MBIC_Val,
403
-                               MBIC_UserVal);// User Atten Low Bit
395
+                bluecell_Prevdatastatus.ATT_UL3_H = bluecell_Currdatastatus.ATT_UL3_H;
396
+    bluecell_Prevdatastatus.ATT_UL3_L = bluecell_Currdatastatus.ATT_UL3_L;
397
+    bluecell_Prevdatastatus.bluecell_User_UL3_H = bluecell_Currdatastatus.bluecell_User_UL3_H;
398
+    bluecell_Prevdatastatus.bluecell_User_UL3_L = bluecell_Currdatastatus.bluecell_User_UL3_L;
399
+    MBIC_Val = bluecell_Currdatastatus.ATT_UL3_H << 8 | bluecell_Currdatastatus.ATT_UL3_L;
400
+    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL3_H << 8 | bluecell_Currdatastatus.bluecell_User_UL3_L;
401
+    val = MBIC_PE43711_Calc(&Att_UL3.Table_0_0_dBm, // Table Offset
402
+                        MBIC_Val,
403
+                       MBIC_UserVal);// User Atten Low Bit
404 404
 
405
-    //        printf("%d val = %x \r\n",__LINE__,val);
406
-            PE43711_atten_ctrl(ALL_ATT.ATT_UL3,val);
405
+//        printf("%d val = %x \r\n",__LINE__,val);
406
+    PE43711_atten_ctrl(ALL_ATT.ATT_UL3,val);
407 407
 
408 408
 
409
-                        bluecell_Prevdatastatus.ATT_UL4_H = bluecell_Currdatastatus.ATT_UL4_H;
410
-            bluecell_Prevdatastatus.ATT_UL4_L = bluecell_Currdatastatus.ATT_UL4_L;
411
-            bluecell_Prevdatastatus.bluecell_User_UL4_H = bluecell_Currdatastatus.bluecell_User_UL4_H;
412
-            bluecell_Prevdatastatus.bluecell_User_UL4_L = bluecell_Currdatastatus.bluecell_User_UL4_L;
413
-            MBIC_Val = bluecell_Currdatastatus.ATT_UL4_H << 8 | bluecell_Currdatastatus.ATT_UL4_L;
414
-            MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL4_H << 8 | bluecell_Currdatastatus.bluecell_User_UL4_L;
415
-            val = MBIC_PE43711_Calc(&Att_UL4.Table_0_0_dBm, // Table Offset
416
-                                MBIC_Val,
417
-                               MBIC_UserVal);// User Atten Low Bit
409
+                bluecell_Prevdatastatus.ATT_UL4_H = bluecell_Currdatastatus.ATT_UL4_H;
410
+    bluecell_Prevdatastatus.ATT_UL4_L = bluecell_Currdatastatus.ATT_UL4_L;
411
+    bluecell_Prevdatastatus.bluecell_User_UL4_H = bluecell_Currdatastatus.bluecell_User_UL4_H;
412
+    bluecell_Prevdatastatus.bluecell_User_UL4_L = bluecell_Currdatastatus.bluecell_User_UL4_L;
413
+    MBIC_Val = bluecell_Currdatastatus.ATT_UL4_H << 8 | bluecell_Currdatastatus.ATT_UL4_L;
414
+    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL4_H << 8 | bluecell_Currdatastatus.bluecell_User_UL4_L;
415
+    val = MBIC_PE43711_Calc(&Att_UL4.Table_0_0_dBm, // Table Offset
416
+                        MBIC_Val,
417
+                       MBIC_UserVal);// User Atten Low Bit
418 418
 
419
-    //        printf("%d val = %x \r\n",__LINE__,val);
420
-            PE43711_atten_ctrl(ALL_ATT.ATT_UL4,val);
419
+//        printf("%d val = %x \r\n",__LINE__,val);
420
+    PE43711_atten_ctrl(ALL_ATT.ATT_UL4,val);
421 421
 
422 422
 }
423 423
 void CompareAttenData(BLUESTATUS_st Curr,BLUESTATUS_st Prev){
@@ -1849,8 +1849,12 @@ void DataStatusSet(void){
1849 1849
      
1850 1850
 }
1851 1851
  void Bluecell_DataInit(){
1852
-
1852
+/*
1853
+    MBIC Request List 
1854
+    Turn off all paths at boot
1855
+ */
1853 1856
     
1857
+#if 0 // PYJ.2020.06.17_BEGIN -- 
1854 1858
     HAL_GPIO_WritePin(PATH_EN_DL1_GPIO_Port,PATH_EN_DL1_Pin,bluecell_Currdatastatus.ATT_DL1_PATH);   
1855 1859
     HAL_GPIO_WritePin(PATH_EN_DL2_GPIO_Port,PATH_EN_DL2_Pin,bluecell_Currdatastatus.ATT_DL2_PATH);   
1856 1860
     HAL_GPIO_WritePin(PATH_EN_DL3_GPIO_Port,PATH_EN_DL3_Pin,bluecell_Currdatastatus.ATT_DL3_PATH);   
@@ -1861,6 +1865,7 @@ void DataStatusSet(void){
1861 1865
     HAL_GPIO_WritePin(PATH_EN_UL2_GPIO_Port,PATH_EN_UL2_Pin,bluecell_Currdatastatus.ATT_UL2_PATH);   
1862 1866
     HAL_GPIO_WritePin(PATH_EN_UL3_GPIO_Port,PATH_EN_UL3_Pin,bluecell_Currdatastatus.ATT_UL3_PATH);   
1863 1867
     HAL_GPIO_WritePin(PATH_EN_UL4_GPIO_Port,PATH_EN_UL4_Pin,bluecell_Currdatastatus.ATT_UL4_PATH);   
1868
+#endif // PYJ.2020.06.17_END -- 
1864 1869
 
1865 1870
 
1866 1871
     CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
@@ -3121,6 +3126,7 @@ bool MBIC_Operate(uint8_t* data){
3121 3126
 
3122 3127
     }
3123 3128
     else{
3129
+        MBIC_Bootloader_FirmwareUpdate();
3124 3130
         /*NOP*/
3125 3131
         printf("DATA ERR\r\n");
3126 3132
     }

+ 81 - 6
Bluecell_Src/CRC.c

@@ -8,6 +8,8 @@
8 8
 /*---------------------------------------------------------------------------------------*/
9 9
 /*									CRC16	TABLE						    			 */
10 10
 /*---------------------------------------------------------------------------------------*/
11
+#include <stdio.h>						
12
+#include <stdint.h>	
11 13
 #include <CRC.h>
12 14
 #include "uart.h"
13 15
 	
@@ -45,6 +47,54 @@ uint16_t crc16_tab[256] = {
45 47
     0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,				
46 48
     0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0				
47 49
 };				
50
+					
51
+						
52
+static uint32_t crc32_tab[] = {						
53
+    0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,						
54
+    0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,						
55
+    0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,						
56
+    0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,						
57
+    0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,						
58
+    0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,						
59
+    0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,						
60
+    0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,						
61
+    0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,						
62
+    0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,						
63
+    0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,						
64
+    0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,						
65
+    0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,						
66
+    0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,						
67
+    0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,						
68
+    0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,						
69
+    0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,						
70
+    0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,						
71
+    0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,						
72
+    0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,						
73
+    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,						
74
+    0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,						
75
+    0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,						
76
+    0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,						
77
+    0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,						
78
+    0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,						
79
+    0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,						
80
+    0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,						
81
+    0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,						
82
+    0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,						
83
+    0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,						
84
+    0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,						
85
+    0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,						
86
+    0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,						
87
+    0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,						
88
+    0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,						
89
+    0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,						
90
+    0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,						
91
+    0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,						
92
+    0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,						
93
+    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,						
94
+    0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,						
95
+    0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d						
96
+};						
97
+				
48 98
 
49 99
 
50 100
 //-----------------------------------------------
@@ -169,10 +219,35 @@ uint16_t CRC16_Generate(uint8_t* buf_ptr, int len)
169 219
 //    printf("len : %d \r\n",len);
170 220
     return crc;
171 221
 }   
222
+		
223
+uint32_t crc32(const void *buf, size_t size)						
224
+{						
225
+    const uint8_t *p;						
226
+    uint32_t crcret = 0;
227
+						
228
+    p = buf;						
229
+    crcret = crcret ^ ~0U;						
230
+						
231
+    while (size--) {						
232
+        crcret = crc32_tab[(crcret ^ *p++) & 0xFF] ^ (crcret >> 8);						
233
+    }						
234
+						
235
+    return crcret ^ ~0U;						
236
+}						
237
+etError crc32Check(uint32_t checksum,uint32_t crc, const void *buf, size_t size)						
238
+{						
239
+    const uint8_t *p;						
240
+    uint32_t crcret = 0;
241
+						
242
+    p = buf;						
243
+    crcret = crcret ^ ~0U;						
244
+						
245
+    while (size--) {						
246
+        crcret = crc32_tab[(crcret ^ *p++) & 0xFF] ^ (crcret >> 8);						
247
+    }						
248
+						
249
+    crcret ^ ~0U;		
250
+
251
+    return (crcret == checksum ? CHECKSUM_ERROR : NO_ERROR);
252
+}							
172 253
 
173
-#if 0 // PYJ.2020.05.28_BEGIN -- 
174
-uint16_t crc16(uint16_t crc, uint8_t data)
175
-{
176
-    return (uint16_t)((crc << 8) ^ crc16_tab[((crc >> 8) ^ data) & 0xff]);
177
-}
178
-#endif // PYJ.2020.05.28_END -- 

+ 359 - 0
Bluecell_Src/MBIC_Bootloader.c

@@ -0,0 +1,359 @@
1
+/*
2
+ * MBIC_Bootloader.c
3
+ *
4
+ *  Created on: 2020. 5. 18.
5
+ *      Author: parkyj
6
+ */
7
+#include <stdio.h>
8
+#include <stdint.h>
9
+#include <stdbool.h>
10
+
11
+#include "main.h"
12
+#include "MBIC_Bootloader.h"
13
+#include "flash.h"
14
+#include "CRC.h"
15
+#include "uart.h"
16
+
17
+extern __IO bool EraseInit;
18
+
19
+extern uint8_t Bank_Flash_write(uint8_t* data,uint32_t StartBankAddress);
20
+
21
+
22
+
23
+
24
+
25
+BootLoaderDataCheck_st MBIC_FileDataCheck(uint8_t* data){
26
+  BootLoaderDataCheck_st ret = {0,0,false};
27
+  int8_t MBIC_Mark[9] = "JT-NRDAS ";
28
+  int8_t MBIC_FileName1[] = "jhfs-mbic-nrdas-v";
29
+  int8_t MBIC_FileName2[] = "v00.00.01.mbc";
30
+  uint8_t MBIC_type = 0x20;
31
+  uint8_t MBIC_FileType = 0x00;
32
+  int i = 0;
33
+  /***
34
+  MARK Check
35
+  ***/
36
+  for(i = MARK_START_POSITION; i < TYPE_START_POSITION; i++){
37
+    if(MBIC_Mark[i] != data[i]){
38
+      printf("Data Diff \r\n");
39
+      return ret;
40
+    }else{
41
+      printf("MARK Data Success \r\n");
42
+    }
43
+  }
44
+    /***
45
+  TYPE Check
46
+  ***/
47
+  for(i = TYPE_START_POSITION; i < FILE_TYPE_START_POSITION; i++){
48
+    if(MBIC_type != data[i]){
49
+      printf("Data Diff \r\n");
50
+      return ret;
51
+    }
52
+    else
53
+    printf("Type Data Success \r\n");
54
+  }  
55
+    /***
56
+  File Type Check
57
+  ***/
58
+  for(i = FILE_TYPE_START_POSITION; i < VERSION_START_POSITION; i++){
59
+    if(MBIC_FileType != data[i]){
60
+      printf("Data Diff \r\n");
61
+      return ret;
62
+    }
63
+    else
64
+      printf("File Type Data Success \r\n");
65
+  }  
66
+    /***
67
+  Version Check 
68
+  ***/
69
+  for(i = VERSION_START_POSITION; i < FILENAME_START_POSITION; i++){
70
+    printf("Version Data Success Version %x\r\n",data[i]);    
71
+  }
72
+  /***
73
+  File Name Check
74
+  ***/
75
+  for(i = FILENAME_START_POSITION; i < 30; i++){
76
+    if(MBIC_FileName1[i-14] != data[i]){
77
+      printf("Data Diff \r\n");
78
+      printf("MBIC_FileName1[%d] : %x, data[%d] :  %x\r\n",i - 14,MBIC_FileName1[i - 14],i,data[i]);
79
+      return ret;
80
+    }
81
+    else
82
+      printf("File Name Data Success %c\r\n",data[i]);
83
+  }  
84
+  for(i = i; i < 43; i++){
85
+    if(MBIC_FileName2[i-30] != data[i]){
86
+//      printf("Data Diff %c\r\n",data[i]);
87
+//      printf("MBIC_FileName2[%d] : %x, data[%d] :  %x\r\n",i - 30,MBIC_FileName2[i - 30],i,data[i]);
88
+   //   return ret;
89
+    }
90
+    else
91
+      printf("File Name Data Success %c\r\n",data[i]);
92
+  }   
93
+
94
+  for(i = i; i < 49; i++){
95
+      printf("Creation Success %x\r\n",data[i]);
96
+  }
97
+  for(i = i; i < 55; i++){
98
+    printf("Creation Success data[%d] : %x\r\n",i,data[i]);
99
+  }
100
+  printf(" %d",data[i++]);
101
+  printf(" -%02d",data[i++]);
102
+  printf(" -%02d",data[i++]);
103
+  printf(" -%02d",data[i++]);
104
+  printf(" -%02d",data[i++]);
105
+  printf(" -%02d\r\n",data[i++]);
106
+  
107
+  
108
+  
109
+  ret.Length = ((data[i++] << 8) & 0xFF00);
110
+  ret.Length += (data[i++]);
111
+  printf("data[%d] : %d\r\n",i - 1,ret.Length);
112
+  printf("data[%d] : %d\r\n",i - 1,ret.Length);
113
+
114
+  ret.Crcchk = ((data[i++] << 8) & 0xFF00);
115
+  ret.Crcchk += (data[i++]);
116
+  /*ONLY DATA CRC*/  
117
+  printf("CRC_H[%d] : %x\r\n",i,ret.Crcchk);
118
+  printf("CRC_L[%d] : %x\r\n",i,ret.Crcchk);
119
+
120
+  ret.FileChk = true;
121
+  return ret;
122
+}
123
+
124
+/*
125
+  MBIC Basic Header merge function 
126
+  Data : Response Data
127
+  Length : Response Data Length
128
+  CRCINDEX : CRC INDEX Number
129
+
130
+*/
131
+uint8_t* MBIC_HeaderMergeFunction(uint8_t* data,uint16_t Length )
132
+{
133
+    uint8_t ret[Length + 22 + 3];/*Data Length + Header Length + Tail Length*/
134
+    uint16_t CRCData = CRC16_Generate(data,Length);
135
+    /*CRC Create*/
136
+    ret[MBIC_PAYLOADSTART + Length + 0] = ((CRCData & 0xFF00) >> 8);
137
+    ret[MBIC_PAYLOADSTART + Length + 1] = ((CRCData & 0x00FF));
138
+    ret[MBIC_PAYLOADSTART + Length + 2] = 0x03;
139
+    /*Data Mark Create*/
140
+    ret[MBIC_PREAMBLE_0] = MBIC_PREAMBLE0;
141
+    ret[MBIC_PREAMBLE_1] = MBIC_PREAMBLE1;
142
+    ret[MBIC_PREAMBLE_2] = MBIC_PREAMBLE2;
143
+    ret[MBIC_PREAMBLE_3] = MBIC_PREAMBLE3;
144
+    /*Data Subid Create*/
145
+    ret[MBIC_SUBUID_0] = MBIC_SUBUID0;
146
+    ret[MBIC_SUBUID_1] = MBIC_SUBUID1;
147
+
148
+    ret[MBIC_RCODE_0] = data[MBIC_RCODE_0];
149
+
150
+    ret[MBIC_TRID_0] = data[MBIC_TRID_0];
151
+    ret[MBIC_TRID_1] = data[MBIC_TRID_1];
152
+
153
+    ret[MBIC_SEQSUM_0] = data[MBIC_SEQSUM_0];
154
+
155
+    ret[MBIC_TTL_0] = data[MBIC_TTL_0];
156
+
157
+    ret[MBIC_TIME_0] = data[MBIC_TIME_0];
158
+    ret[MBIC_TIME_1] = data[MBIC_TIME_1];
159
+    ret[MBIC_TIME_2] = data[MBIC_TIME_2];
160
+    ret[MBIC_TIME_3] = data[MBIC_TIME_3];
161
+    ret[MBIC_TIME_4] = data[MBIC_TIME_4];
162
+    ret[MBIC_TIME_5] = data[MBIC_TIME_5];
163
+    ret[MBIC_ERRRESPONSE_0] = MBIC_ERRRESPONSE;
164
+
165
+
166
+
167
+        
168
+
169
+    ret[MBIC_LENGTH_0] = (Length & 0xFF00) >> 8;
170
+    ret[MBIC_LENGTH_1] = Length & 0x00FF;
171
+
172
+    ret[MBIC_HEADERCHECKSUM_0] = Chksum_Create(ret);
173
+    /*Data Move*/
174
+//    for(int i = 0; i < Length; i++){
175
+//        data[MBIC_PAYLOADSTART + i] = data[i];
176
+//    }
177
+    /*
178
+        MBIC Header Data input
179
+    */
180
+    for(int i = 0; i < MBIC_HEADER_SIZE; i++){
181
+        if(i == MBIC_CMD_0) /*cmd exception*/
182
+            continue;
183
+        data[i] = ret[i];
184
+    }
185
+      /*
186
+          MBIC Tail Data input
187
+      */
188
+    
189
+      for(int i = MBIC_HEADER_SIZE + Length; i < MBIC_HEADER_SIZE + MBIC_TAIL_SIZE + Length; i++){
190
+        data[i] = ret[i];
191
+    }
192
+//    for(uint16_t i = 0; i < Length; i ++)
193
+//        ret[MBIC_PAYLOADSTART + i] = data[i];
194
+//    for(int i = 0; i < Length; i++)
195
+//        printf("MBIC : %x \r\n",data[i]);
196
+
197
+    return data;
198
+}
199
+
200
+void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
201
+    uint8_t MBIC_DownLoadData[0xFFFF];
202
+    uint8_t cmd = data[MBIC_CMD_0];
203
+    static uint8_t Download_Option = 0;
204
+    uint16_t index = 0;
205
+    static uint32_t Curr_Download_DataIndex = 0;
206
+    static uint32_t Prev_Download_DataIndex = 0;    
207
+    uint32_t TotalFrame = 0;
208
+    uint32_t CurrFrame = 0;
209
+    
210
+    uint32_t i = 0 ;
211
+#if 0 // PYJ.2020.06.04_BEGIN -- 
212
+    uint8_t dataTest[1024] = {
213
+      0x4A,0x54,0x2D,0x4E,0x52,0x44,0x41,0x53,0x20,0x20,0x00,0x00,
214
+        0x00,0x01,0x6A,0x68,0x66,0x73,0x2D,0x6D,0x62,0x69,0x63,0x2D,
215
+        0x6E,0x72,0x64,0x61,0x73,0x2D,0x76,0x30,0x30,0x2E,0x30,0x30,0x2E,
216
+        0x30,0x31,0x2E,0x6D,0x62,0x63,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
217
+        0x20,0x20,0x20,0x20,0x20,0x14,0x06,0x03,0x10,0x1F,0xC4,0x3C,0x49,
218
+        0x42,0x98,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
219
+        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
220
+        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
221
+        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
222
+        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
223
+    };
224
+    
225
+#endif // PYJ.2020.06.04_END -- 
226
+    
227
+
228
+//    printf("RX");
229
+//    for(int i = 0; i < 128; i++)
230
+//        printf("%c",*data++);
231
+    switch(cmd){
232
+        case MBIC_Notice_REQ:
233
+            cmd = MBIC_Notice_RSP;
234
+            /*TOTAL FRAME NUMBER*/
235
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];
236
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];        
237
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 2];
238
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 3];        
239
+            /*DOWNLOAD OPTION*/        
240
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 4];
241
+            Download_Option = data[MBIC_PAYLOADSTART + 4];
242
+            /*DOWNLOAD DELAY REQUEST*/
243
+            data[MBIC_PAYLOADSTART + index++] = 3;
244
+            /*DOWNLOAD Reserve*/
245
+            data[MBIC_PAYLOADSTART + index++] = 0;
246
+            data[MBIC_PAYLOADSTART + index++] = 0;
247
+            data[MBIC_PAYLOADSTART + index++] = 0;
248
+            data[MBIC_PAYLOADSTART + index++] = 0;
249
+            data[MBIC_PAYLOADSTART + index++] = 0;
250
+            data[MBIC_PAYLOADSTART + index++] = 0;      
251
+//            printf("ccc\r\n");
252
+        break;
253
+        case MBIC_Download_DATA_REQ:
254
+            TotalFrame = data[MBIC_PAYLOADSTART + 0] << 24
255
+                        |data[MBIC_PAYLOADSTART + 1] << 16
256
+                        |data[MBIC_PAYLOADSTART + 2] << 8
257
+                        |data[MBIC_PAYLOADSTART + 3] << 0;
258
+//            MBIC_FileDataCheck(data);
259
+            cmd = MBIC_Download_DATA_RSP;
260
+            /*TOTAL FRAME NUMBER*/
261
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];
262
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];
263
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 2];
264
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 3];        
265
+            /*Current Download Frame Number*/        
266
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 4];
267
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 5];        
268
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 6];
269
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 7];        
270
+            Curr_Download_DataIndex = data[MBIC_PAYLOADSTART  + 4] << 24;
271
+            Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 5] << 16;
272
+            Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 6] << 8;            
273
+            Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 7];                        
274
+            /*DOWNLOAD Reserve*/
275
+            data[MBIC_PAYLOADSTART + index++] = 0;
276
+            data[MBIC_PAYLOADSTART + index++] = 0;
277
+            data[MBIC_PAYLOADSTART + index++] = 0;
278
+            data[MBIC_PAYLOADSTART + index++] = 0;
279
+            for(i = 0; i < Curr_Download_DataIndex - Prev_Download_DataIndex; i++){
280
+                    MBIC_DownLoadData[i] = data[MBIC_PAYLOADSTART + 12 +i];
281
+//                    printf("%02x ",MBIC_DownLoadData[i]);
282
+            }
283
+//            printf("Data End\r\n");
284
+            Bank_Flash_write(data,FLASH_USER_BANK1_START_ADDR);
285
+//            HAL_Delay(100);
286
+            Prev_Download_DataIndex  = Curr_Download_DataIndex + 1;
287
+            break;
288
+        case MBIC_Download_Confirm_REQ:
289
+            EraseInit = true;
290
+            cmd = MBIC_Download_Confirm_RSP;
291
+            /*TOTAL FRAME NUMBER*/
292
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];
293
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];        
294
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 2];
295
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 3];        
296
+            /*DOWNLOAD OPTION*/        
297
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 4];
298
+            Download_Option = data[MBIC_PAYLOADSTART + 4];
299
+            /*DOWNLOAD DELAY REQUEST*/
300
+            data[MBIC_PAYLOADSTART + index++] = 3;
301
+            /*DOWNLOAD Reserve*/
302
+            data[MBIC_PAYLOADSTART + index++] = 0;
303
+            data[MBIC_PAYLOADSTART + index++] = 0;
304
+            data[MBIC_PAYLOADSTART + index++] = 0;
305
+            data[MBIC_PAYLOADSTART + index++] = 0;
306
+            data[MBIC_PAYLOADSTART + index++] = 0;
307
+            data[MBIC_PAYLOADSTART + index++] = 0;  
308
+        break;
309
+        case MBIC_Complete_Notice_REQ_REQ:
310
+            cmd = MBIC_Complete_Notice_RSP;
311
+            /*TOTAL FRAME NUMBER*/
312
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];
313
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];        
314
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 2];
315
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 3];        
316
+            /*DOWNLOAD OPTION*/        
317
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 4];
318
+            Download_Option = data[MBIC_PAYLOADSTART + 4];
319
+            /*DOWNLOAD DELAY REQUEST*/
320
+            data[MBIC_PAYLOADSTART + index++] = 3;
321
+            /*DOWNLOAD Reserve*/
322
+            data[MBIC_PAYLOADSTART + index++] = 0;
323
+            data[MBIC_PAYLOADSTART + index++] = 0;
324
+            data[MBIC_PAYLOADSTART + index++] = 0;
325
+            data[MBIC_PAYLOADSTART + index++] = 0;
326
+            data[MBIC_PAYLOADSTART + index++] = 0;
327
+            data[MBIC_PAYLOADSTART + index++] = 0;  
328
+            break;
329
+        case MBIC_Reboot_Notice_REQ:
330
+            cmd = MBIC_Reboot_Notice_RSP;
331
+            /*TOTAL FRAME NUMBER*/
332
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];
333
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];        
334
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 2];
335
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 3];        
336
+            /*DOWNLOAD OPTION*/        
337
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 4];
338
+            Download_Option = data[MBIC_PAYLOADSTART + 4];
339
+            /*DOWNLOAD DELAY REQUEST*/
340
+            data[MBIC_PAYLOADSTART + index++] = 3;
341
+            /*DOWNLOAD Reserve*/
342
+            data[MBIC_PAYLOADSTART + index++] = 0;
343
+            data[MBIC_PAYLOADSTART + index++] = 0;
344
+            data[MBIC_PAYLOADSTART + index++] = 0;
345
+            data[MBIC_PAYLOADSTART + index++] = 0;
346
+            data[MBIC_PAYLOADSTART + index++] = 0;
347
+            data[MBIC_PAYLOADSTART + index++] = 0;          
348
+            break;
349
+        default:
350
+            return;
351
+    }
352
+    data[MBIC_CMD_0] = cmd;
353
+    
354
+    data = MBIC_HeaderMergeFunction(data,index); // reponse
355
+//	HAL_UART_Transmit_DMA(&huart1, data,22 + 3 + index);
356
+
357
+    
358
+    Uart1_Data_Send(data ,22 + 3 + index);
359
+}

+ 242 - 0
Bluecell_Src/flash.c

@@ -0,0 +1,242 @@
1
+/*
2
+ * flash.c
3
+ *
4
+ *  Created on: 2019. 7. 15.
5
+ *      Author: parkyj
6
+ */
7
+#include "flash.h"
8
+#include "MBIC_Bootloader.h"
9
+uint8_t flashinit = 0;
10
+uint32_t Address = FLASH_USER_START_ADDR;
11
+volatile static uint32_t UserAddress;
12
+
13
+typedef void (*fptr)(void);
14
+fptr jump_to_app;
15
+uint32_t jump_addr;
16
+void Jump_App(void){
17
+    __HAL_RCC_TIM6_CLK_DISABLE(); // 留ㅼ씤???占쏙옙癒몌옙?? ?占쏙옙占�??占쏙옙?占쏙옙?占쏙옙
18
+    printf("boot loader start\n");               //硫붿꽭占�? 異쒕젰
19
+    jump_addr = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
20
+    jump_to_app = (fptr) jump_addr;
21
+    
22
+    /* init user app's sp */
23
+    printf("jump!\n");
24
+    __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
25
+    jump_to_app();
26
+}
27
+
28
+
29
+
30
+void Flash_InitRead(void) // ?占쏙옙湲고븿?占쏙옙
31
+{
32
+    uint32_t  Address = 0;
33
+    Address = FLASH_USER_TEMPBANK_START_ADDR;
34
+    for(uint32_t i = 0; i < 300; i++ ){
35
+        printf("%08x : %02X \n",Address ,*(uint8_t*)Address);
36
+        Address++;
37
+    }
38
+#if 0 // PYJ.2019.03.27_BEGIN -- 
39
+    for(uint32_t i = 0; i < 13848; i++ ){
40
+        printf("%08x : %02X \n",Address ,*(uint8_t*)Address);
41
+        Address++;
42
+    }
43
+    Address = StartAddr;
44
+    for(uint32_t i = 0; i < 13848; i++ ){
45
+        printf("%02X ",*(uint8_t*)Address);
46
+        Address++;
47
+    }
48
+#endif // PYJ.2019.03.27_END -- 
49
+
50
+}
51
+
52
+
53
+
54
+uint8_t Flash_Data_Write(uint8_t* data){
55
+    uint16_t Firmdata = 0;
56
+    uint8_t ret = 0;
57
+    int i = 0;
58
+    static uint32_t Curr_Download_DataIndex = 0;
59
+    static uint32_t Prev_Download_DataIndex = 0;  
60
+    
61
+    Curr_Download_DataIndex = data[MBIC_PAYLOADSTART  + 4] << 24;
62
+    Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 5] << 16;
63
+    Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 6] << 8;            
64
+    Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 7];      
65
+
66
+//    data[MBIC_PAYLOADSTART + 12 +i];
67
+   
68
+    returntoFirst:
69
+    UserAddress -= i;
70
+    for(i= 0; i <= Curr_Download_DataIndex - Prev_Download_DataIndex; i+=2){
71
+        Firmdata  = ((data[MBIC_PAYLOADSTART + 12 +i]) & 0x00FF);
72
+        Firmdata  += ((data[MBIC_PAYLOADSTART + 12 +i + 1] << 8) & 0xFF00);
73
+        if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,UserAddress ,   (uint16_t)Firmdata) != HAL_OK){
74
+            printf("HAL NOT OK \n");
75
+            ret = 1;
76
+            HAL_Delay(1000);
77
+            goto returntoFirst;
78
+        }else{
79
+            UserAddress += 2;
80
+        }
81
+    }
82
+    Prev_Download_DataIndex = Curr_Download_DataIndex + 1;
83
+    return ret;
84
+}
85
+
86
+
87
+
88
+
89
+uint8_t Bank_Flash_write(uint8_t* data,uint32_t StartBankAddress) // ?占쏙옙湲고븿?占쏙옙
90
+{
91
+
92
+    /*Variable used for Erase procedure*/
93
+    static FLASH_EraseInitTypeDef EraseInitStruct;
94
+    static uint32_t PAGEError = 0;
95
+    uint8_t ret = 0;
96
+
97
+
98
+    HAL_FLASH_Unlock(); // lock ??占�?
99
+    if(flashinit == 0){
100
+        
101
+        flashinit= 1;
102
+        /* Fill EraseInit structure*/
103
+        switch(StartBankAddress){
104
+            case FLASH_USER_START_ADDR:
105
+                EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
106
+                EraseInitStruct.PageAddress = FLASH_USER_START_ADDR - 128;
107
+                EraseInitStruct.NbPages     = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;
108
+            break;
109
+            case FLASH_USER_BANK1_START_ADDR:
110
+                EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
111
+                EraseInitStruct.PageAddress = FLASH_USER_BANK1_START_ADDR - 128;
112
+                EraseInitStruct.NbPages     = (FLASH_USER_END_ADDR - FLASH_USER_BANK1_START_ADDR) / FLASH_PAGE_SIZE;
113
+
114
+            break;
115
+            case FLASH_USER_BANK2_START_ADDR:
116
+                EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
117
+                EraseInitStruct.PageAddress = FLASH_USER_BANK2_START_ADDR - 128;
118
+                EraseInitStruct.NbPages     = (FLASH_USER_END_ADDR - FLASH_USER_BANK2_START_ADDR) / FLASH_PAGE_SIZE;
119
+
120
+            break;
121
+            case FLASH_USER_TEMPBANK_START_ADDR:
122
+                EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
123
+                EraseInitStruct.PageAddress = FLASH_USER_TEMPBANK_START_ADDR - 128;
124
+                EraseInitStruct.NbPages     = (FLASH_USER_END_ADDR - FLASH_USER_TEMPBANK_START_ADDR) / FLASH_PAGE_SIZE;
125
+            break;
126
+
127
+        }        
128
+        
129
+        UserAddress = EraseInitStruct.PageAddress;
130
+        //FLASH_PageErase(StartAddr);
131
+        if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK){
132
+            printf("Erase Failed \r\n");
133
+        }
134
+    }
135
+    ret = Flash_Data_Write(&data[MBIC_PREAMBLE_0]);
136
+    HAL_FLASH_Lock(); // lock ?占쏙옙洹멸린
137
+    return ret;
138
+}
139
+#define DATA_32                 ((uint32_t)0x12345678)
140
+__IO bool EraseInit = false;
141
+
142
+void MBIC_APIFLASH_test(){
143
+    static FLASH_EraseInitTypeDef EraseInitStruct;
144
+    static uint32_t Address = 0, PAGEError = 0;
145
+        
146
+    static __IO uint32_t data32 = 0 , MemoryProgramStatus = 0;
147
+
148
+    HAL_FLASH_Unlock();
149
+    
150
+    /* Erase the user Flash area
151
+      (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
152
+    
153
+    /* Fill EraseInit structure*/
154
+    if(EraseInit == false){
155
+        EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
156
+        EraseInitStruct.PageAddress = FLASH_USER_TEMPBANK_START_ADDR;
157
+        EraseInitStruct.NbPages     = ((FLASH_USER_TEMPBANK_START_ADDR + ((uint32_t)0x000FFFF)) - FLASH_USER_TEMPBANK_START_ADDR) / FLASH_PAGE_SIZE;
158
+        printf("Erase Start\r\n");
159
+        if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
160
+        {
161
+          /*
162
+            Error occurred while page erase.
163
+            User can add here some code to deal with this error.
164
+            PAGEError will contain the faulty page and then to know the code error on this page,
165
+            user can call function 'HAL_FLASH_GetError()'
166
+          */
167
+          /* Infinite loop */
168
+          while (1)
169
+          {
170
+            /* Make LED2 blink (100ms on, 2s off) to indicate error in Erase operation */
171
+            printf("HAL_FLASHEx_Erase Error\r\n");
172
+            
173
+            HAL_Delay(2000);
174
+          }
175
+        }
176
+        EraseInit = true;
177
+        printf("Erase End\r\n");
178
+    }
179
+    /* Program the user Flash area word by word
180
+      (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
181
+    
182
+    Address = FLASH_USER_TEMPBANK_START_ADDR;
183
+    printf("HAL_FLASH_Program Start\r\n");
184
+    while (Address < ((FLASH_USER_TEMPBANK_START_ADDR + ((uint32_t)0x000FFFF))))
185
+    {
186
+      if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, Address, DATA_32) == HAL_OK)
187
+      {
188
+        Address = Address + 2;
189
+      }
190
+      else
191
+      {
192
+        /* Error occurred while writing data in Flash memory.
193
+           User can add here some code to deal with this error */
194
+        while (1)
195
+        {
196
+          /* Make LED2 blink (100ms on, 2s off) to indicate error in Write operation */
197
+          /* Make LED2 blink (100ms on, 2s off) to indicate error in Erase operation */
198
+          printf("HAL_FLASH_Program Error\r\n");
199
+
200
+        }
201
+      }
202
+    }
203
+     printf("HAL_FLASH_Program END\r\n");
204
+    /* Lock the Flash to disable the flash control register access (recommended
205
+       to protect the FLASH memory against possible unwanted operation) *********/
206
+    HAL_FLASH_Lock();
207
+    
208
+    /* Check if the programmed data is OK
209
+        MemoryProgramStatus = 0: data programmed correctly
210
+        MemoryProgramStatus != 0: number of words not programmed correctly ******/
211
+    Address = FLASH_USER_TEMPBANK_START_ADDR;
212
+    MemoryProgramStatus = 0x0;
213
+    
214
+    while (Address < ((FLASH_USER_TEMPBANK_START_ADDR + ((uint32_t)0x000FFFF))))
215
+    {
216
+      data32 = *(__IO uint32_t *)Address;
217
+       printf("%08x : %02X \n",Address ,*(uint8_t*)Address);
218
+      if (data32 != DATA_32)
219
+      {
220
+        MemoryProgramStatus++;
221
+      }
222
+      Address = Address + 4;
223
+    }
224
+    
225
+    /*Check if there is an issue to program data*/
226
+    if (MemoryProgramStatus == 0)
227
+    {
228
+        printf("DATA OK \r\n");
229
+      /* No error detected. Switch on LED2*/
230
+    }
231
+    else
232
+    {
233
+      /* Error detected. LED2 will blink with 1s period */
234
+      while (1)
235
+      {
236
+         printf("Read Error\r\n");
237
+      }
238
+    }
239
+
240
+
241
+}
242
+

+ 5 - 1
Src/main.c

@@ -353,7 +353,7 @@ int main(void)
353 353
   HAL_ADC_Start_DMA(&hadc3, (uint16_t*)ADC3value, 5);
354 354
   HAL_ADC_Start_DMA(&hadc1, (uint16_t*)ADC1value, 4);
355 355
   HAL_TIM_Base_Start_IT(&htim6);
356
-  InitUartQueue(&TerminalQueue);
356
+
357 357
   setbuf(stdout, NULL);
358 358
   PE43711_PinInit();
359 359
   EEPROM_M24C08_Init();
@@ -366,6 +366,9 @@ int main(void)
366 366
     printf("Copyright (c) 2020. BLUECELL\r\n");
367 367
     printf("****************************************\r\n");
368 368
 #endif // PYJ.2020.05.06_END --   
369
+  MBIC_APIFLASH_test();
370
+  //Flash_InitRead();
371
+
369 372
   Booting_LedInit();
370 373
   Booting_LED_Check();
371 374
 #if 0 // PYJ.2020.04.22_BEGIN -- 
@@ -388,6 +391,7 @@ int main(void)
388 391
 //    uint16_t rrrrrr = 0;
389 392
 //  rrrrrr = ((CRC16_Generate(&retdate[0], 10)));  
390 393
 //  printf("CRC : %x \r\n",rrrrrr);
394
+  InitUartQueue(&TerminalQueue);
391 395
   while (1)
392 396
   {
393 397
 //	  HAL_GPIO_TogglePin(GPIOG,GPIO_PIN_14);