cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX sets Timer 2 CC1E bit in the CCER register even when I select "Channel 1 Output Compare No Output"

Konrad1
Associate II

STM32CubeMX sets Timer 2 CC1E bit in the CCER register even when I select "Channel 1 Output Compare No Output"

For Output Compare No Output Channel 1 I select "Frozen (Used for timing base)".

I discovered this when trying to use the TIM2_ETR pin as a source for the clock. The input clock is killed when the HAL libraries set CC1E.

Is this a bug in the cube or am I just getting the setting wrong?


_legacyfs_online_stmicro_images_0693W00000dDdatQAC.png 


_legacyfs_online_stmicro_images_0693W00000dDdajQAC.png

3 REPLIES 3
Konrad1
Associate II

it seems I have to replace

//   HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_1);   //HAL enable compare & interrupt

with

   TIM2->DIER |= TIM_DIER_CC1IE;   //enable counter

so it is just the HAL library, not so flexible.

funnily enough my original code was as above, setting the register bit directly, but I thought I best use the HAL library where possible

Ghofrane GSOURI
ST Employee

Hello @KBamf.1​ 

First let me thank you for posting.

Could you please specify the MCU and the CubeMX version you are utilizing, in order to push further the investigation.

I will be waiting for your feedback and thanks for you collaboration .

Ghofrane

I should have made it more clear, I have solved the problem.

The cube generates the correct code, but I added the line HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_1); into main() manually to enable the Output Compare interrupt.  I did not realise that this line also enables the output.