Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12590 Discussions

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

VViro
Beginner
3,542 Views

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
1,322 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

0 Kudos
10 Replies
AnandRaj_S_Intel
Employee
1,322 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

 

 

0 Kudos
VViro
Beginner
1,322 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.

0 Kudos
AnandRaj_S_Intel
Employee
1,322 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)

 

 

0 Kudos
VViro
Beginner
1,322 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.

0 Kudos
AnandRaj_S_Intel
Employee
1,322 Views

Hi,

 

Yes, it is word aligned.

 

Best Regards,

Anand Raj Shankar

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

0 Kudos
VViro
Beginner
1,322 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.

0 Kudos
AnandRaj_S_Intel
Employee
1,322 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

 

0 Kudos
VViro
Beginner
1,322 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.

0 Kudos
AnandRaj_S_Intel
Employee
1,323 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

0 Kudos
VViro
Beginner
1,322 Views

Hi Anand,

 

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

 

Thanks,

Vasu.

0 Kudos
Reply