I’ve uploaded documentation and a source download for fx2lib. Here is the copy of the Sourceforge announcement.
The fx2lib sources are stable enough to build complete firmware implementations for the cypress fx/fx2 variants of the 8051 chipset.
The current release includes library functions for:
- delay functions
- endpoint functions
- register definitions
- type definitions
- macros for common tasks
- GPIF functions
- i2c functions
- serial IO
- USB jump tables
- vendor commands and setup data.
Library documentation is located at: http://fx2lib.sourceforge.net/docs/
Sources can be downloaded from the project download page: https://sourceforge.net/project/showfiles.php?group_id=247216
Development on fx2lib occurs in a git repository at: http://github.com/mulicheng/fx2lib/
Check out my other posts on fx2 programming for reference. If you are interested, there is much information to discuss on the fx2lib mailing list too. Check the fx2lib home page for information on joining the list.
After playing around with the Cypress FX2 and SDCC for the past while, I’ve developed a library of utilities that make some of the common tasks for writing firmware and performing certain functions a little easier. I’m lucky to work for a company that approves of the open source initiative and believes that it is beneficial to give back as well as receive from a wider audience of developers. That being said, I’ve created a git repository with my library:
Here is fx2lib on github: http://github.com/mulicheng/fx2lib/
You can clone it with git like this:
> git clone git://github.com/mulicheng/fx2lib.git fx2lib
Here is a short list of some of the things you can do with this library:
- Read/Write data on the i2c bus
- Handle USB and GPIF interrupts
- Read/Write data on to a serial console
- Handle the common USB vendor commands
- Implement your own vendor commands
- Program the GPIF
Hope you enjoy!
Update 12/15/08: Added project home page at Sourceforge: fx2lib home.
I’ve had the enjoyable experience of playing around with the Cy7c68013a chip on the Ez-Usb development board for the past few weeks. I thought I’d post a few tips for developing in this type of environment with open source software.
Convert to Linux
The tools that Cypress provides with the development kit are Windows based. You can download a number of their items directly from their website, but i didn’t find a way to unpack their source code examples without running their installer in a Windows session. The installer creates a new directory: C:\Cypress\ You can ignore the bin directory. Copy the docs directory (You’ll need the TRM) and the examples directory to your Linux machine. The examples won’t compile on Linux (The c51 compiler provided by Keil is Windows based) but they provide good insight into how to do a few things when it isn’t immediately clear by reading the TRM. You may also be interested in their util sources but I’ve found only minor uses for these since there are open source alternatives to a lot of what they do.
Convert to SDCC
On Linux, you’ll compile programs for the 8051 chip with SDCC. You can install it from their sources or from a package provided by your Linux distribution. SDCC works very similar to gcc but provides output that can be loaded onto embedded devices.
A couple important switches for compiling:
- -mmcs51 Tells the compiler to produce output for the 8051 chip
- -xram-loc Tells the compiler where to start putting xdata variables
(If a program suddenly doesn’t work after you add an xdata variable, try playing with this 1st.)
Convert the fx2regs.h file
The fx2regs.h file provided with cypress won’t compile with SDCC (It’s Keil specific). There are a few things you can do.
- Just use the 8051.h (or 8052.h) file provided by sdcc. (Works if you don’t need lots of the extended registers. Also works for getting started with basic examples.
- Rewrite it in non compiler specific macros. SDCC comes with a compiler.h file that has macros for SFR, SBIT, etc. You can use these and generate a header file that can be compiled on more than one platform.
- Use a convert utility. There is a perl script on SDCCs contrib folder that can convert Keil to SDCC headers.
(For clarification, this script is included in the source tarball.)
- Rewrite it yourself by hand. Well, if you don’t trust the conversion script anyway.
Learn how to run programs
The Cy7c68013a chip handles some basic USB commands for you. 1st of all, it will enumerate itself. 2nd, it will allow you to upload and download firmware to the 8051. This 2nd tidbit is vital. You can 1st upload a byte to the reset bit location in firmware (putting the chip in reset), then upload a new firmware, and then upload a byte that puts it back out of reset, thus running your program.
This fairly straight forward process is documented in the TRM. Even cooler though, someone already implemented it for you so you don’t have to. I use the cycfx2prog utility. It’s GPLed and the source is available to download.
After compiling a simple program (which produces an ihx-intel hex file), you can upload it like this:
> cycfx2prog prg:program.ihx run
Port a couple example programs to SDCC.
I started by rewriting a few of the examples and libraries for testing. I recommend 1st getting serial io working so you can debug easier. After that, play around with the i2c board and lights. Finally, test writing to eeprom. (For eeprom images, the hex2bix program that comes with the development kit can easily be ported to run on Linux by using linux time libraries instead of the windows files.)
Perhaps this section deserves it’s own blog post later on.
Anyway, I haven’t yet found anything that can’t be done on Linux with the Ez-USB kit.
UPDATE 12/5/08: Added Open Source FX2 Library.