News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

CPC-CPLINK - a coprocessor interface card for all CPCs

Started by revaldinho, 19:54, 10 November 19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

revaldinho

Time to announce availability of a new CPC project: CPC-CPlink  (pronounced CPC Ker-plink)

It's a card which allows you to connect an external co-processor, like a RaspberryPi or Arduino,  directly to any CPC.

The card provides a parallel FIFO link in both directions through which data transfer rates of over 100K Bytes/s can be achieved.

CPC-CPlink's FIFOs and logic deal with all the critical signal timing, so there are no strict real-time requirements for the co-processor. A RaspberryPi running a full Raspbian (Linux) distribution is a suitable co-processor candidate, perhaps making available some of its hardware and OS services to the CPC. For example it's possible for the Pi to provide mass-storage SD card access, timers, serial ports or networking facilities to the CPC without having to write any bare-metal code on the co-processor.  Acceleration is an interesting avenue to explore too.

The FIFOs present a status and a data register in the CPC's IO Port address space, and a bi-directional byte wide data bus and handful of control signals and flags to be connected up to coprocessor GPIOs. The programming protocol is very simple and is described in the documentation and by example programs provided to run on CPC and coprocessor implementing a simple loopback test. These demonstrate communications between a Raspberry Pi (using Python or C) and a CPC using BASIC, BCPL or C and libraries written in Z80 assembler.


Electrically, the card can interface to a wide range of co-processors using either 5V or 3V3 signalling. Since the most likely coprocessor candidate is a Raspberry Pi, the connector on the rear allows a Pi Zero to plug straight in and be powered from the CPC via the FIFO card. This makes for a very neat installation, but larger Pis and all kinds of Arduino, Teensy, PIC or other micros can be accommodated by a suitable cable adapter. On the CPC side, the card has a 50W right-angled box connector compatible with all popular expansion boards.

Just like the Old School 6128 RAM card, CPC-CPlink is cheap and easy to build. All logic ICs are easy to source and easy to solder, through-hole 74 series components; there are no programmable parts of any kind. The project is fully open sourced and licensed under the GNU GPL3. All source code including Eagle board files, Gerbers and digital logic netlists are included in the GitHub repository together with the software examples.

The V1.0 board has been built and tested using a RaspberryPi Zero co-processor, and is now ready for release.

For hardware DIYers, blank PCBs are available directly from SeeedStudio and a reference bill of materials is available at Digi-Key; full construction details are provided on the GitHub Wiki. If you don't want to order packs of 10 PCBs from Seeed then you can get individual PCBs from me.  I can also provide fully assembled cards for anyone who is more interested in the software side of things and doesn't fancy the soldering themselves.  If you'd like to take up either of these offers then please PM me via the forum.




Gryzor

Sounds interesting, hope someone provides a complete assembly!

What uses do you envision for it? Reminds me of the CosmosEX for the Atari ST, which was highly interesting and useful!

revaldinho

#2
Quote from: Gryzor on 20:12, 10 November 19
Sounds interesting, hope someone provides a complete assembly!

What uses do you envision for it? Reminds me of the CosmosEX for the Atari ST, which was nightly interesting and useful!



Thanks, and that's a good question.

In fact, I'm more interested to see what you are planning to do with it !  :D  That's why it's all open-source and designed to be very cheap and easy to build.

I should to stress that this isn't a project dedicated solely to the RaspberyPi, as any co-processor can be attached and you can do quite a bit with things like the latest Teensy4.0 too. However a RPi is the obvious candidate given its cost and capabilities. With the FIFO freeing up the co-processor from having to deal with any timing critical GPIO handling, you can program the Pi in any high level language and use it to provide some of its own OS and hardware facilities to the CPC. A PiZero W costs under £10 in the UK, so even if you just use it to provide the CPC with a real-time clock it's about as cheap as any other hardware solution. The Pi offers so much more than that though.

I need to work on the documentation and example code a bit in the short term. I'll show an accelerated Mandelbrot plot for example, with the CPC calling a Pi to do the time-consuming inner loop. I'll also look at making a better BASIC example with some RSXes for the FIFO handling. Probably I'm going to use the board to play around with other multi-processing ideas and run emulations of various CPUs on a Pi, but retro-computing possibilities abound here. It's a very open-ended project.

