theopensourcerer / esp8266-programmer

WIP - ESP Device Programmer without solder
0 stars 1 forks source link

Using MCP2221 GPIO for ESP8266 flash / reset #7

Open beetecservices opened 7 years ago

beetecservices commented 7 years ago

EDIT: Possible solution for 2 & 3 being tri-state buffer chip, e.g., 74125 (or variation).

  1. If we want to use the GPIO pins of the MCP2221 to toggle flash/reset then we obviously have to roll our own programmer code. OK, there's plenty of open source code out there so not a problem but it's not something I'd considered so far.

  2. With the MCP2221 being powered via USB, its GPIO pins will reflect it's supply voltage, i.e., logic level '1' will be 5V. I've been looking at the MCP2221 datasheet and can't see a mention of the GPIO pins being tri-state - if they're not then we'd need to protect the ESP8266 pins used for flash / reset, OK 3.3V zeners should suffice (in theory).

  3. Point 2 (above) suggests in USB powered / programming mode, the ESP8266 pins normally held high with pull-up resistors, would effectively be held high by the MCP2221 GPIO pins and pull-up resistors are unnecessary. In battery mode for testing however, the pull-ups would still be necessary. It's not clear to me how to design that.

theopensourcerer commented 7 years ago
  1. Was just an idea - I've read other things where peeps have used a few transistors in a astable type design and got the ESP to automatically go into flash or normal boot mode depending on external factors.

  2. The MCP2221 can be bus powered or it can be powered from VCC. It's spec says from 3.0 - 5.5v so can't we just run the supply from the usb connector via the regulator?

  3. If we run the MCP2221 from 3.3v then we should be able to just have a common pull-up surely? Then if either a physical switch, or the MCP2221 pulls the pin low it should work?

theopensourcerer commented 7 years ago

This looks quite interesting (not read in detail but could be useful as an example_ https://shop.mikroe.com/click/interface/usb-i2c

theopensourcerer commented 7 years ago

I just came across this: http://electronics.stackexchange.com/questions/247612/mcp2221-usb-to-uart-programmer

"A better option might be to use the MCP2200, which has RTS/CTS pins that can be used as-is by the programmer."

theopensourcerer commented 7 years ago

This is what they do on the NodeMCU board: See the DTR/RTS pins and the two NPN Transistors. When Platformio, esptool or the Arduino IDE want to program the board, somehow they send the right commands to the UART controller to raise/lower these two pins.

https://raw.githubusercontent.com/nodemcu/nodemcu-devkit/master/Documents/NODEMCU_DEVKIT_SCH.png

beetecservices commented 7 years ago

DOH! Yes of course the MCP2221 could be powered from the regulator - I hadn't thought of that. I'd also wondered how PlatformIO etc forced programming without me intervening manually. So does it matter if we go the MCP2221 or MCP2200 route? Do you think as the commands to toggle DTR/RTS will be possibly standard that the MCP2200 might actually be automatically compatible with PlatforIO etc?

On 10 April 2017 at 14:19, Alan Lord notifications@github.com wrote:

This is what they do on the NodeMCU board: See the DTR/RTS pins and the two NPN Transistors. When Platformio, esptool or the Arduino IDE want to program the board, somehow they send the right commands to the UART controller to raise/lower these two pins.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/theopensourcerer/esp8266-programmer/issues/7#issuecomment-292946677, or mute the thread https://github.com/notifications/unsubscribe-auth/AFwE69Tq3xl4dM1pF3wSxvyHFDLKSeTOks5ruixOgaJpZM4M2CVO .

theopensourcerer commented 7 years ago

Not sure yet - I did a bit of reading today but it's altogether clear quite how this actually works, e.g. what is really is, and how the instruction from the application which is about to upload the image to the MCU, causes the USB->UART to turn on/off the flow-control pins.

Funny when I worked in Q101 all those years ago RS232 was pretty much what I did every day so I'm familiar with RTS/DTR/CTS etc. But from what I have read so far I haven't understood how it gets from a USB signal/protocol(?) to be interpreted by the bridge.

What I did read was that not all USB->UART bridges are made equal ;-)

theopensourcerer commented 7 years ago

Do you think as the commands to toggle DTR/RTS will be possibly standard that the MCP2200 might actually be automatically compatible with PlatforIO etc?

I think the difference(s) is handled in the "driver" software on the PC end. Each USB->bridge has a unique ID and, in Linux, when you plug something in it looks up this ID and loads the right module for the chipset using udev I believe.

theopensourcerer commented 7 years ago

I think this might be it. https://en.wikipedia.org/wiki/USB_communications_device_class

theopensourcerer commented 7 years ago

Yep - And here is how it works... http://janaxelson.com/usb_virtual_com_port.htm

theopensourcerer commented 7 years ago

