AnsweredAssumed Answered

STM32F4xx Use of ETRF Input Pin to Gate PWM

Question asked by MehmoodN on Jan 23, 2015
Latest reply on Jan 26, 2015 by MehmoodN
Hello,

I am new to this forum and have migrated from Freescale to STM32 based projects.  I am implementing a switched mode power supply (SMPS) on the STM32F4Discovery board.  I have successfully configured PB0 as a PWM output using TIM1_CH2N.  Based on the information in the RM0090 Reference Manual (p.538) an external signal applied to the ETRF pin (PA12) can be used to gate the PWM output.  On the Discovery board this is used by the OTG connector.  However, I rigged up a USB cable to assert a signal on PA12 and verified its operation by configuring it as a GPIO.  Based on the code below does anyone know what I have done wrong since the ETRF does not seem to be gating the PWM?

Thanks in advance!

01.    GPIO_InitTypeDef GPIO_InitStructure;
02. 
03.    /* GPIOB Clocks enable */
04.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
05. 
06.    /* GPIOB Configuration: Channel 2N as alternate function push-pull */
07.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
08.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
09.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
10.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
11.    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
12.    GPIO_Init(GPIOB, &GPIO_InitStructure);
13.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_TIM1);
14. 
15.    /* GPIOA Clocks enable */
16.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
17. 
18.    /* Configure ETR for current control */
19.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
20.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
21.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
22.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
23.    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
24.    GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_EVENTOUT);
25.    GPIO_Init(GPIOA, &GPIO_InitStructure);
26. 
27.        /* Compute the value to be set in ARR regiter to generate signal frequency at 1MHZ */
28.    TimerPeriod = (SystemCoreClock / 1000000) - 1;
29. 
30.    /* Compute CCR2 value to generate a duty cycle at 66.667%  for channel 2 and 2N */
31.    Channel2Pulse = (uint16_t) (((uint32_t) 666 * (TimerPeriod - 1)) / 1000);
32. 
33.    /* TIM1 clock enable */
34.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
35. 
36.    /* Time Base configuration */
37.    TIM_TimeBaseStructure.TIM_Prescaler = 0;
38.    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
39.    TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
40.    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
41.    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
42.    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
43. 
44.    /* Channel 2 Configuration in PWM mode */
45.    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
46.    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
47.    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
48.    TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;
49.    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
50.    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
51.    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
52.    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
53.    TIM_OC2Init(TIM1, &TIM_OCInitStructure);
54. 
55.    /* Configure ETR for current control */
56.    TIM_ETRConfig(TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);
57.    TIM_ClearOC2Ref(TIM1, TIM_OCClear_Enable);
58.}

Outcomes