STM32L4xx_HAL_Driver  1.14.0
Peripheral states functions

Peripheral State functions. More...

Functions

HAL_HASH_StateTypeDef HAL_HASH_GetState (HASH_HandleTypeDef *hhash)
 Return the HASH handle state. More...
 
HAL_StatusTypeDef HAL_HASH_GetStatus (HASH_HandleTypeDef *hhash)
 Return the HASH HAL status. More...
 
void HAL_HASH_ContextSaving (HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer)
 Save the HASH context in case of processing suspension. More...
 
void HAL_HASH_ContextRestoring (HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer)
 Restore the HASH context in case of processing resumption. More...
 
void HAL_HASH_SwFeed_ProcessSuspend (HASH_HandleTypeDef *hhash)
 Initiate HASH processing suspension when in polling or interruption mode. More...
 
HAL_StatusTypeDef HAL_HASH_DMAFeed_ProcessSuspend (HASH_HandleTypeDef *hhash)
 Suspend the HASH processing when in DMA mode. More...
 
uint32_t HAL_HASH_GetError (HASH_HandleTypeDef *hhash)
 Return the HASH handle error code. More...
 

Detailed Description

Peripheral State functions.

 ===============================================================================
                      ##### Peripheral State methods #####
 ===============================================================================
    [..]
    This section permits to get in run-time the state and the peripheral handle
    status of the peripheral:
      (+) HAL_HASH_GetState()
      (+) HAL_HASH_GetStatus()

    [..]
    Additionally, this subsection provides functions allowing to save and restore
    the HASH or HMAC processing context in case of calculation suspension:
      (+) HAL_HASH_ContextSaving()
      (+) HAL_HASH_ContextRestoring()

    [..]
    This subsection provides functions allowing to suspend the HASH processing
      (+) when input are fed to the Peripheral by software
          (++) HAL_HASH_SwFeed_ProcessSuspend()
      (+) when input are fed to the Peripheral by DMA
          (++) HAL_HASH_DMAFeed_ProcessSuspend()

Function Documentation

◆ HAL_HASH_ContextRestoring()

void HAL_HASH_ContextRestoring ( HASH_HandleTypeDef hhash,
uint8_t *  pMemBuffer 
)

Restore the HASH context in case of processing resumption.

Parameters
hhashHASH handle.
pMemBufferpointer to the memory buffer where the HASH context is stored.
Note
The IMR, STR, CR then all the CSR registers are restored in that order. Only the r/w bits are restored.
By default, all the context swap registers (HASH_NUMBER_OF_CSR_REGISTERS of those) are restored (all of them have been saved by default beforehand).
Return values
None

Definition at line 1359 of file stm32l4xx_hal_hash.c.

1360 {
1361  uint32_t mem_ptr = (uint32_t)pMemBuffer;
1362  uint32_t csr_ptr = (uint32_t)HASH->CSR;
1363  uint32_t i;
1364 
1365  /* Prevent unused argument(s) compilation warning */
1366  UNUSED(hhash);
1367 
1368  /* Restore IMR register content */
1369  WRITE_REG(HASH->IMR, (*(uint32_t*)(mem_ptr)));
1370  mem_ptr+=4U;
1371  /* Restore STR register content */
1372  WRITE_REG(HASH->STR, (*(uint32_t*)(mem_ptr)));
1373  mem_ptr+=4U;
1374  /* Restore CR register content */
1375  WRITE_REG(HASH->CR, (*(uint32_t*)(mem_ptr)));
1376  mem_ptr+=4U;
1377 
1378  /* Reset the HASH processor before restoring the Context
1379  Swap Registers (CSR) */
1380  __HAL_HASH_INIT();
1381 
1382  /* By default, restore all CSR registers */
1383  for (i = HASH_NUMBER_OF_CSR_REGISTERS; i >0U; i--)
1384  {
1385  WRITE_REG((*(uint32_t*)(csr_ptr)), (*(uint32_t*)(mem_ptr)));
1386  mem_ptr+=4U;
1387  csr_ptr+=4U;
1388  }
1389 }

◆ HAL_HASH_ContextSaving()

void HAL_HASH_ContextSaving ( HASH_HandleTypeDef hhash,
uint8_t *  pMemBuffer 
)

Save the HASH context in case of processing suspension.

Parameters
hhashHASH handle.
pMemBufferpointer to the memory buffer where the HASH context is saved.
Note
The IMR, STR, CR then all the CSR registers are saved in that order. Only the r/w bits are read to be restored later on.
By default, all the context swap registers (there are HASH_NUMBER_OF_CSR_REGISTERS of those) are saved.
pMemBuffer points to a buffer allocated by the user. The buffer size must be at least (HASH_NUMBER_OF_CSR_REGISTERS + 3) * 4 uint8 long.
Return values
None

