Building my own SD card interface for the Apple II

38 replies [Last post]
freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19

Hi there,

just out of curiosity, I am currently in the middle of building my own SD card interface for my enhanced IIe. I am not trying to build a floppy replacement, but more of a ProFile replacement with a SD card with one (later multiple) 32MB ProDos partitions.
The hardware is based around André Fachat's SPI65/B CPLD SPI controller that I have modified for my own needs. My handwired proto board is working fine and I will have a proper PCB made soon.

So far, I have written a ProDos driver (Merlin assembly) for my card, that is nearly working. Currently I install it from floppy as a software driver for the slot the card is in. In the end it should be on the card itself, of course, with auto-boot and so on.
I formatted the card in CiderPress and put a few files and folders on it.
However, when doing a CAT on ProDos I see a few files and then I get a "range error" from basic, just before the "blocks free" message would be printed. When I try to load a program it crashes or hangs.

As this is my first real Apple II project, I am absolutely sure I have multiple issues at once!
First I'd like to make sure I am installing the driver correctly. Right now, the driver is loaded from floppy disk starting at address $8000 and then registered in ProDos' driver table. I am sure there is a much better and safer place in memory, but where? I need about 750 bytes. Can the driver be stored in aux ram?
I suspect when loading a program, the driver is written over and so locking up the machine.

I appreciate your answers and I am happy to share my design and driver source with you, once it is in a working state!
Regards, Flo

__________________

An apple a day keeps the doctor away!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

I was able to solve the problems I described earlier. They were a combination of multiple bugs and not reserving the space for the driver.

After playing around with my handwired prototype for some time, I was confident enough to have the PCB made.
It arrived some weeks ago and after fixing another silly bug in the SD read function it seems to work perfectly. I can even boot off the card! I have to admit, I am kind of proud Wink

I put all the sources (Asm and VHDL), schematics (Eagle) and binaries on Github to share and I'd appreciate any comment!
https://github.com/freitz85/AppleIISd

Have fun, Flo
[image]https://github.com/freitz85/AppleIISd/blob/master/IMG_20170813_124455.jpg[/image]

__________________

An apple a day keeps the doctor away!

Offline
Joined: Jul 31 2014
Posts: 34
Re: Building my own SD card interface for the Apple II

Well done, it's a great feeling when you finally get projects like this working. And thanks for sharing on here.

I'd love to see some pictures of your card.

/Rob

gsmcten's picture
Offline
Joined: Oct 4 2005
Posts: 2616
Re: Building my own SD card interface for the Apple II

Freitz,

Are you planning on taking orders?
And if so, how much would one cost?

Steven Smile

__________________

Steven (gsmcten)

"Apple ][.....It's ALIVE!!!!!"

Offline
Joined: May 9 2014
Posts: 109
Re: Building my own SD card interface for the Apple II

Nice work, freitz! Is the ProDos driver already on ROM and is it autobooting?

Offline
Joined: May 2 2010
Posts: 47
Re: Building my own SD card interface for the Apple II

that is very cool.

a couple of us in Uk would LOVE one of these! Are you by chance planning to sell a few on [please] or could we look at getting a few made up?

i am assuming the cost of parts is quite low from the pic, but i have no idea.

Awesome!

PS you mentioned partitions; presently do you just boot and it reads one file, acts as if it was a single hard drive?

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

The driver is in ROM and it boot from it. To ProDos it acts as a ProFile with 32MB of storage space (65535 Blocks).
Right now, only one partition is supported, but it should be no problem at all to support up to four partitions.

I had only one pcb made and that was 50 eur, but this would become significantly cheaper when ordering more than one.
So, I guess I could supply at least the pcb. As for the parts, the cpld should be the the most expensive part with 6-10 eur. PLCC socket and Sd card socket are 2,50 each. Together below 20 euros, I guess.
Except for a handful of 0603 sized resistors and capacitors everything is normally sized, so it should be possible to build with medium soldering skills.

Now that I see that there is an interest in this card I will add a readme to my repository describing it further.

__________________

An apple a day keeps the doctor away!

Offline
Joined: May 9 2014
Posts: 109
Re: Building my own SD card interface for the Apple II

I took the liberty of using the gerbers on Github and ordered 5 PCBs from Seeed. https://www.seeedstudio.com/ They cost little under $20 delivered. Have to see how they will turn out. Is the datasheets folder practically the BOM?

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

I'm excited that there is such an interest in my little card and I am actually considering having more PCBs made for sale in Europe! Maybe a first run of 10-20 units.

@protek: the price for the PCBs is about what I expected. As for the parts, apart from the CPLD and the SD card slot, there is nothing 'fancy' on the board.

