FreeRTOS library that will work on Nano Every Board

I am using the freertos kernel for my application on the Nano every board.

when i compiled my sketch, the following warning is given :
WARNING: library FreeRTOS claims to run on avr architecture(s) and may be incompatible with your current board which runs on megaavr architecture(s). my board setting is ATMEGA4809 for the nano every board.

following this the Task creation function calls for freertos does not compile and throws up errors. i have attached the snap of freertos library installed on my Arduino IDE used for the compilation. this library claims it will work for Mega AVR architectures also..

Any help to get the right freertos library installed availble on the Arduino forum that will work on the Nano every board..

Let's add that you're converting an existing Nano application to a Nano Every.

Please post the code as well as all error messages that you get; just in case, use code tags for both.

Yes, absolutely right!! i am indeed porting a FreeRTOS project that executed perfectly on the Nano board to the Nano EVERY Board.

the Atmega4809 is the target controller...now..

I am posting the code tags soon

// full CODE BELOW: 

 #include <Arduino_FreeRTOS.h>
#include <semphr.h> 
#include <megaAVR_TimerInterrupt.h>
#include <megaAVR_TimerInterrupt.hpp>
#include <megaAVR_ISR_Timer.h>
#include <megaAVR_ISR_Timer.hpp>
#include <SoftwareSerial.h>
 

// inslude the SPI library:
//#include <SPI.h>


#define SCHEDULING_TIMER_BLDC 20 
#define SCHEDULING_TIMER 20// wait for 16.60ms ~60 Hz
#define KEYPRESSCOUNT 5
#define KEYPRESSCOUNTLOW 0
#define KEYPRESSCOUNTHIGH 5

#define FINEDINE 14
#define ADCHAN 4
#define TOPPWMVALUE 225
#define DUTYVALUE 76

// add the FreeRTOS functions for Semaphores (or Flags).

 /// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0;  // Analog input pin that the power supply monitor is attached to


const int analogInPinSO1 = A6;  // Analog input pin that the SHx
const int analogInPinSO2 = A5;  // Analog input pin that the SHx
const int analogInPinSO3 = A7;  //Analog input pin that the SHx

// constants won't change. Used here to set a pin number;
const int ledPin =  LED_BUILTIN;// the number of the LED pin




// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;



  // constants won't change. Used here to set a pin number;
//const int ledPin =  LED_BUILTIN;// the number of the LED pin
int Leddrive = LOW ;
int ledState = LOW;
int PrevledState = HIGH;// DRIVE MOTOR STATUS

int SteerState = LOW;
int PrevSteerState = HIGH;// STEER MOTOR STATUS
int ButtonState = LOW, bitspistate;
unsigned int simplecnt = 0 ; 
unsigned int humblecount = 0 ;
unsigned int ADcount = 0 ;
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)
int sensorValue1[8][15];
int ADCCHEK ;
unsigned int loccount = 0;
unsigned int count = 0, freecount ;
unsigned int MotorDelay = 0 ;

static unsigned int bldcphasecount = 0 ;

static unsigned int rpmmotor = 400, rpmmotor1 = 400 ; // 30 deg electrical Angular equivalent RPM count

// digital pin 2 has a pushbutton attached to it. Give it a name: 
uint8_t pushButton = 2;
char Rxport ;
unsigned char itimer1, itimer2, adclow, adchigh ;
int buttonState[6] ;

const unsigned int DrvMode[16] = {0x0000,0x8800,0x9000,0x9800,0xa000,0x2b78,0x3378,0x3b36,0xc000,0xc820,0x503f,0xda0a,0x6058,0x0000,0x0000,0x0000};

enum BUTTON_T {PRESS, POSTPRESS, PRESSLOOK, POSTPRESSLOOK} ;

enum MOTORSPEED_T {GEAR0, GEAR1, GEAR2, GEAR3} ;

enum BLDCMOTOR_T {ACCEL0, ACCEL1, ACCEL2, ACCEL3, ACCEL4, ACCEL5, ACCEL6, ACCEL7, ACCEL8, ACCEL9, ACCEL10, ACCEL11, ACCEL12, DECEL, BEMF1, BEMF2, STOP, ALIGN};

enum MOTORSPEEDRAMP_T {ASCEND, DESCEND, SLOW} ;

MOTORSPEEDRAMP_T RampCntrl = ASCEND ;

MOTORSPEED_T motorspeed_state = GEAR0 ;

BUTTON_T stateofbutton = PRESSLOOK ;

 BLDCMOTOR_T bldcstate = STOP ;

unsigned int Period, Period0, Period1, Period2 ;
unsigned int Period3 = 0 ;
unsigned short int k=0;
byte Phase[]={B01100000,B01010000,B01110000,B01000000,B00000010,B11111101}; //Lookup Table pb1 - least, HL format, only pb1 hi or, low and func, d4/d5 direct portd writes...

//long unsigned int change1, change2, change0 ;


// Declare a mutex Semaphore Handle which we will use to manage the Serial Port. 
 // It will be used to ensure only only one Task is accessing this resource at any time. 
  SemaphoreHandle_t xSerialSemaphore; 
  
 
  // define two Tasks for DigitalRead & AnalogRead 
  void TaskDigitalRead( void *pvParameters ); 
  void TaskHumbleRead( void *pvParameters ); 
  void setup( void ) ;

