Electronic – Best way to have circuit powered by USB when plugged in and battery when not

multiplexerpower supply

I am building a circuit that uses a rechargeable battery and also has a USB port so it can be plugged in to charge the battery and power the system.

I am using a buck/boost converter to supply 3.3V for the circuit. I want the input for the converter to be the battery voltage when not connected to USB, but when plugged in, I want the input to be the USB.

One way I thought to do this was with a low forward voltage drop diode in series with each supply. Think it would work, but still some voltage drop, not the most efficient.

Using Diodes

Another way I thought would be with a P channel FET that switches the battery voltage off when USB 5V is at the gate. Seems like the better method.

Using P Channel MOSFET

Would either of these solutions work?
Thanks

EDIT

Following the advice given, this solution seems like it should work:
*Note the symbol for P channel Fet was re drawn from original image so that source is on top and drain on bottom

enter image description here

Best Answer

I just asked a similar question here. One answer was what you proposed in your first circuit, but the diodes need to be ideal and the voltages need to be the same. See user 比尔盖子's answer.

The solution I chose was a premade power supply mux from Pololu:

https://www.pololu.com/product/2596

US$5 and does everything I need it to, and can handle different voltages.

EDIT: Also, you will need a buck/boost on the output of circuit to maintain consistent voltage (LiPo won't be 5V exactly so your Vout will jump around without it). I also discovered you need a lot of cap on Vout because the IR droop from the switching will cause circuits to brownout and/or reset.