Black Magic Probe on an stm32f103c8

User avatar
Rick Kimball
Posts: 724
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Black Magic Probe on an stm32f103c8

Postby Rick Kimball » Sat May 16, 2015 1:08 am

12/3/2016 - You can now contribute to developers of the Black Magic Probe project (which isn't me) using paypal. Find and click the paypal contribute button here: https://github.com/blacksphere/blackmagic

12/8/2016 - Instead of using this port of Black Magic Probe, it is a lot easier to just compile the PROBE_HOST=stlink and load that onto your bluepill. The bluepill hardware is the same as the stlink v1/v2 hardware. Just follow the steps from the Black Magic Probe software for building and installing the BMP stlink platform. The advantage being, you will get the latest BMP version and you will be able to update future versions just using the USB cable on the bluepill with a program called usb-util. The posts in this thread can be thought of as an interesting read on my journey from bluepill newbie to a somewhat proficient users of it.

The Black Magic Probe is a modern, in-application programmer and debugging software for embedded microprocessors. It allows you to see what is going on 'inside' an application running on an embedded microprocessor while it executes. It is able to control and examine the state of the target microprocessor using a JTAG or SWD (Serial Wire debugging) port and on-chip debug logic provided by the microprocessor. The probe connects to a host computer using a standard USB interface. The user is able to control exactly what happens using the GNU source level debugging software, GDB. Read more about it here: https://github.com/blacksphere/blackmagic/wiki

However, the stm32duino crowd here will find the open source Black Magic firmware more appealing than the hardware. The Black Magic Probe firmware can be loaded onto the low cost stm32c8t6 boards you find on eBay. You can then use that clone board with BMP firmware to take the place of an ST-Link programmer. Once the BMP firmware is loaded on a clone board, it provides the ability to upload to the flash of another target board. It does this using a gdb server built into the BMP firmware. This allows for hardware debugging using just arm-none-eabi-gdb without any host server code.

I started with the latest github version of the Black Magic Probe software and added platform support for the stm32f103c8t6 boards you find on ebay. I call it the 'jc66_coreboard' platform, as that is the label printed on the silk screen. Any board with the same pin outs should work (See Red Pill Blue Pill post for more info about the hardware). The new platform is based mostly on the already existing stlink platform source with changes to support the different hardware pin outs and features.

The ebay "Red Pill" board loaded with the Black Magic Probe firmware acting like a programmer:
Image
by Rick Kimball, on Flickr

Target board (another "Red Pill" board) connections from the "Red Pill" BMP programmer:
Image


I've attached a zip file containing the blackmagic.bin file, the blackmagic elf file, and patch file for the source. ( NOTE: I will fork BMP github code and create a branch with the source changes). For now, just download and unpack the zip and then upload the bin or elf file to your jc66_coreboard.

If you want to build the source yourself, do something like the following:

Code: Select all

$ git clone https://github.com/blacksphere/blackmagic
Cloning into 'blackmagic'...
remote: Counting objects: 3463, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3463 (delta 0), reused 0 (delta 0), pack-reused 3461
Receiving objects: 100% (3463/3463), 1.70 MiB | 0 bytes/s, done.
Resolving deltas: 100% (2331/2331), done.
Checking connectivity... done.
$ cd blackmagic
$ unzip ../bmp_jc66_coreboard.zip
Archive:  ../bmp_jc66_coreboard.zip
  inflating: blackmagic             
  inflating: blackmagic.bin         
  inflating: bmp_jc66_coreboard.patch 
$ patch -p1 <bmp_jc66_coreboard.patch
patching file src/Makefile
patching file src/command.c
patching file src/platforms/common/cdcacm.c
patching file src/platforms/jc66_coreboard/Makefile.inc
patching file src/platforms/jc66_coreboard/Readme
patching file src/platforms/jc66_coreboard/jc66_coreboard.png
patching file src/platforms/jc66_coreboard/platform.c
patching file src/platforms/jc66_coreboard/platform.h
$ make
$ cd src
$ make install # assuming it go OK, you will have to change the path for the st-write utility to match your system


To program a target board, The minimal pin connections for uploading and debugging would be:

Code: Select all

TARGETBOARD     JC66_COREBOARD
 GND             GND
 SWDIO           PA4  *
 SWCLK           PA5  *
 POWER           3.3V from someplace with a common ground. Probably easiest to plug both boards in to USB


The Black Magic Probe will appear as 2 serial ports /dev/ttyACM0 and /dev/ttyACM1 (depending on what other tty devices you have plugged in). The lower number port provides a GDB Remote Serial Protocol interface. This tty connection is used as the target remote device with arm-none-eabi-gdb. Black Magic Probe implements a gdb server on the hardware so you don't need any host software like openocd or st-util. The higher number tty port is a virtual com device. Wire the RX2/TX2 pins from the JC66_COREBOARD to your target board on the USART serial port you are using in your arduino sketch. You probably want to add a udev entry for the BMP device. It shows up as an OpenMoko device:

Code: Select all

$ lsusb -d 1d50:
Bus 001 Device 117: ID 1d50:6018 OpenMoko, Inc.


[Edit}I've updated the platform.txt and boards.txt for the generic boards and Roger has added it to the github source. So you can use this directly upload from the Arduino IDE using BMP. To use the debug features, you still have to do some hand work.[/Edit]

So the simple way to use this is turn on the verbose compilation option in the Arduino Preferences Dialog. Then build something. Then cd to /tmp/buildxxxx .. where xxx is the directory where you find the .elf file.

Then do something like this:

Code: Select all

$ pwd
/tmp/build676879315209412495.tmp
$ arm-none-eabi-gdb -b 115200 Blink.cpp.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140731-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/build676879315209412495.tmp/Blink.cpp.elf...done.
(gdb) directory /mnt/vbox/shared/Arduino_STM32RK_Sketch/Blink
Source directories searched: /mnt/vbox/shared/Arduino_STM32RK_Sketch/Blink:$cdir:$cwd
(gdb) target extended-remote /dev/ttyACM0
Remote debugging using /dev/ttyACM0
(gdb) monitor swdp_scan
Target voltage: 3.35V
Available Targets:
No. Att Driver
 1      STM32, Medium density.
(gdb) attach 1
Attaching to program: /tmp/build676879315209412495.tmp/Blink.cpp.elf, Remote target
0x08002170 in delay_us (us=11999)
    at /mnt/vbox/shared/Arduino_STM32RK_Sketch/hardware/stm32duino/STM32F1/system/libmaple/include/libmaple/delay.h:58
58                    : "r0");
(gdb) monitor erase_mass
(gdb) load
Loading section .text, size 0x2d4c lma 0x8000000
Loading section .ARM.exidx, size 0x8 lma 0x8002d50
Loading section .data, size 0xd78 lma 0x8002d58
Loading section .rodata, size 0x12c lma 0x8003ad0
Start address 0x8000170, load size 15352
Transfer rate: 13 KB/sec, 852 bytes/write.
(gdb) break setup
Breakpoint 1 at 0x8000140: file Blink.ino, line 8.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, setup () at Blink.ino:8
8     pinMode(PC13, OUTPUT);
(gdb) disassemble $pc
Dump of assembler code for function setup():
=> 0x08000140 <+0>:   movs   r0, #32
   0x08000142 <+2>:   movs   r1, #0
   0x08000144 <+4>:   b.w   0x8002080 <pinMode(unsigned char, WiringPinMode)>
