STM32L4xx_HAL_Driver  1.14.0
DCMI Private Functions

Functions

static void DCMI_DMAXferCplt (DMA_HandleTypeDef *hdma)
 DMA conversion complete callback. More...
 
static void DCMI_DMAHalfXferCplt (DMA_HandleTypeDef *hdma)
 DMA Half Transfer complete callback. More...
 
static void DCMI_DMAError (DMA_HandleTypeDef *hdma)
 DMA error callback. More...
 
static uint32_t DCMI_TransferSize (uint32_t InputSize)
 Sub-buffers transfer size computation. More...
 

Detailed Description

Function Documentation

◆ DCMI_DMAError()

static void DCMI_DMAError ( DMA_HandleTypeDef hdma)
static

DMA error callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 1407 of file stm32l4xx_hal_dcmi.c.

1408 {
1409  DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1410 
1411  /* Update error code */
1412  hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
1413 
1414  /* Change DCMI state */
1415  hdcmi->State = HAL_DCMI_STATE_READY;
1416 
1417  /* DCMI error Callback */
1418 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
1419  /*Call registered DCMI error callback*/
1420  hdcmi->ErrorCallback(hdcmi);
1421 #else
1422  HAL_DCMI_ErrorCallback(hdcmi);
1423 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1424 }
void(* ErrorCallback)(struct __DCMI_HandleTypeDef *hdcmi)
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
Error DCMI callback.
DMA handle Structure definition.
__IO HAL_DCMI_StateTypeDef State
DCMI handle Structure definition.

◆ DCMI_DMAHalfXferCplt()

static void DCMI_DMAHalfXferCplt ( DMA_HandleTypeDef hdma)
static

DMA Half Transfer complete callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Note
When the size of the frame being captured by the DCMI peripheral is larger than 0xFFFF (DMA maximum transfer length), this API initiates another DMA transfer to copy the first half of the work buffer associated to the DCMI handle to the final destination buffer.
Return values
None

Definition at line 1349 of file stm32l4xx_hal_dcmi.c.

1350 {
1351  uint32_t loop_length; /* transfer length */
1352  uint32_t * tmpBuffer_Dest;
1353  uint32_t * tmpBuffer_Orig;
1354 
1355  DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1356 
1357  if(hdcmi->XferCount != 0U)
1358  {
1359  /* Manage first half buffer copy in case of big transfer */
1360 
1361  /* Decrement half-copies counter */
1362  hdcmi->XferCount--;
1363 
1364  /* Point at DCMI final destination */
1365  tmpBuffer_Dest = (uint32_t *)hdcmi->pBuffPtr;
1366 
1367  /* Point at DCMI circular buffer start */
1368  tmpBuffer_Orig = (uint32_t *)hdcmi->pCircularBuffer;
1369 
1370  /* copy half the buffer size */
1371  loop_length = hdcmi->HalfCopyLength;
1372 
1373  /* Save next entry to write at next DMA transfer interruption */
1374  hdcmi->pBuffPtr += (uint32_t) loop_length*4U;
1375  hdcmi->XferSize -= hdcmi->HalfCopyLength;
1376 
1377  /* Data copy from work buffer to final destination buffer */
1378  /* Enable the DMA Channel */
1379  if (HAL_DMA_Start_IT(hdcmi->DMAM2M_Handle, (uint32_t) tmpBuffer_Orig, (uint32_t) tmpBuffer_Dest, loop_length) != HAL_OK)
1380  {
1381  /* Update error code */
1382  hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
1383 
1384  /* Change DCMI state */
1385  hdcmi->State = HAL_DCMI_STATE_READY;
1386 
1387  /* Process Unlocked */
1388  __HAL_UNLOCK(hdcmi);
1389 
1390  /* DCMI error Callback */
1391 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
1392  /*Call registered DCMI error callback*/
1393  hdcmi->ErrorCallback(hdcmi);
1394 #else
1395  HAL_DCMI_ErrorCallback(hdcmi);
1396 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1397  }
1398  }
1399 }
void(* ErrorCallback)(struct __DCMI_HandleTypeDef *hdcmi)
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
Error DCMI callback.
DMA handle Structure definition.
__IO HAL_DCMI_StateTypeDef State
DMA_HandleTypeDef * DMAM2M_Handle
DCMI handle Structure definition.
__HAL_UNLOCK(hrtc)
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.
return HAL_OK

◆ DCMI_DMAXferCplt()

static void DCMI_DMAXferCplt ( DMA_HandleTypeDef hdma)
static

DMA conversion complete callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Note
When the size of the frame being captured by the DCMI peripheral is larger than 0xFFFF (DMA maximum transfer length), this API initiates another DMA transfer to copy the second half of the work buffer associated to the DCMI handle to the final destination buffer.
Return values
None

Definition at line 1248 of file stm32l4xx_hal_dcmi.c.

