delay a freeRTOS (ESP32 / 8266) task with resume using semaphore

On an ESP32 under freeRTOS there should be no code in the loop().

You can use events or the below method to delay a freeRTOS loop

Not tested.

#include "esp_system.h" //This inclusion configures the peripherals in the ESP system.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"

////
void setup() {
  Serial.begin(115200);
  xTaskCreate(vATask, "vATask Loop", 10000, NULL, 1, NULL);
}
////
void loop() {}
////
// task to be delayed
void vATask( void * pvParameters )
{
  const TickType_t xFrequency = pdMS_TO_TICKS( 5000 );
TickType_t xLastWakeTime = xTaskGetTickCount();
  while (1)
  {

    Serial.println("Begin Loop");
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
    Serial.println("End Loop");
    xLastWakeTime = xTaskGetTickCount();
  }
  vTaskDelete(NULL);
}
////

Whiles semaphores can be used to hold loops, the better use for a semaphore is when dealing with shared resourses, especially across the core of the ESP32.

FreeRTOS API categories <<< frrRTOS API reference.