cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-detecting comport scripts doesn't works (fix inside)

Phil242
Associate II

Hello,

On my setup impossible to run the 2 scripts auto-detecting the COMPORT of the current plugged board. Wrong COMPORT is returned and the Teraterm macro crash.

I've patched the original scripts to ask you for the COMPORT. Modified files StartTTPL4.bat and StartTTPL5.bat are here: https://github.com/Phil242/STM32-Security-Workshop

You need to drop them in folder C :\STM32SecuWS\Tools\teraterm and that's it.

Regards,

Philippe

13 REPLIES 13
Frantz LEFRERE
ST Employee

Thanks for you contribution, to investigate this issue" Wrong COMPORT" which value was return in your case ?

Phil242
Associate II

I think the enumerator in the "FOR" is getting other things than serials ports.

The "call :getport COMPORT" return the value "850". I'm running a Win7 64bits French.

I did not really investigate the problem, just focus on a quick-fix to complete all the pre-workshop tests before the 26 and the best option was to enter COMPORT manually.

BTW: Another tool who can change your life during development: PopCom ( https://github.com/avishorp/PopCom/releases ). When you insert or remove an USB / COM device, it display a popup with the COM number. A little drawback: there is a little CPU-hogging when the tool is running, but I can live with it on an old core i5 CPU, so it's not really anoying.

Hope it helps.

Frantz LEFRERE
ST Employee

Issue is probably coming from the return value of "mode" bash command...

In the file : C:\STM32SecuWS\Tools\teraterm\StartTTPL4.bat  and C:\STM32SecuWS\Tools\teraterm\StartTTPL5.bat

replace line

  FOR /F "tokens=4 USEBACKQ" %%F IN (`mode`) DO (

by

  FOR /F "tokens=4 USEBACKQ" %%F IN (`mode ^| find "Status for device COM"`) DO (

Any feedback is welcome, as I can't reproduce the issue.

Phil242
Associate II

Here is the output with the modifier "for":

C:\STM32SecuWS\Tools\teraterm>StartTTPL4-V2.bat

Return : COMPORT

comport : 850

C:\STM32SecuWS\Tools\teraterm>C:\STM32SecuWS\Tools\teraterm\\ttpmacro.exe C:\STM32SecuWS\Tools\teraterm\\ttlMacro_Startup_L4.ttl 850

C:\STM32SecuWS\Tools\teraterm>goto end

C:\STM32SecuWS\Tools\teraterm>endlocal

C:\STM32SecuWS\Tools\teraterm>Rem

C:\STM32SecuWS\Tools\teraterm>

Same problem, but less output, the added "find" as done some filtering.

Here is an output without the "@echo off":

C:\STM32SecuWS\Tools\teraterm>StartTTPL4-V2.bat

C:\STM32SecuWS\Tools\teraterm>Rem @echo off

C:\STM32SecuWS\Tools\teraterm>setlocal

C:\STM32SecuWS\Tools\teraterm>SET MYSCRIPT=StartTTPL4-V2.bat

C:\STM32SecuWS\Tools\teraterm>Rem echo on

C:\STM32SecuWS\Tools\teraterm>SET DIR_MYSCRIPT=C:\STM32SecuWS\Tools\teraterm\

C:\STM32SecuWS\Tools\teraterm>call :getport COMPORT

C:\STM32SecuWS\Tools\teraterm>FOR /F "tokens=4 USEBACKQ" %F IN (`mode | find "Status for device COM"`) DO (

echo %F

 if %F NEQ CON: SET COMPORT=%F

)

C:\STM32SecuWS\Tools\teraterm>echo Return : COMPORT

Return : COMPORT

C:\STM32SecuWS\Tools\teraterm>GOTO :EOF

C:\STM32SecuWS\Tools\teraterm>if "850" == "" goto ErrorCOM

C:\STM32SecuWS\Tools\teraterm>if "850" == "CON:" goto ErrorCOM

C:\STM32SecuWS\Tools\teraterm>SET TT_MACRO_FILE=C:\STM32SecuWS\Tools\teraterm\\ttlMacro_Startup_L4.ttl

C:\STM32SecuWS\Tools\teraterm>SET TT_MACRO_EXE=C:\STM32SecuWS\Tools\teraterm\\ttpmacro.exe

C:\STM32SecuWS\Tools\teraterm>echo comport : 850

comport : 850

C:\STM32SecuWS\Tools\teraterm>C:\STM32SecuWS\Tools\teraterm\\ttpmacro.exe C:\STM32SecuWS\Tools\teraterm\\ttlMacro_Startup_L4.ttl 850

C:\STM32SecuWS\Tools\teraterm>goto end

C:\STM32SecuWS\Tools\teraterm>endlocal

C:\STM32SecuWS\Tools\teraterm>Rem

The COM55: (my current COMPORT for the plugged board) is missing, meaning the "find" is too restrictive.

Here is a full dump with the original script:

C:\STM32SecuWS\Tools\teraterm>StartTTPL4.bat

C:\STM32SecuWS\Tools\teraterm>Rem @echo off

C:\STM32SecuWS\Tools\teraterm>setlocal

C:\STM32SecuWS\Tools\teraterm>SET MYSCRIPT=StartTTPL4-V2.bat

C:\STM32SecuWS\Tools\teraterm>Rem echo on

C:\STM32SecuWS\Tools\teraterm>SET DIR_MYSCRIPT=C:\STM32SecuWS\Tools\teraterm\

C:\STM32SecuWS\Tools\teraterm>call :getport COMPORT

C:\STM32SecuWS\Tools\teraterm>FOR /F "tokens=4 USEBACKQ" %F IN (`mode`) DO (

echo %F

 if %F NEQ CON: SET COMPORT=%F

)

C:\STM32SecuWS\Tools\teraterm>(

echo COM3:

 if COM3: NEQ CON: SET COMPORT=COM3:

)

COM3:

C:\STM32SecuWS\Tools\teraterm>(

echo 8

 if 8 NEQ CON: SET COMPORT=8

)

8

C:\STM32SecuWS\Tools\teraterm>(

echo COM5:

 if COM5: NEQ CON: SET COMPORT=COM5:

)

COM5:

C:\STM32SecuWS\Tools\teraterm>(

echo 8

 if 8 NEQ CON: SET COMPORT=8

)

8

C:\STM32SecuWS\Tools\teraterm>(

echo COM6:

 if COM6: NEQ CON: SET COMPORT=COM6:

)

COM6:

C:\STM32SecuWS\Tools\teraterm>(

echo 8

 if 8 NEQ CON: SET COMPORT=8

)

8

C:\STM32SecuWS\Tools\teraterm>(

echo COM4:

 if COM4: NEQ CON: SET COMPORT=COM4:

)

COM4:

C:\STM32SecuWS\Tools\teraterm>(

echo 8

 if 8 NEQ CON: SET COMPORT=8

)

8

C:\STM32SecuWS\Tools\teraterm>(

echo COM55:

 if COM55: NEQ CON: SET COMPORT=COM55:

)

COM55:

C:\STM32SecuWS\Tools\teraterm>(

echo 8

 if 8 NEQ CON: SET COMPORT=8

)

8

C:\STM32SecuWS\Tools\teraterm>(

echo CON:

 if CON: NEQ CON: SET COMPORT=CON:

)

CON:

C:\STM32SecuWS\Tools\teraterm>(

echo 850

 if 850 NEQ CON: SET COMPORT=850

)

850

C:\STM32SecuWS\Tools\teraterm>echo Return : COMPORT

Return : COMPORT

C:\STM32SecuWS\Tools\teraterm>GOTO :EOF

C:\STM32SecuWS\Tools\teraterm>if "850" == "" goto ErrorCOM

C:\STM32SecuWS\Tools\teraterm>if "850" == "CON:" goto ErrorCOM

C:\STM32SecuWS\Tools\teraterm>SET TT_MACRO_FILE=C:\STM32SecuWS\Tools\teraterm\\ttlMacro_Startup_L4.ttl

C:\STM32SecuWS\Tools\teraterm>SET TT_MACRO_EXE=C:\STM32SecuWS\Tools\teraterm\\ttpmacro.exe

C:\STM32SecuWS\Tools\teraterm>echo comport : 850

comport : 850

C:\STM32SecuWS\Tools\teraterm>C:\STM32SecuWS\Tools\teraterm\\ttpmacro.exe C:\STM32SecuWS\Tools\teraterm\\ttlMacro_Startup_L4.ttl 850

C:\STM32SecuWS\Tools\teraterm>goto end

C:\STM32SecuWS\Tools\teraterm>endlocal

C:\STM32SecuWS\Tools\teraterm>Rem

C:\STM32SecuWS\Tools\teraterm>

Sorry to not dig a little more, but this evening I'll look deeper. Maybe with those traces you can have more clues to spot the problem.

(but keep in mind the problem is -badly- solved by entering the port number by hand and that'll not stop me for Friday 26).

Jocelyn RICARD
ST Employee

Hello Phil,

could you please give the output of mode command ?

Thank you

Best regards

Jocelyn

Phil242
Associate II

Here it is:

C:\STM32SecuWS\Tools\teraterm>mode

Statut du périphérique COM3:

----------------------------

   Baud :           115200

   Parité :         None

   Bits de données : 8

   Bits d'arrêt :   1

   Temporisation :  OFF

   XON/XOFF :       OFF

   Protocole CTS :  OFF

   Protocole DSR :  OFF

   Sensibilité DSR : OFF

   Circuit DTR :    OFF

   Circuit RTS :    OFF

Statut du périphérique COM5:

----------------------------

   Baud :           0

   Parité :         None

   Bits de données : 8

   Bits d'arrêt :   1

   Temporisation :  OFF

   XON/XOFF :       OFF

   Protocole CTS :  OFF

   Protocole DSR :  OFF

   Sensibilité DSR : OFF

   Circuit DTR :    OFF

   Circuit RTS :    OFF

Statut du périphérique COM6:

----------------------------

   Baud :           0

   Parité :         None

   Bits de données : 8

   Bits d'arrêt :   1

   Temporisation :  OFF

   XON/XOFF :       OFF

   Protocole CTS :  OFF

   Protocole DSR :  OFF

   Sensibilité DSR : OFF

   Circuit DTR :    OFF

   Circuit RTS :    OFF

Statut du périphérique COM4:

----------------------------

   Baud :           0

   Parité :         None

   Bits de données : 8

   Bits d'arrêt :   1

   Temporisation :  OFF

   XON/XOFF :       OFF

   Protocole CTS :  OFF

   Protocole DSR :  OFF

   Sensibilité DSR : OFF

   Circuit DTR :    OFF

   Circuit RTS :    OFF

Statut du périphérique COM55:

-----------------------------

   Baud :           0

   Parité :         Odd

   Bits de données : 8

   Bits d'arrêt :   1

   Temporisation :  OFF

   XON/XOFF :       OFF

   Protocole CTS :  OFF

   Protocole DSR :  OFF

   Sensibilité DSR : OFF

   Circuit DTR :    OFF

   Circuit RTS :    ON

Statut du périphérique CON:

---------------------------

   Lignes :         2260

   Colonnes :       160

   Vitesse clavier : 31

   Délai clavier :  1

   Page de codes :  850

C:\STM32SecuWS\Tools\teraterm>

The Nucleo-L476 is port "COM55:".

Jocelyn RICARD
ST Employee

Hi Phil,

ok thank you. I could debug the issue.

Issue comes from the very last line that is different in french =)

So, the good fix should be:

In the 2 files:

C:\STM32SecuWS\Tools\teraterm\StartTTPL4.bat

C:\STM32SecuWS\Tools\teraterm\StartTTPL5.bat

replace line

  FOR /F "tokens=4 USEBACKQ" %%F IN (`mode`) DO (

by

  FOR /F "tokens=4 USEBACKQ" %%F IN (`mode ^| find " COM"`) DO (

  

Best regards

Jocelyn

Phil242
Associate II

So, this last one was the good one !

Sorry to not investigate more, but I was out of time this whole day ...

I have update the GitHub with 2 working scripts and 2 other in fallback mode, asking you for the COMPORT:

https://github.com/Phil242/STM32-Security-Workshop

Thanks for the support, see you friday.

Philippe

Doesn't work as well for me. Managed to launch manually.