V2.1版本
authorkyz <kyz@kyz.pub>
Thu, 21 Mar 2024 03:32:30 +0000 (11:32 +0800)
committerkyz <kyz@kyz.pub>
Fri, 22 Mar 2024 01:34:41 +0000 (09:34 +0800)
主程序定位到 ITCM 加载地址 0x1000
bootloader程序 从spiflash 读取主程序到itcm,跳转执行

Core/Src/main.c
MDK-ARM/welding_controller_v2.uvprojx
lib/gas_flow_20240320.lib [new file with mode: 0644]
ui/TFT/6.png.tft
user/user.h
user/user_cdc_rx_2.c
user/user_flowmeter.c
user/user_ui.c

index 09ca587b58c76569bd3037bca44623cee017fe6d..b3a000c8cc4203535793b0a6a7d5d237281cbae0 100644 (file)
@@ -82,7 +82,7 @@ int main(void)
     //主程序从flash加载到ITCM中运行,加载地址1000 
     //程序0x00001000不放0地址,否则许多内存读写函数会判为NULL?
     //在这里手动修改VTOR
-//    SCB->VTOR = 0x1000; 
+    SCB->VTOR = 0x1000; 
   /* USER CODE END 1 */
 /* Enable the CPU Cache */
 
index 8b612f8c813299acc16db53641c01e554a63335a..d0273af80a495ac64beb58a4ca64a0b05c7a9b3d 100644 (file)
               </OCR_RVCT3>
               <OCR_RVCT4>
                 <Type>1</Type>
-                <StartAddress>0x8000000</StartAddress>
-                <Size>0x20000</Size>
+                <StartAddress>0x1000</StartAddress>
+                <Size>0x1f000</Size>
               </OCR_RVCT4>
               <OCR_RVCT5>
                 <Type>1</Type>
diff --git a/lib/gas_flow_20240320.lib b/lib/gas_flow_20240320.lib
new file mode 100644 (file)
index 0000000..3be86d5
Binary files /dev/null and b/lib/gas_flow_20240320.lib differ
index f07928891905738d4d7d2cdb913dc3e0f4fd5c20..38190f5ed387c95d028915186d029c12c2f97dc6 100644 (file)
Binary files a/ui/TFT/6.png.tft and b/ui/TFT/6.png.tft differ
index 2ac267ea553f6eca0efd33cb211af7877e9e35a8..a60ed21e26049cab01711f9453672421a67fbdff 100644 (file)
@@ -26,7 +26,7 @@
 //--------------------
 
 #define APP_VER_MAJOR 2
-#define APP_VER_MINOR 0
+#define APP_VER_MINOR 1
 
 #define VREF  2.5f
 
index 6dd5e3cefa5eb29aec9fc6f7f6d28cc427e83b83..e11264deab91cb6d96b2a5e8b1002d67d7124f47 100644 (file)
 */
 
 
