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


rtos on demo9s12xep100 (HCS12x) stack problem

Posted by Andrea Mantovani on September 7, 2010
hi all,
I've ported the freertos demo for HCS12 banked mode to the demo board DEMO9S12XEP100.
The code crashes at the instruction
__asm( "rti" );
inside function xBankedStartScheduler().

I found a funny thing that is:
"rti" instruction is declared to behave as:

(M(SP)) ⇒ CCR; (SP) + $0001 ⇒ SP
(M(SP) : M(SP+1)) ⇒ B : A; (SP) + $0002 ⇒ SP
(M(SP) : M(SP+1)) ⇒ XH : XL; (SP) + $0004 ⇒ SP
(M(SP) : M(SP+1)) ⇒ PCH : PCL; (SP) + $0002 ⇒ SP
(M(SP) : M(SP+1)) ⇒ YH : YL; (SP) + $0004 ⇒ SP

the Freertos function pxPortInitialiseStack() saves info in stack as specified above BUT once I execute the "rti"I I found that register values are wrong and application crashes.
I found that "rti" increments SP by 1 (SP+1 ) BEFORE doing what is declared !
I modified the pxPortInitialiseStack() in order to add a dummy byte in stack and everithing works !.
Find below the modified code for pxPortInitialiseStack():

portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
Place a few bytes of known values on the bottom of the stack.
This can be uncommented to provide useful stack markers when debugging.

*pxTopOfStack = ( portSTACK_TYPE ) 0x11;
*pxTopOfStack = ( portSTACK_TYPE ) 0x22;
*pxTopOfStack = ( portSTACK_TYPE ) 0x33;

/* Setup the initial stack of the task. The stack is set exactly as
expected by the portRESTORE_CONTEXT() macro. In this case the stack as
expected by the HCS12 RTI instruction. */

/* The address of the task function is placed in the stack byte at a time. */
*pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );
*pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );

/* Next are all the registers that form part of the task context. */

/* Y register */
*pxTopOfStack = ( portSTACK_TYPE ) 0xff;
*pxTopOfStack = ( portSTACK_TYPE ) 0xee;

/* X register */
*pxTopOfStack = ( portSTACK_TYPE ) 0xdd;
*pxTopOfStack = ( portSTACK_TYPE ) 0xcc;

/* A register contains parameter high byte. */
*pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );

/* B register contains parameter low byte. */
*pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );

/* CCR: Note that when the task starts interrupts will be enabled since
"I" bit of CCR is cleared */
*pxTopOfStack = ( portSTACK_TYPE ) 0x00;

/* WARNING: Mantovani: Added dummy byte cause RTI assembler instruction seems to be buged !!!! */
*pxTopOfStack = ( portSTACK_TYPE ) 0x00;

/* The page of the task. */
*pxTopOfStack = ( portSTACK_TYPE ) ( ( int ) pxCode );

/* Finally the critical nesting depth is initialised with 0 (not within
a critical section). */
*pxTopOfStack = ( portSTACK_TYPE ) 0x00;

return pxTopOfStack;

It doesn't seem a memory alignement issue rather that an "rti" hw implementation bug.
Is it possible or I'm doing something wrong ?

All suggestions are welcome.

RE: rtos on demo9s12xep100 (HCS12x) stack problem

Posted by Andrea Mantovani on September 7, 2010
found solution on forum:
The HCS12X has 2bytes CCR register and "rti" instruction behave like this:

(M(SP) : M(SP+1)) ⇒ CCRH : CCRL; (SP) + $0002 ⇒ SP
(M(SP) : M(SP+1)) ⇒ B : A; (SP) + $0002 ⇒ SP
(M(SP) : M(SP+1)) ⇒ XH : XL; (SP) + $0004 ⇒ SP
(M(SP) : M(SP+1)) ⇒ PCH : PCL; (SP) – $0002 ⇒ SP
(M(SP) : M(SP+1)) ⇒ YH : YL; (SP) + $0004 ⇒ SP

Will the RTOSDemo be updated for freescale CPU12X ?

RE: rtos on demo9s12xep100 (HCS12x) stack problem

Posted by Richard on September 7, 2010
Maybe one day - but I can say for sure it won't be any time soon - sorry.

If you update it, or find working code, you would be good enough to add it to the FreeRTOS Interactive site? http://interactive.freertos.org


RE: rtos on demo9s12xep100 (HCS12x) stack problem

Posted by Andrea Mantovani on September 8, 2010
I found that porting for HCS12X was already uploaded.
I didn't find it before.
Thanks a lot.

[ 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