No changes between revisions
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Crs232/rs232.cpp
0,0 → 1,494
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : rs232.cpp
* Author : MCD Application Team
* Version : v2.2.0
* Date : 05/03/2010
* Description : Implements the RS232 class for COM communication
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "rs232.h"
 
 
 
 
/// set serial communication over COM1 with 115200 Bauds, 8 bitand no parity.
CRS232::CRS232()
{
hcom = NULL;
bufferSize = 2048;
 
numPort = 1;
speedInBaud = 115200;
nbBit = 8;
parity = 2;
nbStopBit = 1;
 
isConnected = FALSE;
bEcho =0;
FlowControl = FALSE;
}
CRS232::~CRS232()
{
if(hcom != NULL)
closeCom();
}
 
 
void CRS232::SetComSettings(int _numPort, long _speedInBaud, int _nbBit, int _parity, float _nbStopBit)
{
numPort = _numPort;
speedInBaud = _speedInBaud;
nbBit = _nbBit;
parity = _parity;
nbStopBit = _nbStopBit;
}
 
 
 
bool CRS232::open()
{
char buf[] = "\\\\.\\COM1";
 
if(numPort<1 || numPort>999)
return false;
 
if(speedInBaud<1)
return false;
 
if(nbBit<5 || nbBit > 9)
return false;
 
if(parity<0 || parity > 2)
return false;
 
if(nbStopBit<1 || nbStopBit > 2)
return false;
 
 
 
itoa(numPort, &buf[7], 10);
 
 
hcom=CreateFile(buf, GENERIC_READ | GENERIC_WRITE , 0, NULL, OPEN_EXISTING , 0, NULL);
 
if (hcom==0 || hcom==INVALID_HANDLE_VALUE)
return false;
 
isConnected = TRUE;
 
 
setTimeOut(5000);
 
 
if ( !SetupComm(hcom, bufferSize, bufferSize) )
return false;
 
 
if ( !GetCommState(hcom, &dcb))
return false;
 
 
dcb.BaudRate = speedInBaud;
 
 
dcb.ByteSize = nbBit;
 
if(nbStopBit == 1)
dcb.StopBits = ONESTOPBIT;
if(nbStopBit == 1.5)
dcb.StopBits = ONE5STOPBITS;
if(nbStopBit == 2)
dcb.StopBits = TWOSTOPBITS;
 
if(parity == 0)
dcb.Parity = NOPARITY;
if(parity == 1)
dcb.Parity = ODDPARITY;
if(parity == 2)
dcb.Parity = EVENPARITY;
 
 
 
if ( FlowControl == true)
{
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fRtsControl = RTS_CONTROL_ENABLE;
}
else
{
 
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
}
 
 
 
if (!SetCommState(hcom, &dcb))
return false;
else
return true;
 
 
 
}
 
void CRS232::closeCom()
{
CloseHandle(hcom);
hcom = NULL;
isConnected = FALSE;
}
 
bool CRS232::setTimeOut(DWORD ms)
{
 
if( ms<0)
return false;
 
ct.ReadIntervalTimeout = ms;
ct.ReadTotalTimeoutMultiplier = ms;
ct.ReadTotalTimeoutConstant = ms;
ct.WriteTotalTimeoutMultiplier = ms;
ct.WriteTotalTimeoutConstant = ms;
if ( !SetCommTimeouts(hcom, &ct) )
return false;
 
return false;
//MSDN: The SetCommTimeouts function sets the time-out parameters for all read and write operations on a specified communications device.
}
 
bool CRS232::setSpeed(DWORD baudrate)
{
if( baudrate<1)
return false;
 
 
if (!GetCommState(hcom, &dcb))
return FALSE;
 
dcb.BaudRate = baudrate;
 
if (!SetCommState(hcom, &dcb))
return FALSE;
else
return TRUE;
 
 
 
//MSDN: The SetCommState function configures a communications device according to the specifications in a device-control block (a DCB structure). The function reinitializes all hardware and control settings, but it does not empty output or input queues.
}
 
int CRS232::sendData(string* data)
{
if( data == NULL )
return false;
 
return sendData((DWORD)data->size(), (LPBYTE)data->data());
}
 
int CRS232::sendData(DWORD lg, LPBYTE data)
{
DWORD result=0;
DWORD result1=0;
DWORD counter =0;
 
if( lg<0 || data==NULL)
return false;
 
 
 
if ( bEcho == 2)
{
 
 
for ( counter =0 ; counter < lg ; counter ++)
 
{
if ( !WriteFile(hcom, data+counter, 1, &result1, 0) )
return -1;
 
if( lg<0 || data==NULL)
return false;
 
 
if (!ReadFile(hcom, data+counter, 1, &result, 0))
return -1;
}
 
return (counter);
 
 
 
}
 
else
{
 
if ( !WriteFile(hcom, data, lg, &result, 0) )
return -1;
else
return (int)result;
}
 
 
 
 
//MSDN: The WriteFile function writes data to a file and is designed for both synchronous
// and asynchronous operation. The function starts writing data to the file at the
// position indicated by the file pointer. After the write operation has been completed
// , the file pointer is adjusted by the number of bytes actually written, except when
// the file is opened with FILE_FLAG_OVERLAPPED. If the file handle was created for
// overlapped input and output (I/O), the application must adjust the position of the
// file pointer after the write operation is finished.
// This function is designed for both synchronous and asynchronous operation.
// The WriteFileEx function is designed solely for asynchronous operation.
// It lets an application perform other processing during a file write operation.
 
}
 
int CRS232::receiveData(string* data)
{ char buffer[1025];
int nbChar=0;
 
 
if( data==NULL)
return false;
 
nbChar = receiveData(1024, (LPBYTE)buffer);
buffer[nbChar] = 0;
data->assign(buffer);
return nbChar;
}
 
int CRS232::receiveData(DWORD lg, LPBYTE data)
{
DWORD result=0;
DWORD result1=0;
DWORD counter =0;
 
if( lg<0 || data==NULL)
return false;
 
 
if ( bEcho == 0)
{
if (!ReadFile(hcom, data, lg, &result, 0))
return -1;
else
return (int)result;
}
else if ( bEcho == 1)
{
for ( counter =0 ; counter < lg ; counter ++)
 
{
if (!ReadFile(hcom, data+counter, 1, &result, 0))
return -1;
 
if( lg<0 || data==NULL)
return false;
 
if ( !WriteFile(hcom, data+counter, 1, &result1, 0) )
return -1;
}
 
return (counter);
}
 
else if ( bEcho == 2)
{
if (!ReadFile(hcom, data, lg, &result, 0))
return -1;
else
return (int)result;
}
 
 
else
{
/* TODO */
 
return -1;
}
 
 
 
//MSDN: The ReadFile function reads data from a file, starting at the position indicated
// by the file pointer. After the read operation has been completed, the file pointer
// is adjusted by the number of bytes actually read, unless the file handle is
// created with the overlapped attribute. If the file handle is created for
// overlapped input and output (I/O), the application must adjust the position of
// the file pointer after the read operation.
// This function is designed for both synchronous and asynchronous operation.
// The ReadFileEx function is designed solely for asynchronous operation. It lets
// an application perform other processing during a file read operation.
 
}
 
/**************************** SetRts(val) **************************************************/
 
bool CRS232::setRts(bool val)
{
if(val)
{
if(EscapeCommFunction(hcom, SETRTS) == TRUE )
return true;
}
else
{
if(EscapeCommFunction(hcom, CLRRTS) == TRUE )
return true;
}
 
return false;
}
 
/**************************** SetTxd(val) ***************************************************/
bool CRS232::setTxd(bool val)
{
if(val)
{
if( EscapeCommFunction(hcom, SETBREAK) == TRUE )
return true;
}
else
{
if( EscapeCommFunction(hcom, CLRBREAK) == TRUE )
return true;
}
return false;
}
/**************************** SetDtr(val) ************************************************** */
bool CRS232::setDtr(bool val)
{
if(val)
{
if( EscapeCommFunction(hcom, SETDTR) == TRUE )
return true;
}
else
{
if( EscapeCommFunction(hcom, CLRDTR) == TRUE )
return false;
}
return false;
}
 
/********************** GetCts() ***********************/
bool CRS232::getCts()
{
DWORD result;
GetCommModemStatus(hcom, &result);
if(result & MS_CTS_ON)
return true;
else
return false;
}
 
/********************** GetDtr() ***********************/
bool CRS232::getDtr()
{
DWORD result;
GetCommModemStatus(hcom, &result);
if(result & MS_DSR_ON)
return true;
else
return false;
}
 
/********************** GetRi() ***********************/
bool CRS232::getRi()
{
DWORD result;
GetCommModemStatus(hcom, &result);
if(result & MS_RING_ON)
return true;
else
return false;
}
 
 
/********************** GetCd() ***********************/
bool CRS232::getCd()
{ int err=0;
DWORD result;
err = GetCommModemStatus(hcom, &result);
if(result & MS_RLSD_ON)
return true;
else
return false;
}
 
 
 
 
string CRS232::getErrorMsg()
{
LPVOID lpMsgBuf;
string sErreur = "";
 
if ( FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL ))
{
sErreur.assign((LPCTSTR)lpMsgBuf);
}
 
return sErreur;
}
 
 
 
 
void CRS232::SetParity(int _parity)
{
if(_parity == 0)
dcb.Parity = NOPARITY;
if(_parity == 1)
dcb.Parity = ODDPARITY;
if(_parity == 2)
dcb.Parity = EVENPARITY;
 
 
 
SetCommState(hcom, &dcb);
}
 
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Crs232/rs232.h
0,0 → 1,80
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : rs232.h
* Author : MCD Application Team
* Version : v2.2.0
* Date : 05/03/2010
* Description : Defines the RS232 class for COM communication
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#ifndef LSERIE_H
#define LSERIE_H
 
#include <string>
using namespace std;
 
 
class CRS232
{
public:
void SetParity(int _parity);
BOOL isConnected;
 
int numPort;
long speedInBaud;
int nbBit;
int parity;
float nbStopBit;
int bEcho ; /* Echo back for LIN emulation */
/* 0 : Disabled , 1 : Echo Back , 2 : Listen back */
bool FlowControl;
 
//------ CONSTRUCTOR ------
CRS232();
virtual ~CRS232();
 
//------ OPEN AND CONFIGURE ------
void SetComSettings(int _numPort, long _speedInBaud, int _nbBit, int _parity, float _nbStopBit);
 
 
bool open(); // Open the serial port COM "numPort" at the speed "speedInBaud".
// bauds with and this adjustement : "nbBit" bit / "nbStopBit" stop bit / "parity").
// Return: true if success.
void closeCom(); //Close the serial port.
bool setTimeOut(DWORD ms); //Set the time-out for receive data. Return: true if success.
bool setSpeed(DWORD baudrate); //Set the speed in bauds. Return: true if success.
 
//------ SEND AND RECEIVE DATA ------
int sendData(DWORD lg, LPBYTE data); //Send table "data" of "lg" bytes. Return: number of bytes really sent.
int sendData(string* data); //Send string "data". Return: number of bytes really sent.
int receiveData(DWORD lg, LPBYTE data); //Receive table "data" who is limit at "lg" bytes. Return: number of bytes received.
int receiveData(string* data); //Receive string "data". Return: number of bytes received.
 
//------ READ AND WRITE THE STATE OF THE CONTROL LINE ------
 
bool setRts(bool val); // Set the state of RTS. Return: true if success.
bool setDtr(bool val); // Set the state of DTR. Return: true if success.
bool setTxd(bool val); // Set the state of TXD. Return: true if success.
bool getCts(); // Return: The state of CTS.
bool getDtr(); // Return: The state of DTR.
bool getRi(); // Return: The state of RI.
bool getCd(); // Return: The state of CD.
string getErrorMsg(); // Return: The error message generated by the last function.
 
private:
HANDLE hcom; //Otput file to the COM port | The file stream use for acces to the serial port.
_COMMTIMEOUTS ct; //={0,0,0,0,0}; //Config du Time Out | This variable contain the delay of the time-out.
DCB dcb; //Port configuration struct | This object is use in order to configure the serial port.
int bufferSize;
};
 
#endif
 
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/Debug/Files.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/Errors.h
0,0 → 1,45
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
* File Name : Errors.h
* Author : MCD Application Team
* Version : v2.1.0
* Date : 11/02/2009
* Description : Defines the files Input/Output error codes
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#ifndef ERRORS_H
#define ERRORS_H
 
#define FILES_ERROR_OFFSET (0x12340000+0x6000)
 
#define FILES_NOERROR (0x12340000+0x0000)
#define FILES_BADSUFFIX (FILES_ERROR_OFFSET+0x0002)
#define FILES_UNABLETOOPENFILE (FILES_ERROR_OFFSET+0x0003)
#define FILES_UNABLETOOPENTEMPFILE (FILES_ERROR_OFFSET+0x0004)
#define FILES_BADFORMAT (FILES_ERROR_OFFSET+0x0005)
#define FILES_BADADDRESSRANGE (FILES_ERROR_OFFSET+0x0006)
#define FILES_BADPARAMETER (FILES_ERROR_OFFSET+0x0008)
#define FILES_UNEXPECTEDERROR (FILES_ERROR_OFFSET+0x000A)
#define FILES_FILEGENERALERROR (FILES_ERROR_OFFSET+0x000D)
 
#define STPRT_ERROR_OFFSET (0x12340000+0x5000)
 
#define STPRT_NOERROR (0x12340000)
#define STPRT_UNABLETOLAUNCHTHREAD (STPRT_ERROR_OFFSET+0x0001)
#define STPRT_ALREADYRUNNING (STPRT_ERROR_OFFSET+0x0007)
#define STPRT_BADPARAMETER (STPRT_ERROR_OFFSET+0x0008)
#define STPRT_BADFIRMWARESTATEMACHINE (STPRT_ERROR_OFFSET+0x0009)
#define STPRT_UNEXPECTEDERROR (STPRT_ERROR_OFFSET+0x000A)
#define STPRT_ERROR (STPRT_ERROR_OFFSET+0x000B)
#define STPRT_RETRYERROR (STPRT_ERROR_OFFSET+0x000C)
#define STPRT_UNSUPPORTEDFEATURE (STPRT_ERROR_OFFSET+0x000D)
 
#endif
 
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/Files.h
0,0 → 1,99
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
* File Name : Files.h
* Author : MCD Application Team
* Version : v2.1.0
* Date : 11/02/2009
* Description : Defines the Files DLL interface
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
 
#if !defined(AFX_FILES_H__E07F909F_97B4_4295_8B8F_5EA1A83ECA92__INCLUDED_)
#define AFX_FILES_H__E07F909F_97B4_4295_8B8F_5EA1A83ECA92__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
 
#include "resource.h" // main symbols
#include "FilesInc.h"
#include "Image.h"
#include "Errors.h"
//#include "IniFile.h"
 
 
/////////////////////////////////////////////////////////////////////////////
// CFilesApp
// See Files.cpp for the implementation of this class
//
 
class CFilesApp : public CWinApp
{
public:
CFilesApp();
 
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFilesApp)
//}}AFX_VIRTUAL
 
//{{AFX_MSG(CFilesApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
 
extern "C" DWORD EXPORT FILES_OpenExistingFile(PSTR pPathFile, PHANDLE phFile, PWORD pVid, PWORD pPid, PWORD pBcd,PBYTE pNbImages);
extern "C" DWORD EXPORT FILES_CreateNewFile(PSTR pPathFile, PHANDLE phFile, WORD Vid, WORD Pid, WORD Bcd);
extern "C" DWORD EXPORT FILES_CloseFile(HANDLE hFile);
 
extern "C" DWORD EXPORT FILES_AppendImageToFile(HANDLE hFile, HANDLE Image);
extern "C" DWORD EXPORT FILES_ReadImageFromFile(HANDLE hFile, int Rank, PHANDLE pImage);
 
extern "C" DWORD EXPORT FILES_ImageFromFile(PSTR pPathFile, PHANDLE pImage, BYTE nAlternate);
extern "C" DWORD EXPORT FILES_ImageToFile(PSTR pPathFile, HANDLE Image);
 
extern "C" DWORD EXPORT FILES_CreateImage(PHANDLE pHandle, BYTE nAlternate);
extern "C" DWORD EXPORT FILES_CreateImageFromMapping(PHANDLE pHandle, PMAPPING pMapping);
extern "C" DWORD EXPORT FILES_DuplicateImage(HANDLE hSource, PHANDLE pDest);
 
extern "C" DWORD EXPORT FILES_FilterImageForOperation(HANDLE Handle, PMAPPING pMapping, DWORD Operation, BOOL bTruncateLeadFFForUpgrade);
extern "C" DWORD EXPORT FILES_DestroyImageElement(HANDLE Handle, DWORD dwRank);
extern "C" DWORD EXPORT FILES_DestroyImage(PHANDLE pHandle);
 
extern "C" DWORD EXPORT FILES_GetImageAlternate(HANDLE Handle, PBYTE pAlternate);
extern "C" DWORD EXPORT FILES_GetImageNbElement(HANDLE Handle, PDWORD pNbElements);
extern "C" DWORD EXPORT FILES_GetImageName(HANDLE Handle, PSTR Name);
extern "C" DWORD EXPORT FILES_SetImageName(HANDLE Handle, PSTR Name);
 
extern "C" DWORD EXPORT FILES_SetImageElement(HANDLE Handle, DWORD dwRank, BOOL bInsert, IMAGEELEMENT Element);
extern "C" DWORD EXPORT FILES_GetImageElement(HANDLE Handle, DWORD dwRank, PIMAGEELEMENT pElement);
extern "C" DWORD EXPORT FILES_GetMemoryMapping(PSTR pPathFile, PWORD Size, PSTR MapName, PWORD PacketSize, PMAPPING pMapping, PBYTE PagesPerSector);
 
/*FILES_OpenExistingFile
FILES_CreateNewFile
FILES_CloseFile
FILES_AppendImageToFile
FILES_ReadImageFromFile*/
 
/////////////////////////////////////////////////////////////////////////////
 
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
#endif // !defined(AFX_FILES_H__E07F909F_97B4_4295_8B8F_5EA1A83ECA92__INCLUDED_)
 
 
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/FilesInc.h
0,0 → 1,69
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
* File Name : FilesInc.h
* Author : MCD Application Team
* Version : v2.1.0
* Date : 11/02/2009
* Description : Defines the struct types used by Files DLL
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#ifndef FILES_INC_H
#define FILES_INC_H
 
#define OPERATION_DETACH 0
#define OPERATION_RETURN 1
#define OPERATION_UPLOAD 2
#define OPERATION_ERASE 3
#define OPERATION_DNLOAD 4
 
#ifndef TYPE_STATUS
typedef struct
{
UCHAR bStatus;
UCHAR bwPollTimeout[3];
UCHAR bState;
UCHAR iString;
} STATUS, *PSTATUS;
#endif
 
#define BIT_READABLE 1
#define BIT_ERASABLE 2
#define BIT_WRITEABLE 4
 
typedef struct {
char* Name;
DWORD dwStartAddress;
DWORD dwAliasedAddress;
DWORD dwSectorIndex;
DWORD dwSectorSize;
BYTE bSectorType;
BOOL UseForOperation;
BOOL UseForErase;
BOOL UseForUpload;
BOOL UseForWriteProtect;
} MAPPINGSECTOR, *PMAPPINGSECTOR;
 
typedef struct {
BYTE nAlternate;
char Name[MAX_PATH];
DWORD NbSectors;
PMAPPINGSECTOR pSectors;
} MAPPING, *PMAPPING;
 
typedef struct {
DWORD dwAddress;
DWORD dwDataLength;
PBYTE Data;
} IMAGEELEMENT, *PIMAGEELEMENT;
 
 
#endif
 
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/Image.h
0,0 → 1,63
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
* File Name : Image.h
* Author : MCD Application Team
* Version : v2.1.0
* Date : 11/02/2009
* Description : Defines the CImage class interface
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#ifndef _IMAGE_H_
#define _IMAGE_H_
 
class CImage : public CObject
{
private:
char m_LastError[1000];
BYTE m_bAlternate;
CPtrArray *m_pElements;
BOOL m_ImageState;
BOOL m_bNamed;
char m_Name[255];
 
BOOL LoadS19(PSTR pFilePath);
BOOL LoadHEX(PSTR pFilePath);
BOOL LoadBIN(PSTR pFilePath);
 
BOOL SaveS19(PSTR pFilePath);
BOOL SaveHEX(PSTR pFilePath);
 
void LDisplayError(PSTR Str) { lstrcpy(m_LastError, Str); }
BOOL ExistsElementsAtAddress(DWORD Address);
void CompactElements();
public:
CImage(CImage *pSource);
CImage(BYTE bAlternate, BOOL bNamed, PSTR Name);
CImage(PMAPPING pMapping, BOOL bNamed, PSTR Name);
CImage(BYTE bAlternate, PSTR pFilePath, BOOL bNamed, PSTR Name);
virtual ~CImage();
 
BOOL DumpToFile(PSTR pFilePath);
BYTE GetAlternate() { return m_bAlternate; }
BOOL GetImageState() { return m_ImageState; }
BOOL GetName(PSTR Name) { if (m_bNamed) lstrcpy(Name, m_Name); return m_bNamed; }
void SetName(PSTR Name) { lstrcpy(m_Name, Name); m_bNamed=TRUE; }
BOOL GetBuffer(DWORD dwAddress, DWORD dwSize, PBYTE pBuffer);
 
DWORD GetNbElements() { return m_pElements->GetSize(); }
BOOL SetImageElement(DWORD dwRank, BOOL bInsert, IMAGEELEMENT Element);
BOOL GetImageElement(DWORD dwRank, PIMAGEELEMENT pElement);
BOOL FilterImageForOperation(PMAPPING pMapping, DWORD Operation, BOOL bTruncateLeadFF);
BOOL DestroyImageElement(DWORD dwRank);
};
 
#endif
 
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/Release/Files.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/res/Files.rc2
0,0 → 1,13
//
// FILES.RC2 - resources Microsoft Visual C++ does not edit directly
//
 
#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED
 
 
/////////////////////////////////////////////////////////////////////////////
// Add manually edited resources here...
 
/////////////////////////////////////////////////////////////////////////////
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/Files/resource.h
0,0 → 1,15
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Files.rc
//
 
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/STBLLIB.exp
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/STBLLIB.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/STBLLIB.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/STBLLIB.pdb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/STBLLIB.res
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/STBLLIB.sbr
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/rs232.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/rs232.sbr
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/vc60.idb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Debug/vc60.pdb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Release/STBLLIB.exp
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Release/STBLLIB.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Release/STBLLIB.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Release/STBLLIB.res
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Release/rs232.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/Release/vc60.idb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/STBLLIB.cpp
0,0 → 1,827
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : STBLLIB.cpp
* Author : MCD Application Team
* Version : v2.2.0
* Date : 05/03/2010
* Description : Implements the System memory boot loader protocol interface
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
 
#include <malloc.h>
#include "stdafx.h"
#include "STBLLIB.h"
 
 
/************************************************************************************/
/* Generic BL API types
/*
/*
/************************************************************************************/
 
