ENTERPRISE KLUB
2019. május 25., 1055 Budapest, Nyugati tér 9. 14-19 óráig
Részletek
Welcome, Guest. Please login or register.


Author Topic: SD card interface (Read 97658 times)

Offline lgb

  • EP addict
  • *
  • Posts: 3496
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 31.0.1650.34 Chrome 31.0.1650.34
    • View Profile
    • http://lgb.hu/
Re: SD card interface
« Reply #45 on: 2013.October.29. 11:00:44 »
Quote from: Saint
Yes, although I need a clock for the SPI interface. The choices are either an onboard oscillator, or use one of the clocks from the Enterprise (at the expansion port). Given the extra work and cost in the cartridge version (the cartridge body itself), I'm starting to think the expansion port version is looking better... and certainly cheaper.

65SPI has programmable clock divisor inside. Maybe you need it, SD specification says that before the SD card identification, you should keep the clock under 400KHz and you can increase the speed only, if you have the card type, and it allows it. However: I guess not so much newer card are so restricted (but maybe the specification is treated literally that init needs low clock rate even all of the new ones allows higher clock later), and also, 400KHz SPI clock is still 50kbyte/sec, which is not so bad transfer rate for a 8 bit machine. It's also interesting to calculate what is the maximum transfer rate a 4MHz Z80 can do with IN/OUT data while read/write memory. If it's far above 50kbyte/sec, than the ability not to use only a fixed 400KHz SPI clock can be useful, but not so much otherwise ...

Cartridge does not have too much clock from the EP, I guess, so yes, it can be a basic issue to have any clock as the starting point, but a simple canned oscillator (not just a crystal) is still cheap alternative. And with cartridge the connector itself is non-issue, the PCB is just enough. For people doing EXOS 2.4 modification, they don't even need a cartridge otherwise. The only disadvantage I can see is the lack of signals you may need, like some clock, or if you need other thing as well ... ?

However power supply is also interesting, I've read somewhere that in certain cases, an SD card need even 200mA or more for some very short time. Also, hot plugging an SD card is a bit problematic, but maybe you don't want to do that anyway?
« Last Edit: 2013.October.29. 11:27:04 by lgb »

Offline Zozosoft

  • EP addict
  • *
  • Posts: 13334
  • Country: hu
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 24.0 Firefox 24.0
    • View Profile
    • http://enterprise.iko.hu/
Re: SD card interface
« Reply #46 on: 2013.October.29. 11:01:56 »
Quote from: Saint
I'm starting to think the expansion port version is looking better... and certainly cheaper.
But it is need a bus expansion board for use with existing expansions. Or put some connectors to your board.

Offline BruceTanner

  • EP user
  • *
  • Posts: 482
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 30.0.1599.101 Chrome 30.0.1599.101
    • View Profile
Re: SD card interface
« Reply #47 on: 2013.October.29. 11:18:36 »
WIZnet (who do the module I previously posted a link to) do a tiny SPI module with TCP/IP built-in - not much bigger than a RJ45 ethernet socket!:

http://www.shopwiznet.com/wiz820io

$20, requires 3.3V power but has 5v-compatible I/O.


I've found some z80 code from a MSX ethernet project that uses a similar (but not the same) WIZnet module:

http://www.konamiman.com/msx/denyonet/source/denyotcp.asm

so even with a WIZnet chip that does the tcp/ip there is a fair amount of supporting code. And that just gets you TCP/IP - you still need a protocol to run on top of that, so there would be a few K more.

Offline lgb

  • EP addict
  • *
  • Posts: 3496
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 31.0.1650.34 Chrome 31.0.1650.34
    • View Profile
    • http://lgb.hu/
Re: SD card interface
« Reply #48 on: 2013.October.29. 11:34:38 »
Quote from: BruceTanner
WIZnet (who do the module I previously posted a link to) do a tiny SPI module with TCP/IP built-in - not much bigger than a RJ45 ethernet socket!:

http://www.shopwiznet.com/wiz820io

$20, requires 3.3V power but has 5v-compatible I/O.

Funny :) If some need only/mainly ethernet and not so much SD, I would avoid SPI, as this vendor has module with parallel bus as well, which needs almost only some wires and works without any extra interfacing as far as I can see, that is: WIZ830MJ (however that was your idea on the forum originally I think). But the advantage is huge (the cost is: the embedded MCU in these stuffs are more powerful than the Z80 itself, it always bothers me somehow), you don't need UDP/TCP/IP/ARP/whatever for the Z80 to be coded! Now it's almost the "with SPI or without SPI" question, a generic SPI interface is great, etc, but sometimes I feel if you have a parallel already done solution (WIZ830) it's much easier to work with.

Offline BruceTanner

  • EP user
  • *
  • Posts: 482
  • Country: gb
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 30.0.1599.82 Chrome 30.0.1599.82
    • View Profile
