• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Development Tools » TI C/C++ Compiler » TI C/C++ Compiler - Forum » msp430f5438: compiler problem left-shifting uint32_t
Share
TI C/C++ Compiler
  • Forum
Options
  • Subscribe via RSS

Forums

msp430f5438: compiler problem left-shifting uint32_t

  • Tarak Shah
    Posted by Tarak Shah
    on Apr 02 2012 18:45 PM
    Prodigy80 points

    Hi,

    For the code:

            unsigned int i;
            uint32_t address = 0x00;


            // compute address, for flash erase/write commands:
            for( i = 1; i < 4; ++i ){
                address *= 256;    // left-shift by 8
                address |= ( (uint32_t)pBuffer[i] );
            }

    With no optimizations turned on, for the following snippet of code, w/ pBuffer[1] = 0x01, pBuffer[2] = 0x00, pBuffer[3] = 0x00, the value for address turns out to be 0x00000000 instead of expected 0x00010000.

    If i declare address to be volatile, then the value's correct.  Stepping through the debugger, the values for address through the 3 iterations are: 0x00000001, 0x00000100 and 0x00000000.

    Not sure if there's some compiler switch that I'm missing...?  Using MSP430F5438A part.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • George Mock
    Posted by George Mock
    on Apr 03 2012 10:36 AM
    Guru51565 points

    I have a rough idea of what may be happening.  Try adding the build option --no_high_level_opt.  Does that help?

    Thanks and regards,

    -George


    TI C/C++ Compiler Forum Moderator
    Please click Verify Answer on the best reply to your question.
    The Compiler Wiki answers most common questions.
    Track an issue with SDOWP. Enter your bug id in the "Find Record ID" box.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Archaeologist
    Posted by Archaeologist
    on Apr 03 2012 10:47 AM
    Mastermind40900 points

    I cannot reproduce this without more information.

    What version of the compiler are you using (not the CCS version)?

    What command-line options are you using?

    Could you post a complete, compilable test program which demonstrates the problem?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tarak Shah
    Posted by Tarak Shah
    on Apr 03 2012 13:04 PM
    Prodigy80 points

    Sorry, here's more info.  Recreated a simple function:

    int program_flash ( uint8_t *pBuffer )
    {
        int status;
        unsigned int i;
        uint32_t address = 0x00;
        for( i = 1; i < 4; ++i){
            address *= 256;
            address |= ( (uint32_t) pBuffer[i]);
        }

        address &= (~0x7F); // 128-byte aligned address; segments are 128-byte
                            // aligned at 128-byte boundary

        Flash_segmentErase( __MSP430_BASEADDRESS_FLASH__,
                            (unsigned char *)address );

        status = Flash_eraseVerify( __MSP430_BASEADDRESS_FLASH__,
                            (unsigned char *)address,
                            128);
        return status;
    }

    Complete compiler command-line:

    "C:/ti/ccsv5/tools/compiler/msp430/bin/cl430" -vmspx --abi=coffabi --code_model=large --data_model=large -O0 -g --include_path="C:/ti/ccsv5/ccs_base/msp430/include" --include_path="C:/ti/ccsv5/tools/compiler/msp430/include" --include_path="C:/Users/tshah/perforce/tshah_hwlab12_7200/Branches/5.0/main/Deploy/SW/Source/BoardSupport/msp/G3PowerBoard/bootloader/ccsv5_project/../../application_srcs" --include_path="C:/Users/tshah/perforce/tshah_hwlab12_7200/Branches/5.0/main/Deploy/SW/Source/BoardSupport/msp/G3PowerBoard/bootloader/ccsv5_project/../../../../../../OTSS/texas_instruments/msp430/MSP430ware_1_10_01_18/driverlib/5xx_6xx" --define=__MSP430F5438A__ --diag_warning=225 --display_error_number --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU23 --silicon_errata=CPU40 --printf_support=minimal --preproc_with_compile --preproc_dependency="host_cmd_processor.pp"  "C:/Users/tshah/perforce/tshah_hwlab12_7200/Branches/5.0/main/Deploy/SW/Source/BoardSupport/msp/G3PowerBoard/bootloader/host_cmd_processor.c"
    'Finished building: C:/Users/tshah/perforce/tshah_hwlab12_7200/Branches/5.0/main/Deploy/SW/Source/BoardSupport/msp/G3PowerBoard/bootloader/host_cmd_processor.c'

    Running cl430 on command line:

    MSP430 C/C++ Compiler                   v4.0.0
    Tools Copyright (c) 2003-2011 Texas Instruments Incorporated


    thanks,

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Archaeologist
    Posted by Archaeologist
    on Apr 03 2012 13:57 PM
    Mastermind40900 points

    I'm still not able to reproduce the problem.  Please show the values in pBuffer.

    How are you able to determine that the value of "address" is incorrect?  Are you determining this strictly by looking at the value in the debugger?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tarak Shah
    Posted by Tarak Shah
    on Apr 03 2012 14:54 PM
    Prodigy80 points

    hi, --define=no_high_level_opt didn't help..

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tarak Shah
    Posted by Tarak Shah
    on Apr 03 2012 14:57 PM
    Prodigy80 points

    pBuffer[0] = 0xDD

    pBuffer[1] = 0x10

    pBuffer[2] = 0x00

    pBuffer[3] = 0x00

    The intent is, take 24 bits into a 32-bit value for programming flash at 24-bit addresses for the F5438A part; size_t or uint32_t produce same problem.

    In addition to debugger displaying "address" value, stepping into function shows that the value is still zero and then programming doesn't work at the desired address.  If i declare it "volatile" then the debugger shows right address, stepping into function shows correct value and the flash gets erased (reading back as 0xFF all over the segment).

    thanks,

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Archaeologist
    Posted by Archaeologist
    on Apr 03 2012 15:32 PM
    Mastermind40900 points

    The value of "address" is 0x100000, which has no bits set in the lower 20 bits.  When that value is converted to a 20-bit pointer, it gets truncated to zero, as expected.  Perhaps you meant to initialize pBuffer[1] to 0x01?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Tarak Shah
    Posted by Tarak Shah
    on Apr 03 2012 17:34 PM
    Prodigy80 points

    Sorry, typo in my latest posting; I'm using pBuffer[1] = 0x01, results not changed

    thanks

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Archaeologist
    Posted by Archaeologist
    on Apr 04 2012 17:20 PM
    Mastermind40900 points

    I still cannot reproduce the problem.  I need a complete, compilable test case that demonstrates the problem.  I have been unable to construct one with the clues given so far.

    Try turning off hardware multiply support; that is, remove the --use_hw_mpy option.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use