Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE
The problem arises when trying to reconfigure the PLL to run from INTOSC2, when it was running from XTAL before. Roughly 75% of the time, the MCU crashes in this situation, and often ends up at 0x3fd226.
I have attached a modified version of the TI "led_ex1_c28x_cm_blinky_cpu1" example that illustrates the problem.
First, the MCU is configured to run from XTAL, then INTOSC2.
If I disable either configuration step, the code runs fine. If I leave both enabled, the MCU will often crash. This code is compiled to run from RAM and I load it using CCS.
//#############################################################################
//
// FILE: led_ex1_c28x_cm_blinky_cpu1.c
//
// TITLE: LED Blinky Example
//
//! \addtogroup driver_cm_c28x_dual_example_list
//! <h1> LED Blinky Example</h1>
//!
//! This example demonstrates how to blink a LED using CPU1 and blink another
//! LED using CM (led_ex1_blinky_cm.c).
//!
//! \b External \b Connections \n
//! - None.
//!
//! \b Watch \b Variables \n
//! - None.
//!
//
//#############################################################################
// $TI Release: F2838x Support Library v2.00.00.03 $
// $Release Date: Sun Sep 29 07:45:41 CDT 2019 $
// $Copyright:
// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
//
// 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.
// $
//#############################################################################
//
// Included Files
//
#include "driverlib.h"
//#include "device.h"
extern void Device_enableAllPeripherals(void);
extern void Device_initGPIO(void);
#define DEVICE_GPIO_PIN_LED1 31U // GPIO number for LD2
#define DEVICE_GPIO_PIN_LED2 34U // GPIO number for LD3
#define DEVICE_GPIO_CFG_LED1 GPIO_31_GPIO31 // "pinConfig" for LD2
#define DEVICE_GPIO_CFG_LED2 GPIO_34_GPIO34 // "pinConfig" for LD3
#define DEVICE_OSCSRC_FREQ_XTAL 20000000U
#define DEVICE_OSCSRC_FREQ_INTOSC 10000000U
#define DEVICE_SYSCLK_FREQ 190000000U
#define DEVICE_AUXCLK_FREQ 120000000U
#define DEVICE_LSPCLK_FREQ (DEVICE_SYSCLK_FREQ/4)
#define DEVICE_DELAY_US(x) SysCtl_delay(((((long double)(x)) / (1000000.0L / \
(long double)DEVICE_SYSCLK_FREQ)) - 9.0L) / 5.0L)
#define DEVICE_SETCLOCK_CFG_XTAL (SYSCTL_OSCSRC_XTAL | SYSCTL_IMULT(38) | \
SYSCTL_REFDIV(2) | SYSCTL_ODIV(2) | \
SYSCTL_SYSDIV(1) | SYSCTL_PLL_ENABLE | \
SYSCTL_DCC_BASE_1)
#define DEVICE_AUXSETCLOCK_CFG_XTAL (SYSCTL_AUXPLL_OSCSRC_XTAL | SYSCTL_AUXPLL_IMULT(120) | \
SYSCTL_REFDIV(5U) | SYSCTL_ODIV(4U) | \
SYSCTL_AUXPLL_DIV_1 | SYSCTL_AUXPLL_ENABLE | \
SYSCTL_DCC_BASE_0)
#define DEVICE_SETCLOCK_CFG_INTOSC (SYSCTL_OSCSRC_OSC2 | SYSCTL_IMULT(38) | \
SYSCTL_REFDIV(2) | SYSCTL_ODIV(1) | \
SYSCTL_SYSDIV(1) | SYSCTL_PLL_ENABLE | \
SYSCTL_DCC_BASE_1)
#define DEVICE_AUXSETCLOCK_CFG_INTOSC (SYSCTL_AUXPLL_OSCSRC_OSC2 | SYSCTL_AUXPLL_IMULT(120) | \
SYSCTL_REFDIV(5U) | SYSCTL_ODIV(2U) | \
SYSCTL_AUXPLL_DIV_1 | SYSCTL_AUXPLL_ENABLE | \
SYSCTL_DCC_BASE_0)
//
// Main
//
void main(void)
{
//
// Disable the watchdog
//
SysCtl_disableWatchdog();
#ifdef _FLASH
//
// Copy time critical code and flash setup code to RAM. This includes the
// following functions: InitFlash();
//
// The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart symbols
// are created by the linker. Refer to the device .cmd file.
//
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
//
// Call Flash Initialization to setup flash waitstates. This function must
// reside in RAM.
//
Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, DEVICE_FLASH_WAITSTATES);
#endif
#ifdef CPU1
#if 1
// Configure clock tree from XTAL
SysCtl_setClock(DEVICE_SETCLOCK_CFG_XTAL);
SysCtl_setLowSpeedClock(SYSCTL_LSPCLK_PRESCALE_4);
SysCtl_setAuxClock(DEVICE_AUXSETCLOCK_CFG_XTAL);
SysCtl_setCMClk(SYSCTL_CMCLKOUT_DIV_1,SYSCTL_SOURCE_AUXPLL);
ASSERT(SysCtl_getClock(DEVICE_OSCSRC_FREQ_XTAL) == DEVICE_SYSCLK_FREQ);
ASSERT(SysCtl_getLowSpeedClock(DEVICE_OSCSRC_FREQ_XTAL) == DEVICE_LSPCLK_FREQ);
ASSERT(SysCtl_getAuxClock(DEVICE_OSCSRC_FREQ_XTAL) == DEVICE_AUXCLK_FREQ);
#endif
#if 1
// Configure clock tree from INTOSC
SysCtl_setClock(DEVICE_SETCLOCK_CFG_INTOSC);
SysCtl_setLowSpeedClock(SYSCTL_LSPCLK_PRESCALE_4);
SysCtl_setAuxClock(DEVICE_AUXSETCLOCK_CFG_INTOSC);
SysCtl_setCMClk(SYSCTL_CMCLKOUT_DIV_1,SYSCTL_SOURCE_AUXPLL);
ASSERT(SysCtl_getClock(DEVICE_OSCSRC_FREQ_INTOSC) == DEVICE_SYSCLK_FREQ);
ASSERT(SysCtl_getLowSpeedClock(DEVICE_OSCSRC_FREQ_INTOSC) == DEVICE_LSPCLK_FREQ);
ASSERT(SysCtl_getAuxClock(DEVICE_OSCSRC_FREQ_INTOSC) == DEVICE_AUXCLK_FREQ);
#endif
#endif
//
// Turn on all peripherals
//
Device_enableAllPeripherals();
Device_initGPIO();
//
// Boot CM core
//
//#ifdef _FLASH
// Device_bootCM(BOOTMODE_BOOT_TO_FLASH_SECTOR0);
//#else
// Device_bootCM(BOOTMODE_BOOT_TO_S0RAM);
//#endif
//
// Initialize GPIO and configure the GPIO pin as a push-pull output
//
Device_initGPIO();
GPIO_setPadConfig(DEVICE_GPIO_PIN_LED1, GPIO_PIN_TYPE_STD);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED1, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(DEVICE_GPIO_PIN_LED2, GPIO_PIN_TYPE_STD);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2, GPIO_DIR_MODE_OUT);
//
// Configure CPU2 to control the LED GPIO
//
GPIO_setMasterCore(DEVICE_GPIO_PIN_LED2, GPIO_CORE_CM);
//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();
//
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;
//
// Loop Forever
//
for(;;)
{
//
// Turn on LED
//
GPIO_writePin(DEVICE_GPIO_PIN_LED1, 0);
//
// Delay for a bit.
//
DEVICE_DELAY_US(500000);
//
// Turn off LED
//
GPIO_writePin(DEVICE_GPIO_PIN_LED1, 1);
//
// Delay for a bit.
//
DEVICE_DELAY_US(500000);
}
}
//
// End of File
//