cancel
Showing results for 
Search instead for 
Did you mean: 

Anyone successfully using Cube Programmer C++ API?

VMüll.1
Associate II

Haven't found anyone talking about the new API here.

I'm trying to code a program that flashes a STM32F334, reads processor's UID and post it to a proprietary database. STM32CubeIDE and CubeProgrammer works fine. I also managed to run C++ API and identify the STLink probe, but it doesn't connect to the device.

When trying to connect to device via C++ API, I get this error:

STM32CubeProgrammer API v2.5.0
STLinkUSBDriver.dll loaded
STLinkUSBDriver.dll loaded
STLinkUSBDriver.dll loaded
ST-LINK SN  : 0676FF505150807567112946
ST-LINK FW  : V2J36M26
Board       : NUCLEO-L053R8
Voltage     : 0.01V
SWD freq    : 4000 KHz
Connect mode: Normal
Reset mode  : Core reset
Error: Unable to list supported devices
Error: Cannot identify the device
Establishing connection with the device failed 
Disconnected from device.

I'm running on MacOs 10.15.6. This is my source code:

#include <iostream>
#include <string>
#include <CubeProgrammer_API.h>
#include <DeviceDataStructure.h>
#include <DisplayManager.h>
 
using namespace std;
 
extern unsigned int verbosityLevel;
 
void stLinkInit()
{
	int ret = 0;
    const char* loaderPath = "./.";
    displayCallBacks vsLogMsg;
 
    /* Set device loaders path that contains FlashLoader and ExternalLoader folders*/
	setLoadersPath(loaderPath);
 
    /* Set the progress bar and message display functions callbacks */
	vsLogMsg.logMessage = DisplayMessage;
	vsLogMsg.initProgressBar = InitPBar;
	vsLogMsg.loadBar = lBar;
    setDisplayCallbacks(vsLogMsg);
 
    /* Set DLL verbosity level */
    setVerbosityLevel(verbosityLevel = VERBOSITY_LEVEL_3);
}
 
int main()
{
	stLinkInit();
 
	debugConnectParameters *stLinkList;
	debugConnectParameters debugParameters;
 
	int getStlinkListNb = getStLinkList(&stLinkList, 0);
	
	stLinkList[0].connectionMode = NORMAL_MODE;
	stLinkList[0].resetMode = CORE_RESET;
 
	/* Target connect */
	int connectStlinkFlag = connectStLink(stLinkList[0]); 
	if (connectStlinkFlag != 0) {
		logMessage(Error, "Establishing connection with the device failed blerg\n");
		disconnect();
	}
	else {
		logMessage(GreenInfo, "\n--- Device %d Connected --- \n",index);
	}
 
  	return 0;
}

​Just in case, this is my Makefile for the project:

# Compiler
CC = clang++
 
# INCLUDE_PATH = -I/usr/local/opt/curl/include
INCLUDE_PATH = -I/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/api/include
 
# LIB_PATH = -L/usr/local/opt/curl/lib -lcurl
LIB_PATH = -L/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin -lCubeProgrammer_API
 
#
# Compilation and linking
#
# Add this to shell's vars: DYLD_LIBRARY_PATH=/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin
all: main.o DisplayManager.o
	${CC} -g ./out/main.o ./out/DisplayManager.o ${LIB_PATH} -o ./out/main.out 
 
main.o:
	${CC} -g -c main.cpp ${INCLUDE_PATH} -o ./out/main.o
 
DisplayManager.o:
	${CC} -g -c DisplayManager.cpp ${INCLUDE_PATH} -o ./out/DisplayManager.o
 
clean:
	rm -r ./out/*

17 REPLIES 17
FDarr.1
Associate II

Hi,

You can not do :

stLinkList[0].connectionMode = NORMAL_MODE;
stLinkList[0].resetMode = CORE_RESET;

You have to do "first a local copy"..

debugConnectParameters debugParameters;
 
debugParameters = stLinkList[0];
debugParameters.connectionMode = NORMAL_MODE;
debugParameters.resetMode = CORE_RESET;
debugParameters.shared = 0;
 
int connectStlinkFlag = connectStLink(debugParameters);

I think this will work 😉

Have a nice day

Thanks for your answer! I’ve tried that but the error still the same
FDarr.1
Associate II

Sorry I don't read clearly your error : "Error: Unable to list supported devices"

This is a loader path error :

your loader path is the current running directory

const char* loaderPath = "./.";
setLoadersPath(loaderPath);

and you need to have the FlashLoader directory inside with all the loader files inside

If this is OK, try to change your running directory path with short name et no special caract..., I have some problem with path name on my computer...

OGuan.1
Associate II

Hello, what I know is that it is possible to use the ST official absolute path, but the folder you copied is not working. I tried to solve this problem, but it has not yet. If you solve it, please let me know. Thank you

Actually I gave up using the C++ API.

I was able to achieve my goal with a shell script based on STM32CubeProgrammer 2.5.0 terminal commands. Sometimes it fails to connect to the device for no reason at all and I need to restart the computer, but it generally works.

I wish ST had a better documentation on the C++ API though

I am glad that you have achieved this goal through other methods, but I will try to solve this problem for the time being.

Please let me know when you solve it!

I am very happy to do this, as far as the current situation is concerned, I can't find a better way, I might give it up!

Kraal
Senior III

Hi,

Maybe it is a dumb question, but in the original post, the voltage is read as 0.01V

Could it be the issue ?