M.2 For Hackers – Expand Your Laptop [Hackaday]

View Article on Hackaday

You’ve seen M.2 cards in modern laptops already. If you’re buying an SSD today, it’s most likely an M.2 one. Many of our laptops contain M.2 WiFi cards, the consumer-oriented WWAN cards now come in M.2, and every now and then we see M.2 cards that defy our expectations. Nowadays, using M.2 is one of the most viable ways for adding new features to your laptop. I have found that the M.2 standard is quite accessible and also very hackable, and I would like to demonstrate that to you.

If you ever searched the Web trying to understand what makes M.2 tick, you might’ve found one of the many confusing articles which just transcribe stuff out of the M.2 specification PDF, and make things look more complicated than they actually are. Let’s instead look at M.2 real-world use. Today, I’ll show you the M.2 devices you will encounter in the wild, and teach you what you need to know to make use of them. In part 2, I will show you how to build your own M.2 cards and card-accepting devices, too!

Well Thought-Out, Mostly

You can genuinely appreciate the M.2 standard once you start looking into it, especially if you have worked with mPCIe devices for some amount of time. mPCIe is what we’ve been using for all these years, and it gradually became a mish-mash of hardly-compatible pinouts. As manufacturers thought up all kinds of devices they could embed, you’d find hacks like mSATA and WWAN coexistence extensions, and the lack of standardization is noticeable in things like mPCIe WWAN modems as soon as you need something like UART or PCM. The M.2 specification, thankfully, accounted for all of these lessons.

The M.2 standard is designed with real-world usecases in mind and defines as many pins as possible, making sure that same-purpose cards from different manufacturers can be substituted for one another. It’s split into different keyings that each serve a purpose – like storage-oriented, WWAN, WiFi and other purpose keyings. Each keying defines a pinout for a group of interfaces like PCIe, USB 2.0 or 3.0, SATA, I2C, DisplayPort and so on. Most of these interfaces are, naturally, quite tasty for a hacker.


Neither a card nor a socket is required to support all interfaces defined in the keying’s pinout, or any particular interface. This makes sense if you design systems – a lot of interfaces defined are situational or expensive. However, of course, it can cause confusion of the “it fits, but doesn’t work” kind. For instance, a B+M key SATA SSD will not work in some NVMe-only M-key sockets, and some proprietary standards like CNVi throw a wrench into the “any M.2 WiFi card will work with your laptop” concept.

Some M.2 cards might look flippable, but they’re not

However, in real-world use, there’s anchors you can rely on – if you see a M-key, A-key or E-key slot, it has PCIe, if you see a B-key slot, A-key or E-key slot, it has USB 2.0; and if you have schematics or a few M.2 devices on hand, you can quickly test compatibility of any particular slot. There’s also I2C SDA and SCL pins defined in all keyings, but whether they’re connected to anything at all is a 50/50 chance, apparently dependent on the phase of the moon of the exact day when your laptop mainboard was designed.

B+M? The M.2 standard allows combining keys on cards, letting a card fit into two different types of socket and increasing compatibility of your card. There are two combinations you will see – B+M and A+E, used for SSDs and WiFi cards respectively, and the B, M, A and E key pinouts are designed around these two combinations being possible. You lose on some of the optional features, but the crucial stuff like PCIe remains accessible. As an aside, while it might feel like you can insert a B+M SSD flipped upside down if you apply enough force, or push an M-key card into a B-key socket, not only it will not work, you will reverse the input voltage polarity and there might be fiery consequences. Even given these few hiccups, M.2 is way more reasonable and powerful than mPCIe ever could be.

A Stick Of Solid-State

Two B+M SSDs – one SATA and one NVMe through 2x PCIe link

Undoubtably most popular are M.2 SSDs. They’re either SATA, or NVMe – the latter is a storage interface using PCIe as its physical layer. We’ve talked about NVMe internals in depth, feel free to check that out. SATA SSDs usually use B+M keying – some are B-key only, but it’s rare. NVMe SSDs usually use M-key, some using a combination of B+M and thus being limited to 2 PCIe lanes, you’ll see it with cheaper SSDs.

An SSD can only support one of these standards – never both. It might be hard to figure out which one, so if there’s no NVMe or SATA logo on the label, look the model number up. If you have the SSD in hand or got some higher-resolution pictures, look at the number of differential pairs. If there’s only two of them, it’s SATA; if there’s three, five or nine of them, it’s NVMe. Statistically, you’re way more likely to see NVMe SSDs, as they’re getting more and more abundant.

An M-key or B-key port might support either both of them or only one of them. On the B and M pinouts, there’s a pin defined to distinguish between PCIe and SATA SSDs, and if a host supports both standards, it will switch between them automatically. With some laptops, it might be hard to tell if an M.2 SATA SSD would be supported – in contrast, NVMe is a safe bet, as it’s is hardly ever non-supported. And, if you have a simple external adapter that has only a PCIe connector or a SATA connector, it will only support that type of SSD.

All The Ways To Do WiFi

