zhunk 3 months ago
parent
commit
cd71d4bcc4

+ 8 - 0
Application_cbd_apm32f1/applications/main.c

@@ -27,6 +27,14 @@ int clock_information(void);
 
 int main(void)
 {
+    __HAL_RCC_PWR_CLK_ENABLE();
+    __HAL_RCC_BKP_CLK_ENABLE();
+    HAL_PWR_EnableBkUpAccess();
+    uint16_t boot_flag = *(__IO uint16_t *)(BKP_BASE + 4 * 2);  /* RTC_BKP_DR2, 16-bit */
+    //打印boot_flag的值
+    LOG_I("boot_flag:0x%04x\n",boot_flag);
+    /* 清除 bootloader 的启动标志,表示 app 启动成功 */
+    *(__IO uint16_t *)(0x40006C00 + 4 * 2) = 0x0000;
     CompileTime;      //读取固件的编译时间
     led_add_device(LED0_PIN);
     led_set_level(1,0);

+ 1 - 0
Application_cbd_apm32f1/readme.md

@@ -1,6 +1,7 @@
 # 2026-07-28
 	#define VERSION_HK_2000W    "2.42.4(jjk)"           //经济款
 	1、适配DAM0808D数采控制器、用于3路球阀控制,替换上下仓门,增加雨控电机;
+	2、通过ctr_cold()控制模块的供电;
 # 2026-07-13
 	#define VERSION_HK_2000W    "2.41.4(2000W)"         //4.0水稻
 	1、easyflash配置ENV_AREA_SIZE 调整为4096*256

File diff suppressed because it is too large
+ 815 - 73
CBD_FOTA_BootLoader/.config


File diff suppressed because it is too large
+ 816 - 74
CBD_FOTA_BootLoader/.config.old


File diff suppressed because it is too large
+ 239 - 239
CBD_FOTA_BootLoader/.cproject


BIN
CBD_FOTA_BootLoader/.settings/.rtmenus


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

@@ -1,5 +1,5 @@
 #RT-Thread Studio Project Configuration
-#Mon Apr 21 16:30:36 CST 2025
+#Wed Feb 12 12:00:09 CST 2025
 project_type=rtt
 chip_name=STM32F103RE
 cpu_name=None

+ 6 - 1
CBD_FOTA_BootLoader/Kconfig

@@ -15,6 +15,11 @@ config PKGS_DIR
     option env="PKGS_ROOT"
     default "packages"
 
+config PLATFORM_DIR
+    string
+    option env="PLATFORM_DIR"
+    default "D:/RT-ThreadStudio/workspace/IOT_CBD_BZY_CTRL/CBD_FOTA_BootLoader/platform"
+
 source "$RTT_DIR/Kconfig"
 source "$PKGS_DIR/Kconfig"
 source "$PKGS_DIR/packages/misc/samples/Kconfig"
@@ -24,4 +29,4 @@ config RT_STUDIO_BUILT_IN
     select ARCH_ARM_CORTEX_M3
     select RT_USING_COMPONENTS_INIT
     select RT_USING_USER_MAIN
-    default y
+    default y

+ 41 - 3
CBD_FOTA_BootLoader/applications/main.c

@@ -33,8 +33,8 @@
 #include "sys_config.h"
 #include <easyflash.h>
 
-#define BL_VERSION RT_FOTA_SW_VERSION
-#define COMPILE "20260714"
+#define BL_VERSION "1.1.4"
+#define COMPILE "20230901"
 
 #define RTU_DTU GET_PIN(B,13)
 #define Beep    GET_PIN(B, 4)
@@ -346,6 +346,43 @@ static void Hmi_thread_entry(void *parameter)
         //rt_kprintf("workSta.vbat.txt=%c%d.%02d%c\n",hmi_str,voltage/100,voltage%100,hmi_str);
     }
 }
