drivers/pwm/pwm_stm32.c
/*
 * Get the clock rate (cycles per second) for a PWM pin.
 *
 * Parameters
 * dev: Pointer to PWM device structure
 * pwm: PWM port number
 * cycles: Pointer to the memory to store clock rate (cycles per second)
 *
 * return 0, or negative errno code
 */
Get the clock rate (cycles per second) for a PWM pin.
Parameters
dev: Pointer to PWM device structure
pwm: PWM port number
cycles: Pointer to the memory to store clock rate (cycles per second)

return 0, or negative errno code
Get the clock rate ( cycles per second ) for a PWM pin . Parameters dev : Pointer to PWM device structure pwm : PWM port number cycles : Pointer to the memory to store clock rate ( cycles per second ) return 0 or negative errno code
static int pwm_stm32_get_cycles_per_sec(struct device *dev, u32_t pwm,
					u64_t *cycles)
{
	const struct pwm_stm32_config *cfg = DEV_CFG(dev);
	struct pwm_stm32_data *data = DEV_DATA(dev);
	u32_t bus_clk, tim_clk;
	if (cycles == NULL) {
		return -EINVAL;
	}
#if defined(CONFIG_CLOCK_CONTROL_STM32_CUBE)
	clock_control_get_rate(data->clock,
			(clock_control_subsys_t *)&cfg->pclken, &bus_clk);
	tim_clk = __get_tim_clk(bus_clk,
			(clock_control_subsys_t *)&cfg->pclken);
#else
	clock_control_get_rate(data->clock, cfg->clock_subsys, &bus_clk);
	tim_clk = __get_tim_clk(bus_clk, cfg->clock_subsys);
#endif
	*cycles = (u64_t)(tim_clk / (data->pwm_prescaler + 1));
	return 0;
}
static int pwm_stm32_get_cycles_per_sec ( struct device * dev , u32_t pwm , u64_t * cycles ) { const struct pwm_stm32_config * cfg = DEV_CFG ( dev ) ; struct pwm_stm32_data * data = DEV_DATA ( dev ) ; u32_t bus_clk , tim_clk ; if ( cycles == NULL ) { return - EINVAL ; } #if defined ( CONFIG_CLOCK_CONTROL_STM32_CUBE ) clock_control_get_rate ( data -> clock , ( clock_control_subsys_t * ) & cfg -> pclken , & bus_clk ) ; tim_clk = __get_tim_clk ( bus_clk , ( clock_control_subsys_t * ) & cfg -> pclken ) ; #else clock_control_get_rate ( data -> clock , cfg -> clock_subsys , & bus_clk ) ; tim_clk = __get_tim_clk ( bus_clk , cfg -> clock_subsys ) ; #endif * cycles = ( u64_t ) ( tim_clk / ( data -> pwm_prescaler + 1 ) ) ; return 0 ; }
Get the clock rate (cycles per second) for a PWM pin.
Get the clock rate ( cycles per second ) for a PWM pin .
/* Timer clock depends on APB prescaler */