2023-06-12 02:01 PM - edited 2023-11-20 03:24 AM
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?
2023-06-12 02:54 PM
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
2023-06-13 12:48 AM
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
2023-06-16 11:24 AM
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.