Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

This code example writes custom bytes to the Write Buffer within the API-DLL, programs the buffer to target flash, and then verifies the programmed data using direct read-back of the target’s flash. This example is geared towards the single target FlashPro-ARM library.

The condition for this example to work properly is that F_OpenInstancesAndFPAs, and F_Initialization has correctly initialized the given fpa index (1 to 64). If testing adapter 1, the user should call F_Set_FPA_index(1) before this code executes. In addition the user should load the intended configuration file using F_ConfigFileLoad so that the right MCU is selected.

MCU_Info struct was initialized using example Get MCU Info.

The code sequence is as follows:

  • Power on target device and open communication using F_Open_Target_Device

  • Get MCU base flash address, MCU_Info.u.x.FlashStartAddr, and add 0x100. This code will write custom bytes to almost the start of flash.

  • In a loop, populate the Write Buffer with custom bytes starting at address addr using F_Put_Byte_to_Buffer

  • Program custom bytes to target using F_Copy_Buffer_to_Flash

  • Read target memory and save contents to Read Data Buffer using F_Copy_Flash_to_Buffer

  • In a loop, read bytes from the Read Data Buffer and print them using F_Get_Byte_from_Buffer

  • Power down target and close communication using F_Close_Target_Device

Code Block
languagecpp
INT_X response;
const int size=32;

response = F_Open_Target_Device();
if(response != TRUE)
  return response;
  
char text[100200];	
long addr = MCU_Info.u.x.FlashStartAddr + 0x100;
for(int k=0; k< size; k++)
{
	//----------------------------------------------------
	F_Put_Byte_to_Buffer( (INT_X )(addr+k), (BYTE)( 0x10 + k ));
	//----------------------------------------------------
}
//----------------------------------------------------
response = F_Copy_Buffer_to_Flash( addr, size );
if(response != TRUE)
  return response;
//----------------------------------------------------

//----------------------------------------------------
response = F_Copy_Flash_to_Buffer( addr, size ); 
if(response != TRUE)
  return response; 
//----------------------------------------------------

for( int n=0; n<size; n += 16 )
{
	for( int k = 0; k<16; k++ )
	{
		//----------------------------------------------------
		sprintf( text+3*k, "%2.2X  ", F_Get_Byte_from_Buffer((INT_X )( addr + k + n) ));//for single buffer, when reading it works only for FlashPro
		//----------------------------------------------------
	}
	strcat( text, "\r\n" );
}

response = F_Close_Target_Device();
if(response != TRUE)
  return response;

...