Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
c_oflynn
PostPosted: Nov 16, 2007 - 11:23 PM
Raving lunatic


Joined: Mar 23, 2001
Posts: 2091
Location: Halifax, NS

Hi,

My code is throwing a Data Address Read exception. What might cause that, or what should I look for in the code?

Thanks!

-Colin

_________________
VA3 YHZ - http://www.newae.com
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
c_oflynn
PostPosted: Nov 16, 2007 - 11:29 PM
Raving lunatic


Joined: Mar 23, 2001
Posts: 2091
Location: Halifax, NS

PS: The offending instruction according to disassembly of the C code is:

ld.w r9,r8[0x04]

r8 = 0x0001
r9 = 0x12b8

_________________
VA3 YHZ - http://www.newae.com
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
c_oflynn
PostPosted: Nov 22, 2007 - 07:34 PM
Raving lunatic


Joined: Mar 23, 2001
Posts: 2091
Location: Halifax, NS

By the way in case anyone searchs this and finds the same problem:

It was caused by unaligned memory accesses. The code was originally for an 8-bit AVR, and would have structures like:


Code:
/** \brief This is the NLME-NETWORK-DISCOVERY.request structure. */
typedef struct nlme_network_discovery_req_tag
{
    /** The total length of this message. */
    uint8_t     size        ;
    /** This identifies the message as \ref NLME_NETWORK_DISCOVERY_REQUEST  */
    uint8_t     cmdcode     ;
    /** Bitmask of channels to scan for networks. */
    uint32_t    ScanChannels ;
    /** Duration to scan for networks. */
    uint8_t     ScanDuration ;
} nlme_network_discovery_req_t;

[/code]

Which were later typecast to (uint8_t *) and accessed with offsets. This meant that it assumed an 8-bit device was used, as on the 32-bit device it would align the 8 bit variables to 32-bit address boundaries. This allowed faster access on the 32-bit machine.

Solved the problem by forcing hte compiler to pack everything together by adding __attribute__ ((packed)) after each variable declaration.

-Colin

_________________
VA3 YHZ - http://www.newae.com
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
c_oflynn
PostPosted: Nov 22, 2007 - 07:35 PM
Raving lunatic


Joined: Mar 23, 2001
Posts: 2091
Location: Halifax, NS

PS: So the original problem was unaligned addresses, as page 23 of the datasheet says:

Quote:
AVR32UC does not support unaligned accesses, except for doubleword accesses. AVR32UC is
able to perform word-aligned st.d and ld.d. Any other unaligned memory access will cause an
address exception.

_________________
VA3 YHZ - http://www.newae.com
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
speakman
PostPosted: Mar 07, 2008 - 10:05 AM
Newbie


Joined: Dec 04, 2004
Posts: 3


What do you mean with "after each variable declaration"? One of each part for the struct?
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits