Showing posts with label OpenOCD. Show all posts
Showing posts with label OpenOCD. Show all posts

Monday, January 1, 2018

Sino:bit Test drive & attempt to single-step debug with OpenOCD and GDB

Sino:bit - Arduino, OpenOCD and GDB?



A little while back, I responded to an offer to get a free Sino:bit from the nice folks at Elecrow. Well, it was not completely free; I paid $4 for shipping from China, as it was not really practical for me to pick it up. ;)

In case you've not heard - this is the Chinese version of the BBC Micro:bit - or more precisely, based on the Calliope mini, which is based on the Micro:bit. Me... I'm in favor of pretty much any technology that may help inspire the next generation of programmers.

Although there are a variety of ways to program this device, I followed along with the Adafruit instructions to use the Arduino IDE (and/or the VisualMicro add-in for Visual Studio).

Initial programming was really quite easy. There was one little instruction missing from the Adafruit site. Hopefully they will notice my tweet and make the correction. In short, the Arduino HT1632 libraries need to be manually added. So if you see an error like this:


...then simply add the library:


I like to turn on verbose compiling and uploading:


When doing so, a successful upload will look like this:


In particular, I noticed that a forked version of Open OCD is used to upload the sketch. The first thing that comes to mind when mentioning OpenOCD, is of course GDB! So I thought I'd see if I could get some single-step debugging working without the need for a potentially expensive hardware debugger.

One line to notice during the verbose compile / upload is the last line of the compile. Note that a unique directory is created for the binaries. In my case: ~\arduino_build_91191

The full line from my Arduino IDE looked like this:

C:\Users\gojimmypi\AppData\Local\Arduino15\packages\sandeepmistry\tools\openocd\0.10.0-dev.nrf5/bin/openocd.exe -d2 -f interface/cmsis-dap.cfg -c ; -f target/nrf51.cfg -c program {{C:\Users\GOJIMM~1\AppData\Local\Temp\arduino_build_91191/sinobit.ino.hex}} verify reset; shutdown; 

In order to launch OpenOCD to simply listen, and not upload - minor modifications are needed. Remove everything after and including the "-c program":

C:\Users\gojimmypi\AppData\Local\Arduino15\packages\sandeepmistry\tools\openocd\0.10.0-dev.nrf5/bin/openocd.exe -d2 -f interface/cmsis-dap.cfg -c ; -f target/nrf51.cfg  

Upon launching this in a DOS window, the resulting output looks like this:


Note that OpenOCD will not exit. It is waiting and listening for a GDB connection.

In my case, I could not find a suitable Windows GDB executable. So I ventured into the land of WSL - specifically Ubuntu. (I also wrote a little blog on OpenOCD on WSL Ubuntu). Once a local Ubuntu is installed an operational, GDB can be added:

sudo apt-get install gdb
Note that in WSL Ubunto, there's no C:\ drive and the slashes all go in the opposite directions. I went to my specific directory created by the Arduino IDE:

cd /mnt/c/Users/gojimmypi/AppData/Local/Temp/arduino_build_91191


GDB is launched like this:
gdb -d ./ -d /mnt/c/Users/gojimmypi/AppData/Local/arduino15/packages/sandeepmistry/hardware/nRF5/0.4.0/cores/nRF5 -f sinobit.ino.elf

If all goes well, when GDB is running and accepting commands, if will look something like this in the WSL Ubuntu window:


Due to the oddities of Windows vs Linux, I first ran these commands:


# C:\ is found in /mnt/c
set substitute-path c:/ /mnt/c

# There was an odd case problem in Arduino15 vs arduino15
set substitute-path /mnt/c/Users/gojimmypi/AppData/Local/Arduino15/ /mnt/c/Users/gojimmypi/AppData/Local/arduino15/

# make really sure the current directory is used
directory ./


Then connect:
target remote localhost:3333
monitor reset init

The resulting GDB window in Ubuntu should look something like this:


The OpenOCD DOS window should have updated, and look something like this, showing the successful connection:


At this point, things are really exciting! Ready to debug? Sadly, no. Typing the GDB "step" command results in the dreaded message:

Cannot find bounds of current function

I also tried to use the VisualMicro add-in for Visual Studio, no joy there, either:


Although it certainly works to compile and upload code in "release" (no single-step debugging) mode:



@TheFlyingSephyr also suggested trying the Embedded Studio IDE with the Segger hardware debugger. Perhaps another blog for another day...

On a side note, it might me interesting to peek at the elf file:


