yf_zjb 5 years ago
parent
commit
ef47c8ff57

+ 1 - 1
Application_BZY/.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-127453641507294465" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="568617710710193311" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>

File diff suppressed because it is too large
+ 57 - 0
Application_CBD/.settings/Application_CBD.Qemu.Debug.rttlaunch


+ 1 - 1
Application_CBD/.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-164989539578436777" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="531081812639050999" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>

+ 1 - 1
Application_CBD/.settings/projcfg.ini

@@ -1,5 +1,5 @@
 #RT-Thread Studio Project Configuration
-#Wed Jun 16 18:20:33 CST 2021
+#Mon Jul 19 16:22:46 CST 2021
 output_project_path=D\:/RT-ThreadStudio/workspace
 mcu_name=STM32F101RETX
 hardware_adapter=ST-LINK

+ 1 - 1
Application_CBD/applications/control.c

@@ -910,7 +910,7 @@ void WorkTast(void)
             if(ctr_clear(1200)==0)
             ctr_TG_Clear(350);
             //清扫失效则使用震动
-            ctr_shake(ON, 100);
+            //ctr_shake(ON, 100);
         }
     }
     if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1||device_status.ds==0)

+ 3 - 3
Application_CBD/applications/control.h

@@ -14,10 +14,10 @@
 
 #include <rtdevice.h>
 
-#define VERSION_HK "1.24.41(HK)"         //版本
-#define VERSION_ZP "1.24.1(ZP)"         //版本
+#define VERSION_HK "1.25.41(HK)"         //版本
+#define VERSION_ZP "1.25.1(ZP)"         //版本
 
-#define CompileTime "20210716"
+#define CompileTime "20210728"
 
 
 /*******************************测试任务****************************************/

+ 2 - 1
Application_CBD/applications/hmi.c

@@ -781,6 +781,7 @@ void Check_ParamConfig(void)
         device_status.dattim = 20;      //数据上传间隔
         device_status.ds = 1;           //设备状态
         device_status.version_type = 4; //版本类型
+        device_status.update_flag = 0;
         ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave));  //
         ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
         ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
@@ -891,7 +892,7 @@ void Check_ParamConfig(void)
         ymodem_ota(1,0);
     }
     else {
-
+        device_status.update_flag = 0;
         //初始化联网状态
         rt_sprintf(device_status.net,"1");
         rt_sprintf(device_status.csq,"0");

+ 1 - 0
Application_CBD/drivers/board.h

@@ -200,6 +200,7 @@ extern "C" {
 /*#define BSP_USING_PWM2*/
 #define BSP_USING_PWM3
 #define BSP_USING_PWM3_CH1
+
 /*-------------------------- PWM CONFIG END --------------------------*/
 
 

+ 1 - 1
Application_CBD/makefile.targets

@@ -4,4 +4,4 @@ clean2:
 	-@echo ' '
 
 
-*.elf: $(wildcard D:/RT-ThreadStudio/workspace/IOT_CBD_BZY_CTRL/Application_CBD/link.lds)
+*.elf: $(wildcard ../link.lds)

+ 5 - 0
Application_CBD/readme.md

@@ -1,3 +1,8 @@
+# 2021-07-28-版本:
+	define VERSION_HK "1.25.41(HK)"         //版本
+	define VERSION_ZP "1.25.1(ZP)"         //版本
+	CompileTime "20210716"
+- 修复新板子刷完程序后因判断升级的字段未初始化导致直接从flash读出来的数值与判断的不一致引起的工作线程未执行.
 # 2021-07-16-版本:
 	define VERSION_HK "1.24.41(HK)"         //版本
 	define VERSION_ZP "1.24.1(ZP)"         //版本

BIN
Application_GK_CBD/.settings/.rtmenus


+ 1 - 1
Application_GK_CBD/.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-139343116707329832" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="556728235510157944" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>

+ 116 - 21
Application_GK_CBD/applications/beep.c

@@ -10,9 +10,13 @@
 #include <rtdevice.h>  //使用 RT-Thread 的设备需要包含此头文件
 #include <beep.h>
 #include <control.h>
+
+Device_Status_typedef device_status;
+
 struct rt_device_pwm    *pwm_device = RT_NULL; //定义 pwm 设备指针
-/*初始化蜂鸣器*/
-int beep_init(void)
+struct rt_device_pwm    *pwm_tim8 = RT_NULL; //定义 pwm 设备指针
+/*初始化pwm3*/
+int pwm3_init(void)
 {
     /*查找PWM设备*/
     pwm_device = (struct rt_device_pwm *)rt_device_find(BEEP_PWM_DEVICE);
@@ -23,18 +27,21 @@ int beep_init(void)
     }
     return 0;
 }
-/*打开蜂鸣器*/
-int beep_on(void)
-{
-    rt_pwm_enable(pwm_device, BEEP_PWM_CH); //使能蜂鸣器对应的 PWM 通道
-    return 0;
-}
-/*关闭蜂鸣器*/
-int beep_off(void)
+
+int pwm8_init(void)
 {
-    rt_pwm_disable(pwm_device, BEEP_PWM_CH); //失能蜂鸣器对应的 PWM 通道
+    pwm_tim8 = (struct rt_device_pwm *)rt_device_find(RAIN_PWM_DEVICE);
+    if(pwm_tim8==RT_NULL)
+    {
+        rt_kprintf("pwm device %s not found!\n", RAIN_PWM_DEVICE);
+        return -RT_ERROR;
+    }
     return 0;
+
 }
+
+
+
 /*在蜂鸣器设定函数里需要设定 蜂鸣器的频率和音量。PWM 设备设定的 API 是设定 周期 和 脉宽 的,
  * 因此我们需要转换一下,将频率装换成周期,将音量大小(占空比)转换成脉宽。这里的周期的单位是 ns,
  * 因此转换成的 秒 之后还要乘以 10^9 。由于无源蜂鸣器一般是低电平触发的,因此音量越大对应的脉宽就要越小。
@@ -45,7 +52,7 @@ void beep_set(uint32_t freq, uint32_t volume)
 {
 
     rt_uint32_t period, pulse;
-    beep_init();
+    pwm3_init();
     /* 将频率转化为周期 周期单位:ns 频率单位:HZ */
     //period = 1000000000 / freq;  //unit:ns 1/HZ*10^9 = ns
     period = freq;    /* 周期为0.5ms,单位为纳秒500000ns-200k */
@@ -53,8 +60,8 @@ void beep_set(uint32_t freq, uint32_t volume)
     pulse = volume;     //5000
 
     /* 利用 PWM API 设定 周期和占空比 */
-    rt_pwm_set(pwm_device, BEEP_PWM_CH, period, pulse);//channel,period,pulse
-    rt_pwm_enable(pwm_device, BEEP_PWM_CH);
+    rt_pwm_set(pwm_device, 1, period, pulse);//channel,period,pulse
+    rt_pwm_enable(pwm_device, 1);
 }
 void Beep_Tip(uint16_t volnum)
 {
@@ -64,16 +71,104 @@ void Beep_Tip(uint16_t volnum)
     rt_pin_write(Beep, 0);
 }
 
