AnsweredAssumed Answered

F072 Nucleo TIM2/DMA/Input capture issues

Question asked by OASH82 on Jul 17, 2016
Latest reply on Jul 21, 2016 by Clive One
I am trying to work with STM32F072 input capture using TIM2 and DMA transfers.
There is an issue in CubeMX which make it always change the alignment to BYTE, I always have to change it back to WORD, really annoying...

I also noticed that once I configure DMA memory address alignment to WORD, hardware issues pop up, here is the code that inits DMA:

hdma_tim2_ch1.Instance = DMA1_Channel5;
hdma_tim2_ch1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_tim2_ch1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_tim2_ch1.Init.MemInc = DMA_MINC_ENABLE;
hdma_tim2_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_tim2_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_tim2_ch1.Init.Mode = DMA_CIRCULAR;
hdma_tim2_ch1.Init.Priority = DMA_PRIORITY_HIGH;

When the code enters HAL_TIM_IC_CaptureCallback in main.c, if the memory alignment is set to DMA_MDATAALIGN_WORD, the code directly goes to HardFault_Handler inside stm32f0xx_it.c when exectuing __HAL_TIM_SET_COUNTER(htim, 0); indicating there is an issue with htim address. When memory alignment is configured to either HALFWORD or BYTE, htim address is correct, but really useless in my case.

I traced the code, when it arrives to TIM_DMACaptureCplt inside stm32f0xx_hal_tim.c, it seems that this line is responsible for getting htim address:

TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;

which results in the wrong address in case memory alignment was set to DMA_MDATAALIGN_WORD.

I attched the files inside Src directory in addition to CubeMX file. Create  a new directory , copy its path and place CubeMX file inside this directory and edit the paths inside ioc file to become the path of the directory you created to be able to open ioc file correctly.

finally, why do I have to reset TIM2 everytime I exit HAL_TIM_IC_CaptureCallback to get correct results?

CubeMX version: 4.15.1
F0Cube version: 1.6