浏览代码

Multi lock demonstration version

zack 1 年之前
父节点
当前提交
d1f7c179ef
共有 22 个文件被更改,包括 7076 次插入4785 次删除
  1. 75 83
      Core/Inc/ConfigMacros.h
  2. 92 0
      Core/Inc/dtuaes.h
  3. 26 7
      Core/Inc/interface.h
  4. 4 4
      Core/Inc/key.h
  5. 3 1
      Core/Inc/main.h
  6. 10 14
      Core/Inc/mba32a.h
  7. 1 10
      Core/Inc/ml307a.h
  8. 13 0
      Core/Inc/oledfont.h
  9. 2 3
      Core/Inc/usart.h
  10. 572 0
      Core/Src/dtuaes.c
  11. 32 49
      Core/Src/freertos.c
  12. 810 765
      Core/Src/interface.c
  13. 1133 36
      Core/Src/key.c
  14. 25 9
      Core/Src/main.c
  15. 351 484
      Core/Src/mba32a.c
  16. 20 65
      Core/Src/ml307a.c
  17. 8 6
      Core/Src/stm32f1xx_it.c
  18. 37 8
      Core/Src/usart.c
  19. 61 31
      MDK-ARM/dtu.uvoptx
  20. 19 1
      MDK-ARM/dtu.uvprojx
  21. 3781 3209
      Output/dtu.hex
  22. 1 0
      Output/dtu.lnp

+ 75 - 83
Core/Inc/ConfigMacros.h

@@ -1,75 +1,38 @@
 #ifndef __CONFIGMACROS_H
 #define __CONFIGMACROS_H
 
-#include "oled.h"
-#include "key.h"
-#include "interface.h"
 
-/**
-  * @breaf 定义测试开关
-  */
-#define		Test_old			0					//演示入口
-#define  	keyDebuginfo		1
+
+#include "oled.h"
 
 
-/**
-  * @breaf 简化函数单体
-  */
 #define open16			11	//开字
 #define close16			12	//关字
 #define resetDevAddr					((uint32_t)0x8075000)  
+#define DevstatusAddr					((uint32_t)0x8075800)  
+
+
+#define Sn1Addr							((uint32_t)0x8076000)  
+#define Sn2Addr							((uint32_t)0x8076800)  
+#define Sn3Addr							((uint32_t)0x8077700)  
+#define Sn4Addr							((uint32_t)0x8077800)  
+
+#define Sn1StatusAddr					((uint32_t)0x8078000)  
+#define Sn2StatusAddr					((uint32_t)0x8078800)  
+#define Sn3StatusAddr					((uint32_t)0x8079000)  
+#define Sn4StatusAddr					((uint32_t)0x8079800)  
+
+
 #define TIM_Start(htim) 				HAL_TIM_Base_Start_IT(htim)
 #define LED_TOGGLE(pin)       			HAL_GPIO_TogglePin(GPIOC, (pin))		//运行灯
-#define UART_PRINT(huart) 				HAL_UART_Transmit(huart, (uint8_t *)&ch, 1, 0xFFFF);
-#define PRINT_MENU_STATUS(key)  		printf("--->%s pressed\t%d   %d   %d   %d\n", key, menu.current, menu.up, menu.next, menu.enter)
-#define HELLO(message) 					printf("%s\r\n", message)
-#define PRINT_UUID(message) 			printf("#%s符合设置项\n",message)
-#define PRINT_NUUID(message) 			printf("%s不符合\n",message)
 #define RXNE_UART(huart) 				__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE)	
 
-/**
-  * @breaf BT模组测试重启 */
-#define RESET_BT_MODULE_demo() \
-    if(resetBTmodule) { \
-		resetBTmodule = false; \
-        MBA32A_Init_demo(); \
-    }
-	
-/**
-  * @breaf BT模组重启 */
-#define RESET_BT_MODULE() \
-    if(resetBTmodule) { \
-		resetBTmodule = false; \
-        MBA32A_Init(); \
-    }	
-	
-/**
-  * @breaf 4G模组重启 */
-#define RESET_4G_MODULE() \
-    if(reset4Gmodule) { \
-		reset4Gmodule = false; \
-        ML307A_Init(); \
-    }	
-
-/**
-  * @breaf 简化函数多体
-  */
-/* OLED显示 */
-#define OLED_DISPLAY(color, display) do { \
-    OLED_Init(); \
-    OLED_ColorTurn(color); \
-    OLED_DisplayTurn(display);  \
-} while(0)
 
-/* 设置键值 */
-#define SET_MENU_STATUS(current_value, up_value, next_value, enter_value) \
-do { \
-    menu.current = current_value; \
-    menu.up = up_value; \
-    menu.next = next_value; \
-    menu.enter = enter_value; \
-	refresh = true;\
-} while(0)
+#define PRINT_MENU_STATUS(key)  		printf("--->%s pressed\t%d   %d   %x   %d\n", key, menu.current, menu.up, (menu.next&0xf), menu.enter)
+#define HELLO(message) 					printf("%s\r\n", message)
+#define PRINT_UUID(message) 			printf("#%s符合设置项\n",message)
+#define PRINT_NUUID(message) 			printf("%s不符合\n",message)
+#define PRINT_BTRESP(message) 			printf("%s错误\n",message)
 
 /* WDI */
 #define TOGGLE_WDI_PIN(htim_instance) \
@@ -79,14 +42,16 @@ do { \
     } \
 } while(0)
 
-/* 扫描按键刷新屏幕 */
-#define UPDATE_EXECUTE_REFRESH() \
-do { \
-    updatekeystate(); \
-    execute_interface(menu); \
-    OLED_Refresh(); \
+
+
+/* OLED显示 */
+#define OLED_DISPLAY(color, display) do { \
+    OLED_Init(); \
+    OLED_ColorTurn(color); \
+    OLED_DisplayTurn(display);  \
 } while(0)
 
+
 /* U1-U4 DMA */
 #define IDLE_DMA_UART(huart) \
 do {\
@@ -94,14 +59,6 @@ do {\
 	HAL_UART_Receive_DMA(huart, recvBuff, 2048); \
 } while(0)
 
-/* 蓝牙参数初始化(流水号/dtu1/自动施封时间) */	
-#define INIT_BT_FRAME() \
-do { \
-	btframe.serialNum = 0x00000001; \
-	btframe.userId 	  = 0x64747531; \
-	btframe.Autoseal  = 0x01; \
-	printf("\t###01\tBT_init%d...\r\n", resetcount_bt); \
-} while (0)
 
 /* 4G参数初始化*/	
 #define INIT_4G_FRAME() \
@@ -109,40 +66,66 @@ do { \
 	printf("\t###02\t4G_init%d...\r\n",resetcount_4g); \
 } while (0)
 
-/**
-  * @breaf 结构体定义
-  */
-/* 界面参数结构体 */	
+
+#define SET_MENU_STATUS(current_value, up_value, next_value, enter_value) \
+do { \
+    menu.current = current_value; \
+    menu.up = up_value; \
+    menu.next = next_value; \
+    menu.enter = enter_value; \
+	refresh = true;\
+} while(0)
+
+
+
+
 typedef struct
 {
     uint8_t current;		//当前状态索引号
     uint8_t up; 			//向下一个
     uint8_t next; 			//向下一个
     uint8_t enter; 	    	//确定
-	unsigned char* sn; 	//sn
 	uint32_t home;
-	
+	char* SN1;
+	char* SN1F;
+	char* SN1D;
+	char* SN1name;
+	char* SN2;
+	char* SN2F;
+	char* SN2D;
+	char* SN2name;
+	char* SN3;
+	char* SN3F;
+	char* SN3D;
+	char* SN3name;
+	char* SN4;
+	char* SN4F;
+	char* SN4D;
+	char* SN4name;
+	uint8_t PreNext;
 } Menu_table;
 
-/* 按键参数结构体 */	
 struct keys
 {
 	unsigned char judge_sta;	//判断按键按键按下的动作到了第几步
 	bool key_sta;				//如果按键被按下,为0
 	bool key_flag;				//如果确认被按下,为1
+	bool long_flag;				//如果确认被按下,为1
+	uint8_t key_time;
 };
 
-/* 蓝牙锁信息帧参数结构体 */	
 typedef struct
 {
-    uint32_t serialNum;	//4字节流水号
+    uint32_t serialNum1;	//4字节流水号
+    uint32_t serialNum2;	//4字节流水号
+    uint32_t serialNum3;	//4字节流水号
+    uint32_t serialNum4;	//4字节流水号
 	uint32_t userId;	//4字节userid
 	uint32_t Ntime;		//4字节时间
 	uint8_t	 Autoseal;	//1字节自动施封
 	
 } BtFrame;
 
-
 typedef enum {
 	BtStepDefault = 0,
     UUIDS = 1,
@@ -150,10 +133,19 @@ typedef enum {
     UUIDW = 3,
 } BtStep;
 
+
 typedef enum {
     Default = 0,
     InProgress = 1,
-	Abnormal_motor = 2
+	Abnormal_motor = 2,
+	Starting = 3 ,
+	Nosnset = 4 ,
+	Carfail = 5
 } TipsFlag;
 
+
+
+
+
 #endif /*__CONFIGMACROS_H*/
+

+ 92 - 0
Core/Inc/dtuaes.h

@@ -0,0 +1,92 @@
+#ifndef _AES_H_
+#define _AES_H_
+
+#include <stdint.h>
+#include <stddef.h>
+
+// #define the macros below to 1/0 to enable/disable the mode of operation.
+//
+// CBC enables AES encryption in CBC-mode of operation.
+// CTR enables encryption in counter-mode.
+// ECB enables the basic ECB 16-byte block algorithm. All can be enabled simultaneously.
+
+// The #ifndef-guard allows it to be configured before #include'ing or at compile time.
+#ifndef CBC
+  #define CBC 1
+#endif
+
+#ifndef ECB
+  #define ECB 1
+#endif
+
+#ifndef CTR
+  #define CTR 1
+#endif
+
+
+#define AES128 1
+#define CBC 1
+//#define AES192 1
+//#define AES256 1
+
+#define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only
+
+#if defined(AES256) && (AES256 == 1)
+    #define AES_KEYLEN 32
+    #define AES_keyExpSize 240
+#elif defined(AES192) && (AES192 == 1)
+    #define AES_KEYLEN 24
+    #define AES_keyExpSize 208
+#else
+    #define AES_KEYLEN 16   // Key length in bytes
+    #define AES_keyExpSize 176
+#endif
+
+struct AES_ctx
+{
+  uint8_t RoundKey[AES_keyExpSize];
+#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
+  uint8_t Iv[AES_BLOCKLEN];
+#endif
+};
+
+void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key);
+#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
+void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);
+void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);
+#endif
+
+#if defined(ECB) && (ECB == 1)
+// buffer size is exactly AES_BLOCKLEN bytes; 
+// you need only AES_init_ctx as IV is not used in ECB 
+// NB: ECB is considered insecure for most uses
+void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf);
+void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
+
+#endif // #if defined(ECB) && (ECB == !)
+
+
+#if defined(CBC) && (CBC == 1)
+// buffer size MUST be mutile of AES_BLOCKLEN;
+// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
+// NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv()
+//        no IV should ever be reused with the same key 
+void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
+void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
+
+#endif // #if defined(CBC) && (CBC == 1)
+
+
+#if defined(CTR) && (CTR == 1)
+
+// Same function for encrypting as for decrypting. 
+// IV is incremented for every block, and used after encryption as XOR-compliment for output
+// Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
+// NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv()
+//        no IV should ever be reused with the same key 
+void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
+
+#endif // #if defined(CTR) && (CTR == 1)
+
+
+#endif /*__AES_H*/

+ 26 - 7
Core/Inc/interface.h

@@ -3,16 +3,35 @@
 #include "main.h"
 
 
-void asc_display(unsigned char *asc);
 
 
 
-extern bool startdtu;					//声明外部启动界面切换标志位
-extern bool L1bd;		
-extern bool L2bd;		
-extern bool L3bd;		
-extern bool L4bd;		
+void createString(char* result, char* atcon, char* mac, char* crlf);
+extern bool refresh; 	
+
+
+extern char Atcon[];
+extern char CRLF[];
+extern unsigned char Mac001[];
+extern unsigned char Mac002[];
+extern unsigned char Mac003[];
+extern unsigned char Mac004[];
+extern unsigned char Mac005[];
+extern unsigned char Mac006[];
+extern unsigned char Mac007[];
+extern unsigned char Mac008[];
+extern unsigned char Mac009[];
+extern unsigned char Mac00A[];
+extern unsigned char Mac00B[];
+extern unsigned char Mac00C[];
+
+
+extern bool L1bd;						//L1绑定标志位
+extern bool L2bd;						//L2绑定标志位
+extern bool L3bd;					//L3绑定标志位
+extern bool L4bd;						//L4绑定标志位	
+
+
 
-extern bool refresh;		
 #endif /*__INTERFACE_H*/
 

+ 4 - 4
Core/Inc/key.h

@@ -4,13 +4,13 @@
 
 
 
-void updatekeystate(void);
-
-
-
 
+void updatekeystate(void);
 
+void scanMac(void);
 
+extern uint16_t S1;
+extern uint16_t S2;
 #endif /*__KEY_H*/
 
 

+ 3 - 1
Core/Inc/main.h

@@ -38,8 +38,10 @@ extern "C" {
 #include "mba32a.h"
 #include "ml307a.h"
 #include "ConfigMacros.h"
+#include "key.h"
+#include "interface.h"
 
-
+#include "dtuaes.h"
 
 /* USER CODE END Includes */
 

+ 10 - 14
Core/Inc/mba32a.h

@@ -3,26 +3,22 @@
 #include "main.h"
 
 
-extern uint8_t g_MBA32A_8buf[2048];
-extern uint8_t g_MBA32A_8buf_Down[2048];
-extern uint8_t dev1[12];
-extern bool BT_CONN;
 extern bool resetBTmodule;
 
 
-
 void workinfo_W(void);
-void MBA32A_Init(void);
-void MBA32A_Init_demo(void);
-void lock_searchInfo(void);
-void Scan_lock_status(void);
-void Seal_Unseal_Jumptips(void);
-
-void USART_SendString(UART_HandleTypeDef *huart, char *str);
-void Bt_MacScan(char *pCmd);
 void open_close_lock(void);
+extern uint8_t g_MBA32A_8buf[2048];
+extern uint8_t g_MBA32A_8buf_Down[2048];
+void MBA32A_Init(void);
+uint8_t sendCmd_BT(char *pCmd,char *pRes, uint32_t timeOut, uint8_t sendNum);
+extern uint16_t u5length;
 
+void USART_SendString(UART_HandleTypeDef *huart,char *str);
 
-void tips(void);
+void lock_searchInfo(void);
+int dtu_test(void);
+extern uint8_t DtuBtKey[16];
+extern uint8_t iv[16];
 #endif /*__MBA32A_H*/
 

+ 1 - 10
Core/Inc/ml307a.h

@@ -4,22 +4,13 @@
 
 
 
-
-extern bool u4RecvFlag;
-extern bool reset4Gmodule;
-extern bool reset4Gmodule;
-extern bool module4G_init;
 extern uint8_t u4length;
-
-
+extern bool u4RecvFlag;
 extern uint8_t g_ML307A_8buf[2048]; 
 extern uint8_t g_ML307A_8buf_Down[2048];
 
 
-
 void ML307A_Init(void);
-void Transfer4GBuff(void);
-
 
 
 #endif /*__ML307A_H*/

+ 13 - 0
Core/Inc/oledfont.h

@@ -426,6 +426,13 @@ const unsigned char Hzk1[][32]={
 
 {0x20,0x38,0xE7,0x30,0x00,0x48,0x48,0xFF,0x48,0x48,0x00,0xFE,0x42,0xB2,0x0E,0x00,0x22,0x27,0x12,0x12,0x00,0x82,0x62,0x1F,0x02,0x02,0x00,0xFF,0x08,0x10,0x0F,0x00},/*"绑",28*/
 {0x10,0x0C,0x44,0x44,0x44,0x44,0x45,0xC6,0x44,0x44,0x44,0x44,0x44,0x14,0x0C,0x00,0x80,0x40,0x20,0x1E,0x20,0x40,0x40,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00},/*"定",29*/
+	
+{0x00,0x00,0x00,0xFC,0x44,0x44,0x44,0x45,0x46,0x44,0x44,0x44,0x44,0x7C,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0xFC,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFC,0x00,0x00},/*"启",30*/
+{0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00},/*"动",31*/
+
+{0x80,0x80,0x88,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0x88,0x80,0x80,0x00,0x20,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,0x01,0x02,0x04,0x08,0x10,0x20,0x20,0x00},/*"未",32*/
+{0x20,0x38,0xE7,0x30,0x00,0x48,0x48,0xFF,0x48,0x48,0x00,0xFE,0x42,0xB2,0x0E,0x00,0x22,0x27,0x12,0x12,0x00,0x82,0x62,0x1F,0x02,0x02,0x00,0xFF,0x08,0x10,0x0F,0x00},/*"绑",33*/
+{0x10,0x0C,0x44,0x44,0x44,0x44,0x45,0xC6,0x44,0x44,0x44,0x44,0x44,0x14,0x0C,0x00,0x80,0x40,0x20,0x1E,0x20,0x40,0x40,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00},/*"定",34*/
 
 
 
@@ -474,6 +481,12 @@ const unsigned char Hzk5[][24]={	//12*12
 {0x00,0x1F,0x25,0xE5,0x25,0x25,0x25,0x25,0xE5,0x27,0x30,0x00,0x01,0x09,0x05,0x03,0x01,0x01,0x01,0x01,0x0F,0x01,0x01,0x00},/*"异",19*/
 {0x0C,0x04,0x75,0x56,0x54,0xD7,0x54,0x56,0x75,0x04,0x0C,0x00,0x00,0x07,0x01,0x01,0x01,0x0F,0x01,0x01,0x05,0x07,0x00,0x00},/*"常",20*/
 	
+{0x21,0xE2,0x00,0x04,0x34,0x2C,0x27,0xF4,0x24,0x24,0x04,0x00,0x08,0x07,0x08,0x09,0x09,0x09,0x09,0x0F,0x09,0x09,0x09,0x00},/*"连",21*/
+{0x88,0x88,0xFF,0x48,0xA4,0xAC,0xB5,0xE6,0xB4,0xAC,0xA4,0x00,0x00,0x08,0x0F,0x00,0x08,0x0A,0x0B,0x04,0x04,0x0B,0x08,0x00},/*"接",22*/
+{0x00,0xFC,0x24,0x24,0xE4,0x04,0xFF,0x04,0x85,0x66,0x04,0x00,0x08,0x07,0x00,0x02,0x0B,0x04,0x02,0x01,0x02,0x04,0x0F,0x00},/*"成",23*/
+{0x04,0x04,0xFC,0x04,0x04,0x08,0xFF,0x08,0x08,0x08,0xF8,0x00,0x02,0x02,0x01,0x09,0x05,0x03,0x00,0x00,0x08,0x08,0x07,0x00},/*"功",24*/
+
+	
 };
 
 const unsigned char Hzk6[][28]={	//14*14

+ 2 - 3
Core/Inc/usart.h

@@ -56,10 +56,9 @@ void MX_USART2_UART_Init(void);
 void MX_USART3_UART_Init(void);
 
 /* USER CODE BEGIN Prototypes */
-
 uint16_t read_flash_16(uint32_t addr);
-void Write_Information(uint32_t addr);
-void sendCombinedArray(uint8_t *header, size_t headerLength, uint8_t *command, size_t commandLength);
+void Write_Information(uint32_t addr, uint16_t newValue);
+void sendCombinedArray(uint8_t *header, size_t headerLength, uint8_t *command, size_t commandLength, bool JM);
 /* USER CODE END Prototypes */
 
 #ifdef __cplusplus

+ 572 - 0
Core/Src/dtuaes.c

@@ -0,0 +1,572 @@
+/*
+
+This is an implementation of the AES algorithm, specifically ECB, CTR and CBC mode.
+Block size can be chosen in aes.h - available choices are AES128, AES192, AES256.
+
+The implementation is verified against the test vectors in:
+  National Institute of Standards and Technology Special Publication 800-38A 2001 ED
+
+ECB-AES128
+----------
+
+  plain-text:
+    6bc1bee22e409f96e93d7e117393172a
+    ae2d8a571e03ac9c9eb76fac45af8e51
+    30c81c46a35ce411e5fbc1191a0a52ef
+    f69f2445df4f9b17ad2b417be66c3710
+
+  key:
+    2b7e151628aed2a6abf7158809cf4f3c
+
+  resulting cipher
+    3ad77bb40d7a3660a89ecaf32466ef97 
+    f5d3d58503b9699de785895a96fdbaaf 
+    43b1cd7f598ece23881b00e3ed030688 
+    7b0c785e27e8ad3f8223207104725dd4 
+
+
+NOTE:   String length must be evenly divisible by 16byte (str_len % 16 == 0)
+        You should pad the end of the string with zeros if this is not the case.
+        For AES192/256 the key size is proportionally larger.
+
+*/
+
+
+/*****************************************************************************/
+/* Includes:                                                                 */
+/*****************************************************************************/
+#include <string.h> // CBC mode, for memset
+#include "dtuaes.h"
+
+/*****************************************************************************/
+/* Defines:                                                                  */
+/*****************************************************************************/
+// The number of columns comprising a state in AES. This is a constant in AES. Value=4
+#define Nb 4
+
+#if defined(AES256) && (AES256 == 1)
+    #define Nk 8
+    #define Nr 14
+#elif defined(AES192) && (AES192 == 1)
+    #define Nk 6
+    #define Nr 12
+#else
+    #define Nk 4        // The number of 32 bit words in a key.
+    #define Nr 10       // The number of rounds in AES Cipher.
+#endif
+
+// jcallan@github points out that declaring Multiply as a function 
+// reduces code size considerably with the Keil ARM compiler.
+// See this link for more information: https://github.com/kokke/tiny-AES-C/pull/3
+#ifndef MULTIPLY_AS_A_FUNCTION
+  #define MULTIPLY_AS_A_FUNCTION 0
+#endif
+
+
+
+
+/*****************************************************************************/
+/* Private variables:                                                        */
+/*****************************************************************************/
+// state - array holding the intermediate results during decryption.
+typedef uint8_t state_t[4][4];
+
+
+
+// The lookup-tables are marked const so they can be placed in read-only storage instead of RAM
+// The numbers below can be computed dynamically trading ROM for RAM - 
+// This can be useful in (embedded) bootloader applications, where ROM is often limited.
+static const uint8_t sbox[256] = {
+  //0     1    2      3     4    5     6     7      8    9     A      B    C     D     E     F
+  0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
+  0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
+  0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
+  0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
+  0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
+  0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
+  0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
+  0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
+  0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
+  0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
+  0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
+  0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
+  0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
+  0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
+  0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
+  0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 };
+
+#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
+static const uint8_t rsbox[256] = {
+  0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
+  0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
+  0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
+  0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
+  0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
+  0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
+  0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
+  0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
+  0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
+  0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
+  0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
+  0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
+  0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
+  0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
+  0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
+  0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
+#endif
+
+// The round constant word array, Rcon[i], contains the values given by 
+// x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
+static const uint8_t Rcon[11] = {
+  0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
+
+/*
+ * Jordan Goulder points out in PR #12 (https://github.com/kokke/tiny-AES-C/pull/12),
+ * that you can remove most of the elements in the Rcon array, because they are unused.
+ *
+ * From Wikipedia's article on the Rijndael key schedule @ https://en.wikipedia.org/wiki/Rijndael_key_schedule#Rcon
+ * 
+ * "Only the first some of these constants are actually used ¨C up to rcon[10] for AES-128 (as 11 round keys are needed), 
+ *  up to rcon[8] for AES-192, up to rcon[7] for AES-256. rcon[0] is not used in AES algorithm."
+ */
+
+
+/*****************************************************************************/
+/* Private functions:                                                        */
+/*****************************************************************************/
+/*
+static uint8_t getSBoxValue(uint8_t num)
+{
+  return sbox[num];
+}
+*/
+#define getSBoxValue(num) (sbox[(num)])
+
+// This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states. 
+static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key)
+{
+  unsigned i, j, k;
+  uint8_t tempa[4]; // Used for the column/row operations
+  
+  // The first round key is the key itself.
+  for (i = 0; i < Nk; ++i)
+  {
+    RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
+    RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
+    RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
+    RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
+  }
+
+  // All other round keys are found from the previous round keys.
+  for (i = Nk; i < Nb * (Nr + 1); ++i)
+  {
+    {
+      k = (i - 1) * 4;
+      tempa[0]=RoundKey[k + 0];
+      tempa[1]=RoundKey[k + 1];
+      tempa[2]=RoundKey[k + 2];
+      tempa[3]=RoundKey[k + 3];
+
+    }
+
+    if (i % Nk == 0)
+    {
+      // This function shifts the 4 bytes in a word to the left once.
+      // [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
+
+      // Function RotWord()
+      {
+        const uint8_t u8tmp = tempa[0];
+        tempa[0] = tempa[1];
+        tempa[1] = tempa[2];
+        tempa[2] = tempa[3];
+        tempa[3] = u8tmp;
+      }
+
+      // SubWord() is a function that takes a four-byte input word and 
+      // applies the S-box to each of the four bytes to produce an output word.
+
+      // Function Subword()
+      {
+        tempa[0] = getSBoxValue(tempa[0]);
+        tempa[1] = getSBoxValue(tempa[1]);
+        tempa[2] = getSBoxValue(tempa[2]);
+        tempa[3] = getSBoxValue(tempa[3]);
+      }
+
+      tempa[0] = tempa[0] ^ Rcon[i/Nk];
+    }
+#if defined(AES256) && (AES256 == 1)
+    if (i % Nk == 4)
+    {
+      // Function Subword()
+      {
+        tempa[0] = getSBoxValue(tempa[0]);
+        tempa[1] = getSBoxValue(tempa[1]);
+        tempa[2] = getSBoxValue(tempa[2]);
+        tempa[3] = getSBoxValue(tempa[3]);
+      }
+    }
+#endif
+    j = i * 4; k=(i - Nk) * 4;
+    RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0];
+    RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1];
+    RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2];
+    RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3];
+  }
+}
+
+void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key)
+{
+  KeyExpansion(ctx->RoundKey, key);
+}
+#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
+void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv)
+{
+  KeyExpansion(ctx->RoundKey, key);
+  memcpy (ctx->Iv, iv, AES_BLOCKLEN);
+}
+void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv)
+{
+  memcpy (ctx->Iv, iv, AES_BLOCKLEN);
+}
+#endif
+
+// This function adds the round key to state.
+// The round key is added to the state by an XOR function.
+static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey)
+{
+  uint8_t i,j;
+  for (i = 0; i < 4; ++i)
+  {
+    for (j = 0; j < 4; ++j)
+    {
+      (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
+    }
+  }
+}
+
+// The SubBytes Function Substitutes the values in the
+// state matrix with values in an S-box.
+static void SubBytes(state_t* state)
+{
+  uint8_t i, j;
+  for (i = 0; i < 4; ++i)
+  {
+    for (j = 0; j < 4; ++j)
+    {
+      (*state)[j][i] = getSBoxValue((*state)[j][i]);
+    }
+  }
+}
+
+// The ShiftRows() function shifts the rows in the state to the left.
+// Each row is shifted with different offset.
+// Offset = Row number. So the first row is not shifted.
+static void ShiftRows(state_t* state)
+{
+  uint8_t temp;
+
+  // Rotate first row 1 columns to left  
+  temp           = (*state)[0][1];
+  (*state)[0][1] = (*state)[1][1];
+  (*state)[1][1] = (*state)[2][1];
+  (*state)[2][1] = (*state)[3][1];
+  (*state)[3][1] = temp;
+
+  // Rotate second row 2 columns to left  
+  temp           = (*state)[0][2];
+  (*state)[0][2] = (*state)[2][2];
+  (*state)[2][2] = temp;
+
+  temp           = (*state)[1][2];
+  (*state)[1][2] = (*state)[3][2];
+  (*state)[3][2] = temp;
+
+  // Rotate third row 3 columns to left
+  temp           = (*state)[0][3];
+  (*state)[0][3] = (*state)[3][3];
+  (*state)[3][3] = (*state)[2][3];
+  (*state)[2][3] = (*state)[1][3];
+  (*state)[1][3] = temp;
+}
+
+static uint8_t xtime(uint8_t x)
+{
+  return ((x<<1) ^ (((x>>7) & 1) * 0x1b));
+}
+
+// MixColumns function mixes the columns of the state matrix
+static void MixColumns(state_t* state)
+{
+  uint8_t i;
+  uint8_t Tmp, Tm, t;
+  for (i = 0; i < 4; ++i)
+  {  
+    t   = (*state)[i][0];
+    Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ;
+    Tm  = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm);  (*state)[i][0] ^= Tm ^ Tmp ;
+    Tm  = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm);  (*state)[i][1] ^= Tm ^ Tmp ;
+    Tm  = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm);  (*state)[i][2] ^= Tm ^ Tmp ;
+    Tm  = (*state)[i][3] ^ t ;              Tm = xtime(Tm);  (*state)[i][3] ^= Tm ^ Tmp ;
+  }
+}
+
+// Multiply is used to multiply numbers in the field GF(2^8)
+// Note: The last call to xtime() is unneeded, but often ends up generating a smaller binary
+//       The compiler seems to be able to vectorize the operation better this way.
+//       See https://github.com/kokke/tiny-AES-c/pull/34
+#if MULTIPLY_AS_A_FUNCTION
+static uint8_t Multiply(uint8_t x, uint8_t y)
+{
+  return (((y & 1) * x) ^
+       ((y>>1 & 1) * xtime(x)) ^
+       ((y>>2 & 1) * xtime(xtime(x))) ^
+       ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^
+       ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */
+  }
+#else
+#define Multiply(x, y)                                \
+      (  ((y & 1) * x) ^                              \
+      ((y>>1 & 1) * xtime(x)) ^                       \
+      ((y>>2 & 1) * xtime(xtime(x))) ^                \
+      ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^         \
+      ((y>>4 & 1) * xtime(xtime(xtime(xtime(x))))))   \
+
+#endif
+
+#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
+/*
+static uint8_t getSBoxInvert(uint8_t num)
+{
+  return rsbox[num];
+}
+*/
+#define getSBoxInvert(num) (rsbox[(num)])
+
+// MixColumns function mixes the columns of the state matrix.
+// The method used to multiply may be difficult to understand for the inexperienced.
+// Please use the references to gain more information.
+static void InvMixColumns(state_t* state)
+{
+  int i;
+  uint8_t a, b, c, d;
+  for (i = 0; i < 4; ++i)
+  { 
+    a = (*state)[i][0];
+    b = (*state)[i][1];
+    c = (*state)[i][2];
+    d = (*state)[i][3];
+
+    (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09);
+    (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d);
+    (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b);
+    (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e);
+  }
+}
+
+
+// The SubBytes Function Substitutes the values in the
+// state matrix with values in an S-box.
+static void InvSubBytes(state_t* state)
+{
+  uint8_t i, j;
+  for (i = 0; i < 4; ++i)
+  {
+    for (j = 0; j < 4; ++j)
+    {
+      (*state)[j][i] = getSBoxInvert((*state)[j][i]);
+    }
+  }
+}
+
+static void InvShiftRows(state_t* state)
+{
+  uint8_t temp;
+
+  // Rotate first row 1 columns to right  
+  temp = (*state)[3][1];
+  (*state)[3][1] = (*state)[2][1];
+  (*state)[2][1] = (*state)[1][1];
+  (*state)[1][1] = (*state)[0][1];
+  (*state)[0][1] = temp;
+
+  // Rotate second row 2 columns to right 
+  temp = (*state)[0][2];
+  (*state)[0][2] = (*state)[2][2];
+  (*state)[2][2] = temp;
+
+  temp = (*state)[1][2];
+  (*state)[1][2] = (*state)[3][2];
+  (*state)[3][2] = temp;
+
+  // Rotate third row 3 columns to right
+  temp = (*state)[0][3];
+  (*state)[0][3] = (*state)[1][3];
+  (*state)[1][3] = (*state)[2][3];
+  (*state)[2][3] = (*state)[3][3];
+  (*state)[3][3] = temp;
+}
+#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
+
+// Cipher is the main function that encrypts the PlainText.
+static void Cipher(state_t* state, const uint8_t* RoundKey)
+{
+  uint8_t round = 0;
+
+  // Add the First round key to the state before starting the rounds.
+  AddRoundKey(0, state, RoundKey);
+
+  // There will be Nr rounds.
+  // The first Nr-1 rounds are identical.
+  // These Nr rounds are executed in the loop below.
+  // Last one without MixColumns()
+  for (round = 1; ; ++round)
+  {
+    SubBytes(state);
+    ShiftRows(state);
+    if (round == Nr) {
+      break;
+    }
+    MixColumns(state);
+    AddRoundKey(round, state, RoundKey);
+  }
+  // Add round key to last round
+  AddRoundKey(Nr, state, RoundKey);
+}
+
+#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
+static void InvCipher(state_t* state, const uint8_t* RoundKey)
+{
+  uint8_t round = 0;
+
+  // Add the First round key to the state before starting the rounds.
+  AddRoundKey(Nr, state, RoundKey);
+
+  // There will be Nr rounds.
+  // The first Nr-1 rounds are identical.
+  // These Nr rounds are executed in the loop below.
+  // Last one without InvMixColumn()
+  for (round = (Nr - 1); ; --round)
+  {
+    InvShiftRows(state);
+    InvSubBytes(state);
+    AddRoundKey(round, state, RoundKey);
+    if (round == 0) {
+      break;
+    }
+    InvMixColumns(state);
+  }
+
+}
+#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
+
+/*****************************************************************************/
+/* Public functions:                                                         */
+/*****************************************************************************/
+#if defined(ECB) && (ECB == 1)
+
+
+void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf)
+{
+  // The next function call encrypts the PlainText with the Key using AES algorithm.
+  Cipher((state_t*)buf, ctx->RoundKey);
+}
+
+void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf)
+{
+  // The next function call decrypts the PlainText with the Key using AES algorithm.
+  InvCipher((state_t*)buf, ctx->RoundKey);
+}
+
+
+#endif // #if defined(ECB) && (ECB == 1)
+
+
+
+
+
+#if defined(CBC) && (CBC == 1)
+
+
+static void XorWithIv(uint8_t* buf, const uint8_t* Iv)
+{
+  uint8_t i;
+  for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size
+  {
+    buf[i] ^= Iv[i];
+  }
+}
+
+void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, size_t length)
+{
+  size_t i;
+  uint8_t *Iv = ctx->Iv;
+  for (i = 0; i < length; i += AES_BLOCKLEN)
+  {
+    XorWithIv(buf, Iv);
+    Cipher((state_t*)buf, ctx->RoundKey);
+    Iv = buf;
+    buf += AES_BLOCKLEN;
+  }
+  /* store Iv in ctx for next call */
+  memcpy(ctx->Iv, Iv, AES_BLOCKLEN);
+}
+
+void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length)
+{
+  size_t i;
+  uint8_t storeNextIv[AES_BLOCKLEN];
+  for (i = 0; i < length; i += AES_BLOCKLEN)
+  {
+    memcpy(storeNextIv, buf, AES_BLOCKLEN);
+    InvCipher((state_t*)buf, ctx->RoundKey);
+    XorWithIv(buf, ctx->Iv);
+    memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN);
+    buf += AES_BLOCKLEN;
+  }
+
+}
+
+#endif // #if defined(CBC) && (CBC == 1)
+
+
+
+#if defined(CTR) && (CTR == 1)
+
+/* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */
+void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length)
+{
+  uint8_t buffer[AES_BLOCKLEN];
+  
+  size_t i;
+  int bi;
+  for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
+  {
+    if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */
+    {
+      
+      memcpy(buffer, ctx->Iv, AES_BLOCKLEN);
+      Cipher((state_t*)buffer,ctx->RoundKey);
+
+      /* Increment Iv and handle overflow */
+      for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi)
+      {
+	/* inc will overflow */
+        if (ctx->Iv[bi] == 255)
+	{
+          ctx->Iv[bi] = 0;
+          continue;
+        } 
+        ctx->Iv[bi] += 1;
+        break;   
+      }
+      bi = 0;
+    }
+
+    buf[i] = (buf[i] ^ buffer[bi]);
+  }
+}
+
+#endif // #if defined(CTR) && (CTR == 1)
+

