AnsweredAssumed Answered

STM32L071 DMA from Mem to Peri

Question asked by JAN R on Oct 11, 2017
Latest reply on Oct 11, 2017 by waclawek.jan

Hi,

 

I want to use DMA for transfer data from memory (uint16_t DMA_BUFF[10]) to register TM21.ARR. I want to use TIM6 for generating events every 50 ms for DMA to transfer DMA_BUFF[xx] to TIM21.ARR.

In First 50 ms I want to transfer data from DMA_BUFF[0] to TIM21.ARR, another 50 ms  from DMA_BUFF[1] to TIM21.ARR Etc.

I uses CubeMX, but it looks like, there is little problem with Lib. 

 

This my configuration does not work, nothing from my DMA_BUFF is transfered to TIM21.ARR. Can you help me please?

 

I set:

1) TIM6 for generating Events for DMA

TIM_MasterConfigTypeDef sMasterConfig;

htim6.Instance = TIM6;
htim6.Init.Prescaler = 1000;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 100;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

2) Set DMA fro transfer

/*DMA for TIM21*/
DMA_HandleTypeDef hdma;

hdma.Instance=DMA1_Channel2;
hdma.Init.Direction=DMA_MEMORY_TO_PERIPH;
hdma.Init.PeriphInc=DMA_PINC_DISABLE;
hdma.Init.MemInc=DMA_MINC_ENABLE;
hdma.Init.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD;
hdma.Init.MemDataAlignment=DMA_PDATAALIGN_HALFWORD;
hdma.Init.Mode=DMA_NORMAL;
hdma.Init.Request=DMA_REQUEST_9;
HAL_DMA_Init(&hdma);

HAL_DMA_Start(&hdma,(uint32_t)&PWM_DMA_BUFF[0],(uint32_t)&TIM21->ARR,1);

 

3) Run the TIM6

__HAL_TIM_ENABLE(&htim6);

Outcomes