CH376S USB Memory Stick to Serial/Parallel FAT File System Modules?

2,194 views
Skip to first unread message

Mike, K8LH

unread,
Aug 1, 2017, 10:17:21 AM8/1/17
to RC2014-Z80
Has anyone written drivers to integrate one of these reasonably inexpensive Chinese modules into the CP/M operating system on the RC2014?  It allows you to open/read/write/append files on a FAT formatted USB memory stick over a serial or parallel interface.  I heard about them last year after reading this article and I ordered a pair of them from a vendor on AliExpress for $2.75 each (including shipping) at that time.  Unfortunately, I haven't had a chance to play with them yet.

I was wondering if you couldn't simply create a number of files on the USB stick, each file representing a 'drive', then build the drive structure by inserting sectors into the file at the correct locations for the master boot record, volume table of contents, directory, etc.?

Could this be a viable and usable CP/M storage solution?  

Cheerful regards, Mike - K8LH
CH376S Module.png
CH376DS1 Flash Controller Datasheet.PDF

Mike, K8LH

unread,
Aug 1, 2017, 10:27:58 AM8/1/17
to RC2014-Z80
Do you think this module might also support SD and uSD  cards plugged into it via an SD-to-USB adapter?

Scott Lawrence

unread,
Aug 1, 2017, 10:32:36 AM8/1/17
to rc201...@googlegroups.com
The CP/M system BIOS is based on a drive/track/sector system.  This is why CF cards work so well for it, since you can address CF storage in that way, and also why for the CF solutions, it works on the block-level of the CF cards. 

I'm still working on a solution where the drive/track/sector are stored as individual files on a FAT filesystem, which will greatly simplify creation of storage devices.  My implementation will happen over the serial/console connection, but it could just as easily be through another port to a device like this.  

-s

On Tue, Aug 1, 2017 at 10:27 AM, Mike, K8LH <k8...@arrl.net> wrote:
Do you think this module might also support SD and uSD  cards plugged into it via an SD-to-USB adapter?

--
You received this message because you are subscribed to the Google Groups "RC2014-Z80" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rc2014-z80+unsubscribe@googlegroups.com.
To post to this group, send email to rc201...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rc2014-z80/8d2637e2-bab1-43aa-809f-16fb24ebc6c9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Scott Lawrence
yor...@gmail.com

Eric Matecki

unread,
Aug 1, 2017, 11:11:27 AM8/1/17
to RC2014-Z80
I'm currently working on it.
And I think, if I believe everything in the datasheet, that it should work pretty well for CP/M.
But, not much success for now :(

I've ordered a few more boards to modify them for testing some of my theories of failure.

The way I want it to work is to create a 128MB file on the USB stick to contain all the drives, much like the 'raw dump' of the CF, so you can use the same tools on your mainfra... err PC as with the CF image, but directly on a file on the stick, no need to dump then restore the raw data.
A second step will be to enable the user to select the file he want to use, so on a several gigabytes stick you can put many complete sets of 16 CP/M drives.
Then maybe use a 8MB file per disk, so you can 'eject' a 'floppy' from drive 'X' and 'insert' another one.
But the CH376 can only keep a single file open at a time, so copying from one drive to another can be slow (everything is relative, compared to a real world floppy drive it will *probably* still be lightning fast... but we are already spoiled with the speed of the CF)
And then a ROM monitor which can load a file to paged RAM, and execute it.
And the ultimate... load/save in nascom basic :)

That's the plan, but first step first, just get the d..n listing of the files on the stick to work...
Once that works, the basic protocol/timing is worked out, and the rest should follow smoothly.

The CH376 chip itself can handle SD cards, but that interface is not connected in this board.
Up to now I haven't seen any CH376 board with SD support, which doesn't mean such a board doesn't exists.
Using an USB<->SD adapter should work, as it emulates an USB stick and the CH376 has no idea you are cheating.
Even USB harddrives works according to the data sheet. Terabytes of storage for the RC2014 :)