+ 32 - 49
Core/Src/freertos.c

@@ -26,6 +26,10 @@
 /* Private includes ----------------------------------------------------------*/
 /* USER CODE BEGIN Includes */
 
+#include "key.h"
+#include "usart.h"
+void Jump_interface(Menu_table menu);
+extern Menu_table menu;
 /* USER CODE END Includes */
 
 /* Private typedef -----------------------------------------------------------*/
@@ -41,11 +45,6 @@
 /* Private macro -------------------------------------------------------------*/
 /* USER CODE BEGIN PM */
 
-extern Menu_table menu;
-extern BtFrame btframe;
-
-extern bool resetBTmodule;
-extern TipsFlag tipsflag;
 /* USER CODE END PM */
 
 /* Private variables ---------------------------------------------------------*/
@@ -59,9 +58,7 @@ osThreadId loginfoTaskHandle;
 /* Private function prototypes -----------------------------------------------*/
 /* USER CODE BEGIN FunctionPrototypes */
 
-void execute_interface(Menu_table menu);
-void close_lock(BtFrame btframe);
-void open_lock(BtFrame btframe);
+
 /* USER CODE END FunctionPrototypes */
 
 void StartScanKeyTask(void const * argument);
@@ -150,18 +147,11 @@ void StartScanKeyTask(void const * argument)
   for(;;)
   {
     osDelay(1);
-	UPDATE_EXECUTE_REFRESH();// 更新按键状态,执行界面操作,并刷新OLED
+	updatekeystate(); 
+    Jump_interface(menu); 
+    OLED_Refresh(); 
+	open_close_lock();
 	workinfo_W();
-	Scan_lock_status();//扫描状态
-	Seal_Unseal_Jumptips();//施解封跳转tips监测
-	/**扫描重启模块标志位**/	  
-#if Test_old ==1
-	RESET_BT_MODULE_demo();
-#else
-	Transfer4GBuff();	//u4RecvFlag监测位
-	RESET_BT_MODULE();	//蓝牙重启标志位
-	RESET_4G_MODULE();	//4G重启标志位
-#endif
   }
   /* USER CODE END StartScanKeyTask */
 }
