This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430I2041: why it can only download firmware for 1 time

Part Number: MSP430I2041
Other Parts Discussed in Thread: MSP-TS430RHB32A, MSP-FET, MSP430AFE253, MSP-TS430PW24

Hi team,

why MSP430I2041 can only download firmware for 1 time:

I use IAR for MSP430 7.21.1, debuger is MSP-FET Flash Emulation tool, hardware is MSP-TS430RHB32A, device is MSP430I2041, when I use a new chip and stall to MSP-TS430RHB32A, and I can download the firmware for the first time, but when I try to download it for the second time, it can not success even for power on and off many times:

But when I change a new chip, it can download for the first time again, but only for the first time, second time will not OK again.

Below is the configuration of IAR:

Both the software and hardware set up should be good, as when I changed to MSP430AFE253(MSP-TS430PW24), it can download success everytime with same environment.

Would you help to share some comments why MSP430I2041 can only download for 1 time?

Thanks very much.

Regards, Sunny

  • It seems you have not include the low level init file

    2275.low_level_init.c
    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2013, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    // MSP430i20xx Initialization Routines - low_level_init.c
    //
    // This function is called by the start-up code before "main" is called, and
    // before data segment initialization is performed. The function affects the
    // following modules:
    //  - JTAG - JTAG is disabled
    //  - TLV - A TLV checksum is performed
    //  - PMM - The shared reference is calibrated to 1.16V
    //  - Clock System - The DCO is calibrated to 16.384MHz
    //  - SD24 - The SD24 reference voltage trimming is calibrated
    //
    // The return value of this function controls if data segment initialization
    // should take place. If 0 is returned, it is bypassed.
    //
    // Any code example or application written for the MSP430i20xx which takes
    // advantage of any of the affected modules is suggested to include this
    // function to ensure full calibration of the application.
    //
    // Additionally, this initialization routine is suggested for small, short 
    // code examples to ensure the JTAG will be unlocked. The i20xx series of 
    // devices requires execution of 64 MCLK cycles before the JTAG can be unlocked.
    // If a device does not execute 64 MCLK cycles, it cannot be accessed via JTAG.
    //******************************************************************************
    #include "msp430.h"
    
    #ifdef __TI_COMPILER_VERSION__
    int _system_pre_init(void)
    #elif __IAR_SYSTEMS_ICC__
    int __low_level_init(void)
    #elif __GNUC__
    extern int system_pre_init(void) __attribute__((constructor));
    int system_pre_init(void)
    #else
    #error Compiler not supported!
    #endif
    {
        unsigned long *jtagPwd = (unsigned long *)JTAG_DIS_PWD1;
    
        /* Feed the watchdog timer */
        WDTCTL = WDTPW | WDTCNTCL;
    
        /* Check JTAG password locations and disable JTAG if passwords don't match.
         * Else the JTAG will be enabled in the 64th cycle after reset.
         */
        if ((*jtagPwd != 0x00000000) && (*jtagPwd != 0xFFFFFFFF))
        {
            /* Disable JTAG */
            SYSJTAGDIS = JTAGDISKEY;
        }
    
        /* Calibration section
         * Check for the BORIFG flag in IFG1. Execute calibration if this was a BORIFG.
         * Else skip calibration
         */
        if (IFG1 & BORIFG)
        {
            /* Perform 2's complement checksum on 62 bytes of TLV data */
            unsigned int checksum = 0;
            unsigned char *TLV_address_for_parse = ((unsigned char *)TLV_START);
            unsigned int *TLV_address_for_checksum = ((unsigned int *)TLV_START + 1);
    
            do
            {
                checksum ^= *TLV_address_for_checksum++;
            } while (TLV_address_for_checksum <= (unsigned int *)TLV_END);
    
            checksum ^= 0xFFFF;
            checksum++;
    
            /* If check sum is not correct go to LPM4 */
            if (*((unsigned int *)TLV_START) != checksum)
            {
                /* Enter LPM4 if checksum failed */
                __bis_SR_register(LPM4_bits);
            }
    
            /* Check sum matched, now set calibration values */
    
            /* Calibrate REF */
            REFCAL1 = *(TLV_address_for_parse + TLV_CAL_REFCAL1);
            REFCAL0 = *(TLV_address_for_parse + TLV_CAL_REFCAL0);
    
            /* Calibrate DCO */
            CSIRFCAL = *(TLV_address_for_parse + TLV_CAL_CSIRFCAL);
            CSIRTCAL = *(TLV_address_for_parse + TLV_CAL_CSIRTCAL);
            CSERFCAL = *(TLV_address_for_parse + TLV_CAL_CSERFCAL);
            CSERTCAL = *(TLV_address_for_parse + TLV_CAL_CSERTCAL);
    
            /* Calibrate SD24 */
            SD24TRIM = *(TLV_address_for_parse + TLV_CAL_SD24TRIM);
    
            /* Clear BORIFG */
            IFG1 &= ~(BORIFG);
        }
    
        /* Feed the watchdog timer */
        WDTCTL = WDTPW | WDTCNTCL;
    
        /* Return value:
         *  1 - Perform data segment initialization.
         *  0 - Skip data segment initialization.
         */
        return 1;
    }
    
    

  • Hi Gary,

    Really thanks for your comments, I downloaded the file and changed it`s name to low_level_init.c, then replace the same file in IAR as below:

    but the result is same after this operation.

    it is the right operation?

    Do you have any comments how to include this file?

    Thanks again.

    Regards, Sunny

  • add the low_level_init file at the same part with main.c

  • Hi Gary,

    Thanks for comments, first i changed it`s name to low_level_init.c, and add to the main.c folder as below:

    it can not works, still shows could not find device.

    then i added this file to project as below:

    it also can not works as the same result, then i add the function to main.c as below:

    it also can not works with same result.

    Would you help to share more comments, thanks very much.

    Regards, Sunny

  • Please refer to this project 4807.E2E_Project.zip

  • Hi Gary, 

    Thanks for sharing, i tried again, but still failed, result is same(the chip is the on i downloaded firmware before). But when  I change a new chip, it can download successful, and it can download normally time by time.

    But the question is why the previous chip can not download? I mean have several chip which download firmware one time before, but it can not download after first time, why these chips can not download hte new project file?

    Thanks.

    Regards, Sunny

  • What's the project do you downloaded? My or your project?

  • Hi Gary,

    it`s your project, thanks.

    The questions is why  the previous chip can not download? I mean have several chip which download  my project firmware one time before, but it can not download after first time, why these chips can not download the new project file?

    Regards, Sunny

  • I mean if you use a new device to download my project, it should bot be locked. Right?

    If you use my project to download into a device that is failed it is most likely not work, because the device's JTAG maybe locked.

    Could you share me your firmware or project to me?

  • Hi Garry,

    attachment is my project.

    I2041 PWM.zip

    and i confirm the issue: when i use your project, every thing is good, and when i use my project(add low_level_init.c file to the main file folder, and add below function in the main.c), then everything is also good:

    but when i remove the low_level_init.c file from the main file folder, and remove _low_level_init() function in the main.c, then i can not download again, and even change to your project, it also can not download anyway.

    so this issue is found, but the only question is why if I download the project with out low_level_init.c file, the chip become broken, and can not download anyway?

    Really thanks for your help.

    Regards, Sunny

  • Hi Sunny

    First  _low_level_init()  not necessary be included in main(), because it will be called before main().

    Second is low_level_init.c file must be included in the project. It include JTAG state check and device calibration that is must be run when device power up.

  • Hi Gary,

    Got it, really apricated your great support, it do help us find the root course and fix the issue.

    Thanks again.

    Regards, Sunny