-#define APP_FLAG  0x00505041 //'APP\0'
+#define FW_APP_FLAG  0x31505041 //'APP1'
 
 typedef struct{
     uint16_t cmd;
@@ -243,7 +243,7 @@ int32_t load_app( void )
       return -1;
 
   user_sflash_read( APP_INFO_PART_ADDR, (uint8_t*)&fw_info, sizeof( fw_info ) );
-  if( fw_info.flag != APP_FLAG || fw_info.addr <= 0x00000000 || fw_info.addr+fw_info.size > 0x40000 ) //itcm
+  if( fw_info.flag != FW_APP_FLAG || fw_info.addr <= 0x00000000 || fw_info.addr+fw_info.size > 0x40000 ) //itcm
       return -2;
 
   user_sflash_read( APP_PART_ADDR, (uint8_t*)fw_info.addr, fw_info.size );
@@ -297,7 +297,7 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
             resp[0] = 0;
             resp[1] = 'B';
             resp[2] = 1; //BOOT_VER_MAJOR;
-            resp[3] = 2; //BOOT_VER_MINOR;
+            resp[3] = 0; //BOOT_VER_MINOR;
             put_u32_big( &resp[4], 0 ); //fw size
             put_u32_big( &resp[8], 0 ); //fw crc
           #else
@@ -369,7 +369,7 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
             break;
         case 0x0004: //reboot
         {
-            fw.flag = APP_FLAG;
+            fw.flag = FW_APP_FLAG;
             user_sflash_erase( APP_INFO_PART_ADDR, APP_INFO_PART_SIZE );
             user_sflash_write( APP_INFO_PART_ADDR, (uint8_t*)&fw, sizeof( fw ) );
             resp[0] = 1;
@@ -466,7 +466,7 @@ int32_t get_app_fw_info( uint32_t * fw_size, uint16_t fw_crc )
     
     p = (uint32_t*)(app_start+1024);
     flag = p[0];
-    if( flag != 0x00505041 )
+    if( flag != FW_APP_FLAG )
         return 0;
 
     sw_ver_addr = (uint8_t *)p[1];
index 81f3ac72782d2b45795df146d89e2022807c70fe..9ce296d464cdbe4b628535d01a2e09f854ff40fe 100644 (file)
@@ -136,7 +136,10 @@ void user_flowmeter_task( void* unused )
             //读取到 流量
             err = 0;
             g_dev.flowmeter.flow_speed_raw = reg_values[0]/10.0f;
-            g_dev.flowmeter.flow_speed = g_dev.flowmeter.flow_speed_raw + g_dev.cfg.cal.flowrate;
+            if( g_dev.flowmeter.flow_speed_raw + g_dev.cfg.cal.flowrate > 0 )
+                g_dev.flowmeter.flow_speed = g_dev.flowmeter.flow_speed_raw + g_dev.cfg.cal.flowrate;
+            else
+                g_dev.flowmeter.flow_speed = 0;
             g_dev.flowmeter.flow_total = ((reg_values[1]<<16)|reg_values[2])/10.0f;
             g_dev.flowmeter.tem = reg_values[3]/10.0f;
             g_dev.flowmeter.state      = reg_values[4];
index 40f5c7924a8ae06ef6fdda73c4c296691cae4db1..633f7a24fa10dbd7666816762bc75de9cb11fca2 100644 (file)
@@ -89,6 +89,7 @@ void ui_handle_lcd_pkt( void )
 {
     uint16_t ctrl_addr;
     uint16_t  ctrl_value;
+    int16_t flow_cal_x10;
     uint8_t *p;
     static net_cfg_t net_cfg;
     
@@ -166,7 +167,8 @@ void ui_handle_lcd_pkt( void )
                     }else{
                         g_dev.cfg.cal.flowrate = off;
                         dev_cfg_store( &g_dev.cfg );
-                        lcd_write_u16( lcd_flow_cal_value_addr, off*10 );
+                        flow_cal_x10 = (int16_t)(g_dev.cfg.cal.flowrate*10);
+                        lcd_write_s16( lcd_flow_cal_value_addr, flow_cal_x10 );
                     }
                 }
             }
@@ -280,6 +282,12 @@ void lcd_write( uint16_t addr, uint16_t *value, uint8_t reg_nr )
     }
 };
 
+void lcd_write_s16( uint16_t addr, int16_t value )
+{
+    uint16_t reg_value = (uint16_t)value;
+    lcd_write( addr, &reg_value, 1 );
+}
+
 void lcd_write_u16( uint16_t addr, uint16_t value )
 {
     uint16_t reg_value = value;
@@ -298,6 +306,7 @@ void lcd_power_off( void )
 
 void user_ui_task( void* unused )
 {
+    int16_t flow_cal_x10;
     uint16_t reg_values[16];
     //uint32_t last_tick = xTaskGetTickCount();
     EventBits_t uxBits;
@@ -334,7 +343,8 @@ void user_ui_task( void* unused )
     osDelay(10 );
     lcd_write_text( lcd_tcp_server_addr, (uint8_t*)&g_dev.cfg.net.tcp_server, lcd_tcp_server_size );
     osDelay(10 );
-    lcd_write_u16(  lcd_flow_cal_value_addr, g_dev.cfg.cal.flowrate*10 );
+    flow_cal_x10 = (int16_t)(g_dev.cfg.cal.flowrate*10);
+    lcd_write_s16( lcd_flow_cal_value_addr, flow_cal_x10 );
     osDelay(10 );
 
     while(1){