Browse Source

解决崩溃问题

guohui 1 year ago
parent
commit
dcad6508f8

+ 5 - 4
f407/applications/board.c

@@ -12,15 +12,18 @@
 #include <board.h>
 #include <drv_common.h>
 
+
+struct rt_memheap sram2_heap;
 void rt_hw_board_init()
 {
-    struct rt_memheap heap;
+    
     extern void hw_board_init(char *clock_src, int32_t clock_src_freq, int32_t clock_target_freq);
 
     /* Heap initialization */
 #if defined(RT_USING_HEAP)
     rt_system_heap_init((void *) HEAP_BEGIN1, (void *) HEAP_END1);
-    rt_memheap_init(&heap, "sram2", (void *)HEAP_BEGIN2, HEAP_END2-(uint32_t)HEAP_BEGIN2);
+    //rt_memheap_init(&heap, "sram2", (void *)HEAP_BEGIN2, HEAP_END2-(uint32_t)HEAP_BEGIN2);
+    rt_memheap_init(&sram2_heap, "sram2", (void *)0x10000000, 0x10000);
 #endif
 
     hw_board_init(BSP_CLOCK_SOURCE, BSP_CLOCK_SOURCE_FREQ_MHZ, BSP_CLOCK_SYSTEM_FREQ_MHZ);
@@ -34,6 +37,4 @@ void rt_hw_board_init()
 #ifdef RT_USING_COMPONENTS_INIT
     rt_components_board_init();
 #endif
-    
-    //rt_hw_rtc_init();
 }

+ 7 - 5
f407/applications/rtconfig.h

@@ -155,10 +155,9 @@
 #define RT_LWIP_MEM_ALIGNMENT 4
 
 //lwip debug setting
-#define RT_LWIP_DEBUG
+//#define RT_LWIP_DEBUG
 //#define RT_LWIP_PBUF_DEBUG
-#define RT_LWIP_TCPIP_DEBUG
-#define RT_LWIP_TCP_OUTPUT_DEBUG
+//#define RT_LWIP_TCPIP_DEBUG
 
 
 #define RT_LWIP_TCP
@@ -179,9 +178,12 @@
 #define RT_LWIP_TCP
 #define RT_LWIP_RAW
 #define RT_MEMP_NUM_NETCONN 8
+
+//#define MEM_USE_POOLS       1
 //#define PBUF_POOL_SIZE   4
-//#define RT_LWIP_PBUF_NUM 16
-//#define RT_LWIP_PBUF_POOL_BUFSIZE  1024
+//#define RT_LWIP_PBUF_NUM   64
+//#define RT_LWIP_PBUF_POOL_BUFSIZE  512
+
 
 #define RT_LWIP_RAW_PCB_NUM 4
 #define RT_LWIP_UDP_PCB_NUM 4

+ 6 - 6
f407/applications/ui/lcd.c

@@ -22,10 +22,10 @@ typedef struct {
 
 static lcd_handle_t lcdHandle={0};
 
-extern int st7789_init(lcd_handle_t *h);
-extern int st7789_deinit(lcd_handle_t *h);
-extern void st7789_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, void *data, uint32_t len);
-extern void st7789_rotate(lcd_handle_t *h, int rotate);
+extern int st77xx_init(lcd_handle_t *h);
+extern int st77xx_deinit(lcd_handle_t *h);
+extern void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, void *data, uint32_t len);
+extern void st77xx_rotate(lcd_handle_t *h, int rotate);
 
 
 static inline int set_point(lcd_handle_t *h, int x, int y, uint32_t data)
@@ -75,7 +75,7 @@ void lcd_init(int width, int height, uint32_t color)
     h->color  = color;
     h->rotate = 0;
     
-    st7789_init(h);
+    st77xx_init(h);
     
     //lcd_draw_string(0, 0, LCD_WIDTH, LCD_HEIGHT/10, "SmartPDU", FONT_12, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
     //lcd_hw_init(h);
@@ -297,7 +297,7 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
             }
         }
     }
-    st7789_refresh(hd, x0, y0, fdata.width, fdata.height, hd->buf, fdata.width*fdata.height*2);
+    st77xx_refresh(hd, x0, y0, fdata.width, fdata.height, hd->buf, fdata.width*fdata.height*2);
 #endif
 
     return fdata.width;

+ 0 - 71
f407/applications/ui/st7789.h

