Erika3 and Avr8

Forum related to ERIKA Enterprise and RT-Druid version 3

Moderator: paolo.gai

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Erika3 and Avr8

Post by dimolin » Mon Sep 24, 2018 3:15 pm

Hello,

My question is if it’s possible to use Erika 3 and Avr8 without Arduino (hardware and software)? I mean I have a non-Arduino pcb board, just a pcb with Atmega328P mounted on it and I want to use it with Erika 3. I'm asking because I tried to create a project following the information from the link http://www.erika-enterprise.com/wiki/in ... _Main_Page without to install Arduino IDE but I'm getting error messages when I try to build the project.

BR
Dimo

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re: Erika3 and Avr8

Post by paolo.gai » Mon Sep 24, 2018 6:53 pm

Hi!

You can do that by removing the LIB part in the OIL (and of course all the Arduino library calls in the source code...). We tried it on an example and it worked.

Ciao,

PJ

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Tue Sep 25, 2018 8:40 pm

Hi Paolo,

Thank you for your answer. This sounds good. Nevertheless I have a problem to run Erika 3 with Avr8.
I’ll try to give as much as possible details about the problems that I’m facing with.

1. I’m using Window 10 64-bit
2. I have installed eclipse-rtdruid3-photon-win32-x86_64_20180917_gh47
3. Cygwin 32-bits
Note*: On erika wiki page http://www.erika-enterprise.com/wiki/in ... tle=Cygwin the link setup-x86.exe actually points to 64-bit version rather than to 32-bit.
I have pointed the path in System Variables of Windows.
4. I have installed Avr GCC compiler (C:\WinAVR-20100110) and added the path in System Variables of Windows
5. I have created RT-Druid Project as is described on http://www.erika-enterprise.com/wiki/in ... tart_guide skipping the option
Create a project using one of these templates

6. I have created a simple *.oil

Code: Select all

CPU mySystem {
	OS myOs {
		EE_OPT = "__AVR8_GCC_C99__";
		CFLAGS = "-O0 -g";
		
		CPU_DATA = AVR8  {
			COMPILER = GCC;
			MULTI_STACK = TRUE;
		};
		
		MCU_DATA = MEGA {
			MODEL = MEGA_328p;
			//USEIC = TRUE;
		};
		
		KERNEL_TYPE = OSEK{
			CLASS = ECC1;
		};
		
		STARTUPHOOK = TRUE;
	};
	
    COUNTER SystemTimer {
   		MINCYCLE = 1;
   		MAXALLOWEDVALUE = 65535;
  	    TICKSPERBASE = 1;
   		TYPE = HARDWARE {
     		DEVICE = "TIMER1_COMPA";
     		SYSTEM_TIMER = TRUE;
   		};
   		SECONDSPERTICK = 0.001;
     };
     
  	APPDATA myApp {
   	 	APP_SRC  = "main.c";
  	};
  	
	APPMODE DEFAULTAPPMODE;
	
	TASK Task1 {
		PRIORITY = 1;
		AUTOSTART = TRUE;
		STACK = PRIVATE{
			SIZE = 64;
		};
		SCHEDULE = FULL;
	};

	TASK Task2 {
		PRIORITY = 2;
		AUTOSTART = FALSE;
		STACK = PRIVATE{
			SIZE = 64;
		};
		SCHEDULE = FULL ;
	};
	
	ISR ExtInt0{
		CATEGORY = 1;
		SOURCE    = "INT0";
	};
};
7. I’ve created a simple *.c file using it to check that there is switching between tasks, interrupt response and so on.

Code: Select all

#include "ee.h"

#include "avr/io.h"

TASK(Task1)
{
	volatile int x;
	volatile int y;

	x = 10;
	y = 20;

	volatile int z = x + y;
	 z = x + y;
	 z = x + y;

	 PORTD = 1<<2;

	ChainTask(Task2);
}

