Showing posts with label USB. Show all posts
Showing posts with label USB. Show all posts

Monday, February 22, 2021

C64 Emulator for Teensy 4.1 LCD/USB/SD(D64)



Here is my Teensy 4.1 on a breadboard pretending to be a Commodore 64.  USB keyboard, color text, background, border, and D64 (1541 image) support for LOAD/$/SAVE.  6502 emulation supports machine language, and Commodore 2.0 BASIC programs.   Sorry text only, no games, no graphics, no sound, no joysticks, just simple stuff for now.  But that simple stuff works! (mileage may vary, lightly tested, please try this at home under controlled conditions).




Sunday, April 12, 2020

Commodore 64 for STM32F429 Discovery board

So here is a Commodore 64 emulator I built for STM32F429 Discovery board:


Yeah, the LCD is tiny at 2.4", and the emulation runs about 15% slower than an NTSC C64.  But it's running on a small embedded board that's available for under $30 US (DigiKey, Mouser, ...) including mounted LCD display and USB OTG jack.  Just add keyboard, OTG USB adapter, and power supply.

This is a port of my portable C64/6502 emulator for terminal console, which was a port of my Commodore/6502 emulator for Windows Console.   But this time, I dropped the console part, and went for real video (LCD) and USB keyboard support.   Hello PETSCII!

Keyboard mapping (showing my Dell keyboard):
   STOP(ESC) F1 F2 F3 F4 F5 F6 F7 F8            Restore(PrtScr/SysRq) Run/Stop(Pause/Break)
             1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) -_ += Del/Ins(Back)    Ins Hme/Clr     / * -
   Ctrl(Tab) Q  W  E  R  T  Y  U  I  O  P  [  ]  £ (\)            Del           7 8 9 +
             A  S  D  F  G  H  J  K  L  ;: '" Return(ENTER)                     4 5 6
   LShift    Z  X  C  V  B  N  M  ,< .> /?  RShift                     Up       1 2 3
   C=(Ctrl)           SPACEBAR              C=(Ctrl)              Lft Down Rt   0 .   Enter

Features:
  • 320x200 text screen on graphics LCD, with top/bottom border.
  • USB Keyboard (e.g. PC-103) support (symbolic, not positional)
    • Tab maps to C64 Ctrl key
    • Ctlr maps to C64 Commodore key
    • Esc key maps to C64 RUN/STOP key
    • PrtScr/SysRq maps to C64 RESTORE key (supports STOP+RESTORE)
    • PgUp also maps to C64 RESTORE key
  • Full 6502 emulation.  Go ahead, run some machine language on it.
  • Commodore character set
  • Text video at $0400 (address 1024)
  • Text color at $D800 (address 55296)
  • Keyboard scan by writing to $DC00, reading from $DC01
  • Full 64K RAM.  Update 2020-04-14: RAM/ROM/IO/Charset banking is implemented!  And 1K color nybbles
  • 1/60 second IRQ.  So we've got the software clock: TI, TI$
  • Upper/lower case switch ($D018), and reverse characters.
  • Border color ($D020) and background color ($D021).
