cancel
Showing results for 
Search instead for 
Did you mean: 

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?

VMoca.1
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions

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);

}

View solution in original post

11 REPLIES 11
KnarfB
Principal III

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
Associate II

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
Associate II

I attach here the files.

Edit, didn't see all code.

berendi
Principal

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
Associate II

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.

Please try Document DS11532 Table 13 in section 3

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

chapter 3 in the datasheet, not the reference manual. It should be downloadable from the MCU product page on the ST website.

VMoca.1
Associate II

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.