@@ -181,20 +171,10 @@ void StarBT4GTask(void const * argument)
   for(;;)
   {
     osDelay(1);
-	open_close_lock();//执行施解封操作
 	  
-#if Test_old ==1
-
-#else
-	if(tipsflag!=Default)
-	{
-		if(tipsflag==InProgress)
-		{
-			HAL_Delay(1500);
-			SET_MENU_STATUS(7, 3, 0, 2);
-		}
-	}
-#endif
+	  
+	  
+	  
   }
   /* USER CODE END StarBT4GTask */
 }
@@ -214,6 +194,22 @@ void StartTestTask(void const * argument)
   for(;;)
   {
     osDelay(1);
+	  if(S1==0x1111)
+	  {
+		  menu.home=0x1000;
+	  }
+	  if(S1==0x2222)
+	  {
+		  menu.home=0xF000;
+	  }
+	  if(S2==0x1111)
+	  {
+		  menu.home |= 0x0100;
+	  }
+	  if(S2==0x2222)
+	  {
+		  menu.home |= 0x0F00;
+	  }
   }
   /* USER CODE END StartTestTask */
 }
@@ -232,23 +228,10 @@ void StartloginfoTaskTask(void const * argument)
   for(;;)
   {
     osDelay(1000);
-#if Test_old == 1
-	if (BT_CONN && (L1bd || L2bd || L3bd || L4bd) && (menu.current < 8 || menu.current > 11) && (tipsflag==Default))//连接后轮询
-	{
-		lock_searchInfo();
-	}
-#else
-	//Bt_MacScan("AT+SCAN=1\r\n");
-	if (BT_CONN && (L1bd || L2bd || L3bd || L4bd) && (menu.current < 8 || menu.current > 11) && (tipsflag==Default))//连接后轮询
-	{
-		lock_searchInfo();
-	}
-	
-	ML307A_Init();		//4G初始化test Log 有启动时间,放置1000ms
-	
-	
-
-#endif
+	//dtu_test();
+
+		//lock_searchInfo();
+
   }
   /* USER CODE END StartloginfoTaskTask */
 }

