cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Timer Function library

ankhola
Visitor

Hi Guys, I am completely new in the world of ST Microcontroller. I have worked with PIC Microcontrollers using MikroC Compiler. After studying various tutorials on this topic, I am getting it slowly. While going through  code of generation of PWM, I came across a function " HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);" which, I assume, starts PWM. My question, Is it a library function? If so, how can it be accessed. Incidentally it is stated that I have installed STM32 CubeMX and STM32 Cube IDE.

1 ACCEPTED SOLUTION

Accepted Solutions

@ankhola in next time please use </> button to share the code.

CubeMx doesn't implement your all application. It only generates the code to initialize the peripherals and HAL_TIM_PWM_Start() is not part of the generated code.

You need to add it manually in between /* USER CODE BEGIN xxx */ and /* USER CODE END xxx */ in the main().

So you need to generate the code with CubeMx: configure the timer in PWM output and add manually the needed code by inspiring from the example I provided above.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

16 REPLIES 16
TDK
Super User

It's in the HAL library which is open source and included when you generate code with STM32CubeMX.

Recommended starting point would be to download STM32CubeMX, generate a project for STM32CubeIDEt or load an example, and open that project in STM32CubeIDE. Intellisense and "go to definition" can be used to look up functions.

https://github.com/STMicroelectronics/stm32f4xx-hal-driver/blob/b5c4d27f41c0ffbde135c0560d882b8a8eecb88e/Src/stm32f4xx_hal_tim.c#L1454

 

If you feel a post has answered your question, please click "Accept as Solution".
mƎALLEm
ST Employee

Hello @ankhola and welcome to the ST community,

Yes it's a library API.

You didn't tell which STM32 you are using and this is an example for PWM generation on STM32F4:

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM324xG_EVAL/Examples/TIM/TIM_PWMOutput

You can inspire from it.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I am using STM32F103C8T6.

So you can inspire from this example for STM32F1:

https://github.com/STMicroelectronics/STM32CubeF1/tree/master/Projects/STM3210E_EVAL/Examples/TIM/TIM_PWMOutput

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
mfgkw
Senior II

For each STM MCU family there is document UMxxx where the HAL API is described, a list can be found here: https://www.st.com/content/st_com/en/search.html#q=hal%20user%20manual%20description%20of%20STM32-t=resources-page=1

 

In case of your STM32F103C8T6 it is "UM1850 Description of STM32F1 HAL and low-layer drivers": https://www.st.com/content/ccc/resource/technical/document/user_manual/72/52/cc/53/05/e3/4c/98/DM00154093.pdf/files/DM00154093.pdf/jcr:content/translations/en.DM00154093.pdf

Yes, I have generated a code using STM32CubeMX. Please see the screenshot. But this function is not seen anywhere in IDE. 

@ankhola in next time please use </> button to share the code.

CubeMx doesn't implement your all application. It only generates the code to initialize the peripherals and HAL_TIM_PWM_Start() is not part of the generated code.

You need to add it manually in between /* USER CODE BEGIN xxx */ and /* USER CODE END xxx */ in the main().

So you need to generate the code with CubeMx: configure the timer in PWM output and add manually the needed code by inspiring from the example I provided above.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Peter BENSCH
ST Employee

@ankhola 

But if something isn't working as you expect, you should check carefully whether your STM32F103C8T6 is a genuine device – there are illegal clones available from a number of Asian manufacturers. Of course, STMicroelectronics does not support them, nor can you expect them to comply with specifications of STMicroelectronics. In such cases, you should contact the counterfeiter in question. See e.g. threads like here or there (and many more here in the community).

The same applies to the debugger, for which there are illegally copied ST-LINK/V2 devices. Again, don't be surprised if they don't work as expected. For this topic see e.g. the thread How to recognize a genuine ST-LINK/V2 versus a cloned one.

To save frustration and, above all, time, I highly recommend using original products. The few extra pounds/dollars/your local currency will ensure a relaxed development process and allow you to concentrate on real problems.

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I shall adhere to the system of sharing code. I got the issue. So, for such functions, I shall have to go through the examples. Right?