Skip to main content
Konrad1
Associate II
June 12, 2023
Question

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

  • June 12, 2023
  • 2 replies
  • 1964 views

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

This topic has been closed for replies.

2 replies

Konrad1
Konrad1Author
Associate II
June 12, 2023

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
Technical Moderator
June 13, 2023

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Konrad1
Konrad1Author
Associate II
June 16, 2023

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.