USB and Battery switching circuit not working [and buck boost converter not working either]
am trying to build a circuit which provides 3.3V power to a micro-controller (Nordic Semi nRF52840). Absolute maximum range of voltage should be 1.8V to 3.6V. Maximum power consumption would be 140mA. It should use battery power when USB is not connected and use USB power when connected (ideally without resetting). Efficiency is not super critical because I am planning to use a recharging circuit for LiPo battery if this works, but it would be ideal to get 2 weeks standby time.

Pretty much any Low Drop-Out Regulator should work to regulate the 3.8V nominal voltage of a Lipo battery. The AMS1117 is not really a good match because it is not an LDO. Try the AP2112K. You don't need a buck boost converter, since your current consumption is also not that high, hence your power loss is negligible. Here is an example from a previous project I had, that I know works.

When it comes to auto voltage selection it is less intuitive if you are new to electronics but this circuit should work for that purpose.

You don't need D2 and the 5V rail if you don't want an external 5V input pin other than the USB port. The Switch-In would be is your Regulator input.
Also you may want to use polarized tantalum capacitors instead of ceramic ones for C9 and C11.
If you want to trouble shoot the design you provided above:

Try running a spice simulation, it helps a lot

If you have an oscilloscope try monitoring what is going on individual nets. Compare what you see to how it should look like and try to identify the problem step by step.


Edit to explain how the auto select circuit works:
The way my Auto select circuit works is like this:

Ubat: not connected ; VBus: 5V : the current flows through D1 to Vin, other components can be ignored.
Ubat: 3,8V, VBus not connected: Q3 is on, because its gate is connected to ground through R14. So it can supply Vin of the regulator
Ubat 3,8V; VBus: 5V; the gate of Q3 is pulled high so it doesn't conduct, Current flows through D1 again as in (1).

The circuit you provided works pretty much the same way. I am not sure as to why he also used the bipolar transistors. I am sure someone else can explain why he did that.
Edit that comes after edit:
It appears he made a mistake wiring the PMOS in his design, mixing the drain and the source pins. Otherwise the design that he provided should work fine according to the Spice simulation that I made.