End of assembler dump.
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x08002172 in delay_us (us=11999)
    at /mnt/vbox/shared/Arduino_STM32RK_Sketch/hardware/stm32duino/STM32F1/system/libmaple/include/libmaple/delay.h:58
58                    : "r0");
(gdb) exit
Undefined command: "exit".  Try "help".
(gdb) quit
A debugging session is active.

   Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) y
Detaching from program: /tmp/build676879315209412495.tmp/Blink.cpp.elf, Remote target
$


Some notes from above session:
  • /mnt/vbox/shared/Arduino_STM32RK_Sketch/Blink is my sketch directory. Use yours
  • registers can be used if you type them in lower case $pc is the PROGRAM COUNTER. $sp - Stack pointer, $r1 .. etc
  • type layout split to get a terminal based 3 window setup source on top , asm , then a command entry window
I'll put together integration with the Arduino platform.txt and write some about it later. For now, enjoy and let me know if you have successes.

-rick
Last edited by Rick Kimball on Thu Dec 08, 2016 6:43 pm, edited 23 times in total.
-rick

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby RogerClark » Sun May 17, 2015 11:05 am

Rick,

I've tried to install the BMP binary on 2 different C8 boards

This one didnt work, I just get unknown device on USB

Image


However I have a feeling the board either has a defective USB connection or it doesn't have a pull up resistor etc and will only work on USB with special firmware