sudo apt-get install binutils
readelf -a /mnt/c/Users/gojimmypi/AppData/Local/Temp/arduino_build_91191/sinobit.ino.elf


In the end, it seems that you simply can't get to there from here when attempting to debug a "soft device".  :| If you have any ideas, please leave a comment or send me a message at gmail.

UPDATE: I've had a few replies regarding other debugging options. In particular a tweet from Tomas indicating that perhaps Mbed tools might help. Indeed there's some interesting info that shows using arm-none-eabi-gdb and pyOCD. Although I was able to get that toolchain installed and working:


I was not able to actually get single-step debugging working (nor does the Mbed instruction page indicate this is even possible). Note the error:

(gdb) step
Warning:
Cannot insert hardware breakpoint 0.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

As show here:


Another more promising method (although considerably more complex and potentially expensive) - would be the hardware debugging method using JTAG. One of the key things needed here is of course is how to connect the debugger. Many thanks to Elecrow for the prompt reply on twitter for information on the Sino:bit JTAG pins:


What you cannot immediately see from the silkscreen is that those are pads and not through-holes. Another item on my wish list for version 2! (ok, let's make the proper wish: how about a actual header for JTAG connector!)

I'll create another blog page for the Sino:bit JTAG. My first attempt will be using my $2 Blue Pill STM32F103 board converted to a Black Magic Probe.

Overall the Sino:bit seems very cool, despite the problems with OpenOCD and GDB. It would be awesome if some sort of single-step debugging was possible - bit that certainly is not a showstopper. Most people, certainly not beginners - would never even attempt this type of debugging. Other changes I would make would be having a less intensely bright power LED, and making the 12 x 12 grid of LED's multi-color.


Resources, Inspiration, Credits, and Other Links:

Friday, April 28, 2017

OpenDPS with the DPS5015


Once again, I found an awesome project via twitter, this time from Johan Kanflo via this article from hackaday folks:

http://hackaday.com/2017/03/07/open-source-firmware-for-a-cheap-programmable-power-supply/

Or more directly, Johan's blog here:

https://johan.kanflo.com/hacking-the-dps5005/

After reading the details, I promptly ordered my own device, specifically this RD DPS5015 Buck Power Supply LCD color display step-down voltage converter on eBay. This DPS is similar, but different than the one Johan used, going on the assumption that it is similar: "Although this guide is written for the ‘5005 it should work for the entire DPS family but I only have 5005s to test with."

Upon inspection, I found that the onboard processor is an 32F100C8T6B with the LQFP48 pinout using the same pin configuration as on the DPS5005 in Johan's project:



http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f100-value-line/stm32f100c8.html

"Medium-density devices are STM32F100x8 and STM32F100xB microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes." [*1]

The [x] is a placeholder for only 1 character, not "all characters until the end, excluding the last B". The "B" in STM32F100CB means "128KB". This is not to be confused with STM32F100C8 or in the case of the DPS5015 - the STM32F100C8T6B - which are 64KB devices.

Don't confuse the 8 or B  with the trailing "B" on the end, That last B is an "Internal Code" having nothing to do with flash size.



I had OpenOCD for Windows installed via the sysprog VisualGDB app, so I used  that one:

cd C:\SysGCC\esp8266\esp8266-bsp\OpenOCD\share\openocd\scripts
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg

Compiling on Windows turned out to be a real pain, giving lame errors like this:

GENHDR include/libopencm3/stm32/l1/irq.json
GENHDR include/libopencm3/stm32/l4/irq.json
GENHDR include/libopencm3/vf6xx/irq.json
BUILD lib/stm32/f0
make[1]:  No rule to make target desig.o', needed byC:/workspace/libopencm3/lib/libopencm3_stm32f0.a'. Stop.
make:  [lib/stm32/f0] Error 2

https://github.com/libopencm3/libopencm3

@ChuckM over on the libopencm3 gitter:

https://gitter.im/libopencm3/

...suggested that I install the WSL

https://msdn.microsoft.com/en-us/commandline/wsl/install_guide

and so ok, once I have Ubuntu on Windows (am I the only one to find that crazy?!?! *Ubuntu* on *Windows* - wow!)... all the toolchain items need to be installed fresh. None of the Windows binaries will run. So I installed the items listed here:

https://developer.arm.com/open-source/gnu-toolchain/gnu-rm

specifically:

sudo apt-get update
sudo apt-get install binutils
sudo apt-get install gcc
sudo apt-get install gdb
sudo apt-get install make
sudo apt-get install build-essential

sudo apt-get install python
sudo apt-get install gawk

sudo apt-get install openocd


then download the GNU ARM Embedded Toolchain from:

https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads

sudo tar -xvjf gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2

(I put mine in c:\Downloads\arm\  aka  /mnt/c/download/arm in Ubuntu window)

All this ended up needing a path like this:

export PATH="/usr/bin/Python27:/mnt/c/download/arm/gcc-arm-none-eabi-6-2017-q1-update/bin:/usr/local/bin:/usr/bin:/bin"

I ended up hosting the OpenOCD from MINGW64 bash prompt, but programming via the Ubuntu bash prompt (this is NOT a good idea). The problem is with the apparent path. When doing a "make flash" - I kept getting a "couldn't open opendps.elf" error (yet the file was there).

Doing a "pwd" from the OpenOCD telnet session revealed all!

 C:/workspace/opendps/openocd/scripts

This is despite the fact that MINGW64 sees the path as:

/c/workspace/opendps/openocd/scripts

and the Ubuntu Bash sees it as:

/mnt/c/workspace/ ...

the libopencm3.rules.mk file had this simple command for "make flash":

program $(*).elf verify reset exit
so I used a manual command in the OpenOCD telnet session:

program c:/workspace/opendps/opendps/opendps.elf verify reset

and voila! a newly programmed  DPS5015!



Other stuff:

I found a couple of nice cases on Aliexpress: this console-style and this this shelf unit style.

There's also this interesting hack that uses an Arduino to control the unit by emulating the button presses: http://www.instructables.com/id/Power-Supply-Automation-DPS5015-DP50V5A-Controlled/

The Hangzhou Ruideng Technologies Co., Ltd store can be found here:

https://rdtech.aliexpress.com/store/923042

There's also this video:



Next step: follow Johan's instructions for using ESP8266 for WiFicontrol....


*1 - page 6 of PM0063 Programming manual STM32F100xx value line Flash programming

Monday, March 20, 2017

More on Segger J-Link and VisualGDB.

In my previous post, I explained the problem of J-Link JTAG drivers being changed by OpenOCD in VisualGDB, and my difficulty in putting back the proper drivers for use by Segger utilities.

Since posting this information to twitter and sysprogs forums, I've learned some interesting (and cool) things:

1) The clever folks at Sysprogs have their own "zadig-like" USB driver tool (strategically called USBDriverTool), that unlike zadig, has a "put back the original drivers" feature:



