In the first M.2 article, I’ve described real-world types and usecases of M.2 devices, so that you don’t get confused when dealing with various cards and ports available out there. I’ve also designed quite a few M.2 cards and card-accepting adapters myself. And today, I’d like to tell you everything you need to know in order to build M.2 tech on your own.
There’s two sides to building with M.2 – adding M.2 sockets onto your PCBs, and building the PCBs that are M.2 cards. I’ll cover both of these, starting with the former, and knowing how to deal with M.2 sockets might be the only thing you ever need. Apart from what I’ll be describing, there’s some decent guides you can learn bits and pieces from, like the Sparkfun MicroMod design guide, most of which is MicroMod-specific but includes quite a few M.2 tips and tricks too.
First, Let’s Talk About The Y-Key
What could you do with a M.2 socket on your PCB? For a start, many tasty hobbyist-friendly SoMs and CPUs now have a PCIe interface accessible, and if you’re building a development board or a simple breakout, an M.2 socket will let you connect an NVMe SSD for all your high-speed low-power storage needs – many Raspberry Pi Compute Module mainboards have M.2 M-key sockets specifically for that, and there’s NVMe support in the RPi firmware to boot. Plus, you can always plug a full-sized PCIe adapter or an extender into such a socket and connect a PCIe network card or other much-needed device – even perhaps, an external GPU! However, as much as PCIe-equipped SoMs are tasty, they’re far from the only reason to use M.2 sockets.
PCIe itself is an interface increasing in its popularity and accessibility. We’ve covered someone make an adapter aimed at digital cameras, letting you use NVMe SSDs in place of CFExpress cards – both interfaces with PCIe as their backbone. A different adapter we’ve seen lets you put a PCIe WiFi card into a Pinebook, helping you increase the WiFi speeds quite a bit. And of course, it’s not just PCIe, not even when coupled with SATA or USB. Would you like to design a RISC-V Linux-capable SBC into a board of yours? Well, Sipeed makes one of the few RISC-V SoMs available right now, called LicheeRV, and it’s a $20 SOM using two M.2 B-key connectors with a completely custom pinout.
You can do a lot with a low-footprint group of 67 pins, it turns out. For instance, Sparkfun MicroMod is a microcontroller ecosystem that makes use of M.2 hardware with a custom pinout – in MicroMod’s case, it’s E-key hardware, with custom card length and the retention screw location being shifted so that WiFi cards can’t be plugged in. For hobbyists, they’re a neat and funky ecosystem with tons of different CPUs and sensors to play with – in business speak, they let us evaluate a variety of different processors for our applications. In fact, last year’s Remoticon badge spin by [Thomas Flummer] was designed for MicroMod CPUs, and just recently, [tzarc] on Hackaday Discord told us they had plenty of fun building a MicroMod-based keyboard!
My own work with M.2 is mainly about improving laptops and bringing new life into old hardware. For instance, I’ve built quite a few adapters for reviving old laptops – i.e. small-footprint mPCIe to M.2 M-key NVMe adapters, which me and my friends use to put fast and cheap NVMe SSDs into old but still usable machines. I’ve also built a trove of M.2 key-to-key adapters for my friends’ usecases, such as one that lets you replace an A/E WiFi card with a M-key SSD, or vice-versa, and an adapter for Apple Xserve boards to use M.2 SATA SSDs in its proprietary SATA boot drive connector.
There’s a lot of fun to be had with M.2 sockets. Now – how?
What does it take for you to add a M.2 socket? Mechanically, its footprint, as well as some free board space. Let’s talk about board space first. Of course, you can make the card hang off your PCB – transferring the problem from the “PCB space” to the “space inside your case” area, but you still need to account for size. M.2 card size is described with four digits in WWHH format, which are width and height in millimeters – a 3042 WWAN card is 30mm wide and 42mm tall (including the card edge), and a 2280 SSD is 22mm wide and 80mm tall. When putting a footprint on a PCB, the exact location of the card edge related to the footprint will either be explicitly shown in the datasheet, or can be inferred from the cross-section image.
There’s various M.2 sockets you can get – I separate them into mid-mount, flat and angled insertion, and their most important difference is the height above your PCB. M.2 socket PCB-to-card distances are actually standardized, but mid-mount and flat-mounted sockets are a less-than-standardized area – nevertheless, they’re extremely useful for making your projects small and thin. I’m a big fan of using flat sockets because they just hold your card in place, no standoff required – that said, they likely won’t work well with double-sided cards like some fancier SSDs, and I wouldn’t dare put components under the card either.
Most of the M.2 sockets, regardless of the height, use the same exact PCB footprint, since it’s standardized as well – save for mid-mount sockets, which are very useful when you need to save vertical space, but their footprints vary quite a bit more. This footprint is actually standardized in the spec and will be the same for overwhelming majority of the sockets you encounter. A friend has recently shown to me, however, that this isn’t always the case – LOTES APCI0162 is an example of an angled insertion connector that has lower distance between pads than the usual footprint sockets do. So, do recheck the footprint when buying a new part, just in case!
Acquisition And Attachment
Proper places like Digikey and Mouser will have M.2 connectors nicely sorted by key, height and mounting type. In case you, like me, choose price over convenience by shopping at LCSC, about a month ago I’ve compiled a small database of then-in-stock M.2 sockets on LCSC, since LCSC is so bad at actually keeping track of the important parameters. There’s even some G-key sockets in case your contraptions are too wacky to fit the in-spec pinouts!
I couldn’t find M.2 socket footprints in KiCad standard library – if you don’t mind borrowing footprints, I have some for you to reuse. Here’s footprints for M, B and E-key sockets, and here’s an “all M.2 socket pads” footprint – if you need a G-key or some other socket footprint, take this one and remove the pins you don’t need. This is, again, the standardized footprint that most angled-insertion and flat sockets will fit, but do check if your specific one does.
With angled insertion cards, you’ll want a standoff – otherwise, it’s not likely that the card will mechanically connect until you hold it down properly. M2 hardware will work best, and M2.5 will work in a pinch. If the card will be fastened into your case, you’ll probably grab some threaded inserts and be done with it. If you need to fasten your SSD to your PCB, however, you’ll want solderable standoffs – and when shopping at LCSC, s-ol on Twitter reminds us that we can find them using the keyword “smtso”.
What about assembly? My experience is that you’ll absolutely want a stencil with solder paste, as these are pretty dense 0.5 mm pitch parts, and a hot air gun/hotplate/reflow oven will work best. That said, with a thin enough tip and maybe preheating, you can stencil your board and then use a soldering iron in a pinch, too, or perhaps thin solder with thin iron tip – but it will be tiresome if you want to assemble more than two or three boards.
After soldering, you might still end up with solder bridges between pins – in my experience, you can clear these bridges beautifully by heating the bridge area through a narrow hot air gun nozzle from below, adding flux after the bridge’s melted and then using sharp tweezers or a needle to mechanically separate the pins. If the short joins right after separation because you stenciled too much solder paste on the pads, using good old solder wick beforehand should help too.
For PCIe, I recommend you use M-key for SSDs, B-key for WWAN-compatible cards and E-key for WiFi-compatible slots. These three slots can handle up to 4x, 2x and 1x wide PCIe links respectively, but even if you only have 1x PCIe on your CPU, you can use either of these three, only connecting the first lane pins – read our PCIe hacking article if you’d like to know more. If SATA is what you want instead, it’s also pretty simple, just two diffpairs. At that, you can use either B-key or M-key, since overwhelming majority of SATA SSDs are B+M – here’s a board where I used M-key for SATA, simply because by that point I stocked up on some nice M-key sockets.
Where do you get pinouts and symbols from? For a start, there’s symbols in KiCad standard library, at least, in KiCad 6. Other than that, you can, yet again, get symbols from my repo – I got some for M-key, B-key, B+M key, A+E key and E-key; these work with both sockets and cards, as the footprints for cards will just ignore lack of the mounting pads that are present on the sockets. If those are limiting and you need more specific ones, there’s always the dodgy websites, and the specification floating around that I mentioned in the end of the last article.
M.2 cards will only require 3.3 V, but they might use up quite a bit of current. If you’re building custom cards, that won’t be an issue, since you know how much your device might consume. When reusing existing SSDs, WiFi and WWAN cards in your designs, however, things might get a bit more complex. Learning from laptop schematics is the simplest way – to sum it up, providing 1 A – 2 A for WiFi cards and 1 A – 3 A for WWAN and SSD cards is likely a good idea. Also, the M.2 specification mentions some WWAN cards may be built for input voltage in single-cell LiIon range (3 V-4.2 V) instead of 3.3 V. You likely won’t encounter such cards and it’s likely to be written on the label or first page of the datasheet, but this is good to know about nevertheless.
PCIe cards require PERST, CLKREQ and PEWAKE signals. That said, CLKREQ is used for gating the clock for power management purposes, and can be tied to GND on the PCIe host side – as a testament to that, the ever-abundant USB 3-cable-abusing PCIe 1x risers only forward PEWAKE and PERST. For W_DISABLE signals on WWAN and WiFi cards, you might want to add pullups to VCC – I believe they’re active low, but please do double-check. DAA/DSS signal on SATA and NVMe is a nice ‘drive activity’ open-drain signal that you can use to drive a LED. SUSCLK is a 32 kHz clock useful for card power-saving but not required in practice, and DEVSLP is a SATA-only low-power mode signal. I2C signals likely won’t be useful, but it won’t hurt if you connect them to your target – through 0R resistors, just in case.
Building a higher-current card, or card+host combination? Technically, M.2 connectors are rated at 0.5 A per pin, so, M-key with its nine 3.3 V pins would result in 4.5 A max – that said, the recommendation for M-key is to not exceed 2.5 A, and that’s what you’ll want to adhere to. In case both sides of the equation are under your control and you’re creating your own pinout (preferably, using something like G-key), go wild and make use of as many pins with as many different voltages as you want. I just wish that Sipeed knew that when designing LicheeRV – apparently, they only use one M.2 socket pin for feeding 5 V into the baseboard. I don’t know if it’s an actual problem, but it looks suboptimal for sure!
Facing an unjustifiably non-populated M.2 socket on your laptop’s mainboard? Finding a receptacle won’t be the hard part, what’s with footprints being standardized – especially if you have the schematics, as those often list the connector part number. Soldering the connector on would be trickier, however, as you can’t exactly stencil it on a populated mainboard. I recommend you wick off the factory-applied solder first so that the connector can sit flush to the PCB, then put the connector on, and use a thin tip soldering iron with thin solder to attach pads one-by-one. From there, it might be that some power management parts and signal passives, say, capacitors will be unpopulated. A good value for PCIe or SATA series capacitors is about 220nF; USB signals and stuff like PEWAKE/CLKREQ/PERST can be jumpered with something like 0R or 22 R, power management can typically just be jumpered to 3.3 V, and many other signals you’ll find to be optional.
Now, you’re well-equipped to build and hack M.2-accepting stuff, and know quite a few places where it’s useful. Next time, I want to show you how to build M.2 cards – there’s a trove of cool applications for these as well!