cheap voltage level shifter for SWD - Page 1
Forum section: electronics / projects

author: kamtar
author_rank: Regular Contributor
timestamp: January 28, 2020, 01:38:57 am
content: I'm trying to design a voltage level shifter for my ARM programmer - SWD pins + debug UART - 5 signals (2 outputs, 2 inputs, 1 bidirectional)As a learning exercise, I'm trying to design it to be cheap to manufacture by hand and by SMT assembly. So I have a few points I want to observe:1. I would like to get the BOM cost to at least around 1USD2. I don't want to introduce more than one type of new component. (I'm already using P and N MOSFETs in the design so they could be added without breaking this rule)3. It should be widely available in the Chinese market.4 out of 5 signals have set direction but the SWDIO signal is bidirectional I can use another GPIO pin to switch directions.So far I have come up with two solutions:1. 5x SN74AVC1T45 - 1-bit level shifter, which I can get for 1pcs / 0.28USD. BOM cost in the end around 1.5USD .. I think I should be able to do better.2. TXS0108 - 8bit level shifter with auto-direction detection. I can get it for 1pcs / 0.36USD - One problem here is that it holds voltage levels through 4k impedance and I think that could make it rather unreliable in interacting with some MCUs.I was trying to find is some 4-bit level shifters with directional control pin for each channel but that ended in BOM cost more than my solution no.1.If somebody has some ideas please let me know.Thank you.

author: 741
author_rank: Frequent Contributor
timestamp: January 30, 2020, 07:04:43 pm
content: This might helphttps://www.eevblog.com/forum/projects/one-fet-level-convertor-(how-did-it-work)/msg2733424/#msg2733424

author: ataradov
author_rank: Super Contributor
timestamp: January 30, 2020, 07:07:35 pm
content: SWD is a fast interface. MOSFET level shifter will not work.As far as I know the best solution is any level shifter with a direction pin. SWD protocol is well designed for that case with mandatory bus turnaround cycles.

author: Ian.M
author_rank: Super Contributor
timestamp: January 30, 2020, 08:22:41 pm
content: Check costings for 3x 74LVC2T45 or similar, with both sides the unused channel of the bidirectional one grounded.

author: profdc9
author_rank: Frequent Contributor
timestamp: January 30, 2020, 08:32:02 pm
content: How about TXB0104?https://www.ti.com/lit/ds/symlink/txb0104.pdf

author: thinkfat
author_rank: Unknown
timestamp: January 30, 2020, 09:43:06 pm
content: Quote from: profdc9 on January 30, 2020, 08:32:02 pmLCSC has it for $0.49 in single quantities. That should check the BOM box and the "widely available in china" box

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 27, 2022, 06:03:50 am
content: Sorry for digging this up, but has anyone used a TXB0104 for SWD, does that work flawlessly and if so up to what clock rate?

author: ataradov
author_rank: Super Contributor
timestamp: December 27, 2022, 06:25:24 am
content: I have not tried that specific device, but I looked at those automatic bidirectional level shifters and they are not very useful for SWD. They would put too many restrictions on the target device. They can't drive a lot of capacitive load and they can't tolerate typical SWD external pull-up resistance. They typically won't work with anything lower than 50-70 kOhm. And most implementation would use at least 10 kOhm and sometimes lower.They would interpret that as the target side actively driving the line. They can't be used for I2C for the same reason. They really just want clean logic levels.The datasheet says the same:Quote

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 27, 2022, 06:15:28 pm
content: Quote from: ataradov on December 27, 2022, 06:25:24 amYeah, I was thinking so. Also the speed of this device is not fantrastic, you'd probably top at 4-5 MHz.I found the ADG3301, which looks a lot better. Although the automatic direction sensing may always be problematic for SWD.

author: ConKbot
author_rank: Super Contributor
timestamp: December 27, 2022, 06:36:32 pm
content: Quote from: SiliconWizard on December 27, 2022, 06:03:50 amNo.But really the TXB and TXS series, specifically, along with most auto-sensing level shifters are pretty mediocre because of the games they play with logic levels giving them no tolerance for poor SI. When they think they detect an edge, it puts out a massive belch of current with a very sharp edge to be capable of the 11ty mbit/s they promise. But get 100mv of ground bounce because of said transient, and it may think the other device is transmitting, a attempt to reverse the bus, send a belch of current at the transmitter, figure out that's wrong, reverse again... EtcCombined with the inability to drive more than 50k or so of load, and limited capacitance makes them unsuitable for connecting to a cable to another board IMO. Between a micro and a perhiperal of known load impedance on the same board, or though a board to board connection? Sure. But a cable is asking for issues unless it's bringing a really really solid ground connection too.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 27, 2022, 06:39:12 pm
content: Level shifting a SWD interface for which we have no control over is thus pretty much a lost cause as far as I can tell.

author: ataradov
author_rank: Super Contributor
timestamp: December 27, 2022, 06:44:25 pm
content: Yes, it is based on the same principle of detecting if something outside tries to override its output. And strong pull-up resistors would do that.I think TXB0104 is also pretty fast. But there are two things to consider with automatic level shifters. They are pretty fast if driving in the signal in the same direction, but they are much slower at the direction switchover time. In SWD there is at least one dummy clock cycle, but this part is likely to be the bottleneck anyway.If you have control over the firmware of the debugger, it is very easy to add the direction pin. There is a very clear and obvios distinction in the protocol. But for a generic debugger I see no way of doing that. outside of using some smart device that parses the protocol and derives the direction from that.

