Problem with running AT91SAM7S with external clock and emulator connected.

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Problem with running AT91SAM7S with external clock and emulator connected.

    Hello,

    I have run into a problem running an AT91SAM7S with a 24 MHz external clock, and think that I have narrowed it down to being an emulator-related problem, since the same code runs fine when it is running from flash without the emulator attached.

    The problem occurs when selecting the Main clock as the Master Clock. The processor seems to go into an undefined state and hangs (sometimes with an abort condition or other exceptions).

    However, if I set a breakpoint at the line where the switch occurs, execute one single step after hitting the breakpoint, and then run the rest of the program, the problem does not occur. The problem also does not occur if the processor runs without the emulator attached, or if the MCKR already contains 0x00000001 at the start of the program.

    Is there any way to avoid this problem? I'd like to be able to run the program without using the breakpoint "workaround".

    Source Code

    1. ...
    2. AT91C_BASE_PMC->PMC_MOR = (AT91C_CKGR_OSCOUNT | AT91C_CKGR_OSCBYPASS);
    3. while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS) == 0) { ; }
    4. /* Main Clock will be equal to external clock */
    5. /* If new value for CSS corresponds to Main Clk or Slow Clk, program CSS first. Datasheet 03.12.07 p. 214f */
    6. /* Set breakpoint on line below. */
    7. /* Behavior: No breakpoint here: Crash
    8. Breakpoint here, Run: Crash
    9. Breakpoint here, single step, run: runs */
    10. AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_CSS) |
    11. AT91C_PMC_CSS_MAIN_CLK;
    12. while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) { ; }
    13. AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_PRES) |
    14. AT91C_PMC_PRES_CLK;
    15. while((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0) { ; }
    16. ...
    Display All