/**
  void Func_accel0( void );
  void Func_accel2( void );
  void Func_accel4( void );
  void Func_accel6( void );
  void Func_accel8( void );
  void Func_accel10( void );
  void Func_accel12( void );
  void Func_accel_comm( void );

typedef void (*fptr)(void);

const fptr AccelFuncptr[13] = {Func_accel0,Func_accel_comm,Func_accel2,Func_accel_comm,Func_accel4,Func_accel_comm,Func_accel6,Func_accel_comm,Func_accel8,Func_accel_comm,Func_accel10,Func_accel_comm,Func_accel12} ;
 
 **/
 
  
  
  
  // the setup function runs once when you press reset or power the board 
 void setup() 
 { 
  
 
PORTA.DIR = 0x83 ;// PA7 config for CLKOUT chks of CLK_PER value - remove later after DEBUG
PORTA.OUT = 0x0 ;

PORTB.DIR = 0x03 ;
PORTB.OUT = 0x0 ;

PORTC.DIR = 0x50 ;
PORTC.OUT = 0x0 ;

PORTD.DIR = 0x07 ;
PORTD.OUT = 0x0 ;

// port E all are i/ps so no initial value needed
PORTE.DIR = 0x05 ;
PORTE.OUT = 0x0 ;


PORTF.DIR = 0x10 ;
PORTF.OUT = 0x0 ;



// initialize serial communication at 9600 bits per second: 
    Serial.begin(9600); 
    // deafult drive code
    //analogReference(DEFAULT);
        

    while (!Serial) { 
      ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards. 
    } 
  
 
    // Semaphores are useful to stop a Task proceeding, where it should be paused to wait, 
    // because it is sharing a resource, such as the Serial port. 
    // Semaphores should only be used whilst the scheduler is running, but we can set it up here. 
    if ( xSerialSemaphore == NULL )  // Check to confirm that the Serial Semaphore has not already been created. 
    { 
      xSerialSemaphore = xSemaphoreCreateMutex();  // Create a mutex semaphore we will use to manage the Serial Port 
      if ( ( xSerialSemaphore ) != NULL ) 
       {
         xSemaphoreGive( ( xSerialSemaphore ) );
        // Make the Serial Port available for use, by "Giving" the Semaphore. 
       }
    } 

     /* Disable interrupts */
 cli();//stop interrupts

// Timer Init for TB0/1/2 For FRQPW modes

// Timers B & A



//TCA0.SINGLE.CTRLB = 0x01 ; //default is single PWM mode by arduino IDE

//TCA0.SINGLE.CTRLA = 0x09 ; //default arduino IDE provides divide by 64

//TCA0.SINGLE.CMP0 = 0x0064 ;



//TCB0.CTRLB = 0x05 ;
//TCB0.EVCTRL = 0x01 ;




// Timers 1

TCB1.CTRLB = 0x05 ;
TCB1.EVCTRL = 0x01 ;

//TCB1.INTCTRL = 0x01 ;
TCB1.CTRLA = 0x05 ;

// Timers 2

TCB2.CTRLB = 0x05 ;
TCB2.EVCTRL = 0x01 ;

//TCB2.INTCTRL = 0x01 ;
TCB2.CTRLA = 0x05 ;


// EVSYS Drivers

//EVSYS.CHANNEL0 = 0x42 ;
EVSYS.CHANNEL4 = 0x4D ;
EVSYS.CHANNEL5 = 0x43 ;

// EVSYS.CHANNEL1 = 0x84 ;  // TCA0 CMP0 events connected to channel 1


//EVSYS.USERTCB0 = 0x01 ; // TCB0 to CH0

EVSYS.USERTCB1 = 0x05 ; // TCB1 to CH4
EVSYS.USERTCB2 = 0x06 ; // TCB2 to CH5



  // set the digital pin as output:
  // PWMA,PWMB,PWMC hold on zero
        // Engate cmd ZERO
        
    //delay(10);
       
         
         
         for(unsigned int i=0; i<=14; i++)
         {
          sensorValue1[7][i] = 620 ;
         }

         Serial.println("\n\t ADC FILL DONE");

        // enable PWM
        
  // 1-PWM drive
 //TIMER TCB0 SET UP
   //timer TCB0 -- interrupt @32uS

 PORTMUX.TCBROUTEA = 0x01 ; // TCB0 o/p routed to PF4/D6 - Arduino port
  TCB0.CTRLA = 0x04 ; // TCA0 CLK Chosen, but TCB disabled still
TCB0.CTRLB = 0x07 ; // 8 bit PWM mode chosen for TCB0 timer
TCB0.CCMPL = DUTYVALUE ;
TCB0.CCMPH = TOPPWMVALUE ;

TCB0.INTCTRL = 0x01 ; // interrupt enabled in 8bit PWM mode
//TCB0.CTRLA = 0x05 ; // TCB0 enabled


 




     
  //the following port pins are configured for rising edge interrupt if configured as I/Ps


 PORTF.PIN3CTRL = 0x02 ; // A5/SCL ARDUINO PORT
 PORTE.PIN3CTRL = 0x02 ; // D8 ARDUINO PORT
 PORTA.PIN1CTRL = 0x02 ; // D7 ARDUINO PORT
    
   



      
/**
     
    // Now set up two Tasks to run independently. 
    xTaskCreate( 
      TaskDigitalRead 
      ,  (const portCHAR *)"DigitalRead"  // A name just for humans 
      ,  128  // This stack size can be checked & adjusted by reading the Stack Highwater 
      ,  NULL 
      ,  3  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. 
      ,  NULL ); 
  
   xTaskCreate( 
      TaskHumbleRead 
      ,  (const portCHAR *)"HumbleRead"  // A name just for humans 
      ,  128  // This stack size can be checked & adjusted by reading the Stack Highwater 
      ,  NULL 
      ,  1  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. 
      ,  NULL ); 

**/
 
    // Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started. 
         
sei();//allow interrupts   
} 

