How to fix ESP32 FreeRTOS error: too few arguments to function 'void vPortEnterCritical(portMUX_TYPE*)'
Problem:
On FreeRTOS on the ESP32, you want to use a critical zone like this:
portENTER_CRITICAL();
// Your critical code goes here!
portEXIT_CRITICAL();
but while compiling the procject, you see an error message like
src/main.cpp: In function 'void MyFunc(size_t, int16_t)':
/home/uli/.platformio/packages/framework-arduinoespressif32@src-f2ea83e2545300b10a69ff44ef9dc6cd/tools/sdk/esp32/include/freertos/port/xtensa/include/freertos/portmacro.h:476:75: error: too few arguments to function 'void vPortEnterCritical(portMUX_TYPE*)'
#define portENTER_CRITICAL(mux) vPortEnterCritical(mux)
Solution
You need to use portENTER_CRITICAL()
and portEXIT_CRITICAL()
with a spinlock, i.e.
portENTER_CRITICAL(&mySpinlock);
// TODO Your critical code goes here!
portEXIT_CRITICAL(&mySpinlock);
In order to see a full example on how to initialize a spinlock in FreeRTOS and use it for critical zones, see our previous post ESP32 critical zone example using FreeRTOS / PlatformIO