ARM7 compiler doing funny things
Hello,
I have a C++ class that is supposed to be taking care of the timing and PWM signal generation of the lpc2138 system, and I got it working in normal C then I decided to port it over to C++. Now the code is having all these funny but serious errors. It appears as though everytime a method is called from within the class the registers arent configured properly and it results in the overwritting of some of the registers, now this is pretty serious because the PWM signals that I am generating must hold the value they are given, however at the moment they seem to be doing what ever they want. This is just not working.
At the moment the problem looks like when a class method is called the stack pointer is set to the wrong part in memory and so that part of memory is overwritten, im not too sure why it does it but here is the part in the assembly code that does it.
E1A0C00D mov r12, sp
E92DD800 stmfd sp!, {r11-r12, lr-pc}
E24CB004 sub r11, r12, #0x00000004
E24DD008 sub sp, sp, #0x00000008
E50B0014 str r0, [r11, #-0x014]
right on that last line the PWM signal value is overwritten,
the data structure that I have is.
unsigned int32
unsigned char
unsigned char
unsigned int32[6] <--- PWM signals
structure *token_;
the memory address of these data is sequential so im very confused as to why this is happening.
-
A compilable piece of code would help.
E1A0C00D mov r12, sp
r12 = sp_0
E92DD800 stmfd sp!, {r11-r12, lr-pc}
sp = sp_0 - 16
E24CB004 sub r11, r12, #0x00000004r11 = sp_0 - 4
E24DD008 sub sp, sp, #0x00000008sp = sp_0 - 24
E50B0014 str r0, [r11, #-0x014]store r0 to sp_0 - 24
r0 is 'this' which is stored into the stack frame; it's not outside the stack frame.
-
when you say 'this' are you refering to the instance of the class, because if you are, please be aware that the method is a static method and there is no this being passed.
I have also attached the code that I have been using, it utilised the singleton type of class, where the Constructor is protected.
To call the Class methods use the form
Timing::getInstance()->(someMethod());
-
> when you say 'this' are you refering to the instance of the class, because if you are, please be aware that the method is a static method and there is no this being passed.
> To call the Class methods use the form
> Timing::getInstance()->(someMethod());Huh? If someMethod() is static then you don't need getInstance you just use Timing::someMethod(). If someMethod is not static and even if a singleton instance exists, then a 'this' is passed to someMethod().
You code is, unfortunately, buggy, so you need to read a C++ book.
Timing * Timing::getInstance() {if(instance == 0){Timing timer;instance = &timer;}return instance;}Timing * Timing::getInstance() { if(instance == 0){ Timing timer; instance = &timer; } return instance; }This creates a Timing object, you take a pointer to it, then the Timing object is destroyed. Your pointer dangles. You now have no Timing objects yet you are referring to a destructed one through 'instance' in your other methods.
-
>This creates a Timing object, you take a pointer to it, then the Timing object is destroyed. Your pointer dangles. You now have no Timing objects yet you are referring to a destructed one through 'instance' in your other methods.
This was my only option because the 'new' operator wasnt working properly I would have prefered to have the line being
instance = new Timing();
however this was resulting in the abort routine being called, i tried to increase the heap size but this didnt work.
-
I have had a quick look through all of your "How Do I..." posts that you have made, but there is nothing about ensuring that the heap is word-aligned, I have read the heap size post however this doesnt tell me how to ensure that the heap is word-aligned, and I am unsure in how to do that. This is the only code snipet that I could find that was relevant;
/* Initialise the heap */
ldr r0, = __heap_start__
ldr r1, = __heap_end__
sub r1, r1, r0
cmp r1, #8
movge r2, #0
strge r2, [r0], #+4
strge r1, [r0]this was taken from the basic crt0.s file that is supply with the lpc2138 package
-
I have tried to implement a placement new to allocate the memory, but that didnt seem to be the problem ( ie memory allocation). I tried to just do an
int *value = new int;
and this line still behaved in the same way as before, and since you are adamant that there is no bugs in the malloc code, the only logical next problem would be in my project configuration.
i think the configuration settings are in the .hzp file so i will upload that
Please sign in to leave a comment.
Comments
18 comments