For non-DIYers, I am happy to make up small numbers of boards to order. These will be £26 + P&P - PM me if you'd like one.

shifters74

#3
A few ideas i am interested to try:

1) use pi as page memory i.e. can page 8 or 16K chunks in and out of CPC address space (C64 has something similar)

2) use pi HDMI screen as driven output i.e. commands in basic/asm to output to the pi screen rather than cpc's for hires graphics etc

3) interface to online servces via pi and wifi but use cpc keyboard and screen e.g. irc/telnet bbs etc

4) would like to see a fast 6502 and z80 on the pi so that you can send code to pi to execute under the emulator of that processor (like a bbc with a second processor with file, keyboard and screen access still to cpc).


Not all of these i will be able to do myself but very interested to experiment with it!


Does a Pi3A fit ok on the back or does it need a ribbon cable instead?  Currently they are 17.89 on ebay!

cheers
shifters

shifters74

Forgot to ask;  will an M4 from Duke coexist with the board in an MX4 expansion?
thanks
Shifters

revaldinho


Quote from: shifters74 on 17:33, 11 November 19
Forgot to ask;  will an M4 from Duke coexist with the board in an MX4 expansion?


Yes. I am using an M4 for development at the mo', using the wi-fi to squirt files to and from a Mac and as a mass-storage for the CPC. No problems. It's a great setup.


Some good ideas in your other post -

Quote
1) use pi as page memory i.e. can page 8 or 16K chunks in and out of CPC address space (C64 has something similar)


I guess you do know that the CPC already has an extended memory scheme which deals in 16K pages. The FIFO card won't let you use the Pi as an extended RAM using that particular scheme which 6128 software, FutureOS and SymbOS all rely on. You would need to use one of the many available RAM cards for that. You  can create your own CPC software, with the Pi providing additional indirectly accessed RAM to swap in and out though. That's an interesting avenue to explore.

Quote
2) use pi HDMI screen as driven output i.e. commands in basic/asm to output to the pi screen rather than cpc's for hires graphics etc

3) interface to online servces via pi and wifi but use cpc keyboard and screen e.g. irc/telnet bbs etc

4) would like to see a fast 6502 and z80 on the pi so that you can send code to pi to execute under the emulator of that processor (like a bbc with a second processor with file, keyboard and screen access still to cpc).


These all sound very doable - and exactly the kind of thing I hope the card will enable. I'll look forward to seeing any of these getting demoed.


On the last one, CPC-CPlink is very much like a 'poor man's Tube' in the Acorn World. If you want to use an actual Acorn 2nd processor box or PiTubeDirect directly, then my other Z80 Tube project already enables that ... but is a bit light on all the host software required currently. See this older thread - http://www.cpcwiki.eu/forum/amstrad-cpc-hardware/z80tube-running-acorn-co-processors-on-the-amstrad-cpc/ . I will get back to that at some point, but will mainly be working on this card for a bit.

Quote
Does a Pi3A fit ok on the back or does it need a ribbon cable instead?  Currently they are 17.89 on ebay!



Good question and unfortunately I don't have a Pi3A to test this, but I think I'm going to recommend the ribbon cable. You did suggest wanting to use the HDMI output from the Pi, and even if the Pi3A fits when plugged in directly (I think it will as far as the height of the card is concened) you would not be able to access the HDMI port since it would be too close to your expansion board PCB.


I do have a Pi3B (full size) somewhere. I'll see if that plugs in directly and post some snaps later.


GUNHED

Very nice project...

Can we connect a eZ80?

Can the card issue interrupts? Can it send NMI requests?

In which way can the card access the CPC?
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

shifters74

Look at the source code on github - the C source for the amstrad side is cross compiled with SDCC?  Just run 'make' on it?


While not a z80 whiz i have been using c since turbo C days (and recently on arduinos extensively!) so would probably use your c code as a starting point for a project if thats ok?

Paging memory to the pi was to be for my programs - i do have an old school memory expansion for 6128 (and xmem  too from toto).  The c64 used to page memory in and out of main program space for its memory expander.  I know this is not generally usable for other stuff until others use the same code - but the pi4 has up to 4GB of memory!!  Again sharing resources as per your suggestion!


