Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenOCD fails to connect with cortex processor

I'm trying to flash a cortex m0 based SoC from a Raspberry Pi 3 Compute Module GPIOs but it keeps failing with the same error.

Error: Could not initialize the debug port

I'm following this https://learn.adafruit.com/programming-microcontrollers-using-openocd-on-raspberry-pi?view=all and this tutorials https://movr0.com/2016/09/02/use-raspberry-pi-23-as-a-jtagswd-adapter/. Compilation and install happens without issues.

The cortex m0 SoC is a Nordic Semiconductor nRF51822 bluetooth chip packaged in ISP1302 module.

The module GND and 3.3V are wired directly to the Compute module dev-kitand SWDCLK and SWDIO are wired on the GPIO 25, 24 as per tutorials. There's no connection for SRST or TRST.

The configuration file is as follows:

source [find interface/raspberrypi2-native.cfg]
bcm2835gpio_swd_nums 25 24
transport select swd

# target
source [find target/nrf51.cfg]

init
targets

(and I removed bcm2835gpio_srst_num 18 from the raspberrypi2-native.cfg)

executing with sudo openocd -f config.cfg

The raspberry Pi CM3 is running with the option core_freq=250 on /boot/config.txt and I need this option to reliably access UART1. I thought it could be something related to the clock, but not sure how to change/fix if it is.

I've tried several combinations of reset_config nothing changed the error. The full initialization stack is as follows:

Open On-Chip Debugger 0.10.0+dev-00111-gca9dcc8 (2017-04-24-15:30)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
BCM2835 GPIO nums: swclk = 25, swdio = 24
cortex_m reset_config sysresetreq
adapter speed: 1000 kHz
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : SWD only mode enabled (specify tck, tms, tdi and tdo gpios to add JTAG mode)
Info : clock speed 1001 kHz
Info : SWD DPIDR 0x00150634
Error: Could not initialize the debug port
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* nrf51.cpu          cortex_m   little nrf51.cpu          unknown

No matter what I tried I always get this "Error: Could not initialize the debug port".

Interesting enough, using a ST-Link/V2 adapter connected to the PI USB and modifying the interface on the configuration it works without issues.

Any suggestions? What am I doing wrong? Is there some initialization on the GPIO needed?

edit:

I've noticed someone voted to close the question as "unclear what's asking".

I'm asking: How can I connected the Raspberry Pi to a nRF51 SoC using its GPIO? Refer above everything I tried.

like image 548
Budius Avatar asked Apr 25 '17 13:04

Budius


People also ask

How do I run OpenOCD?

To run OpenOCD, navigate to openocd-0.5. 0/tcl in the command console and run OpenOCD as above. You can also create a new folder anywhere on your system, and copy openocd.exe and the contents of openocd-0.5. 0/tcl to the new folder.

What does OpenOCD stand for?

OpenOCD stands for Open On-Chip Debugger. It is an open-source software that supports debugging a wide variety of chips, devices and boards using a range of supported debug interfaces.

How to debug with OpenOCD?

To enable debug output (when reporting problems or working on OpenOCD itself), use the -d command line switch.


2 Answers

Not exactly the same configuration, but searching for pi3 on http://forum.doozan.com/read.php?3,21789,21927 reveals raspberry123-native.cfg, in which we find a change to the clockspeed:

# Please set the right peripheral_base address and Transition delay depending on which Raspi (1,2 or 3) you use.

interface bcm2835gpio

# Raspi2 and Raspi3 peripheral_base address

bcm2835gpio_peripheral_base 0x3F000000

# Raspi1 peripheral_base address
# bcm2835gpio_peripheral_base 0x20000000

# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET
# These depend on system clock, calibrated for stock 700MHz
# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET

# Raspi3 BCM2837 (1200Mhz):
bcm2835gpio_speed_coeffs 194938 48

# Raspi2 BCM2836 (900Mhz):
# bcm2835gpio_speed_coeffs 146203 36

# Raspi1 BCM2835: (700Mhz)
# bcm2835gpio_speed_coeffs 113714 28

like image 90
user1747036 Avatar answered Sep 21 '22 18:09

user1747036


    • Problem: The probe is polling for an event which never gets set.

    • Solution: Might try scrapping the module and install another one which does work ok.


    • Check which PI version you're using, this is a tutorial for programming microcontrollers using openocd on raspberry pi.

    • Note: that you would just use the string raspberrypi2-native instead of raspberrypi-native in the following cfg file. This was the openocd.cfg file I used:


source [find interface/raspberrypi-native.cfg]
transport select swd

bcm2835gpio_swd_nums 25 24
bcm2835gpio_srst_num 18

set CHIPNAME efm32
source [find target/efm32.cfg]

reset_config srst_nogate

adapter_nsrst_delay 100
adapter_nsrst_assert_width 100

init
targets
reset
reset halt
poll
flash probe 0
flash write_image erase emptyProject.hex
sleep 1
reset run
shutdown

  • then run the command sudo openocd in the same directory as openocd.cfg. After that, my uC was programmed and LEDs were blinking.

  • This was the wiring connection for the Raspberry Pi GPIO Header:


3.3V  - 3.3V   - pin 1
SWCLK - GPIO25 - pin 22
SWDIO - GPIO24 - pin 18
SRST  - GPIO18 - pin 12
GND   - GND    - pin 14

  • in the directory containing your *.afx file (should be an output file in the same location as your build *.hex/*.bin), issue the command arm-none-eabi-gdb -ex "target remote localhost:3333" empty_project.axf -tui

  • This should bring up a terminal based source code viewer and gdb console window.

  • break empty_project.c:main.

  • continue
  • step...

  1. As for a Tutorial for installing OpenOCD:

    • Make sure you have Raspberian installed on your PI.
    • Install the latest version of OpenOCD, by following this tutorial.
    • But specifically for the Pi you can just do the following:
      1. sudo apt-get update
      2. sudo apt-get install libtool libusb-dev libusb-1.0 autoconf automake texinfo
    • And then:
      1. git clone git://git.code.sf.net/p/openocd/code openocd-code
      2. cd openocd-code/
      3. ./bootstrap
      4. ./configure
    • This should spit out a bunch of stuff and then if everything worked you should see this at the end:

    • OpenOCD log

    • Make sure support for the programmer you are using is enabled, and then type make. Once that finishes, type sudo make install.

    • Now OpenOCD should be installed and ready to go!
  2. Running OpenOCD:

    • Now you can run OpenOCD. For example, if you were using an F4 discovery board, you could so something like this:
    • sudo openocd -f board/stm32f4discovery.cfg
    • If it worked, you should see something like:
    • Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
    • Which means your programmer is ready to go!

Note: I'm no expert, so I'm sure there's plenty left for me to figure out. On the other hand, I might do some digging to search for more. if this doesn't work, then I would recommend you to look into the chip itself or report the bug to the creators of the nRF51 SoC itself.

like image 35
King Reload Avatar answered Sep 20 '22 18:09

King Reload