文件差异内容过多而无法显示
+ 810 - 765
Core/Src/interface.c


文件差异内容过多而无法显示
+ 1133 - 36
Core/Src/key.c


+ 25 - 9
Core/Src/main.c

@@ -47,6 +47,7 @@
 
 extern Menu_table menu;
 extern bool refresh;
+extern TipsFlag tipsflag;
 /* USER CODE END PM */
 
 /* Private variables ---------------------------------------------------------*/
@@ -59,6 +60,7 @@ void SystemClock_Config(void);
 void MX_FREERTOS_Init(void);
 /* USER CODE BEGIN PFP */
 
+void Jump_interface(Menu_table menu);
 /* USER CODE END PFP */
 
 /* Private user code ---------------------------------------------------------*/
@@ -111,15 +113,28 @@ int main(void)
   TIM_Start(&htim3);		//led
   OLED_DISPLAY(0,0);		//color>1 反色;display>1 翻转
   IDLE_DMA_UART(&huart4);	//开启4G_DMA中断
-  RXNE_UART(&huart5);		//开启BT中断
-  HELLO("\r\t###00\tDtuStart...");
-#if Test_old ==1
-	MBA32A_Init_demo();
-#else
-	MBA32A_Init();		//蓝牙初始化
-	module4G_init=true;
-//	ML307A_Init();		//4G初始化
-#endif
+  RXNE_UART(&huart5);		//开启BT接收中断
+  printf("hello\r\n");
+  menu.current = 0xBB; 
+  tipsflag = Starting; 
+  Jump_interface(menu); 
+  OLED_Refresh(); 
+
+  uint16_t S1bd = read_flash_16(Sn1Addr);
+  uint16_t S2bd = read_flash_16(Sn2Addr);
+  if(S1bd!=0xFFFF)
+  {
+	  L1bd=true;
+  }
+  if(S2bd!=0xFFFF)
+  {
+	  L2bd=true;
+  }
+  S1 = read_flash_16(Sn1StatusAddr);
+  S2 = read_flash_16(Sn2StatusAddr);
+  refresh=true;
+  //ML307A_Init();
+  MBA32A_Init();
   /* USER CODE END 2 */
 
   /* Call init function for freertos objects (in freertos.c) */
@@ -210,6 +225,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
   if (htim->Instance == TIM1) {
     HAL_IncTick();
   }
+
   /* USER CODE BEGIN Callback 1 */
 	//喂看门狗
 	TOGGLE_WDI_PIN(&htim2);

文件差异内容过多而无法显示
+ 351 - 484
Core/Src/mba32a.c


+ 20 - 65
Core/Src/ml307a.c

@@ -1,72 +1,49 @@
 #include "ml307a.h"
+#include "mba32a.h"
 
-/**
-  * @breaf 本页定义
-  */
+uint8_t u4length=0;
+uint8_t resetcount_4g=0;
 bool u4RecvFlag = false;
-bool reset4Gmodule = false;
 bool ml307aFail = false;
-bool module4G_init = false;
-uint8_t u4length = 0;
-uint8_t resetcount_4g=0;
 uint8_t g_ML307A_8buf[2048]={0}; 
 uint8_t g_ML307A_8buf_Down[2048]={0}; 
 
-/**
-  * @breaf 本页方法
-  */
-void ML307AReset(void);	//4G模块重启
-uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum);
 
-/**
-  * @breaf 外部声明
-  */
+extern UART_HandleTypeDef huart3;
 extern UART_HandleTypeDef huart4;
 
-
+uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum);
 
 void ML307A_Init(void)
 {
 	
-	//4Gled 隔1s快闪搜网未注册,隔2s为成功注册上网络
-	//<***> 单括号内为正常回复
-	if(!module4G_init)  //复位需同时变true
-		return;
+	HAL_Delay(2000);
 	INIT_4G_FRAME();
+	
 	if(!sendCmd_4G("AT\r\n","OK",1,1))
 	{
 		ml307aFail=true;
 		printf("4G模组异常!\r\n");
-	}
-	if(sendCmd_4G("AT+CPIN?\r\n","+CME ERROR: 10",1,1))				//00检测是否有SIM卡									<+CPIN: READY\r\nOK>
-	{
-		printf("未检测到SIM卡\r\n");
-	}		
-	else if(ml307aFail)
+	}	
+	
+	if (ml307aFail)
 	{
 		printf("#4G模块初始化Fail");
 	}
