Kaynağa Gözat

MBIC Index 추가 ,MBIC Flash Write 함수 별도 추가 ,

PYJ 5 yıl önce
ebeveyn
işleme
57c66e0499

BIN
Debug/STM32F103_ATTEN_PLL_Zig.elf


Dosya farkı çok büyük olduğundan ihmal edildi
+ 590 - 673
Debug/STM32F103_ATTEN_PLL_Zig.hex


Dosya farkı çok büyük olduğundan ihmal edildi
+ 3447 - 3958
Debug/STM32F103_ATTEN_PLL_Zig.list


Dosya farkı çok büyük olduğundan ihmal edildi
+ 483 - 481
Debug/STM32F103_ATTEN_PLL_Zig.map


+ 34 - 14
Inc/MBIC_Bootloader.h

@@ -8,20 +8,7 @@
8 8
 #ifndef MBIC_BOOTLOADER_H_
9 9
 #define MBIC_BOOTLOADER_H_
10 10
 
11
-typedef enum{
12
-  MBIC_Notice_REQ = 0x10,
13
-  MBIC_Download_DATA_REQ,
14
-  MBIC_Download_Confirm_REQ,
15
-  MBIC_Complete_Notice_REQ_REQ,
16
-  MBIC_Reboot_Notice_REQ,
17
-}MBIC_Download_Req_L;
18
-typedef enum{
19
-  MBIC_Notice_RSP = 0x90,
20
-  MBIC_Download_DATA_RSP,
21
-  MBIC_Download_Confirm_RSP,
22
-  MBIC_Complete_Notice_RSP,
23
-  MBIC_Reboot_Notice_RSP,
24
-}MBIC_Download_Rsp_L;
11
+
25 12
 
26 13
 #define MBIC_HEADER_SIZE 22
27 14
 #define MBIC_TAIL_SIZE 3
