Showing posts with label COOCOX. Show all posts
Showing posts with label COOCOX. Show all posts

Saturday, July 27, 2013

OpenOCD FT2232H based JTAG Adapter(s) with UART

USB to JTAG, and JTAG to JTAG adapters
JTAG adapters are commonly used to program and debug microcontrollers and microprocessors.  This circuit is a prototype of one that is compatible with OpenOCD which is an open source JTAG program and set of drivers.  The board and circuit presented here is simply a set of connections, jumpers, and sockets that leverage the FT2232H Mini Module as a USB to JTAG adapter. 

Four JTAG and/or SWD ports are provided for compatibility with a variety of development boards: 6-pin ST-LINK, 8-pin LPC-Link, 10-pin JTAG, 20-pin JTAG. 

Using one of two plug in modules, the 10-pin is either 0.05" pitch or 0.1" pitch. I plan to include both 10-pin formats on any revisions to this JTAG board so I can easily adapt between the formats.

When used as a USB JTAG adapter, only one of the JTAG or SWD ports is used.  Note that pin 1 is consistently in the upper left on this board.  Ribbon cables or socket cables are used to connect to the target board.  It is useful to have sets of cables that support all these pin-out formats.  Cables are quicker and easier than single conductor jumpers between individual connector pins.

An alternate use is to adapt from one pin-out to another when using other JTAG and/or SWD programmers.  In this case the mini module can be removed or simply disconnect the USB cable from the computer.  The board is only being used to convert pin-outs.  For example, I can use a 6-conductor socket to socket cable to connect the ST-LINK port to the ST-LINK socket on my STM32F4Discovery board, and then connect the LPC-Link socket via an appropriate cable to an LPCxpresso board.  I have used this method to program and debug my LPCxpresso board for LPC1343 with CooCox IDE.

Multiple JTAG adaptions are possible
  • ST-LINK to LPC-Link
  • ST-LINK to 10-pin
  • ST-LINK to 20-pin
  • LPC-Link to 10-pin
  • LPC-Link to 20-pin
  • 10-pin to 20-pin
  • 10-pin (1.27mm) to 10-pin (2.54mm) in future revision

Boards I was able to communicate with either with OpenOCD, ST-LINK, or CoLinkEx using the JTAG adapter(s) board include:

Caveats and Warnings.  Note that I did not do extensive testing.  I am not sure the RESET and RTCK lines are working.  Some boards I could only connect to using SWD instead of JTAG.  Driver installation and basic use of OpenOCD is not described in this post, so see Getting Started with OpenOCD.

Inspiration and References.  Most of the JTAG circuit is gleaned from multiple FTDI specifications regarding the FT2232H, Mini Module, and related MPSSE Basics Application Note AN_135.  And the circuit is very similar to the FLOSS-JTAG one shown here.


Under belly of the JTAG board
 

JTAG Schematic

Thursday, April 4, 2013

Hello World tutorial for STM32 Discovery boards using CooCox CoIDE and GCC ARM

ST Microelectronics has been supporting their Discovery line of ARM demonstration and development boards for a while now.  I was first introduced to the STM32 Value line discovery (STM32-F1), getting a free one at one of the embedded development conferences in San Jose or Santa Clara.  I had tucked it away for safe keeping (or hoarding), and over the years also acquired a STM32-F0, STM32-F4, and STM32-F3.  These are low cost (most $8-$11, with one at $15 US), and some of the more advanced boards include an accelerometer, gyroscope, or compass and multiple LEDs.

I recently stumbled across the CooCox CoIDE for working with the Simplecortex (I'll blog more about NXP chips and boards another time), and while starting to play with it, discovered that this IDE also supported the STM32 boards.  Which is great, as I had just started reading Discovering the STM32 Microcontroller by Geoffrey Brown of Indiana University and wanted to try my hand at developing for ARM in C.

As stated in their tagline, CooCox is a set of "Free and Open ARM Cortex MCU Development Tools."  CoIDE is an Eclipse based integrated development enviroment supporting the standard GCC ARM tool set: compiler, assembler, linker, and debugger.  The STM32 discovery boards include an embedded ST-LINK or ST-LINK/V2 which is supported by CoIDE for flashing and debugging.  The real value add by CoIDE is point and click choice of MCU library modules for various peripherals, with hypertext library references and examples.  CooCox supports a variety of ARM Cortex MCUs from various manufacturers.  ST is just one of the manufacturers.

Here I will show you how to install CoIDE and essential dependencies to develop a simple Hello World program for the STM32 Value line discovery board.  The steps are very similar for the other boards (except STM32-F3 is not directly supported at this time).  The program will display debug output from printf() through the ST-LINK to the IDE's console window.  This is the essential first program to see results from a program running on an embedded board.  And it's not just a blinking LED, though we'll do that too.

One time installation and configuration.

1. Download ARM GCC
2. Download CoIDE
3. Download STM32 ST-LINK Utility
3. Install ARM GCC
4. Install CoIDE
5. Configure CoIDE to point to ARM GCC
6. Install STM32 ST-LINK Utility
7. Plug in USB cable from PC to ST-LINK on discovery board


Creating your first project.

1. Click Create Project, name it hello
2. When prompted Chip or Board, choose Chip
3. Choose ST, and STM32F100RB.  Click Finish
4. In the Repository window, click on Semihosting and GPIO.  Required dependencies will autoselect
5. Double click on main.c in the Project window, and modify to contain

#include <stdio.h>
#include <stm32f10x_gpio.h>
#include <stm32f10x_rcc.h>


int main(void)
{
 GPIO_InitTypeDef gpio;
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);


 GPIO_StructInit(&gpio);
 gpio.GPIO_Pin = GPIO_Pin_9; // Green LED
 gpio.GPIO_Mode = GPIO_Mode_Out_PP;
 gpio.GPIO_Speed = GPIO_Speed_2MHz;
 GPIO_Init(GPIOC, &gpio);


 gpio.GPIO_Pin = GPIO_Pin_8; // Blue LED
 GPIO_Init(GPIOC, &gpio);


 printf("Hello World!\r\n");

 while(1)
 {
  static int count=0;
  static int i;
  static int led_state=0;


  for (i=0; i<1000000; ++i);
  GPIO_WriteBit(GPIOC, GPIO_Pin_9, led_state ? Bit_SET : Bit_RESET);
     led_state = !led_state;
     GPIO_WriteBit(GPIOC, GPIO_Pin_8, led_state ? Bit_SET : Bit_RESET);


  printf("%d\r\n", ++count);
 }
}


6. Open printf.c from the Project window
7. Add #include <semihosting.h> after the other includes.
8. In the PrintChar method, add the following line before the closing brace



SH_SendChar(c);
 
9. Right click on hello in tree of Project Window and choose Configuration
10. Navigate to Debugger tab, and verify ST-Link is chosen
11. Click on Semihosting Enable
12. Choose Project + Build, should be successful
13. Choose Debug + Debug, will deploy to board and stop at top of main
14. Choose Debug + Run to continue the program, should see output in Semihosting window