Samstag, 29. Dezember 2012

SVF Interpreter for VHDL Testbench

Digital chips often contain a JTAG port, which is used to implemente boundary scan and to access internal functionality of the chip, like programming and debugging.

One widespread "standard" to specify JTAG operations is SVF (Serial Vector Format). Many tools can generate SVF files which are then used to operate the JTAG signals of a chip, e.g. with Lib(X)SVF.

As everything in chip design, the JTAG functionality also has to be verified during development. At this time, all modules as well as the whole chip are simulated. vhdl-svf provides an SVF interpreter, written in pure VHDL, which reads a SVF file and exercises the JTAG signals. It is inteded to be integrated in a testbench to verify the chip design.

Donnerstag, 4. Oktober 2012

MSP430 LaunchPad with Debian

The TI MSP430 are ultra-low-power 16-bit RISC microcontrollers. Since a while, TI sells eval kits called "LaunchPad" for $ 4.30 for their "value line" (i.e. cheap) MSP430 products. These have a debugging and programming interface (USB).

To use the LaunchPad with Debian GNU/Linux (sid, as of 2012-10-04), some packages have to be installed

aptitude install gcc-msp430 gdb-msp430 \
  msp430-libc msp430mcu mspdebug binutils-msp430

Debugging

mspdebug supports the LaunchPad for programming and debugging using its rf2500 driver (which is also used for the eZ430-RF2500 and Chronos watch). It is started with

mspdebug rf2500

This program offers a powerful command line interface for memory dump, programming and debugging. It also has a GDB remote stub, so you can debug your programs with GDB. Connecting via the debugger stops the currently running program (presumably the preloaded demo program). To continue execution, type

run

and press ^C to stop again. This will show the current register values and a short disassembly.

(mspdebug) run
Running. Press Ctrl+C to interrupt...
^C
    ( PC: 0fc86)  ( R4: 00282)  ( R8: 0ab57)  (R12: 00000)  
    ( SP: 0027a)  ( R5: 05a08)  ( R9: 0fb5b)  (R13: 0fd90)  
    ( SR: 000dd)  ( R6: 0adff)  (R10: 0aee2)  (R14: 00000)  
    ( R3: 00000)  ( R7: 0fa3f)  (R11: 0bf73)  (R15: 0ffff)  
0xfc86:
    0fc86: 30 41                     RET     
    0fc88: f2 40 0a 00 00 02         MOV.B   #0x000a, &0x0200
    0fc8e: 03 3c                     JMP     0xfc96
    0fc90: 92 42 70 01 72 01         MOV     &0x0170, &0x0172

You can switch on beautifully colorized output:

opt color true

My LaunchPad came with a MSP430G2231. It seems that newer LaunchPads come with a different device. Features of the MSP430G2231:

  • 1.8-3.6V
  • 16MHz
  • 2kB Flash, 128B RAM
  • 10-Bit ADC, 8 IOs, WDT, Timer, USI (SPI, I2C)

Memory map:

  • F800h-FFFFh: Flash, 4 segments of 512 bytes
  • 1000h-10FFh: Information Memory, 4 segments of 64 bytes, stores calibration values!
  • 0200h-027Fh: RAM
  • 0000h-01FFh: SFR, Peripherals
  • FFC0h-FFFFh: Interrupt Vectors, Reset = FFFEh

The LaunchPad has a red LED (connected to P1.0) and a green LED (P1.6) and a button (P1.3).

After reset, the 16-bit value at FFFEh is read. This is used as initial value of the PC register to start execution. Let's examine the boot process!

(mspdebug) md 0xFFFE 2
    0fffe: c2 fc                                           |..              |
(mspdebug) dis 0xFCC2
0xfcc2:
    0fcc2: 31 40 7e 02               MOV     #0x027e, SP
    0fcc6: b2 40 6e fd 36 02         MOV     #0xfd6e, &0x0236
    0fccc: b2 40 6e fd 38 02         MOV     #0xfd6e, &0x0238
    0fcd2: b0 12 66 fd               CALL    #0xfd66
    0fcd6: 0c 93                     TST     R12
    0fcd8: 02 24                     JZ      0xfcde
    0fcda: b0 12 8e fb               CALL    #0xfb8e
    0fcde: 0c 43                     CLR     R12
    0fce0: b0 12 00 f8               CALL    #0xf800
    ...

Before our own program is programmed, we should save the Flash memory content. The following command will save 2048 bytes, starting at F800h, to the Intel HEX file MSP-EXP430G2-2231.ihx.

hexout 0xF800 2048 MSP-EXP430G2-2231.ihx

