cancel
Showing results for 
Search instead for 
Did you mean: 

Porting X-Nucleo-LED16A1 to Nucleo-F429ZI question concerning TIM1

Kevin Flanagan
Associate II
Posted on January 26, 2018 at 22:47

Hello,

I am trying to port the ST provided Nucleo-F401RE X-Nucleo-LED16A1 example code to the Nucleo-F429ZI and am running into issues getting the PWM signal out. 

I do not have a good understand of the advance timer functions on MCU and am looking for some help. 

The F401RE TIM2 CH3 maps out to CN9 D6 on PB10. The equivalent pin on the F429ZI is PE9.

If I understand this correctly, the F401RE this function is TIM2 CH3 coming out of PB10. On the F429ZI, this should map out to TIM1 CH1(?) on PE9. 

On the F401RE the init code is:

/* TIM2 init function */

void TIM2_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

TIM_ClockConfigTypeDef sClockSourceConfig;

TIM_MasterConfigTypeDef sMasterConfig;

TIM_OC_InitTypeDef sConfigOC;

/* Peripheral clock enable */

__TIM2_CLK_ENABLE();

/**TIM2 GPIO Configuration

PB10 ------> TIM2_CH3*/

GPIO_InitStruct.Pin = GPIO_PIN_10;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

htim2.Instance = TIM2;

htim2.Init.Prescaler = 0;

htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

htim2.Init.Period = 0x02;

htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

HAL_TIM_Base_Init(&htim2);

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);

HAL_TIM_PWM_Init(&htim2);

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);

sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = 0x01;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3);

HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_3);

}

The F429ZI equivalent code should be:

/* TIM1 init function */

void TIM1_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

TIM_ClockConfigTypeDef sClockSourceConfig;

TIM_MasterConfigTypeDef sMasterConfig;

TIM_OC_InitTypeDef sConfigOC;

/* Peripheral clock enable */

__TIM1_CLK_ENABLE();

/**TIM1 GPIO Configuration

PE9 ------> TIM1_CH1*/

GPIO_InitStruct.Pin = GPIO_PIN_9;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;

HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

htim2.Instance = TIM1;

htim2.Init.Prescaler = 0;

htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

htim2.Init.Period = 0x02;

htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

HAL_TIM_Base_Init(&htim2);

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);

HAL_TIM_PWM_Init(&htim2);

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);

sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = 0x01;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_1);

}

But on the scope I get no pulses out of the F429zi. I did manage to get pulse equivalents on the SPI and LE pins. Just not the timer/PWM pin. 

Does anyone have some thoughts where I should start digging? Might an IRQ handler be needed or, is this an entirely hardware based timer? Can something, like and SPI configuration be interfering with this timer?

Thank's in advance for any help provided.

-Kevin Flanagan

2 REPLIES 2
Clive1 (HNL)
Senior II
Posted on January 26, 2018 at 23:01

TIM1 has more functionality, being 'advanced'

TIM_OC_InitTypeDef sConfigOC = { 0 }; // Clear ALL fields, especially ones you're not using/initializing otherwise

 

htim2.Init.RepetitionCounter = 0; // perhaps also use TIM specific instances

 

Posted on January 26, 2018 at 23:06

Will give it a try when I get home this evening, thanks!