2024-10-22 06:47 AM - last edited on 2024-10-23 08:56 AM by SofLit
HI, i use CC2 on TIM1 set as input capture measuring pulse period and store in array
/* USER CODE BEGIN TIM1_Init 1 */
LL_DMA_SetPeriphAddress(DMA1, LL_DMA_CHANNEL_3, (uint32_t)&TIM1->CCR2);
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_3, (uint32_t)speedsDMA);
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_3, 360);
this work on MCU offload hw mode. How get in main loop actual positions in DMA arrea? Mean as last valid writed CC2 value ?
Ofcourse last is too in CC2 tim reg , but i require calculate gradient , then previous value is too required = how get possition.
2024-10-22 09:08 AM
DMA has counter, just read it
2024-10-23 07:21 AM
I search in LL or HAL and nothing about counter here...
2024-10-23 07:54 AM
I see it :
/**
* @brief Get Number of data to transfer.
* @note Once the channel is enabled, the return value indicate the
* remaining bytes to be transmitted.
* @rmtoll CNDTR NDT LL_DMA_GetDataLength
* @PAram DMAx DMAx Instance
* @PAram Channel This parameter can be one of the following values:
* @arg @ref LL_DMA_CHANNEL_1
* @arg @ref LL_DMA_CHANNEL_2
* @arg @ref LL_DMA_CHANNEL_3
* @arg @ref LL_DMA_CHANNEL_4
* @arg @ref LL_DMA_CHANNEL_5
* @arg @ref LL_DMA_CHANNEL_6
* @arg @ref LL_DMA_CHANNEL_7 (*)
* @arg @ref LL_DMA_CHANNEL_8 (*)
* (*) Not on all G4 devices
* @retval Between Min_Data = 0 and Max_Data = 0xFFFFFFFF
*/
__STATIC_INLINE uint32_t LL_DMA_GetDataLength(DMA_TypeDef *DMAx, uint32_t Channel)
{
uint32_t dma_base_addr = (uint32_t)DMAx;
return (READ_BIT(((DMA_Channel_TypeDef *)((uint32_t)(dma_base_addr + CHANNEL_OFFSET_TAB[Channel])))->CNDTR,
DMA_CNDTR_NDT));
}
Of course, counter is inverted, means: current-index-in-array = total - remaining.