@Scott 
The drive/track/sector paradigm is not a problem, for the CF this is already converted to LBA ('logical block address' or something alike), which is just a single number.
And because the CH376 can read any part of a file of any length, reading 128 byte 'sectors' is easy, and we can get rid of the deblocking algorithm.

Eric Matecki

unread,
Aug 1, 2017, 11:14:45 AM8/1/17
to RC2014-Z80
The CH376 can also (OVER)WRITE any part of any length of a file, obviously....

Mike, K8LH

unread,
Aug 1, 2017, 12:00:51 PM8/1/17
to RC2014-Z80
Thanks, Eric.  Hi, Matt.

Eric, your 'plan' is similar to mine, though I have a lot of research to figure out CP/M disk structure and organization.  I'd also like to have partitions which include pseudo drives for Apple DOS, ProDOS, and Pascal.  I wrote low level Apple firmware drivers for those operating systems for the Xebec 'Sider' hard drive back in the 80's.

Please let us know how you're doing on the project with periodic updates?  I may just break out a PIC board and start playing with the CH376S units I have at hand.

Cheerful regards, Mike

Eric Matecki

unread,
Aug 1, 2017, 2:22:33 PM8/1/17
to RC2014-Z80
Get a 3.3V PIC...
I think most of my problems are due to the fact the CH376 is powered by an onboard 3.3V regulator,
so it's signals are barely at the limit of what the '2014 understands as a '1'.
I know this is the normal behavior when connecting 3.3V and 5V devices, but I tried it anyway.
Sometimes it works... for some, shorter or longer, span of time, depending on who knows what.
Sometimes the ch376 doesn't even reset when I send him the reset command as first command.
On one of the additional boards I ordered, I'll remove that regulator and see what happen (the CH376 itself is 5V compatible).
Still 2+ weeks to wait for delivery... maybe I'll sacrifice the only one I have on science's altar :)

You can find a schematic of the board here if you want to try the mod yourself : 
I know the schem indicates CH375, but every trace I was able to follow on the board was as on this schem.
And the CH376 includes a superset of the fcts of the CH375, so they are probably pin compatible.
Be aware you also have to change the cnx of the V3 pin (pin 9) if powering the CH376 with 5V, see the datasheet for that.

My knowledge of CP/M bios is also limited, and only theoretical.
For now I'm just writing an executable udir.com which (should :) lists the contents of the USB stick.
Then ucp.com to copy files to/from the stick.
Much easier to debug the protocols/timings this way rather than in the bios where each bug crashes everything and doesn't leave any hint about the cause.

Peter Fielden-Weston

unread,
Aug 1, 2017, 5:20:42 PM8/1/17
to RC2014-Z80
Eric,

If you are planning to have this board as a daughter board, then you could have logic level shifters on the signal lines. That would simplify things a bit.

Peter.

Tom Szolyga

unread,
Aug 2, 2017, 12:36:10 AM8/2/17
to RC2014-Z80


I found this board.  It is at AliExpress.  URL: https://www.aliexpress.com/item/Free-shipping-1PCS-IC-CH376-CH376S-Original-authentic-and-new/32541831306.html    It has a CH376 with USB and SD Card interface.  Cost is $13 with free shipping.
USB and SD Card.jpg

Mike, K8LH

unread,
Aug 2, 2017, 2:54:02 AM8/2/17
to RC2014-Z80
Hi Eric:

Over on the 6502.org Forum in this thread, Marco was using the CH376S parallel interface on a PIC running at 5v without problems so that's what I thought I would try.

Cheerful regards, Mike - K8LH

Eric Matecki

unread,
Aug 2, 2017, 3:41:20 AM8/2/17
to RC2014-Z80
Connecting the CH directly to the PIC probably works because there is no additional load to the CHs output pins, and it's high level stay high enough for the PIC.
In the past I have used 3.3V chips outputing a good stable 3.1V high level, which is OK for TTL levels.
(By the way, are the Arduino inputs TTL levels or CMOS levels ? )

I have it connected to '2014s data bus, where it has to drive much more inputs, and thru the backplane. The resulting high level is probably too low (or at the limit as it sometimes work for a short time) for the Z80.
Unfortunately I don't have a fast enough 'scope to check this (only a cheapo DSO150 not usable on anything faster than audio signals), and my logic analyzer (open workbench logic sniffer) is happy with 3.3V signals.

