cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L071 DMA from Mem to Peri

JAN R
Associate III
Posted on October 11, 2017 at 14:33

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);

#dma-transfer #dma #tim6 #dma-problem #from-memory
5 REPLIES 5
Posted on October 11, 2017 at 15:08

You need to set TIM6_DIER.UDE. I don't know what's the Cube incantation for this.

JW

JAN R
Associate III
Posted on October 11, 2017 at 15:51

Thanks for reply, but it still does not work.

I tried to generate interrupt when TIM6 Update events occur and it works fine.So I think that problem could be somewehere in the DMA setting?!

1) My setting of DMA:

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);

2) TIM6 setting:

/*Start Tim6 for Generate Events for DMA*/

LL_TIM_EnableDMAReq_UPDATE(TIM6);

//LL_TIM_EnableIT_UPDATE(TIM6); // just for check if Update events occur

LL_TIM_EnableCounter(TIM6);

The source and destination adress is OK, so maybe 

hdma.Init.Request=DMA_REQUEST_9; ?

Thanks for help.

JAN R
Associate III
Posted on October 11, 2017 at 16:40

You can see the content of registers bellow:

0690X00000608ZrQAI.png0690X00000608ZwQAI.png

Thank you, Jan.

Posted on October 11, 2017 at 17:06

Both DMA_CNDTR2=0 and  DMA_ISR=0x07 indicate that the DMA has already run into completion.

JW

Posted on October 11, 2017 at 16:01

Dunno. Post the content of relevant DMA and TIM registers.

JW