typedef BYTE virt_GetProgress(LPBYTE progress);
typedef BYTE virt_GetActivityTime(LPDWORD time);
typedef BYTE virt_SetActivityTime(DWORD time);
typedef BYTE virt_TARGET_GetFlashSize(DWORD Addr, LPWORD val);
typedef BYTE virt_TARGET_GetMemoryAddress(DWORD Addr, LPBYTE val);
typedef BYTE virt_TARGET_GetRDPOptionByte(LPBYTE RDP);
typedef BYTE virt_TARGET_GetWRPOptionBytes(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
typedef BYTE virt_Send_RQ(LPSTBL_Request pRQ);
typedef BYTE virt_SetCOMSettings(int numPort, long speedInBaud, int nbBit, int parity, float nbStopBit);
typedef BYTE virt_COM_Open();
typedef BYTE virt_COM_Close();
typedef BYTE virt_STBL_SetSpeed(DWORD speed);
typedef BYTE virt_STBL_Init_BL();
typedef BYTE virt_STBL_GET(LPBYTE Version, LPCommands pCmds);
typedef BYTE virt_STBL_GET_VER_ROPS(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled);
typedef BYTE virt_STBL_GET_ID(LPBYTE size, LPBYTE pID);
typedef BYTE virt_STBL_READ(DWORD Address, BYTE Size, LPBYTE pData);
typedef BYTE virt_STBL_GO(DWORD Address);
typedef BYTE virt_STBL_WRITE(DWORD address, BYTE size, LPBYTE pData);
typedef BYTE virt_STBL_ERASE(WORD NbSectors, LPBYTE pSectors);
typedef BYTE virt_STBL_WRITE_PROTECT(BYTE NbSectors, LPBYTE pSectors);
typedef BYTE virt_STBL_WRITE_TEMP_UNPROTECT();
typedef BYTE virt_STBL_WRITE_PERM_UNPROTECT();
typedef BYTE virt_STBL_READOUT_PROTECT();
typedef BYTE virt_STBL_READOUT_TEMP_UNPROTECT();
typedef BYTE virt_STBL_READOUT_PERM_UNPROTECT();
typedef BYTE virt_STBL_UPLOAD(DWORD Address, LPBYTE pData, DWORD Length);
typedef BYTE virt_STBL_VERIFY(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
typedef BYTE virt_STBL_DNLOAD(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
typedef BYTE virt_SetPaketSize(BYTE size);
typedef BYTE virt_GetPaketSize(LPBYTE size);
typedef ACKS virt_GetAckValue();
typedef BOOL virt_COM_is_Open();
typedef BYTE virt_SetTimeOut(DWORD vms);
typedef BYTE virt_TARGET_GetUserOptionByte(LPBYTE User);
typedef BYTE virt_TARGET_GetDataOptionByte(LPBYTE Data0, LPBYTE Data1);
typedef BYTE virt_TARGET_SetSIFData(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1, BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3);
typedef BYTE virt_TARGET_GetSIFData(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1, LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
typedef BYTE virt_STBL_SetRts(BOOL Val);
typedef BYTE virt_STBL_SetDtr(BOOL Val);
typedef BYTE virt_STBL_setTxd(BOOL val);
typedef BYTE virt_STBL_getCts(BOOL* pval);
typedef BYTE virt_STBL_getDtr(BOOL* pval);
typedef BYTE virt_STBL_getRi(BOOL* pval);
typedef BYTE virt_STBL_getCd(BOOL* pval);
typedef BYTE virt_STBL_SetEcho(int val);
typedef BYTE virt_STBL_SetFlowControl(int Val);
 
/************************************************************************************/
/* Generic BL API references
/*
/*
/************************************************************************************/
 
virt_GetProgress *pt_GetProgress; //(LPBYTE progress);
virt_GetActivityTime *pt_GetActivityTime; //(LPDWORD time);
virt_SetActivityTime *pt_SetActivityTime; //(DWORD time);
virt_TARGET_GetFlashSize *pt_TARGET_GetFlashSize; //(DWORD Addr, LPWORD val);
virt_TARGET_GetMemoryAddress *pt_TARGET_GetMemoryAddress; //(DWORD Addr, LPWORD val);
virt_TARGET_GetRDPOptionByte *pt_TARGET_GetRDPOptionByte; //(LPBYTE RDP);
virt_TARGET_GetWRPOptionBytes *pt_TARGET_GetWRPOptionBytes; //(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
virt_Send_RQ *pt_Send_RQ; //(LPSTBL_Request pRQ);
virt_SetCOMSettings *pt_SetCOMSettings; //(int numPort, long speedInBaud, int nbBit, int parity, float nbStopBit);
virt_COM_Open *pt_COM_Open; //();
virt_COM_Close *pt_COM_Close; //();
virt_STBL_SetSpeed *pt_STBL_SetSpeed; //(DWORD speed);
virt_STBL_Init_BL *pt_STBL_Init_BL; //();
virt_STBL_GET *pt_STBL_GET; //(LPBYTE Version, LPCommands pCmds);
virt_STBL_GET_VER_ROPS *pt_STBL_GET_VER_ROPS; //(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled);
virt_STBL_GET_ID *pt_STBL_GET_ID; //(LPBYTE size, LPBYTE pID);
virt_STBL_READ *pt_STBL_READ; //(DWORD Address, BYTE Size, LPBYTE pData);
virt_STBL_GO *pt_STBL_GO; //(DWORD Address);
virt_STBL_WRITE *pt_STBL_WRITE; //(DWORD address, BYTE size, LPBYTE pData);
virt_STBL_ERASE *pt_STBL_ERASE; //(BYTE NbSectors, LPBYTE pSectors);
virt_STBL_WRITE_PROTECT *pt_STBL_WRITE_PROTECT; //(BYTE NbSectors, LPBYTE pSectors);
virt_STBL_WRITE_TEMP_UNPROTECT *pt_STBL_WRITE_TEMP_UNPROTECT; //();
virt_STBL_WRITE_PERM_UNPROTECT *pt_STBL_WRITE_PERM_UNPROTECT; //();
virt_STBL_READOUT_PROTECT *pt_STBL_READOUT_PROTECT; //();
virt_STBL_READOUT_TEMP_UNPROTECT *pt_STBL_READOUT_TEMP_UNPROTECT; //();
virt_STBL_READOUT_PERM_UNPROTECT *pt_STBL_READOUT_PERM_UNPROTECT; //();
virt_STBL_UPLOAD *pt_STBL_UPLOAD; //(DWORD Address, LPBYTE pData, DWORD Length);
virt_STBL_VERIFY *pt_STBL_VERIFY; //(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
virt_STBL_DNLOAD *pt_STBL_DNLOAD; //(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
virt_SetPaketSize *pt_SetPaketSize; //(BYTE size);
virt_GetPaketSize *pt_GetPaketSize; //(LPBYTE size);
virt_GetAckValue *pt_GetAckValue; //();
virt_COM_is_Open *pt_COM_is_Open; //();
virt_SetTimeOut *pt_SetTimeOut; //(DWORD vms);
virt_TARGET_GetUserOptionByte *pt_TARGET_GetUserOptionByte; //(LPBYTE User);
virt_TARGET_GetDataOptionByte *pt_TARGET_GetDataOptionByte; //(LPBYTE Data0, LPBYTE Data1);
virt_TARGET_SetSIFData *pt_TARGET_SetSIFData; //(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1, BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3);
virt_TARGET_GetSIFData *pt_TARGET_GetSIFData; //(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1, LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
virt_STBL_SetRts *pt_STBL_SetRts; //(BOOL val);
virt_STBL_SetDtr *pt_STBL_SetDtr; //(BOOL val);
virt_STBL_setTxd *pt_STBL_setTxd; //(BOOL val);
virt_STBL_getCts *pt_STBL_getCts; //(BOOL* pval);
virt_STBL_getDtr *pt_STBL_getDtr; //(BOOL* pval);
virt_STBL_getRi *pt_STBL_getRi; //(BOOL* pval);
virt_STBL_getCd *pt_STBL_getCd; //(BOOL* pval);
virt_STBL_SetEcho *pt_STBL_SetEcho ; //(int val);
virt_STBL_SetFlowControl *pt_STBL_SetFlowControl ; //(bool val);
 
 
 
 
DWORD MAX_DATA_SIZE = 0xFF; // Packet size(in byte)
BYTE ACK = 0x79;
BYTE NACK = 0x1F;
 
ACKS ACK_VALUE = ST79;
LPTARGET_DESCRIPTOR Target;
CRS232 Cur_COM;
ACKS McuTarget;
DWORD Progress;
DWORD ActivityTime ;
 
HINSTANCE ST_BL_Lib_Hdle = NULL;
 
 
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH :{
McuTarget = UNDEFINED;
Target = (LPTARGET_DESCRIPTOR)malloc(sizeof(TARGET_DESCRIPTOR));
Target->Version = 0x00;
Target->CmdCount = 0x00;
Target->PIDLen = 0x00;
Target->PID = (LPBYTE)malloc(1);
Target->ROPE = 0x00;
Target->ROPD = 0x00;
 
Target->GET_CMD = FALSE ; //Get the version and the allowed commands supported by the current version of the boot loader
Target->GET_VER_ROPS_CMD = FALSE ; //Get the BL version and the Read Protection status of the NVM
Target->GET_ID_CMD = FALSE ; //Get the chip ID
Target->READ_CMD = FALSE ; //Read up to 256 bytes of memory starting from an address specified by the user
Target->GO_CMD = FALSE ; //Jump to an address specified by the user to execute (a loaded) code
Target->WRITE_CMD = FALSE ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
Target->ERASE_CMD = FALSE ; //Erase from one to all the NVM sectors
Target->ERASE_EXT_CMD = FALSE ; //Erase from one to all the NVM sectors
Target->WRITE_PROTECT_CMD = FALSE ; //Enable the write protection in a permanent way for some sectors
Target->WRITE_TEMP_UNPROTECT_CMD = FALSE ; //Disable the write protection in a temporary way for all NVM sectors
Target->WRITE_PERM_UNPROTECT_CMD = FALSE ; //Disable the write protection in a permanent way for all NVM sectors
Target->READOUT_PERM_PROTECT_CMD = FALSE ; //Enable the readout protection in a permanent way
Target->READOUT_TEMP_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a temporary way
Target->READOUT_PERM_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a permanent way
}break;
case DLL_THREAD_ATTACH :{
/*McuTarget = UNDEFINED;
Target = (LPTARGET_DESCRIPTOR)malloc(sizeof(TARGET_DESCRIPTOR));
 
Target->Version = 0x00;
Target->CmdCount = 0x00;
Target->PIDLen = 0x00;
Target->PID = (LPBYTE)malloc(1);
Target->ROPE = 0x00;
Target->ROPD = 0x00;
 
Target->GET_CMD = FALSE ; //Get the version and the allowed commands supported by the current version of the boot loader
Target->GET_VER_ROPS_CMD = FALSE ; //Get the BL version and the Read Protection status of the NVM
Target->GET_ID_CMD = FALSE ; //Get the chip ID
Target->READ_CMD = FALSE ; //Read up to 256 bytes of memory starting from an address specified by the user
Target->GO_CMD = FALSE ; //Jump to an address specified by the user to execute (a loaded) code
Target->WRITE_CMD = FALSE ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
Target->ERASE_CMD = FALSE ; //Erase from one to all the NVM sectors
Target->WRITE_PROTECT_CMD = FALSE ; //Enable the write protection in a permanent way for some sectors
Target->WRITE_TEMP_UNPROTECT_CMD = FALSE ; //Disable the write protection in a temporary way for all NVM sectors
Target->WRITE_PERM_UNPROTECT_CMD = FALSE ; //Disable the write protection in a permanent way for all NVM sectors
Target->READOUT_PERM_PROTECT_CMD = FALSE ; //Enable the readout protection in a permanent way
Target->READOUT_TEMP_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a temporary way
Target->READOUT_PERM_UNPROTECT_CMD = FALSE ; //Disable the readout protection in a permanent way
*/}break;
case DLL_THREAD_DETACH :{}break;
case DLL_PROCESS_DETACH :{}break;
}
return TRUE;
}
 
/************************************************************************************/
/* SET COMMUNICATION INTERFACE TYPE
/* UART - CAN - ...
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_SetComIntType(BYTE com_int_type)
{
//com_int_type = 0; // This is reserved for Future, When the CANtoUSB Bridge will be available
// The CAN module and DLL should be used in com_int_type =1
 
switch (com_int_type)
{
case 0:{
ST_BL_Lib_Hdle = GetModuleHandle("STUARTBLLIB");
if ( ST_BL_Lib_Hdle == NULL )
{
ST_BL_Lib_Hdle = LoadLibrary("STUARTBLLIB") ;
}
}break;
case 1:{
ST_BL_Lib_Hdle = GetModuleHandle("STCANBLLIB");
if ( ST_BL_Lib_Hdle == NULL )
{
ST_BL_Lib_Hdle = LoadLibrary("STCANBLLIB") ;
}
}break;
}
 
 
pt_GetProgress = (virt_GetProgress*)GetProcAddress(ST_BL_Lib_Hdle,"GetProgress");
pt_GetActivityTime = (virt_GetActivityTime*)GetProcAddress(ST_BL_Lib_Hdle,"GetActivityTime"); //(LPDWORD time);
pt_SetActivityTime = (virt_SetActivityTime*)GetProcAddress(ST_BL_Lib_Hdle,"SetActivityTime"); //(DWORD time);
pt_TARGET_GetFlashSize = (virt_TARGET_GetFlashSize*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetFlashSize");
pt_TARGET_GetMemoryAddress = (virt_TARGET_GetMemoryAddress*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetMemoryAddress");
pt_TARGET_GetRDPOptionByte = (virt_TARGET_GetRDPOptionByte*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetRDPOptionByte");
pt_TARGET_GetWRPOptionBytes = (virt_TARGET_GetWRPOptionBytes*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetWRPOptionBytes");
pt_Send_RQ = (virt_Send_RQ*)GetProcAddress(ST_BL_Lib_Hdle,"Send_RQ");
pt_SetCOMSettings = (virt_SetCOMSettings*)GetProcAddress(ST_BL_Lib_Hdle,"SetCOMSettings");
pt_COM_Open = (virt_COM_Open*)GetProcAddress(ST_BL_Lib_Hdle,"COM_Open");
pt_COM_Close = (virt_COM_Close*)GetProcAddress(ST_BL_Lib_Hdle,"COM_Close");
pt_STBL_SetSpeed = (virt_STBL_SetSpeed*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetSpeed");
pt_STBL_Init_BL = (virt_STBL_Init_BL*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_Init_BL");
pt_STBL_GET = (virt_STBL_GET*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GET");
pt_STBL_GET_VER_ROPS = (virt_STBL_GET_VER_ROPS*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GET_VER_ROPS");
pt_STBL_GET_ID = (virt_STBL_GET_ID*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GET_ID");
pt_STBL_READ = (virt_STBL_READ*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READ");
pt_STBL_GO = (virt_STBL_GO*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_GO");
pt_STBL_WRITE = (virt_STBL_WRITE*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE");
pt_STBL_ERASE = (virt_STBL_ERASE*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_ERASE");
pt_STBL_WRITE_PROTECT = (virt_STBL_WRITE_PROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE_PROTECT");
pt_STBL_WRITE_TEMP_UNPROTECT = (virt_STBL_WRITE_TEMP_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE_TEMP_UNPROTECT");
pt_STBL_WRITE_PERM_UNPROTECT = (virt_STBL_WRITE_PERM_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_WRITE_PERM_UNPROTECT");
pt_STBL_READOUT_PROTECT = (virt_STBL_READOUT_PROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READOUT_PROTECT");
pt_STBL_READOUT_TEMP_UNPROTECT = (virt_STBL_READOUT_TEMP_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READOUT_TEMP_UNPROTECT");
pt_STBL_READOUT_PERM_UNPROTECT = (virt_STBL_READOUT_PERM_UNPROTECT*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_READOUT_PERM_UNPROTECT");
pt_STBL_UPLOAD = (virt_STBL_UPLOAD*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_UPLOAD");
pt_STBL_VERIFY = (virt_STBL_VERIFY*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_VERIFY");
pt_STBL_DNLOAD = (virt_STBL_DNLOAD*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_DNLOAD");
pt_SetPaketSize = (virt_SetPaketSize*)GetProcAddress(ST_BL_Lib_Hdle,"SetPaketSize");
pt_GetPaketSize = (virt_GetPaketSize*)GetProcAddress(ST_BL_Lib_Hdle,"GetPaketSize");
pt_GetAckValue = (virt_GetAckValue*)GetProcAddress(ST_BL_Lib_Hdle,"GetAckValue");
pt_COM_is_Open = (virt_COM_is_Open*)GetProcAddress(ST_BL_Lib_Hdle,"COM_is_Open");
pt_SetTimeOut = (virt_SetTimeOut*)GetProcAddress(ST_BL_Lib_Hdle,"SetTimeOut");
pt_TARGET_GetUserOptionByte = (virt_TARGET_GetUserOptionByte*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetUserOptionByte");
pt_TARGET_GetDataOptionByte = (virt_TARGET_GetDataOptionByte*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetDataOptionByte");
pt_TARGET_SetSIFData = (virt_TARGET_SetSIFData*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_SetSIFData");
pt_TARGET_GetSIFData = (virt_TARGET_GetSIFData*)GetProcAddress(ST_BL_Lib_Hdle,"TARGET_GetSIFData");
pt_STBL_SetRts = (virt_STBL_SetRts*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetRts");
pt_STBL_SetDtr = (virt_STBL_SetDtr*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetDtr");
pt_STBL_setTxd = (virt_STBL_setTxd*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_setTxd");
pt_STBL_getCts = (virt_STBL_getCts*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getCts");
pt_STBL_getDtr = (virt_STBL_getDtr*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getDtr");
pt_STBL_getRi = (virt_STBL_getRi*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getRi");
pt_STBL_getCd = (virt_STBL_getCd*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_getCd");
pt_STBL_SetEcho = (virt_STBL_SetEcho*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetEcho");
pt_STBL_SetFlowControl = (virt_STBL_SetFlowControl*)GetProcAddress(ST_BL_Lib_Hdle,"STBL_SetFlowControl");
return 0;
}
 
/************************************************************************************/
/*Set the communication settings for UART, CAN, ...
/* UART - numPort, speedInBaud, nbBit, parity, nbStopBit
/* CAN - only : speedInBaud
/************************************************************************************/
STBLLIB_API BYTE SetCOMSettings(int numPort, long speedInBaud, int nbBit,
int parity, float nbStopBit)
{
if(pt_SetCOMSettings)
return pt_SetCOMSettings(numPort, speedInBaud, nbBit, parity, nbStopBit);
else
return LIB_LOADING_ERROR;
}
 
STBLLIB_API BYTE Send_RQ(LPSTBL_Request pRQ)
{
if(pt_Send_RQ)
return pt_Send_RQ(pRQ);
else
return LIB_LOADING_ERROR;
}
 
STBLLIB_API BYTE COM_Open()
{
if(pt_COM_Open)
return pt_COM_Open();
else
return LIB_LOADING_ERROR;
}
 
STBLLIB_API BYTE COM_Close()
{
if(pt_COM_Close)
return pt_COM_Close();
else
return LIB_LOADING_ERROR;
}
 
STBLLIB_API BYTE STBL_SetSpeed(DWORD speed)
{
if(pt_STBL_SetSpeed)
return pt_STBL_SetSpeed(speed);
else
return LIB_LOADING_ERROR;
}
 
STBLLIB_API BYTE STBL_Init_BL()
{
if(pt_STBL_Init_BL)
return pt_STBL_Init_BL();
else
return LIB_LOADING_ERROR;
}
/******************************************************************************************/
/* Boot Loader commands implementation
/******************************************************************************************/
STBLLIB_API BYTE STBL_GET(LPBYTE Version, LPCommands pCmds)
{
if(pt_STBL_GET)
return pt_STBL_GET(Version, pCmds);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_GET_VER_ROPS(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled)
{
if(pt_STBL_GET_VER_ROPS)
return pt_STBL_GET_VER_ROPS(Version, ROPEnabled, ROPDisabled);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_GET_ID(LPBYTE size, LPBYTE pID)
{
if(pt_STBL_GET_ID)
return pt_STBL_GET_ID(size, pID);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_READ(DWORD Address, BYTE Size, LPBYTE pData)
{
if(pt_STBL_READ)
return pt_STBL_READ(Address, Size, pData);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_GO(DWORD Address)
{
if(pt_STBL_GO)
return pt_STBL_GO(Address);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_WRITE(DWORD address, BYTE size, LPBYTE pData)
{
if(pt_STBL_WRITE)
return pt_STBL_WRITE(address, size, pData);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_ERASE(WORD NbSectors, LPBYTE pSectors)
{
if(pt_STBL_ERASE)
return pt_STBL_ERASE(NbSectors, pSectors);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_WRITE_PROTECT(BYTE NbSectors, LPBYTE pSectors)
{
if(pt_STBL_WRITE_PROTECT)
return pt_STBL_WRITE_PROTECT(NbSectors, pSectors);
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_WRITE_TEMP_UNPROTECT()
{
if(pt_STBL_WRITE_TEMP_UNPROTECT)
return pt_STBL_WRITE_TEMP_UNPROTECT();
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_WRITE_PERM_UNPROTECT()
{
if(pt_STBL_WRITE_PERM_UNPROTECT)
return pt_STBL_WRITE_PERM_UNPROTECT();
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_READOUT_PROTECT()
{
if(pt_STBL_READOUT_PROTECT)
return pt_STBL_READOUT_PROTECT();
else
return LIB_LOADING_ERROR;
}
STBLLIB_API BYTE STBL_READOUT_TEMP_UNPROTECT()
{
if(pt_STBL_READOUT_TEMP_UNPROTECT)
return pt_STBL_READOUT_TEMP_UNPROTECT();
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* READOUT_PERM_UNPROTECT
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_READOUT_PERM_UNPROTECT()
{
if(pt_STBL_READOUT_PERM_UNPROTECT)
return pt_STBL_READOUT_PERM_UNPROTECT();
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* UPLOAD
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_UPLOAD(DWORD Address, LPBYTE pData, DWORD Length)
{
if(pt_STBL_UPLOAD)
return pt_STBL_UPLOAD(Address, pData, Length);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* VERIFY
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_VERIFY(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad)
{
if(pt_STBL_VERIFY)
return pt_STBL_VERIFY(Address, pData, Length,bTruncateLeadFFForDnLoad);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* DNLOAD - this command uses the STBL_WRITE function to download a big block of data
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_DNLOAD(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad)
{
if(pt_STBL_DNLOAD)
return pt_STBL_DNLOAD(Address, pData, Length,bTruncateLeadFFForDnLoad);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* SET PACKET SIZE
/*
/*
/************************************************************************************/
STBLLIB_API BYTE SetPaketSize(BYTE size)
{
if(pt_SetPaketSize)
return pt_SetPaketSize(size);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* GET PACKET SIZE
/*
/*
/************************************************************************************/
STBLLIB_API BYTE GetPaketSize(LPBYTE size)
{
if(pt_GetPaketSize)
return pt_GetPaketSize(size);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* GetAckValue
/*
/*
/************************************************************************************/
STBLLIB_API ACKS GetAckValue()
{
if(pt_GetAckValue)
return pt_GetAckValue();
else
return UNDEFINED;
}
 
/************************************************************************************/
/* IsConnected
/*
/*
/************************************************************************************/
STBLLIB_API BOOL COM_is_Open()
{
if(pt_COM_is_Open)
return pt_COM_is_Open();
else
return FALSE;
}
 
/************************************************************************************/
/* SetTimeOut
/*
/*
/************************************************************************************/
STBLLIB_API BYTE SetTimeOut(DWORD vms)
{
if(pt_SetTimeOut)
return pt_SetTimeOut(vms);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* GetFlashSize
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetFlashSize(DWORD Addr, LPWORD val)
{
if(pt_TARGET_GetFlashSize)
return pt_TARGET_GetFlashSize(Addr, val);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* GetMemoryAddress
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetMemoryAddress(DWORD Addr, LPBYTE val)
{
if(pt_TARGET_GetMemoryAddress)
return pt_TARGET_GetMemoryAddress(Addr, val);
else
return LIB_LOADING_ERROR;
}
 
 
/************************************************************************************/
/* GetRDPOptionByte
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetRDPOptionByte(LPBYTE RDP)
{
if(pt_TARGET_GetRDPOptionByte)
return pt_TARGET_GetRDPOptionByte(RDP);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* GetWRPOptionBytes
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetWRPOptionBytes(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3)
{
if(pt_TARGET_GetWRPOptionBytes)
return pt_TARGET_GetWRPOptionBytes(WRP0, WRP1, WRP2, WRP3);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* GetUserOptionByte
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetUserOptionByte(LPBYTE User)
{
if(pt_TARGET_GetUserOptionByte)
return pt_TARGET_GetUserOptionByte(User);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* GetDataOptionByte
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetDataOptionByte(LPBYTE Data0, LPBYTE Data1)
{
if(pt_TARGET_GetDataOptionByte)
return pt_TARGET_GetDataOptionByte(Data0, Data1);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* SetSIFData
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_SetSIFData(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1,
BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3)
{
if(pt_TARGET_SetSIFData)
return pt_TARGET_SetSIFData(User, RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* SetSIFData
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetSIFData(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1,
LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3)
{
if(pt_TARGET_GetSIFData)
return pt_TARGET_GetSIFData(User, RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* GET PROGRESS STATE
/*
/*
/************************************************************************************/
STBLLIB_API BYTE GetProgress(LPBYTE progress)
{
if(pt_GetProgress)
return pt_GetProgress(progress);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* Get activity time
/*
/*
/************************************************************************************/
STBLLIB_API BYTE GetActivityTime(LPDWORD time)
{
if(pt_GetActivityTime)
return pt_GetActivityTime(time);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* Set activity time
/*
/*
/************************************************************************************/
STBLLIB_API BYTE SetActivityTime(DWORD time)
{
if(pt_SetActivityTime)
return pt_SetActivityTime(time);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* Set Rts Line State
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_SetRts(BOOL Val)
{
if(pt_STBL_SetRts)
return pt_STBL_SetRts(Val);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* Set Dtr Line State
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_SetDtr(BOOL Val)
{
if(pt_Send_RQ)
return pt_STBL_SetDtr(Val);
else
return LIB_LOADING_ERROR;
}
 
/************************************************************************************/
/* Set the state of TXD. Return: true if success.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_setTxd(BOOL val)
{
if(pt_STBL_setTxd)
return pt_STBL_setTxd(val);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* Return: The state of CTS.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getCts(BOOL* pval)
{
if(pt_STBL_getCts)
return pt_STBL_getCts(pval);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* Return: The state of DTR.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getDtr(BOOL* pval)
{
if(pt_STBL_getDtr)
return pt_STBL_getDtr(pval);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* Return: The state of RI.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getRi(BOOL* pval)
{
if(pt_STBL_getRi)
return pt_STBL_getRi(pval);
else
return LIB_LOADING_ERROR;
}
/************************************************************************************/
/* Return: The state of DTR.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getCd(BOOL* pval)
{
if(pt_STBL_getCd)
return pt_STBL_getCd(pval);
else
return LIB_LOADING_ERROR;
}
 
 
 
/************************************************************************************/
/* Set Echo back Mode
/* 0 = Echo Disabled
/* 1 = Echo Back Enabled
/* 2 = Listen Echo Enabled
/************************************************************************************/
STBLLIB_API BYTE STBL_SetEcho(int val)
{
 
if(pt_STBL_SetEcho)
return pt_STBL_SetEcho(val);
else
return LIB_LOADING_ERROR;
}
 
 
/************************************************************************************/
/* SetFlowControl : Enable/Disable Flow Control of DTR and RTS
/* FALSE = Disabled
/* TRUE = Enabled
/************************************************************************************/
STBLLIB_API BYTE STBL_SetFlowControl(bool val)
{
 
if(pt_STBL_SetFlowControl)
return pt_STBL_SetFlowControl(val);
else
return LIB_LOADING_ERROR;
}
 
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/
 
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/STBLLIB.dsp
0,0 → 1,129
# Microsoft Developer Studio Project File - Name="STBLLIB" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
 
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
 
CFG=STBLLIB - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "STBLLIB.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "STBLLIB.mak" CFG="STBLLIB - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "STBLLIB - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "STBLLIB - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
 
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/PC/ST Generic Boot Loader/SOFTWARE/STxx BL Lib/Lib Tester", ESSAAAAA"
# PROP Scc_LocalPath "..\stblgui"
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
 
!IF "$(CFG)" == "STBLLIB - Win32 Release"
 
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 1
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "STBLLIB_EXPORTS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "STBLLIB_EXPORTS" /D "_VS6_USED" /D "_WINDLL" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 /nologo /dll /machine:I386 /out:"..\BIN\Release\STBLLIB.dll"
 
!ELSEIF "$(CFG)" == "STBLLIB - Win32 Debug"
 
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 1
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "STBLLIB_EXPORTS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "STBLLIB_EXPORTS" /D "_WINDLL" /D "_VS6_USED" /FR /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 /nologo /dll /debug /machine:I386 /out:"..\BIN\Debug\STBLLIB.dll" /pdbtype:sept
 
!ENDIF
 
# Begin Target
 
# Name "STBLLIB - Win32 Release"
# Name "STBLLIB - Win32 Debug"
# Begin Group "Source Files"
 
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
 
SOURCE=..\Crs232\rs232.cpp
# End Source File
# Begin Source File
 
SOURCE=.\STBLLIB.cpp
# End Source File
# Begin Source File
 
SOURCE=.\STBLLIB.rc
# End Source File
# End Group
# Begin Group "Header Files"
 
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
 
SOURCE=..\Crs232\rs232.h
# End Source File
# Begin Source File
 
SOURCE=.\STBLLIB.h
# End Source File
# Begin Source File
 
SOURCE=.\StdAfx.h
# End Source File
# End Group
# Begin Group "Resource Files"
 
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/STBLLIB.h
0,0 → 1,486
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : STBLLIB.h
* Author : MCD Application Team
* Version : v2.2.0
* Date : 05/03/2010
* Description : Defines the system memory boot loader protocol interface
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#ifndef STDLIB_H
#define STDLIB_H
 
#include "StdAfx.h"
#include "../CRs232/rs232.h"
 
#ifdef STBLLIB_EXPORTS
#define STBLLIB_API __declspec(dllexport)
#else
#define STBLLIB_API __declspec(dllimport)
#endif
 
const BYTE INIT_CON = 0x7F;
 
const BYTE GET_CMD = 0x00; //Get the version and the allowed commands supported by the current version of the boot loader
const BYTE GET_VER_ROPS_CMD = 0x01; //Get the BL version and the Read Protection status of the NVM
const BYTE GET_ID_CMD = 0x02; //Get the chip ID
const BYTE SET_SPEED_CMD = 0x03; //set the new baudrate
const BYTE READ_CMD = 0x11; //Read up to 256 bytes of memory starting from an address specified by the user
const BYTE GO_CMD = 0x21; //Jump to an address specified by the user to execute (a loaded) code
const BYTE WRITE_CMD = 0x31; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
const BYTE ERASE_CMD = 0x43; //Erase from one to all the NVM sectors
const BYTE ERASE_EXT_CMD = 0x44; //Erase from one to all the NVM sectors
const BYTE WRITE_PROTECT_CMD = 0x63; //Enable the write protection in a permanent way for some sectors
const BYTE WRITE_TEMP_UNPROTECT_CMD = 0x71; //Disable the write protection in a temporary way for all NVM sectors
const BYTE WRITE_PERM_UNPROTECT_CMD = 0x73; //Disable the write protection in a permanent way for all NVM sectors
const BYTE READOUT_PROTECT_CMD = 0x82; //Enable the readout protection in a permanent way
const BYTE READOUT_TEMP_UNPROTECT_CMD = 0x91; //Disable the readout protection in a temporary way
const BYTE READOUT_PERM_UNPROTECT_CMD = 0x92; //Disable the readout protection in a permanent way
 
 
const BYTE SUCCESS = 0x00; // No error
const BYTE ERROR_OFFSET = 0x00; //error offset
 
const BYTE COM_ERROR_OFFSET = ERROR_OFFSET + 0x00;
const BYTE NO_CON_AVAILABLE = COM_ERROR_OFFSET + 0x01; // No serial port opened
const BYTE COM_ALREADY_OPENED = COM_ERROR_OFFSET + 0x02; // Serial port already opened
const BYTE CANT_OPEN_COM = COM_ERROR_OFFSET + 0x03; // Fail to open serial port
const BYTE SEND_FAIL = COM_ERROR_OFFSET + 0x04; // send over serial port fail
const BYTE READ_FAIL = COM_ERROR_OFFSET + 0x05; // Read from serial port fail
 
const BYTE SYS_MEM_ERROR_OFFSET = ERROR_OFFSET + 0x10;
const BYTE CANT_INIT_BL = SYS_MEM_ERROR_OFFSET + 0x01; // Fail to start system memory BL
const BYTE UNREOGNIZED_DEVICE = SYS_MEM_ERROR_OFFSET + 0x02; // Unreconized device
const BYTE CMD_NOT_ALLOWED = SYS_MEM_ERROR_OFFSET + 0x03; // Command not allowed
const BYTE CMD_FAIL = SYS_MEM_ERROR_OFFSET + 0x04; // command failed
 
const BYTE PROGRAM_ERROR_OFFSET = ERROR_OFFSET + 0x20;
const BYTE INPUT_PARAMS_ERROR = PROGRAM_ERROR_OFFSET + 0x01;
const BYTE INPUT_PARAMS_MEMORY_ALLOCATION_ERROR = PROGRAM_ERROR_OFFSET + 0x02;
const BYTE LIB_LOADING_ERROR = PROGRAM_ERROR_OFFSET + 0x03;
 
 
 
enum ACKS {UNDEFINED=0x00, ST75=0x75, ST79=0x79};
enum INTERFACE_TYPE {UART, CAN};
 
enum EBaudRate { brCustom,br110, br300, br600, br1200, br2400, br4800, br9600, br14400, br19200, br38400,
br56000, br57600, br115200, br128000, br256000 };// Port Numbers ( custom or COM1..COM16 }
enum EPortNumber { pnCustom,pnCOM1, pnCOM2, pnCOM3, pnCOM4, pnCOM5, pnCOM6, pnCOM7,pnCOM8, pnCOM9, pnCOM10,
pnCOM11, pnCOM12, pnCOM13,pnCOM14, pnCOM15, pnCOM16 };// Data bits ( 5, 6, 7, 8 }
enum EDataBits { db5BITS, db6BITS, db7BITS, db8BITS };
// Stop bits ( 1, 1.5, 2 }
enum EStopBits { sb1BITS, sb1HALFBITS, sb2BITS };
// Parity ( None, odd, even, mark, space }
enum EParity { ptNONE, ptODD, ptEVEN, ptMARK, ptSPACE };
// Hardware Flow Control ( None, None + RTS always on, RTS/CTS }
enum EHwFlowControl { hfNONE, hfNONERTSON, hfRTSCTS };
// Software Flow Control ( None, XON/XOFF }
enum ESwFlowControl { sfNONE, sfXONXOFF };
// What to do with incomplete (incoming} packets ( Discard, Pass }
enum EPacketMode { pmDiscard, pmPass };
 
enum OPERATION {NONE, ERASE, UPLOAD, DNLOAD, DIS_R_PROT, DIS_W_PROT, ENA_R_PROT, ENA_W_PROT};
 
typedef struct RESULT
{
OPERATION operation;
char* filename;
HANDLE Image;
}* LPRESULT;
 
typedef struct Commands
{
BOOL GET_CMD ; //Get the version and the allowed commands supported by the current version of the boot loader
BOOL GET_VER_ROPS_CMD ; //Get the BL version and the Read Protection status of the NVM
BOOL GET_ID_CMD ; //Get the chip ID
BOOL SET_SPEED_CMD ; //Change the CAN baudrate
BOOL READ_CMD ; //Read up to 256 bytes of memory starting from an address specified by the user
BOOL GO_CMD ; //Jump to an address specified by the user to execute (a loaded) code
BOOL WRITE_CMD ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
BOOL ERASE_CMD ; //Erase from one to all the NVM sectors
BOOL ERASE_EXT_CMD ; //Erase from one to all the NVM sectors
BOOL WRITE_PROTECT_CMD ; //Enable the write protection in a permanent way for some sectors
BOOL WRITE_TEMP_UNPROTECT_CMD ; //Disable the write protection in a temporary way for all NVM sectors
BOOL WRITE_PERM_UNPROTECT_CMD ; //Disable the write protection in a permanent way for all NVM sectors
BOOL READOUT_PROTECT_CMD ; //Enable the readout protection in a permanent way
BOOL READOUT_TEMP_UNPROTECT_CMD ; //Disable the readout protection in a temporary way
BOOL READOUT_PERM_UNPROTECT_CMD ; //Disable the readout protection in a permanent way
}* LPCommands;
 
typedef struct TARGET_DESCRIPTOR
{
BYTE Version ;
BYTE CmdCount ;
BYTE PIDLen ;
BYTE* PID ;
 
BYTE ROPE ;
BYTE ROPD ;
 
BOOL GET_CMD ; //Get the version and the allowed commands supported by the current version of the boot loader
BOOL GET_VER_ROPS_CMD ; //Get the BL version and the Read Protection status of the NVM
BOOL GET_ID_CMD ; //Get the chip ID
BOOL SET_SPEED_CMD ;
BOOL READ_CMD ; //Read up to 256 bytes of memory starting from an address specified by the user
BOOL GO_CMD ; //Jump to an address specified by the user to execute (a loaded) code
BOOL WRITE_CMD ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
BOOL ERASE_CMD ; //Erase from one to all the NVM sectors
BOOL ERASE_EXT_CMD ; //Erase from one to all the NVM sectors
BOOL WRITE_PROTECT_CMD ; //Enable the write protection in a permanent way for some sectors
BOOL WRITE_TEMP_UNPROTECT_CMD ; //Disable the write protection in a temporary way for all NVM sectors
BOOL WRITE_PERM_UNPROTECT_CMD ; //Disable the write protection in a permanent way for all NVM sectors
BOOL READOUT_PERM_PROTECT_CMD ; //Enable the readout protection in a permanent way
BOOL READOUT_TEMP_UNPROTECT_CMD ; //Disable the readout protection in a temporary way
BOOL READOUT_PERM_UNPROTECT_CMD ; //Disable the readout protection in a permanent way
}* LPTARGET_DESCRIPTOR;
 
typedef struct STBL_Request
{
BYTE _cmd;
DWORD _address;
WORD _length;
BYTE _nbSectors;
LPTARGET_DESCRIPTOR _target;
LPBYTE _data;
WORD _wbSectors;
}* LPSTBL_Request;
 
extern "C"
{
/************************************************************************************/
/* GET PROGRESS STATE
/*
/*
/************************************************************************************/
STBLLIB_API BYTE GetProgress(LPBYTE progress);
 
/************************************************************************************/
/* GET ACTIVITY TIME
/*
/*
/************************************************************************************/
STBLLIB_API BYTE GetActivityTime(LPDWORD time);
 
/************************************************************************************/
/* SET ACTIVITY TIME
/*
/*
/************************************************************************************/
STBLLIB_API BYTE SetActivityTime(DWORD time);
 
/************************************************************************************/
/* SET COMMUNICATION INTERFACE TYPE
/* UART - CAN - ...
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_SetComIntType(BYTE com_int_type);
/************************************************************************************/
/* GetFlashSize
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetFlashSize(DWORD Addr, LPWORD val);
/************************************************************************************/
/* GetMemoryAddress
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetMemoryAddress(DWORD Addr, LPBYTE val);
/************************************************************************************/
/* GetRDPOptionByte
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetRDPOptionByte(LPBYTE RDP);
/************************************************************************************/
/* GetWRPOptionBytes
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetWRPOptionBytes(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
/************************************************************************************/
/* Basic function to send a request
/*
/*
/************************************************************************************/
STBLLIB_API BYTE Send_RQ(LPSTBL_Request pRQ);
 
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STBLLIB_API BYTE SetCOMSettings(int numPort, long speedInBaud, int nbBit,
int parity, float nbStopBit);
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
/*STBLLIB_API BYTE ESetCOMSettings(EPortNumber numPort, EBaudRate speedInBaud, EDataBits nbBit,
EParity parity, EStopBits nbStopBit);*/
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STBLLIB_API BYTE COM_Open();
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STBLLIB_API BYTE COM_Close();
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_SetSpeed(DWORD speed);
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_Init_BL();
/************************************************************************************/
/* 0x00; //Get the version and the allowed commands supported by the current version of the boot loader
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_GET(LPBYTE Version, LPCommands pCmds);
/************************************************************************************/
/* 0x01; //Get the BL version and the Read Protection status of the NVM
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_GET_VER_ROPS(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled);
/************************************************************************************/
/* 0x02; //Get the chip ID
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_GET_ID(LPBYTE size, LPBYTE pID);
/************************************************************************************/
/* 0x11; //Read up to 256 bytes of memory starting from an address specified by the user
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_READ(DWORD Address, BYTE Size, LPBYTE pData);
/************************************************************************************/
/* 0x21; //Jump to an address specified by the user to execute (a loaded) code
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_GO(DWORD Address);
/************************************************************************************/
/* 0x31; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_WRITE(DWORD address, BYTE size, LPBYTE pData);
/************************************************************************************/
/* 0x43; //Erase from one to all the NVM sectors
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_ERASE(WORD NbSectors, LPBYTE pSectors);
/************************************************************************************/
/* 0x63; //Enable the write protection in a permanent way for some sectors
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_WRITE_PROTECT(BYTE NbSectors, LPBYTE pSectors);
/************************************************************************************/
/* 0x71; //Disable the write protection in a temporary way for all NVM sectors
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_WRITE_TEMP_UNPROTECT();
/************************************************************************************/
/* 0x73; //Disable the write protection in a permanent way for all NVM sectors
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_WRITE_PERM_UNPROTECT();
/************************************************************************************/
/* 0x82; //Enable the readout protection in a permanent way
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_READOUT_PROTECT();
/************************************************************************************/
/* 0x91; //Disable the readout protection in a temporary way
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_READOUT_TEMP_UNPROTECT();
/************************************************************************************/
/* 0x92; //Disable the readout protection in a permanent way
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_READOUT_PERM_UNPROTECT();
/************************************************************************************/
/* UPLOAD
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_UPLOAD(DWORD Address, LPBYTE pData, DWORD Length);
/************************************************************************************/
/* VERIFY
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_VERIFY(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
/************************************************************************************/
/* DNLOAD
/*
/*
/************************************************************************************/
STBLLIB_API BYTE STBL_DNLOAD(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
 
/************************************************************************************/
/* SET PACKET SIZE
/*
/*
/************************************************************************************/
STBLLIB_API BYTE SetPaketSize(BYTE WORD);
/************************************************************************************/
/* GET PACKET SIZE
/*
/*
/************************************************************************************/
STBLLIB_API BYTE GetPaketSize(LPBYTE size);
 
/************************************************************************************/
/* GetAckValue
/*
/*
/************************************************************************************/
STBLLIB_API ACKS GetAckValue();
 
/************************************************************************************/
/* IsConnected
/*
/*
/************************************************************************************/
STBLLIB_API BOOL COM_is_Open();
 
/************************************************************************************/
/* SetTimeOut
/*
/*
/************************************************************************************/
STBLLIB_API BYTE SetTimeOut(DWORD vms);
/************************************************************************************/
/* GetUserOptionByte
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetUserOptionByte(LPBYTE User);
/************************************************************************************/
/* GetDataOptionByte
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetDataOptionByte(LPBYTE Data0, LPBYTE Data1);
 
/************************************************************************************/
/* SetSIFData
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_SetSIFData(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1,
BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3);
 
/************************************************************************************/
/* GetSIFData
/*
/*
/************************************************************************************/
STBLLIB_API BYTE TARGET_GetSIFData(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1,
LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
 
/************************************************************************************/
/* Set Rts Line State
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_SetRts(BOOL Val);
 
/************************************************************************************/
/* Set Dtr Line State
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_SetDtr(BOOL Val);
 
/************************************************************************************/
/* Set the state of TXD. Return: true if success.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_setTxd(BOOL val);
/************************************************************************************/
/* Return: The state of CTS.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getCts(BOOL* pval);
/************************************************************************************/
/* Return: The state of DTR.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getDtr(BOOL* pval);
/************************************************************************************/
/* Return: The state of RI.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getRi(BOOL* pval);
/************************************************************************************/
/* Return: The state of DTR.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STBLLIB_API BYTE STBL_getCd(BOOL* pval);
/************************************************************************************/
/* Set Echo back Mode
/* 0 = Echo Disabled
/* 1 = Echo Back Enabled
/* 2 = Listen Echo Enabled
/************************************************************************************/
STBLLIB_API BYTE STBL_SetEcho(int val);
 
 
/************************************************************************************/
/* SetFlowControl : Enable/Disable Flow Control of DTR and RTS
/* FALSE = Disabled
/* TRUE = Enabled
/************************************************************************************/
STBLLIB_API BYTE STBL_SetFlowControl(bool val);
 
 
}
 
 
 
#endif
 
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/STBLLIB.plg
0,0 → 1,31
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: STBLLIB - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\DOCUME~1\Cm\LOCALS~1\Temp\RSP1BF.tmp" with contents
[
/nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "STBLLIB_EXPORTS" /D "_WINDLL" /D "_VS6_USED" /FR"Debug/" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"c:\Devel\ARM\Flash Loader Demonstrator\Src\Crs232\rs232.cpp"
"c:\Devel\ARM\Flash Loader Demonstrator\Src\STBLLIB\STBLLIB.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\Cm\LOCALS~1\Temp\RSP1BF.tmp"
Creating command line "link.exe /nologo /dll /incremental:yes /pdb:"Debug/STBLLIB.pdb" /debug /machine:I386 /out:"..\BIN\Debug\STBLLIB.dll" /implib:"Debug/STBLLIB.lib" /pdbtype:sept ".\Debug\rs232.obj" ".\Debug\STBLLIB.obj" ".\Debug\STBLLIB.res" "
<h3>Output Window</h3>
Compiling...
rs232.cpp
STBLLIB.cpp
Generating Code...
Linking...
Creating library Debug/STBLLIB.lib and object Debug/STBLLIB.exp
 
 
 
<h3>Results</h3>
STBLLIB.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/STBLLIB.rc
0,0 → 1,109
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
 
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
 
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
 
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
 
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
 
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
 
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,2,0,0
PRODUCTVERSION 2,2,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "STMicroelectronics\0"
VALUE "FileDescription", "Flash Loader protocol Virtual APIs\0"
VALUE "FileVersion", "2, 2, 0, 0\0"
VALUE "InternalName", "STBLLIB\0"
VALUE "LegalCopyright", "Copyright © 2010\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "STBLLIB.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "STMicroelectronics STBLLIB\0"
VALUE "ProductVersion", "2, 2, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
 
#endif // !_MAC
 
 
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
 
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
 
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
 
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
 
#endif // APSTUDIO_INVOKED
 
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
 
 
 
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
 
 
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
 
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/STBLLIB.vcproj
0,0 → 1,284
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="STBLLIB"
ProjectGUID="{F9F56A1E-4355-4CC9-92E9-5815BDC57534}"
RootNamespace="STBLLIB"
Keyword="MFCProj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Release/STBLLIB.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;STBLLIB_EXPORTS"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/STBLLIB.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="..\BIN\Release\STBLLIB.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
ProgramDatabaseFile=".\Release/STBLLIB.pdb"
ImportLibrary=".\Release/STBLLIB.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/STBLLIB.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="1"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Debug/STBLLIB.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;STBLLIB_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/STBLLIB.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="..\BIN\Debug\STBLLIB.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\Debug/STBLLIB.pdb"
ImportLibrary=".\Debug/STBLLIB.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/STBLLIB.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="..\Crs232\rs232.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="STBLLIB.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\STBLLIB.rc"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="..\Crs232\rs232.h"
>
</File>
<File
RelativePath="STBLLIB.h"
>
</File>
<File
RelativePath="StdAfx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/StdAfx.cpp
0,0 → 1,10
 
// stdafx.cpp : source file that includes just the standard includes
// STBLLIB.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
 
#include "stdafx.h"
 
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
 
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/StdAfx.h
0,0 → 1,23
 
#if !defined(AFX_STDAFX_H__5756AFC7_1A09_4C0E_B6E8_BA86A975A687__INCLUDED_)
#define AFX_STDAFX_H__5756AFC7_1A09_4C0E_B6E8_BA86A975A687__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
 
// Insert your headers here
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
 
 
#include <windows.h>
 
//#include "../Files/Files.h"
 
// TODO: reference additional headers your program requires here
 
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
#endif // !defined(AFX_STDAFX_H__5756AFC7_1A09_4C0E_B6E8_BA86A975A687__INCLUDED_)
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STBLLIB/resource.h
0,0 → 1,15
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by STBLLIB.rc
//
 
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/Files.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/Ini.cpp
0,0 → 1,1064
/////////////////////////////////////////////////////////////////////////////////
// Cini Class Implementation
/////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h" // include if you got "fatal error C1010: unexpected end of file..."
#include "Ini.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
 
#define DEF_PROFILE_NUM_LEN 64 // numeric string length, could be quite long for binary format
#define DEF_PROFILE_THRESHOLD 512 // temporary string length
#define DEF_PROFILE_DELIMITER _T(",") // default string delimiter
#define DEF_PROFILE_TESTSTRING _T("{63788286-AE30-4D6B-95DF-3B451C1C79F9}") // Uuid for internal use
 
// struct used to be passed to __KeyPairProc as a LPVOID parameter
struct STR_LIMIT
{
LPTSTR lpTarget;
DWORD dwRemain;
DWORD dwTotalCopied;
};
 
/////////////////////////////////////////////////////////////////////////////////
// Constructors & Destructor
/////////////////////////////////////////////////////////////////////////////////
CIni::CIni()
{
m_pszPathName = NULL;
}
 
CIni::CIni(LPCTSTR lpPathName)
{
m_pszPathName = NULL;
SetPathName(lpPathName);
}
 
CIni::~CIni()
{
if (m_pszPathName != NULL)
delete [] m_pszPathName;
}
 
/////////////////////////////////////////////////////////////////////////////////
// Ini File Path Access
/////////////////////////////////////////////////////////////////////////////////
 
// Assign ini file path name
void CIni::SetPathName(LPCTSTR lpPathName)
{
if (lpPathName == NULL)
{
if (m_pszPathName != NULL)
*m_pszPathName = _T('\0');
}
else
{
if (m_pszPathName != NULL)
delete [] m_pszPathName;
 
m_pszPathName = _tcsdup(lpPathName);
}
}
 
// Retrieve ini file path name
DWORD CIni::GetPathName(LPTSTR lpBuffer, DWORD dwBufSize) const
{
*lpBuffer = _T('\0');
DWORD dwLen = 0;
if (lpBuffer != NULL)
{
_tcsncpy(lpBuffer, m_pszPathName, dwBufSize);
dwLen = _tcslen(lpBuffer);
}
else
{
// just calculate the required buffer size
dwLen = _tcslen(m_pszPathName);
}
return dwLen;
}
 
#ifdef __AFXWIN_H__
CString CIni::GetPathName() const
{
return CString(m_pszPathName);
}
#endif
 
/////////////////////////////////////////////////////////////////////////////////
// Raw String Access
/////////////////////////////////////////////////////////////////////////////////
 
// Get a profile string value, if the buffer size is not large enough, the result
// may be truncated.
DWORD CIni::GetString(LPCTSTR lpSection, LPCTSTR lpKey, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDefault) const
{
if (lpBuffer != NULL)
*lpBuffer = _T('\0');
 
LPTSTR psz = __GetStringDynamic(lpSection, lpKey, lpDefault);
DWORD dwLen = _tcslen(psz);
 
if (lpBuffer != NULL)
{
_tcsncpy(lpBuffer, psz, dwBufSize);
dwLen = min(dwLen, dwBufSize);
}
 
delete [] psz;
return dwLen;
}
 
#ifdef __AFXWIN_H__
CString CIni::GetString(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpDefault) const
{
LPTSTR psz = __GetStringDynamic(lpSection, lpKey, lpDefault);
CString str(psz);
delete [] psz;
return str;
}
#endif
 
// Write a string value to the ini file
BOOL CIni::WriteString(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpValue) const
{
if (lpSection == NULL || lpKey == NULL)
return FALSE;
 
return ::WritePrivateProfileString(lpSection, lpKey, lpValue == NULL ? _T("") : lpValue, m_pszPathName);
}
 
// Read a string value from the ini file, append another string after it and then write it
// back to the ini file
BOOL CIni::AppendString(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpString) const
{
if (lpString == NULL)
return FALSE;
 
TCHAR* psz = __GetStringDynamic(lpSection, lpKey);
TCHAR* pNewString = new TCHAR[_tcslen(psz) + _tcslen(lpString) + 1];
_stprintf(pNewString, _T("%s%s"), psz, lpString);
const BOOL RES = WriteString(lpSection, lpKey, pNewString);
delete [] pNewString;
delete [] psz;
return RES;
}
 
/////////////////////////////////////////////////////////////////////////////////
// Ini File String Array Access
/////////////////////////////////////////////////////////////////////////////////
 
// Get an array of string
DWORD CIni::GetArray(LPCTSTR lpSection, LPCTSTR lpKey, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDelimiter, BOOL bTrimString) const
{
if (lpBuffer != NULL)
*lpBuffer = _T('\0');
 
if (lpSection == NULL || lpKey == NULL)
return 0;
 
LPTSTR psz = __GetStringDynamic(lpSection, lpKey);
DWORD dwCopied = 0;
 
if (*psz != _T('\0'))
{
if (lpBuffer == NULL)
{
// just calculate the required buffer size
const DWORD MAX_LEN = _tcslen(psz) + 2;
LPTSTR p = new TCHAR[MAX_LEN + 1];
dwCopied = __StringSplit(psz, p, MAX_LEN, lpDelimiter, bTrimString);
delete [] p;
}
else
{
dwCopied = __StringSplit(psz, lpBuffer, dwBufSize, lpDelimiter, bTrimString);
}
}
 
delete [] psz;
return dwCopied;
}
 
#ifdef __AFXWIN_H__
void CIni::GetArray(LPCTSTR lpSection, LPCTSTR lpKey, CStringArray *pArray, LPCTSTR lpDelimiter, BOOL bTrimString) const
{
if (pArray != NULL)
pArray->RemoveAll();
 
const DWORD LEN = GetArray(lpSection, lpKey, NULL, 0, lpDelimiter);
if (LEN == 0)
return;
 
LPTSTR psz = new TCHAR[LEN + 3];
GetArray(lpSection, lpKey, psz, LEN + 2, lpDelimiter);
ParseDNTString(psz, __SubStrAdd, (LPVOID)pArray);
delete [] psz;
}
#endif
 
#ifdef __AFXWIN_H__
BOOL CIni::WriteArray(LPCTSTR lpSection, LPCTSTR lpKey, const CStringArray *pArray, int nWriteCount, LPCTSTR lpDelimiter) const
{
if (pArray == NULL)
return FALSE;
 
if (nWriteCount < 0)
nWriteCount = pArray->GetSize();
else
nWriteCount = min(nWriteCount, pArray->GetSize());
 
const CString DELIMITER = (lpDelimiter == NULL || *lpDelimiter == _T('\0')) ? _T(",") : lpDelimiter;
CString sLine;
for (int i = 0; i < nWriteCount; i++)
{
sLine += pArray->GetAt(i);
if (i != nWriteCount - 1)
sLine += DELIMITER;
}
return WriteString(lpSection, lpKey, sLine);
}
#endif
 
/////////////////////////////////////////////////////////////////////////////////
// Primitive Data Type Access
/////////////////////////////////////////////////////////////////////////////////
 
// Get a signed integral value
int CIni::GetInt(LPCTSTR lpSection, LPCTSTR lpKey, int nDefault, int nBase) const
{
TCHAR sz[DEF_PROFILE_NUM_LEN + 1] = _T("");
GetString(lpSection, lpKey, sz, DEF_PROFILE_NUM_LEN);
return *sz == _T('\0') ? nDefault : int(_tcstoul(sz, NULL, __ValidateBase(nBase)));
}
 
// Get an unsigned integral value
UINT CIni::GetUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nDefault, int nBase) const
{
TCHAR sz[DEF_PROFILE_NUM_LEN + 1] = _T("");
GetString(lpSection, lpKey, sz, DEF_PROFILE_NUM_LEN);
return *sz == _T('\0') ? nDefault : UINT(_tcstoul(sz, NULL, __ValidateBase(nBase)));
}
 
// Get a boolean value
BOOL CIni::GetBool(LPCTSTR lpSection, LPCTSTR lpKey, BOOL bDefault) const
{
TCHAR sz[DEF_PROFILE_NUM_LEN + 1] = _T("");
GetString(lpSection, lpKey, sz, DEF_PROFILE_NUM_LEN);
return StringToBool(sz, bDefault);
}
 
// Get a double floating value
double CIni::GetDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fDefault) const
{
TCHAR sz[DEF_PROFILE_NUM_LEN + 1] = _T("");
GetString(lpSection, lpKey, sz, DEF_PROFILE_NUM_LEN);
return *sz == _T('\0') ? fDefault : _tcstod(sz, NULL);
}
 
// Write a signed integral value to the ini file
BOOL CIni::WriteInt(LPCTSTR lpSection, LPCTSTR lpKey, int nValue, int nBase) const
{
TCHAR szValue[DEF_PROFILE_NUM_LEN + 1] = _T("");
__IntToString(nValue, szValue, nBase);
return WriteString(lpSection, lpKey, szValue);
}
 
// Write an unsigned value to the ini file
BOOL CIni::WriteUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nValue, int nBase) const
{
TCHAR szValue[DEF_PROFILE_NUM_LEN + 1] = _T("");
__UIntToString(nValue, szValue, nBase);
return WriteString(lpSection, lpKey, szValue);
}
 
// Write a double floating value to the ini file
BOOL CIni::WriteDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fValue, int nPrecision) const
{
TCHAR szFmt[16] = _T("%f");
 
if (nPrecision > 0)
_stprintf(szFmt, _T("%%.%df"), nPrecision);
 
TCHAR szValue[DEF_PROFILE_NUM_LEN + 1] = _T("");
_stprintf(szValue, szFmt, fValue);
return WriteString(lpSection, lpKey, szValue);
}
 
// Read a double value from the ini file, increase it then write it back
BOOL CIni::IncreaseDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fIncrease, int nPrecision) const
{
double f = GetDouble(lpSection, lpKey, 0.0);
f += fIncrease;
return WriteDouble(lpSection, lpKey, f, nPrecision);
}
 
// Write a boolean value to the ini file
BOOL CIni::WriteBool(LPCTSTR lpSection, LPCTSTR lpKey, BOOL bValue) const
{
return WriteInt(lpSection, lpKey, bValue ? 1 : 0, BASE_DECIMAL);
}
 
// Read a boolean value from the ini file, invert it(true becomes false, false becomes true),
// then write it back
BOOL CIni::InvertBool(LPCTSTR lpSection, LPCTSTR lpKey) const
{
return WriteBool(lpSection, lpKey, !GetBool(lpSection, lpKey, FALSE));
}
 
// Read a int from the ini file, increase it and then write it back to the ini file
BOOL CIni::IncreaseInt(LPCTSTR lpSection, LPCTSTR lpKey, int nIncrease, int nBase) const
{
int nVal = GetInt(lpSection, lpKey, 0, nBase);
nVal += nIncrease;
return WriteInt(lpSection, lpKey, nVal, nBase);
}
 
// Read an UINT from the ini file, increase it and then write it back to the ini file
BOOL CIni::IncreaseUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nIncrease, int nBase) const
{
UINT nVal = GetUInt(lpSection, lpKey, 0, nBase);
nVal += nIncrease;
return WriteUInt(lpSection, lpKey, nVal, nBase);
}
 
TCHAR CIni::GetChar(LPCTSTR lpSection, LPCTSTR lpKey, TCHAR cDefault) const
{
TCHAR sz[2] = _T("");
GetString(lpSection, lpKey, sz, 1);
return *sz == _T('\0') ? cDefault : sz[0];
}
 
BOOL CIni::WriteChar(LPCTSTR lpSection, LPCTSTR lpKey, TCHAR c) const
{
TCHAR sz[2] = { c, _T('\0') };
return WriteString(lpSection, lpKey, sz);
}
 
/////////////////////////////////////////////////////////////////////////////////
// User-Defined Data Type Access
/////////////////////////////////////////////////////////////////////////////////
 
// Get a block of raw data from the ini file
DWORD CIni::GetDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPVOID lpBuffer, DWORD dwBufSize, DWORD dwOffset) const
{
LPTSTR psz = __GetStringDynamic(lpSection, lpKey);
DWORD dwLen = _tcslen(psz) / 2;
if (dwLen <= dwOffset)
{
delete [] psz;
return 0;
}
 
// verify psz, must be all in hex format
for (int i = 0; psz[i] != _T('\0'); i++)
{
TCHAR c = psz[i];
if ((c >= _T('0') && c <= _T('9'))
|| (c >= _T('a') && c <= _T('f'))
|| (c >= _T('A') && c <= _T('F')))
{
// valid
}
else
{
delete [] psz;
return 0;
}
}
 
DWORD dwProcLen = 0;
LPBYTE lpb = (LPBYTE)lpBuffer;
 
if (lpb != NULL)
{
dwProcLen = min(dwLen - dwOffset, dwBufSize);
LPCTSTR p = &psz[dwOffset * 2];
for (DWORD i = 0; i < dwProcLen; i++)
{
TCHAR sz[3] = _T("");
_tcsncpy(sz, p, 2);
lpb[i] = BYTE(_tcstoul(sz, NULL, 16));
p = &p[2];
}
}
else
{
dwProcLen = dwLen - dwOffset;
}
delete [] psz;
return dwProcLen;
}
 
// Write a block of raw data to the ini file
BOOL CIni::WriteDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPCVOID lpData, DWORD dwDataSize) const
{
const BYTE* lpb = (const BYTE*)lpData;
if (lpb == NULL)
return FALSE;
 
LPTSTR psz = new TCHAR[dwDataSize * 2 + 1];
for (DWORD i = 0, j = 0; i < dwDataSize; i++, j += 2)
_stprintf(&psz[j], _T("%02X"), lpb[i]);
const BOOL RES = WriteString(lpSection, lpKey, psz);
delete [] psz;
return RES;
}
 
// Append a block of raw data to a specified key in the ini file
BOOL CIni::AppendDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPCVOID lpData, DWORD dwDataSize) const
{
const BYTE* lpb = (const BYTE*)lpData;
if (lpb == NULL)
return FALSE;
 
LPTSTR psz = new TCHAR[dwDataSize * 2 + 1];
for (DWORD i = 0, j = 0; i < dwDataSize; i++, j += 2)
_stprintf(&psz[j], _T("%02X"), lpb[i]);
const BOOL RES = AppendString(lpSection, lpKey, psz);
delete [] psz;
return RES;
}
 
// Get a POINT value
POINT CIni::GetPoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT ptDefault) const
{
POINT pt;
if (GetDataBlock(lpSection, lpKey, &pt, sizeof(POINT)) != sizeof(POINT))
pt = ptDefault;
return pt;
}
 
// Get a RECT value
RECT CIni::GetRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rcDefault) const
{
RECT rc;
if (GetDataBlock(lpSection, lpKey, &rc, sizeof(RECT)) != sizeof(RECT))
rc = rcDefault;
return rc;
}
 
// Write a POINT to the ini file
BOOL CIni::WritePoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT pt) const
{
return WriteDataBlock(lpSection, lpKey, &pt, sizeof(POINT));
}
 
// Write a RECT to the ini file
BOOL CIni::WriteRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rc) const
{
return WriteDataBlock(lpSection, lpKey, &rc, sizeof(RECT));
}
 
/////////////////////////////////////////////////////////////////////////////////
// Sections & Keys Access
/////////////////////////////////////////////////////////////////////////////////
 
// Retrieve a list of key-lines(key-pairs) of the specified section
DWORD CIni::GetKeyLines(LPCTSTR lpSection, LPTSTR lpBuffer, DWORD dwBufSize) const
{
if (lpBuffer != NULL)
*lpBuffer = _T('\0');
 
if (lpSection == NULL)
return 0;
 
if (lpBuffer == NULL)
{
// just calculate the required buffer size
DWORD dwLen = DEF_PROFILE_THRESHOLD;
LPTSTR psz = new TCHAR[dwLen + 1];
DWORD dwCopied = ::GetPrivateProfileSection(lpSection, psz, dwLen, m_pszPathName);
 
while (dwCopied + 2 >= dwLen)
{
dwLen += DEF_PROFILE_THRESHOLD;
delete [] psz;
psz = new TCHAR[dwLen + 1];
dwCopied = ::GetPrivateProfileSection(lpSection, psz, dwLen, m_pszPathName);
}
 
delete [] psz;
return dwCopied + 2;
}
else
{
return ::GetPrivateProfileSection(lpSection, lpBuffer, dwBufSize, m_pszPathName);
}
}
 
// Retrieve a list of key names of the specified section
DWORD CIni::GetKeyNames(LPCTSTR lpSection, LPTSTR lpBuffer, DWORD dwBufSize) const
{
if (lpBuffer != NULL)
*lpBuffer = _T('\0');
 
if (lpSection == NULL)
return 0;
 
STR_LIMIT sl;
sl.lpTarget = lpBuffer;
sl.dwRemain = dwBufSize;
sl.dwTotalCopied = 0;
 
const DWORD LEN = GetKeyLines(lpSection, NULL, 0);
if (LEN == 0)
return 0;
 
LPTSTR psz = new TCHAR[LEN + 1];
GetKeyLines(lpSection, psz, LEN);
ParseDNTString(psz, __KeyPairProc, (LPVOID)(&sl));
delete [] psz;
if (lpBuffer != NULL)
lpBuffer[sl.dwTotalCopied] = _T('\0');
return sl.dwTotalCopied;
}
 
// Get all section names from an ini file
DWORD CIni::GetSectionNames(LPTSTR lpBuffer, DWORD dwBufSize) const
{
if (lpBuffer == NULL)
{
// just calculate the required buffer size
DWORD dwLen = DEF_PROFILE_THRESHOLD;
LPTSTR psz = new TCHAR[dwLen + 1];
DWORD dwCopied = ::GetPrivateProfileSectionNames(psz, dwLen, m_pszPathName);
while (dwCopied + 2 >= dwLen)
{
dwLen += DEF_PROFILE_THRESHOLD;
delete [] psz;
psz = new TCHAR[dwLen + 1];
dwCopied = ::GetPrivateProfileSectionNames(psz, dwLen, m_pszPathName);
}
delete [] psz;
return dwCopied + 2;
}
else
{
return ::GetPrivateProfileSectionNames(lpBuffer, dwBufSize, m_pszPathName);
}
}
 
#ifdef __AFXWIN_H__
void CIni::GetSectionNames(CStringArray *pArray) const
{
if (pArray != NULL)
pArray->RemoveAll();
 
const DWORD LEN = GetSectionNames(NULL, 0);
if (LEN == 0)
return;
 
LPTSTR psz = new TCHAR[LEN + 1];
GetSectionNames(psz, LEN);
ParseDNTString(psz, __SubStrAdd, pArray);
delete [] psz;
}
#endif
 
#ifdef __AFXWIN_H__
// Retrieve a list of key-lines(key-pairs) of the specified section
void CIni::GetKeyLines(LPCTSTR lpSection, CStringArray *pArray) const
{
if (pArray != NULL)
pArray->RemoveAll();
 
const DWORD LEN = GetKeyLines(lpSection, NULL, 0);
if (LEN == 0)
return;
 
LPTSTR psz = new TCHAR[LEN + 1];
GetKeyLines(lpSection, psz, LEN);
ParseDNTString(psz, __SubStrAdd, pArray);
delete [] psz;
}
#endif
 
#ifdef __AFXWIN_H__
// Retrieve a list of key names of the specified section
void CIni::GetKeyNames(LPCTSTR lpSection, CStringArray *pArray) const
{
if (pArray == NULL)
return;
 
pArray->RemoveAll();
#ifndef _VS_USED
const int LEN = GetKeyNames(lpSection, NULL, 0);
#else
const LEN = GetKeyNames(lpSection, NULL, 0);
#endif
LPTSTR psz = new TCHAR[LEN + 1];
GetKeyNames(lpSection, psz, LEN);
ParseDNTString(psz, __SubStrAdd, (LPVOID)pArray);
delete [] psz;
}
#endif
 
// Remove whole section from the ini file
BOOL CIni::DeleteSection(LPCTSTR lpSection) const
{
return ::WritePrivateProfileString(lpSection, NULL, _T(""), m_pszPathName);
}
 
// Remove a key from a section
BOOL CIni::DeleteKey(LPCTSTR lpSection, LPCTSTR lpKey) const
{
return ::WritePrivateProfileString(lpSection, lpKey, NULL, m_pszPathName);
}
 
BOOL CIni::IsSectionExist(LPCTSTR lpSection) const
{
if (lpSection == NULL)
return FALSE;
 
// first get the section name list, then check if lpSection exists
// in the list.
const DWORD LEN = GetSectionNames(NULL, 0);
if (LEN == 0)
return FALSE;
 
LPTSTR psz = new TCHAR[LEN + 1];
GetSectionNames(psz, LEN);
BOOL RES = !ParseDNTString(psz, __SubStrCompare, (LPVOID)lpSection);
delete [] psz;
return RES;
}
 
BOOL CIni::IsKeyExist(LPCTSTR lpSection, LPCTSTR lpKey) const
{
if (lpSection == NULL || lpKey == NULL)
return FALSE;
 
// Test it with the default unique string
LPTSTR psz = __GetStringDynamic(lpSection, lpKey, DEF_PROFILE_TESTSTRING);
const BOOL RES = (_tcscmp(psz, DEF_PROFILE_TESTSTRING) != 0);
delete [] psz;
return RES;
}
 
BOOL CIni::CopySection(LPCTSTR lpSrcSection, LPCTSTR lpDestSection, BOOL bFailIfExist) const
{
if (lpSrcSection == NULL || lpDestSection == NULL)
return FALSE;
 
if (_tcsicmp(lpSrcSection, lpDestSection) == 0)
return FALSE;
 
if (!IsSectionExist(lpSrcSection))
return FALSE;
 
if (bFailIfExist && IsSectionExist(lpDestSection))
return FALSE;
 
DeleteSection(lpDestSection);
 
const DWORD SRC_LEN = GetKeyLines(lpSrcSection, NULL, 0);
LPTSTR psz = new TCHAR[SRC_LEN + 2];
//memset(psz, 0, sizeof(TCHAR) * (SRC_LEN + 2));
GetKeyLines(lpSrcSection, psz, SRC_LEN);
const BOOL RES = ::WritePrivateProfileSection(lpDestSection, psz, m_pszPathName);
delete [] psz;
 
return RES;
}
 
BOOL CIni::CopyKey(LPCTSTR lpSrcSection, LPCTSTR lpSrcKey, LPCTSTR lpDestSection, LPCTSTR lpDestKey, BOOL bFailIfExist) const
{
if (lpSrcSection == NULL || lpSrcKey == NULL || lpDestKey == NULL)
return FALSE;
 
if (_tcsicmp(lpSrcSection, lpDestSection) == 0
&& _tcsicmp(lpSrcKey, lpDestKey) == 0)
return FALSE;
 
if (!IsKeyExist(lpSrcSection, lpSrcKey))
return FALSE;
 
if (bFailIfExist && IsKeyExist(lpDestSection, lpDestKey))
return FALSE;
LPTSTR psz = __GetStringDynamic(lpSrcSection, lpSrcKey);
const BOOL RES = WriteString(lpDestSection, lpDestKey, psz);
delete [] psz;
return RES;
}
 
BOOL CIni::MoveSection(LPCTSTR lpSrcSection, LPCTSTR lpDestSection, BOOL bFailIfExist) const
{
return CopySection(lpSrcSection, lpDestSection, bFailIfExist)
&& DeleteSection(lpSrcSection);
}
 
BOOL CIni::MoveKey(LPCTSTR lpSrcSection, LPCTSTR lpSrcKey, LPCTSTR lpDestSection, LPCTSTR lpDestKey, BOOL bFailIfExist) const
{
return CopyKey(lpSrcSection, lpSrcKey, lpDestSection, lpDestKey, bFailIfExist)
&& DeleteKey(lpSrcSection, lpSrcKey);
}
 
/////////////////////////////////////////////////////////////////////////////////
// Helper Functions
/////////////////////////////////////////////////////////////////////////////////
 
// Get a profile string value, return a heap pointer so we do not have to worry
// about the buffer size, however, this function requires the caller to manually
// free the memory.
// This function is the back-bone of all "Getxxx" functions of this class.
LPTSTR CIni::__GetStringDynamic(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpDefault) const
{
TCHAR* psz = NULL;
if (lpSection == NULL || lpKey == NULL)
{
// Invalid section or key name, just return the default string
if (lpDefault == NULL)
{
// Empty string
psz = new TCHAR[1];
*psz = _T('\0');
}
else
{
psz = new TCHAR[_tcslen(lpDefault) + 1];
_tcscpy(psz, lpDefault);
}
return psz;
}
// Keep enlarging the buffer size until being certain on that the string we
// retrieved was original(not truncated).
DWORD dwLen = DEF_PROFILE_THRESHOLD;
psz = new TCHAR[dwLen + 1];
DWORD dwCopied = ::GetPrivateProfileString(lpSection, lpKey, lpDefault == NULL ? _T("") : lpDefault, psz, dwLen, m_pszPathName);
while (dwCopied + 1 >= dwLen)
{
dwLen += DEF_PROFILE_THRESHOLD;
delete [] psz;
psz = new TCHAR[dwLen + 1];
dwCopied = ::GetPrivateProfileString(lpSection, lpKey, lpDefault == NULL ? _T("") : lpDefault, psz, dwLen, m_pszPathName);
}
return psz; // !!! Requires the caller to free this memory !!!
}
 
// Split a string usinf a particular delimiter, split result are copied into lpBuffer
// in the "double null terminated string" format as the following figure shows:
// xxx\0xxxx\0xx\0xxx\0\0
//
// For example, if the delimiter is ",", then string "ab,cd,e" will be
// splitted into "ab\0cd\0e\0\0", this string format can be parsed into an array
// of sub strings easily using user defined functions or CIni::ParseStringArray.
DWORD CIni::__StringSplit(LPCTSTR lpString, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDelimiter, BOOL bTrimString)
{
if (lpString == NULL || lpBuffer == NULL || dwBufSize == 0)
return 0;
 
DWORD dwCopied = 0;
*lpBuffer = _T('\0');
if (*lpString == _T('\0'))
return 0;
 
// If lpDelimiter is NULL, use the default delimiter ",", if delimiter length
// is 0, then return whole string
if (lpDelimiter != NULL && *lpDelimiter == _T('\0'))
{
_tcsncpy(lpBuffer, lpString, dwBufSize - 1);
return _tcslen(lpBuffer);
}
 
LPTSTR pszDel = (lpDelimiter == NULL) ? _tcsdup(DEF_PROFILE_DELIMITER) : _tcsdup(lpDelimiter);
const DWORD DEL_LEN = _tcslen(pszDel);
LPTSTR lpTarget = lpBuffer;
 
// Search through lpString for delimiter matches, and extract sub strings out
LPCTSTR lpPos = lpString;
LPCTSTR lpEnd = _tcsstr(lpPos, pszDel);
 
while (lpEnd != NULL)
{
LPTSTR pszSeg = __StrDupEx(lpPos, lpEnd);
if (bTrimString)
__TrimString(pszSeg);
 
const DWORD SEG_LEN = _tcslen(pszSeg);
const DWORD COPY_LEN = min(SEG_LEN, dwBufSize - dwCopied);
 
// Need to avoid buffer overflow
if (COPY_LEN > 0)
{
dwCopied += COPY_LEN + 1;
_tcsncpy(lpTarget, pszSeg, COPY_LEN);
lpTarget[COPY_LEN] = _T('\0');
lpTarget = &lpTarget[SEG_LEN + 1];
}
delete [] pszSeg;
lpPos = &lpEnd[DEL_LEN]; // Advance the pointer for next search
lpEnd = _tcsstr(lpPos, pszDel);
}
 
// The last part of string, there may not be the trailing delimiter, so we
// need to take care of this part, too
LPTSTR pszSeg = _tcsdup(lpPos);
if (bTrimString)
__TrimString(pszSeg);
 
const DWORD SEG_LEN = _tcslen(pszSeg);
const DWORD COPY_LEN = min(SEG_LEN, dwBufSize - dwCopied);
 
if (COPY_LEN > 0)
{
dwCopied += COPY_LEN + 1;
_tcsncpy(lpTarget, pszSeg, COPY_LEN);
lpTarget[COPY_LEN] = _T('\0');
}
 
delete [] pszSeg;
lpBuffer[dwCopied] = _T('\0');
delete [] pszDel;
return dwCopied;
}
 
// Parse a "double null terminated string", pass each sub string to a user-defined
// callback function
BOOL CIni::ParseDNTString(LPCTSTR lpString, SUBSTRPROC lpFnStrProc, LPVOID lpParam)
{
if (lpString == NULL || lpFnStrProc == NULL)
return FALSE;
 
LPCTSTR p = lpString;
DWORD dwLen = _tcslen(p);
 
while (dwLen > 0)
{
if (!lpFnStrProc(p, lpParam))
return FALSE;
 
p = &p[dwLen + 1];
dwLen = _tcslen(p);
}
return TRUE;
}
 
// Callback function used to compare elements inside of a
// "double null terminated string" with a given string. Useful for
// searching in the section names list.
BOOL CALLBACK CIni::__SubStrCompare(LPCTSTR lpString1, LPVOID lpParam)
{
assert(lpString1 != NULL);
LPCTSTR lpString2 = (LPCTSTR)lpParam;
assert(lpString2 != NULL);
// if two string matches, return zero to stop the parsing
return _tcsicmp(lpString1, lpString2) != 0;
}
 
// Callback function used to process a key-pair, it extracts the
// key name from the key-pair string
BOOL CALLBACK CIni:: __KeyPairProc(LPCTSTR lpString, LPVOID lpParam)
{
STR_LIMIT* psl = (STR_LIMIT*)lpParam;
if (lpString == NULL || psl== NULL)
return FALSE;
LPCTSTR p = _tcschr(lpString, _T('='));
if (p == NULL || p == lpString)
return TRUE;
// extract the sub-string on left side of the '='
LPTSTR psz = new TCHAR[_tcslen(lpString) + 1];
 
#ifndef _VS6_USED
int i;
#endif
 
for (int i = 0; &lpString[i] < p; i++)
psz[i] = lpString[i];
psz[i] = _T('\0');
 
// trim
__TrimString(psz);
DWORD dwNameLen = _tcslen(psz);
DWORD dwCopyLen = 0;
//copy to the buffer
if (psl->lpTarget != NULL)
{
dwCopyLen = (psl->dwRemain > 1) ? min(dwNameLen, psl->dwRemain - 1) : 0;
_tcsncpy(psl->lpTarget, psz, dwCopyLen);
psl->lpTarget[dwCopyLen] = _T('\0');
psl->lpTarget = &(psl->lpTarget[dwCopyLen + 1]);
psl->dwRemain -= dwCopyLen + 1;
}
else
{
dwCopyLen = dwNameLen;
}
 
delete [] psz;
psl->dwTotalCopied += dwCopyLen + 1;
return TRUE;
}
 
#ifdef __AFXWIN_H__
// Callback function used to add elements that are extracted from a
// "double null terminated string" to an MFC CStringArray.
BOOL CALLBACK CIni::__SubStrAdd(LPCTSTR lpString, LPVOID lpParam)
{
CStringArray* pArray = (CStringArray*)lpParam;
if (pArray == NULL || lpString == NULL)
return FALSE;
 
pArray->Add(lpString);
return TRUE;
}
#endif
 
// Convert an integer into binary string format
void CIni::__ToBinaryString(UINT nNumber, LPTSTR lpBuffer, DWORD dwBufSize)
{
if (dwBufSize == 0)
return;
DWORD dwIndex = 0;
do
{
lpBuffer[dwIndex++] = (nNumber % 2) ? _T('1') : _T('0');
nNumber /= 2;
} while (nNumber > 0 && dwIndex < dwBufSize);
 
lpBuffer[dwIndex] = _T('\0');
_tcsrev(lpBuffer);
}
 
// Make sure the base will be expected value
int CIni::__ValidateBase(int nBase)
{
switch (nBase)
{
case BASE_BINARY:
case BASE_OCTAL:
case BASE_HEXADECIMAL:
break;
 
default:
nBase = BASE_DECIMAL;
}
 
return nBase;
}
 
// Convert a signed integer into string representation, based on its base
void CIni::__IntToString(int nNumber, LPTSTR lpBuffer, int nBase)
{
switch (nBase)
{
case BASE_BINARY:
case BASE_OCTAL:
case BASE_HEXADECIMAL:
__UIntToString((UINT)nNumber, lpBuffer, nBase);
break;
 
default:
_stprintf(lpBuffer, _T("%d"), nNumber);
break;
}
}
 
// Convert an unsigned integer into string representation, based on its base
void CIni::__UIntToString(UINT nNumber, LPTSTR lpBuffer, int nBase)
{
switch (nBase)
{
case BASE_BINARY:
__ToBinaryString(nNumber, lpBuffer, DEF_PROFILE_NUM_LEN);
break;
 
case BASE_OCTAL:
_stprintf(lpBuffer, _T("%o"), nNumber);
break;
 
case BASE_HEXADECIMAL:
_stprintf(lpBuffer, _T("%X"), nNumber);
break;
 
default:
_stprintf(lpBuffer, _T("%u"), nNumber);
break;
}
}
 
BOOL CIni::StringToBool(LPCTSTR lpString, BOOL bDefault)
{
// Default: empty string
// TRUE: "true", "yes", non-zero decimal numner
// FALSE: all other cases
if (lpString == NULL || *lpString == _T('\0'))
return bDefault;
 
return (_tcsicmp(lpString, _T("true")) == 0
|| _tcsicmp(lpString, _T("yes")) == 0
|| _tcstol(lpString, NULL, BASE_DECIMAL) != 0);
}
 
BOOL CIni::__TrimString(LPTSTR lpString)
{
if (lpString == NULL)
return FALSE;
 
BOOL bTrimmed = FALSE;
int nLen = _tcslen(lpString);
 
// '\n' and '\r' are actually not possible in this case, but anyway...
// Trim right side
while (nLen >= 0
&& (lpString[nLen - 1] == _T(' ')
|| lpString[nLen - 1] == _T('\t')
|| lpString[nLen - 1] == _T('\r')
|| lpString[nLen - 1] == _T('\n')))
{
lpString[--nLen] = _T('\0');
bTrimmed = TRUE;
}
 
// Trim left side
LPCTSTR p = lpString;
while (*p == _T(' ')
|| *p == _T('\t')
|| *p == _T('\r')
|| *p == _T('\n'))
{
p = &p[1];
bTrimmed = TRUE;
}
 
if (p != lpString)
{
LPTSTR psz = _tcsdup(p);
_tcscpy(lpString, psz);
delete [] psz;
}
 
return bTrimmed;
}
 
LPTSTR CIni::__StrDupEx(LPCTSTR lpStart, LPCTSTR lpEnd)
{
const DWORD LEN = ((DWORD)lpEnd - (DWORD)lpStart) / sizeof(TCHAR);
LPTSTR psz = new TCHAR[LEN + 1];
_tcsncpy(psz, lpStart, LEN);
psz[LEN] = _T('\0');
return psz; // !!! Requires the caller to free this memory !!!
}
 
/////////////////////////////////////////////////////////////////////////////////
// End of Cini Class Implementation
/////////////////////////////////////////////////////////////////////////////////
 
// If you are getting this error:
// ----------------------------------------------------------------------------
// "fatal error C1010: unexpected end of file while looking for precompiled
// header directive"
//-----------------------------------------------------------------------------
// Please scroll all the way up and uncomment '#include "stdafx.h"'
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/Ini.h
0,0 → 1,171
#ifndef __INI_H__
#define __INI_H__
 
#define _VS6_USED
 
#include <windows.h>
#include <tchar.h>
 
// If MFC is linked, we will use CStringArray for great convenience
#ifdef __AFXWIN_H__
#include <afxtempl.h>
#endif
 
// Number bases
#define BASE_BINARY 2
#define BASE_OCTAL 8
#define BASE_DECIMAL 10
#define BASE_HEXADECIMAL 16
 
//---------------------------------------------------------------
// Callback Function Type Definition
//---------------------------------------------------------------
// The callback function used for parsing a "double-null terminated string".
// When called, the 1st parameter passed in will store the newly extracted sub
// string, the 2nd parameter is a 32-bit user defined data, this parameter can
// be NULL. The parsing will terminate if this function returns zero. To use
// the callback, function pointer needs to be passed to "CIni::ParseDNTString".
typedef BOOL (CALLBACK *SUBSTRPROC)(LPCTSTR, LPVOID);
 
class CIni
{
public:
 
//-----------------------------------------------------------
// Constructors & Destructor
//-----------------------------------------------------------
CIni(); // Default constructor
CIni(LPCTSTR lpPathName); // Construct with a given file name
virtual ~CIni();
 
//-----------------------------------------------------------
// Ini File Path Name Access
//-----------------------------------------------------------
void SetPathName(LPCTSTR lpPathName); // Specify a new file name
DWORD GetPathName(LPTSTR lpBuffer, DWORD dwBufSize) const; // Retrieve current file name
#ifdef __AFXWIN_H__
CString GetPathName() const;
#endif
//------------------------------------------------------------
// String Access
//------------------------------------------------------------
DWORD GetString(LPCTSTR lpSection, LPCTSTR lpKey, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDefault = NULL) const;
#ifdef __AFXWIN_H__
CString GetString(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpDefault = NULL) const;
#endif
BOOL WriteString(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpValue) const;
 
// Read a string from the ini file, append it with another string then write it
// back to the ini file.
BOOL AppendString(LPCTSTR Section, LPCTSTR lpKey, LPCTSTR lpString) const;
//------------------------------------------------------------
// Ini File String Array Access
//------------------------------------------------------------
// Parse the string retrieved from the ini file and split it into a set of sub strings.
DWORD GetArray(LPCTSTR lpSection, LPCTSTR lpKey, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDelimiter = NULL, BOOL bTrimString = TRUE) const;
#ifdef __AFXWIN_H__
void GetArray(LPCTSTR lpSection, LPCTSTR lpKey, CStringArray* pArray, LPCTSTR lpDelimiter = NULL, BOOL bTrimString = TRUE) const;
BOOL WriteArray(LPCTSTR lpSection, LPCTSTR lpKey, const CStringArray* pArray, int nWriteCount = -1, LPCTSTR lpDelimiter = NULL) const;
#endif
//------------------------------------------------------------
// Primitive Data Type Access
//------------------------------------------------------------
int GetInt(LPCTSTR lpSection, LPCTSTR lpKey, int nDefault, int nBase = BASE_DECIMAL) const;
BOOL WriteInt(LPCTSTR lpSection, LPCTSTR lpKey, int nValue, int nBase = BASE_DECIMAL) const;
BOOL IncreaseInt(LPCTSTR lpSection, LPCTSTR lpKey, int nIncrease = 1, int nBase = BASE_DECIMAL) const;
UINT GetUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nDefault, int nBase = BASE_DECIMAL) const;
BOOL WriteUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nValue, int nBase = BASE_DECIMAL) const;
BOOL IncreaseUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nIncrease = 1, int nBase = BASE_DECIMAL) const;
BOOL GetBool(LPCTSTR lpSection, LPCTSTR lpKey, BOOL bDefault) const;
BOOL WriteBool(LPCTSTR lpSection, LPCTSTR lpKey, BOOL bValue) const;
BOOL InvertBool(LPCTSTR lpSection, LPCTSTR lpKey) const;
double GetDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fDefault) const;
BOOL WriteDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fValue, int nPrecision = -1) const;
BOOL IncreaseDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fIncrease, int nPrecision = -1) const;
 
TCHAR GetChar(LPCTSTR lpSection, LPCTSTR lpKey, TCHAR cDefault) const;
BOOL WriteChar(LPCTSTR lpSection, LPCTSTR lpKey, TCHAR c) const;
 
//------------------------------------------------------------
// User-Defined Data Type & Data Block Access
//------------------------------------------------------------
POINT GetPoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT ptDefault) const;
BOOL WritePoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT pt) const;
RECT GetRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rcDefault) const;
BOOL WriteRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rc) const;
 
DWORD GetDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPVOID lpBuffer, DWORD dwBufSize, DWORD dwOffset = 0) const;
BOOL WriteDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPCVOID lpData, DWORD dwDataSize) const;
BOOL AppendDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPCVOID lpData, DWORD dwDataSize) const;
//------------------------------------------------------------
// Section Operations
//------------------------------------------------------------
BOOL IsSectionExist(LPCTSTR lpSection) const;
DWORD GetSectionNames(LPTSTR lpBuffer, DWORD dwBufSize) const;
#ifdef __AFXWIN_H__
void GetSectionNames(CStringArray* pArray) const;
#endif
BOOL CopySection(LPCTSTR lpSrcSection, LPCTSTR lpDestSection, BOOL bFailIfExist) const;
BOOL MoveSection(LPCTSTR lpSrcSection, LPCTSTR lpDestSection, BOOL bFailIfExist = TRUE) const;
BOOL DeleteSection(LPCTSTR lpSection) const;
//------------------------------------------------------------
// Key Operations
//------------------------------------------------------------
BOOL IsKeyExist(LPCTSTR lpSection, LPCTSTR lpKey) const;
DWORD GetKeyLines(LPCTSTR lpSection, LPTSTR lpBuffer, DWORD dwBufSize) const;
#ifdef __AFXWIN_H__
void GetKeyLines(LPCTSTR lpSection, CStringArray* pArray) const;
#endif
DWORD GetKeyNames(LPCTSTR lpSection, LPTSTR lpBuffer, DWORD dwBufSize) const;
#ifdef __AFXWIN_H__
void GetKeyNames(LPCTSTR lpSection, CStringArray* pArray) const;
#endif
BOOL CopyKey(LPCTSTR lpSrcSection, LPCTSTR lpSrcKey, LPCTSTR lpDestSection, LPCTSTR lpDestKey, BOOL bFailIfExist) const;
BOOL MoveKey(LPCTSTR lpSrcSection, LPCTSTR lpSrcKey, LPCTSTR lpDestSection, LPCTSTR lpDestKey, BOOL bFailIfExist = TRUE) const;
BOOL DeleteKey(LPCTSTR lpSection, LPCTSTR lpKey) const;
 
//------------------------------------------------------------
// Parse a "Double-Null Terminated String"
//------------------------------------------------------------
static BOOL ParseDNTString(LPCTSTR lpString, SUBSTRPROC lpFnStrProc, LPVOID lpParam = NULL);
 
//------------------------------------------------------------
// Check for Whether a String Representing TRUE or FALSE
//------------------------------------------------------------
static BOOL StringToBool(LPCTSTR lpString, BOOL bDefault = FALSE);
protected:
 
//------------------------------------------------------------
// Helper Functions
//------------------------------------------------------------
static LPTSTR __StrDupEx(LPCTSTR lpStart, LPCTSTR lpEnd);
static BOOL __TrimString(LPTSTR lpBuffer);
LPTSTR __GetStringDynamic(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpDefault = NULL) const;
static DWORD __StringSplit(LPCTSTR lpString, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDelimiter = NULL, BOOL bTrimString = TRUE);
static void __ToBinaryString(UINT nNumber, LPTSTR lpBuffer, DWORD dwBufSize);
static int __ValidateBase(int nBase);
static void __IntToString(int nNumber, LPTSTR lpBuffer, int nBase);
static void __UIntToString(UINT nNumber, LPTSTR lpBuffer, int nBase);
static BOOL CALLBACK __SubStrCompare(LPCTSTR lpString1, LPVOID lpParam);
static BOOL CALLBACK __KeyPairProc(LPCTSTR lpString, LPVOID lpParam);
#ifdef __AFXWIN_H__
static BOOL CALLBACK __SubStrAdd(LPCTSTR lpString, LPVOID lpParam);
#endif
 
//------------------------------------------------------------
// Member Data
//------------------------------------------------------------
LPTSTR m_pszPathName; // Stores path of the associated ini file
};
 
#endif // #ifndef __INI_H__
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/Release/Ini.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/Release/STMFlashLoader.obj
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/Release/STMFlashLoader.pch
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/Release/vc60.idb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STBLLIB.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.cpp
0,0 → 1,1746
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : STMFlashLoader.cpp
* Author : MCD Application Team
* Version : v2.2.0
* Date : 05/03/2010
* Description : STM Flash Loader command line version
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#include "stdafx.h"
#include "string.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <dos.h>
 
#include "../STBLLIB/STBLLIB.h"
#include "../Files/Files.h"
#include "ini.h"
 
 
#define NONE = 0;
#define ODD = 1;
#define EVEN = 2;
 
typedef enum STATE {OK,KO};
 
char MapFile[256];
PMAPPING pmMapping;
 
int TimeBO = 100;
 
BOOL SHOW_OK = TRUE; // Set to TRUE/FALSE to show/hide OK status messages
BOOL SHOW_KO = TRUE; // Set to TRUE/FALSE to show/hide KO status messages
 
/*******************************************************************************************/
/* Function : FileExist */
/* IN : file name */
/* OUT : boolean */
/* Description : verify if the given file exists */
/*******************************************************************************************/
BOOL FileExist(LPCTSTR filename)
{
// Data structure for FindFirstFile
WIN32_FIND_DATA findData;
 
// Clear find structure
ZeroMemory(&findData, sizeof(findData));
 
// Search the file
HANDLE hFind = FindFirstFile( filename, &findData );
if ( hFind == INVALID_HANDLE_VALUE )
{
// File not found
return false;
}
 
// File found
 
// Release find handle
FindClose( hFind );
hFind = NULL;
 
// The file exists
return true;
}
 
/*******************************************************************************************/
/* Function : void man() */
/* IN : */
/* OUT : */
/* Description : print the manual on the standard output */
/*******************************************************************************************/
void man()
{
printf("STMicroelectronics UART Flash Loader command line v2.2.0 \n\n");
printf(" Usage : \n\n");
printf(" STMFlashLoader.exe [options] [Agrument][[options] [Agrument]...] \n\n");
printf(" -? (Show this help) \n");
printf(" -c (Establish connection to the COM port) \n");
printf(" --pn port_nb : e.g: 1, 2 ..., default 1 \n");
printf(" --br baud_rate : e.g: 115200, 57600 ..., default 57600 \n");
printf(" --db data_bits : value in {5,6,7,8} ..., default 8 \n");
printf(" --pr parity : value in {NONE,ODD,EVEN} ..., default EVEN \n");
printf(" --sb stop_bits : value in {1,1.5,2} ..., default 1 \n");
printf(" --ec echo : value OFF or ECHO or LISTEN ..., default is OFF \n");
printf(" --co control : Enable or Disable RTS and DTR outputs control \n");
printf(" : value OFF or ON ..., default is OFF \n");
printf(" --to time_out : (ms) e.g 1000, 2000, 3000 ..., default 5000 \n");
 
printf(" -Rts (set Rts line to Hi, Lo)\n");
printf(" --State : State in {Hi, Lo} \n");
printf(" -Dtr (Set Rts line to Hi, Lo)\n");
printf(" --State : State in {Hi, Lo}\n");
printf(" -i device_name (e.g STM32_Low-density_16K, [See the Map directory]) \n");
 
printf(" -e (erase flash pages\n");
printf(" --all all pages : erase all pages\n");
printf(" --sec number_of_pages_group pages_group_codes : erase specified group pages \n");
 
printf(" -u (Upload flash contents to a .bin, .hex or .s19 file )\n");
printf(" --fn file_name : full path name of the file \n");
 
printf(" -d (Download the content of a file into MCU flash) \n");
printf(" --a address(hex): start @ in hex ; ignored if it is not a binary file \n");
printf(" --fn file_name : full path name (.bin, .hex or .s19 file) \n");
printf(" --v : verify after download \n");
printf(" --o : optimize; removes FFs data \n");
 
 
printf(" -r (Run the flash code at the specified address \n");
printf(" --a address(hex) : address in hexadecimal) \n");
 
 
printf(" -p (Enable or Disable protections) \n");
printf(" --ewp : enable write protection for sector codes (e.g 1,2,etc.) \n");
printf(" --dwp : disable write protection \n");
printf(" --drp : disable read protection \n");
printf(" --erp : enable read protection, all arguments following this one will fail \n");
 
 
printf(" -o (Get or Set STM32 option bytes: use -d command for STM8!) \n");
printf(" --get --fn file_name : get option bytes from the device \n");
printf(" and write it in the specified file \n");
printf(" --set --fn file_name : load option bytes from the specified file \n");
printf(" and write it to the device \n");
printf(" --set --vals --OPB hex_val : set the specified option byte; OPB in: User, \n");
printf(" RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3 \n");
 
 
}
 
 
 
 
 
/*******************************************************************************************/
/* Function : ParityToInt */
/* IN : parity as string (NONE, ODD, EVEN) */
/* OUT : integer */
/* Description : Get the integer representation of the given parity */
/*******************************************************************************************/
int ParityToInt(char* parity)
{
if (strcmp(parity,"NONE")==0) return 0;
else if(strcmp(parity,"ODD")==0) return 1;
else if(strcmp(parity,"EVEN")==0) return 2;
else return 2;
}
 
 
/*******************************************************************************************/
/* Function : ModeToInt */
/* IN : Mode as string (OFF, ECHO, LISTEN) */
/* OUT : int */
/* Description : Get the int representation of the given string Mode */
/*******************************************************************************************/
int ModeToInt(char* status)
{
if (strcmp(status,"OFF")==0) return 0;
else if(strcmp(status,"ECHO")==0) return 1;
else if(strcmp(status,"LISTEN")==0) return 2;
else return 0;
}
 
/*******************************************************************************************/
/* Function : StatusToBool */
/* IN : Status as string (ON, OFF) */
/* OUT : Bool */
/* Description : Get the boolean representation of the given string ON/OFF */
/*******************************************************************************************/
bool StatusToBool(char* status)
{
if (strcmp(status,"OFF")==0) return false;
else if(strcmp(status,"ON")==0) return true;
else return false;
}
 
 
/*******************************************************************************************/
/* Function : Is_Option */
/* IN : option as string */
/* OUT : boolean */
/* Description : Verify if the given string present an option */
/*******************************************************************************************/
bool Is_Option(char* option)
{
if (strcmp(option,"-?")==0) return true;
else if (strcmp(option,"-c")==0) return true;
else if (strcmp(option,"-i")==0) return true;
else if (strcmp(option,"-e")==0) return true;
else if (strcmp(option,"-u")==0) return true;
else if (strcmp(option,"-d")==0) return true;
else if (strcmp(option,"-v")==0) return true;
else if (strcmp(option,"-p")==0) return true;
else if (strcmp(option,"-r")==0) return true;
else if (strcmp(option,"-o")==0) return true;
else if (strcmp(option,"-Rts")==0) return true;
else if (strcmp(option,"-Dtr")==0) return true;
else if (strcmp(option,"-Auto")==0) return true;
else return false;
}
 
/*******************************************************************************************/
/* Function : Is_SubOption */
/* IN : sub-option as string */
/* OUT : boolean */
/* Description : Verify if the given string present a sub-option */
/*******************************************************************************************/
bool Is_SubOption(char* suboption)
{
if (strcmp(suboption,"--pn")==0) return true;
else if (strcmp(suboption,"--br")==0) return true;
else if (strcmp(suboption,"--db")==0) return true;
else if (strcmp(suboption,"--pr")==0) return true;
else if (strcmp(suboption,"--sb")==0) return true;
else if (strcmp(suboption,"--ec")==0) return true;
else if (strcmp(suboption,"--co")==0) return true;
else if (strcmp(suboption,"--to")==0) return true;
else if (strcmp(suboption,"--lcs")==0) return true;
else if (strcmp(suboption,"--all")==0) return true;
else if (strcmp(suboption,"--sec")==0) return true;
else if (strcmp(suboption,"--a")==0) return true;
else if (strcmp(suboption,"--s")==0) return true;
else if (strcmp(suboption,"--fn")==0) return true;
else if (strcmp(suboption,"--v")==0) return true;
else if (strcmp(suboption,"--o")==0) return true;
else if (strcmp(suboption,"--erp")==0) return true;
else if (strcmp(suboption,"--drp")==0) return true;
else if (strcmp(suboption,"--ewp")==0) return true;
else if (strcmp(suboption,"--dwp")==0) return true;
else if (strcmp(suboption,"--get")==0) return true;
else if (strcmp(suboption,"--set")==0) return true;
else if (strcmp(suboption,"--vals")==0) return true;
else if (strcmp(suboption,"--RDP")==0) return true;
else if (strcmp(suboption,"--User")==0) return true;
else if (strcmp(suboption,"--Data0")==0) return true;
else if (strcmp(suboption,"--Data1")==0) return true;
else if (strcmp(suboption,"--WRP0")==0) return true;
else if (strcmp(suboption,"--WRP1")==0) return true;
else if (strcmp(suboption,"--WRP2")==0) return true;
else if (strcmp(suboption,"--WRP3")==0) return true;
else if (strcmp(suboption,"--Hi")==0) return true;
else if (strcmp(suboption,"--Lo")==0) return true;
else return false;
}
 
/*******************************************************************************************/
/* Function : write_debug_info */
/* IN : */
/* OUT : */
/* Description : print the output messages on the standart output */
/*******************************************************************************************/
void write_debug_info(char *msg, int page, DWORD addr, float size, STATE status)
{
char d_info[256];
 
if((page==0) && (addr==0) && (size==0))
{
if(status == OK)
sprintf(d_info, "%s \t\t\t\t [OK] \n", msg);
else
sprintf(d_info, "%s \t\t\t\t [KO] \n", msg);
}
else if(status == OK)
sprintf(d_info, "%s \t page %i \t @0x %8X \t size %.2f(KB) \t [OK] \n", msg, page, addr, (float)size);
else
sprintf(d_info, "%s \t page %i \t @0x %8X \t size %.2f(KB) \t [KO] \n", msg, page, addr, (float)size);
 
if((SHOW_OK && (status == OK)) || (SHOW_KO && (status == KO))) printf(d_info);
}
 
/*******************************************************************************************/
/* Function : main */
/* IN : */
/* OUT : */
/* Description : */
/*******************************************************************************************/
int main(int argc, char* argv[])
{
START:
 
BYTE Res = SUCCESS;
BYTE User, RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3;
bool WaitForMoreSubOpt = TRUE;
 
//Initializing default serial connection parameters
int portname = 1;
long BaudRate = 57600 ;
int DataBits = 8;
int parity = ParityToInt("EVEN");
double nbStopBit = 1;
int timeout = 5000;
bool control = false;
 
int nsec = 0;
DWORD address = 0x00000000;
DWORD size = 0x00000000;
char* filename;
char devname[256] = "STM32_Low-density_32K.STmap";
bool Verify = FALSE;
bool optimize = FALSE;
int becho = 0;
 
char Drive[3], Dir[256], Fname[256], Ext[256];
char *ptr;
 
bool bAuto = false;
 
if (argc == 1) // wrong parameters
man();
else
{
int arg_index = 1;
 
while(arg_index < argc)
{
if(!Is_Option(argv[arg_index]))
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
 
if (bAuto)
goto Done_Success;
printf("\n Press any key to continue ...");
getchar();
return 1;
}
 
//============================ Show the man =========================================
if (strcmp(argv[arg_index],"-?")==0)
{
man();
return 0;
}
//=============================== connect ============================================
else if (strcmp(argv[arg_index],"-c")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index])) // Set default connection settings and continue with the next option
break;
else if(Is_SubOption(argv[arg_index])) // Get connection settings
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if (strcmp(argv[arg_index-1],"--pn")==0) portname = atoi(argv[arg_index]);//port name (e.g COM1, COM2 ..., default COM1) \n");
else if (strcmp(argv[arg_index-1],"--br")==0) BaudRate = atoi(argv[arg_index]);//baud reate (e.g 115200, 128000 ..., default 57600) \n");
else if (strcmp(argv[arg_index-1],"--db")==0) DataBits = atoi(argv[arg_index]);//data bits (in {5,6,7,8} ..., default 8) \n");
else if (strcmp(argv[arg_index-1],"--pr")==0) parity = ParityToInt(argv[arg_index]); //parity (in {NONE,ODD,EVEN} ..., default EVEN) \n");
else if (strcmp(argv[arg_index-1],"--sb")==0) nbStopBit= atof(argv[arg_index]);//stop bits (in {1,1.5,2} ..., default 1) \n");
else if (strcmp(argv[arg_index-1],"--to")==0) timeout = atoi(argv[arg_index]);//time out (e.g 1000, 2000, 3000 ..., default 5) \n");
else if (strcmp(argv[arg_index-1],"--ec")==0) becho = ModeToInt(argv[arg_index]); // Echo back mode, default is OFF \n");
else if (strcmp(argv[arg_index-1],"--co")==0) control = StatusToBool(argv[arg_index]); // Outputs Control ON/OFF, default is OFF \n");
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 2");
getchar();
return 1;
}
}
 
 
 
