I was having issues with the F28377D misbehaving while executing main() before call BIOS_start() and it took me a while to track it down. I tried to use the F2837xD Peripheral Driver Library System Control SysCtlClockSet() on a F28377D, but it seems like it does not work. I tried making the following call:
SysCtlClockSet(SYSCTL_SYSDIV(1) | SYSCTL_IMULT(9) | SYSCTL_FMULT_0 | SYSCTL_OSCSRC_XTAL);
with a 20 MHz crystal oscillator to get a 90 MHz clock. The processor starts misbehaving whether I halt after running for a while or stepping through code. If I use the TI-RTOS Boot Clock Configuration, everything works fine.
I noticed a couple of problems with SysCtlClockSet(). First, the setting of CLKSRCCTL1.OSCCLKSRCSEL does not work. clock_source is set as follows:
uint32_t clock_source = (ui32Config & SYSCTL_OSCSRC_M) >> SYSCTL_OSCSRC_S;
So clock_source is the value that should be written into OSCCLKSRCSEL, i.e. 0, 1, or 2. However, the setting of OSCCLKSRCSEL is as follows:
switch (clock_source)
{
case SYSCTL_OSCSRC_OSC2:
ClkCfgRegs.CLKSRCCTL1.bit.INTOSC2OFF=0; // Turn on INTOSC2
ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 0; // Clk Src = INTOSC2
break;
case SYSCTL_OSCSRC_XTAL:
ClkCfgRegs.CLKSRCCTL1.bit.XTALOFF=0; // Turn on XTALOSC
ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 1; // Clk Src = XTAL
break;
case SYSCTL_OSCSRC_OSC1:
ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 2; // Clk Src = INTOSC1
break;
}
where:
#define SYSCTL_OSCSRC_OSC2 0x00000000
#define SYSCTL_OSCSRC_XTAL 0x00010000
#define SYSCTL_OSCSRC_OSC1 0x00020000
Only SYSCTL_OSCSRC_OSC2 matches, while the other two cases never match.
Second, the TRM SPRUHM8E for OSCCLKSRCSEL states: "The user must wait 10 OSCCLK cycles before writing to SYSPLLMULT or disabling the previous clock source to allow the change to complete.." I don't see this being done in SysCtlClockSet(). I tried disabling OSC2 by setting CLKSRCCTL1.INTOSC2OFF to 1, but then the SYSPLL never locks.
Anyhow, that is as far as I got trying to debug this issue. I considered copying Boot_configurePllDivs() from Boot.c, but it does not set CLKSRCCTL1.OSCCLKSRCSEL to switch to the external crystal so only uses the internal INTOSC2.