2020-07-29 06:51 AM
Im working with STM32F4 DISCOVERY board. I'm trying to generate DMA request to write to GPIOD[15:8] pins on button press (PA0) by input capture timer configuration (TIM2) .
I presume my configuration of timer is wrong, because i used very similar DMA configuration with request generated on update event from different timer.
#define BUFLEN (512)
static uint8_t dmabuf[BUFLEN] = {0};
int i;
for(i=0; i<BUFLEN; i+=2){ //Generating buffer
dmabuf[i] = 0xFF;
dmabuf[i+1] = 0;
}
/* TIM2_CH1 : Stream 5 Channel 1 */
RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;
DMA1_Stream5->CR &= ~DMA_SxCR_EN;
DMA1_Stream5->CR |= DMA_SxCR_MINC //pointer incrementation
| (3u << DMA_SxCR_CHSEL_Pos) //TIM2_1
| DMA_SxCR_PL_1 // Priority level high
| DMA_SxCR_CIRC // Circular mode enabled
| DMA_SxCR_DIR_0; // 0b01: memory to peripheral
DMA1_Stream5->NDTR = BUFLEN; //BUFLEN = 512
DMA1_Stream5->M0AR = &dmabuf;
DMA1_Stream5->PAR = (uint32_t)&GPIOD->ODR + 1;
DMA1_Stream5->CR |= DMA_SxCR_EN; // Stream enabled
/* TIM2 channel 1 pin (PA0) configuration */
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
GPIOA->MODER |= GPIO_MODER_MODE0_1;
GPIOA->MODER &= ~ GPIO_MODER_MODE0_0;
GPIOA->AFR[0] |= GPIO_AF1_TIM2;
/* Timer2 configurations */
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; // TIM2 clock enable
TIM2->CCMR1 |= TIM_CCMR1_CC1S_0; //T1 Input
TIM2->CCER |= TIM_CCER_CC1E; // Capture enabled
TIM2->DIER |= TIM_DIER_CC1DE; // CC1 DMA request enabled
TIM2->CR1 |= TIM_CR1_CEN; // TIM enable counter