no-OS
stm32_pwm.h
Go to the documentation of this file.
1 /***************************************************************************/
38 #ifndef STM32_PWM_H_
39 #define STM32_PWM_H_
40 
41 #include <stdint.h>
42 #include <stdbool.h>
43 #include "no_os_gpio.h"
44 #include "no_os_irq.h"
45 #include "stm32_gpio.h"
46 #include "stm32_hal.h"
47 
48 /******************************************************************************/
49 /***************************** Include Files **********************************/
50 /******************************************************************************/
51 
52 #include <stdbool.h>
53 
54 /******************************************************************************/
55 /********************** Macros and Constants Definitions **********************/
56 /******************************************************************************/
57 
58 /******************************************************************************/
59 /*************************** Types Declarations *******************************/
60 /******************************************************************************/
61 enum TimOCMode {
65 };
66 
73  uint32_t prescaler;
79  uint32_t timer_chn;
83  uint32_t (*get_timer_clock)(void);
85  uint32_t clock_divider;
88 };
89 
96  TIM_HandleTypeDef htimer;
100  uint32_t prescaler;
106  uint32_t timer_chn;
110  uint32_t (*get_timer_clock)(void);
112  uint32_t clock_divider;
117 };
118 
122 extern const struct no_os_pwm_platform_ops stm32_pwm_ops;
123 
124 #endif // STM32_PWM_H_
stm32_pwm_enable
int32_t stm32_pwm_enable(struct no_os_pwm_desc *desc)
Enable the PWM.
Definition: stm32_pwm.c:447
no_os_pwm_desc::duty_cycle_ns
uint32_t duty_cycle_ns
Definition: no_os_pwm.h:107
no_os_pwm_init_param
Structure containing the init parameters needed by the PWM generator.
Definition: no_os_pwm.h:72
stm32_pwm_init_param::timer_autoreload
bool timer_autoreload
Definition: stm32_pwm.h:75
stm32_pwm_init_param::mode
enum TimOCMode mode
Definition: stm32_pwm.h:77
stm32_pwm_set_duty_cycle
int32_t stm32_pwm_set_duty_cycle(struct no_os_pwm_desc *desc, uint32_t duty_cycle_ns)
Set the PWM duty cycle.
Definition: stm32_pwm.c:577
no_os_callback_desc
Structure describing a callback to be registered.
Definition: no_os_irq.h:148
stm32_pwm_get_period
int32_t stm32_pwm_get_period(struct no_os_pwm_desc *desc, uint32_t *period_ns)
Get the PWM period.
Definition: stm32_pwm.c:553
no_os_irq.h
Header file of IRQ interface.
no_os_irq_register_callback
int32_t no_os_irq_register_callback(struct no_os_irq_ctrl_desc *desc, uint32_t irq_id, struct no_os_callback_desc *callback_desc)
Register a callback to handle the irq events.
Definition: no_os_irq.c:98
PWM_DEFAULT_PERIOD
#define PWM_DEFAULT_PERIOD
Definition: stm32_pwm.c:52
no_os_pwm_desc::id
uint32_t id
Definition: no_os_pwm.h:103
stm32_pwm_disable
int32_t stm32_pwm_disable(struct no_os_pwm_desc *desc)
Disable the PWM.
Definition: stm32_pwm.c:483
no_os_pwm_init_param::period_ns
uint32_t period_ns
Definition: no_os_pwm.h:76
NO_OS_EVT_TIM_PWM_PULSE_FINISHED
@ NO_OS_EVT_TIM_PWM_PULSE_FINISHED
Definition: no_os_irq.h:75
stm32_pwm_desc::timer_callback
struct no_os_callback_desc timer_callback
Definition: stm32_pwm.h:116
stm32_pwm_desc::clock_divider
uint32_t clock_divider
Definition: stm32_pwm.h:112
no_os_pwm_desc::phase_ns
uint32_t phase_ns
Definition: no_os_pwm.h:109
stm32_pwm_init_param::clock_divider
uint32_t clock_divider
Definition: stm32_pwm.h:85
TIM_OC_PWM2
@ TIM_OC_PWM2
Definition: stm32_pwm.h:64
stm32_pwm_desc::nvic_tim
struct no_os_irq_ctrl_desc * nvic_tim
Definition: stm32_pwm.h:114
no_os_pwm_init_param::id
uint32_t id
Definition: no_os_pwm.h:74
stm32_pwm_desc::get_timer_clock
uint32_t(* get_timer_clock)(void)
Definition: stm32_pwm.h:110
no_os_callback_desc::peripheral
enum no_os_irq_peripheral peripheral
Definition: no_os_irq.h:156
no_os_pwm_desc::period_ns
uint32_t period_ns
Definition: no_os_pwm.h:105
stm32_pwm_init
int32_t stm32_pwm_init(struct no_os_pwm_desc **desc, const struct no_os_pwm_init_param *param)
Initialize the PWM.
Definition: stm32_pwm.c:341
TIM_OC_PWM1
@ TIM_OC_PWM1
Definition: stm32_pwm.h:63
no_os_pwm_desc::pwm_gpio
struct no_os_gpio_desc * pwm_gpio
Definition: no_os_pwm.h:115
no_os_pwm_init_param::irq_id
uint32_t irq_id
Definition: no_os_pwm.h:86
stm32_pwm_desc::timer_autoreload
bool timer_autoreload
Definition: stm32_pwm.h:102
stm32_pwm_init_param::timer_chn
uint32_t timer_chn
Definition: stm32_pwm.h:79
no_os_pwm_init_param::polarity
enum no_os_pwm_polarity polarity
Definition: no_os_pwm.h:82
stm32_irq.h
Header file for stm32 irq specifics.
no_os_callback_desc::ctx
void * ctx
Definition: no_os_irq.h:152
no_os_pwm_platform_ops::pwm_ops_init
int32_t(* pwm_ops_init)(struct no_os_pwm_desc **, const struct no_os_pwm_init_param *)
Definition: no_os_pwm.h:133
stm32_pwm_remove
int32_t stm32_pwm_remove(struct no_os_pwm_desc *desc)
Free the resources allocated by stm32_pwm_init()
Definition: stm32_pwm.c:401
stm32_pwm_ops
const struct no_os_pwm_platform_ops stm32_pwm_ops
STM32 platform specific PWM platform ops structure.
Definition: stm32_pwm.c:622
stm32_pwm_desc::htimer
TIM_HandleTypeDef htimer
Definition: stm32_pwm.h:96
no_os_pwm_desc::polarity
enum no_os_pwm_polarity polarity
Definition: no_os_pwm.h:111
no_os_irq_unregister_callback
int32_t no_os_irq_unregister_callback(struct no_os_irq_ctrl_desc *desc, uint32_t irq_id, struct no_os_callback_desc *callback_desc)
Unregisters a generic IRQ handling function.
Definition: no_os_irq.c:118
no_os_pwm_desc::irq_id
uint32_t irq_id
Definition: no_os_pwm.h:117
NO_OS_TIM_IRQ
@ NO_OS_TIM_IRQ
Definition: no_os_irq.h:94
NO_OS_CHN_TO_STM32_CHN
#define NO_OS_CHN_TO_STM32_CHN(x)
Definition: stm32_pwm.c:53
stm32_pwm_ops
const struct no_os_pwm_platform_ops stm32_pwm_ops
STM32 specific PWM platform ops structure.
Definition: stm32_pwm.c:622
no_os_irq_init_param::platform_ops
const struct no_os_irq_platform_ops * platform_ops
Definition: no_os_irq.h:117
stm32_pwm_init_param::complementary_channel
bool complementary_channel
Definition: stm32_pwm.h:81
stm32_irq_ops
const struct no_os_irq_platform_ops stm32_irq_ops
stm32 specific IRQ platform ops structure
Definition: stm32_irq.c:588
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:110
no_os_irq_ctrl_init
int32_t no_os_irq_ctrl_init(struct no_os_irq_ctrl_desc **desc, const struct no_os_irq_init_param *param)
Initialize the IRQ interrupts.
Definition: no_os_irq.c:51
stm32_pwm_desc::complementary_channel
bool complementary_channel
Definition: stm32_pwm.h:108
no_os_callback_desc::handle
void * handle
Definition: no_os_irq.h:158
no_os_pwm_init_param::extra
void * extra
Definition: no_os_pwm.h:92
no_os_callback_desc::callback
void(* callback)(void *context)
Definition: no_os_irq.h:150
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
stm32_pwm_get_duty_cycle
int32_t stm32_pwm_get_duty_cycle(struct no_os_pwm_desc *desc, uint32_t *duty_cycle_ns)
Get the PWM duty cycle.
Definition: stm32_pwm.c:611
NO_OS_PWM_POLARITY_HIGH
@ NO_OS_PWM_POLARITY_HIGH
Definition: no_os_pwm.h:63
no_os_pwm_init_param::pwm_callback
void(* pwm_callback)(void *arg)
Definition: no_os_pwm.h:88
no_os_pwm_desc
Structure representing an PWM generator device.
Definition: no_os_pwm.h:99
no_os_pwm_init_param::duty_cycle_ns
uint32_t duty_cycle_ns
Definition: no_os_pwm.h:78
TimOCMode
TimOCMode
Definition: stm32_pwm.h:61
no_os_pwm_platform_ops
Structure holding PWM function pointers that point to the platform specific function.
Definition: no_os_pwm.h:131
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:55
no_os_callback_desc::event
enum no_os_irq_event event
Definition: no_os_irq.h:154
no_os_pwm.h
Header file of PWM Interface.
no_os_pwm_desc::extra
void * extra
Definition: no_os_pwm.h:123
stm32_gpio.h
Header file for stm32 gpio specifics.
FREQUENCY_HZ_TO_TIME_NS_FACTOR
#define FREQUENCY_HZ_TO_TIME_NS_FACTOR
Definition: stm32_pwm.c:54
no_os_pwm_desc::pwm_callback
void(* pwm_callback)(void *arg)
Definition: no_os_pwm.h:119
no_os_pwm_init_param::pwm_gpio
struct no_os_gpio_init_param * pwm_gpio
Definition: no_os_pwm.h:84
NULL
#define NULL
Definition: wrapper.h:64
no_os_irq_init_param
Structure holding the initial parameters for Interrupt Request.
Definition: no_os_irq.h:113
no_os_irq_ctrl_remove
int32_t no_os_irq_ctrl_remove(struct no_os_irq_ctrl_desc *desc)
Free the resources allocated by no_os_irq_ctrl_init().
Definition: no_os_irq.c:77
stm32_pwm_desc::mode
enum TimOCMode mode
Definition: stm32_pwm.h:104
no_os_irq_enable
int32_t no_os_irq_enable(struct no_os_irq_ctrl_desc *desc, uint32_t irq_id)
Enable specific interrupt.
Definition: no_os_irq.c:187
stm32_pwm_init_param
Structure holding the STM32 PWM parameters.
Definition: stm32_pwm.h:71
no_os_pwm_init_param::phase_ns
uint32_t phase_ns
Definition: no_os_pwm.h:80
no_os_gpio.h
Header file of GPIO Interface.
stm32_pwm_init_param::get_timer_clock
uint32_t(* get_timer_clock)(void)
Definition: stm32_pwm.h:83
stm32_pwm_init_param::prescaler
uint32_t prescaler
Definition: stm32_pwm.h:73
stm32_pwm_desc::prescaler
uint32_t prescaler
Definition: stm32_pwm.h:100
stm32_pwm_desc::timer_chn
uint32_t timer_chn
Definition: stm32_pwm.h:106
stm32_pwm_desc
Structure holding the STM32 PWM descriptor.
Definition: stm32_pwm.h:94
no_os_util.h
Header file of utility functions.
NO_OS_PWM_POLARITY_LOW
@ NO_OS_PWM_POLARITY_LOW
Definition: no_os_pwm.h:65
stm32_pwm_desc::gpio
struct no_os_gpio_desc * gpio
Definition: stm32_pwm.h:98
stm32_pwm_init_param::timer_callback
struct no_os_callback_desc timer_callback
Definition: stm32_pwm.h:87
no_os_irq_disable
int32_t no_os_irq_disable(struct no_os_irq_ctrl_desc *desc, uint32_t irq_id)
Disable specific interrupt.
Definition: no_os_irq.c:204
no_os_irq_ctrl_desc
Definition: no_os_irq.h:129
stm32_hal.h
errno.h
Error macro definition for ARM Compiler.
TIM_OC_TOGGLE
@ TIM_OC_TOGGLE
Definition: stm32_pwm.h:62
stm32_pwm.h
Implementation of stm32 pwm driver.
stm32_pwm_set_period
int32_t stm32_pwm_set_period(struct no_os_pwm_desc *desc, uint32_t period_ns)
Set the PWM period.
Definition: stm32_pwm.c:512