author: ConKbot
author_rank: Super Contributor
timestamp: December 27, 2022, 07:02:19 pm
content: I'd try to find the slowest bidirectional level shifter you can. The TXB's once they get into the higher supply voltages(1.8 and up) are trying to put out 0.6-1ns edges, and 10ns long high current pulses.Not sure what your options are, but you can also try and make the programmer plug into the target board, or just shorten the cable as much as possible, or adding more grounds till it looks like it wants to work. Some series resistance on the signal line (just a bit, < 30 ohms) may also take some of the ringing and bouncing out of the transmission line without choking the one-shot so much it can't pull the bus up.Even then, that's a specific one-off instance of it working, not for general use.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 27, 2022, 07:46:43 pm
content: One way of doing foolproof level shifting for SWD (+isolation if needed) if you don't control the SWD host would be to use a small MCU to analyze the SWD stream just enough to determine when to do a bus turn-around, and generate an output enable signal from that.

author: ataradov
author_rank: Super Contributor
timestamp: December 27, 2022, 07:52:01 pm
content: MCU may be too slow for this. It would be perfect for the new small Renesas FPGA. But they can't get that to the market.But really, just get a debugger with direction control logic already there.

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 28, 2022, 02:42:36 am
content: I used a txs0108e (Rated for 110Mbps) to interface a SDcard reader and a 1.8V eMMC, working at 52MHz, short wires and no resistors, all I can say is it worked great, had to write it a lot of times until I found the correct image (16GB every time)!They're cheap, get one, test it, watch the signals...

author: Peabody
author_rank: Super Contributor
timestamp: December 28, 2022, 03:34:44 pm
content: Quote from: ataradov on January 30, 2020, 07:07:35 pmI assume you're referring to using a single N-channel mosfet to do the translation, with pullup resistors on either side to the respective power rails. I've seen app notes recommending this method for I2C, although from what you are saying, this would only be for 400KHz. Can you give me some suggestions for mosfets that would work well for this, and which come in hobbyist-friendly packages (no smaller than SOT-23)? Would a 2N7000 work, or does it have too much capacitance? I've searched for "small signal" mosfets, and found some with good specs, but the packages are unusable.

author: ataradov
author_rank: Super Contributor
timestamp: December 28, 2022, 05:44:45 pm
content: Quote from: Peabody on December 28, 2022, 03:34:44 pmThe primary reason for MOSFET level shifter to not work for SWD is not even speed. That level shifter only works for open-drain buses, and SWD is push-pull. So, is I2C Hs mode (1 MHz).Quote from: Peabody on December 28, 2022, 03:34:44 pm2N7000 would work. For I2C at 400 kHz almost any generic MOSFET would work.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 28, 2022, 07:46:39 pm
content: Quote from: ataradov on December 27, 2022, 07:52:01 pmYeah, obviously depends on the max clock rate you're targetting for SWD and the type of MCU. (Maybe possible to implement some trick using the PIO of the RP2040 for instance, to handle pretty high clock rates, could be a fun exercise.) Otherwise sure you can use any small FPGA, I would not suggest any of this Renesas stuff that is still not there at this point AFAIK. Just use iCE40 FPGAs which are great for this and pretty cheap, and are getting back in stock.Quote from: ataradov on December 27, 2022, 07:52:01 pmSure, the question was almost rhetorical rather than practical, although we could think of designing some kind of universal level shifter/isolator for just any SWD debug probe - I'm sure there would be some interest.Can you give an example of an OTS probe that has a direction control output available though? (Again of course if you are designing the SWD probe itself, the point is moot as you can fully control the whole chain.)

author: ataradov
author_rank: Super Contributor
timestamp: December 28, 2022, 07:51:53 pm
content: Most if not all vendors would have debuggers that already have level shifters. It would be hard to find a genuine tool that does not.Clones often omit them for cost reasons, of course. But if you are dealing with a clone, you are already half way to custom stuff, might as well go all in and use a modified firmware to expose the direction on may pin you like.And using RP2040 to just do the direction part when you can use it to make the whole debugger is an overkill.

author: Pixie dust
author_rank: Contributor
timestamp: October 05, 2025, 02:57:26 pm
content: For anyone thinkering with a levelshifter for SWD from 3.3 to 5V target. I manage to do it with a mosfet level shifter for the SWDIO pin and a buffer IC MC74HC1GT50 for SWCLK. I encounter the following difficulties:1) the SWCLK can be floating which causing oscillations at the buffer IC. To solve this a pulldown of 100k was added at the input of this IC. I choose pull down as the SWCLK pin of the PY32Fxxx series has a pull down onboard.2) strong ringing of the input signal SWCLK. To solve this a had to add a series resistor on the input of the buffer.3) added 100nF caps at the 3.3V supply from the DAPlink and 5V supply of the buffer IC.4) used a 2N7002 type mosfet as it has very low gate capacitance (high frequency) and a low threshold voltage < 2.5V.Enclosed the schematic of the level shifter.I tested the shifter at maximum speed of 10Mhz and it works fine.

author: peter-h
author_rank: Super Contributor
timestamp: October 05, 2025, 03:51:21 pm
content: QuoteHow does the ISOL add-on board for the STLINK V3 do it? It has no CPU, just some isolators, but the CPU in the STLINK itself (which also implements the USB interface) may well be generating a direction signal.