Black Magic Probe on an stm32f103c8

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

Re: Black Magic Probe on an stm32f103c8

Post by RogerClark » Mon Jan 18, 2016 11:47 pm

Duncan

The STM32F103 does not have a built in USB upload feature built into the chip (the STM32F4 series does but not the F1 series)

Normally when we program the Maple mini and the generic STM32F103 boards using the Arduino IDE, we use the STM32duino-bootloader
(This is updated version of the original Maple-bootloder written by Leaflabs)

The bootloader comes pre-installed on Maple mini boards and can be flashed onto generic STM32 boards (e.g. Blue Pill), and then remains resident and provides the upload / reflashing via USB.

i.e when you power on the Maple mini it runs the bootloader code in the base of flash which enumarates on USB as a DFU device for about 1 second.

If the host PC does not start sending data to the DFU device in about the first second after booting, the bootloader looks to see if there is any code at the sketch start address 0x8002000 and if so it jumps to that address and the sketch starts to run.


In order to get the BMP to work in this way, it would need to be compiled so that the base address of the code is 0x8002000 instead of the start of flash (which is 0x800000)
I did briefly look at doing this, but the code that would need to be changed seems to be deep inside libcm3 and it looked like it would take quite some time to modify, test and debug.

So as there was very little gain in doing this apart from allowing Maple mini users to run the BMP as if it was a sketch, I didnt feel it was worth me spending any of my very limited time on doing that as an option.


Re: Repurposing some of the pins on the STlink as Serial

Its a nice idea, but I'm not sure whether it would be possible

Although the STM32F103 has multiple USARTS, I'm not sure if any of them are on the pins use by RESET and SWIM

You'd need to find a schematic for the STLink stick and find which pins are used (I think one of them my be PB0), you'd then need to check if any of them are USART pins.
If they are not primary USART pins, there are remap / alternative pins for the USARTS, so you need to check that as well

If they are remap pins, in theory you could modify the BMP code to remap the pins and use the appropriate USART.

However the pins may not be both on the same USART

I suspect you are making yourself a huge amount of work.

zmemw16
Posts: 1581
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Black Magic Probe on an stm32f103c8

Post by zmemw16 » Tue Jan 19, 2016 3:48 am

the v2.0 of the bootloader is a major speed improvement, certainly on the maple mini, not done it with a pill.

flashing a pill for bmp install is easy, it's puzzled me or i was unsure and then it was so simple i posted a comment to that effect.
istr 2 photo's from a rick thread, combining them shows all 4 wires that will connected to the target, programming it is
via 4 pins on end of the pill. careful pin counting is reccomended. also there is a link to a binary zip you can install, beginning of the thread and it gets updated.

after that it gets interesting and maybe a tad confusing for my braincell. openocd is suggested. using it is not a gui.

stephen

Darius
Posts: 7
Joined: Mon Jul 04, 2016 12:20 am

Re: Black Magic Probe on an stm32f103c8

Post by Darius » Mon Jul 04, 2016 2:57 am

I am cross posting to this thread on Richard's suggestion from http://www.stm32duino.com/posting.php?m ... 37&p=15530
Rick Kimball wrote:
Darius wrote:Hi all,
I'm just trying out STM32Duino and so I cloned https://github.com/rogerclarkmelbourne/ ... _STM32.git and checked out the development branch.
I twiddled STM32F1/platform.txt to change 'runtime.tools.arm-none-eabi-gcc.path' to point to my build environment.
Why did you have to "twiddle" the platform.txt?

Turn on verbose upload options in File/Preferences and post your output showing the failure
With a fresh clone of the development branch I get..

