2025-12-02 7:29 AM - last edited on 2025-12-02 8:55 AM by mƎALLEm
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.
Solved! Go to Solution.
2025-12-02 8:16 AM
@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.
2025-12-02 7:38 AM - edited 2025-12-02 7:38 AM
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.
2025-12-02 7:45 AM
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:
You can inspire from it.
2025-12-02 7:52 AM
I am using STM32F103C8T6.
2025-12-02 7:54 AM
So you can inspire from this example for STM32F1:
2025-12-02 7:58 AM
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
2025-12-02 8:07 AM
2025-12-02 8:16 AM
@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.
2025-12-02 8:26 AM - edited 2025-12-02 8:28 AM
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
2025-12-02 8:27 AM
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?