+int beep_play(void)
+{
+    pwm3_init();
+    rt_pwm_set(pwm_device, 1, 200000, 100000);//channel,period,pulse
+    rt_pwm_enable(pwm_device, 1);
+    return 0;
+}
+void Motor_Down_PWM_R(uint8_t on_off)
+{
+    pwm3_init();
+    rt_pwm_set(pwm_device, PB0_TIM3_CH, 200000, 100000);//channel,period,pulse
+    if(on_off==ON)
+    {
+        rt_pwm_enable(pwm_device, PB0_TIM3_CH);
+    }
+    else {
+        rt_pwm_disable(pwm_device, PB0_TIM3_CH);
+    }
+}
 
+void Motor_Down_PWM_L(uint8_t on_off)
+{
+    pwm3_init();
+    rt_pwm_set(pwm_device, PB1_TIM3_CH, 200000, 100000);//channel,period,pulse
+    if(on_off==ON)
+    {
+        rt_pwm_enable(pwm_device, PB1_TIM3_CH);
+    }
+    else {
+        rt_pwm_disable(pwm_device, PB1_TIM3_CH);
+    }
+}
 
+void Rain_Motor_PWM_R(uint8_t on_off)
+{
+    pwm8_init();
+    rt_pwm_set(pwm_tim8, PC7_TIM3_CH, 200000, 100000);//channel,period,pulse
+    if(on_off==ON)
+    {
+        rt_pwm_enable(pwm_tim8, PC7_TIM3_CH);
+    }
+    else {
+        rt_pwm_disable(pwm_tim8, PC7_TIM3_CH);
+    }
+}
 
+void Rain_Motor_PWM_L(uint8_t on_off)
+{
+    pwm8_init();
+    rt_pwm_set(pwm_tim8, PC8_TIM3_CH, 200000, 100000);//channel,period,pulse
+    if(on_off==ON)
+    {
+        rt_pwm_enable(pwm_tim8, PC8_TIM3_CH);
+    }
+    else {
+        rt_pwm_disable(pwm_tim8, PC8_TIM3_CH);
+    }
+}
 
