[Solved] Eclipse (sloeber) and ST-Linkv2 upload

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
Post Reply
democles9308
Posts: 5
Joined: Fri Oct 13, 2017 6:57 pm

[Solved] Eclipse (sloeber) and ST-Linkv2 upload

Post by democles9308 » Sun Nov 12, 2017 8:46 pm

Hello you all,
BLUF : I cant get my code uploaded via a clone ST-LinkV2.

what I did:
- installed Jantjes Sloeber V4.1 (product, not plugin) under /opt/sloeber,
- added the stm32duino json file from http://dan.drown.org/stm32duino/package ... index.json under Arduino >Preferences>Arduino>3d partyindex url,
- added via the boardmanager, the arduino SAM boards to get the ARM-compiler,
- created all the udev rules for the boards and the ST-link dongle and reloaded them.

I can compile and build the code of a simple STM blink project but I can't get it uploaded to the board from within eclipse/sloeber. For the ST-link you don't need to specify a comport, not ? I don't get one
I can upload the bin file created by sloeber via the stlink write <binfile> 0x8000000 command in a terminal. (see printscreen below)

Can someone point me to a direction to solve this ? I must solve this before I can continue to usem my STLINK for debugging with OPENOCD from eclipse
I modified already the board.txt file for the generic F103C8 boards by changing the genericSTM32F103C.upload.tool=stlink_upload. This invokes the stlink_upload file but without success... it seems it needs a /dev/TTYACM0 link after all.. so udev problem ?

Many thanks already
Attachments
upload_failed.png
sloeber upload no go
upload_failed.png (134.14 KiB) Viewed 100 times
Screenshot from 2017-11-12 20-44-56.png
uploading working via ST-link under tools
Screenshot from 2017-11-12 20-44-56.png (228.8 KiB) Viewed 100 times
properties.png
my settings for the project
properties.png (82.3 KiB) Viewed 100 times
Last edited by democles9308 on Tue Nov 14, 2017 9:36 pm, edited 1 time in total.

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Eclipse (sloeber) and ST-Linkv2 upload

Post by Pito » Sun Nov 12, 2017 9:23 pm

I do not use the ST_Link for upload under Sloeber, but Jlink (F4) or stm32duino bootloader (F1).
I've tried with ST_Link, getting similar result as you got. Win7 here.
It seems the loader still calls maple_upload.
The Sloeber reads the boards.txt, so perhaps a problem with stlink upload definitions.
I've changed to:

Code: Select all

#genericSTM32F103C.upload.tool=maple_upload
#genericSTM32F103C.upload.protocol=maple_dfu
genericSTM32F103C.upload.protocol=STLink
genericSTM32F103C.upload.tool=stlink_upload
(you have to open the Arduino settings and click Apply and rebuild in order the changes in boards.txt are taken over)
and the stlink starts to work, connects to BluePill, but it cannot find the file because the stlink is getting wrong params probably:

Code: Select all

../win/stlink_upload.bat COM36 1EAF:0003 C:\Users\xxxxx\Sloeber\Ice40_Read_1/Release/Ice40_Read_1.bin 
Output:
STM32 ST-LINK CLI v2.1.0
STM32 ST-LINK Command Line Interface

ST-LINK SN : xxxxxxxxxx
ST-LINK Firmware version : V2J27S6
Connected via SWD.
SWD Frequency = 1800K.
Connection mode : Normal.
Device ID:0x410 
Device flash Size : 64 Kbytes
Device family :STM32F10xx Medium-density

Loading file...
Unable to open file!
The stlink_upload.bat (stm32/tools/win):

Code: Select all

@echo off
rem: Note %~dp0 get path of this batch file
rem: Need to change drive if My Documents is on a drive other than C:
set driverLetter=%~dp0
set driverLetter=%driverLetter:~0,2%
%driverLetter%
cd %~dp0
rem: the two line below are needed to fix path issues with incorrect slashes before the bin file name
set str=%4
set str=%str:/=\%


