Welcome, Guest. Please login or register.


Author Topic: SD card interface (Read 231521 times)

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: SD card interface
« Reply #135 on: 2014.April.24. 00:17:41 »
Isn`t it little, precious, alive, like a new born?

Offline Bagpuss22

  • EP fan
  • *
  • Posts: 167
  • Country: gb
Re: SD card interface
« Reply #136 on: 2014.April.24. 20:43:41 »
@Saint, looking good, as always :smt023

Russ

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14709
  • Country: hu
    • http://enterprise.iko.hu/
Re: SD card interface
« Reply #137 on: 2014.April.25. 11:10:27 »
Looks very amazing!
One question: the final version will be available with standard edge connection, for use with existing expansion?

About the sw: I got ready to use SD DISKIO routines, which are developed to the Videoton TVC version. I just connected these to EXDOS system.
The DISKIO have these functions:
0 - Disk System Reset (initializing)
1-8 unknow command, for avoiding problems with old programs which are use original 16 bit DiskIO system (floppy, etc)
9 - read sector with 32 bit LBA address
10 - write sectors with 32 bit LBA address
11 - write&verify sectors with 32 bit LBA address
12 - I/O controll functions:
I/O 1 - read CSD register and calculate card size in 512 bytes sectors
I/O 2 - read CID register
I/O 3 - read OCR register
I/O 4 - check disk change
I/O 5 - select active card

A register: command code (0, 9-12)
For sector operations (9-11):
BC: high 16 bits of LBA address
DE: low 16 bits of LBA address
l: number of sectors
IX: point to transfer area
Ouput: A error bits, L successfully transfered sectors, F: Z if no error

Function 12:
B: I/O command code
IX transfer area for the function 1-3 read registers
output: A error bits, F: Z if no error

At function 1: HL:DE card size (32 bit LBA)

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14709
  • Country: hu
    • http://enterprise.iko.hu/
Re: SD card interface
« Reply #138 on: 2014.April.25. 11:29:35 »
And what I know about hw:
The SD segment divided to 3 area: ROM, RAM and I/O, now I'm using Page 3 addresses:
C000-DFFFh 8K ROM (it is can be paged, 8*8K total, using Flash ROM chip)
E000-FBFFh 7K RAM (using SRAM chip)
FC00-FFFFh I/O registers, 4 registers these are shadowed in all 4 bytes in the I/O area
FC00: R/W data register
FC01: W: Control: Bit 7: CS0, Bit 6: CS1, Bit 5: reset disk change
FC01: R: Status: Bit 7: WP1, Bit 6: INSRT0&INSRT1, Bit 5: DCHNG0 or DCHNG1
FC02: W: ROM page register
FC03: W: select high speed data read, Bit 7=1 HS enabled
In High Speed mode the Data register can be read at all address from FC00-FFFFh, then possible read sectors with LDIR instructions.

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
Re: SD card interface
« Reply #139 on: 2014.April.25. 11:44:23 »
Quote from: Zozosoft
One question: the final version will be available with standard edge connection, for use with existing expansion?
I could provide a bus bridge compatible version if this is preferred, yes. I'd just need to change the edge connector for a card edge and I could also remove the 5v regulator. In the original design I have been thinking about your "average" Enterprise user who doesn't have things like the bus bridge or other devices, and just has an Enterprise. I think this describes most Enterprise owners in the UK. :)

Do you have direct access to the SPI bus from the cartridge hardware? By the looks of the description above there is some controller involved?

I can map the RAM / ROM how you like in the single segment. I had mapped 12K ROM, 4K RAM and 256b hardware, but this can change as you like.

I can look at adding things like a high speed read mode. At the moment you have direct control over the SPI hardware, and a read actually requires a write first. So you have to perform a byte write followed by a byte read from a register to read a byte from the card.

We can look at speeding things up (if we even need to!) when its working.

I created a JTAG programming adaptor for my JTAG edge connector on the expansion last night and was able to program the CPLD. It current freezes the Enterprise as I think it's constantly writing to the bus, so I'll debug that tonight... :)

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14709
  • Country: hu
    • http://enterprise.iko.hu/
Re: SD card interface
« Reply #140 on: 2014.April.25. 12:07:16 »
Quote from: Saint
Do you have direct access to the SPI bus from the cartridge hardware?
SPI conversion made by th CPLD, Z80 only R/W regular 8 bit data.

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14709
  • Country: hu
    • http://enterprise.iko.hu/
Re: SD card interface
« Reply #141 on: 2014.April.25. 12:12:47 »
Quote from: Saint
I'd just need to change the edge connector for a card edge and I could also remove the 5v regulator.
Don't remove the regulator, and the edge connection same as the machine connection (2x33pin, 9V present). Look at card designed by Gyula Mészáros, this is the Hungarian standard :-)

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
Re: SD card interface
« Reply #142 on: 2014.April.25. 12:14:52 »
Quote from: Zozosoft
SPI conversion made by th CPLD, Z80 only R/W regular 8 bit data.
Ok, not as flexible as mine. :)

I even have a 2nd SPI header on the board so you can add your own SPI devices. If anyone creates a nice ethernet driver or something I'll happily create a new revision of the PCB with it built in... :cool:

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
Re: SD card interface
« Reply #143 on: 2014.April.25. 12:16:19 »
Quote from: Zozosoft
Don't remove the regulator, and the edge connection same as the machine connection (2x33pin, 9V present). Look at card designed by Gyula Mészáros, this is the Hungarian standard :-)
Oh, ok! So I just change the edge connector for a card edge, and that's it? Easy. :)

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
Re: SD card interface
« Reply #144 on: 2014.April.26. 01:04:02 »
Some progress tonight. Got the CPLD talking to the enterprise ok. I can detect the sd card inserted switch and write protect switch and write to the SPI bus all fine. But I've yet to get any response from the sd card. Not sure why, as the data going out looks ok...

More debugging to be drone!

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14709
  • Country: hu
    • http://enterprise.iko.hu/
Re: SD card interface
« Reply #145 on: 2014.April.26. 09:23:52 »
SD Card need to be initialized after inserted. I call SD Disk Reset if Disk Change bit active.

Offline geo1977

  • Newbie
  • Posts: 11
Re: SD card interface
« Reply #146 on: 2014.April.26. 10:02:16 »
@ saint if you have ready sd interface please not forget me ..!!!:lol:

Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: SD card interface
« Reply #147 on: 2014.April.26. 15:02:00 »
AFAIK, SD cards need initialization sequence including switching to SPI mode as most (?) SD cards has other modes too. If I remember correctly there are at least 74 (?) clock pulses as the part of the sequence. Then you can identify the card eg it can be powered safely with a given supply voltage (according the standard you should stop use otherwise - though technically SD cards should work with 3.3V voltage or so as power and signal level, some of them requires lower voltage and maybe it's not so OK to power them with 3.3 for too long - but I am not sure about this), and max SPI clock (till the identification you should use max of 400KHz). Please note that it's from my memory only now, I can be wrong, for sure. Also SD cards sometimes not behaves too well according to he SPI standard, they should work on SPI mode 0, but eg select signal is sometimes not handled as it should or with only a great delay. Also, inserting/ejecting SD card when powered needs some extra care, I would avoid it till the everything is OK (and then you need some solution to avoid dropping power level because of the initial high current eaten by the card at the time of inserting, usually an inductor or other solution needed and good power supply regulator)

Ok, instead of my blah-blah, I've managed to find this page again I used to check out when I played with SD cards with AVR MCUs: http://elm-chan.org/docs/mmc/mmc_e.html But it's also useful to read source of the SD2IEC firmware (partial Commodore floppy drive emulator using SD card), it's GNU/GPL. The page also has this nice diagram about the initialization sequence: http://elm-chan.org/docs/mmc/gx1/sdinit.png
« Last Edit: 2014.April.26. 15:43:09 by lgb »

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
Re: SD card interface
« Reply #148 on: 2014.April.28. 23:45:42 »
I've written SPI / SD CARD code before, so it wasn't as simple as that... :)

It turned out to be a dry solder joint on the MISO SD CARD socket, and also SDCC is buggy! It wasnt setting a bit correctly, so the packet being sent to the SD CARD was wrong.

So I've fixed those problems and I'm talking to the SD CARD, it's all initialised and I've read the card size etc and am ready to read data from it. Tomorrow I hope to actually read a sector, then if that works we're nearly ready to get it working with EXDOS. :mrgreen:

Zozo -- is it possible to have the source code from you for the EXDOS driver? I can then integrate it all here and get it working with my SD CARD code.

Offline Saint

  • EP user
  • *
  • Posts: 266
  • Country: gb
Re: SD card interface
« Reply #149 on: 2014.May.01. 20:51:28 »
Thanks for the source Zozo, I have it. :)

Ok, some more progress. I've spent the last few nights working on the SPI chip hardware. The transfer was really unreliable and wouldn't work at any decent speed using the code that I had found (an Altera example project).

So I've rewritten the SPI interface from scratch and debugged it fully, and I now have it running at full speed (~7Mhz) with no errors. I can read a full 128K in under 2 seconds with no optimisation at all, which is plenty fast enough, so I don't think I'll worry about optimising the transfer speed. :lol:

Next is to get the EXDOS driver working.

Zozo -- where is your modified EXDOS ROM which I will need for the driver to work?

I'm starting to think about orders now as well. Could you see how many people are likely to want one of these over in Hungary Zozo? Also, would people want the card edge version, rather than my edge connector version?

I'm trying to think ahead as getting the PCB's made takes a little while.

And also, anyone else interested please let me know so I can start thinking about numbers. :)

I'll have to sit down and try and figure out a price as well! I've not looked at how much everything costs yet. Been too busy making hardware... :cool: