Questions:为何 FPU 使用 float 变量地址要 4 字节对齐? Answer:当开启 FPU 时,如果 float 变量地址没有 4 字节对齐,会出现 Hard Fault 现象。如下图,test1 没有 4 字节对齐,程序会进入 HardFault_Handler。
test1 = (float*)test_arr;
test1 = (float*)((uint32_t)(&test_arr[0])+2);
*test1 = 0.52f;
*test2 = 0.52f;
修改为如下,就可以正常运行。
test1 = test_arr;
test1 = ((&test_arr[0]) + 2);
*test1 = 0.52f;
*test2 = 0.52f;
|