STM32L4xx_HAL_Driver  1.14.0

IO operation functions. More...

Functions

HAL_StatusTypeDef HAL_DCMI_Start_DMA (DCMI_HandleTypeDef *hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
 Enable DCMI capture in DMA mode. More...
 
HAL_StatusTypeDef HAL_DCMI_Stop (DCMI_HandleTypeDef *hdcmi)
 Disable DCMI capture in DMA mode. More...
 
HAL_StatusTypeDef HAL_DCMI_Suspend (DCMI_HandleTypeDef *hdcmi)
 Suspend DCMI capture. More...
 
HAL_StatusTypeDef HAL_DCMI_Resume (DCMI_HandleTypeDef *hdcmi)
 Resume DCMI capture. More...
 
void HAL_DCMI_ErrorCallback (DCMI_HandleTypeDef *hdcmi)
 Error DCMI callback. More...
 
void HAL_DCMI_LineEventCallback (DCMI_HandleTypeDef *hdcmi)
 Line Event callback. More...
 
void HAL_DCMI_FrameEventCallback (DCMI_HandleTypeDef *hdcmi)
 Frame Event callback. More...
 
void HAL_DCMI_VsyncEventCallback (DCMI_HandleTypeDef *hdcmi)
 VSYNC Event callback. More...
 
void HAL_DCMI_IRQHandler (DCMI_HandleTypeDef *hdcmi)
 Handle DCMI interrupt request. More...
 

Detailed Description

IO operation functions.

 ===============================================================================
                      #####  IO operation functions  #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Configure destination address and data length,
          enable DCMI DMA request and DCMI capture.
      (+) Stop DCMI capture.
      (+) Handle DCMI interrupt request.

    [..]  A set of callbacks is provided:
        (+) HAL_DCMI_ErrorCallback()
        (+) HAL_DCMI_LineEventCallback()
        (+) HAL_DCMI_VsyncEventCallback()
        (+) HAL_DCMI_FrameEventCallback()

Function Documentation

◆ HAL_DCMI_ErrorCallback()

__weak void HAL_DCMI_ErrorCallback ( DCMI_HandleTypeDef hdcmi)

Error DCMI callback.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
Return values
None

Definition at line 813 of file stm32l4xx_hal_dcmi.c.

814 {
815  /* Prevent unused argument(s) compilation warning */
816  UNUSED(hdcmi);
817 
818  /* NOTE : This function should not be modified; when the callback is needed,
819  the HAL_DCMI_ErrorCallback() callback can be implemented in the user file.
820  */
821 }

◆ HAL_DCMI_FrameEventCallback()

__weak void HAL_DCMI_FrameEventCallback ( DCMI_HandleTypeDef hdcmi)

Frame Event callback.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
Return values
None

Definition at line 861 of file stm32l4xx_hal_dcmi.c.

862 {
863  /* Prevent unused argument(s) compilation warning */
864  UNUSED(hdcmi);
865 
866  /* NOTE : This function should not be modified; when the callback is needed,
867  the HAL_DCMI_FrameEventCallback() callback can be implemented in the user file.
868  */
869 }

◆ HAL_DCMI_IRQHandler()

void HAL_DCMI_IRQHandler ( DCMI_HandleTypeDef hdcmi)

Handle DCMI interrupt request.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for the DCMI.
Return values
None

Definition at line 714 of file stm32l4xx_hal_dcmi.c.

715 {
716  uint32_t misflags = READ_REG(hdcmi->Instance->MISR);
717 
718  /* Synchronization error interrupt management *******************************/
719  if ((misflags & DCMI_MIS_ERR_MIS) != 0x0U)
720  {
721  /* Clear the Synchronization error flag */
722  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
723 
724  /* Update error code */
725  hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
726  }
727 
728  /* Overflow interrupt management ********************************************/
729  if ((misflags & DCMI_MIS_OVR_MIS) != 0x0U)
730  {
731  /* Clear the Overflow flag */
732  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
733 
734  /* Update error code */
735  hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
736  }
737 
738  if (hdcmi->ErrorCode != HAL_DCMI_ERROR_NONE)
739  {
740  /* Change DCMI state */
741  hdcmi->State = HAL_DCMI_STATE_READY;
742 
743  /* Set the overflow callback */
745 
746  /* Abort the DMA Transfer */
747  if (HAL_DMA_Abort_IT(hdcmi->DMA_Handle) != HAL_OK)
748  {
749  DCMI_DMAError(hdcmi->DMA_Handle);
750  }
751  }
752 
753  /* Line Interrupt management ************************************************/
754  if ((misflags & DCMI_MIS_LINE_MIS) != 0x0U)
755  {
756  /* Clear the Line interrupt flag */
757  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
758 
759  /* Line interrupt Event Callback */
760 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
761  /*Call registered DCMI line event callback*/
762  hdcmi->LineEventCallback(hdcmi);
763 #else
765 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
766  }
767 
768  /* VSYNC interrupt management ***********************************************/
769  if ((misflags & DCMI_MIS_VSYNC_MIS) != 0x0U)
770  {
771  /* Clear the VSYNC flag */
772  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
773 
774  /* VSYNC Event Callback */
775 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
776  /*Call registered DCMI vsync event callback*/
777  hdcmi->VsyncEventCallback(hdcmi);
778 #else
780 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
781  }
782 
783  /* End of Frame interrupt management ****************************************/
784  if ((misflags & DCMI_MIS_FRAME_MIS) != 0x0U)
785  {
786  /* Disable the Line interrupt when using snapshot mode */
787  if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
788  {
789  __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE|DCMI_IT_VSYNC|DCMI_IT_ERR|DCMI_IT_OVR);
790  /* Change the DCMI state */
791  hdcmi->State = HAL_DCMI_STATE_READY;
792  }
793 
794  /* Clear the End of Frame flag */
795  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
796 
797  /* Frame Event Callback */
798 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
799  /*Call registered DCMI frame event callback*/
800  hdcmi->FrameEventCallback(hdcmi);
801 #else
803 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
804  }
805 }
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
Frame Event callback.
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
Line Event callback.
void(* FrameEventCallback)(struct __DCMI_HandleTypeDef *hdcmi)
__IO HAL_DCMI_StateTypeDef State
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
void(* LineEventCallback)(struct __DCMI_HandleTypeDef *hdcmi)
void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
VSYNC Event callback.
return HAL_OK
DMA_HandleTypeDef * DMA_Handle
static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
DMA error callback.
void(* VsyncEventCallback)(struct __DCMI_HandleTypeDef *hdcmi)