+
+/* 获取STM32F401的复位原因 */
+static void print_reset_reason(void)
+{
+    uint32_t rst_status = RCC->CSR;
+    bool is_iwdg = false;
+
+    rt_kprintf("\n========== Reset Reason ==========\n");
+
+    if (rst_status & RCC_CSR_LPWRRSTF)
+        rt_kprintf("❌ Low Power reset\n");
+
+    if (rst_status & RCC_CSR_WWDGRSTF)
+        rt_kprintf("❌ Window Watchdog reset\n");
+
+    if (rst_status & RCC_CSR_IWDGRSTF)
+    {
+        rt_kprintf("❌ Independent Watchdog reset\n");
+        is_iwdg = true;
+    }
+
+    if (rst_status & RCC_CSR_SFTRSTF)
+        rt_kprintf("✅ Software reset\n");
+
+    if (rst_status & RCC_CSR_PORRSTF)
+        rt_kprintf("✅ Power-on reset\n");
+
+    if (rst_status & RCC_CSR_PINRSTF)
+        rt_kprintf("✅ NRST pin reset\n");
+
+    rt_kprintf("RCC_CSR: 0x%08X\n", rst_status);
+    rt_kprintf("==================================\n");
+
+    /* 清除复位标志(重要!)*/
+    RCC->CSR |= RCC_CSR_RMVF;
+}
+
 int main(void)
 {
 
@@ -353,8 +390,9 @@ int main(void)
     finsh_set_prompt("rt-fota />");
 #endif
     extern void rt_fota_init(void);
-    easyflash_init();
     rt_fota_print_log();
+    easyflash_init();
+    print_reset_reason();
     rt_fota_init();
     HMI_Thread();
     Beep_Tip(100);

File diff suppressed because it is too large
+ 1198 - 930
CBD_FOTA_BootLoader/applications/rt_fota.c


+ 1 - 1
CBD_FOTA_BootLoader/applications/sys_config.h

@@ -5,7 +5,7 @@
 
 
 /* RT-FOTA module define */
-#define RT_FOTA_SW_VERSION      "1.2.5"
+#define RT_FOTA_SW_VERSION      "1.2.4"
 
 /* Enable Ymodem OTA */
 #define PKG_USING_YMODEM_OTA

+ 1 - 1
CBD_FOTA_BootLoader/drivers/board.h

@@ -36,7 +36,7 @@ extern "C"
 #define ROM_END                ((uint32_t)(ROM_START + ROM_SIZE * 1024))
 
 #define RAM_START              (0x20000000)
-#define RAM_SIZE               (64)
+#define RAM_SIZE               (128)
 #define RAM_END                (RAM_START + RAM_SIZE * 1024)
 
 /*-------------------------- ROM/RAM CONFIG END --------------------------*/

+ 1 - 4
CBD_FOTA_BootLoader/drivers/drv_flash_f1.c

@@ -20,7 +20,7 @@
 #include "fal.h"
 #endif
 
-#define DRV_DEBUG
+//#define DRV_DEBUG
 #define LOG_TAG                "drv.flash"
 #include <drv_log.h>
 
@@ -91,7 +91,6 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
         LOG_E("write outrange flash size! addr is (0x%p)", (void *)(addr + size));
         return -RT_EINVAL;
     }
-    //LOG_D("stm32_flash_write:(0x%p)",addr);
     //APM32此处关闭中断
     __disable_irq();
     HAL_FLASH_Unlock();
@@ -103,7 +102,6 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
             if (*(rt_uint32_t *)addr != *(rt_uint32_t *)buf)
             {
                 result = -RT_ERROR;
-                LOG_D("addr ERROR!");
                 break;
             }
             addr += 4;
@@ -111,7 +109,6 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
         }
         else
         {
-            LOG_E("HAL_FLASH_Program ERROR at:(0x%p)!",addr);
             result = -RT_ERROR;
             break;
         }

+ 1 - 1
CBD_FOTA_BootLoader/drivers/fal_cfg.h

@@ -46,7 +46,7 @@ extern struct fal_flash_dev nor_flash0;
 {                                                                                    \
     {FAL_PART_MAGIC_WORD,        "bl",     "onchip_flash",                           0,                       200*1024,       0}, \
     {FAL_PART_MAGIC_WORD,        "app",     "onchip_flash",                          200*1024,                312*1024,       0}, \
-    {FAL_PART_MAGIC_WORD, "easyflash",     FAL_USING_NOR_FLASH_DEV_NAME,             0,                       3*1024*1024,   0}, \
+    {FAL_PART_MAGIC_WORD, "easyflash",     FAL_USING_NOR_FLASH_DEV_NAME,             0,                       1*1024*1024,   0}, \
     {FAL_PART_MAGIC_WORD,  "fm_area",     FAL_USING_NOR_FLASH_DEV_NAME,             3*1024*1024,             512*1024,      0}, \
     {FAL_PART_MAGIC_WORD,  "df_area",     FAL_USING_NOR_FLASH_DEV_NAME,             3*1024*1024 + 512*1024,  512*1024,      0}, \
 }

+ 1 - 1
CBD_FOTA_BootLoader/libraries/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h

@@ -140,7 +140,7 @@ typedef struct
   */
 #define FLASH_LATENCY_0            0x00000000U               /*!< FLASH Zero Latency cycle */
 #define FLASH_LATENCY_1            FLASH_ACR_LATENCY_0       /*!< FLASH One Latency cycle */