ISR(TCB2_INT_vect) 
{
  //PORTE.OUTTGL = 1 << PIN2;                           // to toggle pin PE2
  //TCB2.INTFLAGS = TCB_CAPT_bm;                        // reset interrupt flag
  /* Dont ask why TCB_CAPT_bm to reset TCB2_INT_vect */
}



ISR(TCB1_INT_vect) 
{
  //PORTE.OUTTGL = 1 << PIN2;                           // to toggle pin PE2
  //TCB2.INTFLAGS = TCB_CAPT_bm;                        // reset interrupt flag
  /* Dont ask why TCB_CAPT_bm to reset TCB2_INT_vect */
}
/**
 
ISR(ADC_vect)
{

   adclow = ADCL ;
   adchigh = (ADCH & 0x03) ;
   sensorValue1[(ADMUX & 0x07)][count] = (unsigned int) (  (((unsigned int)adchigh) << 8) | ((unsigned int)adclow) )   ;
    
  //freecount = freecount + 1 ;
  count = count + 1 ;
     
}
**/
/**ISR(TIMER1_OVF_vect)
{
  Period3 += 1 ;
}
**/
/*******ISRs**

ISR(PCINT0_vect)
{
 
  TCCR1B = 0x18 ; //0HZTCCR1B &= ~(1<< CS10);//Stoping timer
  PIND|=B00010000;//PIN B to One
  
  Period=ICR1;
  OCR1A=(Period>>1);
  k=0;
  TCNT1=0;
  TCCR1B = 0x19 ; //16MhzTCCR1B &= (1<< CS10);//Starting timer
  
 
 }
ISR(PCINT1_vect)
{
  
  TCCR1B = 0x18 ; //0HZ Stoping timer
  PIND&=B11110111;//PIN A to Zero
  
  Period=ICR1;
  OCR1A=(Period>>1);
  k=1;
  TCNT1=0;
  TCCR1B = 0x19 ; //16Mhz//Starting timer
  
  
}

ISR(PCINT2_vect)
{
  
  
  TCCR1B = 0x18 ; //0HZ//Stoping timer
  PIND&=B11011111;//Pin C to Zero
  
  Period=ICR1;
  OCR1A=(Period>>1);
  k=2;
  TCNT1=0;
  TCCR1B = 0x19 ; //16Mhz//Starting timer
  


}


ISR(TIMER1_COMPB_vect)
{
PIND|=Phase[k];//Commute
}

****/
    
/**
ISR(PCINT0_vect)
{
  if((PINB & 0x01))
  {
    TCCR1B = 0;//Stoping timer

 

  Period0=TCNT1;

  //OCR1A=(Period>>1);

  //k=0;

  TCNT1=0;

  TCCR1B = 4;//Starting timer
  //change0 += 1 ;
  }
 //pb0 port
}

ISR(PCINT1_vect)
{
  
 if((PINC & 0x20))
  {
    TCCR1B = 0;//Stoping timer

 

  Period1=TCNT1;

  //OCR1A=(Period>>1);

  //k=0;

  TCNT1=0;

  TCCR1B = 4;//Starting timer
  //change1 += 1 ;
  }
 
 //pc5 
}

ISR(PCINT2_vect)
{
  
 if((PIND & 0x80))
  {
    TCCR1B = 0;//Stoping timer

 

  Period2=TCNT1;

  //OCR1A=(Period>>1);

  //k=0;

  TCNT1=0;

  TCCR1B = 4 ;//Starting timer
  //change2 += 1 ;
  }

//pd7
}

**/


