When 5 V is available and Vin is not available
- In the beginning only the body diode of T1 conducts.
- Hence, there will be (5V - diode drop) at the source of T1.
- that is only momentary,because, now we have a valid Source voltage. Gate is pulled low to ground via R9 (10kohm).
- Now, Since, Vgs is more negative, PMOS is ON. Once it is on, diode gets bypassed by the MOSFET. Hence, one will get almost 5V finally for the 3.3 V regulator .
- One can assume, the low on-resitance of PMOS will certainly create very
low ohmic drop.
When 5 V is available and Vin is also available
- The body diode may conduct in the beginning if 5 V is plugged in first.
- The MOSFET too may turn on sooner and provide almost 5 V to 3.3 V regulator
- As soon as Vin is connected (assuming that Vin is greater than 5 V), the MOSFET turns off because VGS is no more a negative value.
- The current from USB will no longer be used because, the strong 5 V is available from 5 V regulator which is now powered from Vin.
When 5 V is not available and Vin is available
- T1 will not be in the picture
- T2 body diode can conduct and supply Vin to the U2 ( 5V regulator)
- 5 V regulator will feed the 3.3 V regulator as previous case
Function of D2
There is a reset switch. Any spike arising out of the reset switch due to debounce can be sometimes higher than 5 V supply itself. This may inherently cause damage to the RESET pin of the MCU. Hence, placing the diode will start to conduct when voltage higher than 5.4 V (example) is present at the output of the switch.
Consider it like a clamping circuit and clamping voltage is set to 5 V plus the forward voltage of the diode.
Normally, there will also be diodes internal to the MCU pin for protection, but placing the external diode is definitely a good practice. The internal one is for emergency use only, i would say.