CH549的pdata實(shí)際地址問題

我的某個(gè)xdata數(shù)組跨越了1024地址,然后我就發(fā)現(xiàn)從1024往后的幾個(gè)字節(jié)會被莫名其妙篡改。

經(jīng)檢查,發(fā)現(xiàn)定義的幾個(gè)pdata實(shí)際就在這幾個(gè)字節(jié),所以pdata是不是實(shí)際是映射到了從1024開始位置?

但問題是編譯器似乎以為pdata是映射到了xdata的0地址?

因?yàn)槲覈L試聲明UINT8X test[256] _at_ 0;編譯器直接報(bào)錯(cuò)說:

*** ERROR L107: ADDRESS SPACE OVERFLOW

? ? SPACE:? ?PDATA

說pdata沒空間可用了

但聲明UINT8X test[256] _at_ 1024;編譯卻通過了。


所以關(guān)于pdata的實(shí)際地址,我希望能確認(rèn)一下。

這樣測試沒有出現(xiàn)報(bào)錯(cuò)。

image.png

上面的變量定義后,查看MAP文件:

image.png

因?yàn)榍懊鎄data指定了從0地址開始,Pdata從0x100開始。

您可以再檢查下代碼是否還有其他變量指定了0地址導(dǎo)致報(bào)錯(cuò)。



你好,我把工程刪減到幾乎最簡,依然是會出現(xiàn)我說的錯(cuò)誤的,附上截圖和工程附件:

image.png

icon_rar.gifTest.zip

然后就是,pdata是xdata的其中256字節(jié),那么pdata這256字節(jié)究竟在CH549的2048字節(jié)的xdata的什么位置?



取消勾選這個(gè)選項(xiàng),即可編譯成功

image.png

在勾選這個(gè)選項(xiàng)時(shí),查看map文件,發(fā)現(xiàn)pdata聲明的變量會默認(rèn)設(shè)置0地址開始,因此當(dāng)Xdata定義 _at_ 0時(shí)會出現(xiàn)報(bào)錯(cuò)現(xiàn)象。
image.png



你好,換鏈接器是可以編譯成功,但是我覺得還是有問題,比如以下代碼:

image.png

我已經(jīng)把2k的xdata全部占滿,但是它還是能編譯成功,而且直接把這個(gè)pdata放到了2048這個(gè)超出芯片內(nèi)存的地址:

image.png

看起來用這個(gè)鏈接器它就不在乎芯片真實(shí)的內(nèi)存大小,我試了只有總量超過64k無法分配地址了它才會報(bào)錯(cuò)。

如果我寫 UINT8X arrayU8X[1024*64-1] _at_ 0;

那么m51文件里它甚至?xí)? X:FFFFH? ? ? ? ?PUBLIC? ? ? ? testU8P? 也即把它扔到物理不存在的最后一個(gè)字節(jié)。


然后就是,我用循環(huán)查找到這個(gè)pdata的真實(shí)位置然后打印輸出,它和m51里寫的也是對不上的,你們可以試一下,感謝

icon_rar.gifTest20241102.zip


您好

超過手冊描述范圍的RAM肯定是不能使用的,編譯器可以加上對RAM的真實(shí)地址限制,這樣可以提醒您使用超范圍。
image.png


你好,感謝提示。超過芯片內(nèi)存我肯定是不會用的哈。

但是我的主要問題不在這里,主要是我對pdata實(shí)際的地址感到疑惑。

比如把這個(gè)工程里改為UINT8X arrayU8X[1024] _at_ 0;這樣不超范圍

這時(shí)m51里寫的是?X:0400H? ? ? ? ?PUBLIC? ? ? ? testU8P,看上去把pdata放到1024地址了

但是重點(diǎn)是,我把xdata清空,然后僅把pdata那一字節(jié)置1,然后用循環(huán)查找它的位置,

看串口打印,會輸出1792,即2048-256,這是很奇怪的

image.png


you are using pdata the wrong way! pdata is a special fast way to access xdata. You need to modify startup.a51 and set the pdata page address in BL51 locate option if you want to use it.


pdata.png


@usbman

Thanks!?I realized that my understanding of PDATA was insufficient.

I tried to find?startup.a51, but there are multiple?startup.a51 in "C51" folder in the installation directory.

I tried to find which one was used by removing them one by one?and clicking "build", but after removing all of them, I was still able to build successfully...

However, I found another keypoint (Also my knowledge blind spot):

P2 register selects the page that PDATA use (I have been wondering these days that no matter how the compiling and linking process goes, there must be a register in the hardware that determines the page used by PDATA. Now I know it's P2).

CH549 has 2k XRAM, which means 8 pages (256B/page), so bit2~bit0 in P2 register are effective for this.

The default value of P2 is 0xFF, so bit2~bit0 = 0x07, and that means the last page is selected, which explains the printed number "1792".

When P2 is 0x04, PDATA start from 1024, and this corresponds exactly to when I first encountered the problem.


for the E51 core it does not make sense to deal with pdata. I dont know why WCH is still using that declarations in their header files... pdada is potentially dangerous as you already found out. All MOVX commands just use one cycle. This was different in the old days. Some derivates use a special page register for addressing otherwise P2 is used. Which is complicated because the bits of P2 are used for alternate functions too.

If you want to use a modified startup.a51 you have to put a copy in your working directory and include the startup.a51 to your project. Otherwise a simple version from the lib is used. I do that for example because i always clear all th internal Ram from 00 to FF. Libcode just clears 00 to 7F to ensure the data seg is cleared and leaves the iseg untouched.


@usbman

You are right.

I once looked at the instruction set, but didn't pay attention to the part about MOVX.

Now it seems that using PDATA will not bring much benefit so I will change them to XDATA.

By the way, thank you for your explanation about startup.a51.


@半山竹梢

pdata 需要 “頁”支持,WCH的 E-8051 系列單片機(jī),因?yàn)闆]有開發(fā)單獨(dú)的PPAGE 寄存器,而是沿用AT89C51的標(biāo)準(zhǔn),用P2寄存器行使的 PPAGE 功能,所以,只有 CH551/552/554 因?yàn)闆]有P2引腳。所以,對pdata的支持的比較好。對于,CH548/549 因?yàn)橛杏玫?P2 引腳,所以,建議不要使用pdata。而在CH558/559 系列中,pdata 被用做了擴(kuò)展寄存器,算是WCH對pdata 一個(gè)不錯(cuò)的安置吧。其實(shí),你如果靈活使用了 雙DPTR指針的話,xdata 不會比 pdata 效率低多少。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频