Community
cancel
Showing results for 
Search instead for 
Did you mean: 
VViro
Beginner
2,387 Views

Nios - II memory alignment issue while accessing integer from non word align location

Jump to solution

Error Msg : Not getting any error message but getting unexpected behavior

- Using Nios-II with eclipse. While accessing integer(32 bit) form non word align location getting incorrect value as described in below example.

- Tested with eclipse version 13 and 16, both are giving same result.

 

- Test case :

--------------------------------------------------------------------------------

char c[10] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};

printf("int = 0x%08x", *(int*)(&c[2]));

--------------------------------------------------------------------------------

above code should print "int = 0x66554433" but getting "int = 0x44332211"

0 Kudos
1 Solution
AnandRaj_S_Intel
Employee
167 Views

Hi Vasu,

 

Try by going to the project folders > right-click > properties> Nios II Application properties >

Debug Level = 2

Optimization Level =2

This gives the required output

 

Best Regards,

Anand Raj Shankar

(This message was posted on behalf of Intel Corporation)

Nios II console.png

View solution in original post

10 Replies
AnandRaj_S_Intel
Employee
167 Views

Hi,

 

I have user Eclipse Version: Kepler Service Release 2.

Result are as expected please check the image.

 

Let me know if this has helped resolve the issue you are facing or if you need any further assistance.

 

Best Regards,

Anand Raj Shankar

(This message was posted on behalf of Intel Corporation)

MemStr.JPG

 

 

VViro
Beginner
167 Views

Hi Anand,

 

Thanks for quick reply. We have tried this with quartus version 13 and 16. Please check below version details.

 

image.pngimage.png 

We are seeing same behavior with both of eclipse.

 

Also can you provide details, which NIOS version you are using?

 

Thanks,

Vasu.

AnandRaj_S_Intel
Employee
167 Views

Hi,

 

I had previously used Nios II EDS 17.0.

Now i have checked with  Nios II Software Build Tools for Eclipse 13.0.0.156 which gives expected out.

Refer attached

N13Eclipse.JPG

Let me know if this has helped resolve the issue you are facing or if you need any further assistance.

 

Best Regards,

Anand Raj Shankar

(This message was posted on behalf of Intel Corporation)

 

 

VViro
Beginner
167 Views

Hi Anand,

 

Mem_alignment.png

 

We have tried using Quartus 18 and at first sight we got expected result. But when we checked for memory address of C[2] it was already word aligned, so it was expected behavior. Can you please check below program with your system?

 

char c[10] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};

 printf("int starting c[0] = 0x%08x and address = 0x%08x\n", *(int*)(&c[0]), (int)&c[0]);

 printf("int starting c[2] = 0x%08x and address = 0x%08x\n", *(int*)(&c[2]), (int)&c[2]);

 

 // We are expecting following output:

 // int starting c[0] = 0x44332211 and address = .....

 // int starting c[2] = 0x66554433 and address = .....

 

Thanks,

Vasu.

AnandRaj_S_Intel
Employee
167 Views

Hi,

 

Yes, it is word aligned.

 

Best Regards,

Anand Raj Shankar

(This message was posted on behalf of Intel Corporation)wordAlign.JPG

VViro
Beginner
167 Views

Anand,

 

We have tested it with Cyclone III (CoreCommander Board), Max 10 (DECA Board) and Cyclone 10 GX (custom board). But seeing same issue with all of them. 

Which FPGA board you are using to test this? Can you share Quartus design? 

We are using default settings in eclipse. Have you made any change in eclipse settings? 

 

Thanks,

Vasu.

AnandRaj_S_Intel
Employee
167 Views

Hi,

 

Apologies for late response.

 

I have used default eclipse settings.

Please find the attached project for max10 dev kit.

 

Let me know if this has helped resolve the issue you are facing or if you need any further assistance.

 

Best Regards,

Anand Raj Shankar

(This message was posted on behalf of Intel Corporation)

ecpmemstruct.png

 

VViro
Beginner
167 Views

Hi Anand,

 

Thanks for your support.

I have gone through your given design & noticed one difference in the eclipse project. I think you have used the template "hello world small" for eclipse project.

I used NIOS code(hello_sw_leds.c) from your design on MAX10 Deca board with BSP template "hello world" & observed wrong result(int = 0x44332211). In a similar way, I also checked NIOS code with "hello world small" template & got expected result(int = 0x66554433). This could be happened due to reduced driver size. 

 

So with the above issue, I want your guidance on how we can get the expected output with "hello world" template in eclipse or in other words what settings need to be done in "hello world" project? Because we already design our project with "hello world" template. 

 

I have attached screenshots of eclipse project for your reference.  

image.pngimage.png

 

Thanks,

Vasu.

AnandRaj_S_Intel
Employee
168 Views

Hi Vasu,

 

Try by going to the project folders > right-click > properties> Nios II Application properties >

Debug Level = 2

Optimization Level =2

This gives the required output

 

Best Regards,

Anand Raj Shankar

(This message was posted on behalf of Intel Corporation)

Nios II console.png

View solution in original post

VViro
Beginner
167 Views

Hi Anand,

 

We have tested as per your suggestion and it worked. Thanks for your efforts and prompt response.

 

Thanks,

Vasu.

Reply