portCOPY_XRAM_TO_STACK on 8052 porting

superfede76 wrote on Monday, July 23, 2007:

I’m trying to port FreeRTOS on a generic 8052 MCU (AT89C51ED2), starting from Cygnal port. I’ve removed the reference to SFRpage, because is not present in this MCU. When xTaskCreate calls the prvAllocateTCBAndStack that calls the pvPortMalloc, the portCOPY_XRAM_TO_STACK macro cannot performs the copletly copy, because when it start the ucStackBytes value is zero, and after the first “do while” cycle, because underflow, it starts from 255 and before arrive to 0, the program restart whithout starting the tasks.


sotd wrote on Monday, July 23, 2007:

Maybe you are simply running out of RAM.  How much RAM does your 8051 have compared to the Cygnal on which the port was made?

superfede76 wrote on Tuesday, July 24, 2007:

I’ve used an At89c51id2 whith 1792 kByte of XRAM. Other porting run on microcontroller like pic18 with a smaller memory.

superfede76 wrote on Thursday, July 26, 2007:

excuse me: the XRAM memory is 1792 Byte and not “KByte”.
During debugging I’ve noted in the portCOPY_XRAM_TO_STACK macro the value of ucStackBytes = pxXRAMStack[ 0 ] is 0 and this causes a bad copy of ram into xram whith a coneguent reset.

adarkar9 wrote on Thursday, July 26, 2007:

Are you checking the return value of the call to xTaskCreate()?  Assuming that xTaskCreate() was able to allocate the required memory in prvAllocateTCBAndStack(), the subsequent call to pxPortInitialiseStack() should set up the task’s XRAM stack copy such that a call to portCOPY_XRAM_TO_STACK() would succeed.

Perhaps you don’t have enough heap space.  What value of configTOTAL_HEAP_SIZE are you using?  What tasks (along with stack sizes) are you trying to create?  The Cygnal demo application allocates 8 flash tasks, 4 semaphore tasks, 1 integer math task, 2 polled queue tasks, 2 com tasks, 4 semaphore tasks, 2 FLOP tasks, a register test task, an error check task, and the idle task, each with about 200 bytes of stack space.  That is roughly 5200 bytes of heap space before adding any of the queues, semaphores, or task structures (the Cygnal port allocates 6 KiB for the heap).  With only 1792 bytes of XRAM, you will have to cut way back on the number of tasks and/or size of stacks you use.

superfede76 wrote on Friday, July 27, 2007:

In my new porting i’ve used only a little test task because the little memory. This morning, during debuging I’ve discovered why this happens. When the first time the portYield is called, it make nothing (I don’t know the motivation), and no byte is saved into XRAM. When xPortStartScheduler call the macro portCOPY_XRAM_TO_STACK there is no data saved into XRAM, the ucStackBytes value is zero, Because in his position there is non data,  and the first decrementation cause his undeflow…
Now my problem is: why portYield make nothing. I’m working on this.