avr-os icon indicating copy to clipboard operation
avr-os copied to clipboard

Can't execute sample code on Mega2560

Open chalos opened this issue 9 years ago • 5 comments

Hi @chrismoos

I facing a problem when running sample code on Mega2560, which it's works on Uno.

Sample Code:

#include "Arduino.h"
#include <Wire.h> 
#include "LiquidCrystal/LiquidCrystal_I2C.h"
#include <util/delay.h>

extern "C" {
    #include "avros/os.h"
}
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

spinlock_t mutex;

void kernel_task(void *arg) {
    while(1) {
        spinlock_acquire(&mutex);
        lcd.setCursor(0, 0);
        lcd.print("kernel: " + String((long)os_get_uptime()));
        spinlock_release(&mutex);
        os_sleep(1000);
    }
}

void user_task(void *arg) {
    int x = 0;
    while(1) {
        spinlock_acquire(&mutex);
        lcd.setCursor(0, 1);
        lcd.print("user_task: " + String(x++));
        spinlock_release(&mutex);
        os_sleep(2000);
    }
}

void setup() {
    lcd.begin(16, 2);
    lcd.print("...");
    os_init();
}

void loop() {
    spinlock_init(&mutex);
    os_schedule_task(kernel_task, NULL, 0);
    os_schedule_task(user_task, NULL, 1);
    os_loop();
}

This is the result when running on Mega2560, it is stucking after calling os_init() image

But same code run on Uno, it is works... image

Thanks.

Chalos

chalos avatar Jun 13 '15 06:06 chalos

@chalos Any updates? My sample project doesn't work on a Funduino board (Mega 2560) when running from current master branch.

kneth avatar Nov 27 '16 17:11 kneth

@chalos @kneth how are you running it? Arduino IDE?

chrismoos avatar Feb 01 '17 06:02 chrismoos

Yes, I am using Arduino IDE 1.6.

kneth avatar Feb 01 '17 07:02 kneth

@kneth Different devices have different preprocessor definitions defined and the Arduino IDE doesn't use the Makefiles that set these.

For example in devices/arduino/mega2560 these are defined:

TARGET_OS_TASK_STACK_SIZE := 512
TARGET_OS_TICK_INTERVAL_MS := 10
TARGET_OS_MAX_TASKS := 18

You can try manually adding #define for these either in the Arduino global CFLAGS or in the actual avr source files.

chrismoos avatar Feb 01 '17 16:02 chrismoos

@chrismoos I'll give it a shot and report back.

kneth avatar Feb 02 '17 08:02 kneth