2
\$\begingroup\$

I have a periodic signal which I want to use as a trigger to two timers - TIM8 and TIM2. When the signal goes high, TIM8 should start running and TIM2 will be clocked once. TIM2 will be configured in external clock mode 2. I have configured PA0 as external trigger for TIM8 and PA5 as exernal trigger for TIM2, and connected the signal to both pins.

I find that TIM8 does not start, unless I disconnect PA5. As soon as PA5 and PA0 are both connected, TIM8 no longer starts. I also find that TIM8 starts if I comment the line that configures PA5. In this case PA5 is in a high-Z state by default.

It appears that the signal can only drive a single pin at a time, not multiple pins. Why would this be the case? The signal I am using can be set at varying drive strengths, I have experimented with all of them and gotten the same result.

PA5 is not connected to anything else on the dev board I am using, and I observed the same behaviour with a few other pins - I tried configuring some other pins on GPIOA as AF inputs and observed TIM8 stop running when both PA0 and the other pins were connected.

The code I am using is as follows:

GPIO_InitTypeDef gpio;
NVIC_InitTypeDef nvic;
GPIO_StructInit(&gpio);

/* Configure PA0 for TIM8 ETR (HSYNC to start pixel clock), datasheet page 62 */
gpio.GPIO_Pin       = GPIO_Pin_0;
gpio.GPIO_Mode      = GPIO_Mode_AF;
gpio.GPIO_Speed     = GPIO_Speed_50MHz;
gpio.GPIO_OType     = GPIO_OType_PP;
gpio.GPIO_PuPd      = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &gpio);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_TIM8);

/* Configure PA1 for TIM2 CH2 (This will be VSYNC, to reset the timer) */
/* Configure PA5 for TIM2 ETR (External clock, this will be HSYNC to count syncs) */
gpio.GPIO_Pin       = GPIO_Pin_1 | GPIO_Pin_5; 
gpio.GPIO_Mode      = GPIO_Mode_AF;
gpio.GPIO_Speed     = GPIO_Speed_50MHz;
gpio.GPIO_OType     = GPIO_OType_PP;
gpio.GPIO_PuPd      = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &gpio); // Works if this is commented
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_TIM2);

The only explanation I can think of is that PA5 is pulling the line low, preventing PA0 from getting the signal. But if PA5 is configured as an input it should not pull low as it will have a high impedance. So I'm thinking it must be misconfigured, or else damaged. PA0 can also be an ETR for TIM2 and PA0 definitely works, I will try that and see if I can get TIM2 to run. If it does I will suspect the pin

\$\endgroup\$
  • \$\begingroup\$ If you leave PA0 unconfigured does TIM2 work correctly? \$\endgroup\$ – Jon Sep 5 '18 at 13:50
  • \$\begingroup\$ Also I'm reasonably sure you can use the ITR function so this can all be done using a single IO pin. \$\endgroup\$ – Jon Sep 5 '18 at 14:04
  • \$\begingroup\$ @Jon TIM2 does not work correctly with PA0 unconnected. \$\endgroup\$ – Batperson Sep 5 '18 at 21:48
  • \$\begingroup\$ @Jon I could clock TIM2 using ITR connected to TIM8, but I also need to reset TIM2 on another external signal (VSYNC) which is why I am using external clock mode 2. If my reading of the datasheet is correct external clock mode 2 only works with ETR. want to be able to use another pin to reset TIM2. As far as I'm aware the only way to have 2 inputs to a timer is external clock mode 2, which is why \$\endgroup\$ – Batperson Sep 5 '18 at 22:14
  • \$\begingroup\$ "Why can't I route the same signal to multiple pins on an STM32F407?" Unless someone here actually designed that part of the STM32F407, any answer would be just pointless speculation. Closing as opinion based. \$\endgroup\$ – Olin Lathrop Sep 5 '18 at 23:26
1
\$\begingroup\$

The second pin was misconfigured as an input

I was attempting to use pin PA5 as ETR for TIM2. However the ETR and CH1 alternate functions both map to the same pin on TIM2. Further down in my code I had the following:

ocnt.TIM_OCMode             = TIM_OCMode_PWM1;
ocnt.TIM_Pulse              = activeVideoLineStart;
ocnt.TIM_OutputState        = TIM_OutputState_Enable;
ocnt.TIM_OutputNState       = TIM_OutputState_Disable;
ocnt.TIM_OCPolarity         = TIM_OCPolarity_High;
ocnt.TIM_OCIdleState        = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM2, &ocnt);

because I want to interrupt when TIM2->CNT exceeds a certain value. Because I set output state to Enabled, the pin for TIM2 OC1 (which happens to be the same pin as ETR) was being configured as an output which had the effect of pulling the pin low, and also pin PA0 which was connected to it.

To fix the problem it was enough to change the code to:

ocnt.TIM_OutputState        = TIM_OutputState_Disable;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.