I will try to connect it to the I/O boards, and do the comm by software, because another of my suspicions is that the RD and/or WR pulses are too fast for the CH (it only runs at 6MHz, so it is likely !).
Additionaly it will just have to drive a single IC, but I'll need to figure out how to connect its databus to both the I and the O board, with the ICs I have lying around.
However the datasheet clearly explain how to connect it to the data bus and RD/WR signals of the CPU, but I found nothing (in a language I understand, that is..., maybe in part 2 of the datasheet, which is unfortunately only available in chinese...) about the speed/pulse width limits.
Chinese datasheets are not the most clear docs I have read !
All timing diagrams in ch376ds1.pdf only gives the ordering of events, not their 'timing' characteristics.

Anyway, that's the way they do it with the arduino, connecting everything to I/O ports and handling everything by software, so let's try it !
That Arduino Basic blog post linked in the thread looks promising, as it looks like it has sorted out the order of the commands to send to the CH for me :)

Eric Matecki

unread,
Aug 2, 2017, 3:46:23 AM8/2/17
to RC2014-Z80
In my experience logic level shifters are a pain in themselves... I use them only as a last resort :)
The ones I have are the simple 'one transistor' ones designed for I2C, and they need pull-ups and open-collector/drain chips on both sides.
While it will probably work with more advanced (IC based) level shifters, it just doesn't make sense for me to use a 3.3V bus between two chips/systems that work (or can work for the CH376) at 5V.

Mike, K8LH

unread,
Aug 2, 2017, 6:01:05 AM8/2/17
to RC2014-Z80
Eric, I'm not sure what the Atmel/AVR input levels are.  I only just purchased my first Arduino about a year ago when I saw the price of a Nano clone drop below $2.  More recently I purchased a couple Arduino compatible 3.3v STM32 "blue pill" boards (~$1.70 ea.) with 20-KB RAM and a 72-MHz clock.

The more recent PIC devices allow you to select open-drain or push-pull, slew rate, and input level (Schmitt Trigger CMOS or TTL) on a per pin basis.  In fact, recently, I couldn't get a 64K SPI RAM chip to run at 16-MHz until I realized I had to turn off the slew rate control bits for the SPI pins.  I still need to hook up a uSD adapter (with built-in level shifters) and learn how to access a micro SD card correctly.  Just not enough time for everything on my "to do" list (grin).

Regards, Mike




Eric Matecki

unread,
Aug 2, 2017, 7:17:27 AM8/2/17
to RC2014-Z80
More recently I purchased a couple Arduino compatible 3.3v STM32 "blue pill" boards (~$1.70 ea.) with 20-KB RAM and a 72-MHz clock.
At one time I though about getting some of these, as their USB port can be set as USB host, for what I have read somewhere.
Would make something much more powerful than the CH376, and tailored to our use (i.e. keep several 'floppys'(files) open at the same time, could even add a few keys and a 16x2 LCD to choose the 'floppys'(files) to mount in each drive).
But that's yet another platform to learn... (even if it uses the Arduino IDE+compatible libs...)
 
Just not enough time for everything on my "to do" list (grin).
People who have enough time to do everything they want to do have to be pitied...

phillip.stevens

unread,
Aug 2, 2017, 10:57:51 AM8/2/17
to RC2014-Z80
Last year, I spent a long time pouring over the data sheets for these devices, and in the end I decided not to integrate them into my design. The main reason was that, although the data sheets are extensive and seemingly complete, there seemed to be a limited amount of English language experience (code and comments) to draw upon when I inevitably got stuck.

But, at face value they seem to be perfect for storing Gigabytes of data, in a very cheap form factor.

In the end, I decided to stick to IDE, and write some drivers to integrate ChaN's FafFS solution. ChaN's code includes full LFN and Unicode support (he's Japanese) and exFAT, and he keeps it very well maintained.

Reply all
Reply to author
Forward
0 new messages