ISR(TCB0_INT_vect)
{
  
  //timer1 interrupt 
switch (bldcstate)
  {
    case  STOP :
     
     
     //digitalWrite(3, LOW);// ports must be zero D3 XCHG TO B1
     //digitalWrite(4, LOW);
     //digitalWrite(5, LOW);
      //PORTB = (B11111101 & PORTB);
     PORTD.OUT = B01000000 ;//digitalWrite(6, HIGH); // ENGATE
     
     bldcphasecount = 0 ;
     bldcstate = ALIGN ;
     break ;

    case ALIGN :
     
     if (bldcphasecount == 0)
     {
        PORTB.OUT = (B00000010 | PORTB.OUT);//digitalWrite(3, HIGH); B1 XCHG
        PORTD.OUT = B01110000 ;
        
     
        //digitalWrite(4, HIGH);
        //digitalWrite(5, HIGH);
        
        bldcphasecount = bldcphasecount + 1 ;
     }
     else if (bldcphasecount < 32000)
     {
        bldcphasecount = bldcphasecount + 1 ;
     }
     else 
     {
       // 1-PWM drive 99% DUTY for entering accel
      bldcphasecount = 0 ;
      bldcstate = ACCEL0 ;
      
      
     }
       
     break ;

    case ACCEL0 :
    
    if (bldcphasecount == 0)
    {

      //*AccelFuncptr[bldcphasecount] ;
    
    PORTB.OUT = (B11111101 & PORTB.OUT);//digitalWrite(3, LOW);
    //PORTD = B01110000 ;
    
    bldcphasecount = bldcphasecount + 1 ;
    }
    else if (bldcphasecount < rpmmotor)
    {
      
      bldcphasecount = bldcphasecount + 1 ;
      
    }
    else
    {
      bldcstate = ACCEL1 ;
      bldcphasecount = 0 ;
    }
    
      
     
    
     break ;

    case ACCEL1 :
    
    // odd states commute cmds
    if (bldcphasecount < rpmmotor)
    {
      bldcphasecount = bldcphasecount + 1 ;
      
    }
    else
    {
      //freecount = 0 ;
      bldcstate = ACCEL2 ;
      bldcphasecount = 0 ;
    }
    
     
     
     break ;

     case ACCEL2 :
     
     if (bldcphasecount == 0)
    {

      //*AccelFuncptr[bldcphasecount] ;
    
    PORTD.OUT = B01010000 ;//digitalWrite(5, LOW);
    
    bldcphasecount = bldcphasecount + 1 ;
    }
    else if (bldcphasecount < rpmmotor)
    {
     
      bldcphasecount = bldcphasecount + 1 ;
    }
    else
    {
      bldcstate = ACCEL3 ;
      bldcphasecount = 0 ;
    }
     
     
     break ;

     case ACCEL3 :

// odd states commute cmds
    if (bldcphasecount < rpmmotor)
    {
      bldcphasecount = bldcphasecount + 1 ;
      
    }
    else
    {
      //freecount = 0 ;
      bldcstate = ACCEL4 ;
      bldcphasecount = 0 ;
    }
     
     
     break ;

     case ACCEL4 :

     if (bldcphasecount == 0)
    {

      //*AccelFuncptr[bldcphasecount] ;
    
    PORTB.OUT = (B00000010 | PORTB.OUT);//PORTD = B01011000 ;//digitalWrite(3, HIGH);
    
    bldcphasecount = bldcphasecount + 1 ;
    }
    else if (bldcphasecount < rpmmotor)
    {
      
      bldcphasecount = bldcphasecount + 1 ;
    }
    else
    {
      bldcstate = ACCEL5 ;
      bldcphasecount = 0 ;
    }
     
     
     break ;

     case ACCEL5 :

     // odd states commute cmds
    if (bldcphasecount < rpmmotor)
    {
      bldcphasecount = bldcphasecount + 1 ;
      
    }
    else
    {
       //freecount = 0 ;
       bldcstate = ACCEL6 ;
      bldcphasecount = 0 ;
    }
     
     break ;

     case ACCEL6 :

     if (bldcphasecount == 0)
    {

      //*AccelFuncptr[bldcphasecount] ;
    
    PORTD.OUT = B01000000 ;//digitalWrite(4, LOW);
    
    bldcphasecount = bldcphasecount + 1 ;
    }
    else if (bldcphasecount < rpmmotor)
    {
      
      bldcphasecount = bldcphasecount + 1 ;
    }
    else
    {
      bldcstate = ACCEL7 ;
      bldcphasecount = 0 ;
    }
     
     
     break ;

     case ACCEL7 :

     // odd states commute cmds
    if (bldcphasecount < rpmmotor)
    {
      bldcphasecount = bldcphasecount + 1 ;
      
    }
    else
    {
      //freecount = 0 ;
      bldcstate = ACCEL8 ;
      bldcphasecount = 0 ;
    }
     
     
     break ;

     case ACCEL8 :
     if (bldcphasecount == 0)
    {

      //*AccelFuncptr[bldcphasecount] ;
    
    PORTD.OUT = B01100000 ;//digitalWrite(5, HIGH);
    
    bldcphasecount = bldcphasecount + 1 ;
    }
    else if (bldcphasecount < rpmmotor)
    {
      
      bldcphasecount = bldcphasecount + 1 ;
    }
    else
    {
      bldcstate = ACCEL9 ;
      bldcphasecount = 0 ;
    }
      
      
     break ;

     case ACCEL9 :

     // odd states commute cmds
    if (bldcphasecount < rpmmotor)
    {
      bldcphasecount = bldcphasecount + 1 ;
      
    }
    else
    {
      //freecount = 0 ;
      bldcstate = ACCEL10 ;
      bldcphasecount = 0 ;
    }
     
     break ;

     case ACCEL10 :

     if (bldcphasecount == 0)
    {

      //*AccelFuncptr[bldcphasecount] ;
    
    PORTB.OUT = (B11111101 & PORTB.OUT);//PORTD = B01100000; //digitalWrite(3, LOW);
    
    bldcphasecount = bldcphasecount + 1 ;
    }
    else if (bldcphasecount < rpmmotor)
    {
      
      bldcphasecount = bldcphasecount + 1 ;
    }
    else
    {
      bldcstate = ACCEL11 ;
      bldcphasecount = 0 ;
    }
      
     
     
     break ;

     case ACCEL11 :

     // odd states commute cmds
    if (bldcphasecount < rpmmotor)
    {
      bldcphasecount = bldcphasecount + 1 ;
      
    }
    else
    {
      //freecount = 0 ;
      bldcstate = ACCEL12 ;
      bldcphasecount = 0 ;
    }
     
     break ;

     case ACCEL12 :

      if (bldcphasecount == 0)
    {

      //*AccelFuncptr[bldcphasecount] ;
    
    PORTD.OUT = B01110000; //digitalWrite(4, HIGH);
    
    bldcphasecount = bldcphasecount + 1 ;

//or BEMF1 if RPM exceeds BEMFTHR
    
    }
    else if (bldcphasecount < rpmmotor)
    {
      
      bldcphasecount = bldcphasecount + 1 ;
    }
    else
    {
      bldcstate = ACCEL1 ;
      rpmmotor = rpmmotor1;
      bldcphasecount = 0 ;
    }
      
     
     
     break ;
    
       
     case DECEL :
     break ;

    case BEMF1 :

     
        
     break ;

    default :  
    bldcstate = STOP ;
    bldcphasecount = 0 ;
    break ;
      
  }
  

}






 
  void loop() 
  { 
     
     // Empty. Things are done in Tasks. 
  } 
  
 
  //*--------------------------------------------------*/ 
 // /*---------------------- Tasks ---------------------*/ 
 // /*--------------------------------------------------*/ 
  
 
  void TaskDigitalRead( void *pvParameters __attribute__((unused)) )  // This is a Task. 
  { 
     
    //digitalWrite(ledPin, LOW);
    //freecount = 0 ;
     //start motor PWM cmd only
      TCB0.CTRLA = 0x05 ; //starts clk io to timer2 //16Mhz
      //change1 = 0;
      //change2 = 0;
      //change0 = 0;
    
    for (;;) // A Task shall never return or exit. 
    { 
      // read the input pin: 
      
    //digitalWrite(ledPin, Leddrive);

        // Leddrive = !Leddrive ;

           // Motor control portion

      // them monitor logic - exit - BATTERY VALUE 670 decimal is good for stop motor control or 660.

  
  // based on RC o/p for motor logic/direction change for sterr+drive, set direction for motor.example only below .all info from Serial port Rx Task
  // first to stop PWM:


  


/******************************************

  if (PrevledState != ledState)
  {

  if (ledState == LOW) 
  {
      // print the results to the Serial Monitor:
      digitalWrite(7, HIGH); 
      if (MotorDelay < 8)
        {
          MotorDelay = MotorDelay + 1 ;
          
        }
        else
        {
  
        MotorDelay = 0 ;
        //delay(100);
        digitalWrite(8, LOW);//6 shud opeartw
        PrevledState = ledState ;
        if (ledState == LOW) {
      
      //analogWrite(6, outputValue);
  
  
    } else {
      
      //analogWrite(5, outputValue);
  
    }
        
        // See if we can obtain or "Take" the Serial Semaphore. 
      // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
      if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { 
        // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
        // We want to have the Serial Port for us alone, as it takes some time to print, 
        // so we don't want it getting stolen during the middle of a conversion. 
        // print out the state of the button:

          if (ledState == LOW) 
         {
      
            Serial.println("\n\t MotorControl = Forward");
  
  
         } 
         else
         {
      
            Serial.println("\n\t MotorControl = Reverse"); 
  
         } 
        
         
 
        xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
              }
        
        }
  
  
    } 
    else
    {
      // print the results to the Serial Monitor:
  digitalWrite(8, HIGH);
       if (MotorDelay < 8)
        {
          MotorDelay = MotorDelay + 1 ;
          
        }
        else
        {
  
        MotorDelay = 0 ;
        //delay(100);
        digitalWrite(7, LOW);// 5 shud operaTE
        PrevledState = ledState ;
        if (ledState == LOW) {
      
      //analogWrite(6, outputValue);
  
  
    } else {
      
      //analogWrite(5, outputValue);
  
    }
        
        // See if we can obtain or "Take" the Serial Semaphore. 
      // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
      if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { 
        // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
        // We want to have the Serial Port for us alone, as it takes some time to print, 
        // so we don't want it getting stolen during the middle of a conversion. 
        // print out the state of the button:

          if (ledState == LOW) 
         {
      
            Serial.println("\n\t MotorControl = Forward");
  
  
         } 
         else
         {
      
            Serial.println("\n\t MotorControl = Reverse"); 
  
         } 
        
         
 
        xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
              }
        
        }
      
  
    }

  
         
    } 

***************************/


     
     
     
    
     
     
     
     
     
     
     
 /**    
     
     
     
     //Battery Monitor portion
        if (count < 8)
        {
          ADMUX |= 0x07 ; //0x47 ; // repeat in isr cpde for A7
          ADCSRA = 0xDF ; //SOC BIT 6
          
          
          //sensorValue1[count] = analogRead(analogInPin);
          
          
        }
        else
        {
  
        count = 0 ;
        sensorValue = 0 ;
        while(count < 8)
        {
            sensorValue += sensorValue1[7][count] ; 
            count = count + 1 ;
        }

        sensorValue = (sensorValue >> 3) ;
  
        count = 0 ;

       
        if (sensorValue >= 500)
        {
  // map it to the range of the analog out, ready for supply voltage based Pwm Control, extend 4 or 5 sample averaging here.
          outputValue = map(sensorValue, 600, 750, 255, 0);
  // 490 coreesponds to 4.5 volts, aref=3.3volts, 22k/12k
  //outputValue = (255 - outputValue) ;

  //outputValue = (outputValue >> 1) ;
  
  // inkl logic for battery cut off...or warning or stop control of motor

          if (outputValue > 255)
          {
            outputValue = 255 ;
          }
          else if (outputValue < 0)
          {
            outputValue = 0 ;
          }

          if (outputValue != 0)
          {
            outputValue = (outputValue >> motorspeed_state) ;
          }

          
          if (simplecnt <= 57)
          {
            simplecnt = simplecnt + 1 ;
          }
          else
          {
            simplecnt = 0 ;
          // See if we can obtain or "Take" the Serial Semaphore. 
      // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
          if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { 
              // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
              // We want to have the Serial Port for us alone, as it takes some time to print, 
             // so we don't want it getting stolen during the middle of a conversion. 
           // print out the value you read: 
             //Serial.println("\n\t  Sensor Value");
             Serial.println(sensorValue); 

            // Serial.println("\n\t PWM Value");
             //Serial.println(outputValue);

              xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others. 
             }
          }
        }
        else
        {
          outputValue = 0 ;  
          if (sensorValue < 580)
          {
            
            if (simplecnt <= 9)
          {
            simplecnt = simplecnt + 1 ;
          }
          else
          {
            simplecnt = 0 ;
            // See if we can obtain or "Take" the Serial Semaphore. 
            // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
            if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { 
              // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
              // We want to have the Serial Port for us alone, as it takes some time to print, 
             // so we don't want it getting stolen during the middle of a conversion. 
             // print out the value you read: 
              Serial.print("\n\t battlow");
              
             // Serial.print("     sensor = ");
              Serial.print(sensorValue);

             // Serial.println("\n\t\t    ");
              //Serial.println(outputValue);

              xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
              }
          }
        }
          
       }
      }

**/
       //serial port checks...

        // See if we can obtain or "Take" the Serial Semaphore. 
      // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
      
        // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
        // We want to have the Serial Port for us alone, as it takes some time to print, 
        // so we don't want it getting stolen during the middle of a conversion. 
        // print out the state of the button: 
        if (Serial.available())
        {
            Rxport = Serial.read();
             
           if (Rxport == '0')
           {
             motorspeed_state = GEAR0 ;
             rpmmotor1 = 350 ;
           }
           else if (Rxport == '1')
           {
             motorspeed_state = GEAR1 ;
             rpmmotor1 = 300 ;
           }
           else if (Rxport == '2')
           {
             motorspeed_state = GEAR2 ;
             rpmmotor1 = 250 ;
           }
           else if (Rxport == '3')
           {
             motorspeed_state = GEAR3 ;
             rpmmotor1 = 200 ;
             
           }
           else if (Rxport == '+')
           {
            //OCR1A += 5 ;
           // OCR2B += 5 ;// duty cycle
           }
            else if (Rxport == '-')
           {
            //OCR1A -= 5 ;
            //OCR2B -= 5 ;// duty cycle
           }
          
        if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
             { 

            Serial.println("\n\t RXPORT");
          Serial.println(Rxport);
          //Serial.println(OCR1A);
       //Serial.println(OCR2B);
          //Rxport1 = Rxport;
          xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
              }
        } 

        
        
       // xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others. 
       //}
       


       

     

        
 

    
        
        /**if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
                  // We want to have the Serial Port for us alone, as it takes some time to print, 
                  // so we don't want it getting stolen during the middle of a conversion. 
                  // print out the state of the button: 
                  //Serial.println("\n\t PushButton = LOW");
                  //ledState = !ledState ;
                    Serial.println("\n\t Pressed");//Serial.println(buttonState); 
                    //stateofbutton = POSTPRESSLOOK ;
 
                  xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
                  
              }*
              */

         
         vTaskDelay( SCHEDULING_TIMER / portTICK_PERIOD_MS );//pdMS_TO_TICKS()
         //vTaskDelay( pdMS_TO_TICKS(16.6) );
         
    }

}
  
