|
I just finished pulling my hair out on another issue we had when moving to the Rev C chips. We are using a custom bootloader that will do something like this upon reset:
Reset() { IF SomeFlashLocation[x] == MAGIC_NUMBER Then goto ApplicationStartupCode();
// if not, we are in firmware update mode and do the following: LowLevelInit(); Copy Bootloader to RAM Goto Bootloader() in RAM }
LowLevelInit() { Initialize Main Oscillator Setup PLL Setup Master Clock }
Bootloader() { flash some LED to indicate that we are ready to download firmware }
This worked fine with the Rev B chip, but the new Rev C chip will not get to the flashing LED. It stalls prior to that. After narrowing it down I came to this conclusion:
In the LowLevelInit function, I am setting up the Master Clock like this:
while (!(PMC_INTERRUPT_STATUS & 4));
// wait for the master clock if it was already initialized while (!(PMC_INTERRUPT_STATUS & 8));
// switch to slow clock + prescaler PMC_MASTER_CLK = PMC_CLK_SELECTION_SLOW_CLOCK | PMC_CLK_PRESCALE_DIV_2; while (!(PMC_INTERRUPT_STATUS & 8));
// switch to fast clock + prescaler PMC_MASTER_CLK |= PMC_CLK_SELECTION_PLL_CLOCK; while (!(PMC_INTERRUPT_STATUS & 8));
I don't see whats wrong with that, the application code does the exact same thing and it works fine. The code stalls on the last two lines, where the master clock is set to be a fast clock. If I comment those out, continuing to run a slow clock, it will actually work (very slow of course). Now, if I move the master clock setup to be done in RAM (Bootloader() function), all works perfectly fine.
|