@@ -50,7 +50,12 @@ void hal_crc_compute_partial_start(const crc_mbed_config_t* config)
50
50
platform_config .seed = config -> initial_xor ;
51
51
platform_config .reflectIn = config -> reflect_in ;
52
52
platform_config .reflectOut = config -> reflect_out ;
53
- platform_config .complementChecksum = (config -> final_xor == 0xFFFFFFFFU );
53
+ if ((width == kCrcBits16 && config -> final_xor == 0xFFFFU ) ||
54
+ (width == kCrcBits32 && config -> final_xor == 0xFFFFFFFFU )) {
55
+ platform_config .complementChecksum = true;
56
+ } else {
57
+ platform_config .complementChecksum = false;
58
+ }
54
59
platform_config .crcBits = width ;
55
60
platform_config .crcResult = kCrcFinalChecksum ;
56
61
@@ -72,20 +77,31 @@ void hal_crc_compute_partial(const uint8_t *data, const size_t size)
72
77
73
78
uint32_t hal_crc_get_result (void )
74
79
{
75
- if ((final_xor != 0x00000000U ) && (final_xor != 0xFFFFFFFFU )) {
76
- CRC_WriteData (CRC0 , (uint8_t * )& final_xor , sizeof (final_xor ));
77
- }
78
-
79
- switch (width )
80
- {
81
- case kCrcBits16 :
82
- return CRC_Get16bitResult (CRC0 );
83
- case kCrcBits32 :
84
- return CRC_Get32bitResult (CRC0 );
85
- default :
86
- MBED_ASSERT ("Unhandled switch case" );
87
- return 0 ;
88
- }
80
+ uint32_t result ;
81
+
82
+ const bool manual_final_xor = ((final_xor != 0x00000000U ) &&
83
+ ((final_xor != 0xFFFFFFFFU && width == kCrcBits32 ) ||
84
+ (final_xor != 0xFFFFU && width == kCrcBits16 )));
85
+
86
+ switch (width )
87
+ {
88
+ case kCrcBits16 :
89
+ result = CRC_Get16bitResult (CRC0 );
90
+ if (manual_final_xor ) {
91
+ result ^= final_xor ;
92
+ result &= 0xFFFF ;
93
+ }
94
+ return result ;
95
+ case kCrcBits32 :
96
+ result = CRC_Get32bitResult (CRC0 );
97
+ if (manual_final_xor ) {
98
+ result ^= final_xor ;
99
+ }
100
+ return result ;
101
+ default :
102
+ MBED_ASSERT ("Unhandled switch case" );
103
+ return 0 ;
104
+ }
89
105
}
90
106
91
107
#endif // DEVICE_CRC
0 commit comments