Re: SD card interface
« Reply #49 on: 2013.October.29. 12:46:05 »
lgb I share your reservations about using current technology to add something that is more powerful than the Enterprise itself, it seems wrong somehow, and if taken to it's logical conclusion you would end up replacing the motherboard and running a superfast emulator! But practically, if you want ethernet on the Enterprise you have two choices: a powerful add-on or write a tcp/ip stack. I don't fancy the second choice! (I'm sure the source code for a tcp/ip stack is freely available but they are nearly aways written in C etc so there is a code size/speed issue). Think of it the same as graphics cards for PCs which often used to be more powerful than the PC itself.

I also agree the WIZ830MJ would be a better choice if we were not talking about an SD card interface too - the interface is a good match for the z80. I was hoping to make this my winter project before saint raised the possibilities of an SD card interface. Maybe it is time to forget the ethernet interface for now and concentrate on just the SD card. It would be nice if they could both be used at the same time though.

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 30.0.1599.101 Chrome 30.0.1599.101
    • View Profile
Re: SD card interface
« Reply #50 on: 2013.October.29. 14:18:53 »
Quote from: lgb
Some off-topic: for some very simple tasks (like trying to interface an AdLib/SoundBlaster OPL2 chip) it's even OK to "overlap" the basic ROM in the cartridge, as only write access to OPL2 is OK to be able use it, and it's not interpreted by the ROM anyway, so ROM area can be re-used for write access for extra hardware.

That's a nice idea that I'd not considered, however we require read and write access in this case, so I cant use it here. One to remember though.

Quote from: lgb
65SPI has programmable clock divisor inside. Maybe you need it, SD specification says that before the SD card identification, you should keep the clock under 400KHz and you can increase the speed only, if you have the card type, and it allows it.

Yes, the SPI Master interface has configurable phase, polarity and clock divisor from /1 through to /256. As you say SPI must be configured with a 400KHz or less SPI clock.

Quote from: Zozosoft
But it is need a bus expansion board for use with existing expansions. Or put some connectors to your board.

Eurgh, yes, this is true. I keep changing my mind about the best way to handle this expansion. Additional expansions are not really an issue for the majority of Enterprise owners here in the UK, but for those with the Spectrum emulator for example, then I'm sure it would be good to be able to use the SD card with that. Or even copying files from floppy to SD on the Enterprise itself.

I'll give the cartridge some more thought. It should just require an additional oscillator on the board, rather than using one of the Enterprise clocks. This could be clocked at a higher rate as well, like 20Mhz. Although I doubt the SPI throughput will be a bottleneck here.

Quote from: BruceTanner
WIZnet (who do the module I previously posted a link to) do a tiny SPI module with TCP/IP built-in - not much bigger than a RJ45 ethernet socket!

I've found some z80 code from a MSX ethernet project that uses a similar (but not the same) WIZnet module.

The ENC28J60 is less than £3, and there is already Z80 based source code for the SpeccyBoot project which can boot over ethernet using this chip. The only difference is that the SPI interface is "bit banged" rather than using a nice hardware SPI master interface. It depends on what you want to use the ethernet for, but in this example it loads files from a TFTP server. It's not a network share, but using FTP as a remote drive for the Enterprise may well do just fine!

My intention is to concentrate on the SD card side of it, but make sure there is expansion capability for other SPI devices such as ethernet or USB. May as well make this thing reasonably universal if it's possible to do so.

Offline lgb

  • EP addict
  • *
  • Posts: 3496
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 31.0.1650.34 Chrome 31.0.1650.34
    • View Profile
    • http://lgb.hu/
Re: SD card interface
« Reply #51 on: 2013.October.29. 14:36:19 »
Quote from: BruceTanner
lgb I share your reservations about using current technology to add something that is more powerful than the Enterprise itself, it seems wrong somehow, and if taken to it's logical conclusion you would end up replacing the motherboard and running a superfast emulator! But practically, if you want ethernet on the Enterprise you have two choices: a powerful add-on or write a tcp/ip stack. I don't fancy the second choice! (I'm sure the source code for a tcp/ip stack is freely available but they are nearly aways written in C etc so there is a code size/speed issue). Think of it the same as graphics cards for PCs which often used to be more powerful than the PC itself.

Well, don't misunderstand me, it's some kind of the "eternal question" for me, that how "fair" to expand a 8 bit home computer with a hardware much more powerful than the computer itself, while at the same time: how cool that nowdays we _can_ do this and integrate these computers into an environment was never even planned by its designers originally. I've already written some kind IP/UDP/ARP for 6502, but not so much TCP. It won't be extra hard, but certainly it will be limited (IP fragmentation issues, MTU, etc), slower, and memory hungry that you definitely need memory expansion. Andyes, good example that was exactly the example I thought about before read your sentence about graphics card :) So sometimes I "fight" for
use the simplest solution as possible, but I want to integrate the whole universe at the next second. Annoying style of me, I must admit ...

Quote
I also agree the WIZ830MJ would be a better choice if we were not talking about an SD card interface too - the interface is a good match for the z80. I was hoping to make this my winter project before saint raised the possibilities of an SD card interface. Maybe it is time to forget the ethernet interface for now and concentrate on just the SD card. It would be nice if they could both be used at the same time though.

Hehe, I am on the opposite path it seems (more or less): if I have ethernet, I would not need SD card at all, since storage can be done over ethernet too, but not the opposite direction too much (well, ok, wi-fi capable tricky sd card, but still it's only storage oriented solution not a general network capable medium as ethernet is nowdays). I wanted SD card too at first, I've even built some extra simple bit-banging solution on the parallel port of a PC to use an SD card, which is easy to implement for EP too (even for bit-banging without hardware SPI - so you need every bit level ops/shifting "by hand" - you can get something like 4-5kbyte/sec on Z80 at 4MHz - if I remember correctly). I don't want to say now that let's skip all the hardware based SPI interfacing (big banging is a bit too slow), just that the first prototype to try to use an SD card can be like this (for the joy to try to develop myself, not to rebuild other projects). And then my "eternal question" style always drives me towards another direction, so basically I won't reach any of my goals it seems :(

By the way, it's time to open an SPI topic (and Ethernet, but maybe there is one already), since the "SD card interface" is partly about Ethernet for now, and partly SPI besides the name "SD card" :)

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 30.0.1599.101 Chrome 30.0.1599.101
    • View Profile
Re: SD card interface
« Reply #52 on: 2013.October.29. 14:48:56 »
I've looked at the cart interface again and could offer memory mapped I/O of the SPI hardware (4 registers) mapped into a 256 byte region. So you would have 0000-FEFF mapped to the ROM and FF00-FFFF mapped to the SPI hardware. The low 2 bits of the SPI hardware address selecting the command, status, read and write registers. No SRAM in there, I want to try and keep this simple and cheap!

This also includes 4 SPI slave select lines, one of which will be the SD card and possibly one for an ethernet chip. The others people can play with as they like.

If this pleases everyone I'll continue on this path! :)

Offline lgb

  • EP addict
  • *
  • Posts: 3496
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 31.0.1650.34 Chrome 31.0.1650.34
    • View Profile
    • http://lgb.hu/
Re: SD card interface
« Reply #53 on: 2013.October.29. 15:11:16 »
Quote from: Saint
Yes, the SPI Master interface has configurable phase, polarity and clock divisor from /1 through to /256. As you say SPI must be configured with a 400KHz or less SPI clock.

Yes, though I prefer name polarity/phase settings as SPI modes. I am not sure how useful they are, as most hardware supports (also or only) mode 0. Afaik SD card supports mode 0 (only/also?), and ENC28J60 supports only mode 0 (mode 0: CPOL and CPHA = 0). It's a good question would be know that how useful to support all the SPI modes (different CPOL/CPHA than zero, or let's say other than mode 0).

Quote
The ENC28J60 is less than £3

That's my problem too. Bruce's idea about the wiznet chips and modules are quite cool. The only problem: expensive and hard to get (in here Hungary at least). I've asked a Hungarian dealer about the 830 module, and it costs about 10000 Hungarian Forints (HUF) with shipping (and it can be even 8 weeks to deliver), while you can buy an ENC28J60 in shops from stock for about 1000HUF or even cheaper like 700HUF, but I can't remember too much. But it's true that these "network chips" from wiznet are quite cool with hardware implementation on TCP/IP. If availability and price is not an issue (and also forgetting my braindead theories about the "being fair" issue with the Z80 ...) the wiznet solution is faster in bandwidth, and also the time needed to finish the project.

BUT: just checked, eg the W5200 chip (with hardware TCP/IP) costs about 3-4$ only which is also the part of that module (what Bruce told about recently). So maybe the price is not because of the chip itself but the module's PCB and other parts. Maybe it's not a fair thing to compare as a bare ENC28J60 still needs components like the RJ45 connector with built-in magnetics, which can be quite expensive (I have no idea), I'd be interested about the cost of working ENC28J60 board which includes the additional needed components. At last, I haven't found a Hungarian shop which solds these kind of RJ45 connectors also called "magjacks" by some sources (or something similar name).

Quote
My intention is to concentrate on the SD card side of it, but make sure there is expansion capability for other SPI devices such as ethernet or USB. May as well make this thing reasonably universal if it's possible to do so.

USB? How? Do you know some kind of SPI-USB interface? USB is a cool medium as well, at least the storage protocol of USB would allow to use pen drives, hard drives (with USB adapter) but also many MP3 players, phones, camers which support storage protocol (beware! Not all of them supports it, some of them needs custom protocol). I only know about FT232 chip but it's a serial (not SPI serial, but the commonly known serial) to USB. And I am not sure it can operate in host mode too ...
« Last Edit: 2013.October.29. 15:19:19 by lgb »

Offline Zozosoft

  • EP addict
  • *
  • Posts: 13334
  • Country: hu
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 24.0 Firefox 24.0
    • View Profile
    • http://enterprise.iko.hu/
Re: SD card interface
« Reply #54 on: 2013.October.29. 15:18:38 »
Quote from: Saint
No SRAM in there
But SRAM needed! :twisted: RAM area can be allocated from the system segment, but using many of them make compatibility problems with some programs.
I think additional one 74xx IC enought for decode the ROM CE to ROM&SRAM CE.
Using narrow SRAM (old cache RAM from 486 boards, I have a very lot of :-) ) can be putted between ROM pins, near to all pins are common, easy to design the PCB.

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 30.0.1599.101 Chrome 30.0.1599.101
    • View Profile