__________________

An apple a day keeps the doctor away!

macnoyd's picture
Offline
Joined: Oct 15 2012
Posts: 224
Re: Building my own SD card interface for the Apple II

Add me to the list of interested parties. Smile

__________________

macnoyd

Offline
Joined: May 9 2014
Posts: 109
Re: Building my own SD card interface for the Apple II

A few questions regarding the components....

Can a 2816 EEPROM be used in place of the 2716?
What values are the resistors and the capacitor(s)?
What component is the red and white block on the top of the board?

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

I have uploaded the schematic in PDF format as well as the BOM.

@protek: The card supports 2716, 2816, 2732 and 2832 (E)EPROMS. Currently 1KB is used.
The red/white block on top is an activity led.

__________________

An apple a day keeps the doctor away!

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

Hi there,
I have decided, that I will offer kits for sale. They will be around 20 Eur, depending on how large the batch is.
Everything will be included: PCB, sockets, CPLD, EPROM, small parts, ...

Write me a PM if you are interested!

__________________

An apple a day keeps the doctor away!

Offline
Joined: May 2 2010
Posts: 47
Re: Building my own SD card interface for the Apple II

hi, thats awesome what you've done, protek has offered me one of his boards - but I think I'll grab another board kit from you as well please Frietz Smile I'll pm

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

I have twelve orders now, so I'll going to make a first batch of 20 boards. I started ordering the parts and expect to ship the kits at the end of September.

__________________

An apple a day keeps the doctor away!

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

Does anyone have a guess what might cause a conflict with a Z80 card?
The card wants to boot, but then hangs during the initialization. I still have to analyze the bus to see at what moment exactly.
It does complete the boot when running in Bugbyter, however.

__________________

An apple a day keeps the doctor away!

gsmcten's picture
Offline
Joined: Oct 4 2005
Posts: 2616
Re: Building my own SD card interface for the Apple II

What is 20 Euros in American money? Smile

__________________

Steven (gsmcten)

"Apple ][.....It's ALIVE!!!!!"

Offline
Joined: Aug 24 2013
Posts: 45
Re: Building my own SD card interface for the Apple II

Flo,

Thank you for creating this, and even more so for releasing it.

I was able to hook it into my FPGA //e with only one minor issue. In the write process, spidataout is not initialized, which causes the Altera Quartus software to optimize out most of the code.

It appears to work the same when linked into both slot 6 and 7 on my implementation.

Do you have a bootable image to share? I believe that others will need it or instructions on how to make one in order for the design to be fully usable.

Thank you again,

Christopher

tokabln's picture
Offline
Joined: Dec 30 2015
Posts: 104
Re: Building my own SD card interface for the Apple II

gsmcten wrote:

What is 20 Euros in American money? Smile

@Steven,

actually it's roundabout 24 Dollar

https://www.oanda.com/currency/converter/

__________________

Kind regards from Berlin (Germany)
Torsten aka tokabln

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

@Christopher,

The VHDL part is basically André Fachat's code from which I have removed the the parts for multiple slaves and added the few bits for the init flag, card detect and write protect. I have to clean it up and look over the code again, but so far, it has worked and I focused on the driver side.
You have added spidataout to the reset part of the write process, I believe? Feel free to suggest further improvements, because VHDL is not really my strong side.
The same goes for everyone! I am open to improvements, bug reports, and so on.

Someone asked me if the card was compatible with the IIgs. I don't have a IIgs (yet), but judging from the timing diagrams and the fact that other cards are working, I suppose that it should. I even bought the book "Exploring Apple GS/OS and ProDOS 8" recently and I will research if there are any things to consider, when dealing with both systems.

I will write a tutorial on how to make a bootable card, which basically is to copy the contents of a bootable floppy to the card using Ciderpress.

__________________

An apple a day keeps the doctor away!

gsmcten's picture
Offline
Joined: Oct 4 2005
Posts: 2616
Re: Building my own SD card interface for the Apple II

freitz,

I would like one too.

Steven Smile

__________________

Steven (gsmcten)

"Apple ][.....It's ALIVE!!!!!"

Offline
Joined: Aug 24 2013
Posts: 45
Re: Building my own SD card interface for the Apple II

freitz wrote:

@Christopher,

The VHDL part is basically André Fachat's code from which I have removed the the parts for multiple slaves and added the few bits for the init flag, card detect and write protect. I have to clean it up and look over the code again, but so far, it has worked and I focused on the driver side.
You have added spidataout to the reset part of the write process, I believe? Feel free to suggest further improvements, because VHDL is not really my strong side.

