From 349b5cbd355cfb4aa059e4251abd60d798648805 Mon Sep 17 00:00:00 2001 From: Skot Date: Fri, 9 Aug 2024 16:27:29 -0400 Subject: [PATCH] reduce ASIC serial RX buf to 16 bytes (from 1024). make sure to free() after every nvs_config_get_string() --- components/bm1397/bm1366.c | 4 ++-- components/bm1397/bm1368.c | 4 ++-- components/bm1397/bm1397.c | 4 ++-- components/bm1397/include/serial.h | 2 +- components/bm1397/serial.c | 2 +- main/http_server/http_server.c | 1 + 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/bm1397/bm1366.c b/components/bm1397/bm1366.c index dcfc72eaa..a2186c381 100644 --- a/components/bm1397/bm1366.c +++ b/components/bm1397/bm1366.c @@ -57,7 +57,7 @@ typedef struct __attribute__((__packed__)) static const char * TAG = "bm1366Module"; -static uint8_t asic_response_buffer[CHUNK_SIZE]; +static uint8_t asic_response_buffer[SERIAL_BUF_SIZE]; static task_result result; /// @brief @@ -523,7 +523,7 @@ uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count) { ESP_LOGI(TAG, "Initializing BM1366"); - memset(asic_response_buffer, 0, 1024); + memset(asic_response_buffer, 0, SERIAL_BUF_SIZE); esp_rom_gpio_pad_select_gpio(BM1366_RST_PIN); gpio_set_direction(BM1366_RST_PIN, GPIO_MODE_OUTPUT); diff --git a/components/bm1397/bm1368.c b/components/bm1397/bm1368.c index ae1c9d0f9..6ee5ce9b5 100644 --- a/components/bm1397/bm1368.c +++ b/components/bm1397/bm1368.c @@ -57,7 +57,7 @@ typedef struct __attribute__((__packed__)) static const char * TAG = "bm1368Module"; -static uint8_t asic_response_buffer[CHUNK_SIZE]; +static uint8_t asic_response_buffer[SERIAL_BUF_SIZE]; static task_result result; /// @brief @@ -402,7 +402,7 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count) { ESP_LOGI(TAG, "Initializing BM1368"); - memset(asic_response_buffer, 0, 1024); + memset(asic_response_buffer, 0, SERIAL_BUF_SIZE); esp_rom_gpio_pad_select_gpio(BM1368_RST_PIN); gpio_set_direction(BM1368_RST_PIN, GPIO_MODE_OUTPUT); diff --git a/components/bm1397/bm1397.c b/components/bm1397/bm1397.c index dbe426576..b2f755453 100644 --- a/components/bm1397/bm1397.c +++ b/components/bm1397/bm1397.c @@ -56,7 +56,7 @@ typedef struct __attribute__((__packed__)) static const char *TAG = "bm1397Module"; -static uint8_t asic_response_buffer[CHUNK_SIZE]; +static uint8_t asic_response_buffer[SERIAL_BUF_SIZE]; static uint32_t prev_nonce = 0; static task_result result; @@ -287,7 +287,7 @@ uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count) { ESP_LOGI(TAG, "Initializing BM1397"); - memset(asic_response_buffer, 0, sizeof(asic_response_buffer)); + memset(asic_response_buffer, 0, SERIAL_BUF_SIZE); esp_rom_gpio_pad_select_gpio(BM1397_RST_PIN); gpio_set_direction(BM1397_RST_PIN, GPIO_MODE_OUTPUT); diff --git a/components/bm1397/include/serial.h b/components/bm1397/include/serial.h index ae165c138..163d7afc3 100644 --- a/components/bm1397/include/serial.h +++ b/components/bm1397/include/serial.h @@ -1,7 +1,7 @@ #ifndef SERIAL_H_ #define SERIAL_H_ -#define CHUNK_SIZE 1024 +#define SERIAL_BUF_SIZE 16 int SERIAL_send(uint8_t *, int, bool); void SERIAL_init(void); diff --git a/components/bm1397/serial.c b/components/bm1397/serial.c index 088b15afe..750411a62 100644 --- a/components/bm1397/serial.c +++ b/components/bm1397/serial.c @@ -85,7 +85,7 @@ int16_t SERIAL_rx(uint8_t *buf, uint16_t size, uint16_t timeout_ms) void SERIAL_debug_rx(void) { int ret; - uint8_t buf[CHUNK_SIZE]; + uint8_t buf[100]; ret = SERIAL_rx(buf, 100, 20); if (ret < 0) diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index 392332e40..222228f59 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -347,6 +347,7 @@ static esp_err_t GET_swarm(httpd_req_t * req) char * swarm_config = nvs_config_get_string(NVS_CONFIG_SWARM, "[]"); httpd_resp_sendstr(req, swarm_config); + free(swarm_config); return ESP_OK; }