Rev Author Line No. Line
2066 kakl 1 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
2 * File Name : STBLLIB.h
3 * Author : MCD Application Team
4 * Version : v2.2.0
5 * Date : 05/03/2010
6 * Description : Defines the system memory boot loader protocol interface
7 ********************************************************************************
8 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
9 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
10 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
11 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
12 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
13 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
14 *******************************************************************************/
15  
16 #ifndef STDLIB_H
17 #define STDLIB_H
18  
19 #include "StdAfx.h"
20 #include "../CRs232/rs232.h"
21  
22 #ifdef STBLLIB_EXPORTS
23 #define STBLLIB_API __declspec(dllexport)
24 #else
25 #define STBLLIB_API __declspec(dllimport)
26 #endif
27  
28 const BYTE INIT_CON = 0x7F;
29  
30 const BYTE GET_CMD = 0x00; //Get the version and the allowed commands supported by the current version of the boot loader
31 const BYTE GET_VER_ROPS_CMD = 0x01; //Get the BL version and the Read Protection status of the NVM
32 const BYTE GET_ID_CMD = 0x02; //Get the chip ID
33 const BYTE SET_SPEED_CMD = 0x03; //set the new baudrate
34 const BYTE READ_CMD = 0x11; //Read up to 256 bytes of memory starting from an address specified by the user
35 const BYTE GO_CMD = 0x21; //Jump to an address specified by the user to execute (a loaded) code
36 const BYTE WRITE_CMD = 0x31; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
37 const BYTE ERASE_CMD = 0x43; //Erase from one to all the NVM sectors
38 const BYTE ERASE_EXT_CMD = 0x44; //Erase from one to all the NVM sectors
39 const BYTE WRITE_PROTECT_CMD = 0x63; //Enable the write protection in a permanent way for some sectors
40 const BYTE WRITE_TEMP_UNPROTECT_CMD = 0x71; //Disable the write protection in a temporary way for all NVM sectors
41 const BYTE WRITE_PERM_UNPROTECT_CMD = 0x73; //Disable the write protection in a permanent way for all NVM sectors
42 const BYTE READOUT_PROTECT_CMD = 0x82; //Enable the readout protection in a permanent way
43 const BYTE READOUT_TEMP_UNPROTECT_CMD = 0x91; //Disable the readout protection in a temporary way
44 const BYTE READOUT_PERM_UNPROTECT_CMD = 0x92; //Disable the readout protection in a permanent way
45  
46  
47 const BYTE SUCCESS = 0x00; // No error
48 const BYTE ERROR_OFFSET = 0x00; //error offset
49  
50 const BYTE COM_ERROR_OFFSET = ERROR_OFFSET + 0x00;
51 const BYTE NO_CON_AVAILABLE = COM_ERROR_OFFSET + 0x01; // No serial port opened
52 const BYTE COM_ALREADY_OPENED = COM_ERROR_OFFSET + 0x02; // Serial port already opened
53 const BYTE CANT_OPEN_COM = COM_ERROR_OFFSET + 0x03; // Fail to open serial port
54 const BYTE SEND_FAIL = COM_ERROR_OFFSET + 0x04; // send over serial port fail
55 const BYTE READ_FAIL = COM_ERROR_OFFSET + 0x05; // Read from serial port fail
56  
57 const BYTE SYS_MEM_ERROR_OFFSET = ERROR_OFFSET + 0x10;
58 const BYTE CANT_INIT_BL = SYS_MEM_ERROR_OFFSET + 0x01; // Fail to start system memory BL
59 const BYTE UNREOGNIZED_DEVICE = SYS_MEM_ERROR_OFFSET + 0x02; // Unreconized device
60 const BYTE CMD_NOT_ALLOWED = SYS_MEM_ERROR_OFFSET + 0x03; // Command not allowed
61 const BYTE CMD_FAIL = SYS_MEM_ERROR_OFFSET + 0x04; // command failed
62  
63 const BYTE PROGRAM_ERROR_OFFSET = ERROR_OFFSET + 0x20;
64 const BYTE INPUT_PARAMS_ERROR = PROGRAM_ERROR_OFFSET + 0x01;
65 const BYTE INPUT_PARAMS_MEMORY_ALLOCATION_ERROR = PROGRAM_ERROR_OFFSET + 0x02;
66 const BYTE LIB_LOADING_ERROR = PROGRAM_ERROR_OFFSET + 0x03;
67  
68  
69  
70 enum ACKS {UNDEFINED=0x00, ST75=0x75, ST79=0x79};
71 enum INTERFACE_TYPE {UART, CAN};
72  
73 enum EBaudRate { brCustom,br110, br300, br600, br1200, br2400, br4800, br9600, br14400, br19200, br38400,
74 br56000, br57600, br115200, br128000, br256000 };// Port Numbers ( custom or COM1..COM16 }
75 enum EPortNumber { pnCustom,pnCOM1, pnCOM2, pnCOM3, pnCOM4, pnCOM5, pnCOM6, pnCOM7,pnCOM8, pnCOM9, pnCOM10,
76 pnCOM11, pnCOM12, pnCOM13,pnCOM14, pnCOM15, pnCOM16 };// Data bits ( 5, 6, 7, 8 }
77 enum EDataBits { db5BITS, db6BITS, db7BITS, db8BITS };
78 // Stop bits ( 1, 1.5, 2 }
79 enum EStopBits { sb1BITS, sb1HALFBITS, sb2BITS };
80 // Parity ( None, odd, even, mark, space }
81 enum EParity { ptNONE, ptODD, ptEVEN, ptMARK, ptSPACE };
82 // Hardware Flow Control ( None, None + RTS always on, RTS/CTS }
83 enum EHwFlowControl { hfNONE, hfNONERTSON, hfRTSCTS };
84 // Software Flow Control ( None, XON/XOFF }
85 enum ESwFlowControl { sfNONE, sfXONXOFF };
86 // What to do with incomplete (incoming} packets ( Discard, Pass }
87 enum EPacketMode { pmDiscard, pmPass };
88  
89 enum OPERATION {NONE, ERASE, UPLOAD, DNLOAD, DIS_R_PROT, DIS_W_PROT, ENA_R_PROT, ENA_W_PROT};
90  
91 typedef struct RESULT
92 {
93 OPERATION operation;
94 char* filename;
95 HANDLE Image;
96 }* LPRESULT;
97  
98 typedef struct Commands
99 {
100 BOOL GET_CMD ; //Get the version and the allowed commands supported by the current version of the boot loader
101 BOOL GET_VER_ROPS_CMD ; //Get the BL version and the Read Protection status of the NVM
102 BOOL GET_ID_CMD ; //Get the chip ID
103 BOOL SET_SPEED_CMD ; //Change the CAN baudrate
104 BOOL READ_CMD ; //Read up to 256 bytes of memory starting from an address specified by the user
105 BOOL GO_CMD ; //Jump to an address specified by the user to execute (a loaded) code
106 BOOL WRITE_CMD ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
107 BOOL ERASE_CMD ; //Erase from one to all the NVM sectors
108 BOOL ERASE_EXT_CMD ; //Erase from one to all the NVM sectors
109 BOOL WRITE_PROTECT_CMD ; //Enable the write protection in a permanent way for some sectors
110 BOOL WRITE_TEMP_UNPROTECT_CMD ; //Disable the write protection in a temporary way for all NVM sectors
111 BOOL WRITE_PERM_UNPROTECT_CMD ; //Disable the write protection in a permanent way for all NVM sectors
112 BOOL READOUT_PROTECT_CMD ; //Enable the readout protection in a permanent way
113 BOOL READOUT_TEMP_UNPROTECT_CMD ; //Disable the readout protection in a temporary way
114 BOOL READOUT_PERM_UNPROTECT_CMD ; //Disable the readout protection in a permanent way
115 }* LPCommands;
116  
117 typedef struct TARGET_DESCRIPTOR
118 {
119 BYTE Version ;
120 BYTE CmdCount ;
121 BYTE PIDLen ;
122 BYTE* PID ;
123  
124 BYTE ROPE ;
125 BYTE ROPD ;
126  
127 BOOL GET_CMD ; //Get the version and the allowed commands supported by the current version of the boot loader
128 BOOL GET_VER_ROPS_CMD ; //Get the BL version and the Read Protection status of the NVM
129 BOOL GET_ID_CMD ; //Get the chip ID
130 BOOL SET_SPEED_CMD ;
131 BOOL READ_CMD ; //Read up to 256 bytes of memory starting from an address specified by the user
132 BOOL GO_CMD ; //Jump to an address specified by the user to execute (a loaded) code
133 BOOL WRITE_CMD ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
134 BOOL ERASE_CMD ; //Erase from one to all the NVM sectors
135 BOOL ERASE_EXT_CMD ; //Erase from one to all the NVM sectors
136 BOOL WRITE_PROTECT_CMD ; //Enable the write protection in a permanent way for some sectors
137 BOOL WRITE_TEMP_UNPROTECT_CMD ; //Disable the write protection in a temporary way for all NVM sectors
138 BOOL WRITE_PERM_UNPROTECT_CMD ; //Disable the write protection in a permanent way for all NVM sectors
139 BOOL READOUT_PERM_PROTECT_CMD ; //Enable the readout protection in a permanent way
140 BOOL READOUT_TEMP_UNPROTECT_CMD ; //Disable the readout protection in a temporary way
141 BOOL READOUT_PERM_UNPROTECT_CMD ; //Disable the readout protection in a permanent way
142 }* LPTARGET_DESCRIPTOR;
143  
144 typedef struct STBL_Request
145 {
146 BYTE _cmd;
147 DWORD _address;
148 WORD _length;
149 BYTE _nbSectors;
150 LPTARGET_DESCRIPTOR _target;
151 LPBYTE _data;
152 WORD _wbSectors;
153 }* LPSTBL_Request;
154  
155 extern "C"
156 {
157 /************************************************************************************/
158 /* GET PROGRESS STATE
159 /*
160 /*
161 /************************************************************************************/
162 STBLLIB_API BYTE GetProgress(LPBYTE progress);
163  
164 /************************************************************************************/
165 /* GET ACTIVITY TIME
166 /*
167 /*
168 /************************************************************************************/
169 STBLLIB_API BYTE GetActivityTime(LPDWORD time);
170  
171 /************************************************************************************/
172 /* SET ACTIVITY TIME
173 /*
174 /*
175 /************************************************************************************/
176 STBLLIB_API BYTE SetActivityTime(DWORD time);
177  
178 /************************************************************************************/
179 /* SET COMMUNICATION INTERFACE TYPE
180 /* UART - CAN - ...
181 /*
182 /************************************************************************************/
183 STBLLIB_API BYTE TARGET_SetComIntType(BYTE com_int_type);
184 /************************************************************************************/
185 /* GetFlashSize
186 /*
187 /*
188 /************************************************************************************/
189 STBLLIB_API BYTE TARGET_GetFlashSize(DWORD Addr, LPWORD val);
190 /************************************************************************************/
191 /* GetMemoryAddress
192 /*
193 /*
194 /************************************************************************************/
195 STBLLIB_API BYTE TARGET_GetMemoryAddress(DWORD Addr, LPBYTE val);
196 /************************************************************************************/
197 /* GetRDPOptionByte
198 /*
199 /*
200 /************************************************************************************/
201 STBLLIB_API BYTE TARGET_GetRDPOptionByte(LPBYTE RDP);
202 /************************************************************************************/
203 /* GetWRPOptionBytes
204 /*
205 /*
206 /************************************************************************************/
207 STBLLIB_API BYTE TARGET_GetWRPOptionBytes(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
208 /************************************************************************************/
209 /* Basic function to send a request
210 /*
211 /*
212 /************************************************************************************/
213 STBLLIB_API BYTE Send_RQ(LPSTBL_Request pRQ);
214  
215 /************************************************************************************/
216 /*
217 /*
218 /*
219 /************************************************************************************/
220 STBLLIB_API BYTE SetCOMSettings(int numPort, long speedInBaud, int nbBit,
221 int parity, float nbStopBit);
222 /************************************************************************************/
223 /*
224 /*
225 /*
226 /************************************************************************************/
227 /*STBLLIB_API BYTE ESetCOMSettings(EPortNumber numPort, EBaudRate speedInBaud, EDataBits nbBit,
228 EParity parity, EStopBits nbStopBit);*/
229 /************************************************************************************/
230 /*
231 /*
232 /*
233 /************************************************************************************/
234 STBLLIB_API BYTE COM_Open();
235 /************************************************************************************/
236 /*
237 /*
238 /*
239 /************************************************************************************/
240 STBLLIB_API BYTE COM_Close();
241 /************************************************************************************/
242 /*
243 /*
244 /*
245 /************************************************************************************/
246 STBLLIB_API BYTE STBL_SetSpeed(DWORD speed);
247 /************************************************************************************/
248 /*
249 /*
250 /*
251 /************************************************************************************/
252 STBLLIB_API BYTE STBL_Init_BL();
253 /************************************************************************************/
254 /* 0x00; //Get the version and the allowed commands supported by the current version of the boot loader
255 /*
256 /*
257 /************************************************************************************/
258 STBLLIB_API BYTE STBL_GET(LPBYTE Version, LPCommands pCmds);
259 /************************************************************************************/
260 /* 0x01; //Get the BL version and the Read Protection status of the NVM
261 /*
262 /*
263 /************************************************************************************/
264 STBLLIB_API BYTE STBL_GET_VER_ROPS(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled);
265 /************************************************************************************/
266 /* 0x02; //Get the chip ID
267 /*
268 /*
269 /************************************************************************************/
270 STBLLIB_API BYTE STBL_GET_ID(LPBYTE size, LPBYTE pID);
271 /************************************************************************************/
272 /* 0x11; //Read up to 256 bytes of memory starting from an address specified by the user
273 /*
274 /*
275 /************************************************************************************/
276 STBLLIB_API BYTE STBL_READ(DWORD Address, BYTE Size, LPBYTE pData);
277 /************************************************************************************/
278 /* 0x21; //Jump to an address specified by the user to execute (a loaded) code
279 /*
280 /*
281 /************************************************************************************/
282 STBLLIB_API BYTE STBL_GO(DWORD Address);
283 /************************************************************************************/
284 /* 0x31; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
285 /*
286 /*
287 /************************************************************************************/
288 STBLLIB_API BYTE STBL_WRITE(DWORD address, BYTE size, LPBYTE pData);
289 /************************************************************************************/
290 /* 0x43; //Erase from one to all the NVM sectors
291 /*
292 /*
293 /************************************************************************************/
294 STBLLIB_API BYTE STBL_ERASE(WORD NbSectors, LPBYTE pSectors);
295  
296 /************************************************************************************/
297 /* 0x63; //Enable the write protection in a permanent way for some sectors
298 /*
299 /*
300 /************************************************************************************/
301 STBLLIB_API BYTE STBL_WRITE_PROTECT(BYTE NbSectors, LPBYTE pSectors);
302 /************************************************************************************/
303 /* 0x71; //Disable the write protection in a temporary way for all NVM sectors
304 /*
305 /*
306 /************************************************************************************/
307 STBLLIB_API BYTE STBL_WRITE_TEMP_UNPROTECT();
308 /************************************************************************************/
309 /* 0x73; //Disable the write protection in a permanent way for all NVM sectors
310 /*
311 /*
312 /************************************************************************************/
313 STBLLIB_API BYTE STBL_WRITE_PERM_UNPROTECT();
314 /************************************************************************************/
315 /* 0x82; //Enable the readout protection in a permanent way
316 /*
317 /*
318 /************************************************************************************/
319 STBLLIB_API BYTE STBL_READOUT_PROTECT();
320 /************************************************************************************/
321 /* 0x91; //Disable the readout protection in a temporary way
322 /*
323 /*
324 /************************************************************************************/
325 STBLLIB_API BYTE STBL_READOUT_TEMP_UNPROTECT();
326 /************************************************************************************/
327 /* 0x92; //Disable the readout protection in a permanent way
328 /*
329 /*
330 /************************************************************************************/
331 STBLLIB_API BYTE STBL_READOUT_PERM_UNPROTECT();
332 /************************************************************************************/
333 /* UPLOAD
334 /*
335 /*
336 /************************************************************************************/
337 STBLLIB_API BYTE STBL_UPLOAD(DWORD Address, LPBYTE pData, DWORD Length);
338 /************************************************************************************/
339 /* VERIFY
340 /*
341 /*
342 /************************************************************************************/
343 STBLLIB_API BYTE STBL_VERIFY(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
344 /************************************************************************************/
345 /* DNLOAD
346 /*
347 /*
348 /************************************************************************************/
349 STBLLIB_API BYTE STBL_DNLOAD(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
350  
351 /************************************************************************************/
352 /* SET PACKET SIZE
353 /*
354 /*
355 /************************************************************************************/
356 STBLLIB_API BYTE SetPaketSize(BYTE WORD);
357  
358 /************************************************************************************/
359 /* GET PACKET SIZE
360 /*
361 /*
362 /************************************************************************************/
363 STBLLIB_API BYTE GetPaketSize(LPBYTE size);
364  
365 /************************************************************************************/
366 /* GetAckValue
367 /*
368 /*
369 /************************************************************************************/
370 STBLLIB_API ACKS GetAckValue();
371  
372 /************************************************************************************/
373 /* IsConnected
374 /*
375 /*
376 /************************************************************************************/
377 STBLLIB_API BOOL COM_is_Open();
378  
379 /************************************************************************************/
380 /* SetTimeOut
381 /*
382 /*
383 /************************************************************************************/
384 STBLLIB_API BYTE SetTimeOut(DWORD vms);
385 /************************************************************************************/
386 /* GetUserOptionByte
387 /*
388 /*
389 /************************************************************************************/
390 STBLLIB_API BYTE TARGET_GetUserOptionByte(LPBYTE User);
391 /************************************************************************************/
392 /* GetDataOptionByte
393 /*
394 /*
395 /************************************************************************************/
396 STBLLIB_API BYTE TARGET_GetDataOptionByte(LPBYTE Data0, LPBYTE Data1);
397  
398 /************************************************************************************/
399 /* SetSIFData
400 /*
401 /*
402 /************************************************************************************/
403 STBLLIB_API BYTE TARGET_SetSIFData(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1,
404 BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3);
405  
406 /************************************************************************************/
407 /* GetSIFData
408 /*
409 /*
410 /************************************************************************************/
411 STBLLIB_API BYTE TARGET_GetSIFData(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1,
412 LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
413  
414 /************************************************************************************/
415 /* Set Rts Line State
416 /* High = TRUE
417 /* Low = FALSE
418 /************************************************************************************/
419 STBLLIB_API BYTE STBL_SetRts(BOOL Val);
420  
421 /************************************************************************************/
422 /* Set Dtr Line State
423 /* High = TRUE
424 /* Low = FALSE
425 /************************************************************************************/
426 STBLLIB_API BYTE STBL_SetDtr(BOOL Val);
427  
428 /************************************************************************************/
429 /* Set the state of TXD. Return: true if success.
430 /* High = TRUE
431 /* Low = FALSE
432 /************************************************************************************/
433 STBLLIB_API BYTE STBL_setTxd(BOOL val);
434  
435 /************************************************************************************/
436 /* Return: The state of CTS.
437 /* High = TRUE
438 /* Low = FALSE
439 /************************************************************************************/
440 STBLLIB_API BYTE STBL_getCts(BOOL* pval);
441  
442 /************************************************************************************/
443 /* Return: The state of DTR.
444 /* High = TRUE
445 /* Low = FALSE
446 /************************************************************************************/
447 STBLLIB_API BYTE STBL_getDtr(BOOL* pval);
448  
449 /************************************************************************************/
450 /* Return: The state of RI.
451 /* High = TRUE
452 /* Low = FALSE
453 /************************************************************************************/
454 STBLLIB_API BYTE STBL_getRi(BOOL* pval);
455  
456 /************************************************************************************/
457 /* Return: The state of DTR.
458 /* High = TRUE
459 /* Low = FALSE
460 /************************************************************************************/
461 STBLLIB_API BYTE STBL_getCd(BOOL* pval);
462  
463 /************************************************************************************/
464 /* Set Echo back Mode
465 /* 0 = Echo Disabled
466 /* 1 = Echo Back Enabled
467 /* 2 = Listen Echo Enabled
468 /************************************************************************************/
469 STBLLIB_API BYTE STBL_SetEcho(int val);
470  
471  
472 /************************************************************************************/
473 /* SetFlowControl : Enable/Disable Flow Control of DTR and RTS
474 /* FALSE = Disabled
475 /* TRUE = Enabled
476 /************************************************************************************/
477 STBLLIB_API BYTE STBL_SetFlowControl(bool val);
478  
479  
480 }
481  
482  
483  
484 #endif
485  
486 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/