Forum Discussion

VViro's avatar
VViro
Icon for New Contributor rankNew Contributor
7 years ago
Solved

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

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"

  • 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)

10 Replies

  • AnandRaj_S_Intel's avatar
    AnandRaj_S_Intel
    Icon for Regular Contributor rankRegular Contributor

    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)

  • VViro's avatar
    VViro
    Icon for New Contributor rankNew Contributor

    Hi Anand,

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

    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's avatar
    AnandRaj_S_Intel
    Icon for Regular Contributor rankRegular Contributor

    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

    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's avatar
    VViro
    Icon for New Contributor rankNew Contributor

    Hi Anand,

    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's avatar
    AnandRaj_S_Intel
    Icon for Regular Contributor rankRegular Contributor

    Hi,

    Yes, it is word aligned.

    Best Regards,

    Anand Raj Shankar

    (This message was posted on behalf of Intel Corporation)

  • VViro's avatar
    VViro
    Icon for New Contributor rankNew Contributor

    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's avatar
    AnandRaj_S_Intel
    Icon for Regular Contributor rankRegular Contributor

    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)

  • VViro's avatar
    VViro
    Icon for New Contributor rankNew Contributor

    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.

    Thanks,

    Vasu.

  • AnandRaj_S_Intel's avatar
    AnandRaj_S_Intel
    Icon for Regular Contributor rankRegular Contributor

    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)

  • VViro's avatar
    VViro
    Icon for New Contributor rankNew Contributor

    Hi Anand,

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

    Thanks,

    Vasu.