// Apply serial connection settings
TARGET_SetComIntType(0);
SetCOMSettings(portname, BaudRate, DataBits, parity, nbStopBit);
STBL_SetFlowControl(control);
 
 
// Opening serial connection
Res = COM_Open();
SetTimeOut(1000);
 
if ((Res != SUCCESS) && (Res != COM_ALREADY_OPENED))
{
write_debug_info("Opening Port", 0 ,0, 0, KO);
printf("Cannot open the com port, the port may \n be used by another application \n");
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 3");
getchar();
return 1;
}
else
write_debug_info("Opening Port", 0 ,0, 0, OK);
 
 
STBL_SetEcho(becho); // Setting Echo back mode
 
 
 
 
}
 
 
//============================ Auto option =======================================
else if (strcmp(argv[arg_index],"-Auto")==0)
{
if (arg_index< argc)
arg_index++;
else
break;
 
bAuto = true;
// BOOT0 = High
STBL_SetDtr(TRUE);
Sleep(50);
// Reset = Low
STBL_SetRts(TRUE);
 
Sleep(50);
 
// Reset = High
STBL_SetRts(FALSE);
 
STBL_SetDtr(FALSE);
Sleep(100);
COM_Close();
COM_Open();
 
STBL_SetDtr(TRUE);
Sleep(50);
// Reset = Low
STBL_SetRts(TRUE);
 
Sleep(50);
 
// Reset = High
STBL_SetRts(FALSE);
 
STBL_SetDtr(FALSE);
Sleep(500);
//Sleep(1000);
write_debug_info("Setting device to BOOT0", 0 ,0, 0, OK);
 
//printf("\n RTS set low. Press any key to continue ... 4");
//getchar();
}
 