Do you have any source for the ribbon cables?

shifters

revaldinho

Quote from: shifters74 on 19:06, 11 November 19
Do you have any source for the ribbon cables?


I haven't got any specific source for them, but a short version of this kind of thing would be fine


https://www.ebay.co.uk/itm/GPIO-Extender-Ribbon-Cable-40-Way-MALE-FEMALE-for-Raspberry-Pi-Model-B-UK-IDC/143182757268?hash=item21565b7d94:m:maH1EOAT9-UTvgc1SuHmTNw


However, I have just plugged my Pi3B in and ... it very nearly fits. In fact it does fit but won't complete mate squarely because the ethernet connector box very slightly overlaps the FIFO board so I can't push the connector all the way in. It fits well enough for me to boot the pi and run the loopback tests though, powering the Pi from the FIFO card. (I'm using an external supply for the expansion card and I can see 0.5A being consumed by the Pi + FIFO + M4 + ROM + Old School RAM card.)


So, looking at the Pi3A+ I think that will fit nicely and there's more clearance below the card than I thought there would be. You might need a flexible right angle type miniHDMI adapter, but certainly looks possible that you can get at the HDMI with a Pi3A+ mounted on the back.


On the libraries and examples, yes please help yourself - that's what they are for and they better describe the interface than any amount of text. :D


Here are a couple of snaps showing the Pi3B plugged right in.


revaldinho

Quote from: GUNHED on 19:01, 11 November 19
Very nice project...

Can we connect a eZ80?

Can the card issue interrupts? Can it send NMI requests?

In which way can the card access the CPC?


Thanks, Gunhed.


If an eZ80 has a parallel port you can use to connect to the data bus and handshaking lines, then yes you can plug that in with a cable adapter.


The card doesn't connect to the INT or NMI lines. My original prototype using a CPLD has those lines connected, but I didn't implement any functionality there and chose to leave it out of the all 74 series version mainly so that it would all fit in a small number of ICs on an 80x100mm board, which is the limit of the free-Eagle CAD tool.


So, access on both sides of the FIFO is by polling the status flags - which are just FIFO data in available, FIFO data out ready.


GUNHED

Ok, thanks a lot for your answer. That could be a great thing more a kind of "math co processor" for example. But lot's of other things are thinkable. Has the card some "connection" to the outer world? Probably that's not needed, but I'm curious.  :)
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

revaldinho

Quote from: GUNHED on 20:39, 11 November 19
Ok, thanks a lot for your answer. That could be a great thing more a kind of "math co processor" for example. But lot's of other things are thinkable. Has the card some "connection" to the outer world? Probably that's not needed, but I'm curious.  :)


Not really. The card brings the UART pins from a Pi or Arduino/ChipKit/Teensy out to pins on the front. This works well to allow comms from another PC/Mac direct to the co-processor when the co-pro is running headless. (On the Pi you just need to enable the serial login via raspi-config when you setup initially). Otherwise I'm relying on you using the IOs direct from the copro - with the Pi3B plugged in you have ethernet, multiple USB, audio, HDMI and even WiFi. They are all accessible. If you use a stackable connector on the co-pro then you can still get at the other GPIOs which aren't required for the FIFO interface too.


Just going back to the Pi3B for a moment, I think that if you use something like this


D7XTC3KTDOLong tall 40 20x2 pin header stacking extension, 2.54mm pitch for Raspberry Pi


as a spacer, then that will solve the issue of any tall components on large RPis and let them all mount directly into the card. It looks like the Zero and Pi3A+ will fit perfectly, but Pi3 and Pi4 will need extra clearance, or a short ribbon cable.


If anyone wants to fit a tall socket on the FIFO card to start with, then something similar to this looks like a reasonable option


2KF5HNMS9XRRaspberry Pi GPIO Tall Header - 2x20












shifters74

Pimoroni also sell the stacking headers - you can use them with a Pi4 to stack the cooling fan with other hats for example.


shifters

revaldinho

Quote from: shifters74 on 22:11, 11 November 19
Pimoroni also sell the stacking headers - you can use them with a Pi4 to stack the cooling fan with other hats for example.


Thanks for that pointer. Looks like one of these will do as a spacer, so no need for a ribbon cable after all.


https://shop.pimoroni.com/products/booster-header


zhulien

I think the following ideas are most useful when I get the time...


Modify a terminal app to communicate to a pi and have the pi direct i/o to the cpc. Allow for pi hosted small c for example to build directly to cpc.


Write a graphics protocol that ideally is RTG for cpc to write to native or hdmi and the terminal should support this.

shifters74

I think one of the first things to write is a shutdown command to run on the cpc that can tell the pi to safely shutdown!  :D

I think writing routines to do the functions that load into an M4 rom slot (or xmem rom slot) would be most useful to share code across any tools - any one any experience in doing that (or documentation) to help out with standard rom layout etc?


Thoughts?

Think its time to brush up on z80 assembly!   :-[    Chibi Akumas videos here i come!!  :P

shifters

revaldinho

Just a brief update after a bit of a plug-fest with different Raspberry Pi Models


RaspberryPi Zero and Pi3A+ both fit perfectly on the standard connector.



For full-size Pis, which have more high-rise components on board, I tried cards using both of these taller GPIO connector optionsBoth work very well.


There is plenty of clearance with either solution for a Pi3 and a Pi1  so both mate squarely with the connector using these options.


The tall header soldered to the CPC-CPlink card is probably the best option, although I haven't found a good, cheap source for these yet - nearly £4 each is quite pricey for a connector and I would need to add that directly on the cost of any cards I assemble.


The spacer is good too. It fits much more securely that I had expected and you can hang a relatively heavy full size Pi on it without any worries. Remember that the CPC-CPlink board has screw fixing holes to mate with those on the Pi, so if in doubt you can always use those to make a totally robust fixture. I wouldn't worry too much though. Just plugging straight into the header seems fine.




biged

Great project and very promising! I had some thought about how to bootstrap - how to start using the companion processor - without needing a custom ROM or a utility.  And I think it's as simple as a Basic one-liner which is easy to memorise and type in, such as:
FOR A=900 TO 933:POKE A,INP(&FD80):NEXT:CALL 900
This would download a short block of code from the coprocessor, supposing it's been set up appropriately, and that code can then start up a more sophisticated and useful protocol, maybe add some RSX facilities, like |LOAD, |RUN, |CHAIN, or |SAVE.
I did get a bit sidetracked on how to do this one-liner as a REM statement, using only printable characters which happen to be a legal Z80 program - discussion here - but I think that was a red herring. Even if the REM comes out shorter, it's harder to type, easier to get wrong, and very difficult to memorise. And it turns out the subset of Z80 you get is only just good enough for the job, and has to begin by constructing some inaccessible opcodes and operands.

shifters74

#18
Hi all,

I have written the commands i talked about previously for the CPC and PI side as previously discussed.

An initial set of services are provided that can be called on the CPC with the provided BASIC programs are:

PING - are we connected to a listening PI?

SHUTDOWN - to shutdown the pi safely

TIME - gets the current time from the PI

DATE - gets the current date from the PI

RESET - resets the PI side of the communication (free's memory, closes files etc).

I am current working on a memory paging system. It allows the pi to read/save (multiple) files (or just provide memory), and the CPC to page them (a xKB page at a time) in and out of its memory space.  The CPC side will be basic to start with and the demo app will be an ASCII file reader i think.

Where is the code you ask - Revaldinho has it and will be releasing on his github page shortly!

While the initial programs are BASIC i hope to provide assembler versions of them in the future but they are currently a reasonable demo app that's easy to understand.  Yes i know my basic sucks - :D   wait till you see my assembler  :o

Here are a few screenies to show you it working - everything is deliberately verbose in v0.1 so lots of screen chatter.


cheers

shiftes

1024MAK

@revaldinho - Looking good :) . I shall have to visit your GitHub page.

@shifters74 - Nice to see someone developing code for this new card already :)

Mark
Looking forward to summer in Somerset :-)