TASK(Task2)
{
	volatile int x;
	volatile int y;

	x = 10;
	y = 20;

	volatile int z = x + y;
	 z = x + y;
	 z = x + y;

	while(1);
}

void StartupHook(void)
{
	DDRB |= (1 << 0);*/ /* set PB0 as output;*/
	PORTB |= (1<<0);
	PORTB &= ~(1<<0);
}

void Mcu_Init(void)
{
	EICRA = 0x01;/* Any logical change on INT0 generates an interrupt request*/
	/*EIMSK = 0x01;*/// INT0 enabled

	PORTD &= ~(1<<2);
	DDRD  |= 1 << 2;// Set PD2 as output
}

ISR1(ExtInt0)
{
	volatile int x;
	volatile int y;

	x = 10;
	y = 20;

	int z = x + y;
}

void  main(void)
{
	Mcu_Init();

	StartOS(OSDEFAULTAPPMODE);
}
7. As I said I don’t want to use Arduino boards and libraries, so I haven’t installed Arduino SDK and I haven’t pointed the path to in Eclipse -> Preferences nor in Environment Variables of Windows.

8. But when I built the project I got
img4.png
img4.png (29.47 KiB) Viewed 10044 times
9. The one solution is to install Arduino and to add path to it. I tried it and it works. The other option I tried is to disable this line manually
The attachment img5.png is no longer available
So it looks that Arduino SDK must be installed even if I’m not going to use it.
Then when I rebuild the project again I got this

10. The only solution I found out to resolve this problem is to change the code manually

ee_oscfg_mk.txt

Code: Select all

line 83: #if 1 //(F_CPU == 16000000L)
11. 11 At last the project is built successfully

Sorry for the long explanation. I tried to explain the problem as well as possible.
Last edited by dimolin on Tue Sep 25, 2018 10:01 pm, edited 4 times in total.

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Tue Sep 25, 2018 9:19 pm

9. The one solution is to install Arduino and to add path to it. I tried it and it works. The other option I tried is to disable this line manually
Attachments
img5.png
img5.png (8.7 KiB) Viewed 10044 times
Last edited by dimolin on Tue Sep 25, 2018 9:25 pm, edited 1 time in total.

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Tue Sep 25, 2018 9:23 pm

So it looks that Arduino SDK must be installed even if I’m not going to use it.
Then when I rebuild the project again I got this
Attachments
img6.png
img6.png (37.26 KiB) Viewed 10044 times

outlawch
Newbie
Posts: 17
Joined: Fri Apr 27, 2012 9:11 pm
Location: Pisa
Contact:

Re: Erika3 and Avr8

Post by outlawch » Wed Sep 26, 2018 9:06 am

Hi Dimolin,
If you don't want to use Arduino SDK, it's always mandatory to install the software package and set the related RT-Druid properties correctly.

Regarding the F_CPU macro, it's mandatory to set it: normally is made correctly by Arduino SDK.

Add in the oil file the following line:

...
OS myOs {
...

CFLAGS = "-DF_CPU=16000000L";
...

To tell Erika3 which is the CLOCK FREQUECY set by your MCU Driver (16MHz in this example).

BR,
Giuseppe

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Wed Sep 26, 2018 12:59 pm

Hi Giuseppe,

Thank you for your advice.

Regarding Arduino SDK, I have installed it and the error message from point 8 disappeared but the error message "Unsupported CPU frequency" was generated again. Then after I added the line CFLAGS = "-DF_CPU=16000000L"; the project was built successfully.

Just to clarify for myself, If I understand correctly, Erika 3 cannot be used absolutely independently from Arduino. I mean that I must install Arduino SDK, add the necessary path to it and my pcb board with Avr8 must use 16MHz quartz as Arduino Uno? I cannot use for example 8MHz quartz, because if I define "-DF_CPU=8000000L"; I will get again the error message "Unsupported CPU frequency" ?

I think Erika 2 can be used with Avr8 absolutely independently from Arduino, right?

BR
Dimo

outlawch
Newbie
Posts: 17
Joined: Fri Apr 27, 2012 9:11 pm
Location: Pisa
Contact:

Re: Erika3 and Avr8

Post by outlawch » Wed Sep 26, 2018 4:33 pm

Hi Dimolin,
you are right!

For now the AVR8 support it's only based and tested on Arduino UNO Board.

So the F_CPU macro SHALL be set to 16000000L.

You can use an 8MHz quartz, but you have to configure your custom MCU Driver to drive the CPU CLOCK to 16MHz (E.g. using the PLL).

For now the FULL AVR8 support in not scheduled.

BR,
Giuseppe.

P.S.: Erika2 AVR8 support is absolutely independent from Arduino SDK.

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Wed Sep 26, 2018 6:27 pm

Hi Guiseppe,

You gave me the necessary information. Thank you.

BR
Dimo

outlawch
Newbie
Posts: 17
Joined: Fri Apr 27, 2012 9:11 pm
Location: Pisa
Contact:

Re: Erika3 and Avr8

Post by outlawch » Wed Sep 26, 2018 7:26 pm

You're Welcome! :1smiley:

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Wed Oct 31, 2018 10:36 am

Hello again,

I faced with the following problem. I have defined an alarm with AUTOSTART = TRUE (see AlarmTask2). I have also defined an application mode RunMode. I want this alarm to start automatically for this mode so I have added the attribute APPMODE = RunMode;. But I get an error during the compilation:

ErrorMsg1.png
ErrorMsg1.png (18.7 KiB) Viewed 9919 times

If I define the default application mode OSDEFAULTAPPMODE and add it to the alarm APPMODE = OSDEFAULTAPPMODE, the compilation passes. Is this some deviation from the OSEK standard?

Code: Select all

CPU mySystem {

   /******************************************************************************************
	* 
	* 						Core OS settings
	* 
	* ****************************************************************************************/	
	OS myOs {
		EE_OPT = "__AVR8_GCC_C99__";
		CFLAGS = "-O0 -g";
		CFLAGS = "-DF_CPU=16000000L";
		
		CPU_DATA = AVR8 {
			MULTI_STACK = TRUE;
		};/* End of CPU_DATA */
		
		MCU_DATA = MEGA {
			MODEL = MEGA_328p;
		};/* End of MCU_DATA */
		
    	KERNEL_TYPE = OSEK {
      		CLASS = ECC1;
    	};/* End of KERNEL_TYPE */
	};/* End of OS */

	/******************************************************************************************
	* 
	* 						Source files
	* 
	******************************************************************************************/
  	APPDATA myApp {
    	APP_SRC  = "main.c";
    	APP_SRC  = "tasks.c";
  	};/* End of APPDATA */

	/******************************************************************************************
	* 
	* 						APPLICATION MODES
	* 
	* ****************************************************************************************/  	
	APPMODE OSDEFAULTAPPMODE;
 	APPMODE RunMode; 	
 	
	/******************************************************************************************
	* 
	* 						TASKS
	* 
	* ****************************************************************************************/
	TASK TaskInit {
		PRIORITY   = 1;
		SCHEDULE   = FULL;
		/*ACTIVATION = 1;*/
		AUTOSTART  = TRUE {
			//APPMODE   = OSDEFAULTAPPMODE;
			APPMODE   = RunMode;
			/*................*/
			/*APPMODE = ModeN;*/
		};
		/*RESOURCE = Resource-Name;*/
		/*EVENT = Event-Name;      */
		/*MESSAGE = Message-name;  */
		STACK = PRIVATE{
			SIZE = 64;
		};

	};/* End of TASK */

	 	  
	TASK Task1 {
		PRIORITY = 20;
		AUTOSTART = TRUE{
			//APPMODE   = OSDEFAULTAPPMODE;
			APPMODE   = RunMode; 
		};
		STACK = PRIVATE{
			SIZE = 64;
		};
		SCHEDULE = NON;
		EVENT = E1;
	};/* End of TASK */


	TASK Task2 {
		PRIORITY = 30;
		AUTOSTART = TRUE{
			//APPMODE   = OSDEFAULTAPPMODE;
			APPMODE   = RunMode; 
		};
		STACK = PRIVATE{
			SIZE = 64;
		};
		SCHEDULE = NON ;
		EVENT = E2;
	};/* End of TASK */

   /******************************************************************************************
	* 
	* 						RESOURCES
	* 
	* ****************************************************************************************/

			    
   /******************************************************************************************
	* 
	* 						COUNTERS
	* 
	* ****************************************************************************************/
 	COUNTER SystemTimer {
   		MINCYCLE = 1;
  		MAXALLOWEDVALUE = 65535;
   		TICKSPERBASE = 1;
   		TYPE = HARDWARE {
    		DEVICE = "TIMER1_COMPA";
     		SYSTEM_TIMER = TRUE;
        };
        SECONDSPERTICK = 0.001;/* 1ms tick */
     };
 
   /******************************************************************************************
	* 
	* 						ALARMS
	* 
	* ****************************************************************************************/ 	
 	 ALARM AlarmTask1 {
    	COUNTER = SystemTimer;
    	ACTION = SETEVENT {
    		TASK = Task1; 
    		EVENT = E1;
    	};
   		AUTOSTART = FALSE;
  	 };
 
  	 ALARM AlarmTask2 {
    	COUNTER = SystemTimer;
    	ACTION = SETEVENT {
    		TASK = Task2; 
    		EVENT = E2;
    	};
   		AUTOSTART = TRUE{
   			ALARMTIME = 500;
   			CYCLETIME = 500;
   			APPMODE   = OSDEFAULTAPPMODE;
   			APPMODE   = RunMode;
   		};
  	 };
 
   /******************************************************************************************
	* 
	* 						EVENTS
	* 
	* ****************************************************************************************/  	 	
	EVENT E1
	{
		MASK = AUTO;	
	};
	
	EVENT E2
	{
		MASK = AUTO;	
	};
};


e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Erika3 and Avr8

Post by e.guidieri » Wed Oct 31, 2018 12:42 pm

Hi Dimolin,

congratulations: you just found a bug in our configuration generator.

Actually, to let the generator generate correctly, if you are using autostart ALARMs with any APPMODE you need to tie at least one AUTOSTART ALARM with all the others APPMODE.
Since OSDEFAULTAPPMODE is always defined by standard (no need to do it explicitly as you have done, but not harm on doing that) you need to tie an autostart ALARM to it.

This bug affect only ALARMs no TASKs, as you can see. I have already found the bug in generator code base and hopefully fixed it (more tests are needed), the fix will be added to the next GH realease.

Sorry for the inconvenience.

Regards,
Errico

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Wed Oct 31, 2018 12:58 pm

Hi Errico,

Thank you for your fast response.

BR
Dimo

dimolin
Newbie
Posts: 18
Joined: Thu Feb 16, 2017 4:58 pm

Re: Erika3 and Avr8

Post by dimolin » Wed Nov 07, 2018 12:14 pm

Hello,

Is it possible the generation of OS files (erika and out folders) to be redirected? For example I want to create a specific folder structure and RT-Druid generated folders (erika and out) to be generated in folder Os.
OsFiles.png
OsFiles.png (9.58 KiB) Viewed 9864 times
BR
Dimo

nicola.serreli
Jr. Member
Posts: 68
Joined: Mon Aug 02, 2010 10:11 am

Re: Erika3 and Avr8

Post by nicola.serreli » Wed Nov 07, 2018 1:34 pm

Hello Dimolin,

currently, it is not possible to change the generation path for any of the generated folder (erika and out).

Best Regards,
Nicola

Post Reply