//============================ command RTS pin =======================================
else if (strcmp(argv[arg_index],"-Rts")==0)
{
//_sleep(1000);
while(arg_index < argc)
{
if (arg_index< argc-1) arg_index++;
else break;
 
if(Is_Option(argv[arg_index])) break;
else if(Is_SubOption(argv[arg_index]))
{
if (strcmp(argv[arg_index],"--Hi")==0)
{
write_debug_info("Set Rts line", 0 ,0, 0,OK);
STBL_SetRts(TRUE);
 
 
 
}
else if (strcmp(argv[arg_index],"--Lo")==0)
{
write_debug_info("Reset Rts line", 0 ,0, 0,OK);
STBL_SetRts(FALSE);
}
else
{
write_debug_info("bad parameter [Set Rts line] should be Hi or Lo ", 0 ,0, 0,KO);
 
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 5");
getchar();
return 1;
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 6");
getchar();
return 1;
}
}
}
//============================ command DTR pin =======================================
else if (strcmp(argv[arg_index],"-Dtr")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index]))
break;
 
else if(Is_SubOption(argv[arg_index]))
{
if (strcmp(argv[arg_index],"--Hi")==0)
{
write_debug_info("Set Dtr line", 0 ,0, 0,OK);
STBL_SetDtr(TRUE);
 
}
else if (strcmp(argv[arg_index],"--Lo")==0)
{
write_debug_info("Reset Dtr line", 0 ,0, 0,OK);
STBL_SetDtr(FALSE);
}
else
{
write_debug_info("bad parameter [Set Dtr line] should be Hi or Lo ", 0 ,0, 0,KO);
 
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 7");
getchar();
return 1;
}
}
else
{
if (arg_index < argc - 1) printf("bad parameter [%s] \n", argv[arg_index]);
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 8");
getchar();
return 1;
}
}
}
//============================ ERASE =================================================
else if (strcmp(argv[arg_index],"-e")==0)
{
while(arg_index < argc)
{
if (!WaitForMoreSubOpt)
break;
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index]))
break;
 
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc)
arg_index++;
else
break;
 