@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2006-2023, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date           Author        Notes
- * 2023-03-23     Vandoul       First version
- */
-#ifndef __ST7789_H__
-#define __ST7789_H__
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-#include <stdint.h>
-#include <rtthread.h>
-#include <rtdevice.h>
-#include "drivers/spi.h"
-#include "lcd.h"
-
-
-/* 0-0 angle|1-90 angle|2-180 angle|-270 angle */
-#define USE_DIRECTION   0
-
-/* lcd size */
-#define LCD_W 240
-#define LCD_H 240
-
-#define CS_PIN       GET_PIN(B, 12)
-#define BK_PIN       GET_PIN(D, 9)     //PD9
-#define DC_PIN       GET_PIN(D, 8)     //PD8
-#define RST_PIN     GET_PIN(B, 14)    //PB14
-
-
-#define LCD_DC_CLR  rt_pin_write(DC_PIN, PIN_LOW)
-#define LCD_DC_SET  rt_pin_write(DC_PIN, PIN_HIGH)
-#define LCD_RES_CLR rt_pin_write(RST_PIN, PIN_LOW)
-#define LCD_RES_SET rt_pin_write(RST_PIN, PIN_HIGH)
-#define LCD_BLK_CLR rt_pin_write(BK_PIN, PIN_HIGH)
-#define DELAY       rt_thread_mdelay
-
-#define WHITE 0xFFFF
-#define BLACK 0x0000
-#define BLUE 0x001F
-#define BRED 0XF81F
-#define GRED 0XFFE0
-#define GBLUE 0X07FF
-#define RED 0xF800
-#define MAGENTA 0xF81F
-#define GREEN 0x07E0
-#define CYAN 0x7FFF
-#define YELLOW 0xFFE0
-#define BROWN 0XBC40
-#define BRRED 0XFC07
-#define GRAY 0X8430
-
-void LCD_Clear(uint16_t Color);
-void LCD_direction(uint8_t direction);
-void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
-void LCD_SetWindows(uint16_t xStar, uint16_t yStar, uint16_t xEnd, uint16_t yEnd);
-void LCD_Fill(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color);
-void lcd_fill_array_spi(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, uint16_t *pcolor);
-
-rt_err_t spi_lcd_init(uint32_t freq);
-
-#ifdef __cplusplus
-}
-#endif
-#endif

+ 14 - 2
f407/applications/web.c

@@ -91,7 +91,17 @@ static void send_powerc(web_handle_t *h, struct mg_connection *c)
     pkt_hdr_t *hdr=NULL;
     power_data_t pd=power_data_get();
     
-    //pd.chs = 2;
+    for(i=0; i<pd.chs; i++) {
+        ws_send_pkt(h, c, PKT_TYPE_POWER_CH, &pd.pch[i], sizeof(power_ch_t), 1);
+    }
+}
+static void send_powerc_once(web_handle_t *h, struct mg_connection *c)
+{
+    int i,xlen,offset;
+    pkt_hdr_t *hdr=NULL;
+    power_data_t pd=power_data_get();
+    
+    pd.chs = 8;
     if(pd.chs==0) {
         return;
     }
@@ -120,6 +130,8 @@ static void send_powerc(web_handle_t *h, struct mg_connection *c)
     }
     ws_send(c, h->buf, xlen, 1);
 }
+
+
 static void send_powert(web_handle_t *h, struct mg_connection *c)
 {
     int i,r;
@@ -189,7 +201,7 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, struct mg_connection *c)
             }
             else {
                 LOGD("_____ send_powerc\n");
-                send_powerc(h, c);
+                send_powerc_once(h, c);
             }
         }
         break;

+ 0 - 1
f407/project/all.uvmpw

@@ -15,7 +15,6 @@
 
   <project>
     <PathAndName>.\boot\boot.uvprojx</PathAndName>
-    <NodeIsExpanded>1</NodeIsExpanded>
   </project>
 
 </ProjectWorkspace>

File diff suppressed because it is too large
+ 561 - 598
f407/project/app/app.uvoptx


+ 24 - 29
f407/project/app/app.uvprojx

@@ -212,7 +212,7 @@
             <Ra2Chk>0</Ra2Chk>
             <Ra3Chk>0</Ra3Chk>
             <Im1Chk>1</Im1Chk>
-            <Im2Chk>1</Im2Chk>
+            <Im2Chk>0</Im2Chk>
             <OnChipMemories>
               <Ocm1>
                 <Type>0</Type>
@@ -394,6 +394,11 @@
               <FileType>5</FileType>
               <FilePath>..\..\applications\board.h</FilePath>
             </File>
+            <File>
+              <FileName>lwipopts.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\..\rt-thread\components\net\lwip\port\lwipopts.h</FilePath>
+            </File>
             <File>
               <FileName>rtconfig.h</FileName>
               <FileType>5</FileType>
@@ -754,9 +759,9 @@
               <FilePath>..\..\applications\ui\ui.c</FilePath>
             </File>
             <File>
