zhao006 il y a 6 mois
Parent
commit
cc491ce3b2

+ 21 - 3
APP/HARDWARE/sources/iwdg.c

@@ -3,14 +3,32 @@
 
 void IWDG_Configuration(uint16_t ms)
 {
+	/* Enable write access to IWDG_PR and IWDG_RLR registers */
     IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
-		IWDG_SetPrescaler(IWDG_Prescaler_256);// 256 min:8ms  max:32768ms
-		IWDG_SetReload(ms); // ms
+		//Prescaler_4  Min timeout:0.125ms  Max timeout :512
+		//Prescaler_8  Min timeout:0.25ms  Max timeout :1024
+		//Prescaler_16  Min timeout:0.5ms  Max timeout :2048
+		//Prescaler_32  Min timeout:1ms  Max timeout :4096
+		//Prescaler_64  Min timeout:2ms  Max timeout :8192
+		//Prescaler_128  Min timeout:4ms  Max timeout :16384
+		//Prescaler_256  Min timeout:8ms  Max timeout :32768
+		IWDG_SetPrescaler(IWDG_Prescaler_64);
+		/* Set counter reload value to obtain 1000ms IWDG TimeOut.
+		Counter Reload Value = 1000ms/IWDG counter clock period
+		= 1000ms / (LSI/64)
+		= 1s / (32 KHz /64)
+		= 2
+		*/
+		IWDG_SetReload(ms/2); // ms
+		/* Enable IWDG (LSI oscillator will be enabled by hardware) */
 		IWDG_Enable();
+		/* Reload IWDG counter */
+		IWDG_ReloadCounter();
 		
 }
  
 void IWDG_feed()
 {
-	IWDG_ReloadCounter(); // ms
+	/* Reload IWDG counter */
+	IWDG_ReloadCounter(); 
 }

+ 60 - 60
APP/HARDWARE/sources/led.c

@@ -108,65 +108,65 @@ void led(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint8_t a) {
 		else		GPIO_ResetBits(GPIOx,GPIO_Pin);	
 }		
 
