rt1052 数据对齐和非对齐访问

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

rt1052 数据对齐和非对齐访问

1,784 Views
cyc583723081
Contributor I

最近在调试rt1052,遇到最多的问题就是关于数据对齐访问的问题,下面来说一下实际中遇到的两个问题:

   问题1:M7系统控制块中的 Configuration and control register 的位UNALIGN_TRP设置与否都不能访问非对齐的数据,只要访问就出硬件故障,测试方式如下:定义了一个结构体如

struct test_s{

char a;

char b;

char c;

int d;

}test_t;

在mcu启动时我获取了Configuration and control register的值,为pastedImage_1.pngUNALIGN_TRP为0.按照M7手册的定义pastedImage_2.png也就是说现在是支持非对齐访问的。但是我在给test.d赋值的时候就直接进入了硬件故障。UNALIGN_TRP设置为1时,情况也一样。求解释!

问题2:定义了一个结构体和字符串指针如下,

struct test_s{
   char a;
   char b;
   char c;
   char d[6];
}test_t;

char *e = "asdfgh";

我要将字符串使用memcpy拷贝到结构体的数组元素d中,结果是直接进入硬件中断,而如果我调整结构体如下:

struct test_s{
   char d[6];  

    char a;
   char b;
   char c;
}test_t;

memcpy是成功的,单对于memcpy来说它内部本就是将地址强转(char*)为对单字节的访问,再进行操作,按理不应该进入硬件故障,不知哪里有坑,请路过的大神赐教。谢谢



Labels (1)
0 Kudos
2 Replies

1,559 Views
crist_xu
NXP Employee
NXP Employee

请尝试修改MPU相关配置

0 Kudos

1,680 Views
jeremyzhou
NXP Employee
NXP Employee
Hi ,
非常感谢使用NXP产品,很高兴为你提供技术支持!
对于这个问题,我需要更多的细节,所以我的建议是先分享测试工程代码,然后我这边测试一下,看能否复现,再讨论原因。

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos