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