stm32+i
来自「STM32烧写」· 代码 · 共 1,575 行 · 第 1/4 页
TXT
1,575 行
Res = STBL_GET(&Version, &pCmds);
if (Res != SUCCESS)
{
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ...");
getchar();
return 1;
}
SetTimeOut(timeout);
}
//============================ 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("[Set 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 ...");
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 ...");
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("[Set 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 ...");
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 ...");
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;
//*****************************************************
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");
}
}
//******************************************************
printf("\n ERASING ... \n");
if (strcmp(argv[arg_index-1],"--all")==0)
{
WaitForMoreSubOpt = false;
Res = STBL_ERASE(0xFF, 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]);
LPBYTE 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]);
}
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, sectors+1);
if (Res != SUCCESS)
{
write_debug_info("erasing", 0 ,0, 0, KO);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ...");
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 ...");
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 ...");
getchar();
return 1;
}
}
printf("\n UPLOADING ... \n\n");
HANDLE Handle;
FILES_CreateImage(&Handle, 0);
FILES_CreateImageFromMapping(&Handle,pMapping);
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();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?