-              <FileName>st7789.c</FileName>
+              <FileName>st77xx.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\..\applications\ui\st7789.c</FilePath>
+              <FilePath>..\..\applications\ui\st77xx.c</FilePath>
             </File>
           </Files>
         </Group>
@@ -2330,7 +2335,22 @@
           </Files>
         </Group>
         <Group>
-          <GroupName>rt-thread/comp/lwip</GroupName>
+          <GroupName>rt-thread/comp/lwip-port</GroupName>
+          <Files>
+            <File>
+              <FileName>ethernetif.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\rt-thread\components\net\lwip\port\ethernetif.c</FilePath>
+            </File>
+            <File>
+              <FileName>sys_arch.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\rt-thread\components\net\lwip\port\sys_arch.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>rt-thread/comp/lwip2.1.2</GroupName>
           <Files>
             <File>
               <FileName>api_lib.c</FileName>
@@ -2377,21 +2397,6 @@
               <FileType>1</FileType>
               <FilePath>..\..\rt-thread\components\net\lwip\lwip-2.1.2\src\api\tcpip.c</FilePath>
             </File>
-            <File>
-              <FileName>fs.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\rt-thread\components\net\lwip\lwip-2.1.2\src\apps\http\fs.c</FilePath>
-            </File>
-            <File>
-              <FileName>httpd.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\rt-thread\components\net\lwip\lwip-2.1.2\src\apps\http\httpd.c</FilePath>
-            </File>
-            <File>
-              <FileName>mqtt.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\rt-thread\components\net\lwip\lwip-2.1.2\src\apps\mqtt\mqtt.c</FilePath>
-            </File>
             <File>
               <FileName>ping.c</FileName>
               <FileType>1</FileType>
@@ -2612,16 +2617,6 @@
               <FileType>1</FileType>
               <FilePath>..\..\rt-thread\components\net\lwip\lwip-2.1.2\src\netif\lowpan6_common.c</FilePath>
             </File>
-            <File>
-              <FileName>ethernetif.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\rt-thread\components\net\lwip\port\ethernetif.c</FilePath>
-            </File>
-            <File>
-              <FileName>sys_arch.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\rt-thread\components\net\lwip\port\sys_arch.c</FilePath>
-            </File>
             <File>
               <FileName>snmp_asn1.c</FileName>
               <FileType>1</FileType>

+ 2 - 2
f407/rt-thread/components/net/lwip/port/lwipopts.h

@@ -279,10 +279,10 @@
 #define MEMP_OVERFLOW_CHECK         1
 #define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
 
-//#define MEM_LIBC_MALLOC             1
+#define MEM_LIBC_MALLOC             1
 //#define MEM_USE_POOLS               1
 //#define MEMP_USE_CUSTOM_POOLS       1
-//#define MEM_SIZE                    (1024*64)
+//#define MEM_SIZE                    (1024*10)
 
 #define MEMP_MEM_MALLOC             0
 

+ 17 - 15
f407/tools/web/data.js

@@ -705,21 +705,23 @@ XXX.hdr = function() {
         }
         
         var data = bin.slice(hdr.len);
-        switch(hdr.type) {
-            case PKT_TYPE.PKT_TYPE_POWER_CH:
-                hdr.powerc = BIN.powerc.b2j(data);
-                break;
-
-            case PKT_TYPE.PKT_TYPE_POWER_TOTAL:
-                hdr.powert = BIN.powert.b2j(data);
-                break;
-               
-           case PKT_TYPE.PKT_TYPE_ALARM:
-                hdr.alarmd = BIN.alarmd.b2j(data);
-                break;
-            
-            default :
-                console.log("wrong hdr type: "+hdr.type);
+        if(data.byteLength>0 && hdr.len==data.byteLength) {
+            switch(hdr.type) {
+                case PKT_TYPE.PKT_TYPE_POWER_CH:
+                    hdr.powerc = BIN.powerc.b2j(data);
+                    break;
+
+                case PKT_TYPE.PKT_TYPE_POWER_TOTAL:
+                    hdr.powert = BIN.powert.b2j(data);
+                    break;
+                   
+               case PKT_TYPE.PKT_TYPE_ALARM:
+                    hdr.alarmd = BIN.alarmd.b2j(data);
+                    break;
+                
+                default :
+                    console.log("wrong hdr type: "+hdr.type);
+            }
         }
         return hdr;
     }

+ 1 - 1
f407/tools/webServer/EasyWebSvr.ini

@@ -24,4 +24,4 @@ LogToFile=0
 LogFileName=
 [StartParam]
 bShowWnd=0
-bStartRun=0
+bStartRun=1