Re: SD card interface
« Reply #55 on: 2013.October.29. 16:39:41 »
Quote from: Zozosoft
But SRAM needed! :twisted: RAM area can be allocated from the system segment, but using many of them make compatibility problems with some programs.
I think additional one 74xx IC enought for decode the ROM CE to ROM&SRAM CE.
Using narrow SRAM (old cache RAM from 486 boards, I have a very lot of :-) ) can be putted between ROM pins, near to all pins are common, easy to design the PCB.
Lol, ok. :lol:

I can't get small SRAM easily -- I can get 32KB the cheapest, so I could add a 32KB SRAM in there and just use 4KB of it, or however much would be required. You could have a whole page if you wanted.

Board space may be getting very tight already for a cart, I'll have to have a look at layout tonight.

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 30.0.1599.101 Chrome 30.0.1599.101
    • View Profile
Re: SD card interface
« Reply #56 on: 2013.October.29. 16:42:00 »
Quote from: lgb
USB? How? Do you know some kind of SPI-USB interface? USB is a cool medium as well, at least the storage protocol of USB would allow to use pen drives, hard drives (with USB adapter) but also many MP3 players, phones, camers which support storage protocol (beware! Not all of them supports it, some of them needs custom protocol). I only know about FT232 chip but it's a serial (not SPI serial, but the commonly known serial) to USB. And I am not sure it can operate in host mode too ...
Yes there are SPI USB controllers, such as this.

