cancel
Showing results for 
Search instead for 
Did you mean: 

`HAL_CRYP_Encrypt_DMA(...)` hangs indefinitely when `PeriphDataAlignment = DMA_PDATAALIGN_WORD`.

ATuli.1
Associate

Hello,

I'm working on two ST Nucleo-F439ZI boards, and using the Eclipse based STM32 IDE for the development and deployment on the boards.

I'm using the CRYP module in DMA mode to carry out AES-CBC operations.

I've generated the main skeleton of the code using the code generator, and this is the relevant output:

void HAL_CRYP_MspInit(CRYP_HandleTypeDef* hcryp)
{
  if(hcryp->Instance==CRYP)
  {
  /* USER CODE BEGIN CRYP_MspInit 0 */
  /* USER CODE END CRYP_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_CRYP_CLK_ENABLE();
  
    /* CRYP DMA Init */
    /* CRYP_IN Init */
    hdma_cryp_in.Instance = DMA2_Stream6;
    hdma_cryp_in.Init.Channel = DMA_CHANNEL_2;
    hdma_cryp_in.Init.Direction = DMA_MEMORY_TO_PERIPH;
    hdma_cryp_in.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_cryp_in.Init.MemInc = DMA_MINC_ENABLE;
    hdma_cryp_in.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    hdma_cryp_in.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
    hdma_cryp_in.Init.Mode = DMA_NORMAL;
    hdma_cryp_in.Init.Priority = DMA_PRIORITY_LOW;
    hdma_cryp_in.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
    if (HAL_DMA_Init(&hdma_cryp_in) != HAL_OK)
    {
      Error_Handler();
    }
 
    __HAL_LINKDMA(hcryp,hdmain,hdma_cryp_in);
 
    /* CRYP_OUT Init */
    hdma_cryp_out.Instance = DMA2_Stream5;
    hdma_cryp_out.Init.Channel = DMA_CHANNEL_2;
    hdma_cryp_out.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_cryp_out.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_cryp_out.Init.MemInc = DMA_MINC_ENABLE;
    hdma_cryp_out.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    hdma_cryp_out.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
    hdma_cryp_out.Init.Mode = DMA_NORMAL;
    hdma_cryp_out.Init.Priority = DMA_PRIORITY_LOW;
    hdma_cryp_out.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
    if (HAL_DMA_Init(&hdma_cryp_out) != HAL_OK)
    {
      Error_Handler();
    }
 
    __HAL_LINKDMA(hcryp,hdmaout,hdma_cryp_out);
 
  /* USER CODE BEGIN CRYP_MspInit 1 */
  /* USER CODE END CRYP_MspInit 1 */
  }
 
}

However, if I leave the `PeriphDataAlignment` to the default value, hence byte, when I `HAL_CRYP_Encrypt_DMA(...)` gets executed, the DMA job never ends. This is true both for mem-to-periph and periph-to-mem, I checked this using the callbacks `HAL_CRYP_OutCpltCallback(...)` and `HAL_CRYP_InCpltCallback(...)`.

For example, when settings both to byte alignment, nothing happens, while when setting the input channel (mem-to-periph) to word alignment, the first step finishes, and the second (periph-to-mem) hangs indefinitely.

This does not happen when using the polling version `HAL_CRYP_Encrypt(...)`.

0 REPLIES 0