//******************** This section is only for STM8 boot loader *******************
BYTE Version;
Commands pCmds;
CString m_Version;
if (STBL_GET(&Version, &pCmds) == SUCCESS)
{
m_Version.Format("%x.%x",Version/16, Version & 0x0F) ;
}
CIni Ini((LPCSTR)MapFile);
 
if(Ini.IsKeyExist((LPCTSTR)"Product",(LPCTSTR)m_Version))
{
CString E_W_ROUTINEs = Ini.GetString((LPCTSTR)"Product",(LPCTSTR)m_Version, "");
CString Path(*__argv);
 
char fullPath [MAX_PATH];
 
GetModuleFileName(0, fullPath, (MAX_PATH));
 
Path=fullPath;
 
int j=Path.ReverseFind('\\')+1;
if(j) Path=Path.Left(j);
 
CString ToFind;
 
ToFind.Format("%s%s%s", Path, "STM8_Routines\\", E_W_ROUTINEs);
 
if(!E_W_ROUTINEs.IsEmpty())
{
if(!FileExist((LPCTSTR)ToFind))
{
printf("\n!WARNING the erase or download operation may fail \n EW routines file is missing [%s]\n", ToFind);
}
else
{
HANDLE Image;
if (FILES_ImageFromFile((LPSTR)(LPCSTR)ToFind,&Image, 1)== FILES_NOERROR)
{
FILES_SetImageName(Image,(LPSTR)(LPCSTR)ToFind);
 
DWORD NbElements;
if (FILES_GetImageNbElement(Image, &NbElements) == FILES_NOERROR)
{
for (int el=0; el< (int)NbElements;el++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
Element.Data=new BYTE[Element.dwDataLength];
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
if (STBL_DNLOAD(Element.dwAddress, Element.Data, Element.dwDataLength, FALSE) != SUCCESS)
{
}
}
}
}
 
// Verify writen data
BOOL VerifySuccess = TRUE;
_sleep(100);;
 
#ifndef _VS6_USED
int el;
#endif
for (el=0; el< (int)NbElements;el++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
Element.Data=new BYTE[Element.dwDataLength];
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
if (STBL_VERIFY(Element.dwAddress, Element.Data, Element.dwDataLength, FALSE) != SUCCESS)
{
VerifySuccess = FALSE;
char str[255];
sprintf(str, "%s at address :0x%X. \n%s \nPlease disable the write protection then try agin.", "Data not matching ", Element.dwAddress, "The page may be write protected.");
AfxMessageBox(str, MB_OK|MB_ICONEXCLAMATION);
return 1;
}
}
}
}
}
}
else
{
AfxMessageBox("Unable to load data from this file " + ToFind + " ...");
return -1;
}
}
}
}
else
{
int family = Ini.GetInt((LPCTSTR)"Product",(LPCTSTR)"family", 0);
if(family == 3)
{
printf("\n!WARNING the erase or download operation may fail \n EW routines file is missing\n");
}
}
//End****************** This section is only for STM8 boot loader *******************
 