During playing, I had an accident, inadvertently typing "mw 0xFFFE 2" instead of "md 0xFFFE 2" which overwrites the value C2h at FFFEh with 02h. It was not possible to correct this with "mw 0xFFFE 0xC2" because the Flash is initialized to all logic 1s and can be set bit-wise to 0. Writing the memory to an Intel HEX file, correcting the value at FFFEh to C2h (and correcting the checksum), and reprogramming the device with "prog MSP-EXP430G2-2231.ihx" restored the old contents. BTW: The "prog" command complained for the invalid checksum and also said which value it expected. So no hand calculation of the value was necessary. :-)

Compiling

As first example program, let's use the blinking LED proposed by TI at http://processors.wiki.ti.com/index.php/Blink_your_first_LED (you have to scroll down a bit). Copy-paste the example program to a file called blink.c and change the included .h-file to the device you own. Then compile using

msp430-gcc -mmcu=msp430g2231 -o blink.elf blink.c

The result can be examined (and disassembled) using

msp430-objdump -d blink.elf

Back in the mspdebug commmand line, program the new firmware to the MCU and start it:

prog blink.elf
run

Nice blinking should be visible.

MSP430 FRAM Devices

The MSP-EXP430FR5739 Experimenter Board with an MSP430 FRAM MCU can also be programmed. It comes with an MSP430FR5739 soldered to the board. Its features are

  • 2-3.6V
  • 24MHz
  • 16kB FRAM, 1kB SRAM
  • 10-BIT ADC, 32 IOs, Comparator, Timer, USCI (UART, IrDA, SPI, I2C)

The memory map is as follows:

  • C200h-FFFFh: FRAM
  • 1C00h-1FFFh: RAM
  • 1A00h-1A7Fh: Device Descriptor Info (FRAM)
  • 1800h-19FFh: Information memory (partly mirrored, FRAM)
  • 1000h-17FFh: Bootstrap loader (ROM)
  • 0000h-0FFFh: SFRs, Peripherals
  • FF80h-FFFFh: Interrupt Vectors, Reset = FFFEh

The MSP-EXP430FR5739 Experimenter Board is a bit more expensive than the LaunchPad (but has a similar form factor). It comes with 8 blue LEDs (everything needs blue LEDs!), an accelerometer, an NTC, two buttons, ... These are connected as follows:

  • LED0..3: PJ.0 .. PJ.3
  • LED4..8: P3.4 .. P3.7
  • S1: P4.0
  • S2: P4.1
  • Accel X: P3.0/A12
  • Accel Y: P3.1/A13

Simple alternate blink program

#include  <msp430fr5739.h>

unsigned int i = 0;

void main(void) {
  // Stop watchdog timer.
  WDTCTL = WDTPW + WDTHOLD;

  // enable PJ.0 and PJ.1 as outputs
  PJDIR |= 0x01 | 0x02;
  // switch on first LED and switch off second LED
  PJOUT = (PJOUT & ~(0x01 | 0x02)) | 0x01;

  // main loop
  for (;;) {
    // toggle LEDs
    PJOUT ^= 0x01 | 0x02;
    // delay
    for(i=0; i< 20000; i++);
  }
}

Save this to a file blink-fram.c and compile with

msp430-gcc -mmcu=msp430fr5739 -o blink-fram.elf blink-fram.c

Important: To download, the mspdebug command "prog" cannot be used, because it issues a Flash erase command. The FRAM devices don't need an erase, because it can be written like normal RAM. Therefore program the device with the "load" command. But first, the FRAM contents should be backuped:

hexout 0xC200 0x3E00 MSP-EXP430FR5739-Demo.ihx
load blink-fram.elf
run

And again, nice blue blinking should be visible

This was only a very coarse run through the tools, but the usage is really astonishing simple, yet powerful. More to come (GDB, Makefile, Eclipse, ...)

Sonntag, 23. September 2012

libusb 1.0 for Pascal

This is a follow-up post to LibUSB for Pascal on 2012-07-15. I've now added header translations for the newer version libusb 1.0 (as well as its fork libusbx) including an object-oriented wrapper and a few examples to be used with Pascal.

Please find the source code in the libusb-1.0 branch at https://github.com/hansiglaser/pas-libusb.

Sonntag, 12. August 2012

NXP LPC11U14 and the LPCXpresso Board

The NXP LPC11xx series microcontrollers include an ARM Cortex-M0 CPU with SRAM, Flash and numerous peripherals. The low-cost LPCXpresso development board offers a debug adapter (JTAG, more precisely SWD) via USB. This is used with the Eclipse-based LPCXpresso IDE. Fortunately NXP offers it for Linux users too, even including the drivers for the debug connection.

