A Failure in Frugality
A short story about trying to be thrifty, and probably spending more money in the end.
The Problem
Programmers are Expensive.
A new ST-Link (ST-LINK/V2-ISOL) costs upwards of £75, and a new Lattice programmer (HW-USBN-2B) will run you some £220. On top of those I need a Tag-Connect TC2030-IDC-NL for $33.95, and adapters for both (an "ARM20-CTX 20-Pin to TC2030-IDC Adapter for Cortex" & a "TC-LATTICE") which are $29.95 each. For just one copy of each, including a little for shipping, the total reaches an eye-watering £400.
Granted, a huge chunk of this is the Lattice programmer, but I'm not ready to mess around with trying to find an alternative for that just yet. The other parts though, I think I can do something about.
The Solution
So what can we do about it? Make and/or bodge our own, that's what.
Custom Programming Headers
The first target of my cost reduction was to make my own Tag-Connect programming adapters. $30 for a tiny 2-layer board with just two headers on it is terrible. I can get the same thing for $2 from JLCPCB, and a few quid for the headers.
So that's exactly what I did. One caffiene fueled evening, I designed a set of three adapters - one for the ST-Link/V2-ISOL, one for the HW-USBN-2B, and one for an STM8S dev-board (more on that in a minute).
Budget ST-Links
My next mission was to try and get a cheaper ST-Link. There's no shortage of knock-offs, and I've actually had decent success with some of them in the past, but I want the guarantee that comes with a genuine ST product so that I'm not constantly fighting with their software.
ST dev-boards to the rescue! Most of their dev-boards have an ST-Link built in, and one further, many are on snap-off sections so that they can be easily be re-purposed for other uses. And there you have a budget friendly way of getting an official ST-Link.
I even happen to have a few on hand already, so to the sacrifice goes my STM8S-DISCOVERY board. Paired with the adapter created above this makes a pretty nice programming setup, albeit not as refined as a proper ST-Link.
The Solution in Practice
So how did these attempts at saving money actually go? Not all that well...
A Folly in Price Breaks
A mistake I've made often in the past, and one I'm sure I'll continue to make in the future, I'm a sucker for price breaks and deals.
5 copies of each adapter PCB for $2 (plus shipping) - sure, doesn't hurt to have spares for free. There's an extra $15 cost because of the multiple designs - no worries, per board they're still super cheap.
Now if I have 5 copies of each of the adapters I should probably get enough headers to populate them all, just in case. It makes the per-adapter cost cheaper as well - it's a no brainer, right?
So some £75 later, I've saved somewhere between 80 and 100 dollars. I'd call this a marginal victory. I've spent more time, and a similar amount of money, but now have significantly more adapters. This will save significantly more money in the future if I should ever need more, but even in the short-term it means they're far less critical. If I lose or break one now - so what, I've got 4 more. Still, not quite the savings I'd hoped for.
Stupid Mistakes & Dodgy Bodges
After assembling my custom STM8S dev-board ST-Link adapter board, I plugged everything in and attempted to connect using STMCubeProgrammer. No luck. After trying with ST-LINK Utility, messing around with drivers and firmware upgrades, and much more, I discovered that the ST-Link from the STM8S-DISCOVERY dev-board doesn't support SwD?JTAG programming, only SWIM. After re-examining the dev-board schematics, the JTAG header I'd attached to was for programming the ST-Link STM32 rather than the target microcontroller. The disappointing thing is that the ST-Link v1 of the STM8S dev-board has the hardware to perform this, the pins are even labelled on the schematic, but they aren't broken out and the firmware is programmed to reject any attempt to use this feature.
No ST-Link there then, so what other dev-boards do I have laying around? Well I've got a couple NUCLEO-F303K8 boards. They don't have a break off section, but if I were to desolder the target STM32F303K8 IC and wire out the SWD pins how would they know the difference? A few bodges later and I was left with this monstrosity:
When testing this, though, I got yet more errors. From STM32CubeProgrammer it reports that its board type is an F303K8 - uh oh. Turns out it's been programmed with what it's meant to be connected to. I'm not sure if it simply won't work unless it sees the target it's expecting, or there's some other hardware error, but I guess this is a dead end as well. Another dev-board down the drain for no benefit.
Hold on though - as a Hail Mary I tried programming with it using STM32CubeIDE, and it worked? Well, it half worked. It failed to verify the programming, but it looked semi-successful. After reprogramming again with a modified blink rate, yes, it does succeed in programming an STM32G473 microcontroller. There is some irony here though - I went down this route to try to avoid fighting with the ST software, and here I am doing just that.
Maybe I'll destroy another dev-board in the near future to get one working more smoothly - I have a couple of NUCLEO-F103RB boards that are just asking to be snapped in half. For now though, it'll do.
Was it All Worth it?
In all honesty, I'm not entirely sure.
I'd probably do it again though, I guess I'm just stuck in my ways like that.