#if CONFIG_FREERTOS_UNICORE
#define ESP32_RUNNING_CORE 0
#else
#define ESP32_RUNNING_CORE 1
#endif
// Performing some mundane tasks
void testTask(void *parameter)
{
while(1)
{
int a;
int b[100];
// Using non-optimized array in the compiler
for(int i=0;i<100;i++)
{
b[i] = a+1;
}
Serial.println(b[0]);
// Print out remaining stack memory words
Serial.print("High Water mark(Words)");
Serial.println(uxTaskGetStackHighWaterMark(NULL));
//Print out number of free heap memory bytes before malloc
Serial.print("Heap before malloc (bytes): ");
Serial.println(xPortGetFreeHeapSize());
int *ptr = (int*)pvPortMalloc(1024*sizeof(int));
for (int i=0;i<1024;i++)
{
ptr[i]=3;
}
// Print out number of free heap memory bytes after malloc
Serial.print("Heap after malloc(bytes)");
Serial.println(xPortGetFreeHeapSize());
// Free up the port memory
vPortFree(ptr);
vTaskDelay(1000/portTICK_PERIOD_MS);
//Wait for the delay
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// Adding a delay, so Serial output is not missed
vTaskDelay(1000/portTICK_PERIOD_MS);
Serial.println();
Serial.println("------FreeRTOS memory demo------");
xTaskCreatePinnedToCore(
testTask,
"Test Task",
1506,
NULL,
1,
NULL,
ESP32_RUNNING_CORE);
vTaskDelete(NULL);
// Delete "setup and loop" task
vTaskDelete(NULL);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}