Source: Hack a Day
Whenever a product becomes popular, it’s only a matter of time before other companies start feeling the urge to hitch a ride on this popularity. This phenomenon is the primary reason why so many terrible toys and video games have been produced over the years. Yet it also drives the world of electronics. Hence it should come as no surprise that ST’s highly successful ARM-based series of microcontrollers (MCUs) has seen its share of imitations, clones and outright fakes.
The fakes are probably the most problematic, as those chips pretend to be genuine STM32 parts down to the markings on the IC package, while compatibility with the part they are pretending to be can differ wildly. For the imitations and clones that carry their own markings, things are a bit more fuzzy, as one could reasonably pretend that those companies just so happened to have designed MCUs that purely by coincidence happen to be fully pin- and register compatible with those highly popular competing MCU designs. That would be the sincerest form of flattery.
Let’s take a look at which fakes and imitations are around, and what it means if you end up with one.
Anatomy of a forgery
Earlier this year, Keir Fraser posted an informative summary of some fake STM32F103 ICs as found on so-called ‘Blue Pill’ and similar boards on their Github. The forgeries carry the same marks on the packaging as the genuine STM32 parts, but can often be identified by the pattern of dimples on the packaging, or by the quality of the silkscreen.
These forgeries aren’t always fully functional. As noted by Fraser, many of these parts cannot even be programmed properly, or even run code as simple as the universal ‘blinky’ example. It’s possible that these forgeries are in fact defective STM32F103 dies or similar that are being sold via less-than-legal channels.
More insidious perhaps are the near-forgeries that at first glance may look like the real part, but are betrayed by the identification on them: ‘STM32FEBKC6’. That’s not a legitimate ST parts code, and that should be the first tip. This is another clone that’s likely to bring you nothing but grief, as even when it does work, it is a cut-down version of the STM32F103 design, with missing features. Finding detailed information on it is hard as well.
Good artists copy
This leaves the trickiest of the clones, in the form of the aforementioned CS32F103. This clone essentially works like the real deal, and can run Blinky compiled for the STM32F103 just fine. Some of these MCUs may even be marked as the ST part, making them hard to identify conclusively.
Some of these are manufactured by CKS (中科芯微), a Chinese company who have apparently made a feature-complete version of the STM32F103, to the point where they have fixed some of the errata listed in the ST datasheet. An article over at CNXSoft provides some more details on this MCU.
A major difference one will quickly encounter with this chip is when programming it and getting the message "UNEXPECTED idcode: 0x2ba01477"
. The reason for this is that the STM32F103 MCU reports the ID 0x1ba01477
, confusing the programmer. This can be fixed for example in OpenOCD by using a configuration script that specifies either no CPUTAPID (0), or this ID reported by the CS32 MCU.
Giga clones
Probably one of the more famous STM32 clone makers is GigaDevice with their GD32 MCUs. As noted over at SMD Prutser in an article series, the GD32F103 appears to be a faster, more capable version of the STM32F103. It has a higher maximum clock speed and faster Flash storage, with a decapped unit showing that they used two dies inside the package. One for the MCU, and one for the Flash storage, allowing for a rather flexible way to change Flash sizes across their product range.
At first glance the GD32 MCUs look more attractive than the STM32F1 series, with significant increases in clock speed (72 versus 108 MHz) and Flash storage. While the Flash storage on the GD32 should be very slow, being a serial SPI ROM, its use of SRAM on the MCU die to ‘cache’ the Flash storage means that it ends up being much faster than on-die Flash storage, with zero wait states required even at full MCU clock speed.
A disadvantage of more SRAM instead of pure Flash is that it increases power usage, especially in sleep mode. It also causes a (small) boot-up delay when the SPI ROM’s contents are copied into SRAM before the firmware can run. Depending on the application this may be an advantage or disadvantage. This is of course the same approach as the ESP8266 MCU, which also uses an external SPI ROM for firmware.
When it comes to other GD32 devices, however, they seem to be less eager to make direct clones. Their GDF303 MCU kept the same peripherals as the GDF103, even though those of the STM32F3 are arguably better. This also prohibits their use as a drop-in solution for STM32F3xx boards. Depending on one’s opinion of the STM32F1 peripherals, this may also affect one’s decision to use those GD32 MCUs.
They’re everywhere
Although I was aware of the aforementioned fakes and clones, I nevertheless came across a new one recently. This involved the purchase of some ‘Blue Pill’ STM32F103 boards from a big German importer and reseller of all kinds of Maker tat. I wasn’t proud of this, but I needed some cheap boards to use for BlackMagic probes, and they had a good deal. In the comments for the Amazon listing some people mentioned they got a genuine boards, while others mentioned that it was a ‘fake’.
In the spirit of morbid curiosity, I got a couple of these boards and was both horrified and pleased to see that I had in fact received Blue Pill boards that did not carry the promised STM32F103C8T6 MCU, but instead one marked CH32F103C8T6. On the bright side it did not claim to be an ‘ST’ part.
This CH32F103 MCU is produced by a Chinese company called WCH, with the (Chinese-only) datasheets and reference manual both provided for download. At a cursory glance, both the datasheet and manaul show a chip that’s practically identical to the STM32F103, with identical memory mapping and peripheral registers.
Hooking it up to an ST-Link/V2 dongle and connecting to it with OpenOCD results in the same CPUTAPID error as with the CS32F103 MCU when using the STM32F1xx profile file. After making the same change to the stm32f1xx.cfg
file as suggested by others, I was able to flash the ‘Blinky’ example from my Nodate STM32 project onto the board without further issues.
This suggests that at least the basic RCC (reset & clock control), GPIO and SysTick functionality is similar enough for such a basic test to work. Next, I’ll have to explore whether it also handles the USART, DMA, SPI, I2C and I2S functionality the same way as the STM32F103 MCU that I have on a few other boards. If this MCU is anything like the CS32F103 part, the answer is probably ‘yes’.
As for the seller’s response when I contacted them about these Blue Pill boards not featuring the advertised STM32 part, they admitted that they were aware of this and claimed that ‘in two months’ they’d have boards with genuine STM32 parts again. Admittedly that raises a lot more questions than it answers, least of all why they’d knowingly sell boards that do not feature the advertised MCU.
Time to panic?
The eagle-eyed among us may have noticed that virtually all of these clones involve ST’s first-generation Cortex-M MCUs (STM32F1 series). Unless you need to buy Blue Pill boards for commercial projects, this is unlikely to do more than seriously annoy hobbyists and others who like to have a stack of $3 Cortex-M3 boards around for random projects. If one orders MCUs and development boards from reputable sellers such as Digikey and Mouser, it’s also unlikely to be much of a concern.
The Blue Pill and Black Pill boards are also seeing a bit of an overhaul recently with updated versions featuring STM32F4-based MCUs. Although a bit more expensive than the STM32F103-based counterparts, they do bring considerably more resources to the table and the much more pleasant (in my opinion) peripherals of the STM32F4 line. These may just make the market for the STM32F103 and with it these countless clones, counterfeits, and copies dry up.
Until the first batches of counterfeit, cloned and copied STM32F401 and STM32F411 MCUs hit the market, naturally. Because that’s apparently the name of the game.