-uint8_t all_whilte_light(uint8_t cmd)
-{
-	// A
-	led(A_LED1_GPIO_PORT,A_LED1_PIN,cmd);//red
-	led(A_LED3_GPIO_PORT,A_LED3_PIN,cmd);//green
-	led(A_LED4_GPIO_PORT,A_LED4_PIN,cmd);//red
-	led(A_LED6_GPIO_PORT,A_LED6_PIN,cmd);//green
-	led(A_LED7_GPIO_PORT,A_LED7_PIN,cmd);//red
-	led(A_LED9_GPIO_PORT,A_LED9_PIN,cmd);//green
-	led(A_LED10_GPIO_PORT,A_LED10_PIN,cmd);//red
-	led(A_LED12_GPIO_PORT,A_LED12_PIN,cmd);//green
-	led(A_LED13_GPIO_PORT,A_LED13_PIN,cmd);//red
-	led(A_LED15_GPIO_PORT,A_LED15_PIN,cmd);//green
-	led(A_LED16_GPIO_PORT,A_LED16_PIN,cmd);//red
-	led(A_LED18_GPIO_PORT,A_LED18_PIN,cmd);//green
-	
-	//	B
-	led(B_LED1_GPIO_PORT,B_LED1_PIN,cmd);//red
-	led(B_LED3_GPIO_PORT,B_LED3_PIN,cmd);//green
-	led(B_LED4_GPIO_PORT,B_LED4_PIN,cmd);//red
-	led(B_LED6_GPIO_PORT,B_LED6_PIN,cmd);//green
-	led(B_LED7_GPIO_PORT,B_LED7_PIN,cmd);//red
-	led(B_LED9_GPIO_PORT,B_LED9_PIN,cmd);//green
-	led(B_LED10_GPIO_PORT,B_LED10_PIN,cmd);//red
-	led(B_LED12_GPIO_PORT,B_LED12_PIN,cmd);//green
-	led(B_LED13_GPIO_PORT,B_LED13_PIN,cmd);//red
-	led(B_LED15_GPIO_PORT,B_LED15_PIN,cmd);//green
-	led(B_LED16_GPIO_PORT,B_LED16_PIN,cmd);//red
-	led(B_LED18_GPIO_PORT,B_LED18_PIN,cmd);//green
-	
-	// C
-	led(C_LED1_GPIO_PORT,C_LED1_PIN,cmd);//red
-	led(C_LED3_GPIO_PORT,C_LED3_PIN,cmd);//green
-	led(C_LED4_GPIO_PORT,C_LED4_PIN,cmd);//red
-	led(C_LED6_GPIO_PORT,C_LED6_PIN,cmd);//green
-	led(C_LED7_GPIO_PORT,C_LED7_PIN,cmd);//red
-	led(C_LED9_GPIO_PORT,C_LED9_PIN,cmd);//green
-	led(C_LED10_GPIO_PORT,C_LED10_PIN,cmd);//red
-	led(C_LED12_GPIO_PORT,C_LED12_PIN,cmd);//green
-	led(C_LED13_GPIO_PORT,C_LED13_PIN,cmd);//red
-	led(C_LED15_GPIO_PORT,C_LED15_PIN,cmd);//green
-	led(C_LED16_GPIO_PORT,C_LED16_PIN,cmd);//red
-	led(C_LED18_GPIO_PORT,C_LED18_PIN,cmd);//green
-	
-	// D
-	led(D_LED1_GPIO_PORT,D_LED1_PIN,cmd);//red
-	led(D_LED3_GPIO_PORT,D_LED3_PIN,cmd);//green
-	led(D_LED4_GPIO_PORT,D_LED4_PIN,cmd);//red
-	led(D_LED6_GPIO_PORT,D_LED6_PIN,cmd);//green
-	led(D_LED7_GPIO_PORT,D_LED7_PIN,cmd);//red
-	led(D_LED9_GPIO_PORT,D_LED9_PIN,cmd);//green
-	led(D_LED10_GPIO_PORT,D_LED10_PIN,cmd);//red
-	led(D_LED12_GPIO_PORT,D_LED12_PIN,cmd);//green
-	led(D_LED13_GPIO_PORT,D_LED13_PIN,cmd);//red
-	led(D_LED15_GPIO_PORT,D_LED15_PIN,cmd);//green
-	led(D_LED16_GPIO_PORT,D_LED16_PIN,cmd);//red
-	led(D_LED18_GPIO_PORT,D_LED18_PIN,cmd);//green
-	return 1;
-}
+//uint8_t all_whilte_light(uint8_t cmd)
+//{
+//	// A
+//	led(A_LED1_GPIO_PORT,A_LED1_PIN,cmd);//red
+//	led(A_LED3_GPIO_PORT,A_LED3_PIN,cmd);//green
+//	led(A_LED4_GPIO_PORT,A_LED4_PIN,cmd);//red
+//	led(A_LED6_GPIO_PORT,A_LED6_PIN,cmd);//green
+//	led(A_LED7_GPIO_PORT,A_LED7_PIN,cmd);//red
+//	led(A_LED9_GPIO_PORT,A_LED9_PIN,cmd);//green
+//	led(A_LED10_GPIO_PORT,A_LED10_PIN,cmd);//red
+//	led(A_LED12_GPIO_PORT,A_LED12_PIN,cmd);//green
+//	led(A_LED13_GPIO_PORT,A_LED13_PIN,cmd);//red
+//	led(A_LED15_GPIO_PORT,A_LED15_PIN,cmd);//green
+//	led(A_LED16_GPIO_PORT,A_LED16_PIN,cmd);//red
+//	led(A_LED18_GPIO_PORT,A_LED18_PIN,cmd);//green
+//	
+//	//	B
+//	led(B_LED1_GPIO_PORT,B_LED1_PIN,cmd);//red
+//	led(B_LED3_GPIO_PORT,B_LED3_PIN,cmd);//green
+//	led(B_LED4_GPIO_PORT,B_LED4_PIN,cmd);//red
+//	led(B_LED6_GPIO_PORT,B_LED6_PIN,cmd);//green
+//	led(B_LED7_GPIO_PORT,B_LED7_PIN,cmd);//red
+//	led(B_LED9_GPIO_PORT,B_LED9_PIN,cmd);//green
+//	led(B_LED10_GPIO_PORT,B_LED10_PIN,cmd);//red
+//	led(B_LED12_GPIO_PORT,B_LED12_PIN,cmd);//green
+//	led(B_LED13_GPIO_PORT,B_LED13_PIN,cmd);//red
+//	led(B_LED15_GPIO_PORT,B_LED15_PIN,cmd);//green
+//	led(B_LED16_GPIO_PORT,B_LED16_PIN,cmd);//red
+//	led(B_LED18_GPIO_PORT,B_LED18_PIN,cmd);//green
+//	
+//	// C
+//	led(C_LED1_GPIO_PORT,C_LED1_PIN,cmd);//red
+//	led(C_LED3_GPIO_PORT,C_LED3_PIN,cmd);//green
+//	led(C_LED4_GPIO_PORT,C_LED4_PIN,cmd);//red
+//	led(C_LED6_GPIO_PORT,C_LED6_PIN,cmd);//green
+//	led(C_LED7_GPIO_PORT,C_LED7_PIN,cmd);//red
+//	led(C_LED9_GPIO_PORT,C_LED9_PIN,cmd);//green
+//	led(C_LED10_GPIO_PORT,C_LED10_PIN,cmd);//red
+//	led(C_LED12_GPIO_PORT,C_LED12_PIN,cmd);//green
+//	led(C_LED13_GPIO_PORT,C_LED13_PIN,cmd);//red
+//	led(C_LED15_GPIO_PORT,C_LED15_PIN,cmd);//green
+//	led(C_LED16_GPIO_PORT,C_LED16_PIN,cmd);//red
+//	led(C_LED18_GPIO_PORT,C_LED18_PIN,cmd);//green
+//	
+//	// D
+//	led(D_LED1_GPIO_PORT,D_LED1_PIN,cmd);//red
+//	led(D_LED3_GPIO_PORT,D_LED3_PIN,cmd);//green
+//	led(D_LED4_GPIO_PORT,D_LED4_PIN,cmd);//red
+//	led(D_LED6_GPIO_PORT,D_LED6_PIN,cmd);//green
+//	led(D_LED7_GPIO_PORT,D_LED7_PIN,cmd);//red
+//	led(D_LED9_GPIO_PORT,D_LED9_PIN,cmd);//green
+//	led(D_LED10_GPIO_PORT,D_LED10_PIN,cmd);//red
+//	led(D_LED12_GPIO_PORT,D_LED12_PIN,cmd);//green
+//	led(D_LED13_GPIO_PORT,D_LED13_PIN,cmd);//red
+//	led(D_LED15_GPIO_PORT,D_LED15_PIN,cmd);//green
+//	led(D_LED16_GPIO_PORT,D_LED16_PIN,cmd);//red
+//	led(D_LED18_GPIO_PORT,D_LED18_PIN,cmd);//green
+//	return 1;
+//}
 uint8_t all_green_light(uint8_t cmd)
 {
 	// A
@@ -275,7 +275,7 @@ uint8_t all_yellow_light(uint8_t cmd)
 }
 uint8_t all_light(uint8_t cmd)
 {
-	all_whilte_light(cmd);
+//	all_whilte_light(cmd);
 	all_green_light(cmd);
 	all_red_light(cmd);
 	all_yellow_light(cmd);

Fichier diff supprimé car celui-ci est trop grand
+ 500 - 500
APP/HARDWARE/sources/led_function.c


+ 79 - 71
APP/HARDWARE/sources/sys_data.c

@@ -118,77 +118,79 @@ int sendCmd(uint8_t *data, uint16_t size)
 
 
 // 文件更新升级
-uint8_t updata()
-{
-	uint16_t crc;	
-	uint8_t databuf[1024];
-	uint16_t packId = 0x01;
-	uint8_t i = 30,c = 0x63,ack = 0x06,nack = 0x15;
-	// 发送第一个'c'
-	sendCmd(&c,1);
-	//检测 3s 内有无收到数据
-	for(int i = 0; i  < 3000; i++)
-	{
-		delay_ms(1);
-		// 收到数据,跳转到处理数据
-		if(usartMsg.done == 1)
-		{
-			goto __start;
-		}
-	}
-	//3s 内未收到第一包数据,再发送'c'
-	sendCmd(&c,1);
+//uint8_t updata()
+//{
+//	uint16_t crc;	
+//	uint8_t databuf[1024];
+//	uint16_t packId = 0x01;
+//	uint8_t i = 30,c = 0x63,ack = 0x06,nack = 0x15;
+//	// 发送第一个'c'
+//	sendCmd(&c,1);
+//	//检测 3s 内有无收到数据
+//	for(int i = 0; i  < 3000; i++)
+//	{
+//		delay_ms(1);
+//		// 收到数据,跳转到处理数据
+//		if(usartMsg.done == 1)
+//		{
+//			goto __start;
+//		}
+//	}
+//	//3s 内未收到第一包数据,再发送'c'
+//	sendCmd(&c,1);
 
-__start:	
-	// 开始处理数据
-	// 当数据包为EOT(0x04),表示结束
-	while(usartMsg.done == 1 && usartMsg.rxBuf[0] != 0x04)
-	{
-		// 检测帧头
-		if(usartMsg.rxBuf[0] != 0x02)
-		{
-			sendCmd(&nack,1);
-			goto __start;
-		}
-		// 检测包序列
-		if(usartMsg.rxBuf[1] != packId)
-		{
-			sendCmd(&nack,1);
-			goto __start;
-		}
-		// 检测包号反码
-		if(usartMsg.rxBuf[2] != ~packId)
-		{
-			sendCmd(&nack,1);
-			goto __start;
-		}
-		// 提取数据包
-		for(int i = 0; i < 1024; i++)
-		{
-			databuf[i] = usartMsg.rxBuf[3 + i];
-		}
-		crc = Checkcrc16(databuf, 1024);
-		// 检测数据包的校验码
-		if (((crc & 0x00FF) != usartMsg.rxBuf[1028]) || (((crc & 0xFF00) >> 8) != usartMsg.rxBuf[1027]))
-		{	
-			sendCmd(&nack,1);	
-			goto __start;
-		}
-		// 准备接收下一包数据
-		sendCmd(&ack,1);
-		packId += 1;
-	}
-		// 接收到结束信号,反馈ack
-		sendCmd(&ack,1);
-	if(packId != 0)
-		return 1;
-	else
-		return 2;
-}
+//__start:	
+//	// 开始处理数据
+//	// 当数据包为EOT(0x04),表示结束
+//	while(usartMsg.done == 1 && usartMsg.rxBuf[0] != 0x04)
+//	{
+//		// 检测帧头
+//		if(usartMsg.rxBuf[0] != 0x02)
+//		{
+//			sendCmd(&nack,1);
+//			goto __start;
+//		}
+//		// 检测包序列
+//		if(usartMsg.rxBuf[1] != packId)
+//		{
+//			sendCmd(&nack,1);
+//			goto __start;
+//		}
+//		// 检测包号反码
+//		if(usartMsg.rxBuf[2] != ~packId)
+//		{
+//			sendCmd(&nack,1);
+//			goto __start;
+//		}
+//		// 提取数据包
+//		for(int i = 0; i < 1024; i++)
+//		{
+//			databuf[i] = usartMsg.rxBuf[3 + i];
+//		}
+//		crc = Checkcrc16(databuf, 1024);
+//		// 检测数据包的校验码
+//		if (((crc & 0x00FF) != usartMsg.rxBuf[1028]) || (((crc & 0xFF00) >> 8) != usartMsg.rxBuf[1027]))
+//		{	
+//			sendCmd(&nack,1);	
+//			goto __start;
+//		}
+//		// 准备接收下一包数据
+//		sendCmd(&ack,1);
+//		packId += 1;
+//	}
+//		// 接收到结束信号,反馈ack
+//		sendCmd(&ack,1);
+//	if(packId != 0)
+//		return 1;
+//	else
+//		return 2;
+//}
 
 void broad_to_host()
 {
 		int i, j;
+		// 数据包大小
+		int packIndex = 0;
 		result = 2;// 初始化为 2 表示操作失败(硬件故障或其他原因)
 		// 反馈信息
 		uint8_t txData[8];
@@ -219,13 +221,19 @@ void broad_to_host()
 				crc[2 + j] = usartMsg.rxBuf[6+ j];//channel
 				crc[3 + j] = usartMsg.rxBuf[7+ j];//平台号
 				crc[4 + j] = usartMsg.rxBuf[8+ j];//指令值
+				packIndex++;
 		}
 		if((CheckXor(crc,1 + (4 * usartMsg.rxBuf[4])) != usartMsg.rxBuf[9 + (4 * (usartMsg.rxBuf[4] - 1))]))
 		{
 				result = 0x03;//校验位异常
 				goto __feedback;
 		}
-			
+		// 数据包判断
+		if(usartMsg.rxBuf[4] != packIndex )
+		{
+				result = 5;//帧内容异常(指令值超出范围等)
+				goto __feedback;
+		}
 		// 执行指令
 		for(i = 0; i < usartMsg.rxBuf[4] * 4;i += 4)
 		{
@@ -247,10 +255,10 @@ void broad_to_host()
 					if(result != 1)goto __feedback;
 						break;
 					
-				case 0x04: // updata指令
-					if(usartMsg.rxBuf[8] == 1)
-						result = updata();	
-					break;				
+//				case 0x04: // updata指令
+//					if(usartMsg.rxBuf[8] == 1)
+//						result = updata();	
+//					break;				
 				default:
 					result = 0x05;//帧内容异常(指令值超出范围等)
 					goto __feedback;

+ 3 - 20
APP/MDKProject/project.uvoptx

@@ -158,24 +158,7 @@
           <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F2xx_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F207ZGTx$CMSIS\Flash\STM32F2xx_1024.FLM))</Name>
         </SetRegEntry>
       </TargetDriverDllRegistry>
-      <Breakpoint>
-        <Bp>
-          <Number>0</Number>
-          <Type>0</Type>
-          <LineNumber>112</LineNumber>
-          <EnabledFlag>1</EnabledFlag>
-          <Address>134224748</Address>
-          <ByteObject>0</ByteObject>
-          <HtxType>0</HtxType>
-          <ManyObjects>0</ManyObjects>
-          <SizeOfObject>0</SizeOfObject>
-          <BreakByAccess>0</BreakByAccess>
-          <BreakIfRCount>1</BreakIfRCount>
-          <Filename>C:\Users\IBM\Desktop\proje\HARDWARE\sources\led.c</Filename>
-          <ExecCommand></ExecCommand>
-          <Expression>\\lora_gateway\../HARDWARE/sources/led.c\112</Expression>
-        </Bp>
-      </Breakpoint>
+      <Breakpoint/>
       <WatchWindow1>
         <Ww>
           <count>0</count>
@@ -289,7 +272,7 @@
 
   <Group>
     <GroupName>Libraries</GroupName>
-    <tvExp>1</tvExp>
+    <tvExp>0</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
@@ -405,7 +388,7 @@
 
   <Group>
     <GroupName>CORE</GroupName>
-    <tvExp>1</tvExp>
+    <tvExp>0</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>