Definition at line 1319 of file stm32l4xx_hal_hash.c.

1320 {
1321  uint32_t mem_ptr = (uint32_t)pMemBuffer;
1322  uint32_t csr_ptr = (uint32_t)HASH->CSR;
1323  uint32_t i;
1324 
1325  /* Prevent unused argument(s) compilation warning */
1326  UNUSED(hhash);
1327 
1328  /* Save IMR register content */
1329  *(uint32_t*)(mem_ptr) = READ_BIT(HASH->IMR,HASH_IT_DINI|HASH_IT_DCI);
1330  mem_ptr+=4U;
1331  /* Save STR register content */
1332  *(uint32_t*)(mem_ptr) = READ_BIT(HASH->STR,HASH_STR_NBLW);
1333  mem_ptr+=4U;
1334  /* Save CR register content */
1335  *(uint32_t*)(mem_ptr) = READ_BIT(HASH->CR,HASH_CR_DMAE|HASH_CR_DATATYPE|HASH_CR_MODE|HASH_CR_ALGO|HASH_CR_LKEY|HASH_CR_MDMAT);
1336  mem_ptr+=4U;
1337  /* By default, save all CSRs registers */
1338  for (i = HASH_NUMBER_OF_CSR_REGISTERS; i >0U; i--)
1339  {
1340  *(uint32_t*)(mem_ptr) = *(uint32_t*)(csr_ptr);
1341  mem_ptr+=4U;
1342  csr_ptr+=4U;
1343  }
1344 }

◆ HAL_HASH_DMAFeed_ProcessSuspend()

HAL_StatusTypeDef HAL_HASH_DMAFeed_ProcessSuspend ( HASH_HandleTypeDef hhash)

Suspend the HASH processing when in DMA mode.

Parameters
hhashHASH handle.
Note
When suspension attempt occurs at the very end of a DMA transfer and all the data have already been entered in the Peripheral, hhash->State is set to HAL_HASH_STATE_READY and the API returns HAL_ERROR. It is recommended to wrap-up the processing in reading the digest as usual.
Return values
HALstatus

Definition at line 1417 of file stm32l4xx_hal_hash.c.