And can be downloaded (free!) here:

http://visualgdb.com/UsbDriverTool/

2) Additionally - the kind support folks at Segger responded to my email and pointed out that VisualGDB also supports talking to the Segger GDB server directly (instead of using OpenOCD). There's even an excellent example:

https://visualgdb.com/tutorials/arm/stm32/

Note in particular that instead of picking the J-Link device from the OpenOCD Debug method drop-down list, that there's a "J-Link JTAG" debug method also listed!



3) The Segger folks also have an explanation on the J-Link showing up as a BULK device in Windows. This is not a problem I had, but I am including this as relevant:

https://wiki.segger.com/J-Link_shown_as_generic_BULK_device_in_Windows

The screen snips there appear to be from an earlier version of Windows. Additionally, as noted in my proir post - simply selecting "Update Driver" would result in Windows saying that the drivers are already the current ones (even though it does not work). So you may need to delete the drivers before attempting the update when seeing this "BULK" driver issue.








Saturday, March 18, 2017

Gizmo Compatibility


I'll be keeping track of my gizmo compatibility here.

See also: https://github.com/gojimmypi/Gizmos

  Atmel ICE Bus Blaster Bus Pirate Olimex
ARM-USB-OCD-H
Segger
J-Link EDU
ST
ST-Link V2
USB-ASP 2.0 (red)
Arduino Uno - - - (no jtag) (no jtag) (no jtag) -
Arduino Due - - - (no jtag) (no jtag) (no jtag)  -
"Blue Pill"
STM32F103C8T6
             
ESP32 - - - - - no -
ESP8266 - - - - - - -
STM32 Smart V2
STM32F103
- - - - - yes -
Wemos ESP8266 - - - - - - -

Friday, March 17, 2017

JTAG Debugging for ESP32

Notes and information on JTAG Debugging the ESP32 WROOM-32 (aka DevKitC, aka ESP32_Core_Board_V2)