1249 {
1250  uint32_t loop_length; /* transfer length */
1251  uint32_t * tmpBuffer_Dest;
1252  uint32_t * tmpBuffer_Orig;
1253  uint32_t temp;
1254 
1255  DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1256 
1257 
1258  if(hdcmi->XferCount != 0U)
1259  {
1260  /* Manage second half buffer copy in case of big transfer */
1261 
1262  /* Decrement half-copies counter */
1263  hdcmi->XferCount--;
1264 
1265  /* Point at DCMI final destination */
1266  tmpBuffer_Dest = (uint32_t *)hdcmi->pBuffPtr;
1267 
1268  /* Point at DCMI circular buffer mid-location */
1269  tmpBuffer_Orig = (uint32_t *)hdcmi->pCircularBuffer;
1270  temp = (uint32_t) (tmpBuffer_Orig);
1271  temp += hdcmi->HalfCopyLength;
1272  tmpBuffer_Orig = (uint32_t *) temp;
1273 
1274  /* copy half the buffer size */
1275  loop_length = hdcmi->HalfCopyLength;
1276 
1277  /* Save next entry to write at next half DMA transfer interruption */
1278  hdcmi->pBuffPtr += (uint32_t) loop_length*4U;
1279  hdcmi->XferSize -= hdcmi->HalfCopyLength;
1280 
1281  /* Data copy from work buffer to final destination buffer */
1282  /* Enable the DMA Channel */
1283  if (HAL_DMA_Start_IT(hdcmi->DMAM2M_Handle, (uint32_t) tmpBuffer_Orig, (uint32_t) tmpBuffer_Dest, loop_length) != HAL_OK)
1284  {
1285  /* Update error code */
1286  hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
1287 
1288  /* Change DCMI state */
1289  hdcmi->State = HAL_DCMI_STATE_READY;
1290 
1291  /* Process Unlocked */
1292  __HAL_UNLOCK(hdcmi);
1293 
1294  /* DCMI error Callback */
1295 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
1296  /*Call registered DCMI error callback*/
1297  hdcmi->ErrorCallback(hdcmi);
1298 #else
1299  HAL_DCMI_ErrorCallback(hdcmi);
1300 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1301  }
1302  }
1303  else
1304  {
1305  /* if End of frame IT is disabled */
1306  if((hdcmi->Instance->IER & DCMI_IT_FRAME) == 0x0U)
1307  {
1308  /* If End of Frame flag is set */
1309  if(__HAL_DCMI_GET_FLAG(hdcmi, (uint32_t)DCMI_FLAG_FRAMERI) != 0x0UL)
1310  {
1311  /* Clear the End of Frame flag */
1312  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
1313 
1314  /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
1315  if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
1316  {
1317  /* Disable the Vsync, Error and Overrun interrupts */
1318  __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
1319 
1320  hdcmi->State = HAL_DCMI_STATE_READY;
1321 
1322  /* Process Unlocked */
1323  __HAL_UNLOCK(hdcmi);
1324  }
1325 
1326  /* Frame Event Callback */
1327 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
1328  /*Call registered DCMI frame event callback*/
1329  hdcmi->FrameEventCallback(hdcmi);
1330 #else
1332 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1333  }
1334  }
1335  }
1336 }
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
Frame Event callback.
void(* ErrorCallback)(struct __DCMI_HandleTypeDef *hdcmi)
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
Error DCMI callback.
void(* FrameEventCallback)(struct __DCMI_HandleTypeDef *hdcmi)
DMA handle Structure definition.
__IO HAL_DCMI_StateTypeDef State
DMA_HandleTypeDef * DMAM2M_Handle
DCMI handle Structure definition.
__HAL_UNLOCK(hrtc)
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.
return HAL_OK

◆ DCMI_TransferSize()

static uint32_t DCMI_TransferSize ( uint32_t  InputSize)
static

Sub-buffers transfer size computation.

Note
In the case of a frame size larger than the maximum DMA transfer length (0xFFFF), the tranfer from DCMI DR register to the final output buffer is carried out by a sequence of intermediate sub-copies to temporary buffers of size less than 0xFFFF. To optimize the number of DMA transfers, the API computes the temporary buffer size so that the latter is an even number less than 0xFFFF, that divides the final buffer size and is as high as possible. The API implements a sub-optimum solution for complexity's sake.
InputSize MUST be even.
Parameters
InputSizefull buffer size (in 32-bit words)
Return values
Transfersize (in 32-bit words)

Definition at line 1439 of file stm32l4xx_hal_dcmi.c.

1440 {
1441  uint32_t j = 1;
1442  uint32_t temp = InputSize;
1443  uint32_t aPrime[NPRIME] = {0};
1444  uint32_t output = 2; /* Want a result which is an even number */
1445  uint32_t PrimeArray[NPRIME] = { 1UL, 2UL, 3UL, 5UL,
1446  7UL, 11UL, 13UL, 17UL,
1447  19UL, 23UL, 29UL, 31UL,
1448  37UL, 41UL, 43UL, 47UL};
1449 
1450 
1451  /* Develop InputSize in product of prime numbers */
1452 
1453  while (j < NPRIME)
1454  {
1455  if (temp < PrimeArray[j])
1456  {
1457  break;
1458  }
1459  while ((temp % PrimeArray[j]) == 0U)
1460  {
1461  aPrime[j]++;
1462  temp /= PrimeArray[j];
1463  }
1464  j++;
1465  }
1466 
1467  /* Search for the biggest even divisor less or equal to 0xFFFE = 65534 */
1468  aPrime[1] -= 1U; /* output is initialized to 2, so don't count dividor 2 twice */
1469 
1470  /* The algorithm below yields a sub-optimal solution
1471  but in an acceptable time. */
1472  j = NPRIME-1U;
1473  while ((j > 0U) && (output <= 0xFFFEU))
1474  {
1475  while (aPrime[j] > 0U)
1476  {
1477  if ((output * PrimeArray[j]) > 0xFFFEU)
1478  {
1479  break;
1480  }
1481  else
1482  {
1483  output *= PrimeArray[j];
1484  aPrime[j]--;
1485  }
1486  }
1487  j--;
1488  }
1489 
1490 
1491 
1492  return output;
1493 }