1418 {
1419  uint32_t tmp_remaining_DMATransferSize_inWords;
1420  uint32_t tmp_initial_DMATransferSize_inWords;
1421  uint32_t tmp_words_already_pushed;
1422 
1423  if (hhash->State == HAL_HASH_STATE_READY)
1424  {
1425  return HAL_ERROR;
1426  }
1427  else
1428  {
1429 
1430  /* Make sure there is enough time to suspend the processing */
1431  tmp_remaining_DMATransferSize_inWords = ((DMA_Channel_TypeDef *)hhash->hdmain->Instance)->CNDTR;
1432 
1433  if (tmp_remaining_DMATransferSize_inWords <= HASH_DMA_SUSPENSION_WORDS_LIMIT)
1434  {
1435  /* No suspension attempted since almost to the end of the transferred data. */
1436  /* Best option for user code is to wrap up low priority message hashing */
1437  return HAL_ERROR;
1438  }
1439 
1440  /* Wait for BUSY flag to be reset */
1441  if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK)
1442  {
1443  return HAL_TIMEOUT;
1444  }
1445 
1446  if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS) != RESET)
1447  {
1448  return HAL_ERROR;
1449  }
1450 
1451  /* Wait for BUSY flag to be set */
1452  if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, RESET, HASH_TIMEOUTVALUE) != HAL_OK)
1453  {
1454  return HAL_TIMEOUT;
1455  }
1456 
1457  /* Disable DMA channel */
1458  if (HAL_DMA_Abort(hhash->hdmain) ==HAL_OK)
1459  {
1460  /*
1461  Note that the Abort function will
1462  - Clear the transfer error flags
1463  - Unlock
1464  - Set the State
1465  */
1466  }
1467 
1468  /* Clear DMAE bit */
1469  CLEAR_BIT(HASH->CR,HASH_CR_DMAE);
1470 
1471  /* Wait for BUSY flag to be reset */
1472  if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK)
1473  {
1474  return HAL_TIMEOUT;
1475  }
1476 
1477  if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS) != RESET)
1478  {
1479  return HAL_ERROR;
1480  }
1481 
1482  /* At this point, DMA interface is disabled and no transfer is on-going */
1483  /* Retrieve from the DMA handle how many words remain to be written */
1484  tmp_remaining_DMATransferSize_inWords = ((DMA_Channel_TypeDef *)hhash->hdmain->Instance)->CNDTR;
1485 
1486  if (tmp_remaining_DMATransferSize_inWords == 0U)
1487  {
1488  /* All the DMA transfer is actually done. Suspension occurred at the very end
1489  of the transfer. Either the digest computation is about to start (HASH case)
1490  or processing is about to move from one step to another (HMAC case).
1491  In both cases, the processing can't be suspended at this point. It is
1492  safer to
1493  - retrieve the low priority block digest before starting the high
1494  priority block processing (HASH case)
1495  - re-attempt a new suspension (HMAC case)
1496  */
1497  return HAL_ERROR;
1498  }
1499  else
1500  {
1501 
1502  /* Compute how many words were supposed to be transferred by DMA */
1503  tmp_initial_DMATransferSize_inWords = (((hhash->HashInCount%4U)!=0U) ? ((hhash->HashInCount+3U)/4U): (hhash->HashInCount/4U));
1504 
1505  /* If discrepancy between the number of words reported by DMA Peripheral and the numbers of words entered as reported
1506  by HASH Peripheral, correct it */
1507  /* tmp_words_already_pushed reflects the number of words that were already pushed before
1508  the start of DMA transfer (multi-buffer processing case) */
1509  tmp_words_already_pushed = hhash->NbWordsAlreadyPushed;
1510  if (((tmp_words_already_pushed + tmp_initial_DMATransferSize_inWords - tmp_remaining_DMATransferSize_inWords) %16U) != HASH_NBW_PUSHED())
1511  {
1512  tmp_remaining_DMATransferSize_inWords--; /* one less word to be transferred again */
1513  }
1514 
1515  /* Accordingly, update the input pointer that points at the next word to be transferred to the Peripheral by DMA */
1516  hhash->pHashInBuffPtr += 4U * (tmp_initial_DMATransferSize_inWords - tmp_remaining_DMATransferSize_inWords) ;
1517 
1518  /* And store in HashInCount the remaining size to transfer (in bytes) */
1519  hhash->HashInCount = 4U * tmp_remaining_DMATransferSize_inWords;
1520 
1521  }
1522 
1523  /* Set State as suspended */
1524  hhash->State = HAL_HASH_STATE_SUSPENDED;
1525 
1526  return HAL_OK;
1527 
1528  }
1529 }
static HAL_StatusTypeDef HASH_WaitOnFlagUntilTimeout(HASH_HandleTypeDef *hhash, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
Handle HASH processing Timeout.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.

◆ HAL_HASH_GetError()

uint32_t HAL_HASH_GetError ( HASH_HandleTypeDef hhash)

Return the HASH handle error code.

Parameters
hhashpointer to a HASH_HandleTypeDef structure.
Return values
HASHError Code

Definition at line 1536 of file stm32l4xx_hal_hash.c.

1537 {
1538  /* Return HASH Error Code */
1539  return hhash->ErrorCode;
1540 }

◆ HAL_HASH_GetState()

HAL_HASH_StateTypeDef HAL_HASH_GetState ( HASH_HandleTypeDef hhash)

Return the HASH handle state.

Note
The API yields the current state of the handle (BUSY, READY,...).
Parameters
hhashHASH handle.
Return values
HALHASH state

Definition at line 1288 of file stm32l4xx_hal_hash.c.

1289 {
1290  return hhash->State;
1291 }

◆ HAL_HASH_GetStatus()

HAL_StatusTypeDef HAL_HASH_GetStatus ( HASH_HandleTypeDef hhash)

Return the HASH HAL status.

Note
The API yields the HAL status of the handle: it is the result of the latest HASH processing and allows to report any issue (e.g. HAL_TIMEOUT).
Parameters
hhashHASH handle.
Return values
HALstatus

Definition at line 1301 of file stm32l4xx_hal_hash.c.

1302 {
1303  return hhash->Status;
1304 }

◆ HAL_HASH_SwFeed_ProcessSuspend()

void HAL_HASH_SwFeed_ProcessSuspend ( HASH_HandleTypeDef hhash)

Initiate HASH processing suspension when in polling or interruption mode.

Parameters
hhashHASH handle.
Note
Set the handle field SuspendRequest to the appropriate value so that the on-going HASH processing is suspended as soon as the required conditions are met. Note that the actual suspension is carried out by the functions HASH_WriteData() in polling mode and HASH_IT() in interruption mode.
Return values
None

Definition at line 1402 of file stm32l4xx_hal_hash.c.

1403 {
1404  /* Set Handle Suspend Request field */
1405  hhash->SuspendRequest = HAL_HASH_SUSPEND;
1406 }