void TaskHumbleRead( void *pvParameters __attribute__((unused)) )  // This is a Task.
{

    for (;;) // A Task shall never return or exit. 
    { 

 
     //push button read portion

    switch(stateofbutton)
    {
      case PRESSLOOK :
        if(loccount <= KEYPRESSCOUNT)
        {
          buttonState[loccount] = digitalRead(pushButton); 
          loccount = loccount + 1 ;
        }
        else
        {
          stateofbutton = PRESS ;
        }
      
        break ;
      
      case PRESS :
      ButtonState = LOW ;
      loccount = KEYPRESSCOUNTLOW ;
        while(loccount <= KEYPRESSCOUNTHIGH)
        {
            if ( !buttonState[loccount] )
            {
              loccount = loccount + 1 ;
            }
            else
            {
               // See if we can obtain or "Take" the Serial Semaphore. 
               // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
              
                  // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
                  // We want to have the Serial Port for us alone, as it takes some time to print, 
                  // so we don't want it getting stolen during the middle of a conversion. 
                  // print out the state of the button: 
                  //Serial.println("\n\t PushButton = HIGH");
                  
                    
                  
                  //Serial.println(buttonState); 
  
 
                  //xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
                  loccount = 0 ;
                  ButtonState = HIGH ;
                  break ; 
              
              
            }

             
        }

              if(ButtonState)
              {
                ButtonState = LOW ;
                stateofbutton = PRESSLOOK ;
              }
              else
              {
                 ledState = !ledState ;
                 stateofbutton = POSTPRESSLOOK ;
                 if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
                  // We want to have the Serial Port for us alone, as it takes some time to print, 
                  // so we don't want it getting stolen during the middle of a conversion. 
                  // print out the state of the button: 
                  //Serial.println("\n\t PushButton = LOW");
                  //ledState = !ledState ;
                    Serial.println("\n\t PushButton = Pressed");//Serial.println(buttonState); 
                    //stateofbutton = POSTPRESSLOOK ;
 
                  xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
                  
              } 
               
              loccount = 0 ;
              
              }
              
      
      break;



     case POSTPRESSLOOK :
     
        if(loccount <= KEYPRESSCOUNT)
        {
          buttonState[loccount] = digitalRead(pushButton); 
          loccount = loccount + 1 ;
        }
        else
        {
          stateofbutton = POSTPRESS ;
        }
      
        break ;


     case POSTPRESS :
     ButtonState = LOW ;
     loccount = KEYPRESSCOUNTLOW ;
     while(loccount <= KEYPRESSCOUNTHIGH)
        {
            if ( buttonState[loccount] )
            {
              loccount = loccount + 1 ;
            }
            else
            {
               // See if we can obtain or "Take" the Serial Semaphore. 
               // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
              
                  // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
                  // We want to have the Serial Port for us alone, as it takes some time to print, 
                  // so we don't want it getting stolen during the middle of a conversion. 
                  // print out the state of the button: 
                  //Serial.println("\n\t PushButton = HIGH");
                  
                    
                  
                  //Serial.println(buttonState); 
  
 
                  //xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
                  loccount = 0 ;
                  stateofbutton = POSTPRESSLOOK ;
                  ButtonState = HIGH ;
                  break ; 
              
              
            }

             
        }

        if(ButtonState)
              {
                ButtonState = LOW ;
               // stateofbutton = LOOK ;
              }
              else
              {
                 
                    stateofbutton = PRESSLOOK ;
 
                  
                  
              }  
               
              loccount = 0 ;
              
              
     break ;
      
    }
    
        
              
        
            
      
        if (humblecount <= 6)
          {
            humblecount = humblecount + 1 ;
          }
          else
          {
            
            switch (RampCntrl)
            {
                case ASCEND :
                if (rpmmotor1 >= 25)
                {
                  rpmmotor1 -= 5 ;
                }
                else
                {
                  //RampCntrl = DESCEND ;
                  //rpmmotor1 = rpmmotor1 ;//rpmmotor1 += 5 ;
                  RampCntrl = SLOW ;
                }
                break ;

                case DESCEND :
                if (rpmmotor1 <= 400)
                {
                  rpmmotor1 += 5 ;
                }
                else
                {
                  RampCntrl = ASCEND ;
                  rpmmotor1 -= 5 ;
                }
                break ;

                case SLOW :
                if (rpmmotor1 > FINEDINE)
                {
                  rpmmotor1 -= 1 ;
                  //PCICR = 0x07 ; // pc interrupts enabled....
                }
                else
                {
                  
                  //RampCntrl = DESCEND ;
                  //rpmmotor1 = rpmmotor1 ;
                  // See if we can obtain or "Take" the Serial Semaphore. 
      // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free. 
          if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 1 ) == pdTRUE ) 
              { 
              // We were able to obtain or "Take" the semaphore and can now access the shared resource. 
              // We want to have the Serial Port for us alone, as it takes some time to print, 
             // so we don't want it getting stolen during the middle of a conversion. 
           // print out the value you read:
                if(k == 0)
                { 
                  Serial.println("\n\t  PCINT 0    :");
                  Serial.println(Period0) ;
                  k += 1 ;
                }
                else if(k == 1)
                {
                  Serial.println("\n\t  PCINT 1    :");
                  Serial.println(Period1) ;
                  k += 1 ;
                }
                else if(k == 2)
                {
                  Serial.println("\n\t  PCINT 2    :");
                  Serial.println(Period2) ;
                  k += 1 ;
                }
                else if(k == 3)
                {
                  Serial.println("\n\t  TIMER1_OVFF    :");
                  Serial.println(Period2) ;
                  k = 0 ;
                }
                
              xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others. 
             } 
             
                  if(ADcount > 12)
                  {
                     ADcount = 0 ;
                  }
                  //rpmmotor1 += 5 ;
                  
                }
                break ;
             }
            
            
            /**if(OCR1A >= 0x000B)
            {
              OCR1A -= 0x000A ; // duty cycle value
            }
            else if (OCR1A >= 0x0180)
            {
              OCR1A += 0x000A ; // duty cycle value
            } **/
            
            humblecount = 0 ;
          
          }
        
    // void BushButtonRead() ;
    vTaskDelay( SCHEDULING_TIMER_BLDC / portTICK_PERIOD_MS );
    // vTaskDelay( 1000 / portTICK_PERIOD_MS ); 
     //vTaskDelay( 10 ); 
    } 

    
}

// HERE THE ERROR MESSAGES BELOW :
Arduino: 1.8.13 (Windows 10), Board: "Arduino Nano Every, None (ATMEGA4809)"

WARNING: library FreeRTOS claims to run on avr architecture(s) and may be incompatible with your current board which runs on megaavr architecture(s).

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:58:14: error: conflicting types for 'TCB_t'

 typedef void TCB_t;

              ^~~~~

In file included from c:\users\vijaymargret\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\io.h:677:0,

                 from C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:32:

c:\users\vijaymargret\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\iom4809.h:1719:3: note: previous declaration of 'TCB_t' was here

 } TCB_t;

   ^~~~~

In file included from c:\users\vijaymargret\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\io.h:99:0,

                 from C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:32:

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c: In function 'wdt_interrupt_enable':

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:96:36: error: 'WDCE' undeclared (first use in this function); did you mean 'ADC0'?

                 "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),

                                    ^

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:96:36: note: each undeclared identifier is reported only once for each function it appears in

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:96:58: error: 'WDE' undeclared (first use in this function); did you mean 'WDCE'?

                 "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),

                                                          ^

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:98:29: error: 'WDIF' undeclared (first use in this function); did you mean 'WDE'?

                         _BV(WDIF) | _BV(WDIE) | (value & 0x07)) )

                             ^

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:98:41: error: 'WDIE' undeclared (first use in this function); did you mean 'WDIF'?

                         _BV(WDIF) | _BV(WDIE) | (value & 0x07)) )

                                         ^

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\tasks.c:429:3: error: conflicting types for 'TCB_t'

 } TCB_t;

   ^~~~~

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c: In function 'wdt_interrupt_reset_enable':

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:162:36: error: 'WDCE' undeclared (first use in this function); did you mean 'ADC0'?

                 "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),

                                    ^

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:162:58: error: 'WDE' undeclared (first use in this function); did you mean 'WDCE'?

                 "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),

                                                          ^

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:164:29: error: 'WDIF' undeclared (first use in this function); did you mean 'WDE'?

                         _BV(WDIF) | _BV(WDIE) | _BV(WDE) | (value & 0x07)) )

                             ^

