STM32U535 hardware CRC peripheral modbus
I want to use crc hardware peripheral in STM32U535 for checking some modbus and I copied a code from this community thanks to @Tesla DeLorean . But in my case this code seems to work only for a buffer lenght multiple of four bytes. I can't found my error. Is there someone who can please help me? I noticed that it insted works if the last bytes, overnumbering the multiple of four, are all zeros. Has someone noticed something like this?
Here is the code:
uint32_t CRC_HardwareBlock(const uint8_t *Buffer, uint16_t Size ){
//funziona solo se Size è multiplo di quattro! Attesi commenti su forum di STM32
//RCC->AHB1ENR |= RCC_AHB1ENR_CRCEN; __NOP(); // init()
CRC->INIT = 0xFFFF;
CRC->POL = 0x8005;
CRC->CR = 0xE9;
//CRC->CR |= CRC_CR_RESET;
while(Size >= 4){ // Do as much as we can at 32-bits
CRC->DR = *((uint32_t *)Buffer);
Buffer += 4;
Size -= 4;
}
while(Size >= 2){ // Perhaps one of these
*((uint16_t *)&CRC->DR ) = *((uint16_t *)Buffer);
Buffer += 2;
Size -= 2;
}
while(Size--) // Perhaps one of these
*((uint8_t *)&CRC->DR) = *Buffer++;
return(CRC->DR); // Return final CRC computation
}//uint32_t CRC_HardwareBlock(const uint8_t *Buffer, uint16_t Size ){