+void Motor_UP_PWM_R(uint8_t on_off)
+{
+    rt_uint32_t up_cnt_r = 0;
+    for(;;)
+    {
 
+        if(on_off==ON&&rt_pin_read(CTR_UPO_LIMIT)==1&&up_cnt_r<50000)
+        {
+            rt_pin_write(PC5_PWM,ON);
+            rt_hw_us_delay(100);
+            rt_pin_write(PC5_PWM,OFF);
+            rt_hw_us_delay(100);
+            up_cnt_r++;
+        }
+        else {
+            rt_pin_write(PC5_PWM,OFF);
+            device_status.ctr_up_motor = 0;
+            break;
+        }
+    }
+}
 
-
-
-
-
-
-
-
+void Motor_UP_PWM_L(uint8_t on_off)
+{
+    rt_uint32_t up_cnt_l = 0;
+    for(;;)
+    {
+        if(on_off==ON&&rt_pin_read(CTR_UPC_LIMIT)==1&&up_cnt_l<50000)
+        {
+            rt_pin_write(PC4_PWM,ON);
+            rt_hw_us_delay(100);
+            rt_pin_write(PC4_PWM,OFF);
+            rt_hw_us_delay(100);
+            up_cnt_l++;
+        }
+        else {
+            rt_pin_write(PC4_PWM,OFF);
+            device_status.ctr_up_motor = 0;
+            break;
+        }
+    }
+}

+ 16 - 1
Application_GK_CBD/applications/beep.h

@@ -12,11 +12,26 @@
 
 #include <rtthread.h>
 #define BEEP_PWM_DEVICE "pwm3"
+#define RAIN_PWM_DEVICE "pwm8"
 #define BEEP_PWM_CH 1
 
-int beep_init(void);                            //蜂鸣器初始化
+int pwm3_init(void);
 int beep_on(void);                              //蜂鸣器开
 int beep_off(void);                             //蜂鸣器关
 void beep_set(uint32_t freq, uint32_t volume);    //蜂鸣器设定
 void Beep_Tip(uint16_t volnum);
+int beep_play(void);
+
+void Motor_UP_PWM_R(uint8_t on_off);
+void Motor_UP_PWM_L(uint8_t on_off);
+
+void Motor_Down_PWM_R(uint8_t on_off);
+void Motor_Down_PWM_L(uint8_t on_off);
+
+void Rain_Motor_PWM_R(uint8_t on_off);
+void Rain_Motor_PWM_L(uint8_t on_off);
+
+
+
+
 #endif                                          /* APPLICATIONS_INC_BEEP_H_ */

+ 26 - 52
Application_GK_CBD/applications/control.c

@@ -61,60 +61,48 @@ void ctr_photo(uint8_t status_photo)
 /*采集风机/上仓门*/
 uint8_t ctr_cangmen_up(uint8_t status_up)
 {
-   rt_pin_mode(Collect_fan_R, PIN_MODE_OUTPUT);
-   rt_pin_mode(Collect_fan_L, PIN_MODE_OUTPUT);
+   rt_pin_mode(PC5_PWM, PIN_MODE_OUTPUT);
+   rt_pin_mode(PC4_PWM, PIN_MODE_OUTPUT);
    if(status_up==OFF)
    {
-       rt_pin_write(Collect_fan_R,OFF);
-       rt_pin_write(Collect_fan_L,OFF);
+       Motor_UP_PWM_R(OFF);
+       Motor_UP_PWM_L(OFF);
        device_status.ctr_up_motor = 0;
    }
    if(status_up==OPEN)
    {
        device_status.up_status = 1;
-       rt_pin_write(Collect_fan_R,OFF);
-       rt_pin_write(Collect_fan_L,OFF);
-       rt_pin_write(Collect_fan_R,ON);
-       rt_pin_write(Collect_fan_L,OFF);
+       Motor_UP_PWM_R(ON);
+       Motor_UP_PWM_L(OFF);
    }
    if(status_up==CLOSE)
    {
        device_status.up_status = 0;
-       rt_pin_write(Collect_fan_R,OFF);
-       rt_pin_write(Collect_fan_L,OFF);
-       rt_pin_write(Collect_fan_R,OFF);
-       rt_pin_write(Collect_fan_L,ON);
+       Motor_UP_PWM_R(OFF);
+       Motor_UP_PWM_L(ON);
    }
    return device_status.up_status;
 }
 //下仓门
 uint8_t ctr_cangmen_down(uint8_t status_down)
 {
-    rt_pin_mode(C_DOWN_R, PIN_MODE_OUTPUT);
-    rt_pin_mode(C_DOWN_L, PIN_MODE_OUTPUT);
     if(status_down==OFF)
        {
-           rt_pin_write(C_DOWN_R,OFF);
-           rt_pin_write(C_DOWN_L,OFF);
+           Motor_Down_PWM_L(OFF);
+           Motor_Down_PWM_R(OFF);
            device_status.ctr_down_motor = 0;
        }
        if(status_down==OPEN)
        {
            device_status.down_status = 1;
-           rt_pin_write(C_DOWN_R,OFF);
-           rt_pin_write(C_DOWN_L,OFF);
-           rt_pin_write(C_DOWN_R,ON);
-           rt_pin_write(C_DOWN_L,OFF);
-
+           Motor_Down_PWM_L(OFF);
+           Motor_Down_PWM_R(ON);
        }
        if(status_down==CLOSE)
        {
            device_status.down_status = 0;
-           rt_pin_write(C_DOWN_R,OFF);
-           rt_pin_write(C_DOWN_L,OFF);
-           rt_pin_write(C_DOWN_R,OFF);
-           rt_pin_write(C_DOWN_L,ON);
-
+           Motor_Down_PWM_R(OFF);
+           Motor_Down_PWM_L(ON);
        }
        return device_status.down_status;
 }
