In my program, I enter and leave low-power mode (all function calls are made from system mode, where the main code runs) back and forth. With low power-mode, I am referring to the 32kHz RC oscillator, with a prescaler of 64 which yields 500Hz. The full power-mode is bases on an external crystal that with PLL yields 24MHz MCK.
My problem is that when I enter the low-power mode by selecting slow clock, the chip restarts (at least the debug output on the rs232 console makes it look that way). I am using the following code to power down/power up:
It seems like gcc produces broken code for a few of my functions… I have tried both 4.4.2 and 4.1.1 for windows, with the same results. I have attached an excerpt of the problem below (offset -#207 etc)
Anyone have any idea of what to do? Simply replacing this .c file with assembler wont do it, as I need to formally guarantee that the (rest of the) generated code really is executed.
monstrum:
Have you checked your header-files? I would be very surprised if the compiler could treat registers differently.
So, check the sam7-register definitions, and if you still can’t find anything wrong, try writing and reading the addresses directly in the code.
I did a test - I compiled the file using gcc 3.2.3 in Linux, and there it performs correctly. Only 4.x that misbehaves. Will try to get a 4.4.2 toolchain for linux to give that a try too.
Then I would try to find exactly what line is causing the reboot. Dump some text to the terminal, or toggle pins or whatever between each statement and make sure the output buffers are flushed before continuing to the next.
What I came to think of. When you disable the voltage-regulator (although you say this reset occurs even if you leave the regulator on) won’t the brown-out detector be mad and reset the chip?
monstrum:
Then I would try to find exactly what line is causing the reboot. Dump some text to the terminal, or toggle pins or whatever between each statement and make sure the output buffers are flushed before continuing to the next.
What I came to think of. When you disable the voltage-regulator (although you say this reset occurs even if you leave the regulator on) won’t the brown-out detector be mad and reset the chip?
The BOD is disabled (programmed that way using SAM-BA).
For the SE devices, rev A seem to be the latest. I was referring to the S devices, which also have a rev B.
The errata for SE doesn’t mention this, but as the SE and S are very similar, I would bet that it’s an undocumented bug. At least you could try running the sleep-code from RAM and see if it works.
monstrum:
For the SE devices, rev A seem to be the latest. I was referring to the S devices, which also have a rev B.
The errata for SE doesn’t mention this, but as the SE and S are very similar, I would bet that it’s an undocumented bug. At least you could try running the sleep-code from RAM and see if it works.
I have tried placing the PD-function in SRAM. The result is that the chip reboots one out of ten times, but it never ever gets past the slow clock-selection (the first line in the function). There obviously is something happening that depends on the SRAM, but it doesn’t seem to be the complete solution.
The problem is now solved, cause: gross incompetence on my part…
When I changed to slow clock, I started with switching clock source as stated in the datasheet, but this also sets the prescaler to 1:1, which is way too fast for a 1.8V system running with 96MHz output from the PLL.
The new way I do it now is:
PLL_CLOCK | PRES_64;
wait (until locked);
SLOW_CLOCK | PRES_64;
wait (until locked);
This way I get no too fast glitches for the chip to handle. This works from both flash and sram.