I started off my day thinking I'd take my ESP32 for a JTAG test drive. Searching for pinouts I quickly realized there are known bad pinouts floating around. This was quite a surprise as the ESP32 has been out for well over a year. I wasted a ton of time on that. I'm posting my findings here.

As one might expect - the Adafruit pinout appears to be the most accurate one:


WROOM-32 ESP32 Pinout
 from: https://cdn-shop.adafruit.com/product-files/3269/pinout_wroom_pinout.png

(many thanks to the folks at @esp32net for responding to my tweet and helping to identify correct pinout).

So if you happen to see the pinout on the sparkfun site, the information is WRONG (hopefully they will correct it soon):

https://www.sparkfun.com/news/2017 (bad pinout here!)

I modified a known-good pinout image to create this little reference to easily identity a bad ESP32 pinout. Hint: look for the locations of the GND pins.


Not all online pinouts are accurate. Here's where to find proper GND on ESP32


Really, the ultimate authority is of course the Espressif data sheet:


The PDF has this pinout overview, with the functions listed in a table on the following pages of the PDF:


See also the Espressif ESP-IDF docs on GitHub:

Ok, so once the correct pinout is found - there was a moment of "oh no, all the JTAG pins are not available on my CoreBoard V2 breakout (grumble, grumble I don't want to solder them on)". But no... all good. Who would think that SD2 = TCK?

I should mention that "ESP32_Core_Board_V2" is the same as "ESP32-DevKitC"

Resources available here:

In particular the PDF of schematic found in "ESP32 Development Board Reference Design":

found in the zip buried in this directory:
ESP32_Development_Board_Reference_Design\ESP32-DevKitC(ESP32_Core_Board_V2)\01_Schematic



I took a variety of sources and copy/pasted into a new pinout diagram for myself:



This one is the whole dev board and includes the 20 pin JTAG header, and my (arbitrary) color code:

ESP32-WROOM32 Pinout for ESP32 DevKitC / ESP32_Core_Board_V2



So these days, I've been really enjoying the JTAG capabilities of the Sysprogs VisualGDB:

They have a tutorial for ESP32 JTAG here:

Online tutorials are really awesome. I wonder how long it would have taken me to figure out Step 7 on my own! ha! (issue with Visual Studio/ESP-IDF framework and optimization default problem: who would have guessed?)

But that tutorial is using the Sparkfun ESP32 Thing, and mine is the Adafruit ESP32 Core Board V2, mentioned above.

Note: Although the Sparkfun apparently has an LED on GPIO5 - according to the schematics, the only LED on this board is the power LED - so don't expect it to blink - unless you are having really serious power problems! ;) But the sample code does indeed control GPIO5.

There's a recommended max of 6mA per pin on ESP32, with and absolute max of 12mA (read: you could still damage or shorten life). Many LED's run at 20mA and drop 1.8V. At (3.3V - 1.8) =  1.5; this means you should be using at least a (1.5/0.006) = 250 or 270 ohm resister for only 6mA. This may not result in a very brightly illuminated LED.

Here are a couple of hookup pics:


JTAG connections for ESP32



JTAG connections to Segger J-Link for ESP32


For information on VSCode debugging of ESP32, see this post.


Visual Studio 2017 source code for ESP32 JTAG Tutorial:

As a bonus, the tutorial is based on freeRTOS (I think all of the ESP32 code is using that). There's a pretty good UDemy FreeRTOS class that I'm taking:

Where to buy:

https://www.adafruit.com/product/3269


See also: http://esp32.net/  (this site is so comprehensive, I should say "start here first!")

Saturday, February 11, 2017

ESP8266 JTAG Debugging in Visual Studio with Segger J-Link and Sysprogs VisualGDB

My go-to development tool so far for the ESP8266 is still the Visual Micro add-in for Visual Studio. It is however a pure software environment, that supports breakpoints, but in a different way. It is also a little odd in the way that it uses the Arduino environment - yes, in Visual Studio. But it works. Reliably. Consistently.

With my newfound confidence in getting J-Tag debugging working with the Olimex ESP8266 I decided to revisit the first unit I bought - the Segger J-Link.

Let's first start by noticing the ESP8266 is nowhere to be found on the Segger supported device list page.  But it is a standard JTAG device that when adhering to standards, Should work, no? Besides, I always enjoy a challenge.

It is cool Segger has an EDU (Educational) version for only $60(USD).  A large discount over their base unit of $378, and massive discount compared to their $1000 J-Link Pro, (with of course different capabilities). Here's a screen snip from their web site comparing versions.  (or visit the Segger Model Overview page for a more detailed comparison).


