2021-08-20 09:50 AM
I'm coming across a strange issue, and the documentation for the API isn't really helping much. I've got a small application to load some firmware using the CubeProgrammer_API, and it works perfectly if I point setLoadersPath() to "C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin". However, I'd like to include the FlashLoader files with my project so that STM32CubeProgrammer isn't required to be installed with my software. I copied over the FlashLoader folder and pointed the function to the directory the FlashLoader folder is in, but now when I call connectUsartBootloader(), it fails and returns -5: CUBEPROGRAMMER_ERROR_NOT_SUPPORTED. Any ideas? What exactly am I missing?
Solved! Go to Solution.
2021-08-26 08:10 AM
Hi @MDunn.2
Sorry It is a typo error , I mean *stldr files.
Don't forget please the DataBase folder also, it must be located in same level than \bin folder.
Houda
2021-08-26 05:45 AM
2021-08-26 05:59 AM
UsartConnectParameters uartParams = new UsartConnectParameters();
// Port name array must have exactly 100 bytes in order to be passed into DLL correctly.
uartParams.portName = new byte[100];
Encoding.ASCII.GetBytes(theState.ComPort).CopyTo(uartParams.portName, 0);
uartParams.baudrate = 115200;
uartParams.parity = UsartParity.EVEN;
uartParams.dataBits = 8;
uartParams.stopBits = 1.0f;
uartParams.flowControl = UsartFlowControl.OFF;
uartParams.noInitBits = 0;
uartParams.rdu = 0;
// Get the path of the executable. The FlashLoader folder should be located in this directory.
string exeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string folderPath = System.IO.Path.GetDirectoryName(exeFilePath);
// TODO: REMOVE THIS!! For some reason the FlashLoader folder only seems to work from the installed directory.
folderPath = "C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\api\\lib";
// Set up CubeProgrammer API
SetLoadersPath(folderPath);
SetDisplayCallbacks(InitProgressBarCallback, MessageReceivedCallback, ProgressBarUpdateCallback);
SetVerbosityLevel(verbosityLevel);
try
{
// Connect to the bootloader (in another thread so GUI continues to function)
CubeProgrammerError errorCode = await Task.Run(() => ConnectUsartBootloader(uartParams));
if (errorCode != 0)
{
throw new InvalidOperationException($"Unable to connect to Bootloader.\nError Code: {(int)errorCode} - {errorCode}");
}
// Send the firmware file to the bootloader (in another thread so GUI continues to function)
errorCode = await Task.Run(() => DownloadFile(openFileDialog.FileName, 0x08000000, 0, 1, ""));
if (errorCode != 0)
{
throw new InvalidOperationException($"Unable to download {openFileDialog.SafeFileName}.\nError Code: {(int)errorCode}:{errorCode}");
}
// Begin execution of firmware (in another thread so GUI continues to function)
errorCode = await Task.Run(() => Execute(0x08000000));
if (errorCode != 0)
{
throw new InvalidOperationException($"Unable to begin execution of new firmware.\nError Code: {(int)errorCode} - {errorCode}");
}
MessageBox.Show(openFileDialog.SafeFileName + " Loaded.\nPower off the unit and set dipswitch back to \"KEEP OFF\"", "Success");
}
catch ( InvalidOperationException exception )
{
MessageBox.Show(exception.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
// Disconnect the API from the bootloader.
Disconnect();
I created a C# wrapper class so I can use the CubeProgrammer_API in .Net, and it works fine with the TODO in there. I have copied the FlashLoader folder into the same directory as the executable, but whenever I remove the TODO portion, I get the CUBEPROGRAMMER_ERROR_NOT_SUPPORTED error. I even get the same issue in the UART_Example project included with CubeProgrammer.
2021-08-26 07:14 AM
one more point please, the Flashloader files should be located in the same directory structure as in CubeProgrammer I mean "LocalFolder"\FlashLoader\*.dll , is it the case?
Houda
2021-08-26 07:25 AM
I'm not sure what you mean. There are no DLL files in the FlashLoader folder. I've got the CubeProgrammer_API.dll and all the dependencies in the same folder as the executable, along with the FlashLoader folder, which I copied straight over from C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin.
2021-08-26 08:10 AM
Hi @MDunn.2
Sorry It is a typo error , I mean *stldr files.
Don't forget please the DataBase folder also, it must be located in same level than \bin folder.
Houda
2021-08-26 09:03 AM
Aha! That fixed it! Thank you so much! I'd recommend adding some commentary about that somewhere in your documentation, I didn't realize the Data_Base folder was required for the API, it isn't mentioned anywhere that I can see.
2021-08-26 09:15 AM
Hi @MDunn.2 ,
Glad to hear that issue is fixed :) .
I'm totally agree with you , we should document more the usage of API.
I will raise this point internally .
Houda