CubeProgrammer_API.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. /* doxygen documentation */
  2. /*!
  3. * \file CubeProgrammer_API.h
  4. * \mainpage STM32CubeProgrammer API Documentation
  5. * \section intro1 Introduction
  6. * In addition to the graphical user interface and the commandline interface, STM32CubeProgrammer offers a C++ API
  7. * that you could use to develop your own application and benefit of wide range
  8. * of features to program STM32 microcontrollers memories (such as Flash, RAM, and OTP)
  9. * either over debug interface or bootloder interface (USB DFU, UART, I²C, SPI and CAN).
  10. *
  11. * This documentation details all types and functions API to use STM32CubeProgrammer functionalities. \n
  12. *
  13. * \section include STM32CubeProgrammer API package
  14. * The API package is based on the following resources that are ready for use : \n
  15. * <table>
  16. * <tr><th>File <th>Description
  17. * <tr><td>CubeProgrammer_API.h <td>header file contains functions declarations and macro definitions to be used by the CubeProgrammer_API.dll.
  18. * <tr><td>DeviceDataStructure.h <td>header file contains macro definitions to be shared between several functions.
  19. * <tr><td>CubeProgrammer_API.dll/.so/.dylib <td>Dynamic Link Library file contains a library of functions and other informations that can be accessed by windows, linux and MacOs programs.
  20. * <tr><td>CubeProgrammer_API.lib <td>import library for use with MSVC compiler.
  21. * </table>
  22. *
  23. * \section app Application System requirements
  24. * We offer various examples developed for use with Visual Studio and Qt Creator IDEs:
  25. * - Visual Studio project for windows applications under MSVC compiler.
  26. * - Qt project for Windows, Linux and MacOs applications under MinGW compiler.
  27. * \note The attached examples are tested on STM32F429, STM32L4R9 and STM32L452RE Nucleo Boards.
  28. *
  29. * \subsection windows Windows build settings
  30. * To ensure the correct environment for the provided examples, some constraints must be taken into account\n
  31. *
  32. * \subsubsection vs Visual studio
  33. * The code was developed with Microsoft Visual Studio Community 2017 version 15.6.6 with Windows SDK version : 10.0.16299.0
  34. * and it was tested also on Microsoft Visual Studio 2010 \n
  35. * - Verify that the api's lib directory is the default working directory.
  36. * - The debug command is to execute the application that is resided in the output directory.
  37. * - Insert the Additional Include Directories:\n
  38. * <HR>
  39. * \image html link1.jpg \n
  40. * <HR>
  41. * - Indicate the output name and path. \n
  42. * - Insert the Additional Library Directories. \n
  43. * - Insert the Additional Dependencies, The CubeProgrammer_API import library "CubeProgrammer_API.lib" must be added to Linker input\n
  44. * <HR>
  45. * \image html link2.jpg \n
  46. * <HR>
  47. * \note The provided Visual studio project is already configured like the description above and you can change it carefully according to your use case.
  48. * \subsubsection qt Qt creator
  49. * The Qt projects are developed with Qt Creator 4.7.1, Qt 5.11.2 and MinGW 32 bit compiler and also it can be compiled by MinGW x64.\n
  50. * <b> The shadow build option must be disable to inform Qt that the build should be located in the original Qt project directory. </b>
  51. * \note Verify that the following DLLs are placed to /lib in the api package directory :
  52. * <table>
  53. * <tr><td>CubeProgrammer_API.dll <td>FileManager.dll <td>STLinkUSBDriver.dll
  54. * <tr><td>HSM_P11_Lib.dll <td>libeay32.dll <td>libgcc_s_dw2-1.dll
  55. * <tr><td>stlibp11_SAM.dll <td>libstdc++-6.dll <td>libwinpthread-1.dll
  56. * <tr><td>mfc120.dll <td>msvcp120.dll <td>msvcr120.dll
  57. * <tr><td>Qt5Core.dll <td>Qt5SerialPort.dll <td>Qt5Xml.dll
  58. * </table>
  59. *
  60. * \subsection qtlinux Linux build settings
  61. * To correctly build the Qt project in linux platform, you should follow the next 3 steps:
  62. * 1. Select the build configuration in Projects field of the main view. \n
  63. * 2. Disable the Shadow build option. \n
  64. * 3. Go to build environment, add the System Environment variable LD_LIBRARY_PATH and set the path to ../../../../lib \n
  65. * <HR>
  66. * \image html LdLibraryPath.png \n
  67. * <HR>
  68. * * \note Verify that the following Shared Objects are placed to /lib in the STM32CubeProgrammer package directory :
  69. * <table>
  70. * <tr><td>libCubeProgrammer_API.so <td>libCubeProgrammer_API.so.1 <td>libSTLinkUSBDriver.so <td>libFileManager.so.1
  71. * <tr><td>libhsmp11.so <td>libQt5SerialPort.so.5 <td>libQtXml.so.5 <td>libQt5Core.so.5
  72. * <tr><td>libicudata.so.56 <td>libicui18n.so.56 <td>libicuuc.so.56 <td> -
  73. * </table>
  74. *
  75. * \subsection qtMacOS MacOS build settings
  76. * To get the default api folder that is integrated into the STM32CubeProgrammer package already installed, go to \n
  77. * /Application/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/contents/MacOs/api
  78. * \note Verify that the following Mach Objects are placed to /Application/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/contents/MacOs/bin in the STM32CubeProgrammer package directory:
  79. * <table>
  80. * <tr><td>libCubeProgrammer_API.dylib <td>libCubeProgrammer_API.1.dylib <td>libCubeProgrammer_API.1.0.dylib <td>libCubeProgrammer_API.1.0.0.dylib
  81. * <tr><td>libFileManager.dylib <td>libFileManager.1.dylib <td>libFileManager.1.0.dylib <td>libFileManager.1.0.0.dylib
  82. * <tr><td>libSTLinkUSBDriver.dylib <td>libhsmp11.dylib <td>libstP11_SAM.dylib <td>libusb-1.0.0.dylib
  83. * <tr><td>QtSerialPort.framework <td>QtXml.framework <td>QtCore.framework <td> -
  84. * </table>
  85. */
  86. #ifndef CUBEPROGRAMMER_API_H
  87. #define CUBEPROGRAMMER_API_H
  88. #ifdef __cplusplus
  89. extern "C" {
  90. #endif
  91. #include <stdint.h>
  92. #include "DeviceDataStructure.h"
  93. #if (defined WIN32 || defined _WIN32 || defined WINCE)
  94. # define CP_EXPORTS __declspec(dllexport)
  95. #else
  96. # define CP_EXPORTS
  97. #endif
  98. /* -------------------------------------------------------------------------------------------- */
  99. /* Errors Enumerations */
  100. /* -------------------------------------------------------------------------------------------- */
  101. /**
  102. * \enum cubeProgrammerVerbosityLevel
  103. * \brief List of verbosity levels.
  104. */
  105. enum cubeProgrammerVerbosityLevel {
  106. /** no messages ever printed by the library */
  107. CUBEPROGRAMMER_VER_LEVEL_NONE = 0,
  108. /** warning, error and success messages are printed (default) */
  109. CUBEPROGRAMMER_VER_LEVEL_ONE = 1,
  110. /** error roots informational messages are printed */
  111. CUBEPROGRAMMER_VER_LEVEL_TWO = 2,
  112. /** debug and informational messages are printed */
  113. CUBEPROGRAMMER_VER_LEVEL_DEBUG = 3,
  114. /** no progress bar is printed in the output of the library */
  115. CUBEPROGRAMMER_NO_PROGRESS_BAR = 4, /* progress bars are printed only with verbosity level one */
  116. };
  117. /**
  118. * \enum cubeProgrammerError
  119. * \brief List of errors that can be occured.
  120. */
  121. enum cubeProgrammerError {
  122. /** Success (no error) */
  123. CUBEPROGRAMMER_NO_ERROR = 0,
  124. /** Device not connected */
  125. CUBEPROGRAMMER_ERROR_NOT_CONNECTED = -1,
  126. /** Device not found */
  127. CUBEPROGRAMMER_ERROR_NO_DEVICE = -2,
  128. /** Device connection error */
  129. CUBEPROGRAMMER_ERROR_CONNECTION = -3,
  130. /** No such file */
  131. CUBEPROGRAMMER_ERROR_NO_FILE = -4,
  132. /** Operation not supported or unimplemented on this interface */
  133. CUBEPROGRAMMER_ERROR_NOT_SUPPORTED = -5,
  134. /** Interface not supported or unimplemented on this plateform */
  135. CUBEPROGRAMMER_ERROR_INTERFACE_NOT_SUPPORTED = -6,
  136. /** Insufficient memory */
  137. CUBEPROGRAMMER_ERROR_NO_MEM = -7,
  138. /** Wrong parameters */
  139. CUBEPROGRAMMER_ERROR_WRONG_PARAM = -8,
  140. /** Memory read failure */
  141. CUBEPROGRAMMER_ERROR_READ_MEM = -9,
  142. /** Memory write failure */
  143. CUBEPROGRAMMER_ERROR_WRITE_MEM = -10,
  144. /** Memory erase failure */
  145. CUBEPROGRAMMER_ERROR_ERASE_MEM = -11,
  146. /** File format not supported for this kind of device */
  147. CUBEPROGRAMMER_ERROR_UNSUPPORTED_FILE_FORMAT = -12,
  148. /** Refresh required **/
  149. CUBEPROGRAMMER_ERROR_REFRESH_REQUIRED = -13,
  150. /** Refresh required **/
  151. CUBEPROGRAMMER_ERROR_NO_SECURITY = -14,
  152. /** Changing frequency problem **/
  153. CUBEPROGRAMMER_ERROR_CHANGE_FREQ = -15,
  154. /* NB: Remember to update CUBEPROGRAMMER_ERROR_COUNT below. */
  155. /** Other error */
  156. CUBEPROGRAMMER_ERROR_OTHER = -99,
  157. };
  158. /* -------------------------------------------------------------------------------------------- */
  159. /* Bootloader Data Structures and Enumerations */
  160. /* -------------------------------------------------------------------------------------------- */
  161. /**
  162. * \enum usartParity
  163. * \brief The parity bit in the data frame of the USART communication tells the receiving device if there is any error in the data bits.
  164. */
  165. typedef enum usartParity
  166. {
  167. EVEN = 0, /**< Even parity bit. */
  168. ODD = 1, /**< Odd parity bit. */
  169. NONE = 2, /**< No check parity. */
  170. }usartParity;
  171. /**
  172. * \enum usartFlowControl
  173. * \brief UART Flow Control is a method for devices to communicate with each other over UART without the risk of losing data.
  174. */
  175. typedef enum usartFlowControl
  176. {
  177. OFF = 0, /**< No flow control. */
  178. HARDWARE = 1, /**< Hardware flow control : RTS/CTS. */
  179. SOFTWARE = 2, /**< Software flow control : Transmission is started and stopped by sending special characters. */
  180. }usartFlowControl;
  181. /**
  182. * \struct dfuDeviceInfo
  183. * \brief Get DFU device informations .
  184. */
  185. typedef struct dfuDeviceInfo
  186. {
  187. char usbIndex[10]; /**< USB index. */
  188. int busNumber; /**< Bus number. */
  189. int addressNumber; /**< Address number. */
  190. char productId[100]; /**< Product number. */
  191. char serialNumber[100]; /**< Serial number. */
  192. unsigned int dfuVersion; /**< DFU version. */
  193. }dfuDeviceInfo;
  194. /**
  195. * \struct usartConnectParameters
  196. * \brief Specify the USART connect parameters.
  197. */
  198. typedef struct usartConnectParameters
  199. {
  200. char portName[100]; /**< Interface identifier: COM1, COM2, /dev/ttyS0...*/
  201. unsigned int baudrate; /**< Speed transmission: 115200, 9600... */
  202. usartParity parity; /**< Parity bit: value in usartParity. */
  203. unsigned char dataBits; /**< Data bit: value in {6, 7, 8}. */
  204. float stopBits; /**< Stop bit: value in {1, 1.5, 2}. */
  205. usartFlowControl flowControl; /**< Flow control: value in usartFlowControl. */
  206. unsigned char noinitBits; /**< Set No Init bits: value in {0,1}. */
  207. }usartConnectParameters;
  208. /**
  209. * \struct spiConnectParameters
  210. * \brief Specify the SPI connect parameters.
  211. * \note Recommended SPI parameters : baudrate=375, crcPol=7, direction=0, cpha=0, cpol=0, crc=0, firstBit=1, frameFormat=0, dataSize=1, mode=1, nss=1, nssPulse=1, delay=1
  212. */
  213. typedef struct spiConnectParameters
  214. {
  215. uint32_t baudrate ; /**< Speed transmission 187, 375, 750, 1500, 3000, 6000, 12000 KHz. */
  216. uint16_t crcPol ; /**< crc polynom value. */
  217. int direction ; /**< 2LFullDuplex/2LRxOnly/1LRx/1LTx. */
  218. int cpha ; /**< 1Edge or 2Edge. */
  219. int cpol ; /**< LOW or HIGH. */
  220. int crc ; /**< DISABLE or ENABLE. */
  221. int firstBit ; /**< First bit: LSB or MSB. */
  222. int frameFormat ; /**< Frame format: Motorola or TI. */
  223. int dataSize ; /**< Size of frame data: 16bit or 8bit . */
  224. int mode ; /**< Operating mode: Slave or Master. */
  225. int nss ; /**< Selection: Soft or Hard. */
  226. int nssPulse ; /**< NSS pulse: No Pulse or Pulse. */
  227. int delay ; /**< Delay of few microseconds, No Delay or Delay, at least 4us delay is inserted */
  228. } spiConnectParameters;
  229. /**
  230. * \struct canConnectParameters
  231. * \brief Specify the CAN connect parameters.
  232. * \note Not all configurations are supported by STM32 Bootloader, such as CAN type is STANDARD and the filter should be always activated.
  233. * \note Recommended CAN parameters : br=125000, mode=0, ide=0, rtr=0, fifo=0, fm=0, fs=1, fe=1, fbn=0
  234. */
  235. typedef struct canConnectParameters
  236. {
  237. int br ; /**< Baudrate and speed transmission 125KHz, 250KHz, 500KHz... */
  238. int mode ; /**< CAN mode: NORMAL, LOOPBACK..., */
  239. int ide ; /**< CAN type: STANDARD or EXTENDED. */
  240. int rtr ; /**< Frame format: DATA or REMOTE. */
  241. int fifo ; /**< Memory of received messages: FIFO0 or FIFO1. */
  242. int fm ; /**< Filter mode: MASK or LIST. */
  243. int fs ; /**< Filter scale: 16 or 32. */
  244. int fe ; /**< Filter activation: DISABLE or ENABLE. */
  245. char fbn ; /**< Filter bank number: 0 to 13. */
  246. } canConnectParameters;
  247. /**
  248. * \struct i2cConnectParameters
  249. * \brief Specify the I2C connect parameters.
  250. * \warning The Bootloader Slave address varies depending on the device (see AN2606).
  251. * \note Not all configurations are supported by STM32 Bootloader, such as address in 7 bits form, analog filter: ENABLE, digital filter: DISABLE.
  252. * \note Recommended I2C parameters : add=0x??, br=400, sm=1, am=0, af=1, df=0, dnf=0, rt=0, ft=0
  253. */
  254. typedef struct i2cConnectParameters
  255. {
  256. int add ; /**< Device address in hex format. */
  257. int br ; /**< Baudrate and speed transmission : 100 or 400 KHz. */
  258. int sm ; /**< Speed Mode: STANDARD or FAST. */
  259. int am ; /**< Address Mode: 7 or 10 bits. */
  260. int af ; /**< Analog filter: DISABLE or ENABLE. */
  261. int df ; /**< Digital filter: DISABLE or ENABLE. */
  262. char dnf ; /**< Digital noise filter: 0 to 15. */
  263. int rt ; /**< Rise time: 0-1000 for STANDARD speed mode and 0-300 for FAST. */
  264. int ft ; /**< Fall time: 0-300 for STANDARD speed mode and 0-300 for FAST. */
  265. } i2cConnectParameters;
  266. /* -------------------------------------------------------------------------------------------- */
  267. /* STLINK Data Structures and Enumerations */
  268. /* -------------------------------------------------------------------------------------------- */
  269. /**
  270. * \enum debugResetMode
  271. * \brief Choose the way to apply a system reset.
  272. */
  273. typedef enum debugResetMode
  274. {
  275. SOFTWARE_RESET, /**< Apply a reset by the software. */
  276. HARDWARE_RESET, /**< Apply a reset by the hardware. */
  277. CORE_RESET /**< Apply a reset by the internal core peripheral. */
  278. }debugResetMode;
  279. /**
  280. * \enum debugConnectMode
  281. * \brief Choose the appropriate mode for connection.
  282. */
  283. typedef enum debugConnectMode
  284. {
  285. NORMAL_MODE, /**< Connect with normal mode, the target is reset then halted while the type of reset is selected using the [debugResetMode]. */
  286. HOTPLUG_MODE, /**< Connect with hotplug mode, this option allows the user to connect to the target without halt or reset. */
  287. UNDER_RESET_MODE, /**< Connect with under reset mode, option allows the user to connect to the target using a reset vector catch before executing any instruction. */
  288. PRE_RESET_MODE /**< Connect with pre reset mode. */
  289. }debugConnectMode;
  290. /**
  291. * \enum debugPort
  292. * \brief Select the debug port interface for connection.
  293. */
  294. typedef enum debugPort
  295. {
  296. JTAG = 0, /**< JTAG debug port. */
  297. SWD = 1, /**< SWD debug port. */
  298. }debugPort;
  299. /**
  300. * \struct frequencies
  301. * \brief Get supported frequencies for JTAG and SWD ineterfaces.
  302. */
  303. typedef struct frequencies
  304. {
  305. unsigned int jtagFreq[12]; /**< JTAG frequency. */
  306. unsigned int jtagFreqNumber; /**< Get JTAG supported frequencies. */
  307. unsigned int swdFreq[12]; /**< SWD frequency. */
  308. unsigned int swdFreqNumber; /**< Get SWD supported frequencies. */
  309. }frequencies;
  310. /**
  311. * \struct debugConnectParameters
  312. * \brief Get device characterization and specify connection parameters through ST-LINK interface.
  313. */
  314. typedef struct debugConnectParameters
  315. {
  316. debugPort dbgPort; /**< Select the type of debug interface #debugPort. */
  317. int index; /**< Select one of the debug ports connected. */
  318. char serialNumber[33]; /**< ST-LINK serial number. */
  319. char firmwareVersion[20]; /**< Firmware version. */
  320. char targetVoltage[5]; /**< Operate voltage. */
  321. int accessPortNumber; /**< Number of available access port. */
  322. int accessPort; /**< Select access port controller. */
  323. debugConnectMode connectionMode; /**< Select the debug CONNECT mode #debugConnectMode. */
  324. debugResetMode resetMode; /**< Select the debug RESET mode #debugResetMode. */
  325. int isOldFirmware; /**< Check Old ST-LINK firmware version. */
  326. frequencies freq; /**< Supported frequencies #frequencies. */
  327. int frequency; /**< Select specific frequency. */
  328. int isBridge; /**< Indicates if it's Bridge device or not. */
  329. int shared; /**< Select connection type, if it's shared, use ST-LINK Server. */
  330. }debugConnectParameters;
  331. /* -------------------------------------------------------------------------------------------- */
  332. /* General Data Structures and Enumerations */
  333. /* -------------------------------------------------------------------------------------------- */
  334. /**
  335. * \enum targetInterfaceType
  336. * \brief Indicates the supported interfaces.
  337. */
  338. typedef enum targetInterfaceType
  339. {
  340. STLINK_INTERFACE = 0, /**< STLINK used as connection interface. */
  341. USART_INTERFACE = 1, /**< USART used as connection interface. */
  342. USB_INTERFACE = 2, /**< USB DFU used as connection interface. */
  343. SPI_INTERFACE = 3, /**< SPI used as connection interface. */
  344. I2C_INTERFACE = 4, /**< I2C used as connection interface. */
  345. CAN_INTERFACE = 5 /**< CAN used as connection interface. */
  346. }targetInterfaceType;
  347. /**
  348. * \struct displayCallBacks
  349. * \brief Functions must be implemented to personalize the display of messages.
  350. */
  351. typedef struct displayCallBacks
  352. {
  353. void (*initProgressBar)(); /**< Add a progress bar. */
  354. void (*logMessage)(int msgType, const wchar_t* str); /**< Display internal messages according to verbosity level. */
  355. void (*loadBar)(int x, int n); /**< Display the loading of read/write process. */
  356. } displayCallBacks;
  357. typedef struct segmentData_C
  358. {
  359. int address; /**< Segment start address. */
  360. int size; /**< Memory segment size. */
  361. unsigned char* data; /**< Memory segment data. */
  362. }segmentData_C ;
  363. /**
  364. * \struct FileData_C
  365. * \brief Get file required informations.
  366. */
  367. typedef struct fileData_C
  368. {
  369. int Type; /**< File extension type. */
  370. int segmentsNbr; /**< Number of required segments. */
  371. segmentData_C* segments; /**< Segments description. */
  372. }fileData_C ;
  373. /**
  374. * \struct GeneralInf
  375. * \brief Get device general informations.
  376. */
  377. typedef struct generalInf
  378. {
  379. unsigned short deviceId; /**< Device ID. */
  380. int flashSize; /**< Flash memory size. */
  381. char type[4]; /**< Device MCU or MPU. */
  382. char cpu[20]; /**< Cortex CPU. */
  383. char name[100]; /**< Device name. */
  384. char series[100]; /**< Device serie. */
  385. char description[100]; /**< Take notice. */
  386. }generalInf ;
  387. /* -------------------------------------------------------------------------------------------- */
  388. /* Loaders Data Structures */
  389. /* -------------------------------------------------------------------------------------------- */
  390. /**
  391. * \struct deviceSector
  392. * \brief Get device sectors basic informations.
  393. */
  394. typedef struct deviceSector
  395. {
  396. uint32_t sectorNum; /**< Number of Sectors. */
  397. uint32_t sectorSize; /**< Sector Size in BYTEs. */
  398. }deviceSector;
  399. /**
  400. * \struct externalLoader
  401. * \brief Get external Loader parameters to launch the process of programming an external flash memory.
  402. */
  403. typedef struct externalLoader{
  404. char filePath[200]; /**< FlashLoader file path. */
  405. char deviceName[100]; /**< Device Name and Description. */
  406. int deviceType; /**< Device Type: ONCHIP, EXT8BIT, EXT16BIT, ... */
  407. uint32_t deviceStartAddress; /**< Default Device Start Address. */
  408. uint32_t deviceSize; /**< Total Size of Device. */
  409. uint32_t pageSize; /**< Programming Page Size. */
  410. // unsigned char EraseValue; /**< Content of Erased Memory. */
  411. uint32_t sectorsTypeNbr; /**< Type number. */
  412. deviceSector* sectors; /**< Device sectors. */
  413. }externalLoader;
  414. /**
  415. * \struct externalStorageInfo
  416. * \brief Get external storage informations useful for external Loader.
  417. */
  418. typedef struct externalStorageInfo
  419. {
  420. unsigned int externalLoaderNbr;
  421. externalLoader* externalLoader;
  422. }externalStorageInfo;
  423. /* -------------------------------------------------------------------------------------------- */
  424. /* STLINK functions */
  425. /* -------------------------------------------------------------------------------------------- */
  426. /*! \addtogroup STLINK
  427. * STLINK module groups debug ports JTAG/SWD functions together.
  428. * @{
  429. */
  430. /**
  431. * \brief This routine allows to get ST-LINK conneted probe(s).
  432. * \param stLinkList : Filled with the connected ST-LINK list and its default configurations.
  433. * \param shared : Enable shared mode allowing connection of two or more instances to the same ST-LINK probe.
  434. * \return Number of the ST-LINK probes already exists.
  435. * \warning The Share option is useful only with ST-LINK Server.
  436. * \note At the end of usage, #deleteInterfaceList must have been called.
  437. */
  438. int getStLinkList(debugConnectParameters** stLinkList, int shared);
  439. /**
  440. * \brief This routine allows to start connection to device through SWD or JTAG interfaces.
  441. * \param debugParameters : Indicates customized configuration for ST-LINK connection,
  442. * It is recommended to check [debugConnectParameters] fields before connection.
  443. * \return 0 if the connection successfully established, otherwise an error occurred.
  444. */
  445. int connectStLink(debugConnectParameters debugParameters);
  446. /**
  447. * \brief This routine used to apply a target reset.
  448. * \note Reset operation is only available with JTAG/SWD debug interface.
  449. * \param rstMode : Indicates the reset type Soft/Hard/Core #debugResetMode. \n
  450. * \return 0 if the reset operation finished successfully, otherwise an error occurred.
  451. */
  452. int reset(debugResetMode rstMode) ;
  453. /*! @} */
  454. /* -------------------------------------------------------------------------------------------- */
  455. /* Bootloader functions */
  456. /* -------------------------------------------------------------------------------------------- */
  457. /*! \addtogroup Bootloader
  458. * Bootloader module is a way to group Serial interfaces USB/UART/SPI/I2C/CAN functions together.
  459. * @{
  460. */
  461. /**
  462. * \brief This routine allows to get connected serial ports.
  463. * \param usartList : Receive serial ports list and its default configurations.
  464. * \return Number of serial ports already connected.
  465. * \note At the end of usage, #deleteInterfaceList must have been called.
  466. */
  467. int getUsartList(usartConnectParameters** usartList);
  468. /**
  469. * \brief This routine allows to start connection to device through USART interface.
  470. * \param usartParameters : Indicates customized configuration for USART connection.
  471. * \return 0 if the connection successfully established, otherwise an error occurred.
  472. */
  473. int connectUsartBootloader(usartConnectParameters usartParameters);
  474. /**
  475. * \brief This routine allows to send a single byte through the USART interface.
  476. * \param byte : The data to be written
  477. * \return 0 if the sending operation correctly achieved, otherwise an error occurred.
  478. */
  479. int sendByteUart(int byte);
  480. /**
  481. * \brief This routine allows to get connected DFU devices.
  482. * \param dfuList : Receive DFU devices list and its default configurations.
  483. * \return Number of DFU devices already connected.
  484. * \note At the end of usage, #deleteInterfaceList must have been called.
  485. */
  486. int getDfuDeviceList(dfuDeviceInfo** dfuList);
  487. /**
  488. * \brief This routine allows to start connection to device through USB DFU interface.
  489. * \param usbIndex : Indicates the index of DFU ports already connected.
  490. * \return 0 if the connection successfully established, otherwise an error occurred.
  491. */
  492. int connectDfuBootloader(char* usbIndex);
  493. /**
  494. * \brief This routine allows to start connection to device through SPI interface.
  495. * \param spiParameters : Indicates customized configuration for SPI connection
  496. * \return 0 if the connection successfully established, otherwise an error occurred.
  497. */
  498. int connectSpiBootloader(spiConnectParameters spiParameters);
  499. /**
  500. * \brief This routine allows to start connection to device through CAN interface.
  501. * \param canParameters : Indicates customized configuration for CAN connection
  502. * \return 0 if the connection successfully established, otherwise an error occurred.
  503. * \warning To have CAN full support, you must have St-Link firmware version at least v3JxMxB2.
  504. */
  505. int connectCanBootloader(canConnectParameters canParameters);
  506. /**
  507. * \brief This routine allows to start connection to device through I2C interface.
  508. * \param i2cParameters : Indicates customized configuration for I2C connection
  509. * \return 0 if the connection successfully established, otherwise an error occurred.
  510. */
  511. int connectI2cBootloader(i2cConnectParameters i2cParameters);
  512. /*! @} */
  513. /* -------------------------------------------------------------------------------------------- */
  514. /* General purposes functions */
  515. /* -------------------------------------------------------------------------------------------- */
  516. /*! \addtogroup General
  517. * General module groups general purposes functions used by any interface.
  518. * @{
  519. */
  520. /**
  521. * \brief This routine allows to choose your custom display.
  522. * \param c : Fill the struct to customize the display tool.
  523. * \note This function must be called first of all to ensure the display management.
  524. */
  525. void setDisplayCallbacks(displayCallBacks c);
  526. /**
  527. * \brief This routine allows to choose the verbosity level for display.
  528. * \param level : Indicates the verbosity number 0, 1 or 3.
  529. */
  530. void setVerbosityLevel(int level);
  531. /**
  532. * \brief This routine allows to check connection status [maintained or lost].
  533. * \return 1 if the device is already connected, otherwise the connection to device is lost.
  534. */
  535. int checkDeviceConnection();
  536. /**
  537. * \brief This routine allows to get general device informations.
  538. * \return Structure #GeneralInf in which the informations are stored.
  539. */
  540. generalInf* getDeviceGeneralInf();
  541. /**
  542. * \brief This routine allows to receive memory data on the used interface with the configration already initialized.
  543. * \param address : The address to start reading from.
  544. * \param data : Pointer to the data buffer.
  545. * \param size : It indicates the size for read data.
  546. * \return 0 if the reading operation correctly finished, otherwise an error occurred.
  547. * \warning Unlike ST-LINK interface, the Bootloader interface can access only to some specific memory regions.
  548. */
  549. int readMemory(unsigned int address, unsigned char** data, unsigned int size);
  550. /**
  551. * \brief This routine allows to write memory data on the user interface with the configration already initialized.
  552. * \param address : The address to start writing from.
  553. * \param data : Pointer to the data buffer.
  554. * \param size : It indicates the size for write data.
  555. * \return 0 if the writing operation correctly finished, otherwise an error occurred.
  556. * \warning Unlike ST-LINK interface, the Bootloader interface can access only to some specific memory regions.
  557. */
  558. int writeMemory(unsigned int address, char* data, unsigned int size);
  559. /**
  560. * \brief This routine allows to download data from a file to the memory.
  561. * File formats that are supported : hex, bin, srec
  562. * \param filePath : Indicates the full path of the considered file.
  563. * \param address : The address to start downloading from.
  564. * \param skipErase : In case to win in term time and if we have a blank device, we can skip erasing memory before programming [skipErase=0].
  565. * \param verify : To add verification step after downloading.
  566. * \param binPath : Path of the binary file.
  567. * \return 0 if the downloading operation correctly finished, otherwise an error occurred.
  568. */
  569. int downloadFile(const wchar_t* filePath, unsigned int address, unsigned int skipErase, unsigned int verify, const wchar_t* binPath);
  570. /**
  571. * \brief This routine allows to run the application.
  572. * \param address : The address to start executing from.
  573. * In most cases, the program will run from the Flash memory starting from 0x08000000.
  574. * \return 0 if the execution correctly started, otherwise an error occurred.
  575. */
  576. int execute(unsigned int address);
  577. /*!
  578. * \brief This routine allows to erase the whole Flash memory.
  579. * \return 0 if the operation finished successfully, otherwise an error was occurred.
  580. * \note Depending on the device, this routine can take a particular period of time.
  581. */
  582. int massErase();
  583. /**
  584. * \brief This routine allows to erase specific sectors of the Flash memory.
  585. * \param sectors : Indicates the indexs of the specific sectors to be erased.
  586. * \param sectorNbr : The number of chosen sectors.
  587. * \return 0 if the operation finished successfully, otherwise an error occurred.
  588. * \note Each circuit has a specific number of Flash memory sectors.
  589. */
  590. int sectorErase(unsigned int sectors[],unsigned int sectorNbr);
  591. /**
  592. * \brief This routine allows to disable the readout protection.
  593. * If the memory is not protected, a message appears to indicate that the device is not
  594. * under Readout protection and the command has no effects.
  595. * \return 0 if the disabling correctly accomplished, otherwise an error occurred.
  596. * \note Depending on the device used, this routine take a specific time.
  597. */
  598. int readUnprotect();
  599. /**
  600. * \brief This routine allows to know the interface what is in use.
  601. * \return The target interface type #targetInterfaceType, otherwise -1.
  602. */
  603. int getTargetInterfaceType();
  604. /**
  605. * \brief This routine allows to drop the current read/write operation.
  606. * \return 0 if there is no call for stop operation, otherwise 1.
  607. */
  608. volatile int* getCancelPointer();
  609. /**
  610. * \brief This routine allows to open and get data from any supported file extension.
  611. * \param filePath : Indicates the full path of the considered file.
  612. * \return Pointer to #fileData_C if the file has hex, bin, srec or elf as extension, otherwise a null pointer to indicate that the file type is not supported.
  613. */
  614. void *fileOpen(const wchar_t* filePath);
  615. /**
  616. * \brief This routine allows to clean up the handled file data.
  617. * \param data
  618. */
  619. void freeFileData(fileData_C* data);
  620. /**
  621. * \brief This routine allows to verfiy if the indicated file data is identical to Flash memory content.
  622. * \param fileData : Input file name.
  623. * \param address : The address to start verifying from, it's considered only if the file has .bin or .binary as extension.
  624. * \return 0 if the file data matching Flash memory content, otherwise an error occurred or the data is mismatched.
  625. */
  626. int verify(fileData_C* fileData, unsigned int address);
  627. /**
  628. * \brief This routine allows to save the data file content to another file.
  629. * \param fileData : Input file name.
  630. * \param sFileName : Output file name.
  631. * \return 0 if the output file was created successfully, otherwise an error occurred.
  632. */
  633. int saveFileToFile(fileData_C *fileData, const wchar_t* sFileName);
  634. /**
  635. * \brief This routine allows to save Flash memory content to file.
  636. * \param address : The address to start saving from.
  637. * \param size : Data size to be saved.
  638. * \param sFileName : Indicates the file name.
  639. * \return 0 if the data copy was acheived successfully, otherwise an error occurred.
  640. * \note The file name must finish with an extension ".hex", ".bin" or ".srec"
  641. */
  642. int saveMemoryToFile(int address, int size, const wchar_t* sFileName);
  643. /**
  644. * \brief This routine allows to clean up and disconnect the current connected target.
  645. * \note This routine disconnect the target and delete the loaded Flash Loaders.
  646. */
  647. void disconnect();
  648. /**
  649. * \brief This routine allows to clear the list of each created interface.
  650. * \note The list is filled by #getStlinkList, #getDfuDeviceList or #getUsartList.
  651. */
  652. void deleteInterfaceList();
  653. /**
  654. * \brief This routine allows to enter and make an automatic process for memory management through JTAG/SWD, UART, DFU, SPI, CAN and I²C interfaces.
  655. * \param filePath : Indicates the full file path.
  656. * \param address : The address to start downloading from.
  657. * \param skipErase : If we have a blank device, we can skip erasing memory before programming [skipErase=0].
  658. * \param verify : Add verification step after downloading.
  659. * \param isMassErase : Erase the whole Flash memory.
  660. * \param obCommand : Indicates the option bytes commands to be loaded "-ob [optionbyte=value] [optionbyte=value]..."
  661. * \param run : Start the application.
  662. * \warning Connection to target must be established before performing automatic mode.
  663. */
  664. void automaticMode(const wchar_t* filePath, unsigned int address, unsigned int skipErase, unsigned int verify, int isMassErase, char* obCommand, int run);
  665. /*! @} */
  666. /* -------------------------------------------------------------------------------------------- */
  667. /* Option Bytes functions */
  668. /* -------------------------------------------------------------------------------------------- */
  669. /*! \addtogroup OB
  670. * OB module groups option bytes functions used by any interface.
  671. * @{
  672. */
  673. /**
  674. * \brief This routine allows program the given Option Byte.
  675. * The option bytes are configured by the end user depending on the application requirements.
  676. * \param command : Indicates the command to execute.
  677. * \return 0 if the programming Option Byte correctly executed, otherwise an error occurred.
  678. * \note The command must written as: -ob [optionbyte=value] [optionbyte=value] ...
  679. * \code
  680. * int ob = sendOptionBytesCmd("–ob rdp=0x0 BOR_LEV=0");
  681. * \endcode
  682. */
  683. int sendOptionBytesCmd(char* command);
  684. /**
  685. * \brief This routine allows to get option bytes values of the connected target.
  686. * \return Structure #Peripheral_C in which the option bytes descriptions are stored.
  687. */
  688. peripheral_C* initOptionBytesInterface();
  689. /*! @} */
  690. /* -------------------------------------------------------------------------------------------- */
  691. /* Loaders functions */
  692. /* -------------------------------------------------------------------------------------------- */
  693. /*! \addtogroup Loaders
  694. * Loaders module groups loaders functions.
  695. * @{
  696. */
  697. /**
  698. * \brief This routine allows to specify the location of Flash Loader.
  699. * \param path : Indicates the full path of the considered folder.
  700. */
  701. void setLoadersPath(const char* path);
  702. /**
  703. * \brief This routine allows to specify the path of the external Loaders to be loaded.
  704. * \param path : Indicates the full path of the folder containing external Loaders.
  705. * \param externalLoaderInfo : Structure in which the external Loaders informations are stored.
  706. */
  707. void setExternalLoaderPath(const char* path, externalLoader** externalLoaderInfo);
  708. /**
  709. * \brief This routine allows to get available external Loaders in th mentioned path.
  710. * \param path : Indicates the full path of the external Loader file ready for loading.
  711. * \param externalStorageNfo : Structure in which we get storage information.
  712. * \return 1 if the External loaders cannot be loaded from the path, otherwise 0.
  713. * \warning All external Loader files should have the extension "stldr".
  714. */
  715. int getExternalLoaders(const char* path, externalStorageInfo** externalStorageNfo);
  716. /**
  717. * \brief This routine allows to unload an external Loaders.
  718. * \param path : Indicates the full path of the external Loader file ready for unloading.
  719. */
  720. void removeExternalLoader(const char* path);
  721. /**
  722. * \brief This routine allows to delete all target Flash Loaders.
  723. */
  724. void deleteLoaders();
  725. /*! @} */
  726. #ifdef __cplusplus
  727. }
  728. #endif
  729. #endif // CUBEPROGRAMMER_API_H