After rapt contemplation I concluded, that most, if not all, of my ideas for nice projects require the connection to a PC. I prefer USB, so the LPC11Uxx microcontrollers including a USB 1.1 (12 MBit) device core come in handy.

NXP really tries to establish a community around their microcontrollers with forums and near-open-source software. The ARM Cortex-M0 MCUs are positioned as 8-bit and 16-bit MCU replacement. Therefore they have quite small packages (QFN33, LQFP48). The LPC1102 is sold in a WLCSP-16 package of which I've posted microscope images some time ago.

The low-cost LPCXpresso boards come without pin headers. I've added sockets, because its easier to connect wires to them.

One feature of these boards is that they can be used as debug adapter for custom boards. The connections from the debug adapter part to the device part of the board are layed out to holes for a 8x2 pin head with 100mil pitch. When delivered, the connection is made with small solder dots which can be removed using desoldering braid. I've added the pin head and put 8 jumpers on it to re-connect the on-board microcontroller.

One massive drawback of these microcontrollers is their extremley slow Flash memory. This gets even worse because it is (nearly) kept secret. The datasheet as well as the web page praise the fast operating frequency of 50 MHz. You have to dig deeply into the user manual to find a third-level section called "Flash memory access" describing a register called "Flash configuration register". Only the specific description of the two bits "Flash memory access time" reveals that wait-states (this word is avoided too) are required at higher frequencies. The maximum flash frequency is 20 MHz, so at the praised 50 MHz CPU frequency only every third cycle is an active one, effectively dividing the performance by three! Only the timers and other peripherals can utilize the higher clock frequency.

While ranting, nearly all ARM microcontrollers have slow flash and nearly all companies try to obscure that fact. Some microcontrollers try to speed up things using some kind of cache, others put loads of (fast) SRAM for code storage. It is still disappointing to be mucked around.

Montag, 16. Juli 2012

Control and communicate with a Cypress EZ-USB

When developing a device with the Cypress EZ-USB AN2131 microcontroller, eztool might come in handy. It is a command line tool to control and to communicate with these microcontrollers via USB. It can also communicate to any USB device in a custom user mode.

eztool offers a convenient command line interface. It uses Tcl as scripting language and command interpreter. Actually, every command you enter is implemented as a Tcl command (but written in Pascal and compiled in the executable). The Tcl programming language offers unlimited options to use, customize and automate eztool.

eztool prints a prompt at the screen which signals the current mode. To wait for the user input, GNU Readline is used. This offers comforable command line editing, history and auto-completion.

For each Tcl command and variable a dedicated manual page is provided.

Please find the source code at https://github.com/hansiglaser/eztool. It uses the Pascal OOP wrappers for GNU Readline, Tcl and LibUSB. Its device firmware is based on the EZ-USB firmware template.

Sonntag, 15. Juli 2012

EZ-USB Firmware Skeleton

Back in 2002 I developed my first evaluation board with the Cypress EZ-USB AN2131 microcontroller. Since then I developed several projects using this microcontroller. Each time a dedicated firmware was necessary.

In 2011 a student used one of my firmware projects to develop a firmware for the Keil ULink JTAG adapter, which also has an EZ-USB microcontroller. Unfortunately my firmware had a few files with unclear license conditions, so he re-implemented most files. His work was published as OpenULINK as part of the OpenOCD JTAG driver.

I used his improved firmware as starting point for the development of a firmware skeleton for the Cypress EZ-USB microcontroller. Please find the source code at https://github.com/hansiglaser/ezusb-firmware.

LibUSB for Pascal

libusb is a C library that gives applications easy access to USB devices. Many of my previous projects involving USB devices (e.g. the EZ-USB breakout board) use the libusb to communicate with it from the PC.

Since libusb is implemented in (plain) C, its headers had to be translated to be used with Pascal. I've also added an object-oriented wrapper. Please find the source code at https://github.com/hansiglaser/pas-libusb.

Mittwoch, 4. Juli 2012

TCL for Pascal

TCL (Tool Command Language) is a scripting language widely used as integrated scripting engine. Some time ago I wrote a tool to remote control an EZ-USB chip via USB (soon to be published). It offers a command line interface using GNU Readline and TCL.

Since TCL is implemented in (plain) C, its headers had to be translated to be used with Pascal. I've also added an object-oriented wrapper. Please find the source code at https://github.com/hansiglaser/pas-tcl.

Dienstag, 3. Juli 2012

GNU Readline for Pascal

The GNU Readline library is used to prompt the user for textual input at the terminal. It provides features like a history and completion. When you work at the terminal, e.g. with the bash shell, you are actually using Readline during typing and acquiring previous input lines from the history.

GNU Readline is implemented in (plain) C. To use it with Pascal, I've translated the C headers and added an object-oriented wrapper. Please find the source code at https://github.com/hansiglaser/pas-readline.

