Recent site activity

Olimex STM32-H103 JTAG

posted 1 Nov 2009 08:11 by Chris Shucksmith   [ updated 17 Jul 2011 11:06 ]
With two weeks tinkering I've managed to get some C-code running on the microprocessor. This involved building a cross-compiler and tool-chain for ARM ELF binary format, compiling sample code, setting up non-root access to the JTAG interface dongle and configuring a debugger, OpenOCD, for programming. In detail:

  • Add username to plugdev group
    gpasswd --add chris plugdev

  • Modify udev rules to chown the Olimex USB device over to plugdev group (on insert)
    • based on sample from http://forum.sparkfun.com/viewtopic.php?t=10548
    • using USB identifiers dVendor=15ba, idProduct=0004
      [chris@chris-desktop ~]$ cat /etc/udev/rules.d/45-ft2232.rules
      BUS!="usb", ACTION!="add", SUBSYSTEM!=="usb_device", GOTO="kcontrol_rules_end"
      SYSFS{idProduct}=="0004", SYSFS{idVendor}=="15ba", MODE="664", GROUP="plugdev"
      LABEL="kcontrol_rules_end"

  • Rebuild binutils, gcc and GDB for the ARM architecture, set to cortex-m3 cpu type
    • downlod F11 spec files + source files for the avr-binutils and avr-gcc
    • change "target" declaration to "arm-elf"
    • rpmbuild the spec files to generate RPM package
      rpmbuild -ba SPECS/arm-elf-binutils.spec

    • Install the RPM for binutils
      sudo rpm --install RPMS/i586/arm-elf-binutils-2.18-4.fc11.i586.rpm

    • Compile & install gcc (C-compiler)
      rpmbuild -ba SPECS/arm-elf-gcc.spec
      rpm --install RPMS/i586/arm-elf-gcc-4.3.3-2.fc11.i586.rpm 

    • Compile & install gdb (debugger)
      rpmbuild -ba SPECS/arm-elf-gdb.spec 
      rpm --install RPMS/i586/arm-elf-gdb-6.8-9.fc11.i586.rpm
  • Grab sample code from the Olimex web page and unpack it
    http://www.olimex.com/dev/stm32-h103.html

  • Bring the make file up to scratch to correctly invoke our new gcc. The linker script supplied by Olimex worked OK for me.
[chris@chris-desktop stm-h103]$ cat makefile
NAME   = demoh103_blink_rom

CC      = arm-elf-gcc
LD      = arm-elf-ld -v
AR      = arm-elf-ar
AS      = arm-elf-as
CP      = arm-elf-objcopy
OD     = arm-elf-objdump
 
CFLAGS  =  -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb
AFLAGS  = -ahls -mapcs-32 -o crt.o
LFLAGS  = -Tstm_h103_blink_rom.cmd -nostartfiles
CPFLAGS = -Obinary
ODFLAGS    = -S

all: test

clean:
    -rm a.lst main.lst main.o main.out main.hex main.map stm32f10x_rcc.o stm32f10x_gpio.o

test: main.out
    $(CP) $(CPFLAGS) main.out main.bin
    $(OD) $(ODFLAGS) main.out > main.list

main.out: main.o stm32f10x_rcc.o stm32f10x_gpio.o stm_h103_blink_rom.cmd
    $(LD) $(LFLAGS) -o main.out  main.o stm32f10x_rcc.o stm32f10x_gpio.o

crt.o: crt.s
    $(AS) $(AFLAGS) crt.s > crt.lst

stm32f10x_rcc.o: stm32f10x_rcc.c
    $(CC) $(CFLAGS) stm32f10x_rcc.c
     
stm32f10x_gpio.o: stm32f10x_gpio.c
    $(CC) $(CFLAGS) stm32f10x_gpio.c
     
main.o: main.c
    $(CC) $(CFLAGS) main.c

  • Build the code. Check the bin-file is reasonably sized with only one section
[chris@chris-desktop stm-h103]$ make
arm-elf-gcc -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb  main.c
arm-elf-gcc -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb  stm32f10x_rcc.c
arm-elf-gcc -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb  stm32f10x_gpio.c
arm-elf-ld -v -Tstm_h103_blink_rom.cmd -nostartfiles -o main.out  main.o stm32f10x_rcc.o stm32f10x_gpio.o
GNU ld (GNU Binutils) 2.18 + coff-avr-patch (20050630)
arm-elf-objcopy -Obinary main.out main.bin
arm-elf-objdump -S main.out > main.list
[chris@chris-desktop stm-h103]$ arm-elf-size main.out
   text       data        bss        dec        hex    filename
   3996          0         12       4008        fa8    main.out

  • Launch openocd server using the board and interface files
    • Default configurations shipped with Fedora's OpenOCD package worked fine for me
    • Note: the board configuration includes the target configuration for you
[chris@chris-desktop stm-h103]$ openocd --file /usr/share/openocd/scripts/board/olimex_stm32_h103.cfg \
    --file /usr/share/openocd/scripts/interface/olimex-jtag-tiny.cfg


[chris@chris-desktop ~]$ telnet localhost 4444
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset init
JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
JTAG Tap/device matched
JTAG tap: stm32.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
JTAG Tap/device matched
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe
> flash erase_sector 0 0 127
erased sectors 0 through 127 on flash bank 0 in 0.033968s
> flash write_bank 0 main.bin 0
wrote  3996 byte from file main.bin to flash bank 0 at offset 0x00000000 in 0.260933s (14.955348 kb/s)
> reset init
JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x3)
JTAG Tap/device matched
JTAG tap: stm32.bs tap/device found: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)
JTAG Tap/device matched
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000010
> resume
>

And lo, behold LED flasher. In the old days I could have built this using a 555 chip and got change from a quid...



Č
ċ
ď
arm-elf-binutils-2.18-4.fc11.i586.rpm
(3968k)
Chris Shucksmith,
22 Feb 2010 14:43
ċ
ď
arm-elf-binutils.spec
(4k)
Chris Shucksmith,
22 Feb 2010 14:41
ċ
ď
arm-elf-gcc-4.3.3-2.fc11.i586.rpm
(3414k)
Chris Shucksmith,
22 Feb 2010 14:43
ċ
ď
arm-elf-gcc.spec
(5k)
Chris Shucksmith,
22 Feb 2010 14:41
ċ
ď
arm-elf-gdb-6.8-9.fc11.i586.rpm
(2991k)
Chris Shucksmith,
22 Feb 2010 14:43
ċ
ď
arm-elf-gdb.spec
(3k)
Chris Shucksmith,
22 Feb 2010 14:41