Does debug change the pin function of GPIO2? Would reassigning the pin function eliminate the problem of debug writing to TX? The pin could be disconnected when flashing, but used as GPIO input after normal boot (run mode).
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO1_U, FUNC_GPIO1)