pzuid
September 21, 2023, 7:41am
1
So I have a sketch for mega (and other boards) and I want to use it on a Giga Board. At verification, I got errors about ISR(TIMER1_OVF_vect:
error: expected constructor, destructor, or type conversion before '(' token
The code:
// SET UP interrupt timer
#if defined(BOARD_UNO) || defined(BOARD_MEGA) || defined(BOARD_GIGA)
TCCR1A = 0;
TCCR1B = _BV(WGM13);
ICR1 = (F_CPU / 4000000) * TIME_CHUNK; // goes twice as often as time chunk, but every other event turns off pins
TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));
TIMSK1 = _BV(TOIE1);
TCCR1B |= _BV(CS10);
#elif defined(BOARD_101)
CurieTimerOne.start(25, &updateStepDirection);
#endif
}
#if defined(BOARD_101)
void updateStepDirection(void)
{
#else
ISR(TIMER1_OVF_vect)
{
#endif
I do net really got a idea how to solve this any push in the right direction?
b707
September 21, 2023, 7:44am
2
If a sketch uses methods to access the hardware of a specific microcontroller - such as writing to registers or using interrupts - such code cannot simply be transferred to a different type of controller, the program will have to be completely rewritten.
Arduino Mega based on AVR mcu family, but the Giga has a STM32 controller. The code you shown is incompatible with STM32 core.
1 Like
b707
September 21, 2023, 7:51am
3
By the way, is the Arduino Giga define in the line below was in the original code
or you added it yourself?
The combination of BOARD_MEGA
and BOARD_GIGA
in the same preprocessor directive looks as nonsense for me....
1 Like
awneil
September 21, 2023, 10:46am
4
Indeed.
Probably should be something like
// SET UP interrupt timer
#if defined(BOARD_UNO) || defined(BOARD_MEGA)
TCCR1A = 0;
TCCR1B = _BV(WGM13);
ICR1 = (F_CPU / 4000000) * TIME_CHUNK; // goes twice as often as time chunk, but every other event turns off pins
TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));
TIMSK1 = _BV(TOIE1);
TCCR1B |= _BV(CS10);
#elif defined(BOARD_101)
CurieTimerOne.start(25, &updateStepDirection);
#elif defined(BOARD_GIGA)
// Put STM32-specific stuff here
#endif
I would always include a #else
to catch any missing or incorrect preprocessor definition; eg,
:
:
#elif defined(BOARD_GIGA)
// Put STM32-specific stuff here
#else
#error "Unsupported board."
#endif
1 Like
pzuid
September 21, 2023, 12:32pm
5
Yes, i have added this myself. But as I understand it is better to start writing this sketch only for Giga instead of changing the sketch to add the Giga as well. Later if everything works it can be possible to add the board selection.
system
Closed
March 19, 2024, 12:33pm
6
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.