-#define FLASH_LATENCY_2            FLASH_ACR_LATENCY_2       /*!< FLASH Two Latency cycles */
+#define FLASH_LATENCY_2            FLASH_ACR_LATENCY_1       /*!< FLASH Two Latency cycles */
 
 /**
   * @}

+ 1 - 1
CBD_FOTA_BootLoader/packages/fal-v0.5.0/src/fal_partition.c

@@ -434,7 +434,7 @@ int fal_partition_write(const struct fal_partition *part, uint32_t addr, const u
     ret = flash_dev->ops.write(part->offset + addr, buf, size);
     if (ret < 0)
     {
-        log_e("Partition write error! Flash device(%s) write error:%d!", part->flash_name,ret);
+        log_e("Partition write error! Flash device(%s) write error!", part->flash_name);
     }
 
     return ret;

+ 1 - 1
CBD_FOTA_BootLoader/packages/ota_downloader-latest/src/ymodem_ota.c

@@ -112,7 +112,7 @@ void ymodem_ota(uint8_t argc, char **argv)
 
     rt_kprintf("Warning: Ymodem has started! This operator will not recovery.\n");
     rt_kprintf("Please select the ota firmware file and use Ymodem to send.\n");
-    //rt_console_set_device("uart2");
+    rt_console_set_device("uart2");
     if (!rym_recv_on_device(&rctx, rt_console_get_device(), RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
                             ymodem_on_begin, ymodem_on_data, NULL, RT_TICK_PER_SECOND))
     {

+ 6 - 9
CBD_FOTA_BootLoader/readme.md

@@ -1,13 +1,10 @@
 # 版本说明 20260714
-	#define BL_VERSION "1.2.5"
-	#define COMPILE "20260714"
-	1. easyflash分区大小调整;
-	2. 打印版本;
-# 版本说明
-#define BL_VERSION "1.1.5"
-#define COMPILE "20250421"
-- 1. 修复app升级报错:
-	rt_fota.c  #define RT_FOTA_ALGO_BUFF_SIZE				4096 改为2048
+	#define BL_VERSION "1.2.4"
+	1、修复flash读取慢引发的升级搬运固件过程复位,复位原因是看门狗复位;
+	2、easyflash分区调整;
+	3、看门狗超时时间由10S改为25S;
+	4、已经找到问题原因了,帮我修复flash读取慢导致固件搬运过程 flash读写阻塞cpu导致 不能及时喂狗引起看门狗重启,搬运前把app分区固件先备份到df_area,如果往app分区搬运过程中异常中断会导致启动失败这时从df_area分区恢复
+	5、使用rtc的bkp寄存器存放app是否正常启动的标志位,启动app失败会触发固件恢复上一个版本;
 # 版本说明
 #define BL_VERSION "1.1.4"
 #define COMPILE "20230901"

BIN
CBD_FOTA_BootLoader/rt-thread/tools/building.pyc


BIN
CBD_FOTA_BootLoader/rt-thread/tools/eclipse.pyc


BIN
CBD_FOTA_BootLoader/rt-thread/tools/menuconfig.pyc


BIN
CBD_FOTA_BootLoader/rt-thread/tools/mkdist.pyc


BIN
CBD_FOTA_BootLoader/rt-thread/tools/utils.pyc


+ 161 - 10
CBD_FOTA_BootLoader/rtconfig.h

@@ -158,6 +158,18 @@
 /* Wiced WiFi */
 
 /* end of Wiced WiFi */
+
+/* CYW43012 WiFi */
+
+/* end of CYW43012 WiFi */
+
+/* BL808 WiFi */
+
+/* end of BL808 WiFi */
+
+/* CYW43439 WiFi */
+
+/* end of CYW43439 WiFi */
 /* end of Wi-Fi */
 
 /* IoT Cloud */
@@ -183,10 +195,24 @@
 
 /* language packages */
 
+/* JSON: JavaScript Object Notation, a lightweight data-interchange format */
+
+/* end of JSON: JavaScript Object Notation, a lightweight data-interchange format */
+
+/* XML: Extensible Markup Language */
+
+/* end of XML: Extensible Markup Language */
 /* end of language packages */
 
 /* multimedia packages */
 
+/* LVGL: powerful and easy-to-use embedded GUI library */
+
+/* end of LVGL: powerful and easy-to-use embedded GUI library */
+
+/* u8g2: a monochrome graphic library */
+
+/* end of u8g2: a monochrome graphic library */
 /* end of multimedia packages */
 
 /* tools packages */
@@ -203,6 +229,21 @@
 
 /* system packages */
 
