Timer 2 output compare mode generating DMA requests without CC match on F411
Hey everyone,
I am outputting a waveform via TIM2 CCR1 stored in an array and transferred via circular DMA access.
The timer is configured for output compare so that whenever a match occurs, a dma request is generated and the next value is fetched from the array. If I make CCR1 larger than ARR no match should occur and no new value should be loaded. The output should keep it's last state. For whatever reason the next values are still loaded into CCR1. I have looked through the datasheet but could not find anything. The code I use to test this is below.
If anyone has an idea on why this is happening please get back to me.
Cheers,
Christian.
#define array_size 4
unsigned int array[array_size] = {200, 400, 1000, 600};
//enable clock for Port A
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
//set PA0 to AF output
GPIOA->MODER |= GPIO_MODER_MODER0_1;
//set AF1
GPIOA->AFR[0] |= 0x01;
//set to high speed
GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR0_0 | GPIO_OSPEEDER_OSPEEDR0_1;
//enable clock for tim2
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
//set prescaler
TIM2->PSC = 0;
//set ARR Value
TIM2->ARR = 999;
//set initial CC value
TIM2->CCR1 = TIM2->ARR >> 1;
//set CC mode
TIM2->CCMR1 = TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_1;
//enable CC Channel
TIM2->CCER = TIM_CCER_CC1E;
//enable DMA for CC1
TIM2->DIER |= TIM_DIER_CC1DE;
//start timer
TIM2->CR1 = TIM_CR1_CEN;
//enable clock for DMA1
RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN;
//set peripheral register address
DMA1_Stream5->PAR = &(TIM2->CCR1);
//Set memory address
DMA1_Stream5->M0AR = &(array[0]);
//set number of items to be transferred
DMA1_Stream5->NDTR = array_size;
//set channel to 3 (TIM2)
DMA1_Stream5->CR |= DMA_SxCR_CHSEL_0 | DMA_SxCR_CHSEL_1;
//Set priority
DMA1_Stream5->CR |= DMA_SxCR_PL_0 | DMA_SxCR_PL_1;
//set memory size
DMA1_Stream5->CR |= DMA_SxCR_MSIZE_1; //32 bit
//set peripheral size
DMA1_Stream5->CR |= DMA_SxCR_PSIZE_1; //32 bit
//increment memory pointer
DMA1_Stream5->CR |= DMA_SxCR_MINC;
//circular mode
DMA1_Stream5->CR |= DMA_SxCR_CIRC;
//direction
DMA1_Stream5->CR |= DMA_SxCR_DIR_0;
//clear flags
DMA1->HIFCR = 0xFFFFFFFF;
DMA1->LIFCR = 0xFFFFFFFF;
//enable dma controller
DMA1_Stream5->CR |= DMA_SxCR_EN;