Skip to main content
VMoca.1
Associate II
January 20, 2020
Solved

Hello, I am working with a STM32F769 EVAL board and I want to make a 20kHz PWM using DMA. The issue I have is that I cannot start-up the timer for a GPIO. I do not find in the docs this information. Do you have an example made for this PWM on GPIO?

  • January 20, 2020
  • 7 replies
  • 1889 views

..

This topic has been closed for replies.
Best answer by Mike_ST

period and pulse are not initialized.

void PWM_Timer_Init(void)

{

   /* Enable TIM3 clock */

   __HAL_RCC_TIM3_CLK_ENABLE();

   /* Configuration for TIM3 */

   ConfTimer.Instance = TIM3;

   ConfTimer.Init.Prescaler = 215U;

   ConfTimer.Init.CounterMode = TIM_COUNTERMODE_UP;

   ConfTimer.Init.Period = 999U; //(1000000U / 1000U) - 1U;

   ConfTimer.Init.ClockDivision = 0U; /* no divider */

   ConfTimer.Init.RepetitionCounter = 0U;

   ConfTimer.Init.AutoReloadPreload = 0U; /* disabled */

   //ConfTimer.Channel = TIM_CHANNEL_2;

   if (HAL_TIM_PWM_Init(&ConfTimer) != HAL_OK)

   {

      Error_Handler();

   }

   sConfigOC.OCMode = TIM_OCMODE_PWM1;

   sConfigOC.Pulse = 499U;

   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

   //sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

   sConfigOC.OCNIdleState = TIM_OCIDLESTATE_SET;

   sConfigOC.OCNIdleState= TIM_OCNIDLESTATE_RESET;

   if (HAL_TIM_PWM_ConfigChannel(&ConfTimer, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

   {

      Error_Handler();

   }

   //HAL_TIM_Base_Start(&ConfTimer);

}

7 replies

KnarfB
Super User
January 20, 2020

A lot of samples come with the STM32Cube firmware (drivers). See your %USERPROFILE%\STM32Cube\Repository folder (Windows) or online: https://github.com/STMicroelectronics/STM32CubeF7/tree/master/Projects. I don't get the idea what you want to do

  1. regular PWM output by a timer (no DMA)
  2. timer PWM pulsewidth modulation by DMA
  3. periodic, timer triggered, DMA output from a memory buffer to a GPIO port

What tools, OS, HAL, LL, register level,...

VMoca.1
VMoca.1Author
Associate II
January 20, 2020

Thank you for your fast reply. I have generated the code just that there is no information about which TIMx module can be used for which GPIOx pin. I want to use TIM3_CH2 with PB5 and the timer does not start.

VMoca.1
VMoca.1Author
Associate II
January 20, 2020

I attach here the files.

Mike_ST
Technical Moderator
January 20, 2020

Edit, didn't see all code.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
berendi
Principal
January 20, 2020

You are perhaps looking for the alternate function mapping table, which can be found at the end of chapter 3 in the datasheet.

VMoca.1
VMoca.1Author
Associate II
January 20, 2020

Yes, exactly. I have RM0410

"Reference manual STM32F76xxx and STM32F77xxx advanced Arm®-based 32-bit MCUs" RM0410 Rev 4 pdf and in chapter 3 there is the FLASH registers. Could you give me a link of the file you refer to? Thank you.

Mike_ST
Technical Moderator
January 20, 2020

Please try Document DS11532 Table 13 in section 3

https://www.st.com/resource/en/datasheet/stm32f765bg.pdf

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
VMoca.1
VMoca.1Author
Associate II
January 21, 2020

Thank you, I have tried with the new file, for PB5 I need TIM3 Channel 2. It still does not work. Can you please look at the code and see what I am doing wrong?

I have added also the main.c

I have started from a FreeRTOS timer example and added the PWM.c and PWM.h attached.

Mike_ST
Mike_STBest answer
Technical Moderator
January 21, 2020

period and pulse are not initialized.

void PWM_Timer_Init(void)

{

   /* Enable TIM3 clock */

   __HAL_RCC_TIM3_CLK_ENABLE();

   /* Configuration for TIM3 */

   ConfTimer.Instance = TIM3;

   ConfTimer.Init.Prescaler = 215U;

   ConfTimer.Init.CounterMode = TIM_COUNTERMODE_UP;

   ConfTimer.Init.Period = 999U; //(1000000U / 1000U) - 1U;

   ConfTimer.Init.ClockDivision = 0U; /* no divider */

   ConfTimer.Init.RepetitionCounter = 0U;

   ConfTimer.Init.AutoReloadPreload = 0U; /* disabled */

   //ConfTimer.Channel = TIM_CHANNEL_2;

   if (HAL_TIM_PWM_Init(&ConfTimer) != HAL_OK)

   {

      Error_Handler();

   }

   sConfigOC.OCMode = TIM_OCMODE_PWM1;

   sConfigOC.Pulse = 499U;

   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

   //sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

   sConfigOC.OCNIdleState = TIM_OCIDLESTATE_SET;

   sConfigOC.OCNIdleState= TIM_OCNIDLESTATE_RESET;

   if (HAL_TIM_PWM_ConfigChannel(&ConfTimer, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

   {

      Error_Handler();

   }

   //HAL_TIM_Base_Start(&ConfTimer);

}

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
VMoca.1
VMoca.1Author
Associate II
January 21, 2020

Thank you Mike, that was the issue. :)