no-OS
stm32_pwm.h
Go to the documentation of this file.
1 /***************************************************************************/
32 #ifndef STM32_PWM_H_
33 #define STM32_PWM_H_
34 
35 #include <stdint.h>
36 #include <stdbool.h>
37 #include "no_os_gpio.h"
38 #include "no_os_irq.h"
39 #include "stm32_gpio.h"
40 #include "stm32_hal.h"
41 
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 
46 #include <stdbool.h>
47 
48 /******************************************************************************/
49 /********************** Macros and Constants Definitions **********************/
50 /******************************************************************************/
51 
52 /******************************************************************************/
53 /*************************** Types Declarations *******************************/
54 /******************************************************************************/
55 enum TimOCMode {
59 };
60 
66 };
67 
77 };
84  uint32_t prescaler;
90  uint32_t timer_chn;
94  uint32_t (*get_timer_clock)(void);
96  uint32_t clock_divider;
103  /* Enable one pulse */
105  /* Number of pulse repetitions */
106  uint32_t repetitions;
107  /* Enable dma */
111 };
112 
119  TIM_HandleTypeDef htimer;
123  uint32_t prescaler;
129  uint32_t timer_chn;
133  uint32_t (*get_timer_clock)(void);
135  uint32_t clock_divider;
140  /* Number of pulse repetitions */
141  uint32_t repetitions;
142  /* Enable dma */
144 };
145 
149 extern const struct no_os_pwm_platform_ops stm32_pwm_ops;
150 
151 #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:509
no_os_pwm_desc::duty_cycle_ns
uint32_t duty_cycle_ns
Definition: no_os_pwm.h:101
no_os_pwm_init_param
Structure containing the init parameters needed by the PWM generator.
Definition: no_os_pwm.h:66
stm32_pwm_init_param::timer_autoreload
bool timer_autoreload
Definition: stm32_pwm.h:86
PWM_TRGO_ENABLE
@ PWM_TRGO_ENABLE
Definition: stm32_pwm.h:70
stm32_pwm_init_param::mode
enum TimOCMode mode
Definition: stm32_pwm.h:88
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:664
no_os_callback_desc
Structure describing a callback to be registered.
Definition: no_os_irq.h:142
stm32_pwm_init_param::repetitions
uint32_t repetitions
Definition: stm32_pwm.h:106
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:640
stm32_pwm_init_param::trigger_output
enum stm32_pwm_trigger_out trigger_output
Definition: stm32_pwm.h:102
PWM_TRGO_UPDATE
@ PWM_TRGO_UPDATE
Definition: stm32_pwm.h:71
no_os_irq.h
Header file of IRQ interface.
PWM_TRGO_OC3REF
@ PWM_TRGO_OC3REF
Definition: stm32_pwm.h:75
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:92
stm32_pwm_desc::repetitions
uint32_t repetitions
Definition: stm32_pwm.h:141
PWM_DEFAULT_PERIOD
#define PWM_DEFAULT_PERIOD
Definition: stm32_pwm.c:46
no_os_pwm_desc::id
uint32_t id
Definition: no_os_pwm.h:97
stm32_pwm_init_param::trigger_source
enum stm32_pwm_trigger trigger_source
Definition: stm32_pwm.h:100
stm32_pwm_disable
int32_t stm32_pwm_disable(struct no_os_pwm_desc *desc)
Disable the PWM.
Definition: stm32_pwm.c:561
no_os_pwm_init_param::period_ns
uint32_t period_ns
Definition: no_os_pwm.h:70
stm32_pwm_trigger
stm32_pwm_trigger
Definition: stm32_pwm.h:61
NO_OS_EVT_TIM_PWM_PULSE_FINISHED
@ NO_OS_EVT_TIM_PWM_PULSE_FINISHED
Definition: no_os_irq.h:69
stm32_pwm_desc::timer_callback
struct no_os_callback_desc timer_callback
Definition: stm32_pwm.h:139
stm32_pwm_desc::clock_divider
uint32_t clock_divider
Definition: stm32_pwm.h:135
no_os_pwm_desc::phase_ns
uint32_t phase_ns
Definition: no_os_pwm.h:103
stm32_pwm_init_param::clock_divider
uint32_t clock_divider
Definition: stm32_pwm.h:96
TIM_OC_PWM2
@ TIM_OC_PWM2
Definition: stm32_pwm.h:58
stm32_pwm_desc::nvic_tim
struct no_os_irq_ctrl_desc * nvic_tim
Definition: stm32_pwm.h:137
no_os_pwm_init_param::id
uint32_t id
Definition: no_os_pwm.h:68
stm32_pwm_desc::get_timer_clock
uint32_t(* get_timer_clock)(void)
Definition: stm32_pwm.h:133
no_os_callback_desc::peripheral
enum no_os_irq_peripheral peripheral
Definition: no_os_irq.h:150
no_os_pwm_desc::period_ns
uint32_t period_ns
Definition: no_os_pwm.h:99
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:403
PWM_TRGO_OC4REF
@ PWM_TRGO_OC4REF
Definition: stm32_pwm.h:76
PWM_TRGO_OC2REF
@ PWM_TRGO_OC2REF
Definition: stm32_pwm.h:74
TIM_OC_PWM1
@ TIM_OC_PWM1
Definition: stm32_pwm.h:57
no_os_pwm_desc::pwm_gpio
struct no_os_gpio_desc * pwm_gpio
Definition: no_os_pwm.h:109
PWM_TRGO_OC1REF
@ PWM_TRGO_OC1REF
Definition: stm32_pwm.h:73
no_os_pwm_init_param::irq_id
uint32_t irq_id
Definition: no_os_pwm.h:80
stm32_pwm_desc::timer_autoreload
bool timer_autoreload
Definition: stm32_pwm.h:125
stm32_pwm_init_param::timer_chn
uint32_t timer_chn
Definition: stm32_pwm.h:90
no_os_pwm_init_param::polarity
enum no_os_pwm_polarity polarity
Definition: no_os_pwm.h:76
stm32_irq.h
Header file for stm32 irq specifics.
PWM_TRGO_RESET
@ PWM_TRGO_RESET
Definition: stm32_pwm.h:69
no_os_callback_desc::ctx
void * ctx
Definition: no_os_irq.h:146
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:127
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:463
stm32_pwm_ops
const struct no_os_pwm_platform_ops stm32_pwm_ops
STM32 platform specific PWM platform ops structure.
Definition: stm32_pwm.c:709
stm32_pwm_desc::htimer
TIM_HandleTypeDef htimer
Definition: stm32_pwm.h:119
no_os_pwm_desc::polarity
enum no_os_pwm_polarity polarity
Definition: no_os_pwm.h:105
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:112
no_os_pwm_desc::irq_id
uint32_t irq_id
Definition: no_os_pwm.h:111
NO_OS_TIM_IRQ
@ NO_OS_TIM_IRQ
Definition: no_os_irq.h:88
NO_OS_CHN_TO_STM32_CHN
#define NO_OS_CHN_TO_STM32_CHN(x)
Definition: stm32_pwm.c:47
stm32_pwm_ops
const struct no_os_pwm_platform_ops stm32_pwm_ops
STM32 specific PWM platform ops structure.
Definition: stm32_pwm.c:709
stm32_pwm_init_param::onepulse_enable
bool onepulse_enable
Definition: stm32_pwm.h:104
PWM_TS_ITR1
@ PWM_TS_ITR1
Definition: stm32_pwm.h:63
no_os_irq_init_param::platform_ops
const struct no_os_irq_platform_ops * platform_ops
Definition: no_os_irq.h:111
stm32_pwm_init_param::complementary_channel
bool complementary_channel
Definition: stm32_pwm.h:92
stm32_irq_ops
const struct no_os_irq_platform_ops stm32_irq_ops
stm32 specific IRQ platform ops structure
Definition: stm32_irq.c:582
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:104
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:45
stm32_pwm_desc::complementary_channel
bool complementary_channel
Definition: stm32_pwm.h:131
no_os_callback_desc::handle
void * handle
Definition: no_os_irq.h:152
no_os_pwm_init_param::extra
void * extra
Definition: no_os_pwm.h:86
no_os_callback_desc::callback
void(* callback)(void *context)
Definition: no_os_irq.h:144
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
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:698
NO_OS_PWM_POLARITY_HIGH
@ NO_OS_PWM_POLARITY_HIGH
Definition: no_os_pwm.h:57
no_os_pwm_init_param::pwm_callback
void(* pwm_callback)(void *arg)
Definition: no_os_pwm.h:82
no_os_pwm_desc
Structure representing an PWM generator device.
Definition: no_os_pwm.h:93
no_os_pwm_init_param::duty_cycle_ns
uint32_t duty_cycle_ns
Definition: no_os_pwm.h:72
TimOCMode
TimOCMode
Definition: stm32_pwm.h:55
stm32_pwm_init_param::dma_enable
bool dma_enable
Definition: stm32_pwm.h:108
no_os_pwm_platform_ops
Structure holding PWM function pointers that point to the platform specific function.
Definition: no_os_pwm.h:125
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:49
no_os_callback_desc::event
enum no_os_irq_event event
Definition: no_os_irq.h:148
PWM_TS_ITR3
@ PWM_TS_ITR3
Definition: stm32_pwm.h:65
no_os_pwm.h
Header file of PWM Interface.
no_os_pwm_desc::extra
void * extra
Definition: no_os_pwm.h:117
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:48
no_os_pwm_desc::pwm_callback
void(* pwm_callback)(void *arg)
Definition: no_os_pwm.h:113
no_os_pwm_init_param::pwm_gpio
struct no_os_gpio_init_param * pwm_gpio
Definition: no_os_pwm.h:78
NULL
#define NULL
Definition: wrapper.h:64
stm32_pwm_init_param::trigger_enable
bool trigger_enable
Definition: stm32_pwm.h:98
PWM_TS_ITR0
@ PWM_TS_ITR0
Definition: stm32_pwm.h:62
no_os_irq_init_param
Structure holding the initial parameters for Interrupt Request.
Definition: no_os_irq.h:107
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:71
stm32_pwm_desc::dma_enable
bool dma_enable
Definition: stm32_pwm.h:143
stm32_pwm_desc::mode
enum TimOCMode mode
Definition: stm32_pwm.h:127
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:181
stm32_pwm_init_param
Structure holding the STM32 PWM parameters.
Definition: stm32_pwm.h:82
no_os_pwm_init_param::phase_ns
uint32_t phase_ns
Definition: no_os_pwm.h:74
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:94
PWM_TS_ITR2
@ PWM_TS_ITR2
Definition: stm32_pwm.h:64
stm32_pwm_init_param::prescaler
uint32_t prescaler
Definition: stm32_pwm.h:84
stm32_pwm_desc::prescaler
uint32_t prescaler
Definition: stm32_pwm.h:123
stm32_pwm_desc::timer_chn
uint32_t timer_chn
Definition: stm32_pwm.h:129
stm32_pwm_desc
Structure holding the STM32 PWM descriptor.
Definition: stm32_pwm.h:117
no_os_util.h
Header file of utility functions.
NO_OS_PWM_POLARITY_LOW
@ NO_OS_PWM_POLARITY_LOW
Definition: no_os_pwm.h:59
stm32_pwm_desc::gpio
struct no_os_gpio_desc * gpio
Definition: stm32_pwm.h:121
stm32_pwm_init_param::timer_callback
struct no_os_callback_desc timer_callback
Definition: stm32_pwm.h:110
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:198
no_os_irq_ctrl_desc
Definition: no_os_irq.h:123
stm32_hal.h
stm32_pwm_trigger_out
stm32_pwm_trigger_out
Definition: stm32_pwm.h:68
errno.h
Error macro definition for ARM Compiler.
PWM_TRGO_OC1
@ PWM_TRGO_OC1
Definition: stm32_pwm.h:72
TIM_OC_TOGGLE
@ TIM_OC_TOGGLE
Definition: stm32_pwm.h:56
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:599