The other C8 board, was fine (its the same board you have)

On Windows I had to download and install the drivers from here http://www.blacksphere.co.nz/downloads/ ... 130819.zip

What does seem a bit odd, is that the drivers 2 years old http://www.blacksphere.co.nz/downloads/

I guess they have no need to update them, but I suspect that they may not work on Windows 10 without us re-packaging them (but its hard to know quite what Windows 10 will end up doing until its released)

I guess it doesnt really matter, but has BlackSphere given up selling the BMP ? There isnt a link to where you an buy it from, on their website. Well there is some text but no hyperlink


Is there any documentation about what GPIO pins on the flashed board need to be connected to the CLOCK and SDIO pins on the SWD connector ?

Do you know how the UART works, is this just a method to print debug messages

e.g. I found this code,

http://electronics.stackexchange.com/qu ... d-using-gd

Is this the sort of UART functionality it provides ?

Thanks

Roger

User avatar
ahull
Posts: 1398
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby ahull » Sun May 17, 2015 12:23 pm

I wonder if it would be possible to flash the BMP firmware on one of http://www.ebay.co.uk/itm/181736138353?ru=http%3A%2F%2Fwww.ebay.co.uk%2Fsch%2Fi.html%3F_from%3DR40%26_sacat%3D0%26_nkw%3D181736138353%26_rdc%3D1these.

Since I now have two of these ST-Link V2 clones it should be possible to use one to probe the other. They are also scarily cheap. If I get a chance I'll try and reverse engineer the board and see if I can A) copy off the existing firmware, and B) figure out if we have enough pins etc to re-purpose it as a Black Magic Probe.
- Andy Hull -

User avatar
Rick Kimball
Posts: 724
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby Rick Kimball » Sun May 17, 2015 12:29 pm

RogerClark wrote:This one didnt work, I just get unknown device on USB

For the modifications I made, I expect you to use the specific board I mentioned, or one that has the exact same circuits. I'm expecting that the PA12 pin (USBDP+) only has a 1.5k pull up resistor to 3.3v. I also expect that pin PC13 has an LED that is active low.

To use a different board, you could look at the changes I made and modify the platform.c and platform.h to do the right thing for your board.

RogerClark wrote:What does seem a bit odd, is that the drivers 2 years old http://www.blacksphere.co.nz/downloads/

The windows drivers aren't really drivers. The .inf file just makes sure that the Microsoft usbser.sys gets loaded:

Code: Select all

[DriverInstall.nt]
CopyFiles=DriverCopyFiles.nt
AddReg=DriverInstall.nt.AddReg

[DriverCopyFiles.nt]
usbser.sys,,,0x20

