返回正常中文阅读

想对这篇译文“指手画脚”吗?

您的参与将有助于译者提高译文的质量;同时,大家一起对问题的讨论也是最佳的学习方式。还等什么?请现在就注册登录译言,开始眉批!
大错 小错 不顺 建议

Simple evaluation board and Linux programmer for C8051F320

First of all I must warn you!!! This is a free, experimental design. It has worked for me, but I do not give you any warranty, that it is error free. I could make any mistake when preparing this material for publication, there can be some not discovered bugs in both my hardware and software. It can also infringe someones patents... (however I don't know anything about it). So keep in mind - you use it on your own risk and responsibility!!! 

One of very nice USB capable microcontrollers is the C8051F320 produced by Silabs (formerly Cygnal). Unfortunately to start playing with this chip you need to buy a rather expensive development kit. On this page I present some alternatives for building a cheaper toolset.

The first component is a simple and cheap development board with C8051F320. The schematic is based on the original development board from Silabs. It has been designed as single layer PCB, and therefore it is really easy to be produced at home.

 The PCB design has been prepared with the free PCB program. For those of you, who are not able to run PCB (eg. because yur PC runs only under the broken operating system® ) I've provided the PDF file.

The schematic diagram has been prepared with the free gschem program, but again the PDF version is also available.

 The board itself however is useless without the programmer. To keep the costs as low as possible, I've prepared a simple programmer (here are the schematics sources in a XFig format) connected directly to the PC's LPT port.

The programmer is controlled with a dedicated software, written in C language. The software (source available under GPL) consists of two parts. The first one is a dedicated Linux driver, and the next one is a program "cygprog". To use the programmer you need first to load the driver (as root):

# insmod cygnal_c2 io_base=0x378 major=233

(certainly you should adjust the io_base to the LPT port address in your PC, and the "major" number to a free value; you can also don't set the major - it will be allocated dynamically and then you'll need to find the allocated number in the /proc/devices).

Then you should create the appropriate device node. Now the programmer expects to find it in its working directory, under the "cygnal" name (you can modify sources if you want to).

# mknod cygnal c 233 0

Then you can use the program. It is wise to give the normal user access to the cygnal device and use the program as a normal user:

# chown user.user cygnal

One important remark - my driver is not "parport" compatible. It is necessary to remove "parport" driver and/or "lp" driver, before using the cygnal device.

 My programmer software now understands only the raw binary files starting from address 0. You can convert standard "ihx" files (as produced by the SDCC compiler) into the binary files, using the "srec_cat" tool (available eg. in the Debian "srecord" package). You should use a command line like this:

$srec_cat -Output test.bin -Binary wzab.ihx -Intel

to convert the "ihx" file into the binary one.

Then you can use the cygprog to write your program into the device's memory:

$./cygprog p test.bin

The software can also verify the program (./cygprog v test.bin) and dump the device's memory into the file (./cygprog r output.bin).

 Certainly this only the first draft version (however it is usable for me), so any corrections and suggestions are appreciated.

I've received some messages, that it is not possible to compile the driver for kernel 2.6. I've checked it, and cleaned up the source a little. Here you can find the source modified for kernel 2.6. The archive contains two subdirectories: "driver" and "program". Make command in the "driver" subdirectory should build a driver module (however some warnings may be issued during the compilation), while make in the "program" directory should build the user mode part of the programmer software.

Things to do

  • To prepare the USB firmware under the free license (GPL or Artistic), able to compile with the SDCC C compiler
  • To improve the programmer, so it could erase only the necessary pages of the FLASH memory
  • To prepare the C2 debugging tools working under Linux OS (however C2 debugging specifications, like register map and command reference, are needed for that task - any help is appreciated)

Improvements sent by Matt Otto

A few days ago I have received the improved version of the programmer, prepared by Matt Otto. This is what he says in the README file:
This is an enhancement to Wojtek Zabolotny's C2 programmer. There are two significant enhancements:

  1. I have included the source code for a new program, c2mon.c, which demonstrates how to perform debugging operations with the C2 interface. It is very crude as far as programs go (there's no user interaction), but the source code shows how to perform any debugging task you may need.
  2. In order to support some undocumented behaviors of the C2 interface, I needed to enhance Wojtek's driver and schematic. The enhancements allow for sending and receiving short C2CK pulses.


In addition to the C2CK enhancements, I also added Plug and Play (PNP) support to the driver so that it would work on my PC (I don't know if my PC hardware is different or if my 2.6.12 kernel requires it).
Instead of trying to make c2mon useful as a stand-alone program, I am starting to integrate c2mon into SDCDB, the debugger that comes with the SDCC compiler. (Currently, SDCDB only knows how to interface with the uCsim simulator.) Until I finish that project, hopefully the c2mon.c sample code will be useful.
Matt Otto matt@__NO_SPAM__klox.net

自制C8051F320简易评估板和Linux编程器

首先我要警告你们!!!这是一个自由、试验性的设计。在我这工作得很好,但是我不能给你任何担保,这是过失自由。当准备材料发表这篇文章时,我可能犯下任何错误,硬件和软件上都有可能有未被发现的漏洞。它也有可能侵犯某人的专利...(尽管我对此一无所知)。所以记住——你使用它,后果自负!!!

Silabs(以前的Cygnal)生产的C8051F320,是一个很好的带USB支持的微控制芯片。不幸的是,如果决定使用这块芯片开发,你不得不购买非常昂贵的开发套件。本文我向大家介绍一些替代品,自制便宜一些的工具套件。

首先是一个C8051F320的简易而且便宜的开发板。原理图基于Silabs公司的原始开发板。它被设计为单层PCB,因此非常容易在家自制。

 PCB设计是通过自由软件PCB完成的。对你们来说,可能运行不了PCB(比如,因为你们的电脑只运行那个破系统®),我提供了PDF文件

 原理图设计是通过自由软件gschem完成的, 但是同样我也提供了PDF文件

 然而如果没有编程器(译注:就是下载线),开发板本身毫无用处。为了尽量减少开支,我提供了一个简单的编程器(这是XFig格式的原理图源文件),它直接的电脑的并口连接。

编程器由一个用C语言写的专用软件控制。这个软件(源码以GPL发布)由两部分组成。第一部分是一个专用Linux驱动,第二部分是一个软件“cygprog”。要使用编程器你首先必须装载驱动(以根用户执行):

# insmod cygnal_c2 io_base=0x378 major=233

(通常你需要调整你电脑并口的端口地址,使io_base 和major数字对应端口为空闲值域;你也可以不设置major——它会被动态分配,你需要从/proc/devices找到那个动态分配的确切值)。

然后你应该创建合适的设备节点。现在编程器期望在它的工作目录找到它,一个叫“cygnal”的节点(如果想改变名字你可以修改源码)。

# mknod cygnal c 233 0

现在你可以使用软件了。给普通用户cygnal设备的访问权和以普通用户执行软件是一个明智的作法:

# chown user.user cygnal

一个重要说明——我写的驱动与“parpot”设备不兼容。在使用cygnal设备之前,必须移除“parport”驱动和/或“lp”驱动。

我的编程器软件现在只能识别从地址0开始的原始二进制文件。你可以使用“srec_cat”工具(在Debian的“srecord”包中有提供),把标准的“ihx”文件(SDCC编译器产生)转化成二进制文件。你应该使用这样的命令行:

$srec_cat -Output test.bin -Binary wzab.ihx -Intel

把“ihx”文件转化成二进制文件。

然后就可以使用cygprog软件把程序写进设备记忆体:

$./cygprog p test.bin

软件也可以验证记忆体中的程序(./cygprog v test.bin),或把设备记忆体中程序写入文件(./cygprog r output.bin)。

当然这只是第一个草稿版本(然而对我来说它很有用),所以如果你可以提出任何修改和建议,我会很感激。

我已经接到一些信息,说在2.6版本的内核无法编译驱动。我已经检查过,并对源文件作了一些小改动。这里是为2.6内核改进的源码。压缩文件包含两个子文件夹:"driver"和"program"。在"driver"子文件夹内打命令将编译驱动模块(然而编译过程中可能会出现一些警告),在"program" 内会编译编程器软件的用户模块。

需要改进之处

  • 筹备在自由许可(GPL或Artistic)下发布的USB固件,以便能用SDCC C 编译器编译。
  • 改进编程器,让它只擦除闪存记忆体中需要擦除的页面。
  • 设计能在Linux操作系统下工作的C2调试工具(然而这个任务需要C2调试说明书,比如寄存器映象和引用命令——如能提供帮助万分感激)

Matt Otto发来的改进

前些日子我接到一个编程器的改进版本,是Matt Otto做的。这是他在README文件中所写的:
这是Wojtek Zabolotny的C2编程器增强版。有两个重要改进:

  1. 我把源代码包含到一个新程序中去了,c2mon.c,它演示了在C2接口中如何显示调试操作。在程序运行时它显示非常粗糙(没有用户交互),但是源代码展示了如何显示任何你想要的调试任务。 
  2. 为了支持一些没有说明的C2接口行为,我必须改进Wojtek的驱动和原理图。这些改进允许发送和接收短的C2CK脉冲。

除了C2CK改进之处,我也对驱动增加了即插即用(PNP)支持,以便它能在工的电脑上工作(我不知道是我的电脑硬件不同或是2.6.12内核需要它)。我没有试图把c2mon做成一个与操作系统无关的软件,而是开始把c2com整合到SDCDB中去,SDCDB是SDCC所带的调试器。(目前为止,SDCDB只知道如何与uCsim仿真器接口。)在这完成这个项目之前,希望c2mon.c样本代码会有用。
Matt Otto matt@__NO_SPAM__klox.net


阅读
发现
翻译