C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\port.c:164:41: error: 'WDIE' undeclared (first use in this function); did you mean 'WDIF'?

                         _BV(WDIF) | _BV(WDIE) | _BV(WDE) | (value & 0x07)) )

                                         ^

In file included from c:\users\vijaymargret\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\io.h:677:0,

                 from C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\FreeRTOSConfig.h:32,

                 from C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\Arduino_FreeRTOS.h:64,

                 from C:\Users\VijayMargret\OneDrive\Documents\Arduino\libraries\FreeRTOS\src\tasks.c:39:

c:\users\vijaymargret\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\iom4809.h:1719:3: note: previous declaration of 'TCB_t' was here

 } TCB_t;

   ^~~~~

exit status 1

Error compiling for board Arduino Nano Every.



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Full code please (without all the unrelated stuff); you can edit your post :wink:

And preferably split the error messages from the code.

That seems fairly self-explanatory. What is your question?

edited my post and pasted full code and below that pasted the errors.

Note : there is lot of commented code in the code section which are stuff that i dont need for the porting project

Yes, what i want ? that is exactly the title of this post..."FreeRTOS library that will work on Nano every board"
pls point me to or send me a link where i can get a FreeRTOS Library that will work with the mega AVR controllers/nano every baord, if this library that i have is incompatible....

