This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28069F: While writing flash memory using serial port.. problem with reading for checksum test.

Part Number: TMS320F28069F


I've been tried to write flash memory.

I referred to TI flash memory writer. And my application is based on windows MFC.

so,my serial writer function is like this...

-----------------------------------------------------------------------

UINT Serial_Flash_Programmer(LPVOID lpData)
{

	
	PointerToDev* thInfo = (PointerToDev*)lpData;
	CProdcutManagerView* pThread = thInfo->pView;
	CMainFrame* pMain = thInfo->pMain;
	int devNo = thInfo->deviceNo;
	
	int iExitCode = 0;//_tmain
	CString g_strComPort;
	CString g_strBaudRate;
	DCB port;
	
	//CString str;
	CString g_strAppFile(_T(""));
	CString g_strKernelFile(_T(""));
	g_strKernelFile = pThread->GetKernelTxtFile();						// Kernel file
	g_strAppFile = pThread->GetAppTxtFile();							// App file

	if (initFlashProgrammer(pThread, devNo, g_strKernelFile, g_strAppFile)==0)
	{
		return 0;
	}

	HANDLE commPortFile = NULL;
	if (initComPort(pThread, devNo, &port, &commPortFile) == 0)
	{
		...//errorHandling...
		return 0;
	}	


	FILE *Kfh;	
	Kfh = openKernel(pThread, devNo, g_strKernelFile);
	if (Kfh == NULL)
	{
		...//errorHandling...
		return 10;
	}


	FILE *Afh;
	Afh = openApp(pThread, devNo, g_strAppFile);
	if (Afh == NULL)
	{
		...//errorHandling...
		return 10;
	}


	if (setKernelAutoBaud(pThread, commPortFile, devNo) < 0)
	{
		...//errorHandling...	
		return(12);
	}
	TRACE(_T("Kernel AutoBaud Successful\n"));
	

	writeKernel(pThread, commPortFile, Kfh, devNo);
	Sleep(1000);

	if (setAppAutoBaud(pThread, commPortFile, devNo) < 0)
	{
		return(12);
	}

	if (writeApp(pThread, commPortFile, Afh, devNo) < 0)
	{
		return 12;
	}
	CloseHandle(commPortFile);	
	CString str;

	...//successHandling...

	pMain->PrintBuild(str);
	return 0;
	
}

-----------------------------------------------------------------------

I've got some problem with writeApp(...).

When writeApp does some checksum test, endless 0-byte reading roof triggers.

Below is the part.

-----------------------------------------------------------------------

