Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

ATmega2560 Porting Help !!

Posted by Nobody/Anonymous on July 14, 2006
I've successfully ported you RTOS on my board equipped with ATMega1280 microcontroller and all seems to works great.
In my next project I need to use ATMega2560 microcontroller but when I try to port the OS on this device IAR compiler
gives me some warnings and demo software doesn't work.

I suppose that It is due to the different size of 2560 program counter register, but I'm not sure.

Is freeRTOS compatible with ATMega2560 ?

Thank you

RE: ATmega2560 Porting Help !!

Posted by Richard on July 15, 2006
I am not familiar with the 2560, but if the program counter is 3 bytes then this will definitely prevent the standard code from executing. I think this should be simple to fix.

Going into and out of interrupts the hardware will handle the three bytes. This area can therefore probably remain the same.

A change will definitely be required where the initial stack of the task is set up. Take a look in the function pxPortInitialiseStack() within Source/Portable/IAR/ATMega323. Here you will see the following code (I have taken out the casting to make it more readable):

///////////////////////////////////////////////////////////

The first part of the stack is the hardware stack. Place the start
address of the task on the hardware stack. */
usAddress = pxCode;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack--;

usAddress >>= 8;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack--;


/* Leave enough space for the hardware stack before starting the software
stack. The '- 2' is because we have already used two spaces for the
address of the start of the task. */
pxTopOfStack -= ( configCALL_STACK_SIZE - 2 );

///////////////////////////////////////////////////////////


This only places two bytes at the stop of the stack for the return address (in this case the start of the task). You will need to modify this to something like:

///////////////////////////////////////////////////////////

The first part of the stack is the hardware stack. Place the start
address of the task on the hardware stack. */
usAddress = pxCode;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack--;

usAddress >>= 8;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack--;


/* AND THE THIRD BYTE! */
usAddress >>= 8;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack--;

/* Leave enough space for the hardware stack before starting the software
stack. The '- 3' is because we have already used two spaces for the
address of the start of the task. */
pxTopOfStack -= ( configCALL_STACK_SIZE - 3 );

///////////////////////////////////////////////////////////

The size required by the hardware stack is going to be larger as each time the program counter is saved you will require an extra byte. It is likely therefore that you will want to increase the value of configCALL_STACK_SIZE.

Regards.

RE: ATmega2560 Porting Help !!

Posted by Nobody/Anonymous on July 18, 2006
Thank you Richard,

with your suggestion now your OS works also with ATMega 2560. I've done only an additional modification:

/* The number of bytes used on the hardware stack by the task start address. */
#define portBYTES_USED_BY_RETURN_ADDRESS( 3 )


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS