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

Hello,

That's a good observation, but it's not the problem. That's because I didn't connect stlink's vcc detection pin, which is not used for communication.

It is worth to mention that I am able to interact with my device using STMCubeProgrammer, STMCubeProgrammer CLI and STMCube IDE. I would say the problem is something related to the C++ API dependencies/linker.

0693W000008zTbFQAU.pngWhen I succeed, I must share this good news; I use USB_Example as an example;

At first I thought the typesetting was wrong, so I used the same as ST0693W000008zTb5QAE.pngBut he still can't

Until I added this folder, it succeeded!

Sorry, the first picture is at the end

Hi,

Thank you for answering. I thought that if the read Vcc was too low, the API would stop right there but apparently that is not the case.

Best regards and good luck

That's good news!

If I understood correctly, you just added the folder `Data_Base` to your project?

Must be added in the upper directory of the directory where the .exe is located

Ok, I will give it a try. Thanks! Em qua., 14 de abr. de 2021 às 09:36, ST Community escreveu:

Thanks, I made a python module for CubeProgrammer API, and

setLoadersPath + copy of the "Data_Base" fixed my problem.