The NodeMCU boards use this chip which is considerably cheaper than the MCP (2 for $0.79 inc. postage lol) and obviously works as desired... The only issue/difference I can really see is this requires an external crystal oscillator:

https://www.aliexpress.com/item/2PCS-Original-CH340G-SOP-16-IC-R3-Board-Free-USB-Cable-Serial-Chip/32633935564.html

beetecservices commented 7 years ago

OK, agreed - much cheaper even with (small) extra cost for the crystal oscillator circuitry but we need a tried and tested CH340G circuit if we go surface mount as we obviously can't breadboard for testing.

Presumably we'd need the transistors too - looking at the GizWits board all I can see is J3Y on the transistor packages (and that took my illuminated desk magnifier and a 40x jeweller's loupe). Searching Google shows J3Y S8050 but leaves me 'none the wiser'. They seem to be BJT NPN transistors but they're bloody tiny - if we can find an equivalent in a slightly more manageable package I'd be happier.

I'll push another commit perhaps later tonight or tomorrow (currently with MCP2221 still in place) but it'll get us in-step. I've got the circuit board down to 52mm x 40mm (about 3.2 sq inches) and there's still some room to spare.

On 14 April 2017 at 15:24, Alan Lord notifications@github.com wrote:

The NodeMCU boards use this chip which is considerably cheaper than the MCP (2 for $0.79 inc. postage lol) and obviously works as desired... The only issue/difference I can really see is this requires an external crystal oscillator:

https://www.aliexpress.com/item/2PCS-Original-CH340G-SOP- 16-IC-R3-Board-Free-USB-Cable-Serial-Chip/32633935564.html

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/theopensourcerer/esp8266-programmer/issues/7#issuecomment-294162335, or mute the thread https://github.com/notifications/unsubscribe-auth/AFwE68Q7Qi9KmjCqg35IsfjX30l2f_ioks5rv4G6gaJpZM4M2CVO .

theopensourcerer commented 7 years ago

Did you look at this? https://raw.githubusercontent.com/nodemcu/nodemcu-devkit/master/Documents/NODEMCU_DEVKIT_SCH.png

It's the NodeMCU schematic :-)

theopensourcerer commented 7 years ago

In their latest commit it looks like they have switched to a different chip: https://github.com/nodemcu/nodemcu-devkit-v1.0/blob/master/Documents/CP2102-9.pdf Which is more expensive. The schematics are similar. I guess the issue is with USB compatible drivers for Windows...

theopensourcerer commented 7 years ago

You can get SOIC and other SMD layout to 2.54mm pitch DIP devices for prototyping. But they can be quite expensive. Or of course we could design one using pogo pins ;-) It's a bit "Meta" I know...

http://uk.rs-online.com/web/p/ic-socket-adapters/4546803/

beetecservices commented 7 years ago

Sorry, slow pick up on your last comments...crappy Easter weekend with hacking cough and cold - just about over it.

I hadn't seen the NodeMCU schematic before - that's a useful reference...bookmarked. :)

The CP2102 is the chip used on my USB/UART SIL breadboard module I bought a while back. It works fine but I had to update the udev rules for PlatformIO. The board is about the size of a postage stamp and the CP2102 is a very small quad package which ties in with the datasheet you linked to - QFN-28 (5mm x 5mm). Pin pitch is 0.5mm - count me out on that one. ;)

I've seen those adapter devices - yeah, sod that at the price. Maybe if we were doing design for mass production commercial sale. It was a bit like the ZIF DIL sockets for things like CPUs, EPROMs etc a few decades ago - they cost a fortune in relative terms but dead useful.

WRT your meta comment about designing one with pogo-pins.....LOL - actually not a bad idea. After all, design would be purely physical so no need to worry about schematic as such - just the board layout. :)

beetecservices commented 7 years ago

OK, the more I looked at the CH340G and in particular the NodeMCU schematic, the more it made sense to go that route. After all, it's tried and tested. I'm wondering if there's a more common alternative to the S8050 transistors though - I'll look into that.

I've ordered a pair of CH340G in SOP16 package and also 10pcs of these...

https://www.aliexpress.com/item/10PCS-SMD-DIP-switch-adapter-plate-SOP-DIP-SOP16-turn-turn-DIP16-pin-adapter-plate-to/32792355771.html

I'd seen them before but didn't pay much attention as I didn't have a use until now. Nice idea that they're double sided for SSOP / TSSOP as well although I doubt I'll go near 0.65mm pitch if I can avoid it. It occurs to me they could also be used for SOP8 and SOP14 packages as the package width will be the same.

I also like this circuit as an alternative to having separate RESET/FLASH switches...

http://www.ba0sh1.com/wp-content/uploads/2015/01/ESP8266-boot-select-sch.png

Short press for reset and long press for flash. The full article is here and explains how it works...

https://ba0sh1.com/blog/2015/01/31/esp8266-breakout-board-im-tindie/

Assuming that can be tied in with the CH340G + transistors for auto-programming then it might be a nice feature.