-	else if(!ml307aFail)
+	else
 	{
-		if(sendCmd_4G("AT+CSQ\r\n","ERROR",1,1))					//01查询信号值(信号强度,误码率)						<+CSQ: 26,99\r\nOK>
-		{printf("查询信号Fail\r\n");}
-		if(sendCmd_4G("AT+CEREG?\r\n","ERROR",1,1))		    		//02查询附着成功(驻网:*,@ @为1或5表示附着成功)	<+CEREG: 0,1\r\nOK>
-		{printf("查询驻网Fail\r\n");}
-		if(sendCmd_4G("AT+MIPCALL?\r\n","ERROR",1,1))				//03查询PDP激活状态									<+MIPCALL: 1,1,"10.94.99.162"\r\nOK>
-		{printf("查询PDP激活状态Fail\r\n");}
+		HAL_Delay(2000);
+		
+		if (sendCmd_4G("AT+CPIN?\r\n", "+CME ERROR: 10", 1, 1)) // 00检测是否有SIM卡 <+CPIN: READY\r\nOK>
+		{
+			printf("\tERROR!-->未检测到SIM卡\r\n");
+			OLED_ShowString(42,50,"NO_SIM",12,0);
+		}
 
 	}
-	//初始化后Todo
-	module4G_init=false;
-	
 }
 
 
-
-
-/**
-  * @breaf 串口发送命令,有接收数组比较函数
-  */
 uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum)
 {
     uint8_t i = 0;
@@ -82,7 +59,6 @@ uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum)
 		{
 			if(strstr((const char *)g_ML307A_8buf_Down, pRes) != NULL)             // 如果检索到关键词
 			{
-				memset(g_ML307A_8buf_Down,0,u4length);
 				return 1;
 			}
 			HAL_Delay(100);
@@ -91,30 +67,9 @@ uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum)
     return 0;
 }
 
-/**
- @brief 重启模块
- @param 无
- @return 无
-*/
-void ML307AReset(void)
-{
-	reset4Gmodule=true;
-	resetcount_4g+=1;
-	printf("4G Module_Reset\n");    
-	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
-	HAL_Delay(5000);
-	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
-}
 
-void Transfer4GBuff(void)
-{
-	if(u4RecvFlag)
-	{
-		u4RecvFlag=false;
-		memset(g_ML307A_8buf_Down,0,2048);
-		memcpy(g_ML307A_8buf_Down,g_ML307A_8buf,u4length);
-	}
-}
+
+
 
 
 

+ 8 - 6
Core/Src/stm32f1xx_it.c

@@ -43,7 +43,6 @@
 /* Private variables ---------------------------------------------------------*/
 /* USER CODE BEGIN PV */
 
-extern uint16_t u5length;
 /* USER CODE END PV */
 
 /* Private function prototypes -----------------------------------------------*/
@@ -367,9 +366,7 @@ void TIM3_IRQHandler(void)
 {
   /* USER CODE BEGIN TIM3_IRQn 0 */
 	
-	/* 运行指示灯 */ 
-	LED_TOGGLE(GPIO_PIN_9);
-	
+  LED_TOGGLE(GPIO_PIN_9);
   /* USER CODE END TIM3_IRQn 0 */
   HAL_TIM_IRQHandler(&htim3);
   /* USER CODE BEGIN TIM3_IRQn 1 */
@@ -425,6 +422,7 @@ void USART3_IRQHandler(void)
 void UART4_IRQHandler(void)
 {
   /* USER CODE BEGIN UART4_IRQn 0 */
+	
 	uint32_t tmpFlag = 0;
 	uint32_t temp;
 	tmpFlag =__HAL_UART_GET_FLAG(&huart4,UART_FLAG_IDLE); //获取IDLE标志位
@@ -434,13 +432,17 @@ void UART4_IRQHandler(void)
 		HAL_UART_DMAStop(&huart4); 
 		temp  =  __HAL_DMA_GET_COUNTER(&hdma_uart4_rx);		// 获取DMA中未传输的数据个数   
 		recvLength  =  2048 - temp - 2; 	//-2>去掉\r\n		//总计数减去未传输的数据个数,得到已经接收的数据个数
+		u4RecvFlag = true;
 		u4length = recvLength;
+		
 		memcpy(g_ML307A_8buf, &recvBuff[2], recvLength);	
-		u4RecvFlag = true;
+		memcpy(g_ML307A_8buf_Down, g_ML307A_8buf, recvLength);	
+		
 		
 		HAL_UART_Receive_DMA(&huart4, recvBuff, 2048);		//重新打开DMA接收,不然只能接收一次数据
 	 }
 
+	
   /* USER CODE END UART4_IRQn 0 */
   HAL_UART_IRQHandler(&huart4);
   /* USER CODE BEGIN UART4_IRQn 1 */
@@ -455,7 +457,7 @@ void UART5_IRQHandler(void)
 {
   /* USER CODE BEGIN UART5_IRQn 0 */
  	static int index = 0; // 用于记录存储到数组中的位置
-  uint8_t data;
+    uint8_t data;
 	
 	if (index > 0 && __HAL_UART_GET_FLAG(&huart5, UART_FLAG_IDLE) == SET)
 	{

+ 37 - 8
Core/Src/usart.c

@@ -22,8 +22,11 @@
 
 /* USER CODE BEGIN 0 */
 
+#include "dtuaes.h"
 volatile uint8_t recvLength = 0;  //接收一帧数据的长度
 uint8_t recvBuff[2048];
+
+extern Menu_table menu;
 /* USER CODE END 0 */
 
 UART_HandleTypeDef huart4;
@@ -597,7 +600,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
 }
 
 /* USER CODE BEGIN 1 */
-
 #ifdef __GNUC__
   /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
      set to 'Yes') calls __io_putchar() */
@@ -619,10 +621,11 @@ PUTCHAR_PROTOTYPE
   *	@brief printf全局打印
   */
 
-  UART_PRINT(&huart3);//TTL
+  HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF);
   return ch;
 }
 
+
 uint16_t read_flash_16(uint32_t addr){
     uint16_t data = *(volatile uint16_t*)addr;     // 从Flash中读取2个字节
     return data;
@@ -644,8 +647,7 @@ void erase_flash(uint32_t ADDR_FLASH){                //
     }
 }
 
-void Write_Information(uint32_t addr) {
-    uint16_t newValue = 0;
+void Write_Information(uint32_t addr, uint16_t newValue) {
 	erase_flash(addr);
     HAL_FLASH_Unlock();  // 解锁Flash
 	
@@ -656,6 +658,19 @@ void Write_Information(uint32_t addr) {
 			//复位写入成功
         }
     }    
+	else if(addr == DevstatusAddr)
+	{
+        newValue = menu.home;
+        HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, addr, newValue);
+        if (status == HAL_OK) {
+			//复位写入成功
+        }
+	}
+	else if(addr == Sn1Addr || addr == Sn2Addr || addr == Sn3Addr || addr == Sn4Addr || addr==Sn1StatusAddr || addr==Sn2StatusAddr || addr==Sn3StatusAddr || addr==Sn4StatusAddr)
+	{
+        HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, addr, newValue);
+	}
+
 	HAL_FLASH_Lock();  // 上锁Flash
 }
 