revaldinho

Quote from: 1024MAK on 12:16, 20 November 19
@revaldinho - Looking good :) . I shall have to visit your GitHub page.

@shifters74 - Nice to see someone developing code for this new card already :)

Mark




Thanks Mark


@shifters74 's MCP code is uploaded into GitHub now too - see the sw/examples/mcp folder.


BTW @1024MAK  - I will be at the ABUG meet this weekend and I see your name down too. I'll be bringing a '464 with my RAM board to show it running FutureOS and maybe other '6128 only' things. I'll bring the FIFO card and some RaspberryPis too, so drop by and say hello.


1024MAK

Quote from: revaldinho on 13:28, 20 November 19
BTW @1024MAK  - I will be at the ABUG meet this weekend and I see your name down too. I'll be bringing a '464 with my RAM board to show it running FutureOS and maybe other '6128 only' things. I'll bring the FIFO card and some RaspberryPis too, so drop by and say hello.
Great :) Will be nice to see your CPC boards in action.

If you have any boards / PCBs that are available for sale (any of your projects), please bring some along.

Mark
Looking forward to summer in Somerset :-)

biged

I nabbed a table next to revaldinho at this weekend's ABUG meetup, and we were able to make some good progress on the CPC+Pi combo.  It's the first time I've seen it in action, and the possibilities are endless, especially with a Pi that has WiFi.