+ 1 - 1
APP/MDKProject/project.uvprojx

@@ -49,7 +49,7 @@
             <InvalidFlash>1</InvalidFlash>
           </TargetStatus>
           <OutputDirectory>..\OBJ\</OutputDirectory>
-          <OutputName>lora_gateway</OutputName>
+          <OutputName>project</OutputName>
           <CreateExecutable>1</CreateExecutable>
           <CreateLib>0</CreateLib>
           <CreateHexFile>1</CreateHexFile>

+ 8 - 3
APP/USER/main.c

@@ -11,16 +11,21 @@ int main(void)
 {
 	// LED硬件初始化
 	LED_GPIO_Config();
+	
 	// 12V电源初始化
 	BAT_12V_Config();
+	
 	// 5V电源初始化
 	BAT_5V_Config();
+	
 	// USART3初始化
 	USART3_config();
+	
 	// 定时器初始化
 	timer_config();
-// 设置看门狗 3S
-//	IWDG_Configuration(3000);// 参数单位ms 范围 0~0x0FFF
+	
+	// 设置看门狗 3S
+	IWDG_Configuration(3000);// 参数单位ms 范围 0~0x0FFF
 	
 	while(1)
 	{
@@ -29,7 +34,7 @@ int main(void)
 			broad_to_host();
 			delay_ms(100);
 		}
-//		IWDG_feed();
+		IWDG_feed();
 	}
 }
 

