fix(vd960DBN): MQTT buffer 从栈改为 static,防止栈溢出 (栈仅 2KB)
iot_mqtt_send_connect: opts(~85B) + buf[256] → static (~340B 省) iot_mqtt_send_subscribe: buf[256] → static (256B 省) iot_mqtt_publish: buf[2048] → static (2KB 省) 调用链 WCHNET_HandleGlobalInt → iot_mqtt_handle_sock_int → iot_mqtt_send_connect 会叠加 WCHNET 协议栈内部开销, 2048B 栈极易溢出导致 hard fault(现象:乱码+truncated日志+重启)
This commit is contained in:
@@ -77,10 +77,12 @@ static int iot_mqtt_send(const uint8_t *buf, uint16_t len) {
|
|||||||
|
|
||||||
/* 发送 MQTT CONNECT */
|
/* 发送 MQTT CONNECT */
|
||||||
static int iot_mqtt_send_connect(void) {
|
static int iot_mqtt_send_connect(void) {
|
||||||
MQTTPacket_connectData opts = MQTTPacket_connectData_initializer;
|
static MQTTPacket_connectData opts; // static: 避免 85字节栈开销
|
||||||
uint8_t buf[256];
|
static uint8_t buf[256]; // static: 避免 256字节栈开销
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
opts = MQTTPacket_connectData_initializer;
|
||||||
|
|
||||||
opts.MQTTVersion = 4; // MQTT 3.1.1
|
opts.MQTTVersion = 4; // MQTT 3.1.1
|
||||||
opts.keepAliveInterval = IOT_MQTT_KEEPALIVE_SEC;
|
opts.keepAliveInterval = IOT_MQTT_KEEPALIVE_SEC;
|
||||||
opts.cleansession = 1;
|
opts.cleansession = 1;
|
||||||
@@ -112,7 +114,7 @@ static int iot_mqtt_send_connect(void) {
|
|||||||
|
|
||||||
/* 发送 MQTT SUBSCRIBE */
|
/* 发送 MQTT SUBSCRIBE */
|
||||||
static int iot_mqtt_send_subscribe(void) {
|
static int iot_mqtt_send_subscribe(void) {
|
||||||
uint8_t buf[256];
|
static uint8_t buf[256]; // static: 避免栈溢出
|
||||||
int len;
|
int len;
|
||||||
char topic[IOT_MQTT_TOPIC_MAX_LEN];
|
char topic[IOT_MQTT_TOPIC_MAX_LEN];
|
||||||
MQTTString topics[3];
|
MQTTString topics[3];
|
||||||
@@ -142,7 +144,7 @@ static int iot_mqtt_send_subscribe(void) {
|
|||||||
/* 发送 MQTT PUBLISH */
|
/* 发送 MQTT PUBLISH */
|
||||||
static int iot_mqtt_publish(const char *topic, const char *payload,
|
static int iot_mqtt_publish(const char *topic, const char *payload,
|
||||||
uint16_t payload_len, uint8_t qos) {
|
uint16_t payload_len, uint8_t qos) {
|
||||||
uint8_t buf[IOT_MQTT_SEND_BUF_LEN];
|
static uint8_t buf[IOT_MQTT_SEND_BUF_LEN]; // static: 避免 2KB 栈溢出
|
||||||
int len;
|
int len;
|
||||||
MQTTString mqtt_topic = MQTTString_initializer;
|
MQTTString mqtt_topic = MQTTString_initializer;
|
||||||
mqtt_topic.cstring = (char *)topic;
|
mqtt_topic.cstring = (char *)topic;
|
||||||
|
|||||||
Reference in New Issue
Block a user