Code: Select all

Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware "/Applications/Arduino.app/Contents/Java/hardware" -hardware "/Users/oconnd1/Library/Arduino15/packages" -hardware "/Users/oconnd1/Documents/Arduino/hardware" -tools "/Applications/Arduino.app/Contents/Java/tools-builder" -tools "/Applications/Arduino.app/Contents/Java/hardware/tools/avr" -tools "/Users/oconnd1/Library/Arduino15/packages" -built-in-libraries "/Applications/Arduino.app/Contents/Java/libraries" -libraries "/Users/oconnd1/Documents/Arduino/libraries" -fqbn=Arduino_STM32:STM32F1:genericSTM32F103V:device_variant=STM32F103VE,upload_method=BMPMethod -ide-version=10609 -build-path "/var/folders/w5/82721l751bscw83qpk2xbj_00000gn/T/build2222e6f03e244404f8792712224020b3.tmp" -warnings=default -prefs=build.warn_data_percentage=75 -verbose "/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/libraries/A_STM32_Examples/examples/Digital/Blink/Blink.ino"
/Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware "/Applications/Arduino.app/Contents/Java/hardware" -hardware "/Users/oconnd1/Library/Arduino15/packages" -hardware "/Users/oconnd1/Documents/Arduino/hardware" -tools "/Applications/Arduino.app/Contents/Java/tools-builder" -tools "/Applications/Arduino.app/Contents/Java/hardware/tools/avr" -tools "/Users/oconnd1/Library/Arduino15/packages" -built-in-libraries "/Applications/Arduino.app/Contents/Java/libraries" -libraries "/Users/oconnd1/Documents/Arduino/libraries" -fqbn=Arduino_STM32:STM32F1:genericSTM32F103V:device_variant=STM32F103VE,upload_method=BMPMethod -ide-version=10609 -build-path "/var/folders/w5/82721l751bscw83qpk2xbj_00000gn/T/build2222e6f03e244404f8792712224020b3.tmp" -warnings=default -prefs=build.warn_data_percentage=75 -verbose "/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/libraries/A_STM32_Examples/examples/Digital/Blink/Blink.ino"
"/bin/arm-none-eabi-g++" -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE  -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103v -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOE -DERROR_LED_PIN=6 -w -x c++ -E -CC -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10609 -DARDUINO_GENERIC_STM32F103V -DARDUINO_ARCH_STM32F1  -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG -DMCU_STM32F103VE -DSTM32F103xE  -mthumb  -march=armv7-m -D__STM32F1__ -DMCU_STM32F103VE -DSTM32F103xE  -mthumb  -march=armv7-m -D__STM32F1__ "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/include" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/stm32f1/include"                                                           "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/stm32f1" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/usb_lib" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/cores/maple" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103v" "/var/folders/w5/82721l751bscw83qpk2xbj_00000gn/T/build2222e6f03e244404f8792712224020b3.tmp/sketch/Blink.ino.cpp" -o "/dev/null"
"/bin/arm-none-eabi-g++" -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE  -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103v -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOE -DERROR_LED_PIN=6 -w -x c++ -E -CC -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10609 -DARDUINO_GENERIC_STM32F103V -DARDUINO_ARCH_STM32F1  -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG -DMCU_STM32F103VE -DSTM32F103xE  -mthumb  -march=armv7-m -D__STM32F1__ -DMCU_STM32F103VE -DSTM32F103xE  -mthumb  -march=armv7-m -D__STM32F1__ "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/include" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/stm32f1/include"                                                           "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/stm32f1" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/usb_lib" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/cores/maple" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103v" "/var/folders/w5/82721l751bscw83qpk2xbj_00000gn/T/build2222e6f03e244404f8792712224020b3.tmp/sketch/Blink.ino.cpp" -o "/dev/null"
"/bin/arm-none-eabi-g++" -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE  -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103v -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOE -DERROR_LED_PIN=6 -w -x c++ -E -CC -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10609 -DARDUINO_GENERIC_STM32F103V -DARDUINO_ARCH_STM32F1  -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG -DMCU_STM32F103VE -DSTM32F103xE  -mthumb  -march=armv7-m -D__STM32F1__ -DMCU_STM32F103VE -DSTM32F103xE  -mthumb  -march=armv7-m -D__STM32F1__ "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/include" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/stm32f1/include"                                                           "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/stm32f1" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/usb_lib" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/cores/maple" "-I/Users/oconnd1/Documents/Arduino/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103v" "/var/folders/w5/82721l751bscw83qpk2xbj_00000gn/T/build2222e6f03e244404f8792712224020b3.tmp/sketch/Blink.ino.cpp" -o "/var/folders/w5/82721l751bscw83qpk2xbj_00000gn/T/build2222e6f03e244404f8792712224020b3.tmp/preproc/ctags_target_for_gcc_minus_e.cpp"
fork/exec /bin/arm-none-eabi-g++: no such file or directory
Error compiling for board Generic STM32F103V series.
Note that arm-none-eabi-gcc is in my path..

Code: Select all

[Maelstrom 12:16] ~/projects/Arduino_STM32 >which arm-none-eabi-gcc
/opt/local/bin/arm-none-eabi-gcc
[Maelstrom 12:19] ~/projects/Arduino_STM32 >arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/arm-none-eabi/5.1.0/lto-wrapper
Target: arm-none-eabi
Configured with: /opt/local/var/macports/build/_opt_mports_dports_cross_arm-none-eabi-gcc/arm-none-eabi-gcc/work/gcc-5.1.0/configure --prefix=/opt/local --target=arm-none-eabi --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/arm-none-eabi-gcc --with-system-zlib --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --enable-stage1-checking --enable-multilib --with-newlib --enable-interwork --disable-newlib-supplied-syscalls --enable-languages=c,c++
Thread model: single
gcc version 5.1.0 (GCC)
However I thought I'd use 4.8 because of the warning on the boot loader page about 4.9 not working.

So I unpacked 4.8 into my home directory and added this to platform.txt
runtime.tools.arm-none-eabi-gcc.path=/Users/oconnd1/projects/gcc-arm-none-eabi-4_8-2014q3/

That gets the build done but the program fails with..

Code: Select all


Sketch uses 8,164 bytes (1%) of program storage space. Maximum is 524,288 bytes.
Global variables use 2,096 bytes of dynamic memory.
{runtime.tools.arm-none-eabi-gcc.path}/bin/{cmd} -cd /var/folders/w5/82721l751bscw83qpk2xbj_00000gn/T/build2222e6f03e244404f8792712224020b3.tmp -b 230400 -ex set debug remote 0 -ex set target-async off -ex set remotetimeout 60 -ex set mem inaccessible-by-default off -ex set confirm off -ex set height 0 -ex target extended-remote /dev/cu.usbmodem7FC58901 -ex monitor swdp_scan -ex attach 1 -ex x/wx 0x8000004 -ex monitor erase_mass -ex echo 0x8000004 expect 0xffffffff after erase\n -ex x/wx 0x8000004 -ex file Blink.ino.elf -ex load -ex x/wx 0x08000004 -ex tbreak main -ex run -ex echo \n\n\nUpload finished! -ex quit 
java.io.IOException: Cannot run program "{runtime.tools.arm-none-eabi-gcc.path}/bin/{cmd}": error=2, No such file or directory
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
	at java.lang.Runtime.exec(Runtime.java:620)
<snip>
The toolchain I unpacked has GDB (in /Users/oconnd1/projects/gcc-arm-none-eabi-4_8-2014q3/bin/arm-none-eabi-gdb).
In the end I changed platform.txt like so

Code: Select all

tools.bmp_upload.cmd=/Users/oconnd1/projects/gcc-arm-none-eabi-4_8-2014q3/bin/arm-none-eabi-gdb
tools.bmp_upload.upload.pattern="{cmd}" -cd "{build.path}" -b {upload.speed} {upload.verbose} -ex "set debug remote 0" -ex "set target-async off" -ex "set remotetimeout 60" -ex "set mem inaccessible-by-default off" -ex "set confirm off" -ex "set height 0" -ex "target extended-remote {serial.port}" -ex "monitor swdp_scan" -ex "attach 1" -ex "x/wx 0x8000004" -ex "monitor erase_mass" -ex "echo 0x8000004 expect 0xffffffff after erase\n" -ex "x/wx 0x8000004" -ex "file {build.project_name}.elf" -ex "load" -ex "x/wx 0x08000004" -ex "tbreak main" -ex "run" -ex "echo \n\n\nUpload finished!" -ex "quit"
then it would work.

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

Re: Black Magic Probe on an stm32f103c8

Post by Rick Kimball » Mon Jul 04, 2016 3:00 am

Go back to the start. Delete all those extra things you downloaded. Get rid of the launchpad arm-none-eabi-gcc toolchain. Unpack the stm32duino stuff in the right place. Then start up the IDE and install the boards package for the Arduino Zero. The will get rid of the missing g++. Then report back.

https://github.com/rogerclarkmelbourne/ ... stallation

Step 2:

Run the IDE, and on the Tools menu, select the Boards manager, and install the Arduino Due from the list of available boards.

*NOTE: this step installed the arm-none-eabi-g++
Last edited by Rick Kimball on Mon Jul 04, 2016 3:34 am, edited 1 time in total.
-rick

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

Re: Black Magic Probe on an stm32f103c8

Post by Rick Kimball » Mon Jul 04, 2016 3:03 am

Are you running the bootloader on your stm32f103c8?
-rick

Darius
Posts: 7
Joined: Mon Jul 04, 2016 12:20 am

Re: Black Magic Probe on an stm32f103c8

Post by Darius » Mon Jul 04, 2016 3:49 am

Rick Kimball wrote:Go back to the start. Delete all those extra things you downloaded. Get rid of the launchpad arm-none-eabi-gcc toolchain. Unpack the stm32duino stuff in the right place. Then start up the IDE and install the boards package for the Arduino Zero. The will get rid of the missing g++. Then report back.

https://github.com/rogerclarkmelbourne/ ... stallation

Step 2:

Run the IDE, and on the Tools menu, select the Boards manager, and install the Arduino Due from the list of available boards.

