2017-04-24 11:58 PM
Hi to everyone,
I am quite new to STM32, i am starting a new project with it. STM32 seems to be very powerful. However am facing something difficulties and am not sure on what I am doing.
I am trying to implement the DMA to read quickly (at about 10Mgh) a port ( for example PORTC).
ie: GPIOC---- > DMA---> memory buffer.
Here is my code below:
1) setting up portc
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_All; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);2 )setting up the timer for trigerring DMA
__HAL_RCC_TIM1_CLK_ENABLE();
htim1.Instance = TIM1; htim1.Init.Prescaler = 0x8000; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 0x9000; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim1.Init.RepetitionCounter = 0; HAL_TIM_Base_Init(&htim1);3) Setting DMA
DmaHandle.Init.Channel = DMA_CHANNEL_0; / * DMA_CHANNEL_0 */
DmaHandle.Init.Direction = DMA_PERIPH_TO_MEMORY; /* P2M transfer mode */
DmaHandle.Init.PeriphInc = DMA_PINC_DISABLE; /* Peripheral increment mode Enable */
DmaHandle.Init.MemInc = DMA_PINC_ENABLE; /* Memory increment mode Enable */
DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; /* Peripheral data alignment : Word */
DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; /* memory data alignment : Word */
DmaHandle.Init.Mode = DMA_CIRCULAR; /* Normal DMA mode */
DmaHandle.Init.Priority = DMA_PRIORITY_HIGH; /* priority level : high */
DmaHandle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; /* FIFO mode disabled */
DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE; /* Memory burst */
DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; /* Peripheral burst */
/*##-3- Select the DMA instance to be used for the transfer : DMA2_Stream0 #*/
DmaHandle.Instance = DMA_INSTANCE;
/*##-4- Initialize the DMA stream ##########################################*/
if (HAL_DMA_Init(&DmaHandle) != HAL_OK)
{
// /* Initialization Error */
Error_Handler();
}
/*##-5- Select Callbacks functions called after Transfer complete and Transfer error */
HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_CPLT_CB_ID, TransferComplete);
HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_ERROR_CB_ID, TransferError);
//
// /*##-6- Configure NVIC for DMA transfer complete/error interrupts ##########*/
// /* Set Interrupt Group Priority */
HAL_NVIC_SetPriority(DMA_INSTANCE_IRQ, 0, 0);
//
// /* Enable the DMA STREAM global Interrupt */
HAL_NVIC_EnableIRQ(DMA_INSTANCE_IRQ);4) linking dma module to timer isntance.
__HAL_LINKDMA(htim1, hdma,DmaHandle);
This part am not quite sure it does the job as the &htim1.hdma[0] from debugger doesn't show any value. ( I must the same as DmaHandle) doesn't it?
if (HAL_DMA_Start_IT(&DmaHandle, (uint32_t)&GPIOC->IDR, (uint32_t)&aDST_Buffer, BUFFER_SIZE) != HAL_OK)
{ /* Transfer Error */ Error_Handler(); };5) Start Timer 1 for triggering
// (Enable TIM for DMA events) */ __HAL_TIM_ENABLE_DMA(&htim1, 0);// (Run TIM) */ __HAL_TIM_ENABLE(&htim1);Does anyone has sone something similar? I have not been able to trigger the dma. The is no data in my output buffer.
Thanks in advance for anyone kind enough to have a look at my problem.
regards