Logic Green

Porting considerations for LGT8F328:

does anyone have freeRTOS running on this MCU… It is extremely similar to the ATmega328 witht the nasty exception of always being delivered with the WOTON fuse unset… cannot use watchdog interrupts.

I use freeRTOS on all my projects of any size and love it… I also love the added feature of the LGT MCU but have not been able to use it… I don’t have enough programming experience to do a port… In my limited thinking it should just be a matter of changing the tick interrupt to a different timer… I actually tried it but tasks would not switch…

Looking for any comments or helpful suggestions…

Which timers are available on the part? You need to select one that can generate a tick at the frequency you require, then install the FreeRTOS tick handler on that instead of which ever timer is used in the example. The way you write and install the tick interrupt should be identical no matter which timer is used - the only difference will be how you clear the timer - for that reason my first suggestion would be to just get a timer interrupt executing at the frequency you require outside of any FreeRTOS application (just set it up from main()) as a first step, and only then add in the FreeRTOS code.

I tried replying to the email but it was rejected… I think I got it…

Thanks for the quick reply…

The LGT8F328 is a clone of the ATmega328 with 3 timers… availability is dependent on the Arduino libraries used…

but I am willing to put up with this…

I had done basically exactly what you indicated but could not get tasks to schedule… This was a few months ago…

your reinforcing my basic assumption gave me the impetus to try again… Took me all day but I am happy to report that

I basically have it working… think my biggest problem was giving too much stack space to the tasks…

I could use help with one item… I had to use timer 2 which is 8bit with a /1024 prescaler which gives me the slowest tick of

around 7.5 mSec. I want to put a counter to divide by 2 in the ISR but don’t know how or whee to declare the variable to do so…

here is my unsuccessful try… in port.c

===============================================

ISR( TIMER2_OVF_vect )
{

volatile uint8_t T_irq_Div;
// if( ++T_irq_Div == 2 ) {
// T_irq_Div = 0;
vPortYieldFromTick();
asm volatile ( “reti” );
// }
}

================================================

I think I have the declaration in an inappropriate place… I tried various other places in port.c and in the header file

but with no success.

Again, many thanks… Happier camper here…

I’ll try to post the cleaned up changes in my git hub…

==============================================================

If the variable is declared in the function as you have done, it is not kept between calls to the function. You can either make if a file global variable (perhaps static so other files can’t access it) or you can make it a function static variable, so it keeps its value between function invocations. The variable, since only accessed inside one interrupt, doesn’t need to be volatile.

Examples:

static uint8_t T_irq_Div1 = 0;
ISR( TIMER2_OVF_vect )
{
static uint8_t T_irq_Div2 = 0;

}

You could use either of the variables for your scaler. The =0 s aren’t strictly needed as they will be automatically zeroed on program start, but I prefer to make them explicit. Note that the function static initialization only happens at program start or the first run of the function, not every invocation.

Hi CanHobby,
May I ask whether you have any progress in this one? I got LGT8F328P and tried a port to this MCU from a ported version of Atmega128 but no lucks, the task doesn’t switch. I’m not sure what wrong with the port, it’s using Timer1 COMPA to tick. I want to use the LGT8F328P for some projects with FreeRTOS.