[DriverInstall.nt.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"

[DriverInstall.nt.Services]
AddService = usbser,0x0002,DriverService.nt

[DriverService.nt]
DisplayName = %BLACKSPHERE_DISPLAY_NAME%
ServiceType = 1                  ; SERVICE_KERNEL_DRIVER
StartType = 3                    ; SERVICE_DEMAND_START
ErrorControl = 1                 ; SERVICE_ERROR_NORMAL
ServiceBinary = %10%\System32\Drivers\usbser.sys
LoadOrderGroup = Base

; Windows 64-bit sections
;~~~~~~~~~~~~~~~~~~~~~~~~~
[DriverInstall.NTamd64]
CopyFiles=DriverCopyFiles.NTamd64
AddReg=DriverInstall.NTamd64.AddReg

[DriverCopyFiles.NTamd64]
usbser.sys,,,0x20

[DriverInstall.NTamd64.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"

[DriverInstall.NTamd64.Services]
AddService = usbser,0x0002,DriverService.NTamd64

[DriverService.NTamd64]
DisplayName = %BLACKSPHERE_DISPLAY_NAME%
ServiceType = 1                  ; SERVICE_KERNEL_DRIVER
StartType = 3                    ; SERVICE_DEMAND_START
ErrorControl = 1                 ; SERVICE_ERROR_NORMAL
ServiceBinary = %10%\System32\Drivers\usbser.sys
LoadOrderGroup = Base


RogerClark wrote:Is there any documentation about what GPIO pins on the flashed board need to be connected to the CLOCK and SDIO pins on the SWD connector ?

I tried to documented above what needs to be connected. You need to add some hardware on the device being used as the BMP. Look in my previous post where it talks about the pull-ups/pull-downs for PA4 and PA5.

If you want to program a maple-mini, they don't break out the SWDIO and SWCLK so you have to connect PA4/PA3 of the BMP to the normal pins. On the maple mini PA13 is SWDIO and PA14 is SWCLK. So PA4 -> PA13 and PA5->PA14.

With another c8 board you just connect PA4-> SWIO and PA5 ->SWCLK.

With both boards you need a common GND. So just connect gnd to gnd on from the BMP to the Target Board.

RogerClark wrote:Do you know how the UART works, is this just a method to print debug messages


The UART is just like a normal USB->serial UART device. It is pinned out on the USART RX2 of the stm32f103c8. You use it like you would use any other dongle. Wire the TX2 (which is pin PA2 of the stm32f103c8 see the pin breakout below) to the appropriate RX pin of whatever target device you are using. Do the same for RX2 -> appropriate TX pin of the target device. (RX2 is PA3) Look at the source code patch in the platforms/jc66_coreboard/platfrom.h for all the PINS that are used.

Image

RogerClark wrote:http://electronics.stackexchange.com/qu ... d-using-gd

Is this the sort of UART functionality it provides ?
Roger


Semi hosting is something completely different, It doesn't use the UART port at all. It uses a special breakpoint in gdb to transfer information. You need to use a different linker --spec argument to make it work. I haven't had time to test this. Hopefuly, it should work, however there are probably lots of 't's to cross and 'i's to dot.

-rick
Last edited by Rick Kimball on Wed May 20, 2015 2:04 pm, edited 2 times in total.
-rick

User avatar
Rick Kimball
Posts: 724
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby Rick Kimball » Sun May 17, 2015 12:49 pm

I really haven't documented all the features. There are some other modifications in there if you look at the code.

I included support for reading the target boards VCC voltage. I found a patch on blackmagic mailing list
http://sourceforge.net/p/blackmagicdebug/mailman/message/33693983/. I slightly modified it to fit the hardware on this board. To use this feature you need to do some things:

o Add a voltage divider and diode on pin PA0.
Use 4k7 resistors and connect to your TARGET VCC (On the c8 board it is broken out with the SWD pins)
pa0_diode_circuit.png
pa0_diode_circuit.png (5.17 KiB) Viewed 9192 times


o Measure the VCC of your BMP board.
To get an accurate reading, the code needs to know what voltage your BMP is running at. I just measured it with a DMM.
TODO: research how to read VCC from the BMP itself.

I updated the code in platform.c. I measured 3.297V and inputted 3297 in the code below:

Code: Select all

const char *platform_target_voltage(void)
{

  static char ret[] = "0.00V";
  const uint8_t channel = 0;
  adc_set_regular_sequence(ADC1, 1, (uint8_t*)&channel);

  adc_start_conversion_direct(ADC1);

  /* Wait for end of conversion. */
  while (!adc_eoc(ADC1));

  uint32_t val = adc_read_regular(ADC1);
  /* VREF = 3.3 Volt, Divider 1/2 for AIN1, 6600 mV range
   * FIXME: Vsupply may drop, so measure VREFINT
   * and relate to measured voltage!
   * TARGET_VCC should have 4k7->4k7 ->
   * PA0 connected after the voltage divider with a 100k pull down
   */
  val = val * ((3297*2)+(600+2)); /* my measured voltage */
  val = val / 4096;
  ret[0] = '0' + val / 1000;
  val = val % 1000;
  ret[2] = '0' + val /100;
  val = val % 100;
  ret[3] = '0' + val /10;
  return ret;
}


This value shows up in arm-none-eabi-gdb when you scan for devices (Note the 3.34V) in the gdb output below. I connected my c8 board to a different board that is powered by usb.

Code: Select all

$ arm-none-eabi-gdb -q -ex 'target extended-remote /dev/ttyACM0'
Remote debugging using /dev/ttyACM0
(gdb) monitor swdp_scan
Target voltage: 3.34V
Available Targets:
No. Att Driver
 1      STM32, Medium density.
(gdb)


The most useful thing about this is when you forget to provide power to the target board. I will show up as a 0.00v : )

I'll try to document more as I test more. I'd like to make sure semihosting works. It is next to be tested on my list. However, incorporating that feature into the IDE and STM32DUINO would take a lot of modifications to the stm32duino setup.

Note:
Here is the values I used for the falstad circuit simulator:

Code: Select all

$ 1 5.0E-6 10.20027730826997 50 5.0 50
O 416 192 480 192 1
R 240 192 176 192 0 0 40.0 3.3 0.0 0.0 0.5
d 240 192 304 192 1 0.6
r 304 192 368 192 0 4700.0
r 368 192 368 256 0 4700.0
w 368 192 416 192 0
g 368 256 368 272 0
r 240 192 240 256 0 100000.0
g 240 256 240 272 0
x 143 147 217 152 0 18 TARGET
x 146 168 184 173 0 18 VCC
x 457 146 496 151 0 18 BMP
x 457 166 491 171 0 18 PA0
x 157 353 444 357 0 16 platform.c: platform_target_voltage()
x 126 89 528 95 0 24 Target Board  Measurement Calcs
x 156 376 373 380 0 16 val=val*((3300*2)+(600*2);

You could copy those values and import them http://falstad.com/circuit


-rick
Last edited by Rick Kimball on Sun May 17, 2015 2:58 pm, edited 4 times in total.
-rick

User avatar
ahull
Posts: 1398
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby ahull » Sun May 17, 2015 1:30 pm

ahull wrote:I wonder if it would be possible to flash the BMP firmware on one of http://www.ebay.co.uk/itm/181736138353?ru=http%3A%2F%2Fwww.ebay.co.uk%2Fsch%2Fi.html%3F_from%3DR40%26_sacat%3D0%26_nkw%3D181736138353%26_rdc%3D1these.

Since I now have two of these ST-Link V2 clones it should be possible to use one to probe the other. They are also scarily cheap. If I get a chance I'll try and reverse engineer the board and see if I can A) copy off the existing firmware, and B) figure out if we have enough pins etc to re-purpose it as a Black Magic Probe.


This might be of interest if attempting to convert an ST-Link board or cheap "ST-Link V2" clone.
http://embdev.net/articles/STM_Discovery_as_Black_Magic_Probe
- Andy Hull -

victor_pv
Posts: 945
Joined: Mon Apr 27, 2015 12:12 pm

Re: Black Magic Probe on an stm32f103c8

Postby victor_pv » Sun May 17, 2015 3:18 pm

Rick, is there a way to use BMP and GDB on windows with the Arduino IDE? I have never used either, so I am getting a bit lost at what is needed.
If you could point me to some directions I can read and try to figure it out.

thanks.

User avatar
Rick Kimball
Posts: 724
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby Rick Kimball » Sun May 17, 2015 4:14 pm

[EDIT] .. see the next post for a possible answer[/EDIT]

victor_pv wrote:Rick, is there a way to use BMP and GDB on windows with the Arduino IDE? I have never used either, so I am getting a bit lost at what is needed. If you could point me to some directions I can read and try to figure it out. thanks.


After I installed the windows drivers for BMP I ended up with a GDB Server port COM5
and a UART Port (COM6) * you don't care about this for now.
windows_devices.png
windows_devices.png (17.29 KiB) Viewed 9182 times


To use it with windows and the IDE would require changes to the board.txt and platform.txt. This has not been done yet.
So the simple way to use this is turn on the verbose compilation option in the Arduino Preferences Dialog. Then build something. Open a command prompt window and cd to that temp directory. I really am not setup for windows so I don't know where they put the tmp files, The IDE will tell you. Basically you want to use a cmd window and cd to that directory and then you find the .elf file.

This is what my linux gdb sessions looks like... where I used /dev/ttyACM0 .. if I were to do it in my windows .. I would replace /dev/ttyACM0 with com5 ...
as that is the Black Magic GDB Server (COM5) in the windows device manager picture above. Also I have the directory for the arm-none-eabi-gdb.exe in my path so I can just type it. You need to find the directory where the arduino IDE installed the gcc exes and add it to your path or use the full path name to start arm-none-eabi-gdb.exe ( Note: the verbose compilation options shows you both the temp directory and the gcc executuable directory)

Code: Select all

$ cd /tmp/build676879315209412495.tmp
$ arm-none-eabi-gdb -b 115200 Blink.cpp.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140731-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/build676879315209412495.tmp/Blink.cpp.elf...done.
(gdb) directory /mnt/vbox/shared/Arduino_STM32RK_Sketch/Blink
Source directories searched: /mnt/vbox/shared/Arduino_STM32RK_Sketch/Blink:$cdir:$cwd
(gdb) target extended-remote /dev/ttyACM0
Remote debugging using /dev/ttyACM0
(gdb) monitor swdp_scan
Target voltage: 3.35V
Available Targets:
No. Att Driver
 1      STM32, Medium density.
(gdb) attach 1
Attaching to program: /tmp/build676879315209412495.tmp/Blink.cpp.elf, Remote target
0x08002170 in delay_us (us=11999)
    at /mnt/vbox/shared/Arduino_STM32RK_Sketch/hardware/stm32duino/STM32F1/system/libmaple/include/libmaple/delay.h:58
58                    : "r0");
(gdb) monitor erase_mass
(gdb) load
Loading section .text, size 0x2d4c lma 0x8000000
Loading section .ARM.exidx, size 0x8 lma 0x8002d50
Loading section .data, size 0xd78 lma 0x8002d58
Loading section .rodata, size 0x12c lma 0x8003ad0
Start address 0x8000170, load size 15352
Transfer rate: 13 KB/sec, 852 bytes/write.
(gdb) break setup
Breakpoint 1 at 0x8000140: file Blink.ino, line 8.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, setup () at Blink.ino:8
8     pinMode(PC13, OUTPUT);
(gdb) disassemble $pc
Dump of assembler code for function setup():
=> 0x08000140 <+0>:   movs   r0, #32
   0x08000142 <+2>:   movs   r1, #0
   0x08000144 <+4>:   b.w   0x8002080 <pinMode(unsigned char, WiringPinMode)>
End of assembler dump.
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x08002172 in delay_us (us=11999)
    at /mnt/vbox/shared/Arduino_STM32RK_Sketch/hardware/stm32duino/STM32F1/system/libmaple/include/libmaple/delay.h:58
58                    : "r0");
(gdb) exit
Undefined command: "exit".  Try "help".
(gdb) quit
A debugging session is active.

   Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) y
