Skip to main content
MM..1
Super User
October 22, 2024
Question

Timer input capture into DMA buffer how get position ?

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.

This topic has been closed for replies.

3 replies

MasterT
Lead II
October 22, 2024

DMA has counter, just read it

MM..1
MM..1Author
Super User
October 23, 2024

I search in LL or HAL and nothing about counter here...

MasterT
Lead II
October 23, 2024

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.