//End****************** This section is only for STM8 boot loader *******************
 
printf("\n ERASING ... \n");
if (strcmp(argv[arg_index-1],"--all")==0)
{
WaitForMoreSubOpt = false;
Res = STBL_ERASE(0xFFFF, NULL);
 
 
 
if (Res != SUCCESS)
write_debug_info("erasing all pages", 0 ,0, 0, KO);
else
write_debug_info("erasing all pages", 0 ,0, 0, OK);
}
else if (strcmp(argv[arg_index-1],"--sec")==0)
{
WaitForMoreSubOpt = true;
 
nsec = atoi(argv[arg_index]);
LPWORD sectors = (LPWORD)malloc(nsec *2 + 2);
 
 
sectors[0] = 0;
for(int i = 1; i<= nsec; i++)
{
sectors[0]++;
arg_index++;
sectors[sectors[0]] = atoi(argv[arg_index]);
}
 
WaitForMoreSubOpt = false;
 
printf("\nerasing %i sectors : ", sectors[0]);
 
#ifndef _VS6_USED
int i;
#endif
 
for(i = 1; i<= nsec; i++)
{
printf("<%i>", sectors[i]);
}
printf("\n");
 
Res = STBL_ERASE(nsec, (LPBYTE)sectors+2);
if (Res != SUCCESS)
{
write_debug_info("erasing", 0 ,0, 0, KO);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ... 9");
getchar();
return 1;
}
else
write_debug_info("erasing", 0 ,0, 0, OK);
 
arg_index++;
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 10");
getchar();
return 1;
}
}
}
//============================ UPLOAD ===============================================
else if (strcmp(argv[arg_index],"-u")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index]))
break;
 
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc)
arg_index++;
else
break;
 
/*if (strcmp(argv[arg_index-1],"--a")==0)
{
address = _tcstoul(argv[arg_index], 0, 16) ;
}
else if (strcmp(argv[arg_index-1],"--s")==0)
{
size = _tcstoul(argv[arg_index], 0, 16) ;
}
else */if (strcmp(argv[arg_index-1],"--fn")==0)
{
filename = argv[arg_index];
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 11");
getchar();
return 1;
}
}
 
