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.

TM4C1231H6PZ: Internal Flash Erase

Part Number: TM4C1231H6PZ
Other Parts Discussed in Thread: UNIFLASH

Hello Team,

Would you be able to help me resolve a customer question regarding reprogramming the TM4C1231H6PZI?

The customer is planning to use the internal oscillator with no connections to the external oscillator pins. However, upon first program, they used the bootloader sample code from the TI Launch Pad which configured the MCU to use the external crystal which doesn't exist on the customer board. Now, every time the chip gets power the bootloader kicks in and configures invalid clock source which causes nothing to work.

Is there a way for the customer to erase the internal flash or reprogram the bootloader in this case?

Best Regards,

Jacob Butler

  • Hi Jacob,

      The bootloader will call the ConfigureDevice() function to configure the clock using the main oscillator if the CRYSTAL_FREQ is defined. The CRYSTAL_FREQ is defined in the bl_config.h file. You will need to comment out the #define CRYSTAL_FREQ so that the ConfigureDevice() will not configure the system clock using the main oscillator. 

    //*****************************************************************************
    //
    // The frequency of the crystal used to clock the microcontroller.
    //
    // This defines the crystal frequency used by the microcontroller running the
    // boot loader. If this is unknown at the time of production, then use the
    // UART_AUTOBAUD feature to properly configure the UART.
    //
    // Depends on: None
    // Exclusive of: None
    // Requires: None
    //
    //*****************************************************************************
    #define CRYSTAL_FREQ 16000000

    void
    ConfigureDevice(void)
    {
    #ifdef UART_ENABLE_UPDATE
        uint32_t ui32ProcRatio;
    #endif
    
    #ifdef CRYSTAL_FREQ
        //
        // Since the crystal frequency was specified, enable the main oscillator
        // and clock the processor from it.
        //
    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
        defined(TARGET_IS_TM4C129_RA2)
        //
        // Since the crystal frequency was specified, enable the main oscillator
        // and clock the processor from it. Check for whether the Oscillator range
        // has to be set and wait states need to be updated
        //
        if(CRYSTAL_FREQ >= 10000000)
        {
            HWREG(SYSCTL_MOSCCTL) |= (SYSCTL_MOSCCTL_OSCRNG);
            HWREG(SYSCTL_MOSCCTL) &= ~(SYSCTL_MOSCCTL_PWRDN |
                                       SYSCTL_MOSCCTL_NOXTAL);
        }
        else
        {
            HWREG(SYSCTL_MOSCCTL) &= ~(SYSCTL_MOSCCTL_PWRDN |
                                       SYSCTL_MOSCCTL_NOXTAL);
        }
    
        //
        // Wait for the Oscillator to Stabilize
        //
        Delay(524288);
    
        if(CRYSTAL_FREQ > 16000000)
        {
            HWREG(SYSCTL_MEMTIM0)  = (SYSCTL_MEMTIM0_FBCHT_1_5 |
                                      (1 << SYSCTL_MEMTIM0_FWS_S) |
                                      SYSCTL_MEMTIM0_EBCHT_1_5 |
                                      (1 << SYSCTL_MEMTIM0_EWS_S) |
                                      SYSCTL_MEMTIM0_MB1);
            HWREG(SYSCTL_RSCLKCFG) = (SYSCTL_RSCLKCFG_MEMTIMU |
                                      SYSCTL_RSCLKCFG_OSCSRC_MOSC);
        }
        else
        {
            HWREG(SYSCTL_RSCLKCFG) = (SYSCTL_RSCLKCFG_OSCSRC_MOSC);
        }
    #else
        HWREG(SYSCTL_RCC) &= ~(SYSCTL_RCC_MOSCDIS);
        Delay(524288);
        HWREG(SYSCTL_RCC) = ((HWREG(SYSCTL_RCC) & ~(SYSCTL_RCC_OSCSRC_M)) |
                             SYSCTL_RCC_OSCSRC_MAIN);
    #endif
    #endif

  • Hey Charles,

    Thanks for your response. I must confess I am not too familiar with the bootloader. Will this change to the bootloader function allow the customer to reconfigure the current chip they are using (will this activate before the device boots up with the problematic config), or is this change intended for correctly configuring the bootloader on a new chip?

    Best Regards,

    Jacob Butler

  • Hi Jacob,

      They will need to reprogram the booloader to their current chip and new chip with the change so they can work with the internal oscillator. The device will boot up using the internal oscillator by default. But the current way the bootloader is written will change to the main oscillator by calling the ConfigureDevice() function. If you want the bootloader to continue with the internal oscillator you will need to undefine the CRYSTAL_FREQ so the ConfigureDevice() is sort of bypassed. 

  • Hi Charles,

    Thanks for the explanation. The customer now has the bootloader working correctly on a new chip.

    The question still remains if it is possible to recover the improperly configured chip. You mentioned in your previous response that they will need to reprogram the bootloader to their current chip, but how can they reprogram the bootloader if they can't communicate with the chip because it does not have a clock? This is why the customer asked about erasing the internal flash. Their question is:

    1. Does TI have a procedure to erase the internal flash to return the device to factory settings when the chip does not have a clock?

    Without this the only solution I can think of would be to connect an external oscillator to allow the MCU to boot and then reprogram the bootloader to not require the external oscillator. Not ideal, but do you think this would work?

    Best Regards,

    Jacob Butler

  • Hi Jacob,

     For the current chip they will need to erase the flash using the JTAG interface. I hope they have the JTAG connector on their board so they can use either the Uniflash or CCS to erase the flash.