rem: ------------- use STLINK CLI
stlink\ST-LINK_CLI.exe -c SWD -P %str% 0x8000000 -Rst -Run

rem: Using the open source texane-stlink instead of the proprietary STM stlink exe
rem:texane-stlink\st-flash.exe write %str% 0x8000000
With echo commented out you may see the garbage:

Code: Select all

..\tools\win>stlink\ST-LINK_CLI.exe -c SWD -P /=\ 0x8000000 -Rst -Run 
When I force the correct path (I edited the stlink_upload.bat) then it uploads fine after the build:

Code: Select all

..\tools\win>stlink\ST-LINK_CLI.exe -c SWD -P C:\Users\xxxxxxxxx\Sloeber\Ice40_Read_1\Release\Ice40_Read_1.bin 0x8000000 -Rst -Run 
STM32 ST-LINK CLI v2.1.0
STM32 ST-LINK Command Line Interface

ST-LINK SN : xxxxxxxxxxxxxxxxxx
ST-LINK Firmware version : V2J27S6
Connected via SWD.
SWD Frequency = 1800K.
Connection mode : Normal.
Device ID:0x410 
Device flash Size : 64 Kbytes
Device family :STM32F10xx Medium-density

Loading file...
Flash Programming:
  File : C:\Users\xxxxxx\Sloeber\Ice40_Read_1\Release\Ice40_Read_1.bin
  Address : 0x08000000
Flash memory programming...
±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± 0%
 0%ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ 46%ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ 92%ÛÛÛÛ 100%
Flash memory programmed in 2s and 371ms.
Programming Complete.

MCU Reset.

Application started.
and it works :)

So there are 3 issues:
1. to fix the boards.txt such it evokes the stlink upload method properly,
2. to fix the stlink_upload.bat such it reads the correct path of the binary,
3. implement the fixes into the linux version, when applicable.. ;)
Pukao Hats Cleaning Services Ltd.

democles9308
Posts: 5
Joined: Fri Oct 13, 2017 6:57 pm

Re: Eclipse (sloeber) and ST-Linkv2 upload

Post by democles9308 » Mon Nov 13, 2017 7:47 pm

Hi Pito,

Many thanks for your quick reply !

In the boards file I changed the settings to

Code: Select all

genericSTM32F103C.upload.protocol=STLink
genericSTM32F103C.upload.tool=stlink_upload
When I plug in my STLinkV2 stick, the following is reported in the logs

Code: Select all

[   29.883973] usb 3-2: new full-speed USB device number 13 using xhci_hcd
[   30.053106] usb 3-2: New USB device found, idVendor=0483, idProduct=3748
[   30.053107] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   30.053108] usb 3-2: Product: STM32 STLink
[   30.053108] usb 3-2: Manufacturer: STMicroelectronics
[   30.053109] usb 3-2: SerialNumber: Hÿkf\xffffffc2\xffffff87PQ@g
and no /dev/ttyACMx link is created

when compiling in Sloeber everything works and the stlink_upload script is launched which does not work because no 'comport' is provided as an argument and the id of the STlink stick <0483:3748> does not pass the tests

Code: Select all

#!/bin/bash

# Check for leaf device.
function leaf_status()
{
this_leaf_status=$(lsusb |grep "lEAF" | awk '{ print $NF}')            <<<<<<< will return nothing 
# Find the mode of the leaf bootloader
case $this_leaf_status in
   "1eaf:0003")
      echo "dfu"
   ;;
   "1eaf:0004")
      echo "ttyACMx"
   ;;
   *)
      #echo "$this_leaf_status"
      echo "unknown"
   ;;
esac
}

# You will need the usb-reset code, see https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Using-a-generic-stm32-board-on-linux-with-Maple-bootloader
#
USBRESET=$(which usb-reset) || USBRESET="./usb-reset"

# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
echo "USB Status [$LEAF_STATUS]"

$(dirname $0)/stlink/st-flash write "$4" 0x8000000  

