C++ operator 'new' causing lpc2138 to abort
I am trying to write a class that uses the c++ operator 'new', however I realised that each time the new operator is called the lpc2138/01 stalls and goes into an abort routine.
Does the new operator not work in CrossWorks or is there another way I could write the code to get around this.
I am trying to implement a Singleton Class for use in the lpc2138.
with
Timing * Timing::getInstance() {
if(instance == 0){
instance = new Timing();
}
return instance;
}
-
Check that you've allocated enough heap to store the object.
See http://rowley.zendesk.com/entries/46159-change-the-heap-size-of-my-application for a description of how you specify the heap size.
-
I have increased the heap size to 8kB, which is much more than enough, but it is still not working.
I have stepped throught the assembly code to where it looks like it enters an infinite loop. The infinite loop appears to start inside the <malloc> subroutine that is in the assembly code, and I am able to step throught the code until the instruction
ldr r3, [r0, #+0x004] //is called
here is the entire malloc subroutine in assembly code;
<malloc>:
E52DE004 str lr, [sp, #-0x004]!
E1A02000 mov r2, r0
E59F30B4 ldr r3, [pc, #+0x0B4]
E5930000 ldr r0, [r3]
E3500000 cmp r0, #0x00000000
0A000027 beq 0x00001AAC
E2823013 add r3, r2, #0x00000013
E3C3100F bic r1, r3, #0x0000000F
E5903004 ldr r3, [r0, #+0x004] <---- infinite loop appears to start here
E1510003 cmp r1, r3
11A02000 movne r2, r0
13A0E000 movne lr, #0x00000000
13E0C000 mvnne r12, #0x00000000
1A00000D bne 0x00001A64
EA000006 b 0x00001A4C
E5903004 ldr r3, [r0, #+0x004]
E1510003 cmp r1, r3
1A000008 bne 0x00001A60
E3520000 cmp r2, #0x00000000
15903000 ldrne r3, [r0]
15823000 strne r3, [r2]
1A000002 bne 0x00001A58
E5902000 ldr r2, [r0]
E59F3060 ldr r3, [pc, #+0x060]
E5832000 str r2, [r3]
E4801004 str r1, [r0], #+0x004
EA000013 b 0x00001AB0
E1A02000 mov r2, r0
E1510003 cmp r1, r3
2A000002 bcs 0x00001A78
E15C0003 cmp r12, r3
81A0E002 movhi lr, r2
81A0C003 movhi r12, r3
E5920000 ldr r0, [r2]
E3500000 cmp r0, #0x00000000
1AFFFFEA bne 0x00001A30
E35E0000 cmp lr, #0x00000000
0A000007 beq 0x00001AAC
E59E3004 ldr r3, [lr, #+0x004]
E0613003 rsb r3, r1, r3
E58E3004 str r3, [lr, #+0x004]
E061300C rsb r3, r1, r12
E083200E add r2, r3, lr
E783100E str r1, [r3, +lr]
E2820004 add r0, r2, #0x00000004
EA000000 b 0x00001AB0
E3A00000 mov r0, #0x00000000
E49DE004 ldr lr, [sp], #+0x004
E12FFF1E bx lr
4000003C andmi r0, r0, r12, lsr r0
Please sign in to leave a comment.
Comments
4 comments