Limitations:
  • Approximately 85% cpu speed of a real C64
  • No NMI.  No Restore key.  Update 2020-04-15: implemented, see keyboard above.
  • No other device support.  No tape, no disk, no serial, no cartridges, no joysticks, no printer.
  • VIC-II support is limited to getting system booted.
    • No full register support.
    • Text address can't be moved.
    • No graphics support.
    • No programmable characters.
    • No raster interrupts.
    • No sprites.
    • No left/right side border displayed.  Ran out of pixels.
  • No CIA1/CIA2 (except for keyboard data ports, but no data direction registers)
  • No SID.
  • In progress.  There are bugs lurking (for example, the IRQ and USB keyboard stops working exactly at 35 minutes, 38 seconds from start, maybe a resource leak in third party libraries, so we'll call that time limited I guess)
  • Keyboard support may need tweaks for more complete PETSCII key support
  • No CAPS LOCK or SHIFT LOCK supported
  • Doesn't utilize full capabilities of the STM32F429 MCU and discovery board components including 2.0MB of Flash (uses 110KB), 256KB of RAM (uses 83KB), 8MB SDRAM, motion sensor, user leds, user button, or other expansion capabilities.  Opportunity awaits!
Links:
Credit:  

Saturday, July 27, 2013

OpenOCD FT2232H based JTAG Adapter(s) with UART

USB to JTAG, and JTAG to JTAG adapters
JTAG adapters are commonly used to program and debug microcontrollers and microprocessors.  This circuit is a prototype of one that is compatible with OpenOCD which is an open source JTAG program and set of drivers.  The board and circuit presented here is simply a set of connections, jumpers, and sockets that leverage the FT2232H Mini Module as a USB to JTAG adapter. 

Four JTAG and/or SWD ports are provided for compatibility with a variety of development boards: 6-pin ST-LINK, 8-pin LPC-Link, 10-pin JTAG, 20-pin JTAG. 

Using one of two plug in modules, the 10-pin is either 0.05" pitch or 0.1" pitch. I plan to include both 10-pin formats on any revisions to this JTAG board so I can easily adapt between the formats.

When used as a USB JTAG adapter, only one of the JTAG or SWD ports is used.  Note that pin 1 is consistently in the upper left on this board.  Ribbon cables or socket cables are used to connect to the target board.  It is useful to have sets of cables that support all these pin-out formats.  Cables are quicker and easier than single conductor jumpers between individual connector pins.

An alternate use is to adapt from one pin-out to another when using other JTAG and/or SWD programmers.  In this case the mini module can be removed or simply disconnect the USB cable from the computer.  The board is only being used to convert pin-outs.  For example, I can use a 6-conductor socket to socket cable to connect the ST-LINK port to the ST-LINK socket on my STM32F4Discovery board, and then connect the LPC-Link socket via an appropriate cable to an LPCxpresso board.  I have used this method to program and debug my LPCxpresso board for LPC1343 with CooCox IDE.

Multiple JTAG adaptions are possible
  • ST-LINK to LPC-Link
  • ST-LINK to 10-pin
  • ST-LINK to 20-pin
  • LPC-Link to 10-pin
  • LPC-Link to 20-pin
  • 10-pin to 20-pin
  • 10-pin (1.27mm) to 10-pin (2.54mm) in future revision

Boards I was able to communicate with either with OpenOCD, ST-LINK, or CoLinkEx using the JTAG adapter(s) board include:

Caveats and Warnings.  Note that I did not do extensive testing.  I am not sure the RESET and RTCK lines are working.  Some boards I could only connect to using SWD instead of JTAG.  Driver installation and basic use of OpenOCD is not described in this post, so see Getting Started with OpenOCD.

Inspiration and References.  Most of the JTAG circuit is gleaned from multiple FTDI specifications regarding the FT2232H, Mini Module, and related MPSSE Basics Application Note AN_135.  And the circuit is very similar to the FLOSS-JTAG one shown here.


Under belly of the JTAG board
 

JTAG Schematic

Sunday, January 20, 2013

USB RS-485 Adapter Through Hole PCBs Revisited

The second batch of through hole PCBs arrived recently.  I had fixed errors in the original design, moved some components around, corrected the silkscreen, and added silkscreen labels.  The design was uploaded to China, services paid for, and twelve PCBs were handed to me by the postal worker about four weeks later.

The worst offence of the original design was necessary green wire jumps and cuts rework for the Vcc and Vusb lines.  This new board doesn't require any rework.  I built up two boards and one works, and unfortunately I snipped a power line on the second board while trimming leads on a capacitor and some green wire solved the problem (oops, but good save!).

The silkscreen labels are a bit too small to see with my eyes, but make the board more usable.  I moved the JITE socket out so it hangs off the board with the benefit of the board also fitting screw terminals like those used in my (mostly) surface mount USB RS-485 Adapter board.

Saturday, September 29, 2012

PIC18F2XK50 brings $3 savings

These RS-485 Adapters were originally designed using PIC18F2455 (24k flash) and PIC18F2550 (32k flash) in mind, but with the recent introduction of the PIC18F24K50 (16k flash) and PIC18F25K50 (32k flash) some serious cost savings will be achieved. 

These new CPUs are pin compatible with the existing chips, almost $2 (US) cheaper, and have internal oscillators factory tuned to be accurate enough for USB full speed operation.  This eliminates the need for an external crystal circuit including two associated capacitors bringing more than $1 (US) cost savings.

The Microchip Libraries of Applications v2012-08-22 (USB stack), MPLAB IDE v8.87, and MPLAB C compiler for PIC18 MCUs v3.43 support these new chips.  I was able to successfully port my existing code using the new stack, and compile and program the chips using MPLAB.

Thanks to Dangerous Prototypes for bringing the news of these new MCUs to my attention.  And to Microchip for providing samples so quickly.  Some stock of these 5V SPDIP chips is currently available directly from Microchip and more supply will be available in the coming months.

Friday, September 21, 2012

USB RS-485 Adapter Through Hole PCBs

Here is my first PCB design that has gone to production. I redid the schematics of my original design now implemented in Eagle and also did a two layer PCB layout. I used Seeed's PCB service to produce the PCBs, ordered parts from Digi-Key and assembled them by hand. There were two mistakes with the board. Somehow I didn't connect VCC from USB, and inadvertently connected VCC to VUSB. Three cuts and three jumpers later and the boards work fine.

Friday, December 16, 2011

Learning Surface Mount Soldering by Experience

Soldering together this Duemilanove (Arduino 2009 model) was my third attempt at surface mount soldering (first was FTDI232RL, second was PIC32). 

This was a roller coaster ride as it included a number of successes and failures.  Is it pretty? Not so much, but it works!  In the end it has been a success as the board works and I learned a lot. 
What exactly did I learn?

1. Dab some flux to the solder pads and tin them.  Heat the fluxed solder pad and apply a light coat of solder.  The flux and heat will suck the solder quickly so be careful to use little solder.

2. Use less solder, get the soldering iron hot enough, use a fine solder pitch, and a fine solder iron tip.  This board is a mess because I applied too much solder and many of the solders look horrible probably due to not enough heat.

3. Be careful desoldering.  I tried to clean up some messes with desoldering braid.  I wasn't very careful and tore off some solder pads.  This required three reworked lines.  You can easily see two, and a small one is in the top middle.  Using a continuity test mode of my multimeter and comparing a bare board with the board under test was very useful in isolating problems.

4. Order the right parts.  Double and triple check parts.  I ordered the bare Duemilanove PCB boards from Hong Kong via eBay, ordered most of the parts from Mouser, and some I already had on hand. 

But I ordered the voltage regulators in the wrong package size (8 pin instead of 3 pin), and ordered the corrected part from DigiKey.  But on the second try I had recorded a fuse part number for DigiKey, and ordered it blindly, and it turned out to be the completely wrong part - wrong value and wrong size.  I still don't have the right fuse.  And I never figured out the right diode.  It would probably take three or more orders to get the right parts.  In the end, I shorted the fuse and diode pads with bare wire, determining these are optional in this circuit design.  Also, I didn't realize I was out of USB sockets and had to purchase some locally. 

5. Order the correct quantity of parts.  I had three PCBs, and ordered most parts in quantity of five just to have extras.  For resistors and capacitors I ordered in quantity 100 to get the good price break and have extra stock on hand for future builds.  But the LEDs I bought only 10 and each board uses 4.  After losing one LED, and soldering one to a test board, I was short 4.  On my second parts order I splurged $8 to get another 100 LEDs.

6. I was able to use 20-pin breakaway sockets found at a local surplus warehouse to create the 8-pin and 6-pin sockets.  I had breakway sockets that already had indents per pin (not smooth), but those ones didn't match well with the standard ones.  Reading comments on SparkFun's site I learned that the standard sockets are created from the 20-pin ones even though they look smooth.  The only caveat is you lose one pin when you cut them (I used the cutter on my wire strippers), and if not done correctly you are unlocky and lose one of the pins you wanted to keep.  I was lucky this time.  Part numbers from DigiKey are also listed at SparkFun at the above link if you want them to cut them for you.

7. Reviewing the Arduino Duemilanove Eagle schematics and gerbers were indispensible for identifying parts and performing the assembly.  I was able to export the BOM from Eagle, but had to research most every part.  Also finding a high resolution picture of an assembled unit helped identify where to place the parts.

8. Soldering the FTDI part (FT232RL) was tricky to remember how to do it well.  It is a 0.65" pitch 28-pin device.  That's a lot of pins in a fairly dense package.  In the end, what worked best was dabbing just a tiny bit of solder on the tip of the iron.  Very very tiny dab.  And then applying the hot iron to the end of the fluxed pin.  Do every other pin, to let the hot solder cool before revisiting.  If I tried soldering consecutive pins or didn't have a steady hand, then the pins could short.  There still might be some shorts, but this design doesn't use every single pin, so I got away with a sloppy job again.

9. The Duemilanove can use an Atmel ATMEGA328-PU instead of an ATMEGA328P.  Since I ordered five CPUs, this saved me 68 cents per, or $3.40 total.  The difference internally is some additional low power idle statements yet doesn't appear required for Arduino programming.  To load these CPUs with the bootloader I had to follow some additional steps in addition to the standard tutorial on loading the bootloader.

10. Buying pre-built boards is much cheaper and efficient. It took me a week to build and test this, and multiple orders. Justing buying an existing board would have been much easier and cheaper.  But the experience is priceless.

11. I can do this!  Even with a cheap 30-watt Radio Shack soldering iron and a coil of lead-free solder.  Though I am considering purchasing a much higher quality iron.

12. Next step is to design my own PCB with a combination of through hole and surface mount components to balance physical size, price, and ease of build.  That will be another learning experience!




It works!  Shown with my thermometer board

Friday, December 2, 2011

USB PIC24 and PIC32 SPDIP Arduino

PIC24FJ64GB002 shown
Microchip has just released a SPDIP-28 PIC32.  This chip is pin compatible with the PIC24 which I have been developing for, and my latest toying has been with Arduino style boards, so I was determined to combine the two.

In the last week I have developed a prototype USB Arduino format board using a PIC24 or PIC32 as its CPU.  The Arduino format consists of the standardized 8 and 6 pin headers for I/O and power.  This was accomplished starting with an empty Arduino shield prototype board and building up as a PIC single board computer instead of a shield.  Now standard shields can be attached to this board.

The two CPUs I am targeting to support with this board are PIC24FJ64GB002 and the recently released PIC32MX220F032B.

The power circuit, ICSP (on left), and USB have been tested.  The PIC24 running a CDC (Serial over USB) project is recognized by the host PC.  Next step is to test the FTDI serial connector (on right), and all the analog/digital pins.  Following that is to add a crystal and capacitors to get USB support for the PIC32 (I wonder if I can do that on a shield?). All pins are exposed via the Arduino shield interface, so it is super expandable.  The red LED is for 5V power, and the green LED is for 3V3 power.  The button is the reset switch.  No user I/O are provided, must be accomplished by add ons.

The missing piece is the Arduino development environment support for PIC24 and this low end PIC32 chip.  That's a pretty big missing piece.  For now I can develop using Microchip's MPLAB 8 and MPLAB X.  I am hoping to use the chipKIT Arduino Development Environment for this board soon as it would be nice to program with Arduino sketches and C++. 
PIC32MX220F032B shown
Underbelly

Tuesday, September 6, 2011

My own first PIC32 Development Board

Here is a USB PIC32 development board that is in progress.  I bought a bare 64-pin PIC32MX795F512H which is the highest end Microchip 32-bit CPU, except for having 36 fewer pins pins than its close sibling.  This CPU has 512K Flash, 128K RAM, and runs at 80MHz.

It was soldered to a breakout board that is connected by dual row 0.1" 16-pin headers so it can be mounted in sockets on a standard solder breadboard.  It has three symmetrical 8 pin headers which expose shared SPI/UART (total of 6 RX/TX pairs), and power lines.  Jumpers choose between USB host and USB device functionality.
The first test of this board was as a four port RS-485 monitor.  I was able to enhance the monitor's protocol to support four sources, then enhanced it as a bidirectional adapter.  The code is built on Microchip's USB device CDC sample and shared among various PIC targets, so the code is also supported on other various 8-bit and 16-bit PICs too.

A planned test is to breakout the RMII/MII lines to an Ethernet PHY and test the Ethernet capability of this CPU.  I purchased a QFN 36-pin SMSC LAN8700 PHY but unfortunately I cannot find a compatible breakout board for it.  Nine pin sides seem to be an odd number, and the breakouts I have tried are built for even numbered pins per side making this one just a bit too small to work with the traces.  My next plan is to try a QFN 24-pin SMSC LAN8720 PHY.

Another plan is to get it to work with the chipKIT Arduino-Compatible Prototyping Platform so it can be programmed in C++.

Monday, August 8, 2011

mbed Text LCD development board


This is my take on an mbed development board to support different LCD sizes.


The three sizes shown here are 20x4, 16x2, and 8x2.  Some LCD screens have a single row of 16 pins.  Others have two columns of seven (or eight) pins.  I developed this board to not hard-wire any connections except those dedicated on the mbed itself.  The LCD screen can be wired up in 4-bit (shown) or 8-bit mode using any available I/O lines.  Additional sockets are provided for USB host, USB device, Ethernet MagJack, and microSD.  Four switches with sockets are also provided.


eBible with power from Motorola


As most everything was socketed and not hard-wired, there's a lot of solder bridges connecting the sockets.  14 or 16 of the LCD socket connections are wired together in a mass of wire under the board.  This allows using jumper wires for just the top 16 wire socket, and plugging in any of the three LCDs that I have.  One of the LCDs was modified to grab power from the 2x7 socket.  Another has an additional two leads that are socketed.  The reason for the two different 2x7 sockets was that the functions of pins 1/2 were reversed on the 16x2 LCD display.  Alternatively, I could have used a switch or relied on changing the jumper wires.

The microSD has 7 connections, so just provided a 7x2 socket, and this requires jumpering the lines to the mbed.  I can then choose which SPI connections to make, and what line to be the chip select and/or card detect.  I attach a microSD breakout board from SparkFun.

The Ethernet MagJack is hard wired except for the LEDs.  A specific breakout board from SparkFun is required.

A USB device jack is socketed to support a mini USB device breakout board.  Alternatively a USB-A cable can be connected.

Power (3.3V) and ground buses are included, hard wired to the mbed.

Wednesday, August 3, 2011

PIC24 USB + Serial Development Board



Two main emphasis of this board are USB and Serial as well as using socketed components.  The 28-pin PIC24FJ64GB002 can perform as either a USB host or USB device, using jumpers to select between the connected USB socket.  The USB jumpers are also configured so when the PIC is USB host using the USB-A connector to attach a thumb drive, the USB-B connector may be configured to attach to an FTDI FT232RL chip to act as USB serial.  Using a USB-A to USB-B adapter, both the PIC and the FTDI chips could be active as USB devices. 

Two serial channels are jumpered for either RS-485 or RS-232 (DB-9 connectors not shown), or the second serial channel can be jumpered to the FTDI USB serial connection.  As configured here, RS-485 uses RX/TX with RTS to select whether reading or writing.  RS-232 can use RX/TX with CTS/RTS.  The ICSP (in circuit serial programming) connection in the lower left works with ICD or PICKit programmers, and shares the lines that provide CTS/RTS, so jumpers are provided to choose between those functions.  The PIC24 has quite a few 5V tolerant inputs, but I ran out of enough of them, so a 5V/3V3 logic level conversion board is socketed to read the CTS lines at 3.3V from the 5V MAX232 and MAX233. 

Voltage regulators are included to power 3.3V and 5V buses, accepting power from USB or 7V-12V external power.  Each module has a power jumper to effectively disable them.  The USB sockets have jumpers to selectively attach power to the 5V bus.

One SPI channel is also configured, allowing connection of features such as a micro SD card and/or SPI Ethernet.  This board specifically supports connection of a Microchip's PICtail Ethernet (ENC28J60) board.   

Wednesday, July 27, 2011

FTDI USB to Serial module

This FT232RL is a popular chip used for converting TTL level serial lines to/from USB serial.  You can find it used with Arduino micro cpus and similar.  The chip supports any voltage logic.  Here it is using 3.3V or 5V logic depending on the jumper setting.  A 3.3V regulator is included on chip.

I used a breakout board from SparkFun to adapt the 28-pin SSOP to 0.1" pitch headers.  This was my first attempt at soldering a surface mount chip.  I was successful soldering the important pins.  Using dual row header sockets, I was able to construct this as a prototype module, making all pins available for use.  LEDs are present for power, RX, and TX.   Sample circuits are available in FTDI's datasheet.

Monday, July 25, 2011

PIC18F2550 RS-485 Adapter

Here is the first RS-485 monitor or adapter I built in small quanity.  I started with a RS-485 board from Modtronix, and used their prototype daughter board to add a USB connector (note: required two simple cuts to get USB to work).

My firmware for the PIC18F2550 adapts USB serial to RS-485 and vice versa (bidirectional).  It bridges the gap between the PC and 9-bit RS-485 protocols.

Also, here is a breadboarded version from scratch that uses identical firmware.  The RS-485 A/B wires are not show, would leave the LTC1487 chip at pins 6/7.  A USB B socket breakout board is used to help prototype the circuit.

Sunday, July 24, 2011

Any Chip prototyping board with USB

Here is a prototyping board I developed in early 2011.  It is a step up from breadboarding in that it has a couple switches, USB connector, LEDs, 3.3V and 5V voltage regulators, power LEDs, screw terminals, and a small breadboarding area.  All the components are distinct and not connected to each other except for some ground connections and ground pins.  The LEDs have a socket for a resistor array based on the voltage used.  This prototype board is agnostic to the chip manufacturer or chip type.  The USB connector can be used just for power, or used as a USB device with the right chip.  It can fit up to 48 pins of narrow chips.  Like the 28 pin PIC18, 28 pin PIC24, 8 pin LTC1785, 16 pin MAX232, etc.


Also shown are the underside, PIC24 glue board, and glue board plugged into prototype board.  The PIC24 glue board is the only portion that makes it Microchip PIC24 specific.  This glue board has all the shared ground and 3V3 connections as well as capacitors and ICSP connector.  The result is using up two of the rows of connectors, but relieving a lot of wiring common to PIC24 USB implementations.  There's no stopping one from creating other glue boards with other functionality.

The original goal of this board in addition to being manufacturer agnostic with some common components, is to be the basis of a PIC24 RS-485 monitor prototype.  More on that later.

PIC24FJ64GB002 with LT1785 and LTC1487