[HAL][CRYP] Update Crypt/Decrypt IT processes to avoid Computation Completed IRQ fires before the DINR pointer increment
diff --git a/Src/stm32l0xx_hal_cryp.c b/Src/stm32l0xx_hal_cryp.c index 4ca4430..b8aa102 100644 --- a/Src/stm32l0xx_hal_cryp.c +++ b/Src/stm32l0xx_hal_cryp.c
@@ -822,7 +822,13 @@ /* Get the last input data address */ inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; - + + /* Increment the pointer before writing the input block in the IN FIFO to make sure that + when Computation Completed IRQ fires, the hcryp->CrypInCount has always a consistent value + and it is ready for the next operation. */ + hcryp->pCrypInBuffPtr += 16U; + hcryp->CrypInCount -= 16U; + /* Write the Input block in the Data Input register */ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; @@ -831,9 +837,7 @@ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; hcryp->Instance->DINR = *(uint32_t*)(inputaddr); - hcryp->pCrypInBuffPtr += 16U; - hcryp->CrypInCount -= 16U; - + /* Return function status */ return HAL_OK; } @@ -911,7 +915,13 @@ /* Get the last input data address */ inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; - + + /* Increment the pointer before writing the input block in the IN FIFO to make sure that + when Computation Completed IRQ fires, the hcryp->CrypInCount has always a consistent value + and it is ready for the next operation. */ + hcryp->pCrypInBuffPtr += 16U; + hcryp->CrypInCount -= 16U; + /* Write the Input block in the Data Input register */ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; @@ -920,9 +930,7 @@ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; hcryp->Instance->DINR = *(uint32_t*)(inputaddr); - hcryp->pCrypInBuffPtr += 16U; - hcryp->CrypInCount -= 16U; - + /* Return function status */ return HAL_OK; } @@ -1000,7 +1008,13 @@ /* Get the last input data address */ inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; - + + /* Increment the pointer before writing the input block in the IN FIFO to make sure that + when Computation Completed IRQ fires, the hcryp->CrypInCount has always a consistent value + and it is ready for the next operation. */ + hcryp->pCrypInBuffPtr += 16U; + hcryp->CrypInCount -= 16U; + /* Write the Input block in the Data Input register */ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; @@ -1009,9 +1023,7 @@ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; hcryp->Instance->DINR = *(uint32_t*)(inputaddr); - hcryp->pCrypInBuffPtr += 16U; - hcryp->CrypInCount -= 16U; - + /* Return function status */ return HAL_OK; } @@ -1086,7 +1098,13 @@ /* Get the last input data address */ inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; - + + /* Increment the pointer before writing the input block in the IN FIFO to make sure that + when Computation Completed IRQ fires, the hcryp->CrypInCount has always a consistent value + and it is ready for the next operation. */ + hcryp->pCrypInBuffPtr += 16U; + hcryp->CrypInCount -= 16U; + /* Write the Input block in the Data Input register */ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; @@ -1095,9 +1113,7 @@ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; hcryp->Instance->DINR = *(uint32_t*)(inputaddr); - hcryp->pCrypInBuffPtr += 16U; - hcryp->CrypInCount -= 16U; - + /* Return function status */ return HAL_OK; } @@ -1175,7 +1191,13 @@ /* Get the last input data address */ inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; - + + /* Increment the pointer before writing the input block in the IN FIFO to make sure that + when Computation Completed IRQ fires, the hcryp->CrypInCount has always a consistent value + and it is ready for the next operation. */ + hcryp->pCrypInBuffPtr += 16U; + hcryp->CrypInCount -= 16U; + /* Write the Input block in the Data Input register */ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; @@ -1184,9 +1206,7 @@ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; hcryp->Instance->DINR = *(uint32_t*)(inputaddr); - hcryp->pCrypInBuffPtr += 16U; - hcryp->CrypInCount -= 16U; - + /* Return function status */ return HAL_OK; } @@ -1264,7 +1284,13 @@ /* Get the last input data address */ inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; - + + /* Increment the pointer before writing the input block in the IN FIFO to make sure that + when Computation Completed IRQ fires, the hcryp->CrypInCount has always a consistent value + and it is ready for the next operation. */ + hcryp->pCrypInBuffPtr += 16U; + hcryp->CrypInCount -= 16U; + /* Write the Input block in the Data Input register */ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; @@ -1272,10 +1298,8 @@ inputaddr+=4U; hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; - hcryp->Instance->DINR = *(uint32_t*)(inputaddr); - hcryp->pCrypInBuffPtr += 16U; - hcryp->CrypInCount -= 16U; - + hcryp->Instance->DINR = *(uint32_t*)(inputaddr); + /* Return function status */ return HAL_OK; } @@ -1921,7 +1945,13 @@ { /* Get the last Input data address */ inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; - + + /* Increment the pointer before writing the input block in the IN FIFO to make sure that + when Computation Completed IRQ fires, the hcryp->CrypInCount has always a consistent value + and it is ready for the next operation. */ + hcryp->pCrypInBuffPtr += 16U; + hcryp->CrypInCount -= 16U; + /* Write the Input block in the Data Input register */ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; @@ -1930,8 +1960,6 @@ hcryp->Instance->DINR = *(uint32_t*)(inputaddr); inputaddr+=4U; hcryp->Instance->DINR = *(uint32_t*)(inputaddr); - hcryp->pCrypInBuffPtr += 16U; - hcryp->CrypInCount -= 16U; } return HAL_OK; }