PWM driver implementation for STM32F4 series (Cortex-M4) More...
#include "core/cortex-m4/pwm.h"#include "core/cortex-m4/clock.h"#include "core/cortex-m4/timer.h"#include <stdint.h>
Functions | |
| void | hal_pwm_init (PWM_Handle *pwm, uint32_t frequency, float dutyCycle) |
| Initialize PWM with specified frequency and duty cycle. | |
| void | hal_pwm_start (PWM_Handle *pwm) |
| Start PWM output. | |
| void | hal_pwm_stop (PWM_Handle *pwm) |
| Stop PWM output. | |
| void | hal_pwm_set_duty_cycle (PWM_Handle *pwm, float dutyCycle) |
| Set PWM duty cycle. | |
| void | hal_pwm_set_frequency (PWM_Handle *pwm, uint32_t frequency) |
| Set PWM frequency (not implemented) | |
PWM driver implementation for STM32F4 series (Cortex-M4)
This file provides Pulse Width Modulation (PWM) functionality for STM32F4 microcontrollers. It supports:
The implementation uses the STM32 timer peripherals to generate precise PWM signals with minimal CPU overhead.
| void hal_pwm_init | ( | PWM_Handle * | pwm, |
| uint32_t | frequency, | ||
| float | dutyCycle ) |
Initialize PWM with specified frequency and duty cycle.
Initialize a PWM handle with the specified frequency and duty cycle.
| [in,out] | pwm | Pointer to PWM handle structure |
| [in] | frequency | Desired PWM frequency in Hz |
| [in] | dutyCycle | Initial duty cycle (0.0 to 1.0) |
Configures the timer peripheral to generate PWM signals by:
| void hal_pwm_set_duty_cycle | ( | PWM_Handle * | pwm, |
| float | dutyCycle ) |
Set PWM duty cycle.
Set the PWM duty cycle.
| [in,out] | pwm | Pointer to PWM handle structure |
| [in] | dutyCycle | New duty cycle (0.0 to 1.0) |
Updates the capture/compare register to change the PWM duty cycle while maintaining the current frequency. The change takes effect immediately on the output.
| void hal_pwm_set_frequency | ( | PWM_Handle * | pwm, |
| uint32_t | frequency ) |
Set PWM frequency (not implemented)
Set the PWM frequency.
| [in,out] | pwm | Pointer to PWM handle structure |
| [in] | frequency | Desired PWM frequency in Hz |
| void hal_pwm_start | ( | PWM_Handle * | pwm | ) |
Start PWM output.
Start PWM signal generation.
| [in] | pwm | Pointer to initialized PWM handle structure |
Enables the timer counter to start generating PWM signals on the configured channel. The output will appear on the corresponding GPIO pin.
| void hal_pwm_stop | ( | PWM_Handle * | pwm | ) |
Stop PWM output.
Stop PWM signal generation.
| [in] | pwm | Pointer to PWM handle structure |
Disables the timer channel output and stops the timer counter. The PWM output pin will return to its idle state.