+ 25 - 0
APP/资料/LED和BAT接口.xls

@@ -0,0 +1,25 @@
+	A_LED	B_LED	C_LED	D_LED		GPIO0	PG1
+1	PB4	PC5	PE15	PC1		GPIO1	PB11
+2	PG10	PA3	PE13	PF8		GPIO2	PB12
+3	PG9	PA1	PE11	PF4		GPIO3	PB13
+4	PD6	PC3	PE9	PF0		GPIO4	PB14
+5	PD4	PF10	PE7	PE4		GPIO5	PB15
+6	PD3	PF6	PF15	PE2		GPIO6	PD10
+7	PD1	PF2	PF13	PE0		GPIO7	PD11
+8	PC12	PC14	PF11	PB8		GPIO8	PD12
+9	PC10	PE5	PB1	PB7		GPIO9	PD13
+10	PB5	PB0	PB10	PC2		GPIO10	PD14
+11	PG11	PC4	PE14	PF9		GPIO11	PD15
+12	PB3	PA2	PE12	PF5		GPIO12	PG2
+13	PD7	PA0	PE10	PF1		GPIO13	PG3
+14	PD5	PC0	PE8	PE6		GPIO14	PG4
+15	PD2	PF7	PG0	PE3		GPIO15	PG5
+16	PD0	PF3	PF14	PE1		GPIO16	PG6
+17	PC11	PC15	PF12	PB9		GPIO17	PG7
+18	PA15	PC13	PB2	PB6		GPIO18	PG8
+						GPIO19	PC6
+						GPIO20	PC7
+						GPIO21	PC8
+						GPIO22	PC9
+						GPIO23	PA8
+						EVM_5V0_C	PA12

BIN
APP/资料/实物图.jpg


BIN
APP/资料/接口定义及通讯详情 -用户手册.docx


BIN
APP/资料/接口定义及通讯详情.docx