Yes, just after the divisor line in the cpu_write: process, I added before the elsif:

spidataout <= (others => '0');

As my development board does not have inputs for the card detect and write protect, I have left
those as constants (card present and not write protected.)

Quote:

I will write a tutorial on how to make a bootable card, which basically is to copy the contents of a bootable floppy to the card using Ciderpress.

I am using the 32meg ProDOS disk from apple-2.com, which works in AppleWin without issues as a virtual hard drive.

However, I have found the issue I believe, which is related to the specific card that I am using. I found that I had to adjust the sd driver read code to add an extra dummy 0xFF write after the read completes in order for my card to work properly. I expect (although I have not confirmed) that I will need a similar dummy in the write block code as well.

This is referenced on this stack overflow page:

https://stackoverflow.com/questions/2365897/initializing-sd-card-in-spi-issues

The author mentions that it is important to send an extra 0xFF after receiving responses.

Christopher

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

Quick status update:

I am busy improving the quality and speed of the code, fixing issues, updating documentation, etc.
All parts for my initial batch of 20 kits are ordered, so I should be able to ship by october.
The price for the guinea pig offer* including shipping is as follows:
Germany: 23 Eur
World (uninsured): 24 Eur / 29 USD
World (insured): 28 Eur / 34 USD

So far, there are only 3 kits left for preorder, so hurry!

* The reason I am calling this my guinea pig offer is that I appreciate your trust, but there may be bugs. You should consider the card in beta test phase.

__________________

An apple a day keeps the doctor away!

macnoyd's picture
Offline
Joined: Oct 15 2012
Posts: 224
Re: Building my own SD card interface for the Apple II

No guts, no glory. I'll take the guinea pig! Smile

__________________

macnoyd

gsmcten's picture
Offline
Joined: Oct 4 2005
Posts: 2616
Re: Building my own SD card interface for the Apple II

Guinea pig!
Guinea pig!

Yea Team!

PM me your Paypal and I'll send payment right away.

Steven Smile

__________________

Steven (gsmcten)

"Apple ][.....It's ALIVE!!!!!"

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

The parts I ordered from china are arriving now and I will send out the order for the pcbs and the remaining components this weekend.
All of you who have made a pre-order will get an email in the next few days about shipping-address, payment and so on.

I have decided to document my progress on the card on a blog: http://bluemeanie-retro.blogspot.de/
So far, you can read about the AppleIISd and my submission for the upcoming RetroChallenge.

__________________

An apple a day keeps the doctor away!

Eudimorphodon's picture
Offline
Joined: Dec 21 2003
Posts: 1204
Re: Building my own SD card interface for the Apple II

Darn, it looks like I'm probably too late to get on board for a test board. Nonetheless I will be keeping an eye on this! If this ends up IIgs compatible I'd love to have one of these as a cheaper alternative to the IDE/CF-based hard drive substitutes.

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

