| Author |
Message |
|
|
Posted: Nov 16, 2007 - 11:23 PM |
|


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
|
| |
|
|
|
|
|
Posted: Nov 16, 2007 - 11:29 PM |
|


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
|
| |
|
|
|
|
|
Posted: Nov 22, 2007 - 07:34 PM |
|


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
|
| |
|
|
|
|
|
Posted: Nov 22, 2007 - 07:35 PM |
|


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
|
| |
|
|
|
|
|
Posted: Mar 07, 2008 - 10:05 AM |
|

Joined: Dec 04, 2004
Posts: 3
|
|
| What do you mean with "after each variable declaration"? One of each part for the struct? |
|
|
| |
|
|
|
|
|