ソースを参照

[IAP]1. fix build
2. add condition when MAIN_FW_NAME "NONE"

balbekova 4 年 前
コミット
d0086d3e0b

+ 2 - 1
.vscode/settings.json

@@ -41,6 +41,7 @@
         "thread": "c",
         "usart.h": "c",
         "fr_timers.h": "c",
-        "string.h": "c"
+        "string.h": "c",
+        "tinystdio.h": "c"
     }
 }

+ 8 - 1
config/common_config.h

@@ -23,7 +23,7 @@
 #define HW_REV_OFFSET                   0x1F0
 
 #define DAUGHTER_FW_NAME                "NONE"
-#define MAIN_FW_NAME                    "ANY"
+#define MAIN_FW_NAME                    "NONE"
 
 
 /**
@@ -69,6 +69,13 @@
 #define IAP_FLASH_FIRST_PAGE_ADDRESS  0x08000000 /* Only as example see comment */
 #define IAP_FLASH_CRC_ADDRESS         0x0801FFFC
 	
+
+#define DB_CPU_FLASH_FIRST_PAGE_ADDRESS   0x08000000
+
+/* high-density value line devices (2Kb page) */
+#define DB_CPU_FLASH_END_ADDRESS          0x0803F7FF
+#define DB_CPU_FLASH_CRC_ADDRESS          0x0803F7FC
+#define DB_CPU_SETTINGS_PAGE              127
 	
 /**
   * @brief  Размер очереди для хранения трапов

+ 36 - 6
iap/Modules/Ethernet/httpserver.c

@@ -77,6 +77,17 @@
                                     SET_FWINVALID_FLAG();\
                                 } while(0)
 
+#define HTTP_RET_UPLOAD_ERROR_NO_FLASH_ERASE() do {\
+                                    memset(sendBuf, 0, 32);\
+                                    strcpy(sendBuf, HTTP_200_OK);\
+                                    strcat(sendBuf, "0");\
+                                    hs->file = sendBuf;\
+                                    hs->left = strlen(sendBuf);\
+                                    send_data(pcb, hs);\
+                                    tcp_sent(pcb, http_sent);\
+                                    htmlpage = UploadErrorPage;\
+                                } while(0)
+
 static char sendBuf[512];
 static char tempBuf[HW_REV_OFFSET + HW_REV_LEN];
 
@@ -163,7 +174,7 @@ bool CookieIsSet(char *inStr, uint16_t inLen, char *paramName);
 
 
 // Implements the GNU function memmem much faster (2x) than the standard memmem
-char *memmem(char *haystack, int hlen, char *needle, int nlen)
+char *memmemory(char *haystack, int hlen, char *needle, int nlen)
 {
     if (nlen > hlen) return 0;
     int i = 0, j = 0;
@@ -648,7 +659,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
                         TotalData = TotalData - len;
                         len = 0;
                     } else {
-                        char *bptr = memmem(data, p->tot_len, boundary, strlen(boundary));
+                        char *bptr = memmemory(data, p->tot_len, boundary, strlen(boundary));
                         // DBG printf("boundary: %s\r\n", boundary);
 
                         if (bptr != NULL) {
@@ -672,7 +683,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
 
                         /* Find "\r\n" or "\r" depending on a current packet length */
                         uint8_t marker_len = (tail_len - boundary_len >= 2) ? 2 : 1;
-                        char *ptr = memmem(data + p->tot_len - boundary_len, boundary_len,
+                        char *ptr = memmemory(data + p->tot_len - boundary_len, boundary_len,
                             marker_len == 2 ? "\r\n" : "\r", marker_len);
 
                         if (ptr != NULL) {
@@ -726,7 +737,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
                             DataFlag = 0;
                             upload_pcb = NULL;
 
-                            HTTP_RET_UPLOAD_ERROR();
+                            HTTP_RET_UPLOAD_ERROR_NO_FLASH_ERASE();
                             pbuf_free(p);
 
                             return ERR_OK;
@@ -811,7 +822,7 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err
                         printf("FW binary size mismatch. Aborting update..\r\n");
                         printf("FW dest size %u was %u\r\n", (unsigned int)FwDestSize, (unsigned int)TotalData);
 
-                        HTTP_RET_UPLOAD_ERROR();
+                        HTTP_RET_UPLOAD_ERROR_NO_FLASH_ERASE();
                     } else {
                         static uint8_t progress = 0;
                         if (progress != TotalReceived * 100 / size) {
@@ -1128,7 +1139,16 @@ void send_index_page(struct tcp_pcb *pcb, struct http_state *hs, struct pbuf *p,
 #endif
 
     strcat(sendBuf, "\r\nSet-Cookie: file2=");
-    strcat(sendBuf, MAIN_FW_NAME);
+
+    char file_name_buf[40];
+    memset(file_name_buf, 0, sizeof(file_name_buf));
+    strcpy(file_name_buf, MAIN_FW_NAME);
+
+    if(strcmp(file_name_buf, "NONE") != 0){
+        strcat(sendBuf, MAIN_FW_NAME);
+    } else {
+        strcat(sendBuf, " ");
+    }
 
     strcat(sendBuf,
            "\r\n\r\n<!DOCTYPE html><html lang="
@@ -1262,6 +1282,16 @@ static bool Parse_Filename(const char *data, uint32_t len, fw_type_t *fw_type, u
     uint32_t FilenameOffset = 0;
     char filename[FILENAME_MAX_LEN];
 
+    char file_name_buf[40];
+    memset(file_name_buf, 0, sizeof(file_name_buf));
+    strcpy(file_name_buf, MAIN_FW_NAME);
+    
+    if(strcmp(file_name_buf, "NONE") == 0){
+        *fw_type = fw_main_board;
+        *fw_size = MAIN_FW_SIZE;
+        return true;
+    }
+
     for (uint32_t i = 0; i < len; i++) {
         if (strncmp((char *)(data + i), "filename=", 9) == 0) {
             FilenameOffset = i + 10;

+ 34 - 0
iap/Modules/gpio_io.c

@@ -16,6 +16,40 @@
 #include "tinystdio.h"
 
 
+#ifdef SLAVEBRD_ENABLE
+/**
+  * @brief  Выставить пин DB_BOOT0
+  */
+void IO_SetDbBoot0(void)
+{
+  /* Inverted! */
+  GPIO_ResetBits(GPIOE, GPIO_Pin_8);
+}
+
+/**
+  * @brief  Выставить пин DB_BOOT0
+  */
+void IO_ClearDbBoot0(void)
+{
+  /* Inverted! */
+  GPIO_SetBits(GPIOE, GPIO_Pin_8);
+}
+
+/**
+  * @brief  Установить пин DB_RST  */
+void IO_SetDbReset(void)
+{
+  GPIO_SetBits(GPIOE, GPIO_Pin_7);
+}
+
+/**
+  * @brief  Сбросить пин DB_RST  */
+void IO_ClearDbReset(void)
+{
+  GPIO_ResetBits(GPIOE, GPIO_Pin_7);
+}
+#endif
+
 /**
   * @brief  Получить состояние кнопки DEFAULT
   */

+ 19 - 1
iap/Modules/gpio_io.h

@@ -15,7 +15,25 @@
 #define GPIO_IO_H
 
 #include <stdbool.h>
-  
+
+/**
+  * @brief  Выставить пин DB_BOOT0
+  */
+void IO_SetDbBoot0(void);
+
+/**
+  * @brief  Выставить пин DB_BOOT0
+  */
+void IO_ClearDbBoot0(void);
+
+/**
+  * @brief  Установить пин DB_RST  */
+void IO_SetDbReset(void);
+
+/**
+  * @brief  Сбросить пин DB_RST  */
+void IO_ClearDbReset(void);
+
 /**
   * @brief  Получить состояние кнопки DEFAULT
   */

+ 2 - 2
iap/User/main.c

@@ -1,4 +1,4 @@
-#include "stm32f2xx.h"
+#include "stm32f4xx.h"
 #include "common_config.h"
 #include "conf.h"
 #include "main.h"
@@ -15,7 +15,7 @@
 #include "tinystdio.h"
 #include "time.h"
 #include "string.h"
-#include "stm32f4xx_eth.h"
+#include "stm32f4x7_eth.h"
 #include "netconf.h"
 #include "rng.h"
 #ifdef SD_ENABLE

+ 1 - 1
iap/stm32sprog/serial.c

@@ -1,6 +1,6 @@
 #include "serial.h"
 
-#include "stm32f2xx_usart.h"
+#include "stm32f4xx_usart.h"
 
 #include "tinystdio.h"
 

+ 1 - 1
iap/stm32sprog/serial.h

@@ -11,7 +11,7 @@
 #include <stdint.h>
 #include "usart.h"
 
-#define USARTn  SWC_USART
+#define USARTn  USER_USART
 
 #define MAX_READ_RETRIES 50000000
 

+ 2 - 2
iap/stm32sprog/stm32sprog.c

@@ -3,8 +3,8 @@
 #include <stdint.h>
 #include "tinystdio.h"
 #include <string.h>
-#include "stm32f2xx_usart.h"
-#include "stm32f2xx_crc.h"
+#include "stm32f4xx_usart.h"
+#include "stm32f4xx_crc.h"
 #include "stm32sprog.h"
 #include "serial.h"
 #include "systick.h"

+ 1 - 1
iap/stm32sprog/stm32sprog.h

@@ -8,7 +8,7 @@
 #ifndef SRM32SPROG_H_
 #define SRM32SPROG_H_
 
-#include "stm32f2xx_usart.h"
+#include "stm32f4xx_usart.h"
 #include "gpio_io.h"
 
 #include "serial.h"