Detaching from program: /tmp/build676879315209412495.tmp/Blink.cpp.elf, Remote target
$


Some notes from above session:
/mnt/vbox/shared/Arduino_STM32RK_Sketch/Blink is my sketch directory. Use yours
registers can be used if you type them in lower case $pc is the PROGRAM COUNTER. $sp - Stack pointer, $r1 .. etc
type layout split to get a terminal based 3 window setup source on top , asm , then a command entry window
I'll put together integration with the Arduino platform.txt and write some about it later. For now, enjoy and let me know if you have successes.

Also, I had previously explained some of the simple command line stuff here:
http://www.stm32duino.com/viewtopic.php?f=35&t=113#p829

If you get all that working you might try 'layout split' in the gdb command prompt as it gives a terminal split windows display that shows you 3 "windows". It just splits the command window into 3 sections).

Maybe someone who has a windows Arduino setup and knows gdb could elaborate. I'm really not setup to do windows.

-rick
Last edited by Rick Kimball on Sun May 17, 2015 7:02 pm, edited 1 time in total.
-rick

User avatar
Rick Kimball
Posts: 724
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby Rick Kimball » Sun May 17, 2015 5:18 pm

I went ahead and modified the platform.txt to do the upload via arm-none-eabi-gdb.

Here is what it looks like when you have verbose upload turned on with the Arduino IDE on linux:
makerlabme_gdb.png
makerlabme_gdb.png (82.85 KiB) Viewed 9177 times


