rx_task栈空间不足***ERROR*** A stack overflow in task uart_rx_task has been detected.

GalaxyNeo
Posts: 1
Joined: Tue Mar 19, 2024 6:35 am

rx_task栈空间不足***ERROR*** A stack overflow in task uart_rx_task has been detected.

Postby GalaxyNeo » Tue Mar 19, 2024 6:46 am

  1. static void rx_task(void *arg)
  2. {
  3.     static const char *RX_TASK_TAG = "RX_TASK";
  4.     esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
  5.     uint8_t* RXdata = (uint8_t*) malloc(RX_BUF_SIZE+1);
  6.  
  7.     while (1) {
  8.         const int rxBytes = uart_read_bytes(UART_NUM_2, RXdata, RX_BUF_SIZE, 2000 / portTICK_PERIOD_MS);
  9.         if (rxBytes > 0) {
  10.             RXdata[rxBytes] = '\0'; // 添加字符串结束符
  11.             ESP_LOGI(RX_TASK_TAG, "Read %d bytes: '%s'", rxBytes, RXdata);
  12.             ESP_LOG_BUFFER_HEXDUMP(RX_TASK_TAG, RXdata, rxBytes, ESP_LOG_INFO);
  13.             //esp_mqtt_client_publish(MQTT_client, AliyunPublishTopic_user_update, (char *)RXdata, rxBytes, 1, 0);
  14.  
  15.             // 构建 JSON 字符串
  16.             char json_message[512]; // 假设消息长度不超过 512 个字符
  17.             snprintf(json_message, sizeof(json_message), "{\"method\":\"thing.service.property.set\",\"id\":\"1428164640\",\"params\":{\"MS72SF1:RemainParkSpace\":%s},\"version\":\"1.0.0\"}", RXdata);
  18.             esp_mqtt_client_publish(MQTT_client, AliyunPublishTopic_user_update, json_message, strlen(json_message), 1, 0);
  19.         }
  20.     }
  21.     free(RXdata);
  22. }
每当运行到 snprintf(json_message, sizeof(json_message), "{\"method\":\"thing.service.property.set\",\"id\":\"1428164640\",\"params\":{\"MS72SF1:RemainParkSpace\":%s},\"version\":\"1.0.0\"}", RXdata);这一句的时候,都会因为***ERROR*** A stack overflow in task uart_rx_task has been detected.而重启,是什么导致栈空间不足。

Who is online

Users browsing this forum: No registered users and 220 guests