@@ -43,6 +30,15 @@ typedef enum{
43 30
 #define MBIC_CHECKSHUM_INDEX MBIC_HEADER_SIZE - 1 //CheckSUM REMOVE INDEX
44 31
 #define MBIC_ETX 0x03
45 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
46 42
 
47 43
 typedef enum{
48 44
 	MBIC_PREAMBLE_0 = 0,
@@ -75,5 +71,29 @@ typedef enum{
75 71
 	 * PayLoadSTART
76 72
 	 */
77 73
 }MBICProt_st;
74
+typedef enum{
75
+  MBIC_Notice_REQ = 0x10,
76
+  MBIC_Download_DATA_REQ,
77
+  MBIC_Download_Confirm_REQ,
78
+  MBIC_Complete_Notice_REQ_REQ,
79
+  MBIC_Reboot_Notice_REQ,
80
+}MBIC_Download_Req_L;
81
+typedef enum{
82
+  MBIC_Notice_RSP = 0x90,
83
+  MBIC_Download_DATA_RSP,
84
+  MBIC_Download_Confirm_RSP,
85
+  MBIC_Complete_Notice_RSP,
86
+  MBIC_Reboot_Notice_RSP,
87
+}MBIC_Download_Rsp_L;
88
+
89
+
90
+
91
+
92
+
93
+typedef struct{
94
+    uint16_t Length;
95
+    uint16_t Crcchk;
96
+    bool FileChk;
97
+}BootLoaderDataCheck_st;
78 98
 
79 99
 #endif /* MBIC_BOOTLOADER_H_ */

+ 1 - 0
Inc/flash.h

@@ -30,4 +30,5 @@
30 30
 #define FirmwareUpdateDelay 50
31 31
 
32 32
 
33
+
33 34
 #endif /* FLASH_H_ */

+ 1 - 1
Inc/uart.h

@@ -31,5 +31,5 @@ void InitUartQueue(pUARTQUEUE pQueue);
31 31
 void GetDataFromUartQueue(UART_HandleTypeDef *huart);
32 32
 bool Get_UartRcv(void);
33 33
 void Set_UartRcv(bool);
34
-void Uart1_Data_Send(uint8_t* data,uint8_t size);
34
+void Uart1_Data_Send(uint8_t* data,uint16_t size);
35 35
 #endif /* UART_H_ */

+ 1 - 0
STM32F103_ATTEN_PLL_Zig.elf.launch

@@ -45,4 +45,5 @@
45 45
 </listAttribute>
46 46
 <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;"/>
47 47
 <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
48
+<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="update_data_buf,data"/>
48 49
 </launchConfiguration>

+ 48 - 28
Src/MBIC_Bootloader.c

@@ -11,20 +11,13 @@
11 11
 #include "main.h"
12 12
 #include "MBIC_Bootloader.h"
13 13
 #include "CRC16.h"
14
-#define MARK_START_POSITION						0
15
-#define TYPE_START_POSITION						9	
16
-#define FILE_TYPE_START_POSITION				10
17
-#define VERSION_START_POSITION					11
18
-#define FILENAME_START_POSITION					14
19
-#define CREATION_TIME_START_POSITION			55
20
-#define LENGTH_START_POSITION					61
21
-#define CRC_START_POSITION						65
22
-#define RESERVED_START_POSITION					69
23
-typedef struct{
24
-    uint16_t Length;
25
-    uint16_t Crcchk;
26
-    bool FileChk;
27
-}BootLoaderDataCheck_st;
14
+#include "uart.h"
15
+
16
+
17
+extern uint8_t Bank_Flash_write(uint8_t* data,uint32_t StartBankAddress);
18
+
19
+
20
+
28 21
 
29 22
 
30 23
 BootLoaderDataCheck_st MBIC_FileDataCheck(uint8_t* data){
@@ -118,7 +111,7 @@ BootLoaderDataCheck_st MBIC_FileDataCheck(uint8_t* data){
118 111
 
119 112
   ret.Crcchk = ((data[i++] << 8) & 0xFF00);
120 113
   ret.Crcchk += (data[i++]);
121
-  
114
+  /*ONLY DATA CRC*/  
122 115
   printf("CRC_H[%d] : %x\r\n",i,ret.Crcchk);
123 116
   printf("CRC_L[%d] : %x\r\n",i,ret.Crcchk);
124 117
 
@@ -137,7 +130,6 @@ uint8_t* MBIC_HeaderMergeFunction(uint8_t* data,uint16_t Length )
137 130
 {
138 131
     uint8_t ret[Length + 22 + 3];/*Data Length + Header Length + Tail Length*/
139 132
     uint16_t CRCData = CRC16_Generate(data,Length);
140
-    uint16_t cmd = data[MBIC_CMD_0];
141 133
     /*CRC Create*/
142 134
     ret[MBIC_PAYLOADSTART + Length + 0] = ((CRCData & 0xFF00) >> 8);
143 135
     ret[MBIC_PAYLOADSTART + Length + 1] = ((CRCData & 0x00FF));
@@ -177,28 +169,43 @@ uint8_t* MBIC_HeaderMergeFunction(uint8_t* data,uint16_t Length )
177 169
 
178 170
     ret[MBIC_HEADERCHECKSUM_0] = Chksum_Create(ret);
179 171
     /*Data Move*/
180
-    for(int i = 0; i < Length; i++){
181
-        data[MBIC_HEADER_SIZE + i] = data[i];
182
-    }
172
+//    for(int i = 0; i < Length; i++){
173
+//        data[MBIC_PAYLOADSTART + i] = data[i];
174
+//    }
175
+    /*
176
+        MBIC Header Data input
177
+    */
183 178
     for(int i = 0; i < MBIC_HEADER_SIZE; i++){
179
+        if(i == MBIC_CMD_0) /*cmd exception*/
180
+            continue;
184 181
         data[i] = ret[i];
185 182
     }
183
+      /*
184
+          MBIC Tail Data input
185
+      */
186
+    
186 187
       for(int i = MBIC_HEADER_SIZE + Length; i < MBIC_HEADER_SIZE + MBIC_TAIL_SIZE + Length; i++){
187 188
         data[i] = ret[i];
188 189
     }
189 190
 //    for(uint16_t i = 0; i < Length; i ++)
190 191
 //        ret[MBIC_PAYLOADSTART + i] = data[i];
192
+//    for(int i = 0; i < Length; i++)
193
+//        printf("MBIC : %x \r\n",data[i]);
191 194
 
192 195
     return data;
193 196
 }
194 197
 
195 198
 void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
196 199
     uint8_t MBIC_DownLoadData[0xFFFF];
197
-    uint16_t cmd = data[MBIC_CMD_0];
200
+    uint8_t cmd = data[MBIC_CMD_0];
198 201
     static uint8_t Download_Option = 0;
199 202
     uint16_t index = 0;
200 203
     static uint32_t Curr_Download_DataIndex = 0;
201 204
     static uint32_t Prev_Download_DataIndex = 0;    
205
+    uint32_t TotalFrame = 0;
206
+    uint32_t CurrFrame = 0;
207
+    
208
+    uint32_t i = 0 ;
202 209
 #if 0 // PYJ.2020.06.04_BEGIN -- 
203 210
     uint8_t dataTest[1024] = {
204 211
       0x4A,0x54,0x2D,0x4E,0x52,0x44,0x41,0x53,0x20,0x20,0x00,0x00,
@@ -214,7 +221,7 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
214 221
     };
215 222
     
216 223
 #endif // PYJ.2020.06.04_END -- 
217
-    MBIC_FileDataCheck(data);
224
+    
218 225
 
219 226
 //    printf("RX");
220 227
 //    for(int i = 0; i < 128; i++)
@@ -238,13 +245,19 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
238 245
             data[MBIC_PAYLOADSTART + index++] = 0;
239 246
             data[MBIC_PAYLOADSTART + index++] = 0;
240 247
             data[MBIC_PAYLOADSTART + index++] = 0;
241
-            data[MBIC_PAYLOADSTART + index++] = 0;        
248
+            data[MBIC_PAYLOADSTART + index++] = 0;      
249
+//            printf("ccc\r\n");
242 250
         break;
243 251
         case MBIC_Download_DATA_REQ:
252
+            TotalFrame = data[MBIC_PAYLOADSTART + 0] << 24
253
+                        |data[MBIC_PAYLOADSTART + 1] << 16
254
+                        |data[MBIC_PAYLOADSTART + 2] << 8
255
+                        |data[MBIC_PAYLOADSTART + 3] << 0;
256
+//            MBIC_FileDataCheck(data);
244 257
             cmd = MBIC_Download_DATA_RSP;
245 258
             /*TOTAL FRAME NUMBER*/
246 259
             data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 0];
247
-            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];        
260
+            data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 1];
248 261
             data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 2];
249 262
             data[MBIC_PAYLOADSTART + index++] = data[MBIC_PAYLOADSTART + 3];        
250 263
             /*Current Download Frame Number*/        
@@ -261,11 +274,13 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
261 274
             data[MBIC_PAYLOADSTART + index++] = 0;
262 275
             data[MBIC_PAYLOADSTART + index++] = 0;
263 276
             data[MBIC_PAYLOADSTART + index++] = 0;
264
-            for(uint32_t i = Prev_Download_DataIndex; i < Curr_Download_DataIndex; i++){
265
-                MBIC_DownLoadData[i] = data[index + i];
266
-                printf("MBIC_DownLoadData[i] : %x",MBIC_DownLoadData[i]);
277
+            for(i = 0; i < Curr_Download_DataIndex - Prev_Download_DataIndex; i++){
278
+                    MBIC_DownLoadData[i] = data[MBIC_PAYLOADSTART + 12 +i];
279
+                    printf("%02x ",MBIC_DownLoadData[i]);
267 280
             }
268
-            
281
+//            printf("Data End\r\n");
282
+//            Bank_Flash_write(data,FLASH_USER_TEMPBANK_START_ADDR);
283
+//            HAL_Delay(100);
269 284
             Prev_Download_DataIndex  = Curr_Download_DataIndex;
270 285
             break;
271 286
         case MBIC_Download_Confirm_REQ:
@@ -332,5 +347,10 @@ void MBIC_Bootloader_FirmwareUpdate(uint8_t* data){
332 347
             return;
333 348
     }
334 349
     data[MBIC_CMD_0] = cmd;
335
-    MBIC_HeaderMergeFunction(data,index); // reponse
350
+    
351
+    data = MBIC_HeaderMergeFunction(data,index); // reponse
352
+//	HAL_UART_Transmit_DMA(&huart1, data,22 + 3 + index);
353
+
354
+    
355
+    Uart1_Data_Send(data ,22 + 3 + index);
336 356
 }