You can see this isn't the normal stm32duino directories. I've been playing the with MakerLabMe STM32 port. I made these simple changes to their platform.txt to support BMP via arm-none-eabi-gdb:

Code: Select all

# stm32 upload via BMP and arm-none-eabi-gdb
# -------------------
tools.sloadhost.cmd=arm-none-eabi-gdb
tools.sloadhost.path={runtime.tools.arm-none-eabi-gcc.path}/bin/

tools.sloadhost.upload.params.verbose=
tools.sloadhost.upload.params.quiet=
tools.sloadhost.upload.pattern="{path}{cmd}" -q -b 115200 -ex "set height 0" -ex "target extended-remote {serial.port}" -ex "mon swdp_scan" -ex "attach 1" -ex "monitor erase_mass" -ex "set confirm off" -ex "load" -ex "quit" "{build.path}/{build.project_name}.elf"


@victor_pv Who knows, this might just work for windows.

-rick
-rick

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Black Magic Probe on an stm32f103c8

Postby RogerClark » Sun May 17, 2015 9:28 pm

Rick

I think that code should work on Windows, but for greater compatibility for anyone on IDE 1.6.1 or earlier I think the path to GDB needs to be changed to the same path that is defined at the top of platform.txt, and then allow the rewrite-keys to handle changing it if necessary

With my other C8 board.
It could just be the board is defective.

Re: connections

After I posted, I managed to find a schematic of a derivative of the BMP called the Cricket Probe, and I can see that the BMP uses serial port 1 to connect to the target, as well as the SWD connection.


I will have a go at using the same model of F103C8 board that you use, and connect to my ZET board.


@ahull

Re: flashing an STLink.

I noticed in the GitHub code that there is a target of STlink, rather than the target of STM32 which I think rick may be using.

I was debating whether to reflash my STLink as a BMP, as I read the article you linked to and then tracked down the Stlink binary it referenced, on a Russian website.

However my stlink board only has the SWD pins broken out to a connector, so connecting a USB to serial to it, and pulling boot 0 high, in order to flash it, would be difficult.

In the longer term I may however reflash by F4 Discover stlink as its a pain needing a separate USB to serial for comms, I.e the Discovery stlink firmware doesn't come with the virtual serial like the Nucleo firmware does :-(


Return to “Black Magic Probe & other”

Who is online

Users browsing this forum: No registered users and 1 guest