STM32: crc lld: in reversal mode should be changed for tail

This commit is contained in:
Andrey Gusakov 2021-07-02 01:57:24 +03:00
parent fe3cdf8314
commit d4a0d9f0a9
1 changed files with 11 additions and 0 deletions

View File

@ -270,6 +270,10 @@ uint32_t crc_lld_calc(CRCDriver *crcp, size_t n, const void *buf) {
* you are writing more than a byte into the DR register.
*/
if (crcp->config->reflect_data != 0) {
#if STM32_CRC_PROGRAMMABLE == TRUE
/* set default bit reversal done by word */
crcp->crc->CR |= CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0;
#endif
while(n > 3) {
_crc_lld_calc_word(crcp, *(uint32_t*)buf);
buf+=4;
@ -287,6 +291,8 @@ uint32_t crc_lld_calc(CRCDriver *crcp, size_t n, const void *buf) {
* you are writing more than a byte into the DR register.
*/
if (crcp->config->reflect_data != 0) {
/* use bit reversal done by half-word if we are going to write tailing halfword */
crcp->crc->CR = (crcp->crc->CR & ~CRC_CR_REV_IN_Msk) | CRC_CR_REV_IN_1;
while(n > 1) {
_crc_lld_calc_halfword(crcp, *(uint16_t*)buf);
buf+=2;
@ -294,6 +300,11 @@ uint32_t crc_lld_calc(CRCDriver *crcp, size_t n, const void *buf) {
}
}
/* use bit reversal done by byte if we are going to write tailing byte */
if (crcp->config->reflect_data != 0) {
crcp->crc->CR = (crcp->crc->CR & ~CRC_CR_REV_IN_Msk) | CRC_CR_REV_IN_0;
}
while(n > 0) {
_crc_lld_calc_byte(crcp, *(uint8_t*)buf);
buf++;