Offline lgb

  • EP addict
  • *
  • Posts: 3496
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 31.0.1650.34 Chrome 31.0.1650.34
    • View Profile
    • http://lgb.hu/
Re: SD card interface
« Reply #57 on: 2013.October.29. 17:02:29 »
Quote from: Saint
Yes there are SPI USB controllers, such as this.

Wow, cool. However as far as I can see from the datasheet, it's "only" a HID device. So you can connect it to a PC. It's still quite useful for data transfer between PC and the EP, but it cannot act as an USB host to accept devices. Or am I wrong here? I'd love to see a simple solution to be act as an USB host (or at least OTG, which can act as a host for some devices at least). But I am far from being an USB guru (even more less than SPI hehe) ...

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 30.0.1599.101 Chrome 30.0.1599.101
    • View Profile
Re: SD card interface
« Reply #58 on: 2013.October.29. 18:31:35 »
Quote from: Zozosoft
But SRAM needed! :twisted: RAM area can be allocated from the system segment, but using many of them make compatibility problems with some programs.
One thought -- why would this SD card driver cause any more compatibility problems than the WD177x EXDOS disk driver? Surely you don't need any more memory to read from an SD card than a disk -- you read 512 byte sectors from one just as you would another?

Offline lgb

  • EP addict
  • *
  • Posts: 3496
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux Linux
  • Browser:
  • Chrome 31.0.1650.34 Chrome 31.0.1650.34
    • View Profile
    • http://lgb.hu/
Re: SD card interface
« Reply #59 on: 2013.October.29. 19:44:04 »
Quote from: Saint
One thought -- why would this SD card driver cause any more compatibility problems than the WD177x EXDOS disk driver? Surely you don't need any more memory to read from an SD card than a disk -- you read 512 byte sectors from one just as you would another?

I am curious too, I haven't thought on this yet. Maybe if you want many drive letters like from F: - T: you need more memory than only for a single disk? Afaik this was an issue also with the IDE interface, maybe for the same reason ...

But by the way memory: if an SD-card solution would be combined with an internal memory expansion board nobody would ever say that you haven't got enough RAM already on the system, no need to add any SRAM too much just for the SD-card interface :)