ESP32, Arduino Core 3.2.0 bug?

I wrote a simple sketch, using an Arduino framework, It just displays pin 16 state: reserved or not.

Sketch outputs:

....
Pin 16 is not reserved
Pin 16 is not reserved
Pin 16 is not reserved
...

Next step is that I initialize UART2 on pins 16 and 17 (IO_MUX pins), by calling uartBegin():

......
[ 13259][V][esp32-hal-uart.c:552] uartBegin(): UART2 baud(115200) Mode(8000001c) rxPin(16) txPin(17)
[ 13269][V][esp32-hal-uart.c:650] uartBegin(): UART2 not installed. Starting installation
[ 13277][V][esp32-hal-uart.c:660] uartBegin(): UART2 RX FIFO full threshold set to 112 (value requested: 112 || FIFO Max = 128)
[ 13289][V][esp32-hal-uart.c:681] uartBegin(): Setting UART2 to use REF_TICK clock
[ 13298][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 16 successfully set to type UART_RX (2) with bus 0x3ffbdd18
[ 13309][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 17 successfully set to type UART_TX (3) with bus 0x3ffbdd18
[ 13320][V][esp32-hal-uart.c:732] uartBegin(): UART2 initialization done.

Sketch outputs:

....
Pin 16 is reserved
Pin 16 is reserved
Pin 16 is reserved
Pin 16 is reserved
....

Now, shut down UART2 via uartEnd():

[ 19051][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 16 successfully set to type INIT (0) with bus 0x0
[ 19063][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 17 successfully set to type INIT (0) with bus 0x0

Sketch outputs:

Pin 16 is reserved
Pin 16 is reserved
Pin 16 is reserved
Pin 16 is reserved

Which is obviously wrong. IDF guys says that they have checked call sequence, and deinstalling an UART driver must call _revoke() on UART's pins.

The exactly same happens to the I2C interface: initialize it, deinitialize it and GPIOs remain reserved.

The sketch itself is:

#include <Arduino.h>


#if __has_include("esp_private/esp_gpio_reserve.h")
#  include "esp_private/esp_gpio_reserve.h"
#elif __has_include("esp_gpio_reserve.h")
#  include "esp_gpio_reserve.h"
#else
#  warning "esp_gpio_reserve.h is not found, lets see if it will compile at all"
#endif


void setup() {
  Serial.begin(115200);
}

void loop() {
  while(1) {
    printf("Pin 16 is %sreserved\r\n",esp_gpio_is_reserved(1ULL << 16) ? "" : "not ");
    delay(1500);
  }
}

UART was initialized and deinited in another FreeRTOS task.

In addition to the above: if i keep creating/deleting UART2 on every pin available they all eventually become reserved.

Sounds like you may need to speak to Expressif, they would have access to the detail of what is going on inside their core.

It turned out it was fixed by recent commit.
Now waiting for this patch to appear in Arduino Core's IDF version..