I've run into quite a confounding situation and would appreciate any advice. I have a EMIF CS2 configured for 32 bit interface, with all the timings set to the slowest possible options. Normal mode is being used with extended wait time enabled. When stepping through a debugger, a function that copies values from this EMIF occasionally copies an incorrect value, but actually checking the value at that EMIF address in JTAG shows the correct value.
typedef union Field {
float32_t f32;
int32_t i32;
uint32_t u32;
} Field;
typedef union {
struct {
uint8_t id:8;
State state:8; // Enum defined elsewhere
uint8_t _16:4;
bool message_refuse:1;
uint8_t _21:3;
MessageType message_type:8; // Enum defined elsewhere
};
uint32_t all;
struct {
uint16_t lower;
uint16_t upper;
};
} Header;
typedef union {
struct {
uint8_t bcc:8;
uint8_t _8:8;
uint8_t speed:8;
uint8_t acceleration:8;
};
uint32_t all;
struct {
uint16_t lower;
uint16_t upper;
};
} Footer;
typedef struct Message {
Header header;
Field sections[6];
Footer footer;
} Message;
Message volatile const* const RECEIVE_MESSAGE = SOME_EMIF_ADDRESS;
void readMessage(Message* message_out) {
Message volatile const* in = RECEIVE_MESSAGE;
message_out->footer.all = in->footer.all;
DELAY_US(0.2);
message_out->header.all = in->header.all;
DELAY_US(0.2);
// Read sections
for (int16_t i = 0; i < 6; ++i) {
message_out->sections[i].u32 = in->sections[i].u32;
DELAY_US(0.2);
}
}
Example definitions above showing a structured read of an EMIF address. Using the `readMessage` function, the `message_out` always produces the correct header/sections, but seems to occasionally fail in the footer's `bcc` code (always with the same value too, where it should be 0x3 but instead is 0x10). The most interesting thing is that setting a breakpoint and observing the value in debugger, the footer is correct within the actual EMIF address, but only in `message_out` the `bcc` code is incorrect. This is also somewhat random/infrequent.
To try to resolve this, I have tried lowering the EMIF timings configuration to the slowest available options, adding various amounts of delay within the read function, reordering the copies within the delay function, and copying the footer from the EMIF address multiple times within the read function. All of this produced no changes in the results (intermittent footer `bcc` error of 0x10 instead of 0x3, only in copied `message_out`).
Does anyone have experience with similar behavior? At this point I am not suspecting the EMIF itself as it produces the correct value when directly read, but I do not understand how a simple copy from one memory region to another can produce the exact same error with the same values at random intervals.

