But "DIY" should not be too difficult. I have found an example for STM32F40x on github
Code: Select all
stm32_tim_t *enc = STM32_TIM4;
palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_PUDR_PULLUP);
palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_PUDR_PULLUP);
rccEnableTIM4(TRUE);
enc->SMCR = 3; // encoder mode 3
enc->CCER = 0; // rising edge polarity
enc->ARR = 0xffff; // count from 0-ARR or ARR-0
enc->CCMR1 = 0xc1c1; // f_DTS/16, N=8 IC1->TI1, IC2->TI2
enc->CNT = 0; // initialize counter
enc->EGR = 1; // generate an update event
enc->CR1 = 1; // enable the counterFor my case, where I intend to use TIM15 and PA2/PA3 I have:
Code: Select all
#define MYTIMER TIM15
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(0));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(0));
GPIOA->PUPDR |= 0x50; // enable pullups.
rccEnableTIM15 (FALSE);
MYTIMER->CR1 = 0;
MYTIMER->CR2 = 0;
MYTIMER->SMCR = 3 * TIM_SMCR_SMS_0;
//MYTIMER->SMCR = 0;
MYTIMER->DIER = 0;
MYTIMER->EGR = 0;
// MYTIMER->CCMR1 = 0xf1f1;
MYTIMER->CCMR1 = 0xc1c1;
// MYTIMER->CCER = 0x91;
MYTIMER->CCER = 0x00;
MYTIMER->PSC = 0;
MYTIMER->ARR = 0xffff;
MYTIMER->RCR = 0;
MYTIMER->CCR1 = 0;
MYTIMER->CCR2 = 0;
MYTIMER->BDTR = 0;
MYTIMER->DCR = 0;
MYTIMER->CNT = 0;
MYTIMER->DMAR = 0;
MYTIMER->EGR = 1;
MYTIMER->CR1 = TIM_CR1_CEN;
The counter register (TIM15->CNT) ALWAYS reads back as zero. (unless I initialize it to another value, then it remains at that value).
Anything I'm missing here?