OpenOCD notes Entry: blue pill as device programmer Date: Sun Mar 22 10:56:32 EDT 2020 Asked on #openocd on freenode. 10:59 < tom> Hi. Is anyone aware of open firmware that can go on a "blue pill" STM32F103 board to act as a programmer supported by OpenOCD? 11:02 < clever> tom: not a proper answer, but ive just been using an rpi4 with sysfs_gpio bit-banging 11:04 < tom> clever: i might be able to do the same on the blue pill. how does the speed compare to a typical programmer? 11:05 < clever> with sysfs_gpio, its a bit slow, but plenty usable for arm debug and loading small (<50kb) .elf files into ram EDIT: Maybe not the rabbit hole to go down into. 11:09 < PaulFertser> tom: yes, there're several options even 11:13 < PaulFertser> tom: https://github.com/devanlai/dap42 11:15 < PaulFertser> tom: looks like an active projet, there was also https://github.com/x893/CMSIS-DAP 11:27 < tom> PaulFertser: thanks! 11:27 < PaulFertser> tom: please share how it goes, probably write a mail to the mailing list 11:27 < PaulFertser> tom: btw, are you aware of fake stm32f103 chips and the firmware tool to test them? 11:50 < tom> PaulFertser: re fake chips: no, not aware 11:53 < PaulFertser> tom: https://github.com/keirf/Greaseweazle/wiki/STM32-Fakes 11:54 < PaulFertser> tom: better to run their blinky to be sure what kind of fake it is so that you can know exactly what features are broken. That is going to be a good starting point. Can't get it to do anything atm. Not sure what's up. Entry: specifying usb location for openocd Date: Mon Apr 13 18:16:27 EDT 2020 I want to distinguish stlink by USB port. Start looking here: openocd/src/jtag/drivers/libusb_helper.c static bool jtag_libusb_location_equal(libusb_device *device) openocd/src/jtag/drivers/jtag_usb_common.c bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len) EDIT: See next post. Use serial number. It's just weird for stlink and doesn't show up properly as UTF string. Entry: Distinguishing stm programmers by serial number Date: Sat Apr 18 09:54:39 EDT 2020 The USB strings are different: [3021786.406034] usb 4-1.6.2.5.3: SerialNumber: QÿqI\xffffffc2\xffffff89IR@0\xffffffc2\xffffff87 [3021789.733476] usb 4-1.6.2.5.4: SerialNumber: SÿqQ\xffffffc2\xffffff88Q@g So I guess I need to pass that in somehow... Bus 004 Device 011: ID 0483:3748 STMicroelectronics ST-LINK/V2 Bus 004 Device 009: ID 0483:3748 STMicroelectronics ST-LINK/V2 # lsusb -s 4:11 -v Starting OpenOCD gives this status line: Info : STLINK V2J17S4 (API v2) VID:PID 0483:3748 which is printed in ./src/jtag/drivers/stlink_usb.c:1087: LOG_INFO("STLINK %s (API v%d) VID:PID %04X:%04X", Also see stlink_usb_get_alternate_serial in that file. In jtag_libusb_open, the alternate serial is only requested if serial is non-NULL: if (serial != NULL && !jtag_libusb_match_serial(libusb_handle, &dev_desc, serial, adapter_get_alternate_serial)) { serial_mismatch = true; libusb_close(libusb_handle); continue; } Ok so to do this in stock openocd: 1. set the serial to something that won't match 2. enable debug messages See LOG_DEBUG("Device alternate serial number '%s' doesn't match requested serial '%s'", alternate_serial, serial); jtag_libusb_match_serial ok now knowing how to look, this is what turns up: https://wunderkis.de/stlink-serialno/ http://openocd.zylin.com/#/c/2198/ https://armprojects.wordpress.com/2016/08/21/debugging-multiple-stm32-in-eclipse-with-st-link-v2-and-openocd/ I modified this so it is LOG_INFO. I did notice a problem with the device. Something the serial number doesn't show up properly: Info : Device alternate serial number '303030303030303030303031' doesn't match requested serial 'wrong_serial' Info : Device alternate serial number '53FF71065188515408400567' doesn't match requested serial 'wrong_serial' Sometimes it just does that apparently... iSerial 3 000000000001 Power cycling resolves it. stlink.cfg mentions issues with reset: ST-LINK/V2 firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial number reset issues. How can I see firmware version? ST hast tool to upgrade firmware: https://www.st.com/en/development-tools/stsw-link007.html But the website seems broken. Link is gone after accepting license agreement and logging in. Entry: what is hla? Date: Sat Apr 18 12:07:06 EDT 2020 High Level Adapters. http://www.openocd.org/doc/html/Debug-Adapter-Configuration.html Ok that one also mentions to upgrade firmware. Maybe try downloading it on windows? ST website doesn't let me download on windows either. Got an alternative source, but that one doesn't recognize the st clone. WTF is this shit. I could have invested that time in an open source programmer firmware.. Maybe just add a bus option to hla? What about just going for it today and set up a programmer on the blue pill? Entry: dap42 Date: Sat Apr 18 12:51:41 EDT 2020 https://github.com/devanlai/dap42 Last time I tried the controller didn't start up properly. Maybe try another board. The image does look like normal, e.g. has meaningful stack pointer in first word and entry point in second. tom@panda:~/git/dap42/build$ hd DAP103-BLUEPILL.bin 00000000 00 50 00 20 45 2a 00 08 41 2a 00 08 3f 2a 00 08 |.P. E*..A*..?*..| How to flash a binary in gdb? It might be simpler in openocd: mon flash write_bank Entry: getting the st link serial number Date: Sat Apr 18 13:04:15 EDT 2020 root@zora:/sys/bus/usb/devices/1-1.2# hd serial 00000000 53 c3 bf 71 06 51 c2 88 51 54 08 40 05 67 0a |S..q.Q..QT.@.g.| 0000000f