Question
CRC32 Calculation of flash memory of STM32L476RG
I am working on STM32L476RG MCU for this one i want to calculate CRC of flash memory. for this i uses 3 logics but my calculated CRC of flash memory is not matched with hex file CRC of code.i share the link here using which i calculate CRC of flash memory.
https://simplycalc.com/crc32-file.php
Logic For crc32 calculation
#include "stm32l476xx.h"
#define FLASH_BASE_ADDR 0x08000000 // Base address of flash memory
#define FLASH_SIZE 0x80FFFFFF // Size of the flash memory (1024 KB)
void CRC32_Init(void) {
// Enable CRC peripheral clock
RCC->AHB1ENR |= RCC_AHB1ENR_CRCEN;
CRC->CR=CRC_CR_RESET; // Reset crc to ensure it is known state
}
uint32_t CalculateCRC32(uint32_t* startAddr, uint32_t length) {
uint32_t crc = 0xFFFFFFFF; // Initial value for CRC32 calculation
// Enable CRC calculation
CRC32_Init();
// Start CRC calculation over the flash memory
for (uint32_t i = 0; i < length / 4; i++) {
// Write 32-bit data from flash memory to the CRC data register
CRC->DR = *(startAddr + i);
}
// Read final CRC value from the CRC data register
crc = CRC->DR;
// Return the CRC value (inverted to match CRC32 convention)
return ~crc;
}
int main(void) {
// Calculate CRC32 for the entire flash memory
uint32_t crc32_result = CalculateCRC32((uint32_t*)FLASH_BASE_ADDR, FLASH_SIZE);
// Now, crc32_result contains the CRC32 checksum of the flash memory
while (1) {
// Main loop
}
}