theopensourcerer commented 7 years ago

Nice - I like the idea of the slow/long button :-) I'll order a couple of CH340Gs too then.

theopensourcerer commented 7 years ago

The S8050 is a pretty bog standard NPN transistor by the looks of it:

DESCRIPTION The UTC S8050 is a low voltage high current small signal NPN transistor, designed for Class B push-pull audio amplifier and general purpose applications.

FEATURES Collector current up to 700mA Collector-Emitter voltage up to 20 V *Complementary to S8550

theopensourcerer commented 7 years ago

I've ordered my CH340s and I also came across this (which I ordered as it was cheap): https://www.aliexpress.com/item/DIYmall-SOP16-SOIC16-to-DIP16-Socket-Programmer-Adapter-Double-PCB-Board-SOP16-28-1-27-By/32775537121.html

beetecservices commented 7 years ago

Interesting especially at that price. Seems to be a SOT28 jig but not all pins have been populated - I wonder if you could expand it yourself? Then again, if you wanted a SOT28 version at those sort of price bands, it would make sense just to buy one too.

My ESP-12S came today - not bad, only 11 days. I'll pt it on an adapter plate later or tomorrow.

I'm adding in the CH340G plus the short/long single pushbutton circuit and will push a commit in a bit. I've also turned the 2x 5-way SIL connectors for ADC/GPIO in to a single DIL 10-way header. To fit things on to the PCB compactly it made sense to have the 2x 5-way next to each other. It can still be done with 2x SIL strips but the silk screen will show a single block.

I think the next stage after this commit (assuming you can't think of any additions / amendments to the schematic) would be breadboarding to test the CH340G including the auto reset/flash plus the short/long press circuitry once the components have arrived.

Going back to the S8050 - yes I looked it up too. I found this site which is handy for getting the various parameters but also equivalent devices...

http://alltransistors.com/transistor.php?transistor=52916

If you click the link for "S8050 Transistor Equivalent Substitute - Cross-Reference Search" it lists equivalents. I have some 2N3904 transistors although not listed as an equivalent will suit me for breadboarding. Not sure what to do about the BSS138 MOSFETs used in the pushbutton circuit - RS sell them but only as SMDs so no good for breadboard tests - I'll see if I can find a cheap source of a TO-92 version or equivalent.

beetecservices commented 7 years ago

BS170 seems a suitable equivalent for BSS138 and comes in a TO-92 package for breadboard. Even though minimum order is 10pcs it won't break the bank. :) I've got some other bits I want from RS anyway.

http://uk.rs-online.com/web/p/mosfet-transistors/6714736/

theopensourcerer commented 7 years ago

Agreed on the plan - I'll sort out an order for a few cheap transistors and a USB connector suitable for breadboarding ;-)

theopensourcerer commented 7 years ago

According to my google-fu the S8050 is a bi-polar transistor not a mosfet.

theopensourcerer commented 7 years ago

RS - Sell them: http://uk.rs-online.com/web/p/bipolar-transistors/7390307/

beetecservices commented 7 years ago

The BSS138s used in the push button circuits are MOSFET. I saw the Fairchild S8050 on RS but didn't think they were equivalent to the SMD ones which are made by a company called UTC.

theopensourcerer commented 7 years ago

Hmmm, if you look down this file to the last page where the BOM is, it just says it's a NPN Transistor: https://github.com/nodemcu/nodemcu-devkit-v1.0/blob/master/NODEMCU_DEVKIT_V1.0.PDF.

This is the later design with the CP2102 but they are the same transistors.

beetecservices commented 7 years ago

lol - I think we're talking at cross purposes. I'll recap...

Agreed the S8050s are NPN BJT transistors - I have a load of 2N3904 TO-92 transistors which have almost equivalent ratings to the S8050 except Ic (max collector current) is 200mA instead of 500mA - no big deal so that's what I intend to use for breadboarding the CH340G side of things.

The BSS138 transistors used in the short/long press single push button circuit I linked to previously are, however, MOSFET. From my dim and distant electronics theory I seem to remember MOSFETs are often used in a logical on/off circuit such as used in that circuit although there's no reason why standard BJTs can't be used. If you simply supply enough current to the base of a BJT, the route from collector to emitter is fully open.

Potentially either circuit could use either BJTs or MOSFETs with a little redesigning / change of component values. In theory, you could use the short / long press approach with a single pin of the CH340G (either DTR or RTS - not both) and a state change on that pin could be short or long (in relative terms) to effect the same thing as the manual push button.

In saying that, however, it would take a rewrite of the driver to use only one pin with two different state change timings. Bearing in mind the NodeMCU circuit approach seems to be widely used (the GizWits daugtherboard / USB / UART does the same thing) it seems like a bit of a faff.

I' didn't finish the changes I was intending last night - I'm just about to have another go to put the last few components into the schematic.