I will have to delay the kits for a few weeks, because the packet with the sockets for the cpld was stolen from my mailbox. I know that for a fact, because when I left the house yesterday morning I noticed the packet sticking out of my mailbox. I was in a hurry, so I decided to get it in the evening. That turned out to be a mistake. When I got home it was gone. >:(

However, this gives me time to get over the cpld design again. I showed it to my colleague from hardware and he pointed out some issues that could very well lead to the problems I described in my blog.

__________________

An apple a day keeps the doctor away!

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

It's been another month and if you have been following my blog, you may know that I still have not managed to make the SD card adapter work. It even kept me from contributing to my RetroChallenge, because I wanted to use the same base design.

I have revised the CPLD design to match the timing specification from the II+ to the IIgs. A VHDL simulation proves this. Additionally, I rewrote parts of the driver to restore all zeropage locations it uses. The current state may be found in the development branch of my repository on Github. I'd appreciate any hints on things to consider when writing a driver for ProDOS.

The computer usually crashes when trying to load the catalog and it won't boot from the SD card. However it displays "Unable to load ProDOS" which means that at least the first block on the card was loaded. I am sure that I am missing only a small thing.

The driver test I wrote writes a predefined block to the card, reads it back and compares the two shows no errors.

@Christopher
I understand that you have implemented this into your FPGA based computer. Could you try with my newest sources?

__________________

An apple a day keeps the doctor away!

Offline
Joined: Dec 12 2011
Posts: 2
Re: Building my own SD card interface for the Apple II

Hi Florian,

After prompting by a fellow hacker, I took your design and re-layed it out to use the VQFP XC9572XL, and a 2764 / 27128 type EPROM as I have a shed load more of these than the 24 pin ones.....

Anyway I am unable to get the damn thing to work in either of my Apple IIe machines (both of them initially where un-enhanced) but I have upgraded one of them with a WD65C02 and the enhanced firmware. However this still doesn't make the thing work symptoms I get are :

Bombs out with "Cannot load ProDos" or bombs out with "Relocation error".

I have tried several SD cards so am fairly sure that's not the problem.

Now the odd thing Both my IIe machines are UK PAL machines. My fellow hacker friend that originally prompted me has a US machine (though using a UK PSU), and the board works in his machine. As does his copy of your original board.

I've also found my own experiments with connecting things to the Apple bus and using an XC95xxXL CPLD to be somwhat proplematic, I suspect that the bus timing is slightly different and is causing things to fall over.

Shout up if you want a copy of my Eagle files with the revised design.

Cheers.

Phill.

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

Hi Phill,
thanks for testing my board. The problems you are describing are exactly the same that I have.
Have you used the files from the master or the development branch?

Quote:

... I have upgraded one of them with a WD65C02 and the enhanced firmware

The firmware contains 65c02 specific code, so it won't work on an unenhanced IIe or II+, but it would be possible to rewrite the code.

Quote:

I've also found my own experiments with connecting things to the Apple bus and using an XC95xxXL CPLD to be somwhat proplematic, I suspect that the bus timing is slightly different and is causing things to fall over.

I have compensated these timing issues, I think. Please have a look at the VHDL simulation files.

Quote:

My fellow hacker friend that originally prompted me has a US machine (though using a UK PSU), and the board works in his machine.

My IIe is PAL as well. It is good and strange at the same time to hear that it seems to work on NTSC models. Maybe that leads us towards a solution.

__________________

An apple a day keeps the doctor away!

Offline
Joined: Dec 20 2008
Posts: 209
Re: Building my own SD card interface for the Apple II

I am in the USA (NTSC) and have several II/II+/IIe/IIgs. I am happy to test and debug (and I'm already on the list for a couple).
Smile

__________________

-
Peter Rittwage
Apple II/II+ Registry - Register yours today!
http://diskpreservation.com/dp.php?pg=apple_registry

Offline
Joined: May 9 2014
Posts: 109
Re: Building my own SD card interface for the Apple II

Hi Florian and others!

I just finished building the board based on your design. I’m currently waiting for a 2732 eprom to arrive to me.

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

@protek:
Please remember to burn the firmware with an offset of 0x800, if you are using a 2732.
I am looking forward to your findings!

__________________

An apple a day keeps the doctor away!

Offline
Joined: May 9 2014
Posts: 109
Re: Building my own SD card interface for the Apple II

I ended up using a 2816 instead. Also changed the 74HCT245 to 74LS245 to deal with some weird bugs during boot. Now my IIGS boots to ProDos Basic 1.5 prompt. I have GSOS put in the boot partition with Ciderpress but the IIGS doesn’t boot into it automatically. Did I miss something?

Offline
Joined: Dec 20 2008
Posts: 209
Re: Building my own SD card interface for the Apple II

Doesn't ProDOS boot whatever *.system file it finds first in the file system?

__________________

-
Peter Rittwage
Apple II/II+ Registry - Register yours today!
http://diskpreservation.com/dp.php?pg=apple_registry

Offline
Joined: May 9 2014
Posts: 109
Re: Building my own SD card interface for the Apple II

Turns out I had an image with just ProDos on my SD card and that appeared to be working. I changed the Image to GSOS now. With that, the IIGS shows the GSOS splash, but the actual load operation fails in the beginning as the IIGS beeps when it shows the splash. The progress bar fills but it doesn't actualy load the GSOS. I had the same issue with Ian Kim's SD Disk II interface until he managed to fix some timing issues with the card.

freitz's picture
Offline
Joined: Jun 11 2013
Posts: 19
Re: Building my own SD card interface for the Apple II

@rittwage: this is true, but only after ProDOS itself has been loaded to memory. At the moment we have problems with that.

@protek: that is great news, it means that we are on the right track. Are you using the sources from the master or the development branch?

I have switched for the LS245 as well and now it's a stable "unable to load ProDOS" without random characters. But that is kind of strange, since timings between the LS and HCT type are virtually the same, except for propagation delay, but I can't see why that would make trouble. In IIgs TechNote 68, Apple recommends LS or HCT types.

__________________

An apple a day keeps the doctor away!

Offline
Joined: May 9 2014
Posts: 109
Re: Building my own SD card interface for the Apple II

@freitz: For the driver ROM, I believe I took it from the master branch. For the CPLD I’m not sure as I got it pre-programmed.