◆ HAL_DCMI_LineEventCallback()

__weak void HAL_DCMI_LineEventCallback ( DCMI_HandleTypeDef hdcmi)

Line Event callback.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
Return values
None

Definition at line 829 of file stm32l4xx_hal_dcmi.c.

830 {
831  /* Prevent unused argument(s) compilation warning */
832  UNUSED(hdcmi);
833 
834  /* NOTE : This function should not be modified; when the callback is needed,
835  the HAL_DCMI_LineEventCallback() callback can be implemented in the user file.
836  */
837 }

◆ HAL_DCMI_Resume()

HAL_StatusTypeDef HAL_DCMI_Resume ( DCMI_HandleTypeDef hdcmi)

Resume DCMI capture.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
Return values
HALstatus

Definition at line 688 of file stm32l4xx_hal_dcmi.c.

689 {
690  /* Process locked */
691  __HAL_LOCK(hdcmi);
692 
693  if(hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
694  {
695  /* Change DCMI state */
696  hdcmi->State = HAL_DCMI_STATE_BUSY;
697 
698  /* Enable Capture */
699  SET_BIT(hdcmi->Instance->CR, DCMI_CR_CAPTURE);
700  }
701 
702  /* Process Unlocked */
703  __HAL_UNLOCK(hdcmi);
704 
705  return HAL_OK;
706 }
__IO HAL_DCMI_StateTypeDef State
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_DCMI_Start_DMA()

HAL_StatusTypeDef HAL_DCMI_Start_DMA ( DCMI_HandleTypeDef hdcmi,
uint32_t  DCMI_Mode,
uint32_t  pData,
uint32_t  Length 
)

Enable DCMI capture in DMA mode.

Parameters
hdcmiPointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
DCMI_ModeDCMI capture mode snapshot or continuous grab.
pDataThe destination memory buffer address.
LengthThe length of capture to be transferred (in 32-bit words).
Note
In case of length larger than 65535 (0xFFFF is the DMA maximum transfer length), the API uses the end of the destination buffer as a work area: HAL_DCMI_Start_DMA() initiates a circular DMA transfer from DCMI DR to the ad-hoc work buffer and each half and complete transfer interrupt triggers a copy from the work buffer to the final destination pData thru a second DMA channel.
Following HAL_DCMI_Init() call, all interruptions are enabled (line end, frame end, overrun, VSYNC and embedded synchronization error interrupts). User can disable unwanted interrupts thru __HAL_DCMI_DISABLE_IT() macro before invoking HAL_DCMI_Start_DMA().
For length less than 0xFFFF (DMA maximum transfer length) and in snapshot mode, frame interrupt is disabled before DMA transfer. FRAME capture flag is checked in DCMI_DMAXferCplt callback at the end of the DMA transfer. If flag is set, HAL_DCMI_FrameEventCallback() API is called.
Return values
HALstatus

Definition at line 467 of file stm32l4xx_hal_dcmi.c.

468 {
469  uint32_t circular_copy_length;
470 
471  /* Check capture parameter */
472  assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
473 
474  /* Process Locked */
475  __HAL_LOCK(hdcmi);
476 
477  /* Lock the DCMI peripheral state */
478  hdcmi->State = HAL_DCMI_STATE_BUSY;
479 
480  /* Configure the DCMI Mode and enable the DCMI IP at the same time */
481  MODIFY_REG(hdcmi->Instance->CR, (DCMI_CR_CM|DCMI_CR_ENABLE), (DCMI_Mode|DCMI_CR_ENABLE));
482 
483  /* Set the DMA conversion complete callback */
485 
486  /* Set the DMA error callback */
488 
489  /* Set the dma abort callback */
490  hdcmi->DMA_Handle->XferAbortCallback = NULL;
491 
492  if(Length <= 0xFFFFU)
493  {
494  hdcmi->XferCount = 0; /* Mark as direct transfer from DCMI_DR register to final destination buffer */
495 
496  /* Enable the DMA channel */
497  if (HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length) != HAL_OK)
498  {
499  /* Update error code */
500  hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
501 
502  /* Set state back to Ready */
503  hdcmi->State = HAL_DCMI_STATE_READY;
504 
505  /* Process Unlocked */
506  __HAL_UNLOCK(hdcmi);
507 
508  return HAL_ERROR;
509  }
510  }
511  else /* Capture length is longer than DMA maximum transfer size */
512  {
513  /* Set DMA in circular mode */
514  hdcmi->DMA_Handle->Init.Mode = DMA_CIRCULAR;
515 
516  /* Set the DMA half transfer complete callback */
518 
519  /* Initialize transfer parameters */
520  hdcmi->XferSize = Length; /* Store the complete transfer length in DCMI handle */
521  hdcmi->pBuffPtr = pData; /* Final destination buffer pointer */
522 
523  circular_copy_length = DCMI_TransferSize(Length);
524 
525  /* Check if issue in intermediate length computation */
526  if (circular_copy_length == 0U)
527  {
528  /* Set state back to Ready */
529  hdcmi->State = HAL_DCMI_STATE_READY;
530 
531  /* Process Unlocked */
532  __HAL_UNLOCK(hdcmi);
533 
534  return HAL_ERROR;
535  }
536 
537  /* Store the number of half - intermediate buffer copies needed */
538  hdcmi->XferCount = 2U * ((Length / circular_copy_length) - 1U);
539  /* Store the half-buffer copy length */
540  hdcmi->HalfCopyLength = circular_copy_length / 2U;
541 
542  /* DCMI DR samples in circular mode will be copied
543  at the end of the final buffer.
544  Now compute the circular buffer start address. */
545  /* Start by pointing at the final buffer */
546  hdcmi->pCircularBuffer = pData;
547  /* Update pCircularBuffer in "moving" at the end of the final
548  buffer, don't forger to convert in bytes to compute exact address */
549  hdcmi->pCircularBuffer += 4U * (((Length / circular_copy_length) - 1U) * circular_copy_length);
550 
551  /* Initiate the circular DMA transfer from DCMI IP to final buffer end */
552  if ( HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)hdcmi->pCircularBuffer, circular_copy_length) != HAL_OK)
553  {
554  /* Update error code */
555  hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
556 
557  /* Set state back to Ready */
558  hdcmi->State = HAL_DCMI_STATE_READY;
559 
560  /* Process Unlocked */
561  __HAL_UNLOCK(hdcmi);
562 
563  return HAL_ERROR;
564  }
565  }
566 
567  /* Enable Capture */
568  SET_BIT(hdcmi->Instance->CR, DCMI_CR_CAPTURE);
569 
570  /* Release Lock */
571  __HAL_UNLOCK(hdcmi);
572 
573  /* Return function status */
574  return HAL_OK;
575 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
DMA conversion complete callback.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_DCMI_StateTypeDef State
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__HAL_UNLOCK(hrtc)
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_InitTypeDef Init
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
__HAL_LOCK(hrtc)
return HAL_OK
DMA_HandleTypeDef * DMA_Handle
static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
DMA error callback.
static uint32_t DCMI_TransferSize(uint32_t InputSize)
Sub-buffers transfer size computation.
static void DCMI_DMAHalfXferCplt(DMA_HandleTypeDef *hdma)
DMA Half Transfer complete callback.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_DCMI_Stop()

