GangFlasher-ST DLL basic example

Writing custom applications using the GangFlasher (GF) DLL can be easily started with a basic programming sequence. This tutorial is intended to provide a simplified setup for programming a single STM32MP1 board (STM32MP157A-EV1). GangFlasher libraries are provided within default installation directory (C:/Elprotronic/GangFlasher-ST). Steps for similar boards, i.e. STM32MP157A-EV1 or STM32MP157F-DK2, are the same.

We will begin by extracting a working configuration from the GUI, and follow by using it in the DLL.

1. GF DLL Windows example (Microsoft Visual Studio)

1.1 GUI configuration export

Start GangFlasher-ST GUI, choose MP1 microprocessor and corresponding TSV file.

GF_EV1.png
GangFlasher-ST GUI example configuration

In GangFlasher-ST GUI, save configuration by going to “File->Save Setup as”.

GF_EV1_setup.png
GangFlasher-ST GUI save configuration

Subsequently, the saved or default configuration file can be imported in your application by using the DLL function F_LoadTargetConfig("C:/Users/Public/lastused_gfst_prog_setup.cfg") : the file C:/Users/Public/lastused_gfst_prog_setup.cfg is created by the GUI every time it is closed containing the latest settings.

1.2 Example with manual configuration

The aforementioned configuration and programming shown in the GUI can be ran using DLL functions from your application. Start Microsoft Visual Studio with new project.

Copy source into project cpp file. The example shown below will also print output status.

#include <iostream> #include "GangFlasher-Dll.h" #define COMMi(s) printf(#s" : %i\n", s); //execute function with integer return #define COMMs(s) printf(#s" : %s\n", s); //execute function with string return int main(void) { char BoardName[] = "STM32MP157A-EV1"; COMMi(F_Set_License_Dir("C:/Elprotronic/GangFlasher-ST/License")); COMMi(F_Set_Startup_Dir_ecosystem_4_0("C:/Elprotronic/GangFlasher-ST/Startup_Ecosystem_4_0")); COMMi(F_Init()); COMMi(F_Set_MPU_name(BoardName)); COMMi(F_USBAutoScanAndAssign()); COMMi(F_Load_OS()); /* Update path to Starter Package for example Ecosystem 4 and uncomment */ //COMMi(F_SetTSVTargetDirectory("C:/ST_Starter_Packages/ST_Toolkit_v4/")); //COMMi(F_LoadTSVFile("C:/ST_Starter_Packages/ST_Toolkit_v4/flashlayout_st-image-weston/trusted/FlashLayout_sdcard_stm32mp157a-ev1-trusted.tsv")); //COMMi(F_AutoProgram()); COMMi(F_DeInit()); return 0; };

Optionally, open cmd window and create necessary hard links (header file, GangFlasher libraries and license libraries) if you are running your example from another directory:

mklink /H GangFlasher-Dll.h C:\Elprotronic\GangFlasher-ST\GangFlasher-Dll.h mklink /H GangFlasher.lib C:\Elprotronic\GangFlasher-ST\GangFlasher.lib mklink /H GangFlasher.dll C:\Elprotronic\GangFlasher-ST\GangFlasher.dll mklink /H HSM_P11_Lib.dll C:\Elprotronic\GangFlasher-ST\HSM_P11_Lib.dll mklink /H libeay32.dll C:\Elprotronic\GangFlasher-ST\libeay32.dll mklink /H LicenseSpringVMD.dll C:\Elprotronic\GangFlasher-ST\LicenseSpringVMD.dll

Follow by adding GangFlasher library to project.

Power up ST Evaluation board STM32MP157A-EV1 and connect to PC. Open Device Manager for STLink COM port number and view UART logs via Putty (this is example terminal emulator, there are also TeraTerm and many other emulators). If the board does not show up in the device manager, you might need to install the default STM32CubeProg package from ST (including USB drivers).

Compile and run example project. Optionally one can download ST Starter Project and use it for AutoProgram functionality (please update paths and uncomment source file).

2. GF DLL Linux example (GNU C Compiler)

2.1 Example with manual configuration

To run GangFlasher-ST library example simply download GangFlasher-ST Linux installer DEB-package and execute commands:

sudo dpkg -i libgangflasher_amd64.deb mkdir GF_DLL_example/ && cd GF_DLL_example/ vi main.cpp

Secondly start UART log terminal session and start program execution in second terminal:

3. License activation

License could be easily activated with usage of GangFlasher GUI or DLL. GUI option is shown in the screenshot below.:

License can also be activated and deactivated from DLL as well, using F_ActivateLicenseKey("AAAA-AAAA-AAAA-AAAA") and F_DeactivateCurrentLicense() functions respectively.