I want to build a device that contains a Raspberry Pi and a STM32F103 based MCU. It should run either with an external 5V power supply or with a built in LiPo battery. To keep things simple, most of the parts for the charging circuit should be off-the-shelf modules. I chose a TP4056 based board with battery protection as charger, a MT3608 based board as step up converter, and a MAX17043 board as battery fuel gauge.
The device will have a single power switch to turn the device on and off.
I'm especially not sure about the use of the different MOSFETs to control various modes of behaviour. Maybe you could tell me wether my design works as intended.
My design for the power delivery part of the box is this:
There's a fuse and a Zener diode (5.6V) to protect the device from high voltages due to wrong power supplies.
Q101 is a n-channel MOSFET, which disconnects the charger board from the input voltage rail if no plug is connected (with no plug inserted, the gate is pulled low via the switch in the DC connector, when a plug is inserted, gate is pulled high via R101).
This part of the circuit is there to prevent the battery essentially charging itself via the output voltage of the DC-DC converter. A diode at the right place would be a simpler solution, but would have unwanted voltage drop due to the forward voltage.
Q103 is a p-channel MOSFET, which disconnects the DC-DC converter from the battery if there is a DC plug plugged in. There is a second pullup to the battery, both pullups are isolated from each other by diodes.
The gate of Q102 is connected to the power switch and the MCU (not in the schematic). If no plug is plugged in, when you press the power switch, the MT3608 gets an input voltage and then there's +5V on the first power rail, which is connected to the MCU. The MCU then keeps the gate of Q102 pulled low, so it stays on. If a plug is plugged in, the MCU is on anyways. The MCU checks the battery levels, and gives them out via WS2812B LEDs (they are there for the main use of the device). After pressing the power switch for some time longer, the MCU pulls the gate of Q103 (another p-channel MOSFET) low, too. So the main system (Raspberry Pi and the rest of the WS2812B LEDs) boots up. The power button is connected to the MCU on two pins, one as output for pulling Q102 low, and one as input, with a diode and a pullup, to sense when the power switch is pressed.
If the system is on, and the power switch is pressed for some seconds, the MCU sends a signal to the Raspi to shut down, and then after some time turns off main power via Q103. If the system is running on battery, the MCU will then turn of Q102, essentially killing itself, unless there is a DC plug connected, then it will monitor the charging of the batteries?
Will the system work like this, or do I have to change something?