Author Topic: cheap voltage level shifter for SWD  (Read 8919 times)

0 Members and 1 Guest are viewing this topic.

Offline kamtarTopic starter

  • Regular Contributor
  • *
  • Posts: 62
cheap voltage level shifter for SWD
« on: January 28, 2020, 01:38:57 am »
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 1USD
2. 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.
 


Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: cheap voltage level shifter for SWD
« Reply #2 on: January 30, 2020, 07:07:35 pm »
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.
Alex
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 14132
Re: cheap voltage level shifter for SWD
« Reply #3 on: January 30, 2020, 08:22:41 pm »
Check costings for 3x 74LVC2T45 or similar, with both sides the unused channel of the bidirectional one grounded.
 

Offline profdc9

  • Frequent Contributor
  • **
  • Posts: 347
  • Country: us
Re: cheap voltage level shifter for SWD
« Reply #4 on: January 30, 2020, 08:32:02 pm »
 
The following users thanked this post: WattsThat

Offline thinkfat

  • Supporter
  • ****
  • Posts: 2163
  • Country: de
  • This is just a hobby I spend too much time on.
    • Matthias' Hackerstübchen
Re: cheap voltage level shifter for SWD
« Reply #5 on: January 30, 2020, 09:43:06 pm »
How about TXB0104?

https://www.ti.com/lit/ds/symlink/txb0104.pdf

LCSC has it for $0.49 in single quantities. That should check the BOM box and the "widely available in china" box ;)
Everybody likes gadgets. Until they try to make them.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17810
  • Country: fr
Re: cheap voltage level shifter for SWD
« Reply #6 on: December 27, 2022, 06:03:50 am »
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?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: cheap voltage level shifter for SWD
« Reply #7 on: December 27, 2022, 06:25:24 am »
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
... If pullup or pulldown resistors are connected externally to the data I/Os, their values must be kept higher than 50 kΩ to ensure that they do not contend with the output drivers of the TXB0104 device. For the same reason, the TXB0104 device must not be used in applications such as I2C or 1-Wire where an open-drain driver is connected on the bidirectional data I/O.
« Last Edit: December 27, 2022, 06:27:15 am by ataradov »
Alex
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17810
  • Country: fr
Re: cheap voltage level shifter for SWD
« Reply #8 on: December 27, 2022, 06:15:28 pm »
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
... If pullup or pulldown resistors are connected externally to the data I/Os, their values must be kept higher than 50 kΩ to ensure that they do not contend with the output drivers of the TXB0104 device. For the same reason, the TXB0104 device must not be used in applications such as I2C or 1-Wire where an open-drain driver is connected on the bidirectional data I/O.

Yeah, 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.
 

Offline ConKbot

  • Super Contributor
  • ***
  • Posts: 1418
Re: cheap voltage level shifter for SWD
« Reply #9 on: December 27, 2022, 06:36:32 pm »
but has anyone used a TXB0104... does that work...?
No.  :popcorn:

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... Etc

Combined 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.

 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17810
  • Country: fr
Re: cheap voltage level shifter for SWD
« Reply #10 on: December 27, 2022, 06:39:12 pm »
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.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: cheap voltage level shifter for SWD
« Reply #11 on: December 27, 2022, 06:44:25 pm »
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.
« Last Edit: December 27, 2022, 06:46:26 pm by ataradov »
Alex
 

Offline ConKbot

  • Super Contributor
  • ***
  • Posts: 1418
Re: cheap voltage level shifter for SWD
« Reply #12 on: December 27, 2022, 07:02:19 pm »
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.

 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17810
  • Country: fr
Re: cheap voltage level shifter for SWD
« Reply #13 on: December 27, 2022, 07:46:43 pm »
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.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: cheap voltage level shifter for SWD
« Reply #14 on: December 27, 2022, 07:52:01 pm »
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.
Alex
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6926
  • Country: es
Re: cheap voltage level shifter for SWD
« Reply #15 on: December 28, 2022, 02:42:36 am »
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...
« Last Edit: December 28, 2022, 02:49:11 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2775
  • Country: us
Re: cheap voltage level shifter for SWD
« Reply #16 on: December 28, 2022, 03:34:44 pm »
SWD is a fast interface. MOSFET level shifter will not work.

I 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.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: cheap voltage level shifter for SWD
« Reply #17 on: December 28, 2022, 05:44:45 pm »
I've seen app notes recommending this method for I2C, although from what you are saying, this would only be for 400KHz.

The 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).

Would a 2N7000 work, or does it have too much capacitance?
2N7000 would work. For I2C at 400 kHz almost any generic MOSFET would work.
Alex
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17810
  • Country: fr
Re: cheap voltage level shifter for SWD
« Reply #18 on: December 28, 2022, 07:46:39 pm »
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.

Yeah, 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.

But really, just get a debugger with direction control logic already there.

Sure, 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.)

 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12494
  • Country: us
    • Personal site
Re: cheap voltage level shifter for SWD
« Reply #19 on: December 28, 2022, 07:51:53 pm »
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.
Alex
 

Offline Pixie dust

  • Contributor
  • Posts: 16
  • Country: nl
Re: cheap voltage level shifter for SWD
« Reply #20 on: October 05, 2025, 02:57:26 pm »
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.
 
The following users thanked this post: spostma

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 6066
  • Country: gb
  • Doing electronics since the 1960s...
Re: cheap voltage level shifter for SWD
« Reply #21 on: October 05, 2025, 03:51:21 pm »
Quote
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.

How 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.

Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->