Other Parts Discussed in Thread: CC2652RB, Z-STACK
With SimpleLink CC13XX/CC26XX SDK Version 7.10.01.24, attribute reporting for float (ZCL_DATATYPE_SINGLE_PREC) attributes fails with a HardFault due to a misaligned pointer access on line 1895 in bdb_reporting.c:
float L = *((float*)lastValue);
float D = *((float*)delta);
float C = *((float*)curValue);
With -O0 this works, but with -Oz the FPU instruction loading the (misaligned) float causes a HardFault.
The pointers lastValue, delta, and curValue are of type uint8_t*, and at least lastValue and curValue are not properly aligned (address divisible by 4) for a float pointer. Dereferencing misaligned pointers causes undefined behaviour in C, so a HardFault is a perfectly valid result here.
The same thing probably happens for other attribute types with _Alignof larger than 2, but I haven't tested that.
I worked around the issue by using a defensive memcpy for all three values:
uint8_t len = zclGetDataTypeLength( datatype );
float L, D, C;
OsalPort_memcpy( &L, lastValue, len );
OsalPort_memcpy( &D, delta, len );
OsalPort_memcpy( &C, curValue, len );
That should probably be fixed in the SDK.