@@ -693,12 +708,17 @@ void USART_SendHexArray(UART_HandleTypeDef *huart, uint8_t *data, int length)
 	HAL_UART_Transmit(&huart3, data, length, 0xFFFF);//ttl
 }
 
-void sendCombinedArray(uint8_t *header, size_t headerLength, uint8_t *command, size_t commandLength) {
+
+struct AES_ctx ctx;
+
+void sendCombinedArray(uint8_t *header, size_t headerLength, uint8_t *command, size_t commandLength, bool JM) {
+	
     // 创建一个长度为20的数组
     uint8_t combinedArray[20] = {0};
     // 将header复制到combinedArray的前两个字节
-    combinedArray[0] = header[0];
-    combinedArray[1] = header[1];
+    combinedArray[0] = header[0];//0x66
+    combinedArray[1] = header[1];//0x01(加密)
+	
     // 计算command的异或校验和
     uint8_t result_xor = xorBytes(command, commandLength);
     // 创建一个长度为16的数组来存储command和result_xor
@@ -708,18 +728,27 @@ void sendCombinedArray(uint8_t *header, size_t headerLength, uint8_t *command, s
         cmd_array[i] = command[i];
     }
     cmd_array[commandLength] = result_xor;
+
+/* 加密 */		
+	if(JM)
+	{
+		AES_init_ctx_iv(&ctx, DtuBtKey, iv);
+		AES_CBC_encrypt_buffer(&ctx, cmd_array, 16);
+	}
+	
     // 将cmd_array添加到combinedArray
     for (int i = 0; i < 16; i++) {
         combinedArray[i + headerLength] = cmd_array[i];
     }
+		
     // 计算combinedArray的CRC校验和
     uint16_t result_frame = crc16(combinedArray, sizeof(combinedArray) - 2);
     // 将result_frame添加到combinedArray
     combinedArray[18] = result_frame & 0xFF;		//低字节在前
     combinedArray[19] = (result_frame >> 8) & 0xFF;
     // 发送combinedArray
-	
     USART_SendHexArray(&huart5, combinedArray, sizeof(combinedArray));
 
 }
+
 /* USER CODE END 1 */

+ 61 - 31
MDK-ARM/dtu.uvoptx

@@ -153,14 +153,32 @@
         <Ww>
           <count>0</count>
           <WinNumber>1</WinNumber>
-          <ItemText>g_MBA32A_8buf_Down</ItemText>
+          <ItemText>in</ItemText>
         </Ww>
         <Ww>
           <count>1</count>
           <WinNumber>1</WinNumber>
-          <ItemText>dev1</ItemText>
+          <ItemText>menu</ItemText>
+        </Ww>
+        <Ww>
+          <count>2</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>S1</ItemText>
+        </Ww>
+        <Ww>
+          <count>3</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>S2</ItemText>
         </Ww>
       </WatchWindow1>
+      <MemoryWindow1>
+        <Mm>
+          <WinNumber>1</WinNumber>
+          <SubType>0</SubType>
+          <ItemText>Sn1StatusAddr</ItemText>
+          <AccSizeX>0</AccSizeX>
+        </Mm>
+      </MemoryWindow1>
       <Tracepoint>
         <THDelay>0</THDelay>
       </Tracepoint>
@@ -443,6 +461,18 @@
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>19</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Core\Src\dtuaes.c</PathWithFileName>
+      <FilenameWithoutPath>dtuaes.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
   </Group>
 
   <Group>
@@ -453,7 +483,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>19</FileNumber>
+      <FileNumber>20</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -465,7 +495,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>20</FileNumber>
+      <FileNumber>21</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -477,7 +507,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>21</FileNumber>
+      <FileNumber>22</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -489,7 +519,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>22</FileNumber>
+      <FileNumber>23</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -501,7 +531,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>23</FileNumber>
+      <FileNumber>24</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -513,7 +543,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>24</FileNumber>
+      <FileNumber>25</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -525,7 +555,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>25</FileNumber>
+      <FileNumber>26</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -537,7 +567,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>26</FileNumber>
+      <FileNumber>27</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -549,7 +579,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>27</FileNumber>
+      <FileNumber>28</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -561,7 +591,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>28</FileNumber>
+      <FileNumber>29</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -573,7 +603,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>29</FileNumber>
+      <FileNumber>30</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -585,7 +615,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>30</FileNumber>
+      <FileNumber>31</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -597,7 +627,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>31</FileNumber>
+      <FileNumber>32</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -609,7 +639,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>32</FileNumber>
+      <FileNumber>33</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -621,7 +651,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>33</FileNumber>
+      <FileNumber>34</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -633,7 +663,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>34</FileNumber>
+      <FileNumber>35</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -645,7 +675,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>35</FileNumber>
+      <FileNumber>36</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -657,7 +687,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>36</FileNumber>
+      <FileNumber>37</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -677,7 +707,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>37</FileNumber>
+      <FileNumber>38</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -697,7 +727,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>38</FileNumber>
+      <FileNumber>39</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -709,7 +739,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>39</FileNumber>
+      <FileNumber>40</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -721,7 +751,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>40</FileNumber>
+      <FileNumber>41</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -733,7 +763,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>41</FileNumber>
+      <FileNumber>42</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -745,7 +775,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>42</FileNumber>
+      <FileNumber>43</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -757,7 +787,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>43</FileNumber>
+      <FileNumber>44</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -769,7 +799,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>44</FileNumber>
+      <FileNumber>45</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -781,7 +811,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>45</FileNumber>
+      <FileNumber>46</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -793,7 +823,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>46</FileNumber>
+      <FileNumber>47</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -805,7 +835,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>47</FileNumber>
+      <FileNumber>48</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>

+ 19 - 1
MDK-ARM/dtu.uvprojx

@@ -632,6 +632,11 @@
               <FileType>1</FileType>
               <FilePath>..\Core\Src\ml307a.c</FilePath>
             </File>
+            <File>
+              <FileName>dtuaes.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Core\Src\dtuaes.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -1543,7 +1548,20 @@
         </targetInfos>
       </component>
     </components>
-    <files/>
+    <files>
+      <file attr="config" category="header" name="RTE\configs\mbedTLS_config.h" version="3.1.0">
+        <instance index="0" removed="1">RTE\Security\mbedTLS_config.h</instance>
+        <component Cclass="Security" Cgroup="mbed TLS" Cvendor="ARM" Cversion="3.1.0"/>
+        <package name="mbedTLS" schemaVersion="1.6.3" url="https://www.keil.com/pack/" vendor="ARM" version="3.1.1"/>
+        <targetInfos/>
+      </file>
+      <file attr="config" category="header" name="RTE\configs\mbedTLS_crypto_config.h" version="3.1.0">
+        <instance index="0" removed="1">RTE\Security\mbedTLS_crypto_config.h</instance>
+        <component Cclass="Security" Cgroup="mbed TLS" Cvendor="ARM" Cversion="3.1.0"/>
+        <package name="mbedTLS" schemaVersion="1.6.3" url="https://www.keil.com/pack/" vendor="ARM" version="3.1.1"/>
+        <targetInfos/>
+      </file>
+    </files>
   </RTE>
 
   <LayerInfo>

文件差异内容过多而无法显示
+ 3781 - 3209
Output/dtu.hex


+ 1 - 0
Output/dtu.lnp

@@ -17,6 +17,7 @@
 "..\output\stm32f1xx_hal_msp.o"
 "..\output\stm32f1xx_hal_timebase_tim.o"
 "..\output\ml307a.o"
+"..\output\dtuaes.o"
 "..\output\stm32f1xx_hal_gpio_ex.o"
 "..\output\stm32f1xx_hal_can.o"
 "..\output\stm32f1xx_hal.o"