RTOS+ arm7 typecast problem

Hi, I use eclipse+yagarto+the exemple RTOS "ARM7_AT91SAM7X256_Eclipse". I have a problem when I do this char var1[2]; int short var2 = 0x1234; *(int short*)var1 = var2 When I do the typecast the arm stop working and go in data abort of boot.s. Can someone tell me why the arm his not able to do that and how I can solve my problem, because with the Rabbit I was able to do that. I know I can use memcpy, but with this cast I save some CPU time. thank

RTOS+ arm7 typecast problem

sounds like an alignment problem.  var1 is probably at an odd address which is fine for byte access but not for 16/32 bit access Ben

RTOS+ arm7 typecast problem

have you tried the reverse ? int short var2 = 0x1234; char* var1; var1 = (char*)&var2; Ben

RTOS+ arm7 typecast problem

yes I have the problem only when the var1 have a odd address, how can I solve that? No I didn’t tried the inverse, because in you exemple var1 is only a ptr, I want the value to be copied and be able to modify var2 without modify the value of var1 Joël

RTOS+ arm7 typecast problem

You could try using the aligned attribute http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html

RTOS+ arm7 typecast problem

That doesn’t work because in my real projet i’m in a structure (who is packed to be sure no memory space is left between two variable), So if I have this kind of structure var1[2]; var2; var3[2]; and I use var3 it is sure that the address of var3 is odd and that doesn’t work on the arm, but I don’t know why because on the rabbit i’m am able to do that

RTOS+ arm7 typecast problem

Assuming the structure has to be packed and you can’t change the order of the structure elements you will have to copy the short int a byte at a time. If you can change the order of the elements then delcare var3 after var 1 and both will probably be aligned on an even address, assuming the structure is aligned that way. This is not really the correct forum for discussing this as it is not a problem with FreeRTOS or related in anyway to it. You would still have your problem even if you used no RTOS.

RTOS+ arm7 typecast problem

Do you know better forum where I can post ? I tried sparfun and atmel thank

RTOS+ arm7 typecast problem

Thisshould work: char var1[2]; int short var2 = 0x1234; var1[1] = (char)  (var2 & 0xFF); var1[0] = (char) (var2 >>8); Maybe not most effective, but it will work? BTW why are you doing such ugly casting anyway?

RTOS+ arm7 typecast problem

I know this work, but it’s take more time to the cpu to do it. Why did you find this cast ugly, I find it so beautiful :P. With this cast the cpu copy the value in one shot and this fast when you have to do many.