sterretje, b4 i try Delta_G suggestiuon, any hope with the current freertos librarry i have and code i have posted...

the atmega4809 register set porting is complete, i am only held up by the freertos implements. let me know. thanks

1. Will you please tell/post the tasks (like acquiring ADC-Ch0 and blinking a LED) that you want execute concurrently using Arduino NANO Every Board and FreeRTOS?

2. You can accomplish the tasks of Step-1 using millis() function and yet you want to use FreeRTOS. Is it an exercise or application need?

3. Usually, the FreeRTOS automatically goes with ESP32 system.

ok here are some answers.

it is an application and i want to use freertos for better multi tasking execution for a handful of digital filtering/math purposes in parallel. using millis() to lock up the CPU in sequential execution within the main loop scheduler is not efficient.

the application has the following needs : i need a dedicated PWM channel - TCB0 for driving the o/p of the application.
the final o/p of the application via PWM needs to be generated via mathematically eqns w.r.t time domain.

The freertos multi tasks cud help me meet the derivation of the time domain based math eqns easily.
if i have to do the appl w/o Freertos then i wud have to set up individual timer interrupts, etc to derive what i need and makes the coding of the project more complex....hence i prefer the FreeRTOS to make it easier for the application

Fine!

Why do you want to use 8-bit Arduino NANO Every Board instead of 32-bit ESP32 Board which is integrated with FreeRTOS?

simple -- my application and target hardware costs are better served with the Nano Every, compared to the ESP32 that is expensive compared to Nano boards. I cant plug an expensive board just to run freertos.

btw, the nano board controller, very basic uC on that board, had a successful Freertos library and the ATmega4809 has far better clking and performance than that uC to run a freeRTOS kernel...maybe that good library availability is a hurdle for me now. definitely the ATmega4809 packs a punch in that every board and at reasonable price too!!

1 Like

Where have you looked? Lots of ESP32 boards are dirt cheap.

The AVR FreeRTOS port uses the Watchdog timer in interrupt mode as its preemption clock tick.

The ATmega4809 on the Arduino Every has a different watchdog timer implementation that doesn't HAVE an interrupt mode (in addition to needing different configuration instructions, even if it did.)

This is a problem.

The "obvious" solution is to replace the WDT periodic interrupt with an interrupt from the 4809's "Periodic Interrupt Timer" (Part of the RTC peripheral, which doesn't exist on older AVRs.) This is what the linked info in Post #9 does. If you're not using the Timer0 options in FreeRTOS, and are not using the RTC in the 4809, I'd think it would work fine.

Whether that code (or some variant thereof) is dependent on the attention and willingness of the Arduino FreeRTOS library maintainer. There is an "issue" for this, with some relevant discussion: `megaavr` support · Issue #88 · feilipu/Arduino_FreeRTOS_Library · GitHub

Hi gfvalvo, i am at least looking at the 2 attached price tag comparisons between the ESP32 and Every board.. if there is still a cheaper ESP32 board than the every board, i might then consider it...let me know
Note : (the ESP32 board will be power-hungry compared to the every board to start with)


Hi Golam, u deleted ur post, but, anyways, i just posted some price comparison b/w the every and the ESP32 and the every is definitely less costlier than the esp32

This is just a local distributor but it gives an indication. Rough conversion rate 20-to-1 so it costs around $2.50.

Hi Westfw, looks like the ATmega4809 might never get a working version of Freertos from all that i cud gather from the discussions...in that Richard barry's release folder

I prefer the boards from Adafruit. They're a little pricier than the made-in-China stuff, but they're made in America and Adafruit has an active support forum with employee participation. Shipping is also quicker as they don't take a slow boat from China. Adafruit has more than a dozen ESP32-based boards. I'm currently using This One.