cancel
Showing results for 
Search instead for 
Did you mean: 

Nucelo-h755zi-q flash crc Error

Ismails
Associate II

Hi all, attempting to write data to a specific address in flash bank 1 and calculate the CRC. Using three different CRC methods: flash CRC, software CRC, and hardware CRC, but getting three different values for the same data. The code is attached below. Additionally, the read and write operations are functioning correctly. Could anyone help identify what the issue might be?

#include"flash_api.h"
#include "crc.h"
uint32_t SW_crc32_Calcul(const uint32_t *buf, size_t len, uint32_t BurstSize);
uint32_t data[70] = { 0x11111111, 0x22222222, 0x33333333, 0x44444444,
		0x55555555, 0x66666666, 0x77777777, 0x88888888, 0x11111111, 0x22222222,
		0x33333333, 0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888,
		0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555, 0x66666666,
		0x77777777, 0x88888888, 0x11111111, 0x22222222, 0x33333333, 0x44444444,
		0x55555555, 0x66666666, 0x77777777, 0x88888888, 0x11111111, 0x22222222,
		0x33333333, 0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888,
		0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555, 0x66666666,
		0x77777777, 0x88888888 };
uint32_t readback_data[70];
uint8_t complete = 0;
#define FLASHADRESS 0x080EF000
#define crcendadress 0x080EF09C
void flash_write_read(void) {
	HAL_FLASH_Unlock();
	FLASH_EraseInitTypeDef EraseInitStruct;
	uint32_t SectorError;
	EraseInitStruct.Banks = FLASH_BANK_1;
	EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
	EraseInitStruct.Sector = FLASH_SECTOR_7;
	EraseInitStruct.NbSectors = 1;
	EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

	if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
		while (1)
			;
	}
	for (uint32_t i = 0; i < 5; i++) {

		HAL_FLASH_Program_IT(FLASH_TYPEPROGRAM_FLASHWORD,
				(FLASHADRESS + i * 32), (uint32_t) data);
		while (complete == 0)
			;
		complete = 0;
	}
	HAL_FLASH_Lock();
	for (int i = 0; i < 40; i++) {
		readback_data[i] = *(uint32_t*) (FLASHADRESS + i * 4);
		UART_printf("%x\n", readback_data[i]);
	}
}

void flashcrccalculation(void) {
	uint32_t result = 0U;
	uint32_t result2 = 0U;
	uint32_t result3 = 0U;
	size_t value = 0U;
	HAL_FLASH_Unlock();
	FLASH_CRCInitTypeDef crccalculator={0};
	crccalculator.TypeCRC = FLASH_CRC_ADDR;
	crccalculator.Bank = FLASH_BANK_1;
	crccalculator.BurstSize = FLASH_CRC_BURST_SIZE_4;
	crccalculator.Sector = FLASH_SECTOR_7;
	crccalculator.NbSectors = 1;
	crccalculator.CRCStartAddr = FLASHADRESS;
	crccalculator.CRCEndAddr = crcendadress;
	HAL_FLASHEx_ComputeCRC(&crccalculator, &result);
//	result^= 0x55555555;
	UART_printf("%x\n", result);
	value = 50*4*8;
	result2 = SW_crc32_Calcul(FLASHADRESS, value, 4);
	UART_printf("%x\n", result2);
	result3 = HAL_CRC_Calculate(&hcrc, data, 50);
//	result3^= 0x55555555;
	UART_printf("%x\n", result3);
	HAL_FLASH_Lock();

}
void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue) {
	complete = 1;
}
#define POLY 0x4c11bd7
uint32_t SW_crc32_Calcul(const uint32_t *buf, size_t len, uint32_t BurstSize) {
	int k;
	/* Define the initial CRC value */
	uint32_t crc = 0xFFFFFFFF;
	/* Define the length of data on which CRC has to be computed depending on CRC burst size
	 */
	if (len > BurstSize) {
		if ((len % BurstSize) != 0) {
			len = BurstSize * ((len / BurstSize) + 1);
		}
	} else {
		len = BurstSize;
	}
	/* Calculate CRC value */
	while (len--) {
		crc ^= *buf++;
		for (k = 0; k < 32; k++)
			crc = crc & 0x80000000 ? (crc << 1) ^ POLY : crc << 1;
		crc ^= 0x55555555;
	}
	/* Return CRC value */
	return crc;
}

 

0 REPLIES 0