From 941529aca3aab2871570dfe5d9d795b2a42515ea Mon Sep 17 00:00:00 2001 From: kyz Date: Thu, 21 Mar 2024 11:27:20 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81,=E7=A7=BB?= =?utf8?q?=E9=99=A4=E7=BC=96=E8=AF=91warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- MDK-ARM/welding_controller_v2.uvprojx | 43 +++++++++++++++++++++++++++ user/bootloader.c | 3 +- user/user.h | 16 ++++++++++ user/user_adc.c | 18 +++++------ user/user_app.c | 4 +-- user/user_cdc_rx_2.c | 12 ++++---- user/user_debug.c | 2 +- user/user_ui.c | 9 ++++-- user/user_valve_ctrl.c | 4 +-- user/user_wifi.c | 30 ++++++++++--------- 10 files changed, 100 insertions(+), 41 deletions(-) diff --git a/MDK-ARM/welding_controller_v2.uvprojx b/MDK-ARM/welding_controller_v2.uvprojx index c8cac00..8b612f8 100644 --- a/MDK-ARM/welding_controller_v2.uvprojx +++ b/MDK-ARM/welding_controller_v2.uvprojx @@ -1122,6 +1122,49 @@ gas_flow_yn.lib 4 ..\lib\gas_flow_yn.lib + + + 2 + 0 + 0 + 0 + 0 + 0 + 2 + 2 + 2 + 2 + 11 + + + 1 + + + + + + gas_flow_20240320.lib + 4 + ..\lib\gas_flow_20240320.lib + + + 2 + 0 + 0 + 0 + 1 + 2 + 2 + 2 + 2 + 2 + 11 + + weld_alg.o|1|0|0|0 + 1 + + + diff --git a/user/bootloader.c b/user/bootloader.c index d170853..df357ac 100644 --- a/user/bootloader.c +++ b/user/bootloader.c @@ -32,7 +32,6 @@ #include "user.h" -#define BOOT_MODE_LOAD_ADDR 0x30000000 dev_info_t g_dev; @@ -144,7 +143,7 @@ int main(void) } uint32_t download_flag = 0; - if( *(uint32_t *)BOOT_MODE_LOAD_ADDR == 0x00505041 ){ + if( *(uint32_t *)BOOT_MODE_LOAD_ADDR == BOOT_MODE_DOWNLOAD ){ *(uint32_t *)BOOT_MODE_LOAD_ADDR = 0; //清除下载标志 download = 1; SCB_CleanDCache(); download_flag = 1; diff --git a/user/user.h b/user/user.h index df4d7dc..2ac267e 100644 --- a/user/user.h +++ b/user/user.h @@ -30,6 +30,14 @@ #define VREF 2.5f + +//SRAM1 30000000--30003FFF 16K Byte mapped on D2 domain +//SRAM2 30004000--30007FFF 16K Byte mapped on D2 domain +//SRAM4 38000000--38003FFF 16K Byte mapped on D3 domain + +#define BOOT_MODE_LOAD_ADDR 0x30004000 //保存重启标志,用于软件重启进入下载模式 +#define BOOT_MODE_DOWNLOAD 0x00505041 //下载模式标志值 + #define DBG_PRINTF(fmt, args...) debug_printf(fmt, ##args) void debug_printf(char* str , ...); @@ -195,5 +203,13 @@ void user_beep_task( void* unused ); //lcd void lcd_uart_rx_cb( void ); +//cdc +uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len); + +//从数据读取和写入字段 +uint16_t get_u16_big( uint8_t *p ); +uint32_t get_u32_big( uint8_t *p ); +void put_u16_big( uint8_t *p, uint16_t d ); +void put_u32_big( uint8_t *p, uint32_t d ); #endif //__USER_H__ diff --git a/user/user_adc.c b/user/user_adc.c index 6b6d623..3f508f8 100644 --- a/user/user_adc.c +++ b/user/user_adc.c @@ -29,7 +29,7 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) SCB_InvalidateDCache_by_Addr((uint32_t *)&adc2_raw[0], sizeof( adc2_raw) ); for( int32_t i=0; i< ARRAY_SIZE( adc2_raw); i++ ) - adc2_curr[i] = (adc2_raw[i] * VREF*2/0xffff - 2.5)/0.625*400; + adc2_curr[i] = (adc2_raw[i] * VREF*2/0xffff - 2.5f)/0.625f*400; osEventFlagsSet( g_dev.ev_group, EVENT_ADC2_UPDATE ); }else if( hadc == &hadc3 ){ SCB_InvalidateDCache_by_Addr((uint32_t *)&adc3_raw[0], sizeof( adc3_raw) ); @@ -58,14 +58,14 @@ float calc_welding_current( float *values, uint32_t len ) //6. 峰值和基值差距大,判断为脉冲, 峰值电流计算均方根有效值 //直流和交流可以直接用均方根计算有效值, int32_t average; - int32_t zero_raw; +// int32_t zero_raw; int32_t p_nr=0; int32_t m_nr=0; int32_t z_nr=0; uint32_t s_curr=0; - uint32_t s_p=0; - uint32_t s_z=0; - uint32_t s_m=0; +// uint32_t s_p=0; +// uint32_t s_z=0; +// uint32_t s_m=0; float curr; float welding_curr = 0; @@ -173,8 +173,6 @@ void user_adc_task( void* unused ) EventBits_t uxBits; - float dbg_curr; //for debug - HAL_ADCEx_Calibration_Start( &hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED ); HAL_ADCEx_Calibration_Start( &hadc2, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED ); HAL_ADCEx_Calibration_Start( &hadc3, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED ); @@ -266,10 +264,10 @@ void user_adc_task( void* unused ) //模拟电流用于调试 g_dev.welding_current = g_dev.debug_welding_curr; }else{ - static uint32_t t10, t11; - t10 = HAL_GetTick(); +// static uint32_t t10, t11; +// t10 = HAL_GetTick(); g_dev.welding_current = calc_welding_current( adc2_curr, ARRAY_SIZE(adc2_curr)); - t11 = HAL_GetTick() - t10; +// t11 = HAL_GetTick() - t10; } if( g_dev.welding_current < -500 || g_dev.welding_current > 500 ){ diff --git a/user/user_app.c b/user/user_app.c index 38b6771..da1eead 100644 --- a/user/user_app.c +++ b/user/user_app.c @@ -58,7 +58,7 @@ void StartDefaultTask(void *argument) { /* init code for USB_DEVICE */ MX_USB_DEVICE_Init(); - +#if 0 while(0){ const char*method[3] = {"TIG", "MIG", "MAG" }; double flowspeed; @@ -75,7 +75,7 @@ void StartDefaultTask(void *argument) } } } - +#endif //dev init memset( &g_dev, 0, sizeof( g_dev ) ); user_sflash_init(); diff --git a/user/user_cdc_rx_2.c b/user/user_cdc_rx_2.c index aae2faa..6dd5e3c 100644 --- a/user/user_cdc_rx_2.c +++ b/user/user_cdc_rx_2.c @@ -262,10 +262,12 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt ) static uint8_t tx_pkt[100]; uint8_t resp[64]; uint8_t tx_n = 0; +#ifdef BOOTLOADER uint32_t off; uint32_t sz; uint16_t crc; - uint32_t ma; +#endif +// uint32_t ma; switch( pkt->cmd ){ case 0x00f0: @@ -315,12 +317,12 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt ) #ifndef BOOTLOADER //下载固件 指令 A0-connect A1-擦除 A2-写入 ... - //主程序收到开始下载指令,在SRAM1 中写入标志, 重启设备, boot中读取到标志进入下载模式 + //主程序收到开始下载指令,在SRAM2 中写入标志, 重启设备, boot中读取到标志进入下载模式 case 0xA0: resp[0] = 1; tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 ); //__attribute__((at(0x30001000))) uint32_t app_flag; - *(uint32_t*)0x30000000 = APP_FLAG; + *(uint32_t*)BOOT_MODE_LOAD_ADDR = BOOT_MODE_DOWNLOAD; SCB_CleanDCache(); HAL_NVIC_SystemReset(); break; @@ -431,10 +433,6 @@ void cdc_rx_proccess( void ) } } -#ifdef BOOTLOADER - -#endif - int32_t get_app_fw_info( uint32_t * fw_size, uint16_t fw_crc ) { diff --git a/user/user_debug.c b/user/user_debug.c index caa97f6..09a8518 100644 --- a/user/user_debug.c +++ b/user/user_debug.c @@ -4,7 +4,7 @@ uint32_t dbg_report_raw_current = 0; //采集上报原始AD值,用于获取交流脉冲等原始数据,调试不同电流算法。 -uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len); + int32_t fputc( int32_t data, FILE *fd ) { diff --git a/user/user_ui.c b/user/user_ui.c index 5a43b92..40f5c79 100644 --- a/user/user_ui.c +++ b/user/user_ui.c @@ -121,8 +121,11 @@ void ui_handle_lcd_pkt( void ) if( strlen( net_cfg.wifi_ssid)&& strlen( net_cfg.wifi_passwd ) && strlen( net_cfg.tcp_server ) && strlen( net_cfg.tcp_port ) ){ - memcpy( &g_dev.cfg.net, &net_cfg, sizeof( net_cfg ) ); - dev_cfg_store( &g_dev.cfg ); + if( memcmp( &g_dev.cfg.net, &net_cfg, sizeof( net_cfg ) ) ){ + memcpy( &g_dev.cfg.net, &net_cfg, sizeof( net_cfg ) ); + dev_cfg_store( &g_dev.cfg ); + g_dev.connected = 0; + } } break; } @@ -148,7 +151,7 @@ void ui_handle_lcd_pkt( void ) g_dev.cfg.welding_method = welding_method; dev_cfg_store( &g_dev.cfg ); } - }else if( ctrl_addr == lcd_valve_bypass_addr ){//比例阀开度 + }else if( ctrl_addr == lcd_valve_bypass_addr ){//比例阀旁路 uint8_t bypass = ctrl_value; g_dev.ui_bypass = bypass; }else if( ctrl_addr == lcd_wifi_config_addr ){ //点击配置按钮 diff --git a/user/user_valve_ctrl.c b/user/user_valve_ctrl.c index 95525ad..b984220 100644 --- a/user/user_valve_ctrl.c +++ b/user/user_valve_ctrl.c @@ -150,7 +150,7 @@ int32_t calc_target_flow( double *target_flowspeed ) else welding_current = g_dev.welding_current; - if( caculate( g_dev.cfg.welding_method, welding_current, g_dev.cfg.save_gas_factor, &flowspeed ) == 0 ){ + if( caculate( (WeldMethod)g_dev.cfg.welding_method, welding_current, g_dev.cfg.save_gas_factor, &flowspeed ) == 0 ){ //控制流量输出, 按焊接电流和节气因子计算目标流量 *target_flowspeed = flowspeed; return 0; @@ -182,7 +182,7 @@ float calc_valve_open_default( uint8_t open_percent ) if( open_percent == 0 ) curr = 0; else - curr = curr_start + ( 0.165-curr_start )*open_percent/100.0f; + curr = curr_start + ( 0.165f-curr_start )*open_percent/100.0f; return curr; } diff --git a/user/user_wifi.c b/user/user_wifi.c index 4db2625..586c81e 100644 --- a/user/user_wifi.c +++ b/user/user_wifi.c @@ -40,7 +40,7 @@ void wifi_uart_rx_cb( void ) if( rx_buf_wr+1==rx_buf_rd ){ //full! }else{ - wifi_rx_buf[rx_buf_wr&WIFI_RX_BUF_SIZE_MASK] = wifi_rx_byte; + wifi_rx_buf[rx_buf_wr&WIFI_RX_BUF_SIZE_MASK] = rx_byte; rx_buf_wr++; } @@ -154,7 +154,7 @@ int32_t wifi_connect( const char * ssid, const char * passwd ) return -1; } str = strstr( resp_buf, "STAMAC" ); - if( str && sscanf( str, "STAMAC,\"%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] )!= 6 ){ + if( str && sscanf( str, "STAMAC,\"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5] )!= 6 ){ return -1; } if( ip[0] == 0 && ip[1] == 0 && ip[2] == 0 && ip[3] == 0 ) @@ -171,11 +171,11 @@ int32_t tcp_server_connect( const char * tcp_server, const char * port ) //4. 连接TCP服务器 //AT+CIPSTART="TCP","192.168.3.116",8080 //protocol, server IP and port - at_cfg.reply_prefix = "WIFI"; - at_cfg.reply_success_postfix="OK"; //"CONNECTED"; - at_cfg.reply_fail_postfix = "FAIL"; //"DISCONNECT"; + at_cfg.reply_prefix = NULL; + at_cfg.reply_success_postfix="OK"; //"CONNECT OK"; + at_cfg.reply_fail_postfix = "ERROR"; //"ERROR CLOSED"; sprintf( cmd, "AT+CIPSTART=\"TCP\",\"%s\",%s", tcp_server, port ); - if( at_send_wait_reply( cmd, strlen(cmd), true, NULL, 0, resp_buf, sizeof( resp_buf )-1, NULL ) ){ + if( at_send_wait_reply( cmd, strlen(cmd), true, NULL, 0, resp_buf, sizeof( resp_buf )-1, &at_cfg ) ){ return -1; } if( !strstr( resp_buf, "OK" ) ){ @@ -269,13 +269,13 @@ static void tcp_rx_data_handle(void *arg, char *rspinfo, int rsplen) { unsigned char unusesymbol = 0; unsigned char datalen[6] = {0}; - unsigned char ipaddr[16] = {0}; +// unsigned char ipaddr[16] = {0}; int i = 0; int j = 0; int len = 0; - int remoteport = 0; - int linkid = 0; +// int remoteport = 0; +// int linkid = 0; char *recvdata = NULL; //+IPD,20:http://www.cmsoft.cn @@ -338,10 +338,10 @@ void user_wifi_task( void* unused ) char *ssid; char *passwd; - int32_t connected; +// int32_t connected; TickType_t last_ticks; - connected = 0; +// connected = 0; g_dev.connected = 0; MX_UART5_Init(); @@ -395,14 +395,15 @@ void user_wifi_task( void* unused ) //定时上报 if( devinfo_report() < 0 ){ //reconnect - connected = 0; +// connected = 0; + g_dev.connected = 1; break; } } } } -static osThreadId_t wifiTaskHandle; +//static osThreadId_t wifiTaskHandle; const osThreadAttr_t wifiTask_attributes = { .name = "wifiTask", @@ -412,5 +413,6 @@ const osThreadAttr_t wifiTask_attributes = { void wifi_task_start( void ) { - wifiTaskHandle = osThreadNew(user_wifi_task, NULL, &wifiTask_attributes); + // wifiTaskHandle = osThreadNew(user_wifi_task, NULL, &wifiTask_attributes); + osThreadNew(user_wifi_task, NULL, &wifiTask_attributes); } -- 2.34.1