Tuesday, April 19, 2016

Slamy STM32 Floppy Controller - Part 1

Motivation

Back then i had quite some struggle getting old games to work again. My dad once brought me to an Amiga distributor and i was allowed to buy a game. I chose "Enchanted Land" a disk which years after that refuses to load.

I remember that i got my first way around issues like that sometimes after that. There was a program called "Amiga Explorer" allowing me to write ADF files using a windows tool with the same name and a server running on my Amiga 500 communicating over the RS232 port.
This way i could play some of my games again but.... i had to work with sometimes faulty cracked version.

At that time i also read about the Catweasel controller, a PCI card with a flexible floppy controller design allowing a more easier way to write disks back in a direct way from the PC.

That was about 10 years ago....

An half year ago or so i read about Kryoflux. This powerful device which is mostly designed to preserve dying floppy media for future generations also had writing capabilities.
The price was not that high but i didn't knew if it would suit my needs as i had mostly the intent of writing images back.
Also i was very interested in the techniques used around that time so a new tinkering project was on its way.

Atari ST - ISO sectors and MFM stuff (starting from 2016-02-07)

During February 2016 i decided to give it a go and started at the hardware design.
During 2014 I did make a floppy controller with an FPGA to write Atari ST compatible disks so i had already some knowledge on that matter. As FPGA development is rather tedious and modern controllers have become very fast i decided to go for an ARM instead.

My choice fell on the very cheap STM32F4 discovery board. It costed about 12€ and is equipped with an STM32 clocked at 168 MHz. What a beast !!!
Another very important feature was the integrated debugging and flash circuit and a USB OTG controller for getting image data from a PC.


I ported my original C code running on the plasma mips softcore from opencores to the STM32 and implemented the MFM decoder using the integrated timer.
For USB communication i used the stack of https://github.com/MaJerle. It's a modifed version of the OTG driver coming with the STM32F4 examples which luckily ran quite nice. (The original library from STM just refused to work)

And after some tinkering i was able to decode MFM and to parse the ISO floppy format making me able to read Atari ST and MS DOS disks in DD and HD. This page helped me a lot. Everything you need to know about MFM and ISO sectors.

So what comes next after reading? Writing of course! I've developed a linux driver to transfer image data from *.ST images to the controller which writes it track for track.
My Atari 1040STFM was quite happy about the result and played cracked versions of some games without problems.

Coming that far i decided to go for Amiga disks. The MFM used on my most beloved machine was quite different. Instead of encoding 8 bits to 16 MFM bits it used an odd and even way. When encoding 32 bits it first encoded the 16 odd bits and then the 16 even bits. Quite a hassle but possibly a style which had a better performance on the floppy controller design in the custom chips.

After basic writing of ADF files which are a binary representation of a standard Amiga DOS disk i finally went for the main goal.

Amiga IPF files (starting from 2016-03-06)

Original versions of amiga games usually come with a certain copy protection. Some use very long tracks with a reduced bitrate to get more data on a track than usual. An amiga couldn't write that. Turrican 1 and 2 are protected that way.
Others were protected using a varying bitrate. Speedlock is a protection which used that technique.
The ADF format is only capable of storing the payload data. No meta information is saved.
For everything else IPF files are used.
Soon i've discovered that http://fengestad.no/libfs-capsimage/ was all i needed. The capsimage library is a closed source manager for IPF track data which i decided to use.
What it basically does is giving back the raw MFM tracks and also with bitrate information for every MFM byte if specified by the image.
It took a few weeks of debugging and analyzing but it worked in the end. Writing back Turrican 1 and 2 (Long tracks) and Rodland (Speedlock) was possible using my so called "Slamy STM32 Floppy Controller".

This success gave me an amazing motivation and i went further.
I realized this wasn't a normal floppy controller anymore. This was called a floppy tracer, an industrial device to write mastered disks ! >:-)


To be continued.... Amstrad CPC and C64