HAL_StatusTypeDef HAL_DCMI_Stop ( DCMI_HandleTypeDef hdcmi)

Disable DCMI capture in DMA mode.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
Return values
HALstatus

Definition at line 583 of file stm32l4xx_hal_dcmi.c.

584 {
585  uint32_t tickstart;
586  HAL_StatusTypeDef status = HAL_OK;
587 
588  /* Process locked */
589  __HAL_LOCK(hdcmi);
590 
591  /* Lock the DCMI peripheral state */
592  hdcmi->State = HAL_DCMI_STATE_BUSY;
593 
594  /* Disable Capture */
595  CLEAR_BIT(hdcmi->Instance->CR, DCMI_CR_CAPTURE);
596 
597  /* Get tick */
598  tickstart = HAL_GetTick();
599 
600  /* Check if the DCMI capture is effectively disabled */
601  while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U)
602  {
603  if((HAL_GetTick() - tickstart ) > DCMI_TIMEOUT_STOP)
604  {
605  /* Update error code */
606  hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
607 
608  status = HAL_TIMEOUT;
609  break;
610  }
611  }
612 
613  /* Disable the DMA */
614  if (HAL_DMA_Abort(hdcmi->DMA_Handle) != HAL_OK)
615  {
616  DCMI_DMAError(hdcmi->DMA_Handle);
617  }
618 
619  /* Disable DCMI IP */
620  __HAL_DCMI_DISABLE(hdcmi);
621 
622  /* Change DCMI state */
623  hdcmi->State = HAL_DCMI_STATE_READY;
624 
625  /* Process Unlocked */
626  __HAL_UNLOCK(hdcmi);
627 
628  /* Return function status */
629  return status;
630 }
__IO HAL_DCMI_StateTypeDef State
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
DMA_HandleTypeDef * DMA_Handle
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
DMA error callback.