Samstag, 23. Juni 2012

Raspberry Pi

Last Thursday, 2012-06-21, the Raspberry Pi has arrived. :-)


The first thing is that I ordered three at Farnell to sell to friends and to share shipping cost. Unfortunately, they reduced the order to a single piece. The guy on the phone explained, that everybody is limited to one device only. So be prepared to spend extra shipping cost.

To play with it, I followed the instruction in the Quick Start Guide. Therefore I downloaded the Debian Squeeze image and copied to an SD card. Then I connected the Raspberry Pi to my monitor, plugged in the ethernet cable, mouse and keyboard and used the power supply of my Samsung Galaxy 3 (note: not S3!) and there we go. It booted like a charm and shows its IP address at the screen.

To access the Raspberry Pi via SSH, you first have to generate a host key. Therefore run the commands

sudo dpkg-reconfigure openssh-server

which will also start the SSH server.

Next, I started the X Windows system by

startx

and got the LXDE desktop environment. The browser is "Midori" and the "LXTerminal" can be used for command line interface. I used "aptitude" to install the packages "vim-gtk" for a powerful editor, "fp-compiler" for a powerful programming language and "scrot" to make screenshots as suggested here. Note that the "scrot" package was not available originally, but after changing /etc/apt/sources.list to use the ftp.at.debian.org mirror and pressing the [U] key in "aptitude", it was there.

Most important thing? Write a Hello World! program, once in FreePascal, once with GCC. :-)

So, what next?

T6 Manager

The T6 Manager is a GUI frontend to manager your trainings performed with the Suunto T6 training computer. It uses LibT6 (included) to communicate to the T6 and to download the training logs. These are stored on disk for later reference. Each training log can be displayed. The heart rate, altitude and distance (and speed) data are visualized.

SourceForge.net Project

Donnerstag, 31. Mai 2012

k7103-USB

Several years ago I wrote a GUI frontend for the Velleman k7103 PC Storage Oscilloscope.

K7103 picture          K7103 Frontend

The DSO is connected to the PC with a parallel printer cable. Most modern PCs don't have this interface any more. USB to Parallel converter cables don't work as interface because special control signals are used by k7103.

Therefore I developed a USB interface for k7103. k7103-USB is a dedicated interface with direct connection to the internal signals of the k7103. It offers all features of k7103 as available with the parallel printer cable. Additionally, an increased bandwidth for the data transfer of the sampling RAM to the PC is achieved. The K7103 frontend is extended with an appropriate driver for the new USB interface. It achieves approx. 70 acquisitions per second at my Core-i7 at 2.8GHz.

An additional PCB (100x76mm) is inserted into the k7103 case and connects to several digital chips of the k7103 PCB. k7103-USB mainly contains a Cypress AN2131Q EZ-USB 8051 microcontroller (MCU) and a Xilinx XC9572-PC84 CPLD.

Find more information on the GUI frontend and the k7103-USB hardware at http://k7103.sourceforge.net/.

Donnerstag, 17. Mai 2012

Colorful svn diff

How to get a colorful svn diff?

First install the program colordiff.

aptitude install colordiff

Now SVN must be told to use colordiff, so edit your ~/.subversion/config and add the line

diff-cmd = colordiff

in the [helpers] section (usually there is a commented template you can use). Now the output of

svn diff

will be a colorful representation of your changes.

However, this creates one problem when piped to less, because it shows the escape characters with caret notation. Therefore the command line parameter -R is used to display ANSI color escape sequences as colors. Set the environment variable LESS with this option.

export LESS="-R"

One more improvement: less wraps the lines at screen width which is often not desired. Therefore use the switch -s to get a line-by-line output. For a permanent setting, put

export LESS="-sR"

to ~/.bashrc or system wide to /etc/bash.bashrc.

One more tip: A recursive search in an SVN working copy with grep also reveals occurences in the internal "backup" files. Therefore the following alias excludes the .svn subdirectory (and backup files of your editor and compiled Python files).

alias rsgrep='rgrep --exclude-dir=.svn --exclude=*~ --exclude=*.pyc'

Sonntag, 5. Februar 2012

LaTeX \boldsymbol and \package{struktex}


The LaTeX package "struktex" for drawing structograms break the "\boldsymbol" command, which is used for bold letters in math mode. A little investigation shows that the sub-package "struktxf" does some font magic to define the commands \nat, \integer, ... Fortunately this sub-package doesn't define anything if the command "\nat" is already defined.

To re-enable "\boldsymbol" simply define the command "\nat" before using the package "struktex".
% Struktogramm
\def\nat{}   
\usepackage{struktex}