+/* enhanced kernel services */
+
+/* end of enhanced kernel services */
+
+/* acceleration: Assembly language or algorithmic acceleration packages */
+
+/* end of acceleration: Assembly language or algorithmic acceleration packages */
+
+/* CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */
+
+/* end of CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */
+
+/* Micrium: Micrium software products porting for RT-Thread */
+
+/* end of Micrium: Micrium software products porting for RT-Thread */
 #define PKG_USING_FAL
 #define FAL_DEBUG_CONFIG
 #define FAL_DEBUG 1
@@ -221,16 +262,74 @@
 #define SYSWATCH_THREAD_STK_SIZE 512
 #define SYSWATCH_THREAD_NAME "syswatch"
 #define SYSWATCH_WDT_NAME "wdt"
-#define SYSWATCH_WDT_TIMEOUT 10
+#define SYSWATCH_WDT_TIMEOUT 25
 #define PKG_USING_SYSWATCH_LATEST_VERSION
-
-/* Micrium: Micrium software products porting for RT-Thread */
-
-/* end of Micrium: Micrium software products porting for RT-Thread */
 /* end of system packages */
 
 /* peripheral libraries and drivers */
 
+/* HAL & SDK Drivers */
+
+/* STM32 HAL & SDK Drivers */
+
+/* end of STM32 HAL & SDK Drivers */
+
+/* Infineon HAL Packages */
+
+/* end of Infineon HAL Packages */
+
+/* Kendryte SDK */
+
+/* end of Kendryte SDK */
+
+/* MM32 HAL & SDK Drivers */
+
+/* end of MM32 HAL & SDK Drivers */
+
+/* WCH HAL & SDK Drivers */
+
+/* end of WCH HAL & SDK Drivers */
+
+/* AT32 HAL & SDK Drivers */
+
+/* end of AT32 HAL & SDK Drivers */
+
+/* HC32 DDL Drivers */
+
+/* end of HC32 DDL Drivers */
+
+/* NXP HAL & SDK Drivers */
+
+/* end of NXP HAL & SDK Drivers */
+
+/* NUVOTON Drivers */
+
+/* end of NUVOTON Drivers */
+
+/* GD32 Drivers */
+
+/* end of GD32 Drivers */
+
+/* HPMicro SDK */
+
+/* end of HPMicro SDK */
+
+/* FT32 HAL & SDK Drivers */
+
+/* end of FT32 HAL & SDK Drivers */
+
+/* NOVOSNS Drivers */
+
+/* end of NOVOSNS Drivers */
+/* end of HAL & SDK Drivers */
+
+/* sensors drivers */
+
+/* end of sensors drivers */
+
+/* touch drivers */
+
+/* end of touch drivers */
 #define PKG_USING_SIGNAL_LED
 #define PKG_USING_SIGNAL_LED_LATEST_VERSION
 
@@ -243,13 +342,15 @@
 
 /* end of AI packages */
 
+/* Signal Processing and Control Algorithm Packages */
+
+/* end of Signal Processing and Control Algorithm Packages */
+
 /* miscellaneous packages */
 
-#define PKG_USING_FASTLZ
-#define PKG_USING_FASTLZ_V101
-#define PKG_USING_QUICKLZ
-#define QLZ_COMPRESSION_LEVEL 3
-#define PKG_USING_QUICKLZ_V101
+/* project laboratory */
+
+/* end of project laboratory */
 
 /* samples: kernel and components samples */
 
@@ -258,7 +359,57 @@
 /* entertainment: terminal games and other interesting software packages */
 
 /* end of entertainment: terminal games and other interesting software packages */
+#define PKG_USING_FASTLZ
+#define PKG_USING_FASTLZ_V101
+#define PKG_USING_QUICKLZ
+#define QLZ_COMPRESSION_LEVEL 3
+#define PKG_USING_QUICKLZ_V101
 /* end of miscellaneous packages */
+
+/* Arduino libraries */
+
+
+/* Projects and Demos */
+
+/* end of Projects and Demos */
+
+/* Sensors */
+
+/* end of Sensors */
+
+/* Display */
+
+/* end of Display */
+
+/* Timing */
+
+/* end of Timing */
+
+/* Data Processing */
+
+/* end of Data Processing */
+
+/* Data Storage */
+
+/* Communication */
+
+/* end of Communication */
+
+/* Device Control */
+
+/* end of Device Control */
+
+/* Other */
+
+/* end of Other */
+
+/* Signal IO */
+
+/* end of Signal IO */
+
+/* Uncategorized */
+
+/* end of Arduino libraries */
 /* end of RT-Thread online packages */
 
 /* samples: kernel and components samples */

BIN
CBD_FOTA_BootLoader/rtconfig.pyc