I have a PCB that is getting powered from mains and is connected to a Hi Link component (HLK-5M05 with 5V output). At the moment it is connected to an extensions with a button, a little bit like this one. When I power it on and start measuring I get the 5V output, 3v3 output, I can see that some components are working accordingly (voltage monitor) and then I went to load my firmware into the st microcontroller.
I disconnected eveything since I don't want to accidentally get shocked, I connect all the pins (gnd to gnd, 3v3 to Vapp, TMS -> TMS, etc). After I connected this I connected the board to the extension and turned on the button. Immediately I heard a loud noise and I noticed the st link wasn't ON anymore (a capacitor exploded) and the circuit breaker activated. Then I went to measure the board and I notice that there is a3v3 short to ground.
I have revised my entire layout and there is no connection between mains and GND in my circuit. The closest to it is the analog circuitry for measuring the voltage, but still, they are not connected. From what I can see everything is connected as it should be according to datasheets, but it still didn't work.
After that I tried connecting and programming my board via the bootloader. I did the required connections and tested my board and everything was working properly. Again I disconnected everything and connected the USB-serial board to my board (GND, TX and RX ... very simple and straight forward). When I connected everything the circuit breaker still activated but fortunately this time it didn't destroy my PCB.
Very distraught I turned off the button and went to disconnect the USB-serial board and got shocked. After that I measured the voltage between the USB connector and my PCB ground and there was 220Vac ... when the extension was turned off and the extension is not grounded (not USA .. incompatibility between different types of plugs ... old everything), but there is 0V when I measure the voltage between them when the extension is powered on.
What could I be doing wrong? I measured other devices (USB chargers and similar) and they all had the same behaviour ... 0V when ON and 220V when OFF. I have compared my schematic to others, such as open energy monitor and many other projects you can find online and I'm not doing anything crazy here (in terms of schematics and connections). Could there be something wrong with my installation? Or is it a PEBKAC (more like between PCB and chair [PEBPAC])?