Electronic – Is it safe to drive P-channel MOSFET gate directly from an MCU pin and 12V pull-up

microcontrollermosfet

I was wondering how reliable it would be to drive a P-channel MOSFET directly from a micro-controller pin like this:

schematic

simulate this circuit – Schematic created using CircuitLab

When I want the FET to be ON I make the pin output low (connecting the gate to the ground).
When I want the FET to be OFF I make the pin input (high impedance), pulling the gate to 12V through R1.
The only problem I see is that when OFF, the MCU pin will "see" 12V through R1, but I am thinking it shouldn't really be a problem, since R1 is quite high and the impedance of the pin itself is much higher, so there shouldn't really be any danger for the pin. Or am I wrong?
Obviously, we're not talking high switching speeds here, just turning stuff on and off from an MCU.
I know it is usually done with a BJT or N-channel MOSFET acting as "gate driver" for the P-channel MOSFET. The question is, what will go wrong if I try to skip it?
I don't have a specific MCU in mind, could be an ATTiny monitoring the input voltage and deciding whether or not to pass it to the rest of the circuit or an ESP8266 turning stuff on and off over the internet and whatnot.

Best Answer

Good question. You are wise to ask.

This is not recommended. Sometimes MCU inputs specify that a certain amount of current can be injected through the protection diodes. You will have to check the MCU you eventually settle on. Select a pullup that will insure you stay under the maximum allowable current. But it would probably just be easier to add an additional NPN or N-channel (BSS138) to pull down the gate of the PMOS. Then there is no problem and you are free to choose any MCU, because it will never "see" 12 V.

Edit: I was only thinking about damage to the MCU. But @abdullah kahraman raises another equally important point. The diode current will also cause the PMOS to turn on. So this just plain won't work.