Menu

PIC 18F47Q10 HUGE Project: Utilize CH376 USB Host Module & CLC's to develop Serial Port, ROM & 765 Floppy Controller Emulation for Amstrad CPC!

ikonsgr74
2021-05-16
2023-12-03
  • ikonsgr74

    ikonsgr74 - 2021-05-16

    Hi all,

    What i'm going to present you here, is the code i developed using GCB, to make this
    It's a device that allows an Amstrad CPC 8bit computer to access files (or dsk disk images) from a usb flash drive, and emulate ROM and 765 Floppy Disk controller in "low level"!

    Inside you will find:
    - Code for utilizing multiple CLC's (configurable Logic Cells)
    - Full read/write impementation of HW UART port, using asynchronous interrupt handling and a large ring buffer for input,
    - Routines for access usb flash drives through a cheap & easy to find CH376 Usb host module,
    - A "low level" emulation for 765 Floppy Disk Controller,
    - Reading large byte array tables and treat them as ROMs for AMSTRAD CPC

    I hope this will help other people with their projects too! ;-)

     
  • Anobium

    Anobium - 2021-05-16

    What a stunning project.

    The videos show what you have done.

    Amazing stuff!

     
  • mmotte

    mmotte - 2021-05-16

    Thanks for sharing! Lots of good stuff in the code and it will take a bit to digest. I was working with the ch376 last winter. Wow 3400 lines of code.

     
  • ikonsgr74

    ikonsgr74 - 2021-05-16

    Well, the word "HUGE" in topic's label was not an exaggeration :-)
    In fact, this might be the biggest project for 18F PICs, either in terms of size (it takes almost all 128kb of program memory!) and time: took me ~1,5 years and literraly 1000's hours of work to develop all functions, routines etc (of course there was also much work to be done in Z80 assembly too).
    The most difficult part, was the 765 FDC emulation, and believe me, this controller is nothing but easy to emulate: https://cpctech.cpcwiki.de/docs/upd765a/necfdc.htm
    Instead of a simple "request to send-> acknowledge" approach , there is whole series of "negotiation" between the CPU and the controller, for EACH data byte you want to send or receive! Even ONE wrong answer or responce in the process, is enough to crash everything! :-)
    But,i think the most useful part for other developers , would be the routines for utlizing the CH376 USB host module!
    This module, although very cheap and with big potential, was really hard to make it work right:
    - It has poor documentation (usual "google translate" from chinese to english...), and a rather complex way to access files.
    - There are various restrictions that are NOT mentioned, for example, you CAN'T fetch CORRECTLY more than 128bytes using a single "get data" command, although documentation stated it works for up to 255bytes! For weeks, i couldn't understand why my code didn't work right, until i startted to experiment with less bytes, ending up to the "magic" 128bytes!
    - There were errors in reported responce code bytes, in the end, i had to connect the CH376 module to a PC, and using a termnial program, give all required commands i needed, to finally get the correct responces from module in various situations...
    Anyway, the good news is that, the code regarding communication with the CH376 module, is rather well structured (with distinct routines for seek a file, read/write a number of bytes from a file etc, check at the end of the GCB code to see these routines), so in the future, there might be a GCB library for CH376 USB host modules based on this code! :-)

     
  • Anobium

    Anobium - 2021-05-17

    Huge is an understatement.

    This project makes the work of lead by Hugh all worthwhile.

    Your code is portable (across chip with similar capabilities) and uses no ASM. This means the compiler is doing what is asked.

    The one tweak I would add is.. #option explicit Just to ensure all the variable types are defined.

    :-)

     
  • ikonsgr74

    ikonsgr74 - 2021-05-17

    I've added #option explicit , and it seems that one variable "got away" from declaring :-)
    But it was used for temporary storing byte size pointer of some arryay variables in loops, so the "automatic" byte declaration of gcb for undeclared variables worked the same :-)
    Anyway, i'm pretty sure that, without GCB, such porject would be MUCH more difficult to make, using the "official" MPLAB tools. ;-)
    Thanks again for creating this fantastic alternative for 8bit PIC Microcontroller programming!

     
    • Anobium

      Anobium - 2021-05-18

      Very good coding to only miss one little variable.

      :-)

       
  • Domenic Cirone

    Domenic Cirone - 2021-05-19

    Wow, Amazing! I am trying to digest it. I was trying to duplicate the CLC logic but the CLC tool doesn't have that chip in its database. I assume that would be the way, never used CLC before. Is there a way to load that config in?

     
    • ikonsgr74

      ikonsgr74 - 2021-05-19

      To setup vasrous CLC's i had to use MPLABX-IDE and the embedded Microchip Code configurator (MCC). Then, you can generate the configuration files for each clc module and copy-paste them into cowbasic source. It's a bit tricky at first, but once you learn it it's rather easy to do it.

       

      Last edit: ikonsgr74 2021-05-19
      • Anobium

        Anobium - 2021-05-19

        You can add new chips to the CLC standalone application. Edit the clc.ini file and edit/add chips - all very obvious. And, the advantage of the CLC standalone application is that you can export and import settings.

        :-)

        Or, use MPLAB-IDE the online version to export the CLC source for your Great Cow BASIC project.

        Or, use MPLAB-IDE on your PC.

        :-(

         

        Last edit: Anobium 2021-05-19
  • Anobium

    Anobium - 2021-05-21

    @ikonsgr74 and @ all.

    This project compiles using PIC-AS! This is a huge test for the PIC-AS compiler as this is huge program.

    :-)

     
  • Domenic Cirone

    Domenic Cirone - 2023-12-01

    i was as looking at this for another project, but I am lost with CLC config. Is there a way to view the logic diagrams from the CLC source. I looked at the CLC configurator but was lost. BTW, this project is amazing.

     
  • ikonsgr74

    ikonsgr74 - 2023-12-01

    The easiest way to configure a CLC and get the required code for GCB is with the newer version of CLCDesigner: https://www.dropbox.com/s/phmofypnjp7t0pi/CLCDesignerTool.zip?dl=0

     
  • Jerry Messina

    Jerry Messina - 2023-12-02

    The CLCDesigner app came from a project I did for the Swordfish BASIC compiler.
    The current version is available at https://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.CLCDesignerTool

    That link will always have the latest version, but you should note that since Swordfish only supports the 18F family, that's all that's kept current. There's a newer version coming out soon that adds the 18FxxQ20 and Q24 families.

    There's even a simulator available that can show some of the basic operation of the CLC, but it's a REALLY simple simulation, so don't get too excited!

     
  • Anobium

    Anobium - 2023-12-02

    There is always use the Microchip standalone CLC tool. See the Microchip website.

     
  • Jerry Messina

    Jerry Messina - 2023-12-03

    Since they integrated the CLC designer into MPLABX the standalone tool was abandoned. It hasn't been updated since 2016 and never included support for the PIC18F.

    Although you can add devices using the .ini file, the version on the website doesn't have support for devices that use the CLCSELECT register overlay model (Q20, Q24, Q40/41, Q43, Q71, Q83/84). It also doesn't support anything with more than 4 CLC's, so it's pretty obsolete.

     
  • Anobium

    Anobium - 2023-12-03

    Latest standalone download page https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator

    This has the latest version dated 23rd Nov 2023. This is what I have used.

     

    Last edit: Anobium 2023-12-03
  • Jerry Messina

    Jerry Messina - 2023-12-03

    That page is for the MCC plugin, so it requires MPLABX.

    Maybe I have a different definition of "standalone". Am I missing something? Is there something hidden on that page?

     
    • Anobium

      Anobium - 2023-12-03

      Try the download, i cannot at the moment. But, it is a standalone application that cover CLC ( both types ).

       
  • Jerry Messina

    Jerry Messina - 2023-12-03

    Oh, I think I see... you're talking about the standalone version of MCC, not a standalone version of the CLCDesigner.

     
    • Anobium

      Anobium - 2023-12-03

      Yes, CLC is a sub capability. If it the software were 32bit I would adopt completely. But, being 64bit is a huge constraint.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.