@@ -206,22 +194,19 @@ void ctr_rain_Motor(uint8_t r_m_s)
     rt_uint16_t check_rlt = 0;
     rt_pin_mode(CTR_R_LOW, PIN_MODE_OUTPUT);
 
-    rt_pin_mode(CLEAR_R, PIN_MODE_OUTPUT);
-    rt_pin_mode(CLEAR_L, PIN_MODE_OUTPUT);
     //雨控限位
     rt_pin_mode(CTR_RO_LIMIT,PIN_MODE_INPUT);
     rt_pin_mode(CTR_RC_LIMIT,PIN_MODE_INPUT);
     rt_pin_write(CTR_R_LOW,OFF);
-    rt_pin_write(CLEAR_R,OFF);
-    rt_pin_write(CLEAR_L,OFF);
+
     if(r_m_s==OPEN)
     {
         device_status.clear_status = 1; /*落虫*/
         if(rt_pin_read(CTR_RO_LIMIT)==0)
             rt_thread_delay(100);
         if(rt_pin_read(CTR_RO_LIMIT)==0) return;
-        rt_pin_write(CLEAR_R,OFF);
-        rt_pin_write(CLEAR_L,ON);
+        Rain_Motor_PWM_R(OFF);
+        Rain_Motor_PWM_L(ON);
         while(rt_pin_read(CTR_RO_LIMIT)!=0)
         {
             check_rlt++;
@@ -231,8 +216,8 @@ void ctr_rain_Motor(uint8_t r_m_s)
                 break;
             }
         }
-        rt_pin_write(CLEAR_R,OFF);
-        rt_pin_write(CLEAR_L,OFF);
+        Rain_Motor_PWM_R(OFF);
+        Rain_Motor_PWM_L(OFF);
         check_rlt = 0;
     }
     else if (r_m_s==CLOSE) {
@@ -240,8 +225,8 @@ void ctr_rain_Motor(uint8_t r_m_s)
         if(rt_pin_read(CTR_RC_LIMIT)==0)
             rt_thread_delay(100);
         if(rt_pin_read(CTR_RC_LIMIT)==0) return;
-        rt_pin_write(CLEAR_R,ON);
-        rt_pin_write(CLEAR_L,OFF);
+        Rain_Motor_PWM_R(ON);
+        Rain_Motor_PWM_L(OFF);
         while(rt_pin_read(CTR_RC_LIMIT)!=0)
         {
             check_rlt++;
@@ -252,12 +237,12 @@ void ctr_rain_Motor(uint8_t r_m_s)
             }
         }
         check_rlt = 0;
-        rt_pin_write(CLEAR_R,OFF);
-        rt_pin_write(CLEAR_L,OFF);
+        Rain_Motor_PWM_R(OFF);
+        Rain_Motor_PWM_L(OFF);
     }
     else {
-        rt_pin_write(CLEAR_R,OFF);
-        rt_pin_write(CLEAR_L,OFF);
+        Rain_Motor_PWM_R(OFF);
+        Rain_Motor_PWM_L(OFF);
     }
 }
 //清扫-常闭型限位开关
@@ -523,34 +508,23 @@ void calorstat(uint16_t heat_time)
 void HardWare_Init(uint8_t boot)
 {
     Beep_Tip(200);
-
     //雨控电机归位
-    ctr_rain_Motor(OFF);
+    ctr_rain_Motor(OPEN);
     //关闭上仓门
     ctr_cangmen_up(OFF);
-
     //关闭下仓门电机
     ctr_cangmen_down(OFF);
-
     //关闭镇流器
     ctr_lamp(OFF);
-
     //关闭震动电机
     ctr_shake(OFF,0);
-
     //关闭清扫电机
-
     //关闭加热
     ctr_Heat(OFF);
-
     //关闭补光灯
     ctr_led(OFF);
-
-
     //关闭12V供电(海康相机,RTU)
     ctr_photo(OFF);
-
-
 }
 //拍照
 void HK_TakePhoto(void)

