cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L100 RI for TIM IC routing

bhamilton
Associate II
Posted on July 10, 2014 at 04:57

Hi all, question on the STM32L100 RI. I'm trying to use the RI to remap PA12 to TIM4CH1. As soon as the GPIO pin is set to alternate function mode on AF14 it's immediately set to output low, regardless of RI->ICR's value.

The following bit of code reproduces it on every processor I've tested (STM32L100R8T6, STM32L100RCT6):

#include ''stm32l1xx.h''
int main()
{
RCC->AHBENR |= 0xFFFFFFFF;
RCC->APB1ENR |= 0xFFFFFFFF;
RCC->APB2ENR = 0xFFFFFFFF;
// remap only PA12 to TIM4
RI->ICR = 0x70003;
GPIOA->AFR[1] = (GPIOA->AFR[1] & ~GPIO_AFRH_AFRH12) | (0xE << ((12 - 8) * 4)); // AF14
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER12)) | GPIO_MODER_MODER12_1; // alternate function mode
// GPIOB->AFR[0] = 0x2 << (6 * 4);
// GPIOB->MODER = 0x2 << (6 * 2);
// GPIOB->PUPDR = 0;
RI->ICR = 0x70003;
// set up TIM4
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
TIM4->CR1 = TIM_CR1_URS;
TIM4->CR2 = 0;
TIM4->CCER = 0;
TIM4->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_IC1F_1;
TIM4->CCMR2 = 0;
TIM4->PSC = 32-1;
TIM4->CCER = TIM_CCER_CC1P | TIM_CCER_CC1E;
TIM4->ARR = 0xFFFF;
TIM4->CR1 |= TIM_CR1_CEN; // start counter
while(1)
{
if (TIM4->SR & TIM_SR_CC1IF)
{
TIM4->SR = ~TIM_SR_CC1IF;
}
__NOP();
}
}

Note that if I comment out the stuff to remap PA12 then the default pin (PB6) floats as expected and causes the CH1 capture, so I'm reasonably certain that my timer setup isn't causing the problem. I double-checked all the register addresses. PA12 appears to be otherwise functioning normally if I manually throw some data into the GPIOA registers with the debugger. #ri-routing-interface
1 REPLY 1
bhamilton
Associate II
Posted on July 23, 2014 at 04:01

I appear to have stumbled on a workaround, in case somebody finds this thread in the future. PA12 should not be set to AF14, rather it should be set as a high impedance input (MODER = 0). When this is done the routing interface can correctly route it to TIM4 IC1.

#include ''stm32l1xx.h''
int
main()
{
RCC->AHBENR = 0xFFFFFFFF;
RCC->APB1ENR = 0xFFFFFFFF;

RCC->APB2ENR = 0xFFFFFFFF;
// remap only PA12 to TIM4
RI->ICR = 0x70003;
GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR12; 
// no pull up
GPIOA->MODER &= ~GPIO_MODER_MODER12; 
// high impedance input
RI->ICR = 0x00070003;
// set up TIM4
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
TIM4->CR1 = 0;
TIM4->CR2 = 0;
TIM4->CCER = 0;
TIM4->CCMR1 = 1;
//TIM_CCMR1_CC1S_0 | TIM_CCMR1_IC1F_1;
TIM4->CCMR2 = 0;
TIM4->PSC = 32-1;
TIM4->CCER = TIM_CCER_CC1P | TIM_CCER_CC1E;
TIM4->ARR = 0xFFFF;
TIM4->CR1 |= TIM_CR1_CEN; 
// start counter
while
(1)
{
if
(TIM4->SR & TIM_SR_CC1IF)
{
TIM4->SR = ~TIM_SR_CC1IF;
}
}
}