◆ HAL_DCMI_Suspend()

HAL_StatusTypeDef HAL_DCMI_Suspend ( DCMI_HandleTypeDef hdcmi)

Suspend DCMI capture.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
Return values
HALstatus

Definition at line 638 of file stm32l4xx_hal_dcmi.c.

639 {
640  uint32_t tickstart;
641 
642  /* Process locked */
643  __HAL_LOCK(hdcmi);
644 
645  if(hdcmi->State == HAL_DCMI_STATE_BUSY)
646  {
647  /* Change DCMI state */
649 
650  /* Disable Capture */
651  CLEAR_BIT(hdcmi->Instance->CR, DCMI_CR_CAPTURE);
652 
653  /* Get tick */
654  tickstart = HAL_GetTick();
655 
656  /* Check if the DCMI capture is effectively disabled */
657  while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U)
658  {
659  if((HAL_GetTick() - tickstart ) > DCMI_TIMEOUT_STOP)
660  {
661  /* Update error code */
662  hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
663 
664  /* Change DCMI state */
665  hdcmi->State = HAL_DCMI_STATE_READY;
666 
667  /* Process Unlocked */
668  __HAL_UNLOCK(hdcmi);
669 
670  return HAL_TIMEOUT;
671  }
672  }
673  }
674 
675  /* Process Unlocked */
676  __HAL_UNLOCK(hdcmi);
677 
678  /* Return function status */
679  return HAL_OK;
680 }
__IO HAL_DCMI_StateTypeDef State
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_DCMI_VsyncEventCallback()

__weak void HAL_DCMI_VsyncEventCallback ( DCMI_HandleTypeDef hdcmi)

VSYNC Event callback.

Parameters
hdcmipointer to a DCMI_HandleTypeDef structure that contains the configuration information for DCMI.
Return values
None

Definition at line 845 of file stm32l4xx_hal_dcmi.c.

846 {
847  /* Prevent unused argument(s) compilation warning */
848  UNUSED(hdcmi);
849 
850  /* NOTE : This function should not be modified; when the callback is needed,
851  the HAL_DCMI_VsyncEventCallback() callback can be implemented in the user file.
852  */
853 }