- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to cast a byte array pointer to the following structure:
typedef struct {
uint16_t data1;
uint16_t data2;
uint16_t data3;
uint16_t data4;
uint8_t data5;
} BleServicesValues_t;
I do something like this:
void func1(uint8_t* buffer) {
BleServicesValues_t* values;
values = (BleServicesValues_t*) &buffer[1];
func2(values->data1);
}
While debugging, everything looks fine, but when I step into func2, the program jumps to Fault_Handler in startup_psoc63_cm0plus.S.
Does anyone understand why this is not working?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's an alignment problem. The BleServicesValues_t cast should be set to an address that is multiple of 4 (32-bit architecture). You are probably accessing an address ending to 1.
If you cast at buffer[0] you probably be fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's an alignment problem. The BleServicesValues_t cast should be set to an address that is multiple of 4 (32-bit architecture). You are probably accessing an address ending to 1.
If you cast at buffer[0] you probably be fine.