Skip to main content
Visitor II
December 2, 2025
Solved

STM32 Timer Function library

  • December 2, 2025
  • 4 replies
  • 547 views

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.

    This topic has been closed for replies.
    Best answer by mƎALLEm

    @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.

    4 replies

    Super User
    December 2, 2025

    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

     

    ankholaAuthor
    Visitor II
    December 2, 2025

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

    mƎALLEmAnswer
    Technical Moderator
    December 2, 2025

    @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.

    Technical Moderator
    December 2, 2025

    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.

    ankholaAuthor
    Visitor II
    December 2, 2025

    I am using STM32F103C8T6.

    Technical Moderator
    December 2, 2025
    Graduate II
    December 2, 2025

    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

    ankholaAuthor
    Visitor II
    December 2, 2025

    I have downloaded the UM. Yes, I have found the functions there. Thanks.

    Technical Moderator
    December 2, 2025

    @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