int writeApp(CProdcutManagerView* pThread, HANDLE targetBoard, FILE* AppFileHandle, int devNo)
{
        ...//preview is all passed processes...
        int pos = 0;
	while (1)
	{
		CString str;
		fileStatus = fscanf_s(AppFileHandle, "%x ", &sendData[0]);

		if (fileStatus == EOF) 
			break;


		WriteFile(targetBoard, &sendData[0], 1, &dwWritten, NULL);
		checksum += sendData[0];

		// Get block size
		// block size = targetBoard[0] + (targetBoard[1]<<8)
		if (txCount == 0x00)		
		{
			w_blockSize = sendData[0];
		}
		else if (txCount == 0x01)
		{
			
			byteData = sendData[0];
			// form the wordData from the MSB:LSB
			w_blockSize |= (byteData << 8);
		}

		txCount++;
		
		//If the next block size is 0, exit the while loop. 
		if (w_blockSize == 0x00 && txCount > 1)
			//handle file end
		{
			w_blockSize = 0x0000;
			byteData = 0x0000;
			//str.Format(_T("testing checksum :%d"), pos);
			pThread->SetNotify(devNo, _T("Test passed."));
			break;
		}
		// will execute when all the data in the block has been sent
		else if (txCount == 2 * (w_blockSize + 3))
			//handle block end
		{
			str.Format(_T("testing checksum :%d, send"), pos);
			pThread->SetNotify(devNo, str);
			doublewordReadCount = 0;
			while (doublewordReadCount == 0)
			{
				ReadFile(targetBoard, &rcvData, 1, &doublewordReadCount, NULL);
				
			}
			doublewordReadCount = 0;
			
			while (doublewordReadCount == 0)
			{
				ReadFile(targetBoard, &rcvDataH, 1, &doublewordReadCount, NULL);
			
			}
			//Ensure checksum matches
			if (checksum != (rcvData | (rcvDataH << 8)))
			{
				TRACE(_T("chkSum(%x):%x"), checksum, (rcvData | (rcvDataH << 8)));
				CloseHandle(targetBoard);
				pThread->SetNotify(devNo, _T("Checksum error."));
				return -1;
			}
			else
				checksum = 0;

			w_blockSize = 0x0000;
			byteData = 0x0000;
			txCount = 0x00;
		}
		// will execute when the flash kernel buffer is full (0x400 words == 0x800 bytes)
		else if ((txCount - 6) % 0x800 == 0 && txCount > 6)
			//handle kernel overflow
		{
			
			int retry = 0;
			doublewordReadCount = 0;
			rcvData = 0;
			rcvDataH = 0;

			while (doublewordReadCount == 0)
			{
				ReadFile(targetBoard, &rcvData, 1, &doublewordReadCount, NULL);
				if (retry++ > 1000)
				{
					CloseHandle(targetBoard); 
					str.Format(_T("testing checksum :%d, txRead1:%d"), pos, txCount);
pThread->SetNotify(devNo, str);
					return -1;
}
}
 ...//remained process

return 1;
}

-----------------------------------------------------------------------

Result log is 

"testing checksum :3515, txRead1 : 2054" and stopped.


I'm expecting upload app file is broken, but I'm not sure.
Because,
1. Some file is working well, but some file is not working.
2. All uploading with JTAG-writing is working well.

Can you check the file and what is the problem while uploading?

I'm waiting for the answer. 

  • addition : Ooops..

    -----------------------------

    int writeApp(CProdcutManagerView* pThread, HANDLE targetBoard, FILE* AppFileHandle, int devNo)
    {
            ...//preview is all passed processes...
            int pos = 0;
    	while (1)
    	{
    		CString str;
    		fileStatus = fscanf_s(AppFileHandle, "%x ", &sendData[0]);
    
    		if (fileStatus == EOF) 
    			break;
    
    
    		WriteFile(targetBoard, &sendData[0], 1, &dwWritten, NULL);
    		checksum += sendData[0];
    
    		// Get block size
    		// block size = targetBoard[0] + (targetBoard[1]<<8)
    		if (txCount == 0x00)		
    		{
    			w_blockSize = sendData[0];
    		}
    		else if (txCount == 0x01)
    		{
    			
    			byteData = sendData[0];
    			// form the wordData from the MSB:LSB
    			w_blockSize |= (byteData << 8);
    		}
    
    		txCount++;
    		
    		//If the next block size is 0, exit the while loop. 
    		if (w_blockSize == 0x00 && txCount > 1)
    			//handle file end
    		{
    			w_blockSize = 0x0000;
    			byteData = 0x0000;
    			//str.Format(_T("testing checksum :%d"), pos);
    			pThread->SetNotify(devNo, _T("Test passed."));
    			break;
    		}
    		// will execute when all the data in the block has been sent
    		else if (txCount == 2 * (w_blockSize + 3))
    			//handle block end
    		{
    			str.Format(_T("testing checksum :%d, send"), pos);
    			pThread->SetNotify(devNo, str);
    			doublewordReadCount = 0;
    			while (doublewordReadCount == 0)
    			{
    				ReadFile(targetBoard, &rcvData, 1, &doublewordReadCount, NULL);
    				
    			}
    			doublewordReadCount = 0;
    			
    			while (doublewordReadCount == 0)
    			{
    				ReadFile(targetBoard, &rcvDataH, 1, &doublewordReadCount, NULL);
    			
    			}
    			//Ensure checksum matches
    			if (checksum != (rcvData | (rcvDataH << 8)))
    			{
    				TRACE(_T("chkSum(%x):%x"), checksum, (rcvData | (rcvDataH << 8)));
    				CloseHandle(targetBoard);
    				pThread->SetNotify(devNo, _T("Checksum error."));
    				return -1;
    			}
    			else
    				checksum = 0;
    
    			w_blockSize = 0x0000;
    			byteData = 0x0000;
    			txCount = 0x00;
    		}
    		// will execute when the flash kernel buffer is full (0x400 words == 0x800 bytes)
    		else if ((txCount - 6) % 0x800 == 0 && txCount > 6)
    			//handle kernel overflow
    		{
    			
    			int retry = 0;
    			doublewordReadCount = 0;
    			rcvData = 0;
    			rcvDataH = 0;
    
    			while (doublewordReadCount == 0)
    			{
    				ReadFile(targetBoard, &rcvData, 1, &doublewordReadCount, NULL);
    				if (retry++ > 1000)
    				{
    					CloseHandle(targetBoard); 
    					str.Format(_T("testing checksum :%d, txRead1:%d"), pos, txCount);
                                            pThread->SetNotify(devNo, str);
    					return -1;
    
    				}
    					
    			}
     ...//remained process
    
               return 1; 
    }

    result : 

    "testing checksum :3515, txRead1 : 2054" and stopped.


  • Hi,

    I will not be able to help debugging your custom flash programmer.

    But you can use the serial flash programmer and SCI flash kernels to help you get started.

    Please see www.ti.com/.../sprabv4b.pdf

    Regards,
    sal