mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #10824 from ABOSTM/PRSTM32_PWMWRTIE_GLITCH_10734
STM32: pwmout_write: configure channel only when not already enabledpull/10919/head
commit
61c4d05ce9
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32f0xx_ll_usart.h"
|
||||
#include "stm32f0xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32f1xx_ll_usart.h"
|
||||
#include "stm32f1xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32f2xx_ll_usart.h"
|
||||
#include "stm32f2xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32f3xx_ll_usart.h"
|
||||
#include "stm32f3xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32f4xx_ll_usart.h"
|
||||
#include "stm32f4xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32f7xx_ll_usart.h"
|
||||
#include "stm32f7xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "PinNames.h"
|
||||
#include "stm32h7xx_ll_usart.h"
|
||||
#include "stm32h7xx_ll_rtc.h"
|
||||
#include "stm32h7xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32l0xx_ll_usart.h"
|
||||
#include "stm32l0xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32l1xx_ll_usart.h"
|
||||
#include "stm32l1xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32l4xx_ll_usart.h"
|
||||
#include "stm32l4xx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "PeripheralNames.h"
|
||||
#include "PinNames.h"
|
||||
#include "stm32wbxx_ll_usart.h"
|
||||
#include "stm32wbxx_ll_tim.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -39,6 +39,43 @@
|
|||
|
||||
static TIM_HandleTypeDef TimHandle;
|
||||
|
||||
/* Convert STM32 Cube HAL channel to LL channel */
|
||||
uint32_t TIM_ChannelConvert_HAL2LL(uint32_t channel, pwmout_t *obj)
|
||||
{
|
||||
#if !defined(PWMOUT_INVERTED_NOT_SUPPORTED)
|
||||
if (obj->inverted) {
|
||||
switch (channel) {
|
||||
case TIM_CHANNEL_1 :
|
||||
return LL_TIM_CHANNEL_CH1N;
|
||||
case TIM_CHANNEL_2 :
|
||||
return LL_TIM_CHANNEL_CH2N;
|
||||
case TIM_CHANNEL_3 :
|
||||
return LL_TIM_CHANNEL_CH3N;
|
||||
#if defined(LL_TIM_CHANNEL_CH4N)
|
||||
case TIM_CHANNEL_4 :
|
||||
return LL_TIM_CHANNEL_CH4N;
|
||||
#endif
|
||||
default : /* Optional */
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
switch (channel) {
|
||||
case TIM_CHANNEL_1 :
|
||||
return LL_TIM_CHANNEL_CH1;
|
||||
case TIM_CHANNEL_2 :
|
||||
return LL_TIM_CHANNEL_CH2;
|
||||
case TIM_CHANNEL_3 :
|
||||
return LL_TIM_CHANNEL_CH3;
|
||||
case TIM_CHANNEL_4 :
|
||||
return LL_TIM_CHANNEL_CH4;
|
||||
default : /* Optional */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pwmout_init(pwmout_t *obj, PinName pin)
|
||||
{
|
||||
// Get the peripheral name from the pin and assign it to the object
|
||||
|
@ -214,10 +251,15 @@ void pwmout_write(pwmout_t *obj, float value)
|
|||
return;
|
||||
}
|
||||
|
||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
||||
error("Cannot initialize PWM\n");
|
||||
if (LL_TIM_CC_IsEnabledChannel(TimHandle.Instance, TIM_ChannelConvert_HAL2LL(channel, obj)) == 0) {
|
||||
// If channel is not enabled, proceed to channel configuration
|
||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
||||
error("Cannot initialize PWM\n");
|
||||
}
|
||||
} else {
|
||||
// If channel already enabled, only update compare value to avoid glitch
|
||||
__HAL_TIM_SET_COMPARE(&TimHandle, channel, sConfig.Pulse);
|
||||
}
|
||||
|
||||
#if !defined(PWMOUT_INVERTED_NOT_SUPPORTED)
|
||||
if (obj->inverted) {
|
||||
HAL_TIMEx_PWMN_Start(&TimHandle, channel);
|
||||
|
|
Loading…
Reference in New Issue