no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stm32_pwm.c File Reference

Implementation of stm32 pwm driver. More...

#include <stdlib.h>
#include <errno.h>
#include "no_os_util.h"
#include "no_os_gpio.h"
#include "no_os_pwm.h"
#include "stm32_gpio.h"
#include "stm32_pwm.h"
#include "stm32_irq.h"
Include dependency graph for stm32_pwm.c:

Macros

#define PWM_DEFAULT_PERIOD   0xffff
 
#define NO_OS_CHN_TO_STM32_CHN(x)
 
#define FREQUENCY_HZ_TO_TIME_NS_FACTOR   1000000000.0
 

Functions

int32_t stm32_pwm_init (struct no_os_pwm_desc **desc, const struct no_os_pwm_init_param *param)
 Initialize the PWM.
 
int32_t stm32_pwm_remove (struct no_os_pwm_desc *desc)
 Free the resources allocated by stm32_pwm_init()
 
int32_t stm32_pwm_enable (struct no_os_pwm_desc *desc)
 Enable the PWM.
 
int32_t stm32_pwm_disable (struct no_os_pwm_desc *desc)
 Disable the PWM.
 
int32_t stm32_pwm_set_period (struct no_os_pwm_desc *desc, uint32_t period_ns)
 Set the PWM period.
 
int32_t stm32_pwm_get_period (struct no_os_pwm_desc *desc, uint32_t *period_ns)
 Get the PWM period.
 
int32_t stm32_pwm_set_duty_cycle (struct no_os_pwm_desc *desc, uint32_t duty_cycle_ns)
 Set the PWM 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.
 

Variables

const struct no_os_pwm_platform_ops stm32_pwm_ops
 STM32 platform specific PWM platform ops structure.
 

Detailed Description

Implementation of stm32 pwm driver.

Copyright 2023-25(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ FREQUENCY_HZ_TO_TIME_NS_FACTOR

#define FREQUENCY_HZ_TO_TIME_NS_FACTOR   1000000000.0

◆ NO_OS_CHN_TO_STM32_CHN

#define NO_OS_CHN_TO_STM32_CHN ( x)
Value:
(0x4*(x-1))

◆ PWM_DEFAULT_PERIOD

#define PWM_DEFAULT_PERIOD   0xffff

Function Documentation

◆ stm32_pwm_disable()

int32_t stm32_pwm_disable ( struct no_os_pwm_desc * desc)

Disable the PWM.

Parameters
desc- PWM descriptor
Returns
0 in case of success, negative error otherwise.

◆ stm32_pwm_enable()

int32_t stm32_pwm_enable ( struct no_os_pwm_desc * desc)

Enable the PWM.

Parameters
desc- PWM descriptor
Returns
0 in case of success, negative error code otherwise.

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

Parameters
desc- Pointer where the configured instance is stored.
duty_cycle_ns- PWM duty cycle.
Returns
0 in case of success, negative error code otherwise.

◆ stm32_pwm_get_period()

int32_t stm32_pwm_get_period ( struct no_os_pwm_desc * desc,
uint32_t * period_ns )

Get the PWM period.

Parameters
desc- Pointer where the configured instance is stored.
period_ns- PWM period.
Returns
0 in case of success, negative error code otherwise.

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

Parameters
desc- PWM descriptor.
param- The structure containing PWM init parameters.
Returns
0 in case of success, negative error code otherwise.

◆ stm32_pwm_remove()

int32_t stm32_pwm_remove ( struct no_os_pwm_desc * desc)

Free the resources allocated by stm32_pwm_init()

Parameters
desc- PWM descriptor
Returns
0 in case of success, negative error code otherwise.

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

Parameters
desc- Pointer where the configured instance is stored.
duty_cycle_ns- PWM duty cycle.
Returns
0 in case of success, negative error code otherwise.

◆ stm32_pwm_set_period()

int32_t stm32_pwm_set_period ( struct no_os_pwm_desc * desc,
uint32_t period_ns )

Set the PWM period.

Parameters
desc- Pointer where the configured instance is stored.
period_ns- PWM period.
Returns
0 in case of success, negative error code otherwise.

Variable Documentation

◆ stm32_pwm_ops

const struct no_os_pwm_platform_ops stm32_pwm_ops
Initial value:
= {
.pwm_ops_init = &stm32_pwm_init,
.pwm_ops_enable = &stm32_pwm_enable,
.pwm_ops_disable = &stm32_pwm_disable,
.pwm_ops_set_period = &stm32_pwm_set_period,
.pwm_ops_get_period = &stm32_pwm_get_period,
.pwm_ops_set_duty_cycle = &stm32_pwm_set_duty_cycle,
.pwm_ops_get_duty_cycle = &stm32_pwm_get_duty_cycle,
.pwm_ops_remove = &stm32_pwm_remove
}
int32_t stm32_pwm_enable(struct no_os_pwm_desc *desc)
Enable the PWM.
Definition stm32_pwm.c:826
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:1162
int32_t stm32_pwm_remove(struct no_os_pwm_desc *desc)
Free the resources allocated by stm32_pwm_init()
Definition stm32_pwm.c:757
int32_t stm32_pwm_disable(struct no_os_pwm_desc *desc)
Disable the PWM.
Definition stm32_pwm.c:931
int32_t stm32_pwm_get_period(struct no_os_pwm_desc *desc, uint32_t *period_ns)
Get the PWM period.
Definition stm32_pwm.c:1083
int32_t stm32_pwm_set_period(struct no_os_pwm_desc *desc, uint32_t period_ns)
Set the PWM period.
Definition stm32_pwm.c:1017
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:1126
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:679

STM32 platform specific PWM platform ops structure.

STM32 specific PWM platform ops structure.