cancel
Showing results for 
Search instead for 
Did you mean: 

How to use HAL_CRC_Accumulate? BufferLength does not accept the entire FLASH volume?

Not applicable

Using a STM32F407VGT6 (1MB Flash)

For the starting address of 0x08000000 (base address), HAL_CRC_Accumulate only accepts a buffer length of up to 0x40000.

For 0x080F0000, only buffer length up to 0x4000.

For 0x080FF000, only buffer length up to 0x400.

For 0x080FFF00, only buffer length up to 0x40.

For 0x080FFFF0, only buffer length up to 0x4.

For 0x080FFFFC, only buffer length up to 0x1.

I understand that it is related to the fact that it is 32 bits, which means 4 bytes. But how would it be possible to CRC all Flash?

Ref.: https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/blob/master/hands-on/06_F746-DISCO-CRC/README.md

8 REPLIES 8
Not applicable

I understood, following the example of the link, the memory volume must be divided by 4.

#ifdef BUFFER_SIZE_0x4000
#define BUFFER_SIZE	(0x4000 - 4)/4
#else
#define BUFFER_SIZE	(0x8000 - 4)/4
#endif

It is strange the function to work with steps of 4 bytes, for each unit of buffer length. It would be interesting if there was a brief explanation in the function header.

/**
  * @brief  Compute the 32-bit CRC value of a 32-bit data buffer
  *         starting with the previously computed CRC as initialization value.
  * @param  hcrc CRC handle
  * @param  pBuffer pointer to the input data buffer.
  * @param  BufferLength input data buffer length (number of uint32_t words).
  * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
  */
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)

>>It is strange the function to work with steps of 4 bytes, for each unit of buffer length.

Well it is passed a 32-bit pointer, and a count of those words. Seems like standard practice.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Not applicable

Yes, I found the problem, instead of putting 0x8000 in the sample code, to test 1MB you have to use 0x100000 and also change the length of a variable (myDataBufferCount). Now it worked.

Not applicable

main.c:

/* USER CODE BEGIN 0 */
#ifdef BUFFER_SIZE_0x4000
#define BUFFER_SIZE	(0x4000 - 4)/4
#else
#define BUFFER_SIZE	(0x100000 - 4)/4
#endif
 
__IO uint32_t uwCRCValue = 0;
__IO uint32_t myCRCValue1 = 0xFFFFFFFF;
 
const uint32_t *myDataBuffer;
 
 
/* USER CODE END 0 */
 
/**
 * @brief  The application entry point.
 * @retval int
 */
int main(void)
{
	/* USER CODE BEGIN 1 */
	  uint32_t myDataBufferCount = BUFFER_SIZE;
	  myDataBuffer = (uint32_t*) 0x08000000;
	/* USER CODE END 1 */
 
 
	/* MCU Configuration--------------------------------------------------------*/
 
	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();
 
	/* USER CODE BEGIN Init */
 
	/* USER CODE END Init */
 
	/* Configure the system clock */
	SystemClock_Config();
 
	/* USER CODE BEGIN SysInit */
 
	/* USER CODE END SysInit */
 
	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_CRC_Init();
	MX_USART1_UART_Init();
	/* USER CODE BEGIN 2 */
	  printf("\n\rCRC TEST\n\r");
 
	  /*##-1- Compute the CRC by STM32 CRC peripheral ###################################*/
	  //uwCRCValue = HAL_CRC_Calculate(&hcrc, (uint32_t *)0x08000000, BUFFER_SIZE);
	  uwCRCValue = HAL_CRC_Accumulate(&hcrc, (uint32_t *)0x08000000, BUFFER_SIZE);
	  //uwCRCValue = MY_HAL_CRC_Calculate(&hcrc, (uint8_t *)0x08000000, BUFFER_SIZE_BYTE);
 
	  /*##-2- Compute the CRC of "myDataBuffer" by Crc32 SW Code###################################*/
	  while (myDataBufferCount--)
	  {
	    myCRCValue1 = Crc32(myCRCValue1, *myDataBuffer++);
	  }
	  printf("\n\n\r========================================Display Final Result========================================\n\r");
	  printf("uwCRCValue generated by STM32 CRC Unit= 0x%08X\n\r",(unsigned int) uwCRCValue);	//shut compiling warning up
	  printf("myCRCValue1 generated by Crc32 SW code= 0x%08X\n\r",(unsigned int) myCRCValue1);	//shut compiling warning up
 
	#ifdef BUFFER_SIZE_0x4000
	  if (uwCRCValue == *(uint32_t*)0x08003FFC)
	#else
	  if (uwCRCValue == *(uint32_t*)(0x100000 - 4))
	#endif
	  {
	    printf("CRC Check: OK...\n\r");
	  }
	  else
	  {
	    printf("CRC Check: Fail...\n\r");
	  }
	  printf("\tChecksum generated by STM32 CRC Unit= 0x%08X\n\r",(unsigned int) uwCRCValue);
 
	#ifdef BUFFER_SIZE_0x4000
	  printf("\tChecksum stored at address 0x08003FFC= 0x%08X\n\r",*(uint32_t*)0x08003FFC);
	#else
	  printf("\tChecksum stored at address 0x08007FFC= 0x%08X\n\r",*(unsigned int*)(0x100000 - 4));
	#endif
 
	/* USER CODE END 2 */

checksum.bat:

..\srec_cat.exe %1 -Intel -fill 0x00 0x08000000 0x080FFFFC -STM32 0x080FFFFC -o ROM.hex -Intel

(0x080FFFFC = 0x100000 - 4): (1MB - 4 bytes for storing the checksum)

Post-build steps Command:

arm-none-eabi-objcopy -O ihex "${BuildArtifactFileBaseName}.elf" "${BuildArtifactFileBaseName}.hex" && ..\checksum.bat ${BuildArtifactFileBaseName}.hex

0690X00000DC8BwQAL.png

debug config:

0690X00000DC8C1QAL.png

result:

0690X00000DC8CBQA1.png

Not applicable

Related error: File not found error. "Failed to execute MI command"

(if the checksum.bat script does not generate the file or the file name is incorrect in the debug settings, this error may occur)

https://community.st.com/s/question/0D50X0000CAsSRPSQ3/stm32cubeide-file-not-found-error-failed-to-execute-mi-command

CiuppaPT
Associate III

Hello,

  

I know this has been discussed before, but following your procedure i am still unable to generate with srec_cat the same CRC of one generated by STM32 CRC hw peripheral.

did you make some other tricks in order to have match between the two CRC calculation over the whole STM32F746G 1MB of flash?

CiuppaPT
Associate III

Hello,

  

I know this has been discussed before, but following your procedure i am still unable to generate with srec_cat the same CRC of one generated by STM32 CRC hw peripheral.

did you make some other tricks in order to have match between the two CRC calculation over the whole STM32F746G 1MB of flash?

Not applicable

Hello,

The chip I used is the STM32F407, I suggest you contact the original repository (mentioned in the first post, which I didn't write):

https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/blob/master/hands-on/06_F746-DISCO-CRC/README.md

---> https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/issues

I just left some details of what I was doing:

https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/issues?q=is%3Aissue+is%3Aclosed