I am attempting to flash an STM8S103F3P6 dev board (platform = ststm8, board = stm8sblue) using an STLink v3 on Windows. I see the STLink listed in the Serial tab in PIO Home. The blink program successfully compiles, but fails during upload step. The output I get during the upload step is:
Configuring upload protocol...
AVAILABLE: serial, stlinkv2
CURRENT: upload_protocol = stlinkv2
Uploading .pio\build\stm8sblue\firmware.hex
Determine FLASH area
libusb: error [init_device] device '\\.\USB#VID_0483&PID_374F&MI_02#6&3470BFC9&0&0002' is no longer connected!
libusb: info [windows_get_device_list] The following device has no driver: '\\.\USB#VID_1235&PID_8210&MI_03#6&1612EDE&0&0003'
libusb: info [windows_get_device_list] libusb will not be able to access it.
libusb: info [windows_get_device_list] The following device has no driver: '\\.\USB#VID_0A5C&PID_21E8#001986003B14'
libusb: info [windows_get_device_list] libusb will not be able to access it.
libusb: info [windows_get_device_list] The following device has no driver: '\\.\USB#VID_1235&PID_8210&MI_03#6&1612EDE&0&0003'
libusb: info [windows_get_device_list] libusb will not be able to access it.
libusb: info [windows_get_device_list] The following device has no driver: '\\.\USB#VID_0A5C&PID_21E8#001986003B14'
libusb: info [windows_get_device_list] libusb will not be able to access it.
Could not open USB device.
*** [upload] Error 4294967295
The other two USB devices are an audio interface and bluetooth adapter. I installed the ST USB drivers before connecting the STLink. I originally thought it was an issue with the board being write-protected, but I used ST Visual Programmer to unlock the board (confirmed by using STVP to successfully flash the .hex file built by PIO) and this didn’t change the output from PIO trying to upload.
>C:\Users\Max\.platformio\packages\tool-stm8flash\stm8flash.exe
Usage: C:\Users\Max\.platformio\packages\tool-stm8flash\stm8flash.exe [-c programmer] [-S serialno] [-p partno] [-s memtype] [-b bytes] [-r|-w|-v] <filename>
Options:
-? Display this help
-c programmer Specify programmer used (stlink, stlinkv2, stlinkv21 or stlinkv3)
-S serialno Specify programmer's serial number. If not given and more than one programmer is available, they'll be listed.
-d port Specify the serial device for espstlink (default: /dev/ttyUSB0)
-p partno Specify STM8 device
-l List supported STM8 devices
-s memtype Specify memory type (flash, eeprom, ram, opt or explicit address)
-b bytes Specify number of bytes
-r <filename> Read data from device to file
-w <filename> Write data from file to device
-v <filename> Verify data in device against file
-V Print Date(YearMonthDay-Version) and Version format is IE: 20171204-1.0
-u Unlock. Reset option bytes to factory default to remove write protection.
Running with the new version, I don’t see any changes and it looks like the verbosity only increased during the build step. Full log including compile, just so I don’t miss anything:
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : STLINK V3J10M3B5S1 (API v3) VID:PID 0483:374F
Info : Target voltage: 3.263298
Error: Unable to set adapter speed
Error: stlink_swim_enter_failed (unable to connect to the target)
Have you ever succesfully programmed the target chip before? I remember on many occassions I had to do a flash unlock before it would do anything, even on dev boards. That is usually done with
Yes, that gives the same crash after attempting unlock. Before starting this thread, I unlocked using ST Visual Programmer, and successfully flashed the .hex file that PIO compiled.
I was able to erase using STVP. I get the same error from stm8flash if I try to reprogram after erasing.
The breakout board I’m using has a separate 4 pins for GND/NRST/SWIM/VCC - I can try using the pin for D1 instead, but it doesn’t seem like it would change, given that STVP can read/write when using the dedicated debug pins
Can you hold down the reset button of the board, invoke OpenOCD, and when OpenOCD output seems to stall, release the reset button? Timing might be a bit tricky, but I’ve seen cases where that actually helps.
This happened if I released the reset button any time before Listening on port 4444 for telnet connections:
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : STLINK V0J12S4 (API v0) VID:PID 0000:0000
Error: init mode failed (unable to connect to the target)
This happened if I released reset after that line appeared:
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: read version failed
Both states would then repeat on any future openocd runs until I disconnected/reconnected the stlink.
Was the NRST line connected between the ST-Link and target at that moment? What happens when you disconnect that line and only trigger reset manually via the button?
The upload error on my pio configuration was caused from a corrupt (!) version of stm8flash.exe
… having done an update pio …
*Workaraound:
Resolving this issue for others which also may having this issue, after having updated pio:
Rename in pio-folder C:\Users<username>.platformio\packages\tool-stm8flash stm8flash.exe to stm8flash.exe.nok and libusb-1.0.dll in libusb-1.0.dll.nok
Copy from a working Arduino version these two files in the pio-folder.
Found them in C:\Users<username>\AppData\Local\Arduino15\packages\sduino\tools\STM8Tools\2019.02.05\win
Now: CURRENT: upload_protocol = stlinkv2 Uploading .pio\build\stm8sblue\firmware.hex Determine FLASH area
libusb: error [init_device] device ‘\.\USB#VID_04B4&PID_0060&MI_01#6&2BDC5FE1&1&0001’ is no longer connected! libusb: error [init_device] device ‘\.\USB#VID_0C76&PID_1607&MI_03#6&33B77DAF&0&0003’ is no longer connected! Due to its file extension (or lack thereof), “.pio\build\stm8sblue\firmware.hex” is considered as INTEL HEX format! 1821 bytes at 0x8000… OK Bytes written: 1821 ======================================================================================================================= [SUCCESS] Took 4.18 seconds Before: Building .pio\build\stm8sblue\firmware.hex Configuring upload protocol… AVAILABLE: serial, stlinkv2 CURRENT: upload_protocol = stlinkv2 Uploading .pio\build\stm8sblue\firmware.hex
**** [upload] Error 3221225595* ======================================================================================================================= [FAILED] Took 3.85 seconds ===