[freertos - Open Discussion and Support] FreeRTOS Port For ATmega32

26 views
Skip to first unread message

SourceForge.net

unread,
Nov 20, 2011, 10:43:37 AM11/20/11
to SourceForge.net

Read and respond to this message at:
https://sourceforge.net/projects/freertos/forums/forum/382005/topic/4829539
By: balace

I am doing a project on Atmega32. I am suppose to use FreeRTOS. I started off
with the demo
project for Atmega323 and later removed the demo project files and
included mine. It all works fine and runs without errors(I am using WinAVR
and AVRStudio5).
The problem I have is running more than one task. I created
two tasks(one puts ON some LEDs and then delays for about 250ms, and the other
puts OFF
the LEDs and also delays) and just one works. There is no preemption
since I created both tasks with thesame priorities. Even at different
priorities, it still doesn't work. Preemption is enabled in the config file.
I would like to seek your help and advice because I have tried all I can
to no avail.

I found out also that FreeRTOS in my case is low-active(e.g DDRA = 0xFF
sets it as input instead) don't know why.

_____________________________________________________________________________________
You are receiving this email because you elected to monitor this topic or entire forum.
To stop monitoring this topic visit:
https://sourceforge.net/projects/freertos/forums/forum/382005/topic/4829539/unmonitor
To stop monitoring this forum visit:
https://sourceforge.net/projects/freertos/forums/forum/382005/unmonitor

SourceForge.net

unread,
Nov 21, 2011, 9:21:13 AM11/21/11
to SourceForge.net
By: richardbarry

How are you implementing the delays? Using the vTaskDelay/vTaskDelayUntil or
using a different method?

Can you post your code?

Regards.

SourceForge.net

unread,
Nov 21, 2011, 1:03:47 PM11/21/11
to SourceForge.net
By: balace

Thanks for the quick reply Mr Barry, I am using vTaskDelayUntil, though I also
tried with vTaskDelay and it still did not work.
Below are the tasks and some changes I made in the makefile of ATmega323 to
suit ATmega32
NB: I am using an STK500 board
********************************************************************************
********************

Task A:

void taskA(void *pV)
{
char *name;
name = (char*)pV;
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();

DDRA = 0x00; // 8 Switches are connected to this port but are not used for
this task
DDRC = 0xFF; // Eight LEDs are connected to this port


for(;;)
{
//TODO:: Please write your application code

PORTC = 0xFF;
vTaskDelayUntil(250/portTICK_RATE_MS);

}
}

********************************************************************************
********************

Task B:

void taskB(void *pV)
{
char *name;
name = (char*)pV;
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();


for(;;)
{
//TODO:: Please write your application code

PORTC = 0xFF;
vTaskDelayUntil(250/portTICK_RATE_MS); // 250ms Delay

}
}



********************************************************************************
********************
Main File:

#include <avr/io.h>
#include <util/delay.h>
#include "FreeRTOS.h"
#include "list.h"
#include "task.h"
#include "queue.h"
#include "croutine.h"
#include "timers.h"
#include "FreeRTOSConfig.h"
#include "taskA.h"
#include "taskB.h"
#include <avr/portpins.h>
#include "portable.h"
#include "timers.h"


int main(void)
{
DDRA = 0x00; // set port A as Input (switches are connected
to this port)
DDRC = 0xFF; // set port B as Output (LEDs are connected to
this port)

const signed char *Task_A= (const signed char *)("My_TaskA");
const signed char *Task_B= (const signed char *)("my_TaskB");

xTaskCreate(taskB, Task_A, 1000, NULL, 2, NULL ); // creates TaskB
xTaskCreate(taskA, Task_B, 1000, NULL, 2, NULL ); // creates
TaskA

vTaskStartScheduler(); // starts the Task Scheduler
for( ;; );
}



********************************************************************************
********************
For the make file, the demo files were commented out and my files included.
As seen below, the target and MCU name was changed amongst others. What ever
is not shown here means it wasn't altered and remains thesame for ATmega323
demo.

Makefile:


F_CPU = 8000000
# MCU name
MCU = atmega32

# Output format. (can be srec, ihex, binary)
FORMAT = ihex

# Target file name (without extension).
TARGET = AVR32PROJECT

# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = 0


# List C source files here. (C dependencies are automatically generated.)
DEMO_DIR = ../Common/Minimal
SOURCE_DIR = ../../Source
PORT_DIR = ../../Source/portable/GCC/ATMega32

SRC = \
AVR32PROJECT.c \
taskA.c \
taskB.c \
$(SOURCE_DIR)/tasks.c \
$(SOURCE_DIR)/queue.c \
$(SOURCE_DIR)/list.c \
$(SOURCE_DIR)/croutine.c \
$(SOURCE_DIR)/timers.c \
$(SOURCE_DIR)/portable/MemMang/heap_1.c \
$(PORT_DIR)/port.c

#$(DEMO_DIR)/crflash.c \
#$(DEMO_DIR)/integer.c \
#$(DEMO_DIR)/PollQ.c \
#$(DEMO_DIR)/comtest.c
#main.c \
#ParTest/ParTest.c \
#serial/serial.c \
#regtest.c \


AVRDUDE_PROGRAMMER = stk500


Thanks and I gladly await your support

SourceForge.net

unread,
Nov 21, 2011, 4:34:11 PM11/21/11
to SourceForge.net
By: edwards3

Both tasks are setting port C to the same value. Is that intended.
Have you checked that xTaskCreate() is returning pdPASS? Maybe only one task
is created.

SourceForge.net

unread,
Nov 21, 2011, 5:00:27 PM11/21/11
to SourceForge.net
By: balace

hi edwards3, thanks for your reply...that wasn't intended. TaskB was meant to
set PORTC to 0x00. Its a typo.
As per your suggestion...If i create just TaskA (without TaskB), everything
works fine, like wise if i create TaskB without TaskA, it also works fine. The
problem comes when I create both. It seems to "hang" with the first task created.
If TaskA is created first, just TaskA runs...which means the LEDs remain ON.
If TaskB is created first, The LEDs remain OFF.

SourceForge.net

unread,
Nov 23, 2011, 4:37:40 AM11/23/11
to SourceForge.net

Thanks to you all for your efforts...I found a solution to this problem...the
stack depth is too big. After reducing this value to 500 for both tasks, everything
worked fine. Any value below 500 or for both tasks that summed up to 1000(e.g
700:300, 600:400, 500:500, etc) was ok

Reply all
Reply to author
Forward
0 new messages