13 comments:

  1. Can you share your code with us?

    ReplyDelete
    Replies
    1. The code is a big mess at the moment. But I will think about it!

      Delete
    2. If not the code, do you have the method on how you decode the MFM data? Is it basically using one timer to time the high, then on int, another to test the low length?

      Delete
    3. https://github.com/Slamy/SlamySTM32Floppy

      Delete
  2. How are you decode MFM data from FDD?
    Directly in STM32F407?

    ReplyDelete
  3. Wow! Can you share your code? Actually I own a bunch of floppy disk drives (not usable with Amiga) and I will be happy to write/read them using the STM32 board as mass-storage device in Linux. Is this can be possible? It would be great if it is can be done. The mass-storage interface I used some time ago in a project of mine, to flash the internal and/or external flash for firmware and it works as rock solid!
    Please tell me something at: Gianluca Renzi gianlucarenzi@eurek.it
    Best regards,

    ReplyDelete
    Replies
    1. Here you go
      https://github.com/Slamy/SlamySTM32Floppy

      Delete
  4. Hi Slamy, wir hatten einen kurzen Plausch auf der DoReCo Party #11, ich war der von gegenüber mit dem Acorn A5000. Wir hatten auch kurz über das Floppy-Controller-Projekt geredet, und ich habe jetzt alle notwendigen Bauteile am Start. Erstmal zum Testen ein paar CPC-Disketten schreiben, und dann Unterstützung für die Acorn-Formate hinzufügen (ADFS D/E/F) ist mein Plan.

    Wie hast Du die Verdrahtung vom 50pin-Header des STM32F4 zur 34pin-Buchse für die Floppy in Deinem Beispielaufbau gelöst? Freiflugverdrahtung auf Lochraster? Sonst noch irgendwas beachtenswertes, bevor ich den Lötkolben schwinge?

    ReplyDelete
    Replies
    1. Bei dem Github Projekt ist eine Datei dabei: Pins.ods. Das ist ein LibreOffice Calc Dokument wo exakt drin steht, welcher Pin vom STM32F4 Discovery Board (ist ja aufgedruckt) mit welchem Pin von dem 34pin Header verbunden werden muss.
      Das ganze habe ich fliegend mit einer Lochraster Platine verdrahtet.
      Bauteile braucht es sonst nicht viele. Nur einen 74HCT14N solltest du vielleicht parat haben. Das wurde leider nicht erwähnt bisher, stelle ich gerade fest. Man kann den auch umgehen, muss aber in den Sourcen angepasst werden. Das ist ein Inverter mit Eingangshysterese. Das macht das Signal etwas sauberer, welches über /RDATA zum STM32 geht. Dann brauchst du noch 4 Pull Ups und zwar an /RDATA, /TRK00, /REDWC und /INDEX.
      Das ist, damit die Signale die zur Floppy gehen auch schön auf saubere 5V kommen.
      Die Doku ist an der Stelle vielleicht etwas schlecht. Tut mir leid.
      Wenn du fragen hast, ruhig weiter löchern.

      Delete
    2. Hier auch ein Foto vom Unterbau:

      https://lh3.googleusercontent.com/oakRsABlnCKuTQoapUrtMh05DqeakIvFyEPZE8PB7bwstES6dhO8Z_KImQ9_N30-bjpSql6mW3ki0JIMpiJxuHM9EFKbC3kAu6T6qHEjbueiSA0jpLzCssekw9xMymHmmbx7E0uXL7QFgUzzIlwYqptzhWeVQ4X5z_gwjrQ_UrxhhRbzcd7rGdk2y-JtTZQtLwpnzYZP2yM2ml2un1xiWNSG7zAQNVp5yzRHKBEGpBCBVLV6iiYN0EkYl4JoCTCpec78PM3G5DPUScpfj03fZ10e-NCEwcVEumTt51DAfKCr5DUeb0lvgB5R0Ln09x2LDIDvZrEmCoXmxBCD1mjVR7_u-s5zVadV6dwR12V49vHf9GfcVCCyeZPJ4WvGLeErHEK_dKQbw74qawfTb83DJv9eKjWgEh6KR9UbK2H3PVkm5BSXWzVPMQOoU_HeTM930xfx5A8kzVXX1q9sZ6OhbJHjoZbolb2mIe5D8ro0RsIl6-Qa2VGp1ylLkIH7p75LmRcfyK0N0jFN4ehdrLoveO52hpH0jglWLkxqPtzlrFhWEq-SRrTMOrDO_H5U5OaiWmHyLraLL00K1cONfZ9Vv-YQ3jNe_GVmYVE4UoG3o_xK0NbIhEMrQr97yJsK46G-L_KjsLnQ_ONHV96U-BCj2sa4ZbZChsrxlJZEFoOOx1aH6LRgdu1k6A=w580-h1030-no

      Delete