+ 15 - 2
Application_GK_CBD/applications/control.h

@@ -17,7 +17,7 @@
 #define VERSION_ZP "1.14.1(ZP)"         //版本
 #define VERSION "1.0.3(GK)"
 
-#define CompileTime "20210708"
+#define CompileTime "20210728"
 
 /*******************************测试任务****************************************/
 /*********************************************************************/
@@ -101,6 +101,19 @@ typedef struct{
 #define Beep    GET_PIN(B, 4)
 #define OPEN 0x02
 #define CLOSE 0x03
+/*************************************************/
+
+#define PB0_TIM3_CH  3
+#define PB1_TIM3_CH  4
+
+#define PC4_PWM GET_PIN(C,4)
+#define PC5_PWM GET_PIN(C,5)
+
+
+
+#define PC7_TIM3_CH 2
+#define PC8_TIM3_CH 3
+
 /************************************************/
 //光控
 #define LIGHT_PIN GET_PIN(C,0)
@@ -172,7 +185,7 @@ void HardWare_Check(uint8_t boot);              //自检
 void ResetInit(void);                           //上电复位
 void SunTest(void);                             //光控测试
 /*****************************************************/
-
+int Motor_pwm_init(void);
 /****************************************************/
 void WorkCheck(void);               //工作检测
 void WorkTast(void);                //工作任务

+ 3 - 0
Application_GK_CBD/applications/dtu_uart2.c

@@ -395,6 +395,9 @@ char * makeJson()
     {
         rt_sprintf(device_status.driver,"%s-%s",VERSION_ZP,device_status.driver_4g);
     }
+    else if (device_status.version_type==3) {
+        rt_sprintf(device_status.driver,"%s-%s",VERSION,device_status.driver_4g);
+    }
     else if (device_status.version_type==4) {
         rt_sprintf(device_status.driver,"%s-%s",VERSION_HK,device_status.driver_4g);
     }

+ 37 - 67
Application_GK_CBD/applications/hmi.c

@@ -582,10 +582,8 @@ static void HMI_Decode(char *cmd,uint8_t cmd_len)
 static void Ctr_Mortor_entry(void* parameter)
 {
    rt_uint32_t limit_current = 2000;     //推杆电机限制电流1A
-   static rt_uint16_t num_up_open = 800;    //20s
-   static rt_uint16_t num_up_close = 800;   //
-   static rt_uint16_t num_down_open = 800;  //
-   static rt_uint16_t num_down_close = 800;  //
+   static rt_uint16_t num_down_open = 500;  //
+   static rt_uint16_t num_down_close = 500;  //
    static rt_uint16_t photo_led_sec = 300;  //45S
    //上限位
    rt_pin_mode(CTR_UPO_LIMIT,PIN_MODE_INPUT);
@@ -606,19 +604,12 @@ static void Ctr_Mortor_entry(void* parameter)
             else {
                 ctr_cangmen_up(OFF);
             }
-            num_up_open--;
             //如果未工作且上仓门电机电流大于1A,立即停止,记录到Flash,上报预警
             if(atoi(device_status.power)>limit_current)
             {
                 ctr_cangmen_up(OFF);
-                num_up_open = 1000;
                 rt_kprintf("*************************上仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
             }
-            if (num_up_open == 0)
-            {
-                ctr_cangmen_up(OFF);
-                num_up_open = 1000;
-            }
         }
         else if(device_status.ctr_up_motor==2)
         {
@@ -629,19 +620,12 @@ static void Ctr_Mortor_entry(void* parameter)
             else {
                 ctr_cangmen_up(OFF);
             }
-            num_up_close --;
             if(atoi(device_status.power)>limit_current)
             {
                 ctr_cangmen_up(OFF);
-                num_up_close = 200;
                 rt_kprintf("************************上仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
             }
 
-            if (num_up_close == 0)
-            {
-                ctr_cangmen_up(OFF);
-                num_up_close= 200;
-            }
         }
         if (device_status.ctr_down_motor == 1)
         {
@@ -656,13 +640,13 @@ static void Ctr_Mortor_entry(void* parameter)
             if(atoi(device_status.power)>limit_current)
             {
                 ctr_cangmen_down(OFF);
-                num_down_open = 200;
+                num_down_open = 500;
                 rt_kprintf("*************************下仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
             }
             if (num_down_open == 0)
             {
                 ctr_cangmen_down(OFF);
-                num_down_open = 200;
+                num_down_open = 500;
             }
         }
         else if (device_status.ctr_down_motor == 2)
@@ -678,21 +662,15 @@ static void Ctr_Mortor_entry(void* parameter)
             if(atoi(device_status.power)>limit_current)
             {
                 ctr_cangmen_down(OFF);
-                num_down_close = 200;
+                num_down_close = 500;
                 rt_kprintf("*************************下仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
             }
             if (num_down_close == 0)
             {
                ctr_cangmen_down(OFF);
-               num_down_close = 200;
+               num_down_close = 500;
             }
         }
-        if(device_status.clear_status==1)
-        {
-            device_status.clear_status = 0;
-            if(ctr_clear(650)==0)
-            ctr_TG_Clear(250);
-        }
         if(device_status.sun_test==1)
         {
             SunTest();
@@ -875,16 +853,9 @@ void Check_ParamConfig(void)
         if(device_status.version_type==0)
         {
             app_partion_backup();   //固件备份至df_area
-            device_status.version_type = 4;
+            device_status.version_type = 3;
             ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
         }
-        if(device_status.version_type==1)
-        {
-            rt_sprintf(device_status.driver, "%s",VERSION_ZP);
-        }
-        else if (device_status.version_type==4) {
-            rt_sprintf(device_status.driver, "%s",VERSION_HK);
-        }
         device_status.version_type=3;
         device_status.ds=1;
         rt_sprintf(device_status.driver, "GK3.0");
@@ -916,40 +887,39 @@ void Check_ParamConfig(void)
         ymodem_ota(1,0);
     }
     else {
-
+        device_status.update_flag = 0;
         //初始化联网状态
-//        rt_sprintf(device_status.net,"1");
-//        rt_sprintf(device_status.csq,"0");
-//        rt_sprintf(device_status.sim,"1");
-
-//        uint16_t connect_num=0;
+        rt_sprintf(device_status.net,"1");
+        rt_sprintf(device_status.csq,"0");
+        rt_sprintf(device_status.sim,"1");
+        ctr_router(ON);
+        Hmi_Fresh();
+        dtu_data_play();
+        sht30_collect();
+        mb_master_samlpe();
+        uint16_t connect_num=0;
         //等待联网,
-//        while(atoi(device_status.net)==1)
-//        {
-//            char *readinfo =  makeJson_ReadInfo();
-//            DTU_Write("%s",readinfo);
-//            rt_free(readinfo);
-//            rt_thread_delay(1000);
-//            connect_num++;
-//            rt_kprintf("联网中......%d\n",connect_num);
-//            //超时时间为3分钟
-//            if(connect_num==60)
-//            {
-//                device_status.timeSwitch = 0;
-//                //保存光控变量
-//                ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
-//                rt_kprintf("Time not set:%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
-//                set_date(2020, 1, 1);
-//                set_time(0, 0, 0);
-//                break;
-//            }
-//            if(tm.tm_year>=2021)
-//            break;
-//        }
-        if(tm.tm_year+1900<2021)
+        while(atoi(device_status.net)==1)
         {
-            set_date(2021, 1, 1);
-            set_time(0, 0, 0);
+            char *readinfo =  makeJson_ReadInfo();
+            DTU_Write("%s",readinfo);
+            rt_free(readinfo);
+            rt_thread_delay(1000);
+            connect_num++;
+            rt_kprintf("联网中......%d\n",connect_num);
+            //超时时间为3分钟
+            if(connect_num==30)
+            {
+                device_status.timeSwitch = 0;
+                //保存光控变量
+                ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
+                rt_kprintf("Time not set:%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
+                set_date(2021, 1, 1);
+                set_time(0, 0, 0);
+                break;
+            }
+            if(tm.tm_year>=2021)
+            break;
         }
         DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
     }

+ 8 - 7
Application_GK_CBD/applications/main.c

@@ -39,6 +39,7 @@ static void idle_hook(void);
 /********************************************************************/
 int main(void)
 {
+
     /* 初始化设备 */
     rt_device_init(wdg_dev);
     led_add_device(LED0_PIN);
@@ -57,19 +58,21 @@ int main(void)
     //是否触发固件更新
     if(device_status.update_flag==0)
     {
-
+        //屏幕初始化
+        //Hmi_Fresh();
+        //传感器数据采集线程
+        //sht30_collect();
+        //mb_master_samlpe();
         //开机自检
         HardWare_Check(0);
-        Hmi_Fresh();        //屏幕初始化
-        dtu_data_play();
-        sht30_collect();    //传感器数据采集线程
-        mb_master_samlpe();
         //工作状态置位线程
         Workstatus_check();
         /***************/
         //工作流程
         Work_Loop_Task();
         /*******************/
+        //数据透传
+        //dtu_data_play();
     }
     //看门狗初始化
      wdt_init();
@@ -117,8 +120,6 @@ static void idle_hook(void)
     alarm_new =*localtime(&now);
     if((alarm_new.tm_hour)==9&&(alarm_new.tm_min==0)&&(alarm_new.tm_sec==0))
     {
-        ctr_RTU_DTU(OFF);
-        rt_thread_delay(2000);
         rt_hw_cpu_reset();
     }
 //    else {

+ 1 - 1
Application_GK_CBD/applications/sht30_collect.c

@@ -243,7 +243,7 @@ int Read_Real_Voltage(void)
     adc0_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_0);
     /* 关闭通道 */
     rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_0);
-    return  (adc0_value * REFER_VOLTAGE/CONVERT_BITS*12+20);
+    return  (adc0_value * REFER_VOLTAGE/CONVERT_BITS*12);
 }
 /*读取保险丝的电压值*/
 int Read_Fuse_Voltage(void)

+ 128 - 11
Application_GK_CBD/drivers/board.c

@@ -16,6 +16,7 @@
 #define DBG_LVL DBG_INFO
 #include <rtdbg.h>
 TIM_HandleTypeDef htim3;
+TIM_HandleTypeDef htim8;
 ADC_HandleTypeDef hadc1;
 SPI_HandleTypeDef hspi1;
 void SystemClock_Config(void)
@@ -80,7 +81,10 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
 
   /* USER CODE END TIM3_MspInit 1 */
   }
-
+  else if (htim_base->Instance==TIM8)
+  {
+     __HAL_RCC_TIM8_CLK_ENABLE();
+  }
 }
 void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
 {
@@ -91,29 +95,55 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
   /* USER CODE BEGIN TIM3_MspPostInit 0 */
 
   /* USER CODE END TIM3_MspPostInit 0 */
-
-    __HAL_RCC_GPIOC_CLK_ENABLE();
+    __HAL_RCC_GPIOB_CLK_ENABLE();
     /**TIM3 GPIO Configuration
-    PC6     ------> TIM3_CH1
+    PB0     ------> TIM3_CH3
+    PB1     ------> TIM3_CH4
+    PB4     ------> TIM3_CH1
     */
-    GPIO_InitStruct.Pin = GPIO_PIN_6;
+    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
-    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
-    __HAL_AFIO_REMAP_TIM3_ENABLE();
+    __HAL_AFIO_REMAP_TIM3_PARTIAL();
 
   /* USER CODE BEGIN TIM3_MspPostInit 1 */
 
   /* USER CODE END TIM3_MspPostInit 1 */
   }
+  else if(htim->Instance==TIM8)
+  {
+  /* USER CODE BEGIN TIM8_MspPostInit 0 */
+
+  /* USER CODE END TIM8_MspPostInit 0 */
+
+    __HAL_RCC_GPIOC_CLK_ENABLE();
+    /**TIM8 GPIO Configuration
+    PC7     ------> TIM8_CH2
+    PC8     ------> TIM8_CH3
+    */
+    GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+  /* USER CODE BEGIN TIM8_MspPostInit 1 */
+
+  /* USER CODE END TIM8_MspPostInit 1 */
+  }
 
 }