*NOTE: this step installed the arm-none-eabi-g++
Ugh sorry, I missed step 2 originally (I guess I should have gone to bed earlier :) )

After doing that it all works!

Sorry for the noise :(

alex
Posts: 19
Joined: Tue Jul 28, 2015 2:12 am

Re: Black Magic Probe on an stm32f103c8

Post by alex » Mon Aug 29, 2016 5:25 am

BMP and gdb can load(flash) .hex now.
'STM32 ST-LINK Utility' is needed for convert .bin to .hex, I tried to use arm-none-eabi-objcopy for convertion but failed.

Code: Select all

$ arm-none-eabi-gdb -batch -ex 'tar ext COM3' -ex 'mon ver' -ex 'mon sw' -ex 'at 1' -ex 'mon option erase' -ex 'load x.hex'
Black Magic Probe (Firmware xxx) (Hardware Version 1)
Copyright (C) 2015  Black Sphere Technologies Ltd.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

Target voltage: Not Implemented!
Available Targets:
No. Att Driver
 1      STM32F1 medium density
0x0800cc98 in ?? ()
0x1FFFF800: 0x5AA5
0x1FFFF802: 0xFFFF
0x1FFFF804: 0xFFFF
0x1FFFF806: 0xFFFF
0x1FFFF808: 0xFFFF
0x1FFFF80A: 0xFFFF
0x1FFFF80C: 0xFFFF
0x1FFFF80E: 0xFFFF
Loading section .sec1, size 0x2000 lma 0x8000000
Loading section .sec2, size 0x2000 lma 0x8002000
Loading section .sec3, size 0x2000 lma 0x8004000
Loading section .sec4, size 0x2000 lma 0x8006000
Loading section .sec5, size 0x2000 lma 0x8008000
Loading section .sec6, size 0x2000 lma 0x800a000
Loading section .sec7, size 0x2000 lma 0x800c000
Loading section .sec8, size 0x318 lma 0x800e000
Start address 0x0, load size 58136

Rick Kimball wrote:
alex wrote:How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the "STLinkV2.J16.S4.bin" file.
GDB has a "restore" command.
https://sourceware.org/gdb/onlinedocs/g ... Files.html

(gdb) restore ../STLinkV2.J16.S4.bin
'../STLinkV2.J16.S4.bin' is not a recognized file format.
(gdb) restore ../STLinkV2.J16.S4.bin binary
Restoring binary file ../STLinkV2.J16.S4.bin into memory (0x0 to 0x10000)
warning: restore: memory write failed ((undocumented errno -1)).
(gdb) restore ../STLinkV2.J16.S4.bin binary 0x8000000
Restoring binary file ../STLinkV2.J16.S4.bin into memory (0x8000000 to 0x8010000)
Writing to flash memory forbidden in this context
(gdb)
I ran into this problem with something else. I wanted to use the binary file provided by mbed and load it using BMP. If you first convert it to a .elf file it can be used with the load command without error:

Code: Select all

$ arm-none-eabi-objcopy -O elf32-littlearm -B arm --rename-section .data=.text -I binary mbed_blinky_lpc1114_LPC1114.bin foo.o
$ arm-none-eabi-gdb -b 115200 -ex 'target extended-remote /dev/ttyACM0' -ex 'monitor swdp_scan' -ex 'attach 1' foo.o
....
Available Targets:
No. Att Driver
 1      LPC11xx
Attaching to program: /tmp/foo.o, Remote target
0x000024bc in _binary_mbed_blinky_lpc1114_LPC1114_bin_start ()
(gdb) load
Loading section .text, size 0x28a0 lma 0x0
Start address 0x0, load size 10400
Transfer rate: 18 KB/sec, 945 bytes/write.
(gdb) run
....
-rick

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

Re: Black Magic Probe on an stm32f103c8

Post by RogerClark » Mon Aug 29, 2016 6:10 am

You should be able to get the IDE to generate HEX

Try using the Export Compiled Binary menu option on the Sketch menu

alex
Posts: 19
Joined: Tue Jul 28, 2015 2:12 am

Re: Black Magic Probe on an stm32f103c8

Post by alex » Mon Aug 29, 2016 7:35 am

RogerClark wrote:You should be able to get the IDE to generate HEX

Try using the Export Compiled Binary menu option on the Sketch menu
This is only for closed source firmware.

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

Re: Black Magic Probe on an stm32f103c8

Post by RogerClark » Mon Aug 29, 2016 10:42 am

alex wrote:
This is only for closed source firmware.

Aren't you using the Arduino IDE ?

Ah. You mean you are uploading a file for which you only have the binary. Closed source into RAM so you can make modifications to a closed source program very easily

Locked