printf("\n UPLOADING ... \n\n");
 
HANDLE Handle;
FILES_CreateImage(&Handle, 0);
 
FILES_CreateImageFromMapping(&Handle,pmMapping);
 
DWORD NbElements = 0;
if (FILES_GetImageNbElement(Handle, &NbElements) == FILES_NOERROR)
{
if (NbElements > 0)
{
for(int i = 0; i< (int)NbElements; i++)
{
IMAGEELEMENT Element={0};
// Get element data size
if (FILES_GetImageElement(Handle, i, &Element) == FILES_NOERROR)
{
//Upload element data
Element.Data = (LPBYTE)malloc(Element.dwDataLength);
if (STBL_UPLOAD(Element.dwAddress, Element.Data, Element.dwDataLength) == SUCCESS)
{
//Insert elment in the Image
write_debug_info("Uploading", i ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, OK);
FILES_SetImageElement(Handle,i,FALSE,Element);
}
else
{
write_debug_info("Uploading", i ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, KO);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ... 12");
getchar();
return 1;
}
}
}
}
}
 
if(!FileExist((LPCTSTR)filename))
{
printf( "file %s does not exist .. Creating file\n", filename);
FILE* fp = fopen((LPCTSTR)filename, "a+");
fclose(fp);
}
 
printf( "Writing data ...\n");
 
if (FILES_ImageToFile((LPSTR)(LPCSTR)filename,Handle) != FILES_NOERROR)
{
printf( "cannot write to file %s \n", filename);
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 13");
getchar();
return 1;
}
else
printf("\n Uploaded data is dumped on %s", filename);
}
 
 
 
//============================ Get Device map file name ==============================
else if (strcmp(argv[arg_index],"-i")==0)
{
if (arg_index< argc)
arg_index++;
else
break;
 
 
sprintf(devname,"%s.STmap", argv[arg_index]);
 
char Drive[3], Dir[256], Fname[256], Ext[256];
_splitpath(argv[0],Drive,Dir,Fname,Ext);
sprintf(MapFile, "%s%s%s%s", Drive, Dir , "Map\\", devname);
 
pmMapping = NULL;
WORD size = 0;
 
WORD PacketSize = 0;
pmMapping = NULL;
WORD Size = 0;
char MapName[256];
// Get the number of sectors in the flash target: pmMapping should be NULL
// number of sectors is returned in the Size value
BYTE PagePerSector = 0;
 
if (!FileExist((LPCTSTR)MapFile))
{
printf("This version is not intended to support the <%s> target\n", argv[arg_index]);
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 14");
getchar();
return 1;
}
 
FILES_GetMemoryMapping((LPSTR)(LPCTSTR)MapFile, &Size, (LPSTR)MapName, &PacketSize, pmMapping, &PagePerSector);
// Allocate the mapping structure memory
pmMapping = (PMAPPING)malloc(sizeof(MAPPING));
pmMapping->NbSectors = 0;
pmMapping->pSectors = (PMAPPINGSECTOR) malloc((Size) * sizeof(MAPPINGSECTOR));
 
// Get the mapping info
FILES_GetMemoryMapping((LPSTR)(LPCTSTR)MapFile, &Size, (LPSTR)(LPCTSTR)MapName, &PacketSize, pmMapping, &PagePerSector);
SetPaketSize(PacketSize);
 
 
 
//sending BL config byte (0x7F) & identifing target
 
 
 
Res = STBL_Init_BL();
 
if (Res == UNREOGNIZED_DEVICE)
{
write_debug_info("Activating device", 0 ,0, 0, KO);
 
if(COM_is_Open())
COM_Close();
 
printf("Unrecognized device... Please, reset your device then try again \n");
 
if(COM_is_Open())
COM_Close();
printf("Please, reset your device then press any key to continue \n");
printf("\n Press any key to continue ... 15");
getchar();
goto START;
}
else if (Res != SUCCESS)
{
write_debug_info("Activating device", 0 ,0, 0, KO);
printf("No response from the target, the Boot loader can not be started. \nPlease, verify the boot mode configuration, reset your device then try again. \n");
if(COM_is_Open())
COM_Close();
printf("Please, reset your device then then press any key to continue \n");
printf("\n Press any key to continue ... 16");
getchar();
goto START;
}
 
_sleep(TimeBO);
write_debug_info("Activating device", 0 ,0, 0, OK);
//Getting Target informations (version, available commands)
BYTE Version ;
Commands pCmds;
 
Res = STBL_GET(&Version, &pCmds);
if (Res != SUCCESS)
{
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 17");
getchar();
return 1;
}
 
SetTimeOut(timeout);
 
if (arg_index< argc)
arg_index++;
else
break;
}
//============================ DOWNLOAD ==============================================
else if (strcmp(argv[arg_index],"-d")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index]))
break;
 
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc)
arg_index++;
else
break;
 
if (strcmp(argv[arg_index-1],"--a")==0)
{
address = _tcstoul(argv[arg_index], 0, 16) ;
}
else if (strcmp(argv[arg_index-1],"--v")==0)
{
Verify = true;
arg_index--;
}
else if (strcmp(argv[arg_index-1],"--o")==0)
{
optimize = TRUE;
arg_index--;
}
else if (strcmp(argv[arg_index-1],"--fn")==0)
{
filename = argv[arg_index];
_splitpath(filename,Drive,Dir,Fname,Ext);
ptr=strupr(Ext);
strcpy(Ext, ptr);
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 18");
getchar();
return 1;
}
}
 
PMAPPINGSECTOR pSector = pmMapping->pSectors;
for(int i = 1; i<= (int)pmMapping->NbSectors; i++)
{
if ((strcmp(Ext, ".BIN")!=0) && (i==0))
address = pSector->dwStartAddress;
 
pSector->UseForOperation = TRUE;
pSector++;
}
 
if(!FileExist((LPCTSTR)filename))
{
printf( "file does not exist %s \n", filename);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 19");
getchar();
return 1;
}
//****************** This section is only for STM8 boot loader *******************
BYTE Version;
Commands pCmds;
CString m_Version;
if (STBL_GET(&Version, &pCmds) == SUCCESS)
{
m_Version.Format("%x.%x",Version/16, Version & 0x0F) ;
}
CIni Ini((LPCSTR)MapFile);
 
if(Ini.IsKeyExist((LPCTSTR)"Product",(LPCTSTR)m_Version))
{
CString E_W_ROUTINEs = Ini.GetString((LPCTSTR)"Product",(LPCTSTR)m_Version, "");
CString Path(*__argv);
int j=Path.ReverseFind('\\')+1;
if(j) Path=Path.Left(j);
 
CString ToFind;
 
ToFind.Format("%s%s%s", Path, "STM8_Routines\\", E_W_ROUTINEs);
 
if(!E_W_ROUTINEs.IsEmpty())
{
if(!FileExist((LPCTSTR)ToFind))
{
printf("\n!WARNING the erase or download operation may fail \n EW routines file is missing [%s]\n", ToFind);
}
else
{
HANDLE Image;
if (FILES_ImageFromFile((LPSTR)(LPCSTR)ToFind,&Image, 1)== FILES_NOERROR)
{
FILES_SetImageName(Image,(LPSTR)(LPCSTR)ToFind);
 
DWORD NbElements;
if (FILES_GetImageNbElement(Image, &NbElements) == FILES_NOERROR)
{
for (int el=0; el< (int)NbElements;el++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
Element.Data=new BYTE[Element.dwDataLength];
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
if (STBL_DNLOAD(Element.dwAddress, Element.Data, Element.dwDataLength, FALSE) != SUCCESS)
{
}
}
}
}
 
// Verify writen data
BOOL VerifySuccess = TRUE;
_sleep(100);
 
#ifndef _VS6_USED
int el;
#endif
 
for (el=0; el< (int)NbElements;el++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
Element.Data=new BYTE[Element.dwDataLength];
if (FILES_GetImageElement(Image, el, &Element) == FILES_NOERROR)
{
if (STBL_VERIFY(Element.dwAddress, Element.Data, Element.dwDataLength, FALSE) != SUCCESS)
{
VerifySuccess = FALSE;
char str[255];
sprintf(str, "%s at address :0x%X. \n%s \nPlease disable the write protection then try agin.", "Data not matching ", Element.dwAddress, "The page may be write protected.");
AfxMessageBox(str, MB_OK|MB_ICONEXCLAMATION);
return 1;
}
}
}
}
}
}
else
{
AfxMessageBox("Unable to load data from this file " + ToFind + " ...");
return -1;
}
}
}
}
else
{
int family = Ini.GetInt((LPCTSTR)"Product",(LPCTSTR)"family", 0);
if(family == 3)
{
printf("\n!WARNING the erase or download operation may fail \n EW routines file is missing\n");
}
}
//End****************** This section is only for STM8 boot loader *******************
 
printf("\n DOWNLOADING ... \n\n");
 
HANDLE Handle;
if (FILES_ImageFromFile((LPSTR)(LPCSTR)filename,&Handle, 1) == FILES_NOERROR)
{
FILES_SetImageName(Handle,(LPSTR)(LPCSTR)filename);
 
DWORD NbElements = 0;
if (FILES_GetImageNbElement(Handle, &NbElements) == FILES_NOERROR)
{
if ( NbElements > 0 )
{ // if binary file -> change the elemnts address
if (strcmp(Ext, ".BIN")==0)
{
for (int i=0;i< (int)NbElements;i++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Handle, i, &Element) == FILES_NOERROR)
{
Element.Data= (LPBYTE)malloc(Element.dwDataLength);
if (FILES_GetImageElement(Handle, i, &Element) == FILES_NOERROR)
{
Element.dwAddress = Element.dwAddress + address;
FILES_SetImageElement(Handle, i, FALSE, Element);
}
}
}
}
}
}
 
FILES_FilterImageForOperation(Handle, pmMapping, OPERATION_UPLOAD, optimize);
}
else
{
printf("cannot open file %s \n", filename);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 20");
getchar();
return 1;
}
 
DWORD NbElements = 0;
if (FILES_GetImageNbElement(Handle, &NbElements) == FILES_NOERROR)
{
for (int el=0; el< (int)NbElements;el++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Handle, el, &Element) == FILES_NOERROR)
{
Element.Data= (LPBYTE)malloc(Element.dwDataLength);
if (FILES_GetImageElement(Handle, el, &Element) == FILES_NOERROR)
{
if ((strcmp(Ext, ".BIN")==0) && (el==0))
Element.dwAddress = address;
if (STBL_DNLOAD(Element.dwAddress, Element.Data, Element.dwDataLength, optimize) != SUCCESS)
{
write_debug_info( "downloading", el ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, KO);
write_debug_info("The flash may be read protected; use -p --drp to disable write protection." , 0, 0, 0, KO);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ... 21");
getchar();
return 1;
}
 
write_debug_info( "downloading", el ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, OK);
}
}
}
}
 
bool VerifySuccess = true;
if (Verify)
{
printf("\n VERIFYING ... \n\n");
 
 
for (int el=0; el< (int)NbElements;el++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Handle, el, &Element) == FILES_NOERROR)
{
Element.Data=(LPBYTE)malloc(Element.dwDataLength);
if (FILES_GetImageElement(Handle, el, &Element) == FILES_NOERROR)
{
if ((strcmp(Ext, ".BIN")==0) && (el==0))
Element.dwAddress = address;
 
if (STBL_VERIFY(Element.dwAddress, Element.Data, Element.dwDataLength, optimize) != SUCCESS)
{
VerifySuccess = false;
write_debug_info("verifying" ,el ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, KO);
write_debug_info("some pages may be write protected; use -p --dwp to disable write protection." , 0, 0, 0, KO);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ... 22");
getchar();
return 1;
}
 
write_debug_info("verifying" ,el ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, OK);
}
}
}
}
 
}
//============================ VERIFY ================================================
else if (strcmp(argv[arg_index],"-v")==0)
{
if (arg_index< argc)
arg_index++;
else
break;
}
//============================ Program option bytes ==================================
else if (strcmp(argv[arg_index],"-o")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index]))
break;
 
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc)
arg_index++;
else
break;
 
if (strcmp(argv[arg_index-1],"--get")==0)
{
if (arg_index< argc)
arg_index++;
else
break;
if (strcmp(argv[arg_index-1],"--fn")==0)
filename = argv[arg_index];
if(TARGET_GetSIFData(&User, &RDP, &Data0, &Data1, &WRP0, &WRP1, &WRP2, &WRP3) == SUCCESS)
{
write_debug_info("Getting Option bytes data" ,0 ,0, 0, OK);
 
HANDLE Image;
if (FILES_CreateImage(&Image, 1) == FILES_NOERROR)
{
IMAGEELEMENT Element={0};
Element.dwAddress = 0x1FFFF800;
Element.dwDataLength = 16;
Element.Data = (LPBYTE)malloc(Element.dwDataLength);
 
{
Element.Data[0] = RDP;
Element.Data[1] = ~RDP;
Element.Data[2] = User;
Element.Data[3] = ~User;
Element.Data[4] = Data0;
Element.Data[5] = ~Data0;
Element.Data[6] = Data1;
Element.Data[7] = ~Data1;
Element.Data[8] = WRP0;
Element.Data[9] = ~WRP0;
Element.Data[10] = WRP1;
Element.Data[11] = ~WRP1;
Element.Data[12] = WRP2;
Element.Data[13] = ~WRP2;
Element.Data[14] = WRP3;
Element.Data[15] = ~WRP3;
}
 
FILES_SetImageElement(Image,0,TRUE,Element);
if (FILES_ImageToFile((LPSTR)(LPCSTR)filename,Image) != FILES_NOERROR)
{
write_debug_info("Saving Option bytes data",0 ,0, 0, KO);
}
else write_debug_info("Saving Option bytes data",0 ,0, 0, OK);
}
}
else write_debug_info("Getting Option bytes data" ,0 ,0, 0, KO);
}
else if (strcmp(argv[arg_index-1],"--set")==0)
{
if (arg_index< argc) arg_index++;
else break;
if (strcmp(argv[arg_index-1],"--fn")==0)
{
filename = argv[arg_index];
 
HANDLE OPBImage;
 
if(!FileExist((LPCTSTR)filename))
{
printf( "file does not exist %s \n", filename);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ... 23");
getchar();
return 1;
}
 
if (FILES_ImageFromFile((LPSTR)(LPCSTR)filename, &OPBImage, 0) == FILES_NOERROR)
{
DWORD NbElements = 0;
if (FILES_GetImageNbElement(OPBImage, &NbElements) == FILES_NOERROR)
{
if ( NbElements == 1 )
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(OPBImage, 0, &Element) == FILES_NOERROR)
{
Element.Data= (LPBYTE)malloc(Element.dwDataLength);
if (FILES_GetImageElement(OPBImage, 0, &Element) == FILES_NOERROR)
{
RDP = Element.Data[0] ;
User = Element.Data[2] ;
Data0 = Element.Data[4] ;
Data1 = Element.Data[6] ;
WRP0 = Element.Data[8] ;
WRP1 = Element.Data[10];
WRP2 = Element.Data[12];
WRP3 = Element.Data[14];
 
if (TARGET_SetSIFData(User, RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3) == SUCCESS)
{
write_debug_info("Setting Option bytes data" ,0 ,0, 0, OK);
 
if(COM_is_Open())
COM_Close();
 
COM_Open();
 
if(STBL_Init_BL() != SUCCESS)
write_debug_info("Resetting device" ,0 ,0, 0, KO);
else
write_debug_info("Resetting device" ,0 ,0, 0, OK);
}
else
write_debug_info("Setting Option bytes data" ,0 ,0, 0, KO);
}
}
}
}
}
}
else if (strcmp(argv[arg_index-1],"--vals")==0)
{
TARGET_GetSIFData(&User, &RDP, &Data0, &Data1, &WRP0, &WRP1, &WRP2, &WRP3);
while(arg_index< argc)
{
if(Is_Option(argv[arg_index]))
break;
else if(Is_SubOption(argv[arg_index]))
{
arg_index++;
if(strcmp(argv[arg_index-1],"--RDP")==0) { RDP = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
else if(strcmp(argv[arg_index-1],"--User")==0) { User = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
else if(strcmp(argv[arg_index-1],"--data0")==0){ Data0 = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
else if(strcmp(argv[arg_index-1],"--data1")==0){ Data1 = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
else if(strcmp(argv[arg_index-1],"--WRP0")==0) { WRP0 = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
else if(strcmp(argv[arg_index-1],"--WRP1")==0) { WRP1 = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
else if(strcmp(argv[arg_index-1],"--WRP2")==0) { WRP2 = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
else if(strcmp(argv[arg_index-1],"--WRP3")==0) { WRP3 = _tcstoul(argv[arg_index], 0, 16);arg_index++;}
}
}
if (TARGET_SetSIFData(User, RDP, Data0, Data1, WRP0, WRP1, WRP2, WRP3) != SUCCESS)
write_debug_info("Setting Option bytes data" ,0 ,0, 0, KO);
else
{
write_debug_info("Setting Option bytes data" ,0 ,0, 0, OK);
 
if(COM_is_Open())
COM_Close();
 
COM_Open();
 
if(STBL_Init_BL() != SUCCESS)
write_debug_info("Resetting device" ,0 ,0, 0, KO);
else
write_debug_info("Resetting device" ,0 ,0, 0, OK);
}
arg_index--;
}
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 24");
getchar();
return 1;
}
}
}
//============================ Set/Unset R/W protection ==========================
else if (strcmp(argv[arg_index],"-p")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index]))
break;
 
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc)
arg_index++;
else
break;
 
if (strcmp(argv[arg_index-1],"--erp")==0)
{
if(STBL_READOUT_PROTECT() != SUCCESS)
write_debug_info( "enabling read protection", 0 , 0, 0, KO);
else
write_debug_info( "enabling read protection", 0 , 0, 0, OK);
_sleep(TimeBO);
 
if(STBL_Init_BL() != SUCCESS)
write_debug_info( "reseting device", 0 , 0, 0, KO);
else
write_debug_info( "reseting device", 0 , 0, 0, OK);
 
arg_index--;
}
else if (strcmp(argv[arg_index-1],"--drp")==0)
{
if(STBL_READOUT_PERM_UNPROTECT() == SUCCESS)
{
write_debug_info( "disabling read protection", 0 , 0, 0, OK);
 
_sleep(TimeBO);
 
if(STBL_Init_BL() != SUCCESS)
write_debug_info( "reseting device", 0 , 0, 0, KO);
else
write_debug_info( "reseting device", 0 , 0, 0, OK);
}
else
write_debug_info( "disabling read protection", 0 , 0, 0, KO);
arg_index--;
}
else if (strcmp(argv[arg_index-1],"--ewp")==0)
{
LPBYTE sectors;
if(Is_Option(argv[arg_index])) break;
 
nsec = atoi(argv[arg_index]);
sectors = (LPBYTE)malloc(nsec + 1);
 
 
sectors[0] = 0;
for(int i = 1; i<= nsec; i++)
{
sectors[0]++;
arg_index++;
sectors[sectors[0]] = atoi(argv[arg_index]);
}
 
 
printf("\nenabling write protection %i sectors : ", sectors[0]);
 
#ifndef _VS6_USED
int i;
#endif
 
for(i = 1; i<= nsec; i++)
{
printf("<%i>", sectors[i]);
}
printf("\n");
 
if(STBL_WRITE_PROTECT(((LPBYTE)sectors)[0],&((LPBYTE)sectors)[1]) != SUCCESS)
write_debug_info( "enabling write protection", 0 , 0, 0, KO);
else
write_debug_info( "enabling write protection", 0 , 0, 0, OK);
_sleep(TimeBO);
 
if(STBL_Init_BL() != SUCCESS)
write_debug_info( "reseting device", 0 , 0, 0, KO);
else
write_debug_info( "reseting device", 0 , 0, 0, OK);
}
else if (strcmp(argv[arg_index-1],"--dwp")==0)
{
if(STBL_WRITE_PERM_UNPROTECT() != SUCCESS)
write_debug_info( "disabling write protection", 0 , 0, 0, KO);
else
write_debug_info( "disabling write protection", 0 , 0, 0, OK);
_sleep(TimeBO);
 
if(STBL_Init_BL() != SUCCESS)
write_debug_info( "reseting device", 0 , 0, 0, KO);
else
write_debug_info( "reseting device", 0 , 0, 0, OK);
arg_index--;
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 25");
getchar();
return 1;
}
}
}
//============================ Run at address ========================================
else if (strcmp(argv[arg_index],"-r")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1)
arg_index++;
else
break;
 
if(Is_Option(argv[arg_index]))
break;
 
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc)
arg_index++;
else
break;
 
PMAPPINGSECTOR pSector = pmMapping->pSectors;
address = pSector->dwStartAddress;
 
if (strcmp(argv[arg_index-1],"--a")==0)
{
address = _tcstoul(argv[arg_index], 0, 16) ;
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 26");
getchar();
return 1;
}
 
if (STBL_GO(address) == SUCCESS)
{
printf("Your code is running...\n");
}
else
{
printf( "run fails \n");
}
}
}
else
{
if (arg_index < argc - 1)
printf("bad parameter [%s] \n", argv[arg_index]);
 
if(COM_is_Open())
COM_Close();
 
printf("\n Press any key to continue ... 27");
getchar();
return 1;
}
}
}
 
Done_Success:
if (bAuto)
{
// commented
STBL_SetDtr(FALSE);
Sleep(50);
 
if(COM_is_Open())
COM_Close();
COM_Open();
 
// Reset = Low
STBL_SetRts(TRUE);
Sleep(50);
write_debug_info("Unset BOOT0 & RESET ", 0 ,0, 0, OK);
// Reset = High
STBL_SetRts(FALSE);
 
// printf("command executed succesfully, press any key to close the COM port and exit");
// printf("\n RTS set high. Press any key to continue ... 28");
// getchar();
}
 
printf("\nFlashing done. Enjoy ... \n");
 
if(COM_is_Open())
COM_Close();
 
return 0;
}
 
 
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.dsp
0,0 → 1,93
# Microsoft Developer Studio Project File - Name="STMFlashLoader" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
 
# TARGTYPE "Win32 (x86) Console Application" 0x0103
 
CFG=STMFlashLoader - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "STMFlashLoader.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "STMFlashLoader.mak" CFG="STMFlashLoader - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "STMFlashLoader - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "STMFlashLoader - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
 
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
 
!IF "$(CFG)" == "STMFlashLoader - Win32 Release"
 
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x405 /d "NDEBUG"
# ADD RSC /l 0x405 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
 
!ELSEIF "$(CFG)" == "STMFlashLoader - Win32 Debug"
 
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 2
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /YX /FD /GZ /c
# ADD BASE RSC /l 0x405 /d "_DEBUG"
# ADD RSC /l 0x405 /d "_DEBUG" /d "_AFXDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 STBLLIB.lib Files.lib STUARTBLLIB.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
 
!ENDIF
 
# Begin Target
 
# Name "STMFlashLoader - Win32 Release"
# Name "STMFlashLoader - Win32 Debug"
# Begin Source File
 
SOURCE=.\Ini.cpp
# End Source File
# Begin Source File
 
SOURCE=.\STMFlashLoader.cpp
# End Source File
# End Target
# End Project
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.dsw
0,0 → 1,29
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
 
###############################################################################
 
Project: "STMFlashLoader"=".\STMFlashLoader.dsp" - Package Owner=<4>
 
Package=<5>
{{{
}}}
 
Package=<4>
{{{
}}}
 
###############################################################################
 
Global:
 
Package=<5>
{{{
}}}
 
Package=<3>
{{{
}}}
 
###############################################################################
 
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.ncb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.opt
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.plg
0,0 → 1,27
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: STMFlashLoader - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\DOCUME~1\MIJA~1.ICZ\LOCALS~1\Temp\RSP364.tmp" with contents
[
/nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /Fp"Debug/STMFlashLoader.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"C:\projekts\ARM-ST32F\sw\UNPACK\Src\STMFlashLoader\STMFlashLoader.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\MIJA~1.ICZ\LOCALS~1\Temp\RSP364.tmp"
Creating command line "link.exe STBLLIB.lib Files.lib STUARTBLLIB.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/STMFlashLoader.pdb" /debug /machine:I386 /out:"Debug/STMFlashLoader.exe" /pdbtype:sept ".\Debug\STMFlashLoader.obj" ".\Debug\Ini.obj" "
<h3>Output Window</h3>
Compiling...
STMFlashLoader.cpp
Linking...
 
 
 
<h3>Results</h3>
STMFlashLoader.exe - 0 error(s), 0 warning(s)
</pre>
</body>
</html>
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.rc
0,0 → 1,102
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
 
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
 
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
 
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
 
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
 
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
 
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,1,0,0
PRODUCTVERSION 2,1,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "STMicroelectronics"
VALUE "FileDescription", "Flash loader command line"
VALUE "FileVersion", "2, 1, 0, 0"
VALUE "InternalName", "STMFlashLoader"
VALUE "LegalCopyright", "Copyright © 2009"
VALUE "OriginalFilename", "STMFlashLoader.exe"
VALUE "ProductName", "STMicroelectronics STMFlashLoader"
VALUE "ProductVersion", "2, 1, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
 
 
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
 
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
 
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
 
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
 
#endif // APSTUDIO_INVOKED
 
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
 
 
 
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
 
 
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
 
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STMFlashLoader.vcproj
0,0 → 1,281
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="STMFlashLoader"
ProjectGUID="{5DED8251-B239-46C2-B2EE-087FF8D46398}"
Keyword="MFCProj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/STMFlashLoader.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release/STMFlashLoader.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="2"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;..\STBLLIB\Release\STBLLIB.lib&quot; ..\Files\Release\Files.lib odbc32.lib odbccp32.lib"
OutputFile="..\BIN\Release\STMFlashLoader.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
ProgramDatabaseFile=".\Release/STMFlashLoader.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release/STMFlashLoader.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="1"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/STMFlashLoader.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/STMFlashLoader.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
BrowseInformation="1"
WarningLevel="2"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;..\STBLLIB\Release\STBLLIB.lib&quot; ..\Files\Release\Files.lib"
OutputFile="..\BIN\Debug\STMFlashLoader.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\Debug/STMFlashLoader.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug/STMFlashLoader.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\Ini.cpp"
>
</File>
<File
RelativePath="StdAfx.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
UsePrecompiledHeader="1"
PrecompiledHeaderThrough="stdafx.h"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
UsePrecompiledHeader="1"
PrecompiledHeaderThrough="stdafx.h"
/>
</FileConfiguration>
</File>
<File
RelativePath="STMFlashLoader.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\STMFlashLoader.rc"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath=".\Ini.h"
>
</File>
<File
RelativePath="StdAfx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/STUARTBLLIB.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/StdAfx.cpp
0,0 → 1,9
 
// stdafx.cpp : source file that includes just the standard includes
// STMFlashLoader.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
 
#include "stdafx.h"
 
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/StdAfx.h
0,0 → 1,22
 
 
#if !defined(AFX_STDAFX_H__0581A7FA_DEC6_4D61_B47A_826059363FA9__INCLUDED_)
#define AFX_STDAFX_H__0581A7FA_DEC6_4D61_B47A_826059363FA9__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
 
#include <stdio.h>
 
#include <afxcmn.h> // MFC support for Windows Common Controls
#include "../Files/Files.h"
 
// TODO: reference additional headers your program requires here
 
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
#endif // !defined(AFX_STDAFX_H__0581A7FA_DEC6_4D61_B47A_826059363FA9__INCLUDED_)
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMFlashLoader/resource.h
0,0 → 1,15
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by STMFlashLoader.rc
//
 
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMicroelectronics Flash Loader project.dsw
0,0 → 1,52
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
 
###############################################################################
 
Project: "STBLLIB"=".\STBLLIB\STBLLIB.dsp" - Package Owner=<4>
 
Package=<5>
{{{
begin source code control
"$/PC/ST Generic Boot Loader/SOFTWARE", UBQAAAAA
.
end source code control
}}}
 
Package=<4>
{{{
}}}
 
###############################################################################
 
Project: "STMFlashLoader"=".\STMFlashLoader\STMFlashLoader.dsp" - Package Owner=<4>
 
Package=<5>
{{{
begin source code control
"$/PC/ST Generic Boot Loader/SOFTWARE", UBQAAAAA
.
end source code control
}}}
 
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name STBLLIB
End Project Dependency
}}}
 
###############################################################################
 
Global:
 
Package=<5>
{{{
}}}
 
Package=<3>
{{{
}}}
 
###############################################################################
 
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMicroelectronics Flash Loader project.ncb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMicroelectronics Flash Loader project.opt
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STMicroelectronics Flash Loader project.sln
0,0 → 1,29

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "STMFlashLoader", "STMFlashLoader\STMFlashLoader.vcproj", "{5DED8251-B239-46C2-B2EE-087FF8D46398}"
ProjectSection(ProjectDependencies) = postProject
{F9F56A1E-4355-4CC9-92E9-5815BDC57534} = {F9F56A1E-4355-4CC9-92E9-5815BDC57534}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "STBLLIB", "STBLLIB\STBLLIB.vcproj", "{F9F56A1E-4355-4CC9-92E9-5815BDC57534}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5DED8251-B239-46C2-B2EE-087FF8D46398}.Debug|Win32.ActiveCfg = Debug|Win32
{5DED8251-B239-46C2-B2EE-087FF8D46398}.Debug|Win32.Build.0 = Debug|Win32
{5DED8251-B239-46C2-B2EE-087FF8D46398}.Release|Win32.ActiveCfg = Release|Win32
{5DED8251-B239-46C2-B2EE-087FF8D46398}.Release|Win32.Build.0 = Release|Win32
{F9F56A1E-4355-4CC9-92E9-5815BDC57534}.Debug|Win32.ActiveCfg = Debug|Win32
{F9F56A1E-4355-4CC9-92E9-5815BDC57534}.Debug|Win32.Build.0 = Debug|Win32
{F9F56A1E-4355-4CC9-92E9-5815BDC57534}.Release|Win32.ActiveCfg = Release|Win32
{F9F56A1E-4355-4CC9-92E9-5815BDC57534}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STUARTBLLIB/Debug/STUARTBLLIB.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STUARTBLLIB/Debug/STUARTBLLIB.res
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STUARTBLLIB/Release/STUARTBLLIB.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STUARTBLLIB/Release/STUARTBLLIB.res
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STUARTBLLIB/STUARTBLLIB.h
0,0 → 1,486
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : STUARTBLLIB.h
* Author : MCD Application Team
* Version : v2.2.0
* Date : 05/03/2010
* Description : Defines the system memory boot loader protocol interface
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
 
#ifndef STDLIB_H
#define STDLIB_H
 
#include "StdAfx.h"
#include "../CRs232/rs232.h"
 
#ifdef STUARTBLLIB_EXPORTS
#define STUARTBLLIB_API __declspec(dllexport)
#else
#define STUARTBLLIB_API __declspec(dllimport)
#endif
 
const BYTE INIT_CON = 0x7F;
 
const BYTE GET_CMD = 0x00; //Get the version and the allowed commands supported by the current version of the boot loader
const BYTE GET_VER_ROPS_CMD = 0x01; //Get the BL version and the Read Protection status of the NVM
const BYTE GET_ID_CMD = 0x02; //Get the chip ID
const BYTE SET_SPEED_CMD = 0x03; //set the new baudrate
const BYTE READ_CMD = 0x11; //Read up to 256 bytes of memory starting from an address specified by the user
const BYTE GO_CMD = 0x21; //Jump to an address specified by the user to execute (a loaded) code
const BYTE WRITE_CMD = 0x31; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
const BYTE ERASE_CMD = 0x43; //Erase from one to all the NVM sectors
const BYTE ERASE_EXT_CMD = 0x44; //Erase from one to all the NVM sectors
const BYTE WRITE_PROTECT_CMD = 0x63; //Enable the write protection in a permanent way for some sectors
const BYTE WRITE_TEMP_UNPROTECT_CMD = 0x71; //Disable the write protection in a temporary way for all NVM sectors
const BYTE WRITE_PERM_UNPROTECT_CMD = 0x73; //Disable the write protection in a permanent way for all NVM sectors
const BYTE READOUT_PROTECT_CMD = 0x82; //Enable the readout protection in a permanent way
const BYTE READOUT_TEMP_UNPROTECT_CMD = 0x91; //Disable the readout protection in a temporary way
const BYTE READOUT_PERM_UNPROTECT_CMD = 0x92; //Disable the readout protection in a permanent way
 
 
const BYTE SUCCESS = 0x00; // No error
const BYTE ERROR_OFFSET = 0x00; //error offset
 
const BYTE COM_ERROR_OFFSET = ERROR_OFFSET + 0x00;
const BYTE NO_CON_AVAILABLE = COM_ERROR_OFFSET + 0x01; // No serial port opened
const BYTE COM_ALREADY_OPENED = COM_ERROR_OFFSET + 0x02; // Serial port already opened
const BYTE CANT_OPEN_COM = COM_ERROR_OFFSET + 0x03; // Fail to open serial port
const BYTE SEND_FAIL = COM_ERROR_OFFSET + 0x04; // send over serial port fail
const BYTE READ_FAIL = COM_ERROR_OFFSET + 0x05; // Read from serial port fail
 
const BYTE SYS_MEM_ERROR_OFFSET = ERROR_OFFSET + 0x10;
const BYTE CANT_INIT_BL = SYS_MEM_ERROR_OFFSET + 0x01; // Fail to start system memory BL
const BYTE UNREOGNIZED_DEVICE = SYS_MEM_ERROR_OFFSET + 0x02; // Unreconized device
const BYTE CMD_NOT_ALLOWED = SYS_MEM_ERROR_OFFSET + 0x03; // Command not allowed
const BYTE CMD_FAIL = SYS_MEM_ERROR_OFFSET + 0x04; // command failed
 
const BYTE PROGRAM_ERROR_OFFSET = ERROR_OFFSET + 0x20;
const BYTE INPUT_PARAMS_ERROR = PROGRAM_ERROR_OFFSET + 0x01;
const BYTE INPUT_PARAMS_MEMORY_ALLOCATION_ERROR = PROGRAM_ERROR_OFFSET + 0x02;
 
 
 
enum ACKS {UNDEFINED=0x00, ST75=0x75, ST79=0x79};
enum INTERFACE_TYPE {UART, CAN};
 
enum EBaudRate { brCustom,br110, br300, br600, br1200, br2400, br4800, br9600, br14400, br19200, br38400,
br56000, br57600, br115200, br128000, br256000 };// Port Numbers ( custom or COM1..COM16 }
enum EPortNumber { pnCustom,pnCOM1, pnCOM2, pnCOM3, pnCOM4, pnCOM5, pnCOM6, pnCOM7,pnCOM8, pnCOM9, pnCOM10,
pnCOM11, pnCOM12, pnCOM13,pnCOM14, pnCOM15, pnCOM16 };// Data bits ( 5, 6, 7, 8 }
enum EDataBits { db5BITS, db6BITS, db7BITS, db8BITS };
// Stop bits ( 1, 1.5, 2 }
enum EStopBits { sb1BITS, sb1HALFBITS, sb2BITS };
// Parity ( None, odd, even, mark, space }
enum EParity { ptNONE, ptODD, ptEVEN, ptMARK, ptSPACE };
// Hardware Flow Control ( None, None + RTS always on, RTS/CTS }
enum EHwFlowControl { hfNONE, hfNONERTSON, hfRTSCTS };
// Software Flow Control ( None, XON/XOFF }
enum ESwFlowControl { sfNONE, sfXONXOFF };
// What to do with incomplete (incoming} packets ( Discard, Pass }
enum EPacketMode { pmDiscard, pmPass };
 
enum OPERATION {NONE, ERASE, UPLOAD, DNLOAD, DIS_R_PROT, DIS_W_PROT, ENA_R_PROT, ENA_W_PROT};
 
typedef struct RESULT
{
OPERATION operation;
char* filename;
HANDLE Image;
}* LPRESULT;
 
typedef struct Commands
{
BOOL GET_CMD ; //Get the version and the allowed commands supported by the current version of the boot loader
BOOL GET_VER_ROPS_CMD ; //Get the BL version and the Read Protection status of the NVM
BOOL GET_ID_CMD ; //Get the chip ID
BOOL SET_SPEED_CMD ; //Change the CAN baudrate
BOOL READ_CMD ; //Read up to 256 bytes of memory starting from an address specified by the user
BOOL GO_CMD ; //Jump to an address specified by the user to execute (a loaded) code
BOOL WRITE_CMD ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
BOOL ERASE_CMD ; //Erase from one to all the NVM sectors
BOOL ERASE_EXT_CMD ; //Erase from one to all the NVM sectors
BOOL WRITE_PROTECT_CMD ; //Enable the write protection in a permanent way for some sectors
BOOL WRITE_TEMP_UNPROTECT_CMD ; //Disable the write protection in a temporary way for all NVM sectors
BOOL WRITE_PERM_UNPROTECT_CMD ; //Disable the write protection in a permanent way for all NVM sectors
BOOL READOUT_PROTECT_CMD ; //Enable the readout protection in a permanent way
BOOL READOUT_TEMP_UNPROTECT_CMD ; //Disable the readout protection in a temporary way
BOOL READOUT_PERM_UNPROTECT_CMD ; //Disable the readout protection in a permanent way
}* LPCommands;
 
typedef struct TARGET_DESCRIPTOR
{
BYTE Version ;
BYTE CmdCount ;
BYTE PIDLen ;
BYTE* PID ;
 
BYTE ROPE ;
BYTE ROPD ;
 
BOOL GET_CMD ; //Get the version and the allowed commands supported by the current version of the boot loader
BOOL GET_VER_ROPS_CMD ; //Get the BL version and the Read Protection status of the NVM
BOOL GET_ID_CMD ; //Get the chip ID
BOOL SET_SPEED_CMD ;
BOOL READ_CMD ; //Read up to 256 bytes of memory starting from an address specified by the user
BOOL GO_CMD ; //Jump to an address specified by the user to execute (a loaded) code
BOOL WRITE_CMD ; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
BOOL ERASE_CMD ; //Erase from one to all the NVM sectors
BOOL ERASE_EXT_CMD ; //Erase from one to all the NVM sectors
BOOL WRITE_PROTECT_CMD ; //Enable the write protection in a permanent way for some sectors
BOOL WRITE_TEMP_UNPROTECT_CMD ; //Disable the write protection in a temporary way for all NVM sectors
BOOL WRITE_PERM_UNPROTECT_CMD ; //Disable the write protection in a permanent way for all NVM sectors
BOOL READOUT_PERM_PROTECT_CMD ; //Enable the readout protection in a permanent way
BOOL READOUT_TEMP_UNPROTECT_CMD ; //Disable the readout protection in a temporary way
BOOL READOUT_PERM_UNPROTECT_CMD ; //Disable the readout protection in a permanent way
}* LPTARGET_DESCRIPTOR;
 
typedef struct STBL_Request
{
BYTE _cmd;
DWORD _address;
WORD _length;
BYTE _nbSectors;
LPTARGET_DESCRIPTOR _target;
LPBYTE _data;
WORD _wbSectors;
}* LPSTBL_Request;
 
 
extern "C"
{
 
/************************************************************************************/
/* SET COMMUNICATION INTERFACE TYPE
/* UART - ...
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_SetComIntType(BYTE com_int_type);
 
/************************************************************************************/
/* GET PROGRESS STATE
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE GetProgress(LPBYTE progress);
 
/************************************************************************************/
/* GET ACTIVITY TIME
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE GetActivityTime(LPDWORD time);
 
/************************************************************************************/
/* SET ACTIVITY TIME
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE SetActivityTime(DWORD time);
 
/************************************************************************************/
/* GetFlashSize
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_GetFlashSize(DWORD Addr, LPWORD val);
/************************************************************************************/
/* GetRAMSize
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_GetMemoryAddress(DWORD Addr, LPBYTE val);
/************************************************************************************/
/* GetRDPOptionByte
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_GetRDPOptionByte(LPBYTE RDP);
/************************************************************************************/
/* GetWRPOptionBytes
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_GetWRPOptionBytes(LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
/************************************************************************************/
/* Basic function to send a request
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE Send_RQ(LPSTBL_Request pRQ);
 
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE SetCOMSettings(int numPort, long speedInBaud, int nbBit,
int parity, float nbStopBit);
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
/*STUARTBLLIB_API BYTE ESetCOMSettings(EPortNumber numPort, EBaudRate speedInBaud, EDataBits nbBit,
EParity parity, EStopBits nbStopBit);*/
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE COM_Open();
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE COM_Close();
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_SetSpeed(DWORD speed);
/************************************************************************************/
/*
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_Init_BL();
/************************************************************************************/
/* 0x00; //Get the version and the allowed commands supported by the current version of the boot loader
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_GET(LPBYTE Version, LPCommands pCmds);
/************************************************************************************/
/* 0x01; //Get the BL version and the Read Protection status of the NVM
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_GET_VER_ROPS(LPBYTE Version, LPBYTE ROPEnabled, LPBYTE ROPDisabled);
/************************************************************************************/
/* 0x02; //Get the chip ID
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_GET_ID(LPBYTE size, LPBYTE pID);
/************************************************************************************/
/* 0x11; //Read up to 256 bytes of memory starting from an address specified by the user
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_READ(DWORD Address, BYTE Size, LPBYTE pData);
/************************************************************************************/
/* 0x21; //Jump to an address specified by the user to execute (a loaded) code
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_GO(DWORD Address);
/************************************************************************************/
/* 0x31; //Write maximum 256 bytes to the RAM or the NVM starting from an address specified by the user
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_WRITE(DWORD address, BYTE size, LPBYTE pData);
/************************************************************************************/
/* 0x43; //Erase from one to all the NVM sectors
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_ERASE(WORD NbSectors, LPBYTE pSectors);
/************************************************************************************/
/* 0x63; //Enable the write protection in a permanent way for some sectors
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_WRITE_PROTECT(BYTE NbSectors, LPBYTE pSectors);
/************************************************************************************/
/* 0x71; //Disable the write protection in a temporary way for all NVM sectors
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_WRITE_TEMP_UNPROTECT();
/************************************************************************************/
/* 0x73; //Disable the write protection in a permanent way for all NVM sectors
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_WRITE_PERM_UNPROTECT();
/************************************************************************************/
/* 0x82; //Enable the readout protection in a permanent way
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_READOUT_PROTECT();
/************************************************************************************/
/* 0x91; //Disable the readout protection in a temporary way
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_READOUT_TEMP_UNPROTECT();
/************************************************************************************/
/* 0x92; //Disable the readout protection in a permanent way
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_READOUT_PERM_UNPROTECT();
/************************************************************************************/
/* UPLOAD
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_UPLOAD(DWORD Address, LPBYTE pData, DWORD Length);
/************************************************************************************/
/* VERIFY
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_VERIFY(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
/************************************************************************************/
/* DNLOAD
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_DNLOAD(DWORD Address, LPBYTE pData, DWORD Length,BOOL bTruncateLeadFFForDnLoad);
 
/************************************************************************************/
/* SET PACKET SIZE
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE SetPaketSize(BYTE size);
/************************************************************************************/
/* GET PACKET SIZE
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE GetPaketSize(LPBYTE size);
 
/************************************************************************************/
/* GetAckValue
/*
/*
/************************************************************************************/
STUARTBLLIB_API ACKS GetAckValue();
 
/************************************************************************************/
/* IsConnected
/*
/*
/************************************************************************************/
STUARTBLLIB_API BOOL COM_is_Open();
 
/************************************************************************************/
/* SetTimeOut
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE SetTimeOut(DWORD vms);
/************************************************************************************/
/* GetUserOptionByte
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_GetUserOptionByte(LPBYTE User);
/************************************************************************************/
/* GetDataOptionByte
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_GetDataOptionByte(LPBYTE Data0, LPBYTE Data1);
 
/************************************************************************************/
/* SetSIFData
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_SetSIFData(BYTE User, BYTE RDP, BYTE Data0, BYTE Data1,
BYTE WRP0, BYTE WRP1, BYTE WRP2, BYTE WRP3);
 
/************************************************************************************/
/* GetSIFData
/*
/*
/************************************************************************************/
STUARTBLLIB_API BYTE TARGET_GetSIFData(LPBYTE User, LPBYTE RDP, LPBYTE Data0, LPBYTE Data1,
LPBYTE WRP0, LPBYTE WRP1, LPBYTE WRP2, LPBYTE WRP3);
 
/************************************************************************************/
/* Set Rts Line State
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_SetRts(BOOL Val);
 
/************************************************************************************/
/* Set Dtr Line State
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_SetDtr(BOOL Val);
 
/************************************************************************************/
/* Set the state of TXD. Return: true if success.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_setTxd(BOOL val);
/************************************************************************************/
/* Return: The state of CTS.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_getCts(BOOL* pval);
/************************************************************************************/
/* Return: The state of DTR.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_getDtr(BOOL* pval);
/************************************************************************************/
/* Return: The state of RI.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_getRi(BOOL* pval);
/************************************************************************************/
/* Return: The state of DTR.
/* High = TRUE
/* Low = FALSE
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_getCd(BOOL* pval);
 
 
/************************************************************************************/
/* Set Echo Mode
/* 0 = Echo Disabled
/* 1 = Echo Back Enabled
/* 2 = Listen Echo Enabled
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_SetEcho(int val);
 
 
/************************************************************************************/
/* SetFlowControl : Enable/Disable Flow Control of DTR and RTS
/* FALSE = Disabled
/* TRUE = Enabled
/************************************************************************************/
STUARTBLLIB_API BYTE STBL_SetFlowControl(bool val);
 
}
 
#endif
 
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE******/
/Modules/ARM/STM32F10xRxT/SW/RS232_bootloader/Src/STUARTBLLIB/resource.h
0,0 → 1,15
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by STUARTBLLIB.rc
//
 
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif