Discrepancy in values when struct is accessed via a pointer.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Discrepancy in values when struct is accessed via a pointer.

1,811 次查看
dmckeever
Contributor II

Hello

I am using the iMXRT1064 processor on a custom board with an eMMC card fitted

MCUXpresso is the development environment.

I am using the file fsl_mmc.c from the SDK for library functions to access the eMMC card.

The eMMC card descriptor is a C struct allocated at a certain memory address.

mmc_card_t g_mmc;

 

The descriptor is initialised by calling the library function, MMC_Init(mmc_card_t *card) passing a pointer to the struct.

After the return from MMC_Init, the fields of the struct have "bad" values, eg blockSize is 17017344 instead of 512.

Inside MMC_Init, when the struct is accessed directly (as a test), most of the fields show different values than when it is accessed via the pointer; so that the initialisation done via the pointer is placing bad values into the actual struct in memory.

The attached file g_mmc.docx shows two screenshots taken just before the return from MMC_Init. This shows the "good" values via the pointer, but "bad" values in the actual memory locations.
( In successive executions, the "bad" values are always the same.)

NOTE. For those familiar with mmc_card_t,  I experimented by moving one field to the end of the struct.

I have tried various alignments of g_mmc but without success.

Can anyone suggest how accessing the same struct directly and via a pointer can yield different values?

Thank you in anticipation.

Damien


标签 (1)
0 项奖励
回复
2 回复数

1,779 次查看
dmckeever
Contributor II

The behavior is even more bizarre.

Example.

mmc_card_t *card = (mmc_card_t*)&g_mmc;

...

Execute the following statement, with a breakpoint on the second line:

MMCdeviceSectors = g_mmc.userPartitionBlocks;

Success = true;


Expression windows in the debugger show that the value of g_mmc.userPartitionBlocks shown in the struct (ie 7733248) is not being assigned to the variable MMCdeviceSectors ( ie. 131072)

The value assigned (131072) is the "bad" value  shown when the g_mmc struct is accessed via the  pointer card .

The attached file Expression Discrepancy.docx shows this with screenshots.

Help please!

Damien

0 项奖励
回复

1,717 次查看
Kan_Li
NXP TechSupport
NXP TechSupport

Hi @dmckeever ,

 

May I have the IDE tool version? From here it seems ok. Please kindly refer to the following for details.

Kan_Li_0-1712803430293.png

Kan_Li_1-1712803465906.png

Kan_Li_2-1712803537529.png

 

If your IDE version is lower than above, maybe you have to update it.

 

Hope that helps,

 

Have a great day,
Kan


-------------------------------------------------------------------------------
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 项奖励
回复