This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220S中的MQTT demo 程序中的client thread 竟然创建失败?

Other Parts Discussed in Thread: CC3220S, SYSBIOS

用 mqtt_client_CC3220S_LAUNCHXL_tirtos_ccs sample 程序。

在mainthread中,用malloc 分配了一个11KB的内存块,mqtt client创建、运行正常。

但是,增大到16KB 就失败。

此时,串口打印的消息如下:

..

Client Thread Create Failed failed
MQTT Client lib initialization failed

..

这是什么原因? 改回11KB 后恢复正常。TI RTOS 默认的heapSize设置太小? 

经查看,是如下函数返回值有误。

lRetVal  |=  pthread_create(&g_rx_task_hndl, &pAttrs, MqttClientThread,
(void *) &threadArg);
if(lRetVal != 0)
{
UART_PRINT("Client Thread Create Failed failed\n\r");
gInitState &= ~CLIENT_INIT_STATE;
return(-1);
}

  • 谢谢指导!但是,链接里描述的是基于CCS4的设置方法,现在我用的是CCS8.1 ,依然没找到在哪里可设置这个线程的 heapSize?
  • 尝试在mqtt 配到的 release.cfg文件中增加:
    heapMemParams.size = 18432; // 默认是 4096
    问题依然: 11KB 能工作,16KB失败。 难道不是heapSize的问题?

    /* ================ Memory configuration ================ */
    var Memory = xdc.useModule('xdc.runtime.Memory');
    /*
    * The Memory module itself simply provides a common interface for any
    * variety of system and application specific memory management policies
    * implemented by the IHeap modules(Ex. HeapMem, HeapBuf).
    */

    /*
    * Use HeapMem primary heap instance to use linker-defined memory region
    * Add HeapTrack on top to find over-writes, invalid frees, and
    * aid in finding the correct sizing of the heap and memory leaks.
    */
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    HeapMem.primaryHeapBaseAddr = "&__primary_heap_start__";
    HeapMem.primaryHeapEndAddr = "&__primary_heap_end__";

    var heapMemParams = new HeapMem.Params();
    heapMemParams.usePrimaryHeap = true;


    heapMemParams.size = 18432;

    Program.global.heap0 = HeapMem.create(heapMemParams);

    Memory.defaultHeapInstance = Program.global.heap0;

  • 创建线程的时候不是要设置堆栈大小吗?
    比如lRetVal = osi_TaskCreate(MqttClient,
    (const signed char *)"Mqtt Client App",
    OSI_STACK_SIZE, NULL, 2, NULL );
    然后里面也有利用内存分配函数操作的。
  • 有设置堆栈大小的参数,很奇怪将堆栈调小,虽没彻底解决,但是有所改善。
  • 在项目属性----ARM linker --------basic options 页面里尝试修改 heapSize 和Stacksize , 都没有效果。为什么? 这个地方的设置和 cfg文件里的 heapMEM 设置 是什么关系?