My main fascination is with ROMless and diskless booting - an unmodified and unenhanced CPC with a CPLink board should be able to do interesting things, with just a one-line boot command written in Basic. And indeed we succeeded! We went through several iterations, and the current winner is this:

FOR A=100 TO 160:POKE A,INP(&FD80):NEXT:CALL 116

That Basic boot command pulls down a short chunk of Z80 code from the Pi, which can then offer all manner of wonders, by loading a longer chunk. I'm pretty sure we can make this idea compatible with, and perhaps an extension of, shifters74's idea of a server which responds to commands.The most visible success we had is the loading of Defend or Die in a fraction of a second. Here's a before and after hitting the enter key, with a slightly earlier and clunkier incantation of the boot:

1024MAK

It was an impressive demonstration  :P

Mark
Looking forward to summer in Somerset :-)

shifters74

HI guys,
i have finished writing and am just testing my next build (0.2) which includes the following commands:
/**********************************************************************************/
/* These commands control moving pages of memory in/out of the CPC to/from the pi */
/* Using allocation_id's you can have a number (default 20) different areas of    */
/* of memory allocated and you can request and store pages to each area seperately*/
/* When you work with a memory allocation you work with RPAGE and SPAGE and work  */
/* with page size as specified in the CPAGE command e.g. if you specified         */
/* CPAGE 5 8\n then you will have 5 pages of 8K and each RPAGE or SPAGE will work */
/* with an 8KB page at a time.                                                    */


/* CPAGE will create the number and size of pages requested in PI memory          */
/*       and return the allocation_id of that memory allocation                   */
/*       Any use of the other commands MUST have CPAGE performed first.           */
/*                                                                                */
/* FPAGE will free the memory allocation created by a CPAGE.                      */
/*                                                                                */
/* RPAGE is used by the CPC to fetch a page from the PI memory to its memory      */
/* The size of the page retrieved is what you specified in CPAGE                  */
/*                                                                                */
/* SPAGE is used by the CPC to store a page from its memory to the PI memory      */
/* The size of the page to be stored is what you specified in CPAGE               */
/*                                                                                */
/* PILPAGES is used by the CPC to tell the PI to load a file into its memory      */
/*          The CPC can then page the loaded file in and out of CPC memory from   */
/*          the PI's memory                                                       */
/*                                                                                */
/* PISPAGES is used by the CPC to tell the PI to save its memory back to          */
/*          file on the PI storage                                                */
/*                                                                                */
/* See each function for format of the messages                                   */
/**********************************************************************************/

Included within this build is automatic flow control of the queues, a retry mechanism for commands when they are unable to proceed, multi stage commands and better shutdown etc.


This is the base for my next commands (0.3) which are FILEREAD and FILEWRITE  to and from the PI to  CPC storage.


No reason why you cant have auto boot as per biged's post if some one provides the code (will make it an option as i use an M4 for that).


regards

shifters

Powered by SMFPacks Menu Editor Mod