OpenOCD, STM32-P103 and ARM USB TINY problems

lpsmith,

I am asking questions to try and get to the cause of the issue.

We also can only follow the manufacturers info etc on programming/debugging - this is not always correct.

Remember this is a openocd source project, all our own free time. We try and make it as bug free as possible.

It is hard however to take into account all systems, it works on all the systems we test on.

Personally i have been using openocd with the stm32 for over a year, in that time i have found it very reliable.

Regards

Spen

Spen,

Does OpenOCD svn r623 support Cortex-M3?

Regards,

Peter

ntfreak

Thank you very much indeed! That worked, for both my boards. I still get a segfault when openocd tries to do a reset, but I will explore that further tomorrow.

Best regards,

Peter

gregson:
Spen,

Does OpenOCD svn r623 support Cortex-M3?

Regards,

Peter

sure does, currently svn is 627

Cheers

Spen

Could someone please tell me where to get a copy of the binary file for the Olimex demo software for the STM32F103-STK board? I trashed mine in the troubles above and would like to re-install it.

Thanks in advance,

Peter

I am pleased to report that I can download code to flash on both of my boards. Thank you, all, for your help. ntfreak, your trick worked. I still get the segfault when the board is reset, but the code is loaded so I just push the reset button.

Best regards,

Peter

Hi there, I don’t understand what tricks you’ve made to make it work. I have almost the same problem, with this SWJ-DP STICKY ERROR.

I explain :

I have the STM32-P103 board

I use the jtagkey (tiny one) from Amontec

I have downloaded the openocd here :

http://www.siwawi.arubi.uni-kl.de/avr_p … index.html

I’ve mixed what I’ve found in several sites (thanks gregson for your script)

here is the script I use

#daemon configuration
telnet_port 4444
gdb_port 3333

# we use the ft2232 interface
interface ft2232
ft2232_device_desc "Amontec JTAGkey A"
ft2232_layout jtagkey
ft2232_vid_pid 0x0403 0xCFF8
# these settings come from openocd homepage.

#how fast should we talk to the jtag interface
#the numeb is a divisor for the speed -> 0 is the fastest possible
jtag_speed 40

jtag_nsrst_delay 200
jtag_ntrst_delay 200

#use combined on interfaces or targets that can't set TRST/SRST separately
#reset_config srst_only srst_pulls_trst
reset_config srst_only

#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
jtag_device 4 0x1 0xf 0xe
jtag_device 5 0x1 0x1 0x1e

#target configuration
#actually, we attatch to the <B5>C
#daemon_startup attach
#for flashing
daemon_startup reset



#target <type> <startup mode>
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>
#target arm7tdmi little run_and_halt 0 arm7tdmi-r4
#flash test
target cortex_m3 little reset_halt 0
#run_and_halt_time 0 30

working_area 0 0x20000000 0x5000 nobackup

#flash configuration
#flash bank <driver> <base> <size> <chip_width> <bus_width>
#flash bank at91sam7 0 0 0 0 <target#> (base, size, chip and bus_width are read from the target)
flash bank stm32x 0x08000000 0x00020000 0 0 0

I’ve opened a command line window and entered :

openocd_local -d 3 -l logfile.txt -f Amontec.cfg

In an other window :

telnet localhost 4444
...
Open On-Chip Debugger
> load_image main.bin 0x8000000
SWJ-DP STICKY ERROR
dcb_dhcsr 0x3000f, nvic_shcsr 0x20000, nvic_cfsr 0x0, nvic_bfar 0xe000edf8
SWJ-DP STICKY ERROR
dcb_dhcsr 0x3000f, nvic_shcsr 0x20000, nvic_cfsr 0x0, nvic_bfar 0xe000edf8
Block write error address 0x8000000, wcount 0x3f5
>
> flash info 0
device id = 0x20016410
flash size = 128kbytes
#0: stm32x at 0x08000000, size 0x00020000, buswidth 0, chipwidth 0
        #0: 0x00000000 (0x400 1kB) protected
        #1: 0x00000400 (0x400 1kB) protected
        #2: 0x00000800 (0x400 1kB) protected
        #3: 0x00000c00 (0x400 1kB) protected
        #4: 0x00001000 (0x400 1kB) protected
        #5: 0x00001400 (0x400 1kB) protected
  .
  .
  .
        #125: 0x0001f400 (0x400 1kB) protected
        #126: 0x0001f800 (0x400 1kB) protected
        #127: 0x0001fc00 (0x400 1kB) protected
stm32x flash driver info
>

The main.bin is the blinking example from olimex

Ok, I’ve done what’s written in this post viewtopic.php?t=10548

and manage to program my board.

Now I have to write a good script for openocd to program the target in one command.

Duck,

A few comments:

  1. you should really use reset_config trst_and_srst, it provides better control.

  2. jtag_speed 10 should work ok

  3. flash bank stm32x 0 0 0 0 0 should work as the flash size etc is probed from the target.

I am not suprised you are getting a error using load_image main.bin 0x8000000 - this command is normally for writing to RAM.

flash write_image for example should be used.

The openocd from that link is quite old (svn rev 555). If possible get the latest from svn and build, especially from cortex_m3 support.

Cheers

Spen

Ok, thanks I will check that and post the results for others. In the meanwhile, I’ve made some changes that work, but I want to post the entire procedure when I make it simple.

OK what’s work for me :

download the openocd brand new files here:

http://www.yagarto.de/download/openocd/ … 080419.exe

Save this script (for Amontec Jtagkey-tiny) as myScript.cfg

telnet_port 4444
gdb_port 3333

interface ft2232
ft2232_device_desc "Amontec JTAGkey A"
ft2232_layout jtagkey
ft2232_vid_pid 0x0403 0xCFF8

jtag_speed 10

jtag_nsrst_delay 200
jtag_ntrst_delay 200

reset_config trst_and_srst

jtag_device 4 0x1 0xf 0xe
jtag_device 5 0x1 0x1 0x1e

daemon_startup reset

target cortex_m3 little run_and_init 0
#run_and_halt_time 0 30

working_area 0 0x20000000 0x4000 nobackup

flash bank stm32x 0 0 0 0 0 

target_script 0 reset my_scr.script

the file my_scr.script should be

halt
wait_halt
#poll
flash probe 0
stm32x mass_erase 0
flash write_image main.bin 0x8000000
halt
reset run 
shutdown

create a new text file, save it as program.cmd (or whatever you want)

paste this :

openocd-ftd2xx -d3 -f Amontec.cfg 
pause

now double click on this cmd file, and that’s it…

FWIW, I have a similar problem to gregson but I found a different solution. I was using this programming script

halt
stm32 mass_erase 0
flash write_image build/main.elf elf
reset run
exit

getting this error in telnet

>  flash write_image build/main.elf elf 
flash writing failed with error code: 0xfffffc7a
error writing to flash at address 0x08000000 at offset 0x00000000 (-902)

and this error in openocd

Error:   cortex_swjdp.c:222 swjdp_transaction_endcheck(): SWJ-DP STICKY ERROR
Error:   cortex_swjdp.c:236 swjdp_transaction_endcheck(): dcb_dhcsr 0x30003, nvic_shcsr 0x20000, nvic_cfsr 0x1001, nvic_bfar 0xe000edf8
Error:   gdb_server.c:1024 gdb_error(): unexpected error -107

That problem would occur exactly every other time when interrupts were enabled in the program. I determined that the interrupts were interfering with the programmer. the flash_erase operation would always succeed, but the flash_write operation would fail if interrupts were currently enabled. The solution was to reset the processor before programming it, which will always disable the interrupts. My new programming script, which works 100%, is:

halt
stm32 mass_erase 0
flash write_image build/main.elf elf
reset run
exit

I’m using openocd r737

Oops, I didn’t post the new script correctly. Here it is:

reset halt
stm32 mass_erase 0
flash write_image build/main.elf elf
reset run
exit

BTW, this is using a cortex-m3 processor, the STM32F101C6T6.