20 Commonly Used STM32 MCU Library Functions

The development of STM32 microcontrollers relies heavily on their powerful library function support. These library functions provide developers with a unified interface, simplifying the operation of low-level hardware, improving development efficiency and the reliability of programs. Below we will share 20 commonly used library functions for STM32 microcontrollers.

20 Commonly Used STM32 MCU Library Functions

1. GPIO Initialization Function

void HAL_GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);

2. GPIO Pin Output Level Setting Function

void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

3. GPIO Pin Level Toggle Function

void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

4. GPIO Pin Level Read Function

GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

5. Delay Function

void HAL_Delay(uint32_t Delay);

6. Timer Interrupt Callback Function

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);

7. Timer Start Interrupt Mode Function

HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);

8. PWM Signal Start Function

HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);

9. PWM Duty Cycle Modification Function

__HAL_TIM_SetCompare(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t Compare);

10. Timer Enable Function

void __HAL_TIM_ENABLE(TIM_HandleTypeDef *htim);

11. Timer Disable Function

void __HAL_TIM_DISABLE(TIM_HandleTypeDef *htim);

12. Serial Port Send Data Function

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

13. Serial Port Receive Data Function

HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

14. Serial Port Interrupt Mode Send Data Function

HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);

15. Serial Port Interrupt Mode Receive Data Function

HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);

16. Get Current Milliseconds Function

uint32_t HAL_GetTick(void);

17. External Interrupt Initialization Function

void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);

18. External Interrupt Callback Function

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);

19. ADC Start Function

HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);

20. Watchdog Enable Function

void IWDG_Enable(void); // For Independent Watchdog

void WWDG_Enable(void); // For Window Watchdog

This article is an original piece by Fan Yi Education, please indicate the source when reprinting!

Leave a Comment