M.2 WiFi uses A or E keyings – most WiFi cards you will see will use a combined A+E keying, and sockets used to be A-key but nowadays E-key is the rule. You get an 1x PCIe link and USB 2.0 , with former used for actual WiFi and latter used for Bluetooth. On both A and E keys, you can get a second PCIe 1x link – not lane, link! – but it’s rare to see sockets that wire it up, hence it’s hard to find hosts for cards like this Google Coral Dual TPU Accelerator. Compared to mPCIe, the antenna connectors are no longer uFL – they’re MHF3, also known as wFL, so it might be that you’ll need some new antenna hardware.

Not all embedded WiFi cards run PCIe, of course – the E-key pinout also accounts for SDIO WiFi cards. SDIO is an embeddable interface used mostly for SD cards and WiFi chip connections – for instance, on boards like the Raspberry Pi. A few cards and adapters have been seen out there using E-key, having the yet-uninitiated hackers raise eyebrows. Given how easy it is to design your own M.2 cards, hopefully we could see M.2 SDIO WiFi cards become more popular one day – maybe then, Pine64 will no longer design weird WiFi modules.

half-sized WiFi card on top, 1216 M.2 WiFi module on the bottom

It’s rare to see pure E-key or A-key cards – one of the exceptions, CNVi, uses E-key, and it’s not the good kind of exception. It’s an Intel-only proprietary M.2-derived interface that lets the chipset do most of the WiFi work that used to be done on the PCIe WiFi cards. Not only do these cursed M.2 WiFi cards not work with AMD processors or older laptops, there are two versions of CNVi and they have neither backwards nor forwards compatibility, resulting in user confusion, extra expenses, and e-waste. There’s one tentative upside – slots usually wire up both CNVi and PCIe+USB2, so you can theoretically use a CNVi card, then get yourself extra internal PCIe and USB links for your hacking purposes.

There are two somewhat wacky WiFi card form-factors you might encounter. First of all, there’s this fun-sized E-key WiFi card – made possible because large portion of the pinout is unused by default. Going even more fun-sized but not necessarily as fun, you might’ve seen these small shielded soldered-on modules in ultrabooks. This, too, is M.2 form-factor, called 1216. It’s solderable and hence not as easily upgradeable, but with a pre-defined pinout all the same. Sadly, these modules also come in CNVi variety – on the upside, it’s not like you’re going to be swapping these cards often.

Go Worldwide With B-Key

Project-ready USB 4G modems for cheap

If you need a cheap USB-connected 4G modem with decent Linux support in your project, you won’t go wrong with getting a used M.2 B-key modem, typically coming in 3042 form-factorm, so 30 mm wide. A lot of these cards got manufactured for laptops with WWAN connectivity, and the second-hand market has them for ultra low prices. Most of them are USB 2.0, with some USB 3.0 cards available – for either, you can find USB-plug-equipped breakouts online, and there’s some homebrew open-source breakouts out there as well.

These go into B-key slots on laptops – out of all M.2 slots available, these are the most “wild west” ones, in that you can only really rely on USB 2.0 being present – everything else highly varies. The standard defines quite a few other features – some B-key slots have extra SATA, some have extra PCIe, some have both SATA and PCIe switchable by the same PCIe/SATA config pin M-key SSDs use. Sometimes there’s USB 3.0 too, but no guarantee. You will definitely have USB 2.0 for your modem, but for any other devices like SSDs, you’ll have to google your laptop’s model number with “can I put SSD in B-key slot” inquiries.

Sadly, if your laptop didn’t actually come with a WWAN option, not only the WWAN antennas might be absent, but the on-mainboard B-key socket might not be soldered either – it’s a bizarre and frustrating assembly choice to face and it hampers upgradability, but it’s nothing we haven’t seen done with mPCIe, I guess. On the upside, if you do have a B-key slot, you don’t have to limit yourself by SSDs and WWAN cards – for instance, here’s an open-source USB 2.0-connected RP2040-based M.2 expansion card by [Timonsku], likely to be a fun upgrade for your laptop!

M.2: Evolving, Ever-Present, Here To Stay

Some parts of the M.2 standard are fading into obscurity, and are no longer accessible on laptops out there – if they’ve ever been in the first place. If you want to go down a rabbithole, the M.2 Electromechanical Specification Rev1.0 document can be found online, and you can learn a lot from its 201 pages. For instance, you will find that the F-key is reserved for some obscure thing called Future Memory Interface, no doubt a shelved Intel project only described on some Blogspot page that’s not even indexed by Google anymore.

For more real-world but no less fun parts, there was a standard called WiGig, and some ThinkPads exposed a DisplayPort link on the A-key WiFi slot for that – along with actually making use of the second PCIe link on the A-key I mentioned above. Apparently, you could have wireless laptop docks, with DisplayPort and USB3.0 connectivity bringing you a ton of devices without a cable in sight. There’s some interesting pictures of WiGig dock internals out there – the in-dock receiver hardware is actually a M.2 G-key card itself. You can actually find the in-dock cards on eBay, as a piece of somewhat recent computing peripheral history.

You will find M.2 basically everywhere. It has plenty of hidden potential, and if we ever need to tap into that, it helps that you learn how it’s used out there in the wild. Even if you’re never going to design a M.2 card, now you know how to tell SATA and NVMe M.2 SSDs apart, and why pushing a B-key 4G card into your M-key SSD slot will not result in anything good. In the next article, I’ll show you how to design a M.2 card or put a M.2 socket on your own board, too!