diff --git a/BootLoader.uvoptx b/BootLoader.uvoptx
index a0e345d1ca553e7b55628bf5f4be76235695979d..b73e744c4fb591564523ec1420329dd1f00df9f3 100644
--- a/BootLoader.uvoptx
+++ b/BootLoader.uvoptx
@@ -75,7 +75,7 @@
1
0
- 0
+ 1
255
@@ -123,24 +123,7 @@
UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0GD32F4xx_3MB -FS08000000 -FL0300000 -FP0($$Device:GD32F450ZK$Flash\GD32F4xx_3MB.FLM))
-
-
- 0
- 0
- 154
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- .\ymodem.c
-
-
-
-
+
0
@@ -240,7 +223,7 @@
1
0
- 1
+ 0
255
@@ -314,18 +297,14 @@
-
-
- 0
- 1
- 0x200004ce
-
-
- 1
+
+
1
- Crc_Table[256]
-
-
+ 0
+ 0x8008000
+ 0
+
+
2
@@ -410,6 +389,18 @@
1
2
+ 5
+ 0
+ 0
+ 0
+ .\bsp_uart.h
+ bsp_uart.h
+ 0
+ 0
+
+
+ 1
+ 3
1
0
0
@@ -421,7 +412,19 @@
1
- 3
+ 4
+ 5
+ 0
+ 0
+ 0
+ .\bsp_ocflash.h
+ bsp_ocflash.h
+ 0
+ 0
+
+
+ 1
+ 5
1
0
0
@@ -433,7 +436,7 @@
1
- 4
+ 6
1
0
0
@@ -445,25 +448,25 @@
1
- 5
- 1
+ 7
+ 5
0
0
0
- .\bsp_gpio.c
- bsp_gpio.c
+ .\ymodem.h
+ ymodem.h
0
0
1
- 6
+ 8
1
- 1
+ 0
0
0
- .\driverCrc16.c
- driverCrc16.c
+ .\bsp_gpio.c
+ bsp_gpio.c
0
0
@@ -477,7 +480,7 @@
0
2
- 7
+ 9
1
0
0
@@ -489,7 +492,7 @@
2
- 8
+ 10
1
0
0
diff --git a/BootLoader.uvprojx b/BootLoader.uvprojx
index a310d68f779955722d256ac9fba2c18a6037cc5c..308be06777890427c8fb82f874688d19f336f6a1 100644
--- a/BootLoader.uvprojx
+++ b/BootLoader.uvprojx
@@ -10,7 +10,7 @@
BootLoader
0x4
ARM-ADS
- 5060960::V5.06 update 7 (build 960)::ARMCC
+ 6180000::V6.18::ARMCLANG
0
@@ -389,11 +389,21 @@
1
.\bsp_uart.c
+
+ bsp_uart.h
+ 5
+ .\bsp_uart.h
+
systick.c
1
.\systick.c
+
+ bsp_ocflash.h
+ 5
+ .\bsp_ocflash.h
+
bsp_ocflash.c
1
@@ -405,14 +415,14 @@
.\ymodem.c
- bsp_gpio.c
- 1
- .\bsp_gpio.c
+ ymodem.h
+ 5
+ .\ymodem.h
- driverCrc16.c
+ bsp_gpio.c
1
- .\driverCrc16.c
+ .\bsp_gpio.c
@@ -822,11 +832,21 @@
1
.\bsp_uart.c
+
+ bsp_uart.h
+ 5
+ .\bsp_uart.h
+
systick.c
1
.\systick.c
+
+ bsp_ocflash.h
+ 5
+ .\bsp_ocflash.h
+
bsp_ocflash.c
1
@@ -838,14 +858,14 @@
.\ymodem.c
- bsp_gpio.c
- 1
- .\bsp_gpio.c
+ ymodem.h
+ 5
+ .\ymodem.h
- driverCrc16.c
+ bsp_gpio.c
1
- .\driverCrc16.c
+ .\bsp_gpio.c
diff --git a/driverCrc16.c b/driverCrc16.c
deleted file mode 100644
index 94f2f37b79b41682b69a17de60dd387d5a4423d0..0000000000000000000000000000000000000000
--- a/driverCrc16.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * @Author: Ma Yuchen
- * @Date: 2022-11-30 19:01:06
- * @LastEditors: Ma YuChen
- * @LastEditTime: 2022-11-30 19:33:29
- * @Description: file content
- * @FilePath: \BootLoader\driverCrc16.c
- */
-#include "driverCrc16.h"
-
-static uint16_t Crc_Table[256] = {0};
-
-void InitCRC(void)
-{
- int index = 0;
- int bit_cnt = 0;
- uint32_t temp = 0;
-
- for (index = 0; index < 256; index++)
- {
- temp = 0;
- for (bit_cnt = 8; bit_cnt > 0; bit_cnt--)
- {
- if ((index >> (bit_cnt - 1) ^ temp >> (CRC_WIDTH - 1)) & 0x1)
- {
- temp = (temp << 1) ^ CRC_PLOY;
- }
- else
- {
- temp <<= 1;
- }
- }
-
- Crc_Table[index] = (uint16_t)temp;
- }
-}
-
-uint16_t CalcuCRC(char *buff, int len)
-{
- char *tempPtr = buff;
- int reg = CRC_INIT;
- int i = 0;
-
- for (i = 0; i < len; i++)
- {
- reg = (reg << 8) ^ Crc_Table[((reg >> (CRC_WIDTH - 8)) & 0xFF) ^ *tempPtr];
- tempPtr++;
- }
- return (uint16_t)(reg & 0xFFFF);
-}
diff --git a/driverCrc16.h b/driverCrc16.h
deleted file mode 100644
index 8fb1d75032780381522cd5ac7066f0419d70db6d..0000000000000000000000000000000000000000
--- a/driverCrc16.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * @Author: Ma Yuchen
- * @Date: 2022-11-30 19:01:15
- * @LastEditors: Ma YuChen
- * @LastEditTime: 2022-11-30 19:32:24
- * @Description: file content
- * @FilePath: \BootLoader\driverCrc16.h
- */
-#ifndef Driver_CRC16_H
-#define Driver_CRC16_H
-
-#include
-
-#define CRC_WIDTH 16
-#define CRC_PLOY 0x1021
-#define CRC_INIT 0x0000
-
-void InitCRC(void);
-uint16_t CalcuCRC(char* buff, int len);
-
-#endif //Driver_CRC16_H
diff --git a/main.c b/main.c
index 7185d96990036e629bca48dafdd2a4a3b46be6b2..df9d58f57bfe173d8eb6a53372a311e7f15e6966 100644
--- a/main.c
+++ b/main.c
@@ -2,7 +2,7 @@
* @Author: Ma Yuchen
* @Date: 2022-11-22 21:03:02
* @LastEditors: Ma YuChen
- * @LastEditTime: 2022-11-30 19:34:44
+ * @LastEditTime: 2022-11-26 15:00:32
* @Description: file content
* @FilePath: \BootLoader\main.c
*/
@@ -11,7 +11,6 @@
#include "bsp_gpio.h"
#include "bsp_uart.h"
#include "bsp_ocflash.h"
-#include "driverCrc16.h"
#include "systick.h"
extern pFunction Jump_To_Application;
@@ -25,7 +24,6 @@ int main(void)
{
//初始化Core时钟
systick_config();
- InitCRC();
#ifndef BOARD_EVAL
//初始化GPIO并打开V3.3外设供电
InitGpio();
@@ -37,8 +35,8 @@ int main(void)
SerialPutString("\r\nThanks for use this bootLoader\r\n");
- //if(GetIAPIntper() == 1)
- if(1)
+ if(GetIAPIntper() == 1)
+ //if(1)
//如果获取到IAP请求中断则打印菜单进行IAP操作
{
Flash_IF_Init();
diff --git a/menu.c b/menu.c
index dd715006c482d97fff9a809a6076d77f51604720..9a67862f4bc97a32e3e2d3d634a8b7b4a4e0fde1 100644
--- a/menu.c
+++ b/menu.c
@@ -2,7 +2,7 @@
* @Author: Ma Yuchen
* @Date: 2022-11-24 10:03:28
* @LastEditors: Ma YuChen
- * @LastEditTime: 2022-11-30 19:34:36
+ * @LastEditTime: 2022-11-25 15:19:15
* @Description: file content
* @FilePath: \BootLoader\menu.c
*/
@@ -31,7 +31,7 @@ void PrintMenu(void)
SerialPutString("=========================================================\r\n");
SerialPutString("= =\r\n");
SerialPutString("= BMC GD32F4XX In-Application Programming Apllication =\r\n");
- SerialPutString("= V 0.0.3 =\r\n");
+ SerialPutString("= V 0.0.1 =\r\n");
SerialPutString("=========================================================\r\n");
while (1)
diff --git a/ymodem.c b/ymodem.c
index cd439b91697d4f63e3d39d7c25d282b8bd66a717..dbf2fead5a7ac18dc99e0fdd955cc4a90b0f9963 100644
--- a/ymodem.c
+++ b/ymodem.c
@@ -2,14 +2,13 @@
* @Author: Ma Yuchen
* @Date: 2022-11-23 23:29:58
* @LastEditors: Ma YuChen
- * @LastEditTime: 2022-11-30 19:35:28
+ * @LastEditTime: 2022-11-26 18:26:40
* @Description: file content
* @FilePath: \BootLoader\ymodem.c
*/
#include "ymodem.h"
#include "bsp_ocflash.h"
#include "bsp_uart.h"
-#include "driverCrc16.h"
#include "systick.h"
typedef struct _YModemInfo
@@ -60,6 +59,71 @@ static int Send_Byte(uint8_t c)
return 0;
}
+static uint16_t UpdateCrc16(uint16_t crcIn, uint8_t d)
+{
+ /*
+ uint8_t count = 8;
+ uint16_t newCrc = crc;
+ uint16_t data = d;
+
+ while ((count--) > 0)
+ {
+ if (newCrc & 0x8000)
+ {
+ newCrc <<= 1;
+ newCrc += (((data <<= 1) & 0x0400) != 0);
+ newCrc ^= 0x1021;
+ }
+ else
+ {
+ newCrc <<= 1;
+ newCrc += (((data <<= 1) & 0x0400) != 0);
+ }
+ }
+
+ return newCrc;
+ */
+ uint32_t crc = crcIn;
+ uint32_t in = d|0x100;
+
+ do
+ {
+ crc <<= 1;
+ in <<= 1;
+
+ if(in&0x100)
+ {
+ ++crc;
+ }
+
+ if(crc&0x10000)
+ {
+ crc ^= 0x1021;
+ }
+ } while(!(in&0x10000));
+
+ return (crc&0xffffu);
+}
+
+static uint16_t ClcCrc16(const uint8_t *datas, int size)
+{
+ uint16_t crc = 0;
+
+ const uint8_t *endofDatas = datas + size;
+
+ while (datas < endofDatas)
+ {
+ crc = UpdateCrc16(crc, *datas);
+ datas++;
+ }
+ crc = UpdateCrc16(crc, 0);
+ crc = UpdateCrc16(crc, 0);
+
+ return (crc & (uint16_t)0xffff);
+}
+
+uint8_t debugData=0xff;
+
/**
* @brief
*
@@ -78,16 +142,16 @@ static int Receive_Packet(uint8_t *buffer, int32_t *length, uint32_t timeout)
uint16_t i, packet_size, computedcrc;
uint8_t data;
*length = 0;
- int result=0;
- // receive packet
- usart_start_receive_block((uint32_t)buffer, PACKET_OVERHEAD+PACKET_DATA_LENGTH);
- result = Receive_Byte(timeout);
+ int result=0;
+
+ usart_start_receive_block((uint32_t)buffer, PACKET_OVERHEAD+PACKET_DATA_LENGTH);
+ result = Receive_Byte(timeout);
if (result == 0)
{
return -1;
}
//delay_1ms(50);
- data=*buffer;
+ data=*buffer;
//SEGGER_RTT_printf(0,"%d:get Head %X result=%d\r\n",debugLoop++ , data, result);
switch (data)
{
@@ -111,22 +175,35 @@ static int Receive_Packet(uint8_t *buffer, int32_t *length, uint32_t timeout)
return -1;
}
default:
+ debugData=data;
return -3;
}
+ //*buffer = data; // buffer store header in buffer[0];
+
+ // receive packet
+ /*
+ for (i = 1; i < packet_size; i++)
+ {
+ if (Receive_Byte(timeout) != 0)
+ {
+ return -4;
+ }
+ }
+ */
// check packet no
if (buffer[PACKET_NO_INDEX] != ((buffer[PACKET_NO_N_INDEX] ^ 0xff) & 0xff))
{
return -2;
}
-
- computedcrc = CalcuCRC(&(buffer[PACKET_HEADER]), (int)packet_size);
+/*
+ computedcrc = ClcCrc16(buffer[PACKET_HEADER], (int)packet_size);
if (computedcrc != (((uint16_t)buffer[packet_size + 3] << 8) | buffer[packet_size + 4]))
{
return -3;
}
-
+*/
*length = packet_size;
return 0;