sleep 4
# Reset the usb device to bring up the tty rather than DFU, 
"$USBRESET" "/dev/bus/usb/$(lsusb |grep "leaf" |awk '{print $2,$4}'|sed 's/\://g'|sed 's/ /\//g')" >/dev/null 2>&1
# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
echo "USB Status [$LEAF_STATUS]"
# Check to see if the tty came up
TTY_DEV=$(find /dev -cmin -2 |grep ttyAC)
echo -e "Waiting for tty device $TTY_DEV \n"
sleep 20
echo -e "$TTY_DEV should now be available.\n"
exit 0
I modified the stlink_uploadscript and then it works but with remarks on the TTY stuff.

Code: Select all

# Check for leaf device.
function leaf_status()
{

this_leaf_status=$(lsusb |grep "0483" | awk '{ print $NF}')      <<<<<<<<<<<<<<<<< changed grep "0483"
# Find the mode of the leaf bootloader
case $this_leaf_status in
   "1eaf:0003")
      echo "dfu"
   ;;
   "1eaf:0004")
      echo "ttyACMx"
   ;;
   "ST-LINK/V2")                                                <<<<<<< added this  the result given by this_leaf_status
      echo "STLINK"
   ;;
   *)
      #echo "$this_leaf_status"
      echo "unknown"
   ;;
esac
}

# You will need the usb-reset code, see https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Using-a-generic-stm32-board-on-linux-with-Maple-bootloader
#
USBRESET=$(which usb-reset) || USBRESET="./usb-reset"

# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
echo "USB Status [$LEAF_STATUS]"

$(dirname $0)/stlink/st-flash write "$1" 0x8000000                                 <<<<<<<<<<< changed $4 was $1 as this gives the bin file

sleep 4
# Reset the usb device to bring up the tty rather than DFU, 0483 was leaf
"$USBRESET" "/dev/bus/usb/$(lsusb |grep "leaf" |awk '{print $2,$4}'|sed 's/\://g'|sed 's/ /\//g')" >/dev/null 2>&1
# Check to see if a maple compatible board is attached
LEAF_STATUS=$(leaf_status)
echo "USB Status [$LEAF_STATUS]"
# Check to see if the tty came up
TTY_DEV=$(find /dev -cmin -2 |grep ttyAC)
echo -e "Waiting for tty device $TTY_DEV \n"
sleep 20
echo -e "$TTY_DEV should now be available.\n"
exit 0
So I made some progress, I have to rewrite my own stlink_upload it should be working (just removing the nod needed code in the above script.

I could mark this as solved but I'm waiting for a last update from your side or somebody else :-)

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Eclipse (sloeber) and ST-Linkv2 upload

Post by Pito » Mon Nov 13, 2017 9:56 pm

I do not understand why the change in boards.txt is needed - why it does not read the STLink upload method properly..
Most probably some of the directives formats in boards.txt are not up to date.
Sometimes are people get surprised something does not work - mostly because nobody is using that feature thus it stay defunct.. :)
Pukao Hats Cleaning Services Ltd.

democles9308
Posts: 5
Joined: Fri Oct 13, 2017 6:57 pm

Re: Eclipse (sloeber) and ST-Linkv2 upload

Post by democles9308 » Tue Nov 14, 2017 9:36 pm

Hi Pito,
I think this is related to Sloeber's plugin. :roll:
When you change the uploadmethod, it does not change the command accordingly. When you change the upload method in the projects properties> Arduino>Upload method ( to STM32duino bootlader for instance) you'll see that under the Properties>C/C++Build>Environment the variable JANTJE.MENU.UPLOAD_METHOD changes (DFUUPLOADMETHOD) but the JANTJE.UPLOAD.PATTERN does not. (see screenshot)

But I can use my modified script so my first problem is solved.... now up to the next get the debugging working via OPENOCD. I saw some info on the forum already.
Many thanks !
Attachments
envvars.png
envvars.png (124.2 KiB) Viewed 35 times

Post Reply