+/**
+  * @brief TIM3 Initialization Function
+  * @param None
+  * @retval None
+  */
 static void MX_TIM3_Init(void)
 {
 
   /* USER CODE BEGIN TIM3_Init 0 */
-
+    HAL_TIM_Base_MspInit(&htim3);
   /* USER CODE END TIM3_Init 0 */
 
   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
@@ -124,9 +154,9 @@ static void MX_TIM3_Init(void)
 
   /* USER CODE END TIM3_Init 1 */
   htim3.Instance = TIM3;
-  htim3.Init.Prescaler = 72-1;
+  htim3.Init.Prescaler = 72;
   htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
-  htim3.Init.Period = 500-1;
+  htim3.Init.Period = 1000;
   htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
   htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
   if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
@@ -149,19 +179,105 @@ static void MX_TIM3_Init(void)
     Error_Handler();
   }
   sConfigOC.OCMode = TIM_OCMODE_PWM1;
-  sConfigOC.Pulse = 0;
+  sConfigOC.Pulse = 100;
   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
   if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
   {
     Error_Handler();
   }
+  if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
+  {
+    Error_Handler();
+  }
   /* USER CODE BEGIN TIM3_Init 2 */
 
   /* USER CODE END TIM3_Init 2 */
   HAL_TIM_MspPostInit(&htim3);
 
 }