I really like that the EDU version is available to any hobbyist, not just students - just provided that you are not using it to make a commercial product for profit. Segger explains more on the terms of the EDU version on their web site. One thing to note is that there's no support other than forum questions.

The Olimex ARM-USB-OCD-H/ unit is also available for about $60 from Mouser Electronics - but they do not appear to have other more advanced units with more features. The Segger with Ethernet could be a really cool device to have one day....

So yes, I'm over $120 into a couple of hardware debuggers that I intend to use with a $3 ESP8266.

I first tried connecting my Segger to a NodeMCU with no success. VisualGSB seemed happy with the JTAG interface at project setup / test time, but not when actually programming.

For an easy increment step - I'll revisit prgramminh the $9 Olimex ESP8266 EVB shown in the SysProgs VisualGDB ESP8266 Tutorial, using the same pins:




The first thing that was immediately obvious, is that I like the Olimex having its own 5V power supply for their EDP8266 EVB board. The Segger does not have a power supply connector, however on page 420 of the J-Link manual - "Pin 19 of the connector can be used to supply power to the target hardware. Supply voltage is 5V, max. current is 300mA. The output current is monitored and protected against overload and short-circuit. Power can be controlled via the J-Link commander". I could not find the specs on the ESP8266-EVB (surely it is less than 300mA, eh?) - but I used a separate power supply for the Olimex ESP8266-EVB.

For reference: Pages 418 and 419 of the Segger manual* shows this table of JTAG pin definitions:


* (I've requested permission from Segger to include this)

As noted in my previous blog, I am following the Syslogs VisualGDB ESP8266 OpenOCD tutorial.

Success! The Segger *does* work in the same way as the Olimex ARM-USB-OCD-H to debug the ESP8266 - but my target is still the Olimex ESP8266-EVB.  I really want to get debugging working on the NodeMCU as noted in this long and winding forum topic.










Saturday, February 4, 2017

ESP8266 JTAG Debugging in Visual Studio with Olimex ARM-USB-OCD-H and Sysprogs VisualGDB

To date, my go-to development environment - in Visual Studio 2015, is the VisualMicro add-in. There's no hardware debugging, but I've found it easy to use and reliable.

However, I've been interested on getting JTAG ESP8266 hardware debugging working in Visual Studio using the Sysprogs VisualGDB add-in - with mixed results.

I started with the Altera Bus Blaster than I already had on hand for programming Arduino. (hint: don't bother, it won't work: no reset control - see this discussion )

There are several tutorials, some not really up to date, but each with interesting information:

Developing projects for the ESP8266 WiFi chip with Visual Studio - August 24, 2015
Debugging ESP8266 firmware with Olimex ARM-USB-OCD-H - September 9, 2015
Debugging ESP8266 firmware with the UART GDB Stub - October 14, 2015
Debugging ESP8266 code with OpenOCD and Visual Studio - November 5, 2015

First, just figuring out which JTAG debugging hardware to buy: first I tried the Segger (kudos to them for having a generous discount for people not developing to sell a product). The Sysprogs folks then recommended that I follow the tutorial exactly, by using an Olimex instead. Another week into my 30 day trial and Mouser Electronics to the rescue with an ARM-USB-OCD-H debugger delivered. The price was about the same as the EDU version of the Segger. (approx. $60)

I had problems even finding the ESP8266 Xtensa-LX 106 elf for GDB stub (hint, it does not display in the directory shown in tutorial!) 

I also had problems with the interesting feature to debug existing project.

In the end I did get the debugging working.

I have this video on Creating Olimex VisualGDB Embedded Project for ESP8266 :


and this video on JTAG Debugging ESP8266 with Olimex and VisualGDB


 (they are separate as Windows 10 feature "Windows Key + G" video recording does not record pop-up dialog boxes)

Here are the pinouts of the Olimex ARM-USB-OCD-H 20-pin JTAG connector and the Olimex ESP8266-EVB ESP8266 10 pin header:


Here's also a partial Olimex schematic of interest:


My setup looks like this:




Now that I have this working with the Olimex version of the ESP8266... on to trying to do this with the NodeMCU version!

I'll be posting updates on twitter with source code on GitHub.
 
 
 

 


Find gojimmypi at gojimmypi.github.io

I'm currently working on my new blog home at  gojimmypi.github.io After implementing a variety of features such as dark mode , syntax hi...