2024-07-01 06:29 AM
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 ){
2024-07-01 07:48 AM
I don't know, what does the configuration unpack as?
The STM32 is very fussy with respect to the bit/byte widths and directions.
MODBUS-CRC is right shifting
Inspect the generated code.
The software table methods aren't particularly slow
Roberto's LL (Low Level) implementation looks right, my original link seems broken after several forum transitions.
2024-07-09 12:05 AM
Thank you Tesla.
I'll keep you updated, but at this time I can't investigate furthermore. I swapped hardware crc for external memory (always multiple of four bytes) and software tabled crc for modbus.