zliudr wrote:
If I want to do a delay, is there a convenience function like the delay() in arduino? I'm using a while loop with the vTaskDelay.
vTaskDelay() should work as a simple delay.
vTaskDelay() essentially blocks the calling task (thread) for a specified number of FreeRTOS ticks. However, since its resolution is FreeRTOS ticks, you should not expect the delay to be high resolution or high accuracy (i.e., the exact delay interval that occurs may be affected by other factors such as higher priority tasks).
zliudr wrote:If I am in the main program, can I still use vTaskDelay?
Do you mean
app_main()? If so, then yes,
app_main() is a function that is simply called from the main task (thread) which in turn is created automatically on startup.
zliudr wrote:What should be the minimal delay for vTaskDelay call?
The unit of delay used in
vTaskDelay() is in terms of FreeRTOS ticks. The FreeRTOS tick frequency is set by default to 100Hz, meaning a tick will occur every 1ms. Therefore calling
vTaskDelay(1) will block the calling task by 1ms. Note that you can change the FreeRTOS tick frequency using menuconfig.
You can also use the
pdMS_TO_TICKS() macro which will convert a delay interval in ms to the equivalent of FreeRTOS ticks. For example, calling
vTaskDelay(pdMS_TO_TICKS(1500)) to delay for 1500ms will be equivalent to calling
vTaskDelay(150).