Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
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

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
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

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
have you tried the reverse ?

int short var2 = 0x1234;
char* var1;

var1 = (char*)&var2;

Ben

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
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

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
You could try using the aligned attribute

http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
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

RE: RTOS+ arm7 typecast problem

Posted by Ben on July 29, 2009
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.

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
Do you know better forum where I can post ? I tried sparfun and atmel

thank

RE: RTOS+ arm7 typecast problem

Posted by Adam Turowski on July 29, 2009
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?

RE: RTOS+ arm7 typecast problem

Posted by Joel cote on July 29, 2009
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.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner