Microchip
直播中

杨晓静

7年用户 161经验值
私信 关注
[问答]

访问程序空间中的常量编译错误?

XC16V1.31设备DEPIC33 EP512GM710HI,对于一个Flash编程项目,我有这样的代码:没有错误编译的代码,MyFlash存储器位于程序存储器中作为地址0x15000,但是有些错误,因为从FLASH读取的值与预期值不匹配,而不是使用ICD时。3,而不是当使用模拟器。我检查代码分解在“为”循环,得到:当然,这个代码不能访问Flash,iTHER TBRD或一种PSV将是NeDED。当我测试:我得到了预期的编译器错误:MUC.C:51:6:错误:不恰当的程序地址“MyFlash存储器”的USI我认为编译器如果不能访问MyFlash存储器,而不是生成非工作代码,就应该给出一个错误。

以上来自于百度翻译


      以下为原文

    XC16 v1.31 Device dePIC33EP512GM710

Hi,
for a Flash-Programming Project I had a code like this:
const unsigned int __attribute__((space(prog),address(0x15000),section("myFlashSpace")))
    myFlashMemory[32]={1,2,3,4,5,6,7,8};
unsigned int LowWordInstructions[32]; //to read back the 16 lower bits of instructions
...
int main(void) {
    unsigned int i;
...
   // read from flash to ram
    for (i=0;i<32;i++)
    {
        LowWordInstructions=myFlashMemory;
    }
...

The code compiled without errors, myFlashMemory was located in program memory as address 0x15000, but something was wrong as the values read from Flash didn't match the expected values, - not when using ICD3 and not when using Simulator.
I checked the code Disassembly inside the "for" loop and got:
! LowWordInstructions=myFlashMemory;
0x33E: MOV [W14], W0
0x340: ADD W0, W0, W1
0x342: MOV #0x2FA, W0
0x344: ADD W1, W0, W0
0x346: MOV [W0], W1
0x348: MOV [W14], W0
0x34A: ADD W0, W0, W2
0x34C: MOV #0x1000, W0
0x34E: ADD W2, W0, W0
0x350: MOV W1, [W0]
Of course this code could not access FLASH, eigther TBLRD or a kind of PSV would be needed.
when I tested:
i=myFlashMemory[2];
I got the expected compiler error:
main.c:51:6: error: Inappropriate program address 'myFlashMemory'


Using
__eds__ const unsigned int __attribute__((space(prog),address(0x15000),section("myFlashSpace")))
    myFlashMemory[32]={1,2,3,4,5,6,7,8};
solved the Problem.

I think the compiler should give an error if it can't access the myFlashMemory instead of generating non-working code.

回帖(12)

李兆峰

2019-3-13 08:40:05
貌似强制地址在15000是编译器允许的,但是不能检查“深入”…

以上来自于百度翻译


      以下为原文

    Looks like forcing the address at 15000 is something that the compiler allows, but can't check "in depth" ...
举报

王杰

2019-3-13 08:54:55
是的,你必须使用y-uBuffTynTabLeRDL等来读取这些变量。所有的声明都是保留空间并初始化数组。你也可以使用PSV来更传统地阅读它们。

以上来自于百度翻译


      以下为原文

    Yes, you have to use the __builtin_tablerdl, etc., to read back those variables.  All your declaration does is reserve the space and init the array.  You can also use psv to read them back more conventionally.
举报

倪辰曦

2019-3-13 09:09:15
让我澄清一下:我检查了几种在Flash中声明缓冲区的方法:1。const无符号int MyFlash内存[32 ]={1,2,3,4,5,6,7,8};2。const无符号int yAtAtditTyx((地址(0x15000)))MyFlash存储器[32 ]={1,2,3,4,5,6,7,8};3。const无符号int yAtAtditTyx((空间(PSV),地址(0x15000)))MyFlash存储器[32 ]={1,2,3,4,5,6,7,8};4。const无符号int yAtAtditTyx((空间(PROG),地址(0x15000)))MyFlash存储器[32 ]={1,2,3,4,5,6,7,8};5。(32)[1,2,3,4,5,6,7,8};6。(32){ 1,2,3,4,5,6,7,8};一些定义引起麻烦。(使用本测试的模拟器)1。编译器将常数放置在名为“.const”(在我的例子位于0x000 0300)的LoWordDebug [K]=MyFlash内存[k}的区段中,代码是OK的。编译器将DSRPAG设置在不可见代码中的任何地方到0x0200,并用MOV[W0]读取MyFlash空间的第一个字。W0=0x8300,即偏移0x0300和比特15设置为指示PSV/EDS访问。2。一个地址是放置常量的地方。在这种情况下,编译器生成警告:MyFlash内存不被放置到编译器管理的PSV部分(由于地址());假设空间(PSV)为“MyFlash内存”。常量放置在地址为0x15000的Flash中,代码类似于1。但是DSRPAG被设置为0x001而不是0x0202。(0x00万…0x07FFF-&;DSPPAGG=0x200;0x00 8000…0x00 FFFF & &;DSPPAG=0x0201;0x010000…0x017FFF & &;dSPPAG=0x0202),因此结果是错误的,有时运行此代码模拟器崩溃(没有单步执行,没有重置,没有完成调试会话可能)。重新启动MPLAB X(V3.45)需要3.3显式使用空间(PSV):没有警告,没有错误,常量放置在闪存在0x15000。同样的问题和2一样。DSRPAG是0x00 01,模拟器崩溃从RAM的EDS页1读取(而不是从程序存储器读取)4。没有警告,没有错误。但是代码是完全错误的。5。没有警告,没有错误。代码好。DSRPAG被设置为UnWord指令=MyFlash存储器;6。没有警告,没有错误。代码好。代码与5略有不同,问题是3。4。在那里你既没有警告也没有错误,但是这些值是从ELSE读取的,而不是从程序内存中的常量读取的。

以上来自于百度翻译


      以下为原文

    Let my clarify:
I checked several ways to declare the buffer in Flash:
 
1. const unsigned int myFlashMemory[32]={1,2,3,4,5,6,7,8};
2. const unsigned int __attribute__((address(0x15000)))  myFlashMemory[32]={1,2,3,4,5,6,7,8};
3. const unsigned int __attribute__((space(psv),address(0x15000)))  myFlashMemory[32]={1,2,3,4,5,6,7,8};
4. const unsigned int __attribute__((space(prog),address(0x15000)))myFlashMemory[32]={1,2,3,4,5,6,7,8};
5. __psv__ const unsigned int __attribute__((space(prog),address(0x15000)))  myFlashMemory[32]={1,2,3,4,5,6,7,8};
6. __eds__ const unsigned int __attribute__((space(prog),address(0x15000)))  myFlashMemory[32]={1,2,3,4,5,6,7,8};


Some of the definitions are causing trouble.
(used the Simulator for this Test)
1. The compiler places the constants at a section named ".const" (in my Example located at 0x000300)
LowWordInstructions[k]=myFlashMemory[k}; code is OK.
The compiler has set DSRPAG anywhere in the non-visible code to 0x0200 and reads the first word of myFlashSpace with MOV [W0],.. with W0=0x8300 i.e. offset 0x0300 and Bit 15 set to indicate PSV/EDS access.
 
2. An address is where the constants are placed.
In this case the compiler generates a warning:
warning: myFlashMemory Not placing into compiler managed PSV section due to address(); assuming space(psv) for 'myFlashMemory'.
The Constants are placed in Flash at address 0x15000 and the code is similar to 1. But DSRPAG is set to 0x0001 instead of 0x0202. (0x000000 ... 0x007FFF->DSPRPAG=0x200; 0x008000...0x00FFFF->DSPRPAG=0x0201; 0x010000...0x017FFF->DSPRPAG=0x0202) So the results are wrong and sometimes running this code the Simulator crashes (no single-stepping, no reset, no Finish Debug Session possible. Restart of MPLAB X (v3.45) required)
 
3.Explicit using space(psv): No warnings, no errors, constants placed in Flash at 0x15000. Same Problem as with 2. DSRPAG is 0x0001 and simulator crashes reading from EDS-Page 1 of RAM (instead of reading from Program memory)
 
4. No warnings, no errors. But code is totally wrong.
 
5. No warnings, no errors.Code OK. DSRPAG is set explictite  for LowWordInstructions=myFlashMemory;
 
6. No warnings, no errors.Code OK. Code slightly different from 5.
 
The problems are 3. and 4. where you get neither warning nor errors but the values are read from elswhere but not from the constants in program memory.
 
 
 
举报

陈晨

2019-3-13 09:23:06
你到底想做什么?这些方法中有很多是针对特定用途的。你有特殊需要吗?Const将工作,但限于32 K。

以上来自于百度翻译


      以下为原文

    What are you trying to actually do?
Many of those methods are for specific uses.
You you have a special need?
Const will work, but is limited to 32k.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分