Heap and stack collision
Risposta
08/08/19 13.41

Dear All,

i am facing a Heap and stack collision situation using the cJON library v1.7.12.

i have followed the example and create 

char * getAccJsonData(void){
	 char *string = NULL;
	 cJSON *accXArr = NULL;
	/* cJSON *accY = NULL;
	 cJSON *accZ = NULL;*/
	 size_t index = 0;

	 cJSON *accData = cJSON_CreateObject();
	 	if(accData == NULL){
	 		goto end;
	 	}
	cJSON_AddStringToObject(accData, "id", "1704342");
	cJSON_AddNumberToObject(accData, "aquisitionTime", 111111);

	accXArr = cJSON_AddArrayToObject(accData, "AccX");
		if (accXArr == NULL)
		{
			goto end;
		}

   for(index = 0; index < (sizeof(PublishAccData.X) / sizeof(int32_t)) ; index++ ){
	   cJSON *accXObj = cJSON_CreateObject();
	   accXObj = cJSON_CreateNumber(10);

	   if (accXObj == NULL)
		   {
			   goto end;
		   }

	   cJSON_AddItemToArray(accXArr, accXObj);
	   }


   string = cJSON_Print(accData);
	   if (string == NULL) {
		   fprintf(stderr, "Failed to print accData.\n");
	   }

	end:
		cJSON_Delete(accData);
		return string;
}

i had create two tasks, one getting sensor values and the other calling the above function

static void PublishData(void * pvParameters){

	BCDS_UNUSED(pvParameters);

	while(1){
		vTaskDelay(XDK_APP_DELAY);

		/*char *envData = createEnvJson();
		printf("%s\r\n", envData);
		free(envData);*/

		char *accData = getAccJsonData();
		printf("%s\r\n", accData);
		free(accData);
	}
}

and the 

static void AppControllerEnable(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    /* @todo - Enable necessary modules for the application and check their return values */
    if(RETCODE_OK == retcode){
    	retcode = Sensor_Enable();
    }
    if (RETCODE_OK == retcode)
    {
        if (pdPASS != xTaskCreate(AppControllerFire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle))
        {
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
        if(pdPASS != xTaskCreate(PublishData,(const char * const) "PublishData", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &PublishControllerHandle)){
        	retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
    }
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerEnable : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
    Utils_PrintResetCause();
}

the Task for getting the sensor values

static void AppControllerFire(void* pvParameters)
{
    BCDS_UNUSED(pvParameters);
    Retcode_T retcode = RETCODE_OK;
    Sensor_Value_T sensorValue;

    memset(&sensorValue, 0x00, sizeof(sensorValue));

   // PublishEnvData.SntpTimeStamp = 1565084525; //for testing purposes TODO Remove it

    /* A function that implements a task must not exit or attempt to return to
     its caller function as there is nothing to return to. */
    while (1)
    {
        /* code to implement application control flow */
        vTaskDelay(XDK_APP_DELAY);

        if(RETCODE_OK == retcode){
        	retcode = Sensor_GetData(&sensorValue);
        }

       /* PublishEnvData.SntpTimeStamp += 1; //emulation
        PublishEnvData.Temp = (sensorValue.Temp /= 1000);
        PublishEnvData.Pressure = sensorValue.Pressure;
        PublishEnvData.RH = sensorValue.RH;
        //TODO - Put that in another Task every 25 ms
        PublishAccData.X[0] = sensorValue.Accel.X;
        PublishAccData.Y[0] = sensorValue.Accel.Y;
        PublishAccData.Z[0] = sensorValue.Accel.Z;*/

        if (RETCODE_OK != retcode)
		{
			Retcode_RaiseError(retcode);
		}
    }
}

I am getting 

INFO | XDK DEVICE 1: Heap and stack collision

after some minutes....

What i am doing wrong, any comments and suggestions are more than welcome.

Thank you ....

0 (0 Voti)
RE: Heap and stack collision
Risposta
09/08/19 11.24 come risposta a Andreas Mantelos.

Hi Andreas,

I'm not sure if this will work but try to define the TOTAL_HEAP_SIZE differently in the file SDK/xdk110/Common/config/AmazonFreeRTOS/FreeRTOS/FreeRTOSConfig.h (line 110).
For example try this:
#define configTOTAL_HEAP_SIZE (( size_t )(60 * 1024 ))
Let me know if that helped.

regards

Saeid

0 (0 Voti)