How should we protect GPIOs from unwanted conditions such as short circuit, high voltage, etc. Is it sufficient to use a series resistor especially when the pin is driving a CMOS device? how large should it be?
Adding to the colleagues above, in case of using the pin in output mode you can use optical couplers for electrically isolating the output from any miss operation specially when driving power switching circuits operating at higher voltages than TTL levels.
In case of using the pin as an input it is recommend to make voltage protection by using Zener diode in parallel with the pin.
Ali Mosahebfard As a rule of thumb, if the GPIO signal doesn't cross the border of the PCB (i. e. isn't routed to a connector) there is no need for special protection.
If the IO pin is driving a CMOS input you could use a series resistor as protection. The lower limit of the resistance is given by the maximum output current (and the maximum current through internal protection diodes if the external voltage exceeds the GND and VDD rails), and by the external voltage in the worst case. (With moderate external voltages something between 1 kOhm and 10 kOhm.)
The upper limit is given by the maximum input current of the driven input, and the input voltage specification of the driven device. However, you have to keep in mind that the series resistor and the input capacitance form a low pass filter which causes a signal delay. If the temporal behavior of the signal is critical, the resistance has to be much lower than permitted by the static case (> 100 kOhm).
Alternatively, one can use additional clamping diodes (more rugged than the ones usually integrated in the IO) and a relatively low series resistor (e. g. 100 Ohm).
For signals with low rise/fall time, and traces/wires longer than about 1/10 of the wavelength, one has to take reflections into account. In this case, the series resistors (if any) are determined by the requirement to keep reflections low, and clamping diodes are mandatory if the coupling to high voltage sources is to be expected.
Adding to the colleagues above, in case of using the pin in output mode you can use optical couplers for electrically isolating the output from any miss operation specially when driving power switching circuits operating at higher voltages than TTL levels.
In case of using the pin as an input it is recommend to make voltage protection by using Zener diode in parallel with the pin.