SLE4442 Smart Card adapter (KF-011C)

Walks to the market always solve problems. To make the half duplex PIO thing feature complete with the hardware UART it needs to be simplified.

TX

  • set the total number of bits to write in the upper four bits of the PIO FIFO along with the total packet with parity (or none) and stop bit(s)
  • add the parity and stop bits in code before handing to PIO to just shoot them out.

RX

  • trickier because we want the pio to handle at least one stop bit to toss garbage data
  • set bits to read at total length - 1
  • handle the single or final (if 2) stop bits in PIO
  • software deals with parity or 1st stop bit error

Yeah! Received a replacement logic analyzer and I can finish up this mode.

    pio_sm_exec(pio, sm, pio_encode_set(pio_y, bits));

The PIO can be forced to execute commands. In this case I set the y register with the number of bits for a single TX/RX (data bits + parity bit + stop bit(s) - 2) action, then reload the x counter from that on each cycle. Easy!

RX is working, now to hook up the logic analyzer and finish the transmit. Then tidy everything and we have a new mode feature complete vs the uart mode. Can’t believe it was this easy.

1 Like

This is the SIM card ATR reply.

image

Transmit is 99% done, but output needs to be inverted.

gpio_set_oeover(pin_tx, GPIO_OVERRIDE_INVERT);

This works fine in the I2C PIO stuff, but when I use it here the output just disappears. It’s very strange, probably something obvious after I step away from it for a moment.

1 Like

gpio_set_outover(pin_tx, GPIO_OVERRIDE_INVERT);

Such a tiny difference. Things seem to be going now. I’ll clean up and push.

2 Likes

Seems to be working. I only tested the 8/E/2 mode for the SIM card, there may be bugs at other settings, but I think it’s ok. I’m going to push now.

Now to learn how to read from the SIM.

1 Like

I just got replacement board. Flashed fresh FW and I get:
2WIRE> sle4442
Card not found

I tried many cards that I previously wrote because I thought that if there are all blanks then detection of ATR might not work but seems not the case.

Leds for power and card detection shine. I checked with continuity metter my solder work and seems fine. Is there some regression while cleaning up code?

1 Like

No its worse than that :rofl: The pinout on that version of the adapter board doesn’t play well with the PIO, so I used jumper wires in development. I connected VCC/GND to VOUT/GND, and then IO/CLK/RST according to the labels on the displays.

I think I could actually make it work now that I understand the PIO side set arrangement better, but the next revision of the board has already been reconfigured :face_with_open_eyes_and_hand_over_mouth:

1 Like

Now when I look whats on labels and on the screen it would make sense.

And yes hacking in the dark always comes better😅

So I see two options. You implement something ugly to support that. Or I just order the final board and like that I can play also with the SIM cards

Do you have a few jumper wires? Or the probe cable?

ImportedPhoto_1711642949707

This is how I’ve been debugging. Note that this is the wrong pin connection for the SLE4442, a pin is swapped for the clock I think (not on the cards, on my debug setup).

I do have a probe cables. But well all that precise soldering for nothing😭

I also have some SmartCard connectors with thru hole pins so I could simply wire up that connector right

Sorry about that. I generally brute force my way through the first prototype and read the datasheet when I have something to work on.

No problem. But I will like to buy one of those final boards.

I can send the new board and connectors and stuff that arrived today. I think it is the final version, we’re getting production quotes. The only thing is the micro SIM socket is a real pain to solder, but do those really exist anymore?

1 Like

I’d like to get one and solder myself. Thanks

I mean if you may send it it would be awesome

1 Like

Sign me up for one as well.

1 Like

media_20240329_131852_3307454442020415914

I put together 2 kits and will mail it off to you both.

image

Be sure to solder the shell the best you can, because the metal thing will slide off.

Everything tested ok EXCEPT the micro sim. May need a new part. It’s really ugly.

1 Like

Wrote a loop to power cycle, pause, enter wrong password, pause, enter correct password and reset counter.

image

Measured the output of the current sense op-amp from pin 4 with my scope.

ImportedPhoto_1711803294815

Alas, no repeatable triggering above the noise floor. This is probably because we’re measuring before about 10uF of capacitors, which are absorbing the big hit.

All is not lost. We can make an external version of the sense circuit and put between the card and all caps. The Bus Pirate iSense scales 0-500mA to a 0-3.3volt output, and uses a 0.2 ohm resistor.

image

Conveniently they don’t specify read/write/erase current in the datasheet. But, an isense that is 10ma or 12ma max will give a lot more resolution on small changes. A bigger voltage drop resistor would get rid of some noise because the op-amp gain will be a lot less.

I’ve only ever seen this done with an FPGA, so maybe we can’t react fast enough with the RP2040. In that case, something like the current limit circuit controlling all IO pins and power through PFETs would be even faster than an FPGA and a lot cheaper.

I managed to solder Smardcard adapter and it works! Flashed new firmware to check it out. And I am missing dumping SLE4442 content to file. May I request that?