Using TX and RX as GPIO
If your circuit uses TX (GPIO1) as an output and RX (GPIO3) as an input then all you need to do is not call Serial.begin( ) as this is the default setting for GPIO3.If you need to use GPIO1 as an input or GPIO3 as an output, then you only need to call the appropriate pinMode( ) either INPUT, INPUT_PULLUP or OUTPUT.
Remember the ESP8266 ALWAYS outputs a start up message on GPIO1, so for that short time GPIO1 is ALWAYS an output. So be sure to add a series 330R resistor between GPIO1 and whatever output is driving that input to prevent shorting things out during the startup message.
TX GPIO1
Remember the ESP8266 ALWAYS outputs a start up message on GPIO1, so for that short time GPIO1 is ALWAYS an output. So be sure to add a series 330R resistor between GPIO1 and whatever output is driving that input to prevent shorting things out during the startup message.
GPIO2 (TX only) by starting Serial1
To keep the debugging simple, you can also choose to keep using TX as the standard debug output while freeing up RX (GPIO3) as an input by using the Serial.begin( ) statement
Serial.begin(115200,SERIAL_8N1,SERIAL_TX_ONLY);
This allows you to use RX as normal I/O, while still writing debug messages to Serial.
Or
Serial.begin(115200,SERIAL_8N1,SERIAL_RX_ONLY);
which allows you to receive Serial input but not send output, but leaves GPIO1 available for general I/O use.
Again add a 330 ohm resistor between the RX lead to the Flash programmer TX connection to protect against shorting out the programmer's or the ESPs pin if it connected while RX is an output.