+/**
+  * @brief TIM8 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_TIM8_Init(void)
+{
+
+  /* USER CODE BEGIN TIM8_Init 0 */
+
+  /* USER CODE END TIM8_Init 0 */
+
+  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+  TIM_MasterConfigTypeDef sMasterConfig = {0};
+  TIM_OC_InitTypeDef sConfigOC = {0};
+  TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
+
+  /* USER CODE BEGIN TIM8_Init 1 */
+
+  /* USER CODE END TIM8_Init 1 */
+  htim8.Instance = TIM8;
+  htim8.Init.Prescaler = 72;
+  htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
+  htim8.Init.Period = 1000;
+  htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+  htim8.Init.RepetitionCounter = 0;
+  htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
+  if (HAL_TIM_Base_Init(&htim8) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+  if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_TIM_PWM_Init(&htim8) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
+  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
+  if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sConfigOC.OCMode = TIM_OCMODE_PWM1;
+  sConfigOC.Pulse = 100;
+  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
+  sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
+  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
+  sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
+  sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
+  if (HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
+  sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
+  sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
+  sBreakDeadTimeConfig.DeadTime = 0;
+  sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
+  sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
+  sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
+  if (HAL_TIMEx_ConfigBreakDeadTime(&htim8, &sBreakDeadTimeConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN TIM8_Init 2 */
+
+  /* USER CODE END TIM8_Init 2 */
+  HAL_TIM_MspPostInit(&htim8);
+
+}
 
 /**
 * @brief ADC MSP Initialization
@@ -272,6 +388,7 @@ static int SPI1_INIT(void)
 static int PWM3_INIT(void)
 {
     MX_TIM3_Init();
+    MX_TIM8_Init();
     return RT_EOK;
 }
 /**

+ 11 - 0
Application_GK_CBD/drivers/board.h

@@ -19,6 +19,11 @@
 extern "C" {
 #endif
 #define RT_APP_PART_ADDR  0x8032000
+
+#define CHIP_FAMILY_STM32
+#define CHIP_SERIES_STM32F1
+#define CHIP_NAME_STM32F103RE
+
 /*-------------------------- UART CONFIG BEGIN --------------------------*/
 
 /** After configuring corresponding UART or UART DMA, you can use it.
@@ -200,6 +205,11 @@ extern "C" {
 /*#define BSP_USING_PWM2*/
 #define BSP_USING_PWM3
 #define BSP_USING_PWM3_CH1
+#define BSP_USING_PWM3_CH3
+#define BSP_USING_PWM3_CH4
+#define BSP_USING_PWM8
+#define BSP_USING_PWM8_CH2
+#define BSP_USING_PWM8_CH3
 /*-------------------------- PWM CONFIG END --------------------------*/
 
 
@@ -262,6 +272,7 @@ extern "C" {
 /*#define BSP_USING_TIM*/
 #ifdef BSP_USING_TIM
 #define BSP_USING_TIM3
+#define BSP_USING_TIM8
 /*#define BSP_USING_TIM15*/
 /*#define BSP_USING_TIM16*/
 /*#define BSP_USING_TIM17*/

+ 11 - 0
Application_GK_CBD/drivers/include/config/pwm_config.h

@@ -61,6 +61,17 @@ extern "C" {
 #endif /* PWM5_CONFIG */
 #endif /* BSP_USING_PWM5 */
 
+#ifdef BSP_USING_PWM8
+#ifndef PWM8_CONFIG
+#define PWM8_CONFIG                             \
+    {                                           \
+       .tim_handle.Instance     = TIM8,         \
+       .name                    = "pwm8",       \
+       .channel                 = 0             \
+    }
+#endif /* PWM8_CONFIG */
+#endif /* BSP_USING_PWM5 */
+
 #ifdef __cplusplus
 }
 #endif

+ 1 - 1
Application_GK_CBD/makefile.targets

@@ -4,4 +4,4 @@ clean2:
 	-@echo ' '
 
 
-*.elf: $(wildcard D:/RT-ThreadStudio/workspace/IOT_CBD_BZY_CTRL/Application_GK_CBD/link.lds)
+*.elf: $(wildcard ../link.lds)

+ 3 - 2
Application_GK_CBD/readme.md

@@ -1,5 +1,6 @@
-
-
+## 2021-07-28-版本:1.0.3(GK)
+###版本更新:
+- 电机驱动PWM
 
 # 版本说明
 #define VERSION_HK "1.1.4-(HK)"         //版本

+ 1 - 1
Application_GK_CBD/rtconfig.h

@@ -278,6 +278,6 @@
 /* end of samples: kernel and components samples */
 #define SOC_FAMILY_STM32
 #define SOC_SERIES_STM32F1
-#define SOC_STM32F101RETX
+#define SOC_STM32F103RETX
 
 #endif

+ 1 - 1
Application_GK_CBD/rtconfig_preinc.h

@@ -7,7 +7,7 @@
 
 #define HAVE_CCONFIG_H
 #define RT_USING_NEWLIB
-#define STM32F101xE
+#define STM32F103xE
 #define USE_HAL_DRIVER
 
 #endif /*RTCONFIG_PREINC_H__*/

+ 1 - 1
CBD_FOTA_BootLoader/.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-168307560337915404" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="527763791879572372" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>