Quality RTOS & Embedded Software

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


Porting to ATMega644 for GCC

Posted by Hendrik Lachmann on April 30, 2007
I started to port FreeRTOS to ATMega644. Now I got stuck with the following simulation error "AVR Simulator: Invalid opcode 0x0053 at address 0x000017" (AVR Studio 4.13). This error occurs right after the first call to portRESTORE_CONTEXT() in function xPortStartScheduler (file port.c). Did anybody successfully port FreeRTOS to ATMega644 for GCC and could help me? Thanks.

What I did so far:
1) created new folder for ATMega644 and added #ifdef to portable.h
2) adjusted timer1 in port.c (it works)
3) added the third byte of program counter (PC) in function pxPortInitialiseStack (file port.c) as described at http://sourceforge.net/forum/message.php?msg_id=3823030. The PC of ATMega644 is three byte, but the highest program memory address is 0x007FFC. IMHO I can push just another 0x00 on the stack.
/* The start of the task code will be popped off the stack last, so place
it on first. */
usAddress = ( unsigned portSHORT ) pxCode;
*pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff );

usAddress >>= 8;
*pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff );

/* The third byte of program counter is always 0x00. */
*pxTopOfStack = ( portSTACK_TYPE ) 0x00;

(Just doing another 8-bit-shift didn't work because of compiler complaints: pxCode is a pointer to a 16bit integer.)

RE: Porting to ATMega644 for GCC

Posted by Nobody/Anonymous on April 30, 2007
Have you tried putting the extra byte first rather than last of the three. I have run code designed for 16bit program counter in the simulator when a 24bit program counter part was selected and it worked. It seemed illogical and I never worked out how come, but then I did not really study it that closely.

Failing that, can you step through the restore context assembly code and say at what point the error occurs?

RE: Porting to ATMega644 for GCC

Posted by Hendrik Lachmann on April 30, 2007
Putting the extra byte first results in the same error with just different opcode / address. That your code worked has most likely something to do with a different endianess.

Unfortunately, I can't step through the assembly code as the debugger doesn't support it (maybe there is a switch and I don't know about it?). The error actually occurs at "asm volatile ( "ret" );" after portRESTORE_CONTEXT().

I don't know how the stack is or should be organized for the ATMega644. Then I could check, if I see the expected values.

RE: Porting to ATMega644 for GCC

Posted by Hendrik Lachmann on May 1, 2007
After debugging I finally solved the problem:
1) Even though the PC of ATMega644 is 3 byte long (compared to 2 byte of ATMega32), an additional third byte for the PC must NOT be added in function pxPortInitialiseStack.
2) The simulator errors occured due to a stack overflow (a different problem)

RE: Porting to ATMega644 for GCC

Posted by kd5uwl on October 3, 2009
You say you adjusted Timer1 in port.c. Could you please share the specifics of that? I'm trying to port to the 1284p which is very much like the 644.


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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists