No changes between revisions
/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=""..\STBLLIB\Release\STBLLIB.lib" ..\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=""..\STBLLIB\Release\STBLLIB.lib" ..\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 |