Pārlūkot izejas kodu

HFR Boot Index 추가 / EEPROM Falsh init 부분 추가 /

PYJ 5 gadi atpakaļ
vecāks
revīzija
f54eb028a3

+ 0 - 2
.settings/org.eclipse.core.resources.prefs

@@ -1,2 +0,0 @@
1
-eclipse.preferences.version=1
2
-encoding//Src/flash.c=UTF-8

BIN
Debug/STM32F103_ATTEN_PLL_Zig.elf


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1139 - 808
Debug/STM32F103_ATTEN_PLL_Zig.hex


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 6975 - 4914
Debug/STM32F103_ATTEN_PLL_Zig.list


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 696 - 659
Debug/STM32F103_ATTEN_PLL_Zig.map


+ 1 - 1
Debug/Src/CRC16.su

@@ -5,4 +5,4 @@ CRC16.c:156:9:CRC16_Check	12	static
5 5
 CRC16.c:191:9:STH30_CreateCrc	8	static
6 6
 CRC16.c:209:9:STH30_CheckCrc	12	static
7 7
 CRC16.c:228:10:crc32	8	static
8
-CRC16.c:242:9:crc32Check	12	static
8
+CRC16.c:243:9:crc32Check	12	static

+ 6 - 5
Debug/Src/main.su

@@ -1,5 +1,6 @@
1
-main.c:82:6:HAL_TIM_PeriodElapsedCallback	0	static
2
-main.c:91:5:_write	8	static
3
-main.c:189:6:SystemClock_Config	72	static
4
-main.c:107:5:main	40	static
5
-main.c:432:6:Error_Handler	0	static
1
+main.c:83:6:HAL_TIM_PeriodElapsedCallback	0	static
2
+main.c:92:5:_write	8	static
3
+main.c:100:6:BootingBankSelect	16	static
4
+main.c:241:6:SystemClock_Config	72	static
5
+main.c:134:5:main	40	static
6
+main.c:484:6:Error_Handler	0	static

+ 19 - 0
Inc/eeprom.h

@@ -563,6 +563,25 @@ typedef struct{
563 563
   int8_t Table_Ref;
564 564
   int8_t Table_Length;
565 565
 }TEMP_TABLE_st;
566
+typedef enum{
567
+    HFR_BANK1_SEL = 1,
568
+    HFR_BANK2_SEL = 2,
569
+    HFR_AUTO_SEL = 3,    
570
+}HFR_BootSelIndex_;
571
+
572
+typedef enum{
573
+    MBIC_BOOT_MARK  =     0,
574
+    MBIC_BOOT_TYPE   =    9   ,
575
+    MBIC_BOOT_FILE_TYPE=      10,
576
+    MBIC_BOOT_VERSION  = 11,
577
+    MBIC_BOOT_FILENAME  =      14,
578
+    MBIC_BOOT_CREATION_TIME=     55,
579
+    MBIC_BOOT_LENGTH = 61,
580
+    MBIC_BOOT_CRC     =65,
581
+    MBIC_BOOT_RESERVED =       69,
582
+    MBIC_BOOT_DATA =       128,
583
+
584
+}HFR_BootLoader_Index_;
566 585
 
567 586
 
568 587
 typedef struct{

+ 6 - 6
Inc/flash.h

@@ -13,17 +13,17 @@
13 13
 
14 14
 
15 15
 
16
-#define FLASH_MBICUSER_START_ADDR (uint32_t)((0x08005000) - 128)
16
+#define FLASH_MBICUSER_START_ADDR (uint32_t)((0x08008000) - 128)
17 17
 #define FLASH_MBICUSER_END_ADDR FLASH_MBICUSER_START_ADDR + ((uint32_t)0x1FFFF)
18 18
 
19 19
 
20
-#define FLASH_USER_START_ADDR ((uint32_t)0x08005000)
21
-#define FLASH_USER_END_ADDR     FLASH_USER_START_ADDR + ((uint32_t)0x000FFFF)   /* End @ of user Flash area */
20
+#define FLASH_USER_START_ADDR ((uint32_t)0x08008000)
21
+#define FLASH_USER_END_ADDR     FLASH_USER_START_ADDR + ((uint32_t)0x1FFFF)   /* End @ of user Flash area */
22 22
 
23
-#define APPLICATION_ADDRESS     (uint32_t)0x08005000      /* Start user code address: ADDR_FLASH_PAGE_8 */
23
+#define APPLICATION_ADDRESS     (uint32_t)0x08008000      /* Start user code address: ADDR_FLASH_PAGE_8 */
24 24
 
25
-#define FLASH_USER_BANK1_START_ADDR ((uint32_t)0x08025000)
26
-#define FLASH_USER_BANK2_START_ADDR ((uint32_t)0x08045000)
25
+#define FLASH_USER_BANK1_START_ADDR ((uint32_t)0x08028000)
26
+#define FLASH_USER_BANK2_START_ADDR ((uint32_t)0x08048000)
27 27
 
28 28
 
29 29
 

+ 2 - 2
STM32F103ZE_FLASH.ld

@@ -40,8 +40,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
40 40
 /* Specify the memory areas */
41 41
 MEMORY
42 42
 {
43
-RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 64K
44
-FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 20K
43
+RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 10K
44
+FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 32K
45 45
 }
46 46
 
47 47
 /* Define output sections */

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 8 - 8
STM32F103_ATTEN_PLL_Zig.elf.launch


+ 2 - 1
Src/CRC16.c

@@ -234,7 +234,8 @@ uint32_t crc32(const void *buf, size_t size)
234 234
     crcret = crcret ^ ~0U;						
235 235
 						
236 236
     while (size--) {						
237
-        crcret = crc32_tab[(crcret ^ *p++) & 0xFF] ^ (crcret >> 8);						
237
+//        printf("index : size :  %d    buf %x \r\n",size,*p);                
238
+        crcret = crc32_tab[(crcret ^ *p++) & 0xFF] ^ (crcret >> 8);			
238 239
     }						
239 240
 						
240 241
     return crcret ^ ~0U;						

+ 0 - 1
Src/MBIC_Bootloader.c

@@ -19,7 +19,6 @@ extern uint8_t Bank_Flash_write(uint8_t* data,uint32_t StartBankAddress);
19 19
 
20 20
 
21 21
 
22
-
23 22
 BootLoaderDataCheck_st MBIC_FileDataCheck(uint8_t* data){
24 23
   BootLoaderDataCheck_st ret = {0,0,false};
25 24
   int8_t MBIC_Mark[9] = "JT-NRDAS ";

+ 178 - 16
Src/eeprom.c

@@ -8,11 +8,13 @@
8 8
 #include <string.h>
9 9
 #include "main.h"
10 10
 #include "eeprom.h"
11
+#include "flash.h"
11 12
 #include "stm32f1xx_hal.h"
12 13
 #include "stm32f1xx_hal_gpio.h"
13 14
 
14 15
 /* Includes ------------------------------------------------------------------*/   
15 16
 HAL_StatusTypeDef EEPROM_M24C08_ByteRead(uint16_t devid,uint16_t Address,uint8_t* data,uint8_t size);
17
+extern uint8_t MBIC_BankBooting_Flash_write(uint8_t* data,uint32_t StartBankAddress);
16 18
 
17 19
 
18 20
 BLUESTATUS_st bluecell_Currdatastatus;
@@ -21,41 +23,201 @@ BLUESTATUS_st bluecell_Currdatastatus;
21 23
 extern I2C_HandleTypeDef hi2c2;
22 24
 
23 25
 
24
-typedef enum{
25
-    HFR_BANK1_SEL = 1,
26
-    HFR_BANK2_SEL = 2,
27
-    HFR_AUTO_SEL = 3,    
28
-}HFR_BootSelIndex_;
29 26
 
30 27
 
31 28
 
32 29
 void EEPROM_M24C08_Init(void){
30
+    
31
+    bool Download_Possible[2] = {false,false};
33 32
     EEPROM_M24C08_Read(EEPROM_M24C08_ID,EEPROM_WINDOW_STATUS_ADDRESDS,&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st) );
33
+
34
+
35
+
36
+    uint32_t  CurrApiAddress = 0,Bank1Address=0,Bank2Address = 0;
37
+    uint32_t i = 0;
38
+    uint8_t ret = 0;
39
+    CurrApiAddress = FLASH_MBICUSER_START_ADDR;
40
+    Bank1Address = FLASH_USER_BANK1_START_ADDR;
41
+    Bank2Address = FLASH_USER_BANK2_START_ADDR;
42
+
43
+    uint8_t* Currdata = (uint8_t*)CurrApiAddress;
44
+    uint8_t* Bank1data = (uint8_t*)Bank1Address;
45
+    uint8_t* Bank2data = (uint8_t*)Bank2Address;
46
+
47
+    uint32_t FileCrc = 0;
48
+    uint32_t CrcLength = 0;
49
+    uint32_t crcret=0;
50
+
51
+
52
+      
53
+
54
+
55
+
56
+
57
+
58
+    printf("Flash Init \r\n");
59
+   
60
+    uint8_t* pdata;
61
+    bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime1 = Bank1data[MBIC_BOOT_CREATION_TIME + 0];
62
+    bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime2 = Bank1data[MBIC_BOOT_CREATION_TIME + 1];
63
+    bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime3 = Bank1data[MBIC_BOOT_CREATION_TIME + 2];
64
+    bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime4 = Bank1data[MBIC_BOOT_CREATION_TIME + 3];
65
+    bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime5 = Bank1data[MBIC_BOOT_CREATION_TIME + 4];
66
+    bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime6 = Bank1data[MBIC_BOOT_CREATION_TIME + 5];
67
+
68
+    bluecell_Currdatastatus.CPU_Bank1_Image_Version1 = Bank1data[MBIC_BOOT_VERSION + 0];
69
+    bluecell_Currdatastatus.CPU_Bank1_Image_Version2 = Bank1data[MBIC_BOOT_VERSION + 1];
70
+    bluecell_Currdatastatus.CPU_Bank1_Image_Version3 = Bank1data[MBIC_BOOT_VERSION + 2];
71
+
72
+    pdata = &bluecell_Currdatastatus.CPU_Bank1_Image_Name;
73
+    printf("BANK1 IMAGE NAME : ");
74
+    for(int i = 0 ; i< 32; i++){
75
+       pdata[i] = Bank1data[MBIC_BOOT_FILENAME + i];
76
+       printf("%c",pdata[i]);
77
+    }
78
+    printf("\r\n");
79
+
80
+
81
+    bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime1 = Bank2data[MBIC_BOOT_CREATION_TIME + 0];
82
+    bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime2 = Bank2data[MBIC_BOOT_CREATION_TIME + 1];
83
+    bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime3 = Bank2data[MBIC_BOOT_CREATION_TIME + 2];
84
+    bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime4 = Bank2data[MBIC_BOOT_CREATION_TIME + 3];
85
+    bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime5 = Bank2data[MBIC_BOOT_CREATION_TIME + 4];
86
+    bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime6 = Bank2data[MBIC_BOOT_CREATION_TIME + 5];
87
+
88
+    bluecell_Currdatastatus.CPU_Bank2_Image_Version1 = Bank2data[MBIC_BOOT_VERSION + 0];
89
+    bluecell_Currdatastatus.CPU_Bank2_Image_Version2 = Bank2data[MBIC_BOOT_VERSION + 1];
90
+    bluecell_Currdatastatus.CPU_Bank2_Image_Version3 = Bank2data[MBIC_BOOT_VERSION + 2];
91
+
92
+    pdata = & bluecell_Currdatastatus.CPU_Bank2_Image_Name;
93
+    printf("BANK2 IMAGE NAME : ");
94
+    for(int i = 0 ; i< 32; i++){
95
+       pdata[i] = Bank2data[MBIC_BOOT_FILENAME + i];  
96
+       printf("%c",pdata[i]);
97
+    }
98
+    printf("\r\n");
99
+
100
+
101
+   printf("20%d Y / %d M / %d D / %d H / %d M / %d S  \r\n",
102
+   Currdata[MBIC_BOOT_CREATION_TIME + 0],
103
+   Currdata[MBIC_BOOT_CREATION_TIME + 1],
104
+   Currdata[MBIC_BOOT_CREATION_TIME + 2],
105
+   Currdata[MBIC_BOOT_CREATION_TIME + 3],
106
+   Currdata[MBIC_BOOT_CREATION_TIME + 4],
107
+   Currdata[MBIC_BOOT_CREATION_TIME + 5]        
108
+);
109
+
110
+    if(Currdata[MBIC_BOOT_VERSION + 0] == Bank1data[MBIC_BOOT_VERSION + 0]
111
+     &&Currdata[MBIC_BOOT_VERSION + 1] == Bank1data[MBIC_BOOT_VERSION + 1]
112
+     &&Currdata[MBIC_BOOT_VERSION + 2] == Bank1data[MBIC_BOOT_VERSION + 2]){
113
+      ret = HFR_BANK1_SEL;
114
+    }else if(
115
+       Currdata[MBIC_BOOT_VERSION + 0] == Bank2data[MBIC_BOOT_VERSION + 0]
116
+     &&Currdata[MBIC_BOOT_VERSION + 1] == Bank2data[MBIC_BOOT_VERSION + 1]
117
+     &&Currdata[MBIC_BOOT_VERSION + 2] == Bank2data[MBIC_BOOT_VERSION + 2]){
118
+      ret = HFR_BANK2_SEL;
119
+    }else{
120
+      ret = 0;
121
+    }
122
+
123
+    bluecell_Currdatastatus.CPU_Current_Bank = ret;
124
+    printf("MBIC BANK %d Booting \r\n",bluecell_Currdatastatus.CPU_Current_Bank);    
34 125
     printf("bluecell_Currdatastatus.CPU_Bank_Select : %d \r\n",bluecell_Currdatastatus.CPU_Bank_Select);
126
+
127
+    if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK2_SEL)
128
+    {
129
+       ret = HFR_BANK2_SEL;
130
+        FileCrc = 
131
+        ((Bank2data[MBIC_BOOT_CRC] << 24 ) 
132
+        | Bank2data[MBIC_BOOT_CRC + 1]<<16 
133
+        | Bank2data[MBIC_BOOT_CRC + 2]<<8   
134
+        | Bank2data[MBIC_BOOT_CRC + 3]);
135
+        CrcLength=
136
+        ((Bank2data[MBIC_BOOT_LENGTH] << 24 ) 
137
+        | Bank2data[MBIC_BOOT_LENGTH + 1]<<16 
138
+        | Bank2data[MBIC_BOOT_LENGTH + 2]<<8   
139
+        | Bank2data[MBIC_BOOT_LENGTH + 3]);       
140
+        crcret = crc32(&Bank2data[MBIC_BOOT_DATA], CrcLength);
141
+    }
142
+    else if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK1_SEL)
143
+    {
144
+       ret = HFR_BANK1_SEL;
145
+        FileCrc = 
146
+        ((Bank1data[MBIC_BOOT_CRC] << 24 ) 
147
+        | Bank1data[MBIC_BOOT_CRC + 1]<<16 
148
+        | Bank1data[MBIC_BOOT_CRC + 2]<<8   
149
+        | Bank1data[MBIC_BOOT_CRC + 3]);
150
+        CrcLength=
151
+        ((Bank1data[MBIC_BOOT_LENGTH] << 24 ) 
152
+        | Bank1data[MBIC_BOOT_LENGTH + 1]<<16 
153
+        | Bank1data[MBIC_BOOT_LENGTH + 2]<<8   
154
+        | Bank1data[MBIC_BOOT_LENGTH + 3]);
155
+        crcret = crc32(&Bank1data[MBIC_BOOT_DATA], CrcLength);
156
+    }
157
+    else if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_AUTO_SEL)
158
+    {
159
+        if(bluecell_Currdatastatus.CPU_Current_Bank == HFR_BANK1_SEL)
160
+        {
161
+           ret = HFR_BANK1_SEL;
162
+            FileCrc = 
163
+            ((Bank1data[MBIC_BOOT_CRC] << 24 ) 
164
+            | Bank1data[MBIC_BOOT_CRC + 1]<<16 
165
+            | Bank1data[MBIC_BOOT_CRC + 2]<<8   
166
+            | Bank1data[MBIC_BOOT_CRC + 3]);
167
+            CrcLength=
168
+            ((Bank1data[MBIC_BOOT_LENGTH] << 24 ) 
169
+            | Bank1data[MBIC_BOOT_LENGTH + 1]<<16 
170
+            | Bank1data[MBIC_BOOT_LENGTH + 2]<<8   
171
+            | Bank1data[MBIC_BOOT_LENGTH + 3]);
172
+             crcret = crc32(&Bank1data[MBIC_BOOT_DATA], CrcLength);
173
+        }
174
+        else    
175
+        {
176
+            ret = HFR_BANK2_SEL;
177
+            FileCrc = 
178
+            ((Bank2data[MBIC_BOOT_CRC] << 24 ) 
179
+            | Bank2data[MBIC_BOOT_CRC + 1]<<16 
180
+            | Bank2data[MBIC_BOOT_CRC + 2]<<8   
181
+            | Bank2data[MBIC_BOOT_CRC + 3]);
182
+            CrcLength=
183
+            ((Bank2data[MBIC_BOOT_LENGTH] << 24 ) 
184
+            | Bank2data[MBIC_BOOT_LENGTH + 1]<<16 
185
+            | Bank2data[MBIC_BOOT_LENGTH + 2]<<8   
186
+            | Bank2data[MBIC_BOOT_LENGTH + 3]);           
187
+        }
188
+        crcret = crc32(&Bank2data[MBIC_BOOT_DATA], CrcLength);
189
+    }
190
+    printf("CRC LENGTH : %d,CRC LENGTH : %X \r\n",CrcLength,CrcLength);
191
+    if(crcret != FileCrc){
192
+        printf("CRC ERROR : %x , File CRC : %x \r\n",crcret,FileCrc);
193
+        return;
194
+    }
195
+    else
196
+        printf("CRC SUCCESS  : %x , File CRC : %x \r\n",crcret,FileCrc);      
197
+
198
+
35 199
     
36
-    if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK1_SEL){
37
-        printf("Write Start \r\n");
200
+    if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK1_SEL && bluecell_Currdatastatus.CPU_Current_Bank != HFR_BANK1_SEL){
201
+        printf("Write Start BANK 1 Down Start\r\n");
38 202
         MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK1_START_ADDR,FLASH_MBICUSER_START_ADDR);
39 203
         bluecell_Currdatastatus.CPU_Bank_Select = 5;
40
-    }else if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK2_SEL){
41
-                printf("Write Start \r\n");
204
+    }else if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK2_SEL && bluecell_Currdatastatus.CPU_Current_Bank != HFR_BANK2_SEL){
205
+        printf("Write Start BANK 2 Down Start\r\n");
42 206
         MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK2_START_ADDR,FLASH_MBICUSER_START_ADDR);
43 207
         bluecell_Currdatastatus.CPU_Bank_Select = 6;
44 208
     }
45
-    else if (bluecell_Currdatastatus.CPU_Bank_Select == HFR_AUTO_SEL){
46
-        if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK1_SEL){
47
-                    printf("Write Start \r\n");
209
+    else if (bluecell_Currdatastatus.CPU_Bank_Select == HFR_AUTO_SEL || bluecell_Currdatastatus.CPU_Bank_Select == 7){
210
+        if(bluecell_Currdatastatus.CPU_Current_Bank == HFR_BANK1_SEL){
211
+            printf("Write Start BANK BANK 1 Down Start\r\n");
48 212
             MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK2_START_ADDR,FLASH_MBICUSER_START_ADDR);
49
-            bluecell_Currdatastatus.CPU_Bank_Select = 6;
50 213
         }else{
51
-                    printf("Write Start \r\n");
214
+            printf("Write Start BANK BANK 2 Down Start\r\n");
52 215
             MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK1_START_ADDR,FLASH_MBICUSER_START_ADDR);
53
-            bluecell_Currdatastatus.CPU_Bank_Select = 5;
54 216
         }
217
+        bluecell_Currdatastatus.CPU_Bank_Select = 3;
55 218
     }
56 219
     EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_WINDOW_STATUS_ADDRESDS),&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));    
57 220
     printf("EEPROM INIT COMPLETE\r\n");
58
-
59 221
 }
60 222
 
61 223
 

+ 18 - 12
Src/flash.c

@@ -9,6 +9,7 @@
9 9
 uint8_t flashinit = 0;
10 10
 uint32_t Address = FLASH_USER_START_ADDR;
11 11
 volatile uint32_t UserAddress;
12
+uint8_t MBIC_BankBooting_Flash_write(uint8_t* data,uint32_t StartBankAddress);
12 13
 
13 14
 
14 15
 typedef void (*fptr)(void);
@@ -123,17 +124,17 @@ uint8_t MBIC_Flash_Data_Write(uint8_t* data){
123 124
     uint16_t Curr_Download_Data = 0;
124 125
 
125 126
 #endif // PYJ.2020.06.24_END -- 
126
-        printf("=====================Data Recv2================\r\n");
127
-    for(a  = 0; a  < 128; a++ ){
128
-        printf("%08x : %02X  Index : %d \n",data ,*(uint8_t*)data,a );
129
-        data++;
130
-    }  
131
-    data -= a;
132
-        printf("=====================Data Recv2================\r\n");    
133
-    printf("Download Data Length :%d \r\n",WriteDataLength);
127
+//        printf("=====================Data Recv2================\r\n");
128
+//    for(a  = 0; a  < 128; a++ ){
129
+//        printf("%08x : %02X  Index : %d \n",data ,*(uint8_t*)data,a );
130
+//        data++;
131
+//    }  
132
+//    data -= a;
133
+//        printf("=====================Data Recv2================\r\n");    
134
+//    printf("Download Data Length :%d \r\n",WriteDataLength);
134 135
 
135 136
    
136
-    printf("Curr_Download_Data %x   : i  : %d\r\n",Curr_Download_Data,i);
137
+//    printf("Curr_Download_Data %x   : i  : %d\r\n",Curr_Download_Data,i);
137 138
 #if 0 // PYJ.2020.06.24_BEGIN -- 
138 139
     for(i= 0; i < 128; i+=4){
139 140
         Curr_Download_Data = 0;
@@ -196,8 +197,9 @@ uint8_t MBIC_Flash_Data_Write(uint8_t* data){
196 197
 //        Curr_Download_Data =  ;                  (*(uint8_t*)(data+((i * 4)+ 1)) << 8)
197 198
 //        Curr_Download_Data |= ;        
198 199
         uint16_t writedata = (*(uint8_t*)(data+((i)+ 1))) << 8 | (*(uint8_t*)(data+((i)+ 0)));
199
-        printf("%02X ",(*(uint8_t*)(data+((i )+ 0))));
200
-        printf("%02X ",(*(uint8_t*)(data+((i )+ 1))));
200
+        printf("%02X ",writedata & 0xFF00 >> 8);
201
+        printf("%02X ",writedata & 0x00FF);        
202
+//        printf("%02X ",(*(uint8_t*)(data+((i )+ 1))));
201 203
         
202 204
 //        if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,UserAddress , *(uint8_t*)(data+(i * 2))  | *(uint8_t*)data+((i * 2)+1) << 8) != HAL_OK){
203 205
         if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,UserAddress ,writedata /*(*(uint8_t*)(data+((i * 2)+ 0))) | (*(uint8_t*)(data+((i * 2)+ 1))) << 8*/) != HAL_OK){
@@ -489,6 +491,10 @@ uint8_t MBIC_BankBooting_Flash_write(uint8_t* data,uint32_t StartBankAddress) //
489 491
     uint32_t i = 0;
490 492
     printf("=====================Data Recv================\r\n");
491 493
     uint8_t datacnt = 0;
494
+    if(data[0]!= 0x4A){
495
+        printf("File ERRor\r\n");
496
+        return;
497
+    }
492 498
     for( i = 0; i < 128; i++ ){
493 499
         if(*(uint8_t*)data == 0xFF)
494 500
             datacnt++;
@@ -521,7 +527,7 @@ uint8_t MBIC_BankBooting_Flash_write(uint8_t* data,uint32_t StartBankAddress) //
521 527
                 /* Fill EraseInit structure*/
522 528
                 EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
523 529
                 EraseInitStruct.PageAddress = FLASH_MBICUSER_START_ADDR;
524
-                EraseInitStruct.NbPages     = (FLASH_MBICUSER_END_ADDR - FLASH_MBICUSER_START_ADDR) / FLASH_PAGE_SIZE;
530
+                EraseInitStruct.NbPages     = ((FLASH_MBICUSER_END_ADDR - FLASH_MBICUSER_START_ADDR) / FLASH_PAGE_SIZE )+ 1;
525 531
 #else
526 532
                 EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
527 533
                 EraseInitStruct.PageAddress = FLASH_MBICUSER_START_ADDR;

+ 60 - 8
Src/main.c

@@ -25,8 +25,9 @@
25 25
 /* USER CODE BEGIN Includes */
26 26
 #include <stdio.h>
27 27
 #include "flash.h"
28
+#include "eeprom.h"
28 29
 /* USER CODE END Includes */
29
-
30
+#include "MBIC_Bootloader.h"
30 31
 /* Private typedef -----------------------------------------------------------*/
31 32
 /* USER CODE BEGIN PTD */
32 33
 
@@ -96,6 +97,32 @@ int _write (int file, uint8_t *ptr, uint16_t len)
96 97
 extern UARTQUEUE TerminalQueue;
97 98
 
98 99
 
100
+void BootingBankSelect(){
101
+    uint32_t APIBankAddress = FLASH_USER_START_ADDR - 128;
102
+    uint8_t* data = (uint8_t*)APIBankAddress;
103
+    uint32_t Length = data[LENGTH_START_POSITION] << 24 
104
+                    | data[LENGTH_START_POSITION + 1] << 16
105
+                    | data[LENGTH_START_POSITION + 2] << 8
106
+                    | data[LENGTH_START_POSITION + 3];
107
+
108
+                    
109
+    printf("Length : %d \r\n",Length);
110
+    
111
+    for(uint32_t i = 0; i < 128; i++ ){
112
+        printf("%08x : %02X \n",APIBankAddress + i ,data[i]);
113
+//        printf("%08x : %02X \n",APIBankAddress ,*(uint8_t*)APIBankAddress);
114
+    } 
115
+    
116
+//    
117
+//    if()
118
+//        Address = FLASH_USER_START_ADDR - 128;
119
+//        for(uint32_t i = 0; i < 300; i++ ){
120
+//            printf("%08x : %02X \n",Address ,*(uint8_t*)Address);
121
+//            Address++;
122
+//        }
123
+
124
+
125
+}
99 126
 
100 127
 
101 128
 /* USER CODE END 0 */
@@ -143,21 +170,46 @@ int main(void)
143 170
   setbuf(stdout, NULL);
144 171
   /*printf("Uart Start \r\n");
145 172
   printf("Crc generate %x \r\n",CRC16_Generate(tempdata,11));*/
146
-#if 1 // PYJ.2020.06.24_BEGIN --
147
-  Firmware_BootStart_Signal();
173
+#if 0 // PYJ.2020.06.24_BEGIN --
174
+//  Firmware_BootStart_Signal();
148 175
 #else
149 176
 //  Jump_App();
150
-
151
-  /*printf("BootLoader Start ---\r\n");
152
-
177
+#if 0 // PYJ.2020.06.28_BEGIN -- 
178
+  uint32_t  CurrApiAddress = 0,Bank1Address=0,Bank2Address = 0;
179
+  uint8_t BankNum = 0;
180
+  uint32_t CrcLength = 0;
181
+  static bool CRCERR = false;
182
+  CurrApiAddress = FLASH_MBICUSER_START_ADDR;
183
+  Bank1Address = FLASH_USER_BANK1_START_ADDR;
184
+  Bank2Address = FLASH_USER_BANK2_START_ADDR;
185
+    uint8_t* Currdata = (uint8_t*)CurrApiAddress;
186
+    uint8_t* Bank1data = (uint8_t*)Bank1Address;
187
+    uint8_t* Bank2data = (uint8_t*)Bank2Address;   
188
+    CrcLength=
189
+    ((Bank1data[MBIC_BOOT_LENGTH] << 24 ) 
190
+    | Bank1data[MBIC_BOOT_LENGTH + 1]<<16 
191
+    | Bank1data[MBIC_BOOT_LENGTH + 2]<<8   
192
+    | Bank1data[MBIC_BOOT_LENGTH + 3]);  
193
+    
194
+  
195
+//  printf("CRC RET  : %x ,CRC RET : %x \r\n ",crc32(&Bank2data[MBIC_BOOT_DATA],CrcLength),CrcLength);
196
+  
197
+//  while(1);
198
+#endif // PYJ.2020.06.28_END -- 
199
+
200
+  printf("BootLoader Start ---\r\n");
201
+  EEPROM_M24C08_Init();
202
+
203
+//  BootingBankSelect();
153 204
   printf("BootLoader END\r\n");
154
-  Jump_App();*/
205
+  Jump_App();
206
+  while(1);
155 207
 
156 208
 //while(1);
157 209
 //  Jump_App();    
158 210
 
159 211
 #endif // PYJ.2020.06.24_END -- 
160
-  //MBIC_FirmwareFile_CrcCheck();
212
+//  MBIC_FirmwareFile_CrcCheck();
161 213
 //  FLASH_If_Init();
162 214
 //  Flash_InitRead();
163 215
   /* USER CODE END 2 */