'Timer2' was not declared in this scope
Posted: Sun Mar 07, 2021 4:15 pm
I encountered this problem when compiling this code,
'Timer2' was not declared in this scope.
I tried for a day and still not resolved.
PLATFORM: ST STM32 (8.0.0)> ST Nucleo F446RE
HARDWARE: STM32F446RET6 180MHz, 128KB RAM, 512KB Flash
Thanks.
'Timer2' was not declared in this scope.
I tried for a day and still not resolved.

PLATFORM: ST STM32 (8.0.0)> ST Nucleo F446RE
HARDWARE: STM32F446RET6 180MHz, 128KB RAM, 512KB Flash
Code: Select all
#include "Arduino.h"
int32_t channel_1_start, channel_1_stop, channel_1;
void handler_channel_1(void) {
if (0b1 & GPIOB ->IDR) {
channel_1_start = TIM2->CCR1;
TIM2->CCER |= TIM_CCER_CC1P;
}
else {
channel_1 = TIM2->CCR1 - channel_1_start;
if (channel_1 < 0)channel_1 += 0xFFFF;
TIM2->CCER &= ~TIM_CCER_CC1P;
}
}
void setup() {
Serial.begin(9600);
pinMode(PA0, INPUT);
delay(250);
Timer2.attachCompare1Interrupt(handler_channel_1);
TIM2->CR1 = TIM_CR1_CEN;
TIM2->CR2 = 0;
TIM2->SMCR = 0;
TIM2->DIER = TIM_DIER_CC1IE;
TIM2->EGR = 0;
TIM2->CCMR1 = TIM_CCMR1_CC1S_1;
TIM2->CCMR2 = 0;
TIM2->CCER = TIM_CCER_CC1E;
TIM2->PSC = 71;
TIM2->ARR = 0xFFFF;
TIM2->DCR = 0;
}
void loop() {
delay(1000);
Serial.println(channel_1);
}
Code: Select all
src/main.cpp: In function 'void setup()':
src/main.cpp:20:3: error: 'Timer2' was not declared in this scope
20 | Timer2.attachCompare1Interrupt(handler_channel_1);
| ^~~~~~
*** [.pio/build/nucleo_f446re/src/main.cpp.o] Error 1