cancel
Showing results for 
Search instead for 
Did you mean: 

TIM_CCxChannelCmd for STML0xx in HAL 1.10.2.0 has the wrong layout

SSkje.1
Associate II

Version:

#define __STM32L0xx_HAL_VERSION_MAIN  (0x01U) /*!< [31:24] main version */

#define __STM32L0xx_HAL_VERSION_SUB1  (0x0AU) /*!< [23:16] sub1 version */

#define __STM32L0xx_HAL_VERSION_SUB2  (0x02U) /*!< [15:8] sub2 version */

#define __STM32L0xx_HAL_VERSION_RC   (0x00U) /*!< [7:0] release candidate */

File Drivers\STM32L0xx_HAL_Driver\Inc\stm32l0xx_hal_tim.h

static void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)

{

 uint32_t tmp;

 /* Check the parameters */

 assert_param(IS_TIM_CC1_INSTANCE(TIMx));

 assert_param(IS_TIM_CHANNELS(Channel));

 tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */

 /* Reset the CCxE Bit */

 TIMx->CCER &= ~tmp;

 /* Set or reset the CCxE Bit */

 TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */

}

This function assumes CCER has 1 bit per timer, but on this MCU, each timer has 4 bits. Function should have this layout instead:

static void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)

{

 uint32_t tmp;

 /* Check the parameters */

 assert_param(IS_TIM_CC1_INSTANCE(TIMx));

 assert_param(IS_TIM_CHANNELS(Channel));

 tmp = TIM_CCER_CC1E << (Channel & 0x03U)*3;

 /* Reset the CCxE Bit */

 TIMx->CCER &= ~tmp;

 /* Set or reset the CCxE Bit */

 TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x03U)*3);

}

0 REPLIES 0