+ 32 - 1
Src/flash.c

@@ -5,8 +5,10 @@
5 5
  *      Author: parkyj
6 6
  */
7 7
 #include "flash.h"
8
+#include "MBIC_Bootloader.h"
8 9
 uint8_t flashinit = 0;
9 10
 uint32_t Address = FLASH_USER_START_ADDR;
11
+volatile static uint32_t UserAddress;
10 12
 
11 13
 typedef void (*fptr)(void);
12 14
 fptr jump_to_app;
@@ -60,6 +62,7 @@ void Flash_InitRead(void) // ?占쏙옙湲고븿?占쏙옙
60 62
 #if 1 // PYJ.2020.05.20_BEGIN -- 
61 63
 uint8_t Flash_RGB_Data_Write(uint8_t* data){
62 64
     uint16_t Firmdata = 0;
65
+
63 66
     uint8_t ret = 0;
64 67
     for(int i = 0; i < data[bluecell_length] - 2; i+=2){
65 68
         Firmdata  = ((data[(bluecell_length + 1) + i]) & 0x00FF);
@@ -74,6 +77,31 @@ uint8_t Flash_RGB_Data_Write(uint8_t* data){
74 77
     }
75 78
     return ret;
76 79
 }
80
+uint8_t Flash_Data_Write(uint8_t* data){
81
+    uint16_t Firmdata = 0;
82
+    uint8_t ret = 0;
83
+    static uint32_t Curr_Download_DataIndex = 0;
84
+    static uint32_t Prev_Download_DataIndex = 0;  
85
+    
86
+    Curr_Download_DataIndex = data[MBIC_PAYLOADSTART  + 4] << 24;
87
+    Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 5] << 16;
88
+    Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 6] << 8;            
89
+    Curr_Download_DataIndex += data[MBIC_PAYLOADSTART + 7];      
90
+
91
+//    data[MBIC_PAYLOADSTART + 12 +i];
92
+    for(int i= 0; i <= Curr_Download_DataIndex - Prev_Download_DataIndex+1; i+=2){
93
+        Firmdata  = ((data[MBIC_PAYLOADSTART + 12 +i]) & 0x00FF);
94
+        Firmdata  += ((data[MBIC_PAYLOADSTART + 12 +i + 1] << 8) & 0xFF00);
95
+        if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,UserAddress ,   (uint16_t)Firmdata) != HAL_OK){
96
+            printf("HAL NOT OK \n");
97
+            ret = 1;
98
+        }
99
+        UserAddress += 2;
100
+    }
101
+    Prev_Download_DataIndex = Curr_Download_DataIndex;
102
+    return ret;
103
+}
104
+
77 105
 uint8_t Flash_Bank_Data_Write(uint8_t* data){
78 106
     uint16_t Firmdata = 0;
79 107
     uint16_t Length = 0;
@@ -93,6 +121,7 @@ uint8_t Flash_Bank_Data_Write(uint8_t* data){
93 121
     return ret;
94 122
 }
95 123
 
124
+#if 0 // PYJ.2020.06.10_BEGIN -- 
96 125
 uint8_t Flash_Data_Write(uint8_t* data){
97 126
     uint64_t Firmdata = 0;
98 127
     uint8_t ret = 0;
@@ -130,6 +159,7 @@ uint8_t Flash_Data_Write(uint8_t* data){
130 159
     }
131 160
     return ret;
132 161
 }
162
+#endif // PYJ.2020.06.10_END -- 
133 163
 uint8_t Flash_DataTest_Write(uint8_t* data){
134 164
     uint32_t Firmdata = 0;
135 165
     uint8_t ret = 0;
@@ -236,12 +266,13 @@ uint8_t Bank_Flash_write(uint8_t* data,uint32_t StartBankAddress) // ?占쏙옙
236 266
     HAL_FLASH_Unlock(); // lock ??占�?
237 267
     if(flashinit == 0){
238 268
         flashinit= 1;
269
+        UserAddress = EraseInitStruct.PageAddress;
239 270
         //FLASH_PageErase(StartAddr);
240 271
         if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK){
241 272
             printf("Erase Failed \r\n");
242 273
         }
243 274
     }
244
-    ret = Flash_RGB_Data_Write(&data[bluecell_stx]);
275
+    ret = Flash_Data_Write(&data[MBIC_PREAMBLE_0]);
245 276
     HAL_FLASH_Lock(); // lock ?占쏙옙洹멸린
246 277
     return ret;
247 278
 }

+ 1 - 1
Src/main.c

@@ -144,7 +144,7 @@ int main(void)
144 144
 	 // printf("Uart Start \r\n");
145 145
 	  if(LedTimerCnt > 500){HAL_GPIO_TogglePin(BOOT_LED_GPIO_Port,BOOT_LED_Pin);LedTimerCnt = 0;}
146 146
 	  while (TerminalQueue.data > 0 && UartTimerCnt > 30) GetDataFromUartQueue(&hTerminal);
147
-	  while(FirmwareTimerCnt > 3000)  Jump_App();
147
+	 // while(FirmwareTimerCnt > 3000)  Jump_App();
148 148
 
149 149
 	  //HAL_Delay(500);
150 150
     /* USER CODE END WHILE */

+ 9 - 3
Src/uart.c

@@ -50,9 +50,9 @@ void PutDataToUartQueue(UART_HandleTypeDef *huart, uint8_t data)
50 50
    // HAL_UART_Receive_DMA(&hTerminal,  pQueue->Buffer + pQueue->head, 10);
51 51
 }
52 52
 
53
+uint8_t update_data_buf[QUEUE_BUFFER_LENGTH];
53 54
 void GetDataFromUartQueue(UART_HandleTypeDef *huart)
54 55
 {
55
-    volatile static uint8_t update_data_buf[QUEUE_BUFFER_LENGTH];
56 56
     volatile static int cnt;
57 57
     uint16_t Length = 0;
58 58
     uint16_t CrcChk = 0;
@@ -107,7 +107,13 @@ void GetDataFromUartQueue(UART_HandleTypeDef *huart)
107 107
 
108 108
 }
109 109
 
110
-void Uart1_Data_Send(uint8_t* data,uint8_t size){
111
-	HAL_UART_Transmit_DMA(&huart1, data,size);
110
+void Uart1_Data_Send(uint8_t* data,uint16_t size){
111
+//    printf("size : %d \r\n",size);
112
+    HAL_UART_Transmit (&huart1, data, size, 0xFFFF);
113
+//    for(int i = 0; i < size; i++)
114
+//    if(HAL_UART_Transmit_DMA(&huart1, data, size) != HAL_OK){
115
+//        printf("ERROR \r\n");
116
+//    }
117
+//        printf("data : %x \r\n",data[i]);
112 118
 }
113 119