Error using Heap2

emerico wrote on Sunday, December 11, 2005:

Hello,
On a FreeRTOS port on ADuC7026 in nonpreemtive mode using Heap_2 as Heap,
I can not correctly start a task after have allocated memory to a pointer.

Example:
If a write this:
/**********************************************/
3. xTaskCreate( vAbcsp_aduc_ABCSPLaunch, "ABCSP",
4. 100, NULL, ABCSP_PRIORITY, &xABCSPHANDLE);
/**********************************************/

then a will not have any problem. but if l first allocate memory to a pointer like this:

/***********************************************/
1. uint8* pointer = pvPortMalloc (sizeof(uint8*));
2. pointer[0] = 0x00;
3. xTaskCreate( vAbcsp_aduc_ABCSPLaunch, "ABCSP",
4. 100, NULL, ABCSP_PRIORITY, &xABCSPHANDLE);
/***********************************/

then a have a problem at line 3. (Especially in xTaskCreate where memory is allocated to the Task control block.)
Error:
/***************
Data Abort: Thumb Instruction at 000830F2H, Memory Access at 00C016E8H
****************************************/

Can somebody help me? any idea where the error is comming from?
Best regards
Emeric

nobody wrote on Sunday, December 11, 2005:

What are you using to debug your system with?  Are you able to step through the code?  If so can you find the line that is causing the problem?

The ADuC7026 is not a standard port, did you write it yourself?  If so, have you checked the startup code to ensure the processor is in the expected mode, and that the stacks are setup correctly?

emerico wrote on Sunday, December 11, 2005:

I am using the Keil debugger.

The error is:
in funktion xTaskCreate in tasks.c  at line:
pxNewTCB = prvAllocateTCBAndStack( usStackDepth );

in funktion prvAllocateTCBAndStack in tasks.c at line:
pxNewTCB = ( tskTCB * ) pvPortMalloc( sizeof( tskTCB ) );

in funktion pvPortMalloc in Heap_2.c at line:
Especially at line :
/* Insert the new block into the list of free blocks. */
prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );

Looking in startup.s i found this
/************************************

// <h> Stack Configuration (Stack Sizes in Bytes)
//   <o0> Undefined Mode      <0x0-0xFFFFFFFF:4>
//   <o1> Supervisor Mode     <0x0-0xFFFFFFFF:4>
//   <o2> Abort Mode          <0x0-0xFFFFFFFF:4>
//   <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:4>
//   <o4> Interrupt Mode      <0x0-0xFFFFFFFF:4>
//   <o5> User/System Mode    <0x0-0xFFFFFFFF:4>
// </h>
*/
        UND_Stack_Size  EQU     0x00000004
        SVC_Stack_Size  EQU     0x00000100
        ABT_Stack_Size  EQU     0x00000004
        FIQ_Stack_Size  EQU     0x00000004
        IRQ_Stack_Size  EQU     0x00000080
        USR_Stack_Size  EQU     0x00000200

AREA   STACK, DATA, READWRITE, ALIGN=2
        DS   (USR_Stack_Size+3)&~3  ; Stack for User/System Mode
        DS   (SVC_Stack_Size+3)&~3  ; Stack for Supervisor Mode
        DS   (IRQ_Stack_Size+3)&~3  ; Stack for Interrupt Mode
        DS   (FIQ_Stack_Size+3)&~3  ; Stack for Fast Interrupt Mode
        DS   (ABT_Stack_Size+3)&~3  ; Stack for Abort Mode
        DS   (UND_Stack_Size+3)&~3  ; Stack for Undefined Mode
Top_Stack:

/**********************************

and this.

/*************************************************

// Enter Supervisor Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_SVC|I_Bit|F_Bit
                MOV     SP, R0
                SUB     R0, R0, #SVC_Stack_Size

// Enter S Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_SYS
                MOV     SP, R0

// Start in supervisor mode
                MSR     CPSR_c, #Mode_SVC|I_Bit|F_Bit
// Enter the C code
                LDR     R0,=?C?INIT
                TST     R0,#1       ; Bit-0 set: main is Thumb
                LDREQ   LR,=exit?A  ; ARM Mode
                LDRNE   LR,=exit?T  ; Thumb Mode
                BX      R0
                ENDP

/*********************************************/

How to be sure to be sure that the stack is normally setted?
thank you in advance.