openOCD 配置和使用 (英文)

来源:互联网 发布:xp找不到网络路径 编辑:程序博客网 时间:2024/05/22 02:23

Openocd Usage and its Debug

a)      Hardware connection between STlink and STM32

i.        For STlink/V2, there are 10 pins, SWCLK, SWDIO(SWIO), RST, SWIM. Ther other are 3.3v or 5v or GND

ii.      For STM32, the pins used for simulating includeJTCK, JTMS, JNRST, NRST, JTDI, JTDO.

iii.     Usually, we just use the JTCK, JTMS(JTDIO) ,3.3v, GND to connect to the STLink/V2 and JTAG. JTCK to SWCLK, JTMS (JTDIO) toSWD (SWDIO).

b)      Make usb rule file

i.        To let the Ubuntu to recognize the STlink,RS232, JTAG device and make them usable, we need to add a .rules file to /etc/udev/rules.d/this directory. We can make a file called OLIMEX_ARM-USB-OCD-H.rules orstlink-v2.rules.

The contentshould be like this:

For JTAG:

SUBSYSTEMS=="usb",ATTRS{idVendor}=="15ba",ATTRS{idProduct}=="002b",MODE="0666"

For stlink-v2:

SUBSYSTEMS=="usb",ATTRS{idVendor}=="0483",ATTRS{idProduct}=="3748",MODE="0666"

To checkwhether Ubuntu can recognize those devices:

Commands:     lsusb,  ro dmesg

 

c)      Make openocd.cfg configuration file

        i.        After the machine recognize the device, justcreate a file which is to configure the openocd (open on- Chip debugger) tolink to the device and find the matching scripts to get the information fromthe simulator and control the simulator to control the STM32 chip.

       ii.      Create openocd.cfg file

      This file should contain four sections: daemon ,interface, board, target.

      1)      Daemon(port) section should be like (determinewhich port you will use to make remote connection and use the terminal tocontrol openocd to flash and debug the STM32):

#daemon configuration

telnet_port4444

gdb_port 3333

     2)     Interface Section:

# reset_configparameter (see OpenOCD manual):

# none-->srst and trst of MCU not connected to JTAG device

#srst_only--> only srst of MCU connected to JTAG device

#trst_only--> only trst of MCU connected to JTAG device

#srst_and_trst--> srst and trst of MCU connected to JTAG device

# defaultsetting: "reset_config none" will produce a single reset via    #SYSRESETREQ (JTAG commands) at reset pin ofMCU

reset_confignone


     3)     target Section(used to search the boardinfo script from openocd script directory /usr/local/share/openocd/):

#targetconfiguration##########################################

source [findtarget/stm32f1x.cfg]

 

    4). Boardsection(determine the worksize and RAM of the board)

#boardconfiguration###########################################

# AdjustWork-area size (RAM size) according to MCU in use:

# STM32F103RB--> 20KB

setWORKAREASIZE 0x5000

# STM32F103RE--> 64KB

#setWORKAREASIZE 0x10000       


if you don’t want to make this file, you can usecommand:

openocd-f /usr/local/share/openocd/script/interface/stlink-v2.cfg -f/usr/local/share/openocd/script/target/stm32f1x.cfg to search the settings


d)      Check Simulator device and openOCD connect to device

i.        Use command: openocd -fopenocd.cfg to open openOCD to link to the stlink. Then the terminalwill show the version and type of the simulator. If it doesn’t work, you maybe dosomething wrong when connecting the stlink and the STM32 board, or use thewrong settings from the openocd scripts which doesn’t match the version of yousimulator.


e)      Telnet communicate with openOCD

i.        After the openOCD connects to the simulator,openOCD has built a link to the simulator and the board and also create a portfor you to connect to it. It should be localhost 4444 .  If you use gdb to connect to the opencod,just use localhost 3333

ii.      Type the command: telnetlocalhost 4444

iii.     If you use gdb to debug the program, first type:  gdb program_name.

After entering the gdb, type: target remote localhost:3333


f)       Connect GDB to openOCD

i.        As what I said just now, if you wan to connect the openocd to the debug the program, just type: gdb programName   and then type: target remotelocalhost:3333  to connect to the openocd.

ii.      When you use the gdb to check the registers andcontrol the openocd to write and read, you need to add ‘monitor’ before thecommand from openocd

For example:to halt the stm32,  use:  monitor reset halt. (but in telnet you justneed to type: reset halt).


g)      Useful commands

1. flash probe 0: probe the stm32 and return its information of size of flash and its id.

2.flash write_bank 0 main.bin 0 : write the main.bin tothe flash of the bank 0 which is your board

3. flashwrite_image erase main.bin 0x08000000 : auto erase before flashing, flash themain.bin file starting from the address 0x08000000

4.Stm32f1x mass_erase 0 : erase flash of the bank 0

5.Stm32f1x options_read 0: read state andinformation  of bank 0

6.Regs register_name : show the data in the register

原创粉丝点击