Strange that this obvious error survived so long, I have actually used the code to flash an AT91SAM7S running from both 12MHz crystal and the 48MHz PLL for USB and it has worked.
I think the patch needs another fix, since the condition for settng FMCN to 0 is 30uS clock cycle = 33kHz, but the condition for allowing FWS = 0 is a frequency of 30 MHz.
So your code works correctly if the clock is above 33MHz and below 33kHz
(working copy)
--- /home/lundin/delad/arbete/animatronics/arm7/openocd/trunk/src/flash/at91sam7.c (revision 92)
+++ /home/lundin/delad/arbete/animatronics/arm7/openocd/trunk/src/flash/at91sam7.c @@ -220,10 +220,11 @@
/* main clocks in 1.5uS */
fmcn = (at91sam7_info->mck_freq/666666ul)+1;
- /* Only allow fmcn=0 if clock period is > 30 us. */
- if (at91sam7_info->mck_freq <= 33333333ul)
+ /* Only allow fmcn=0 if clock period is > 30 us = 33kHz. */
+ if (at91sam7_info->mck_freq <= 33333ul)
fmcn = 0;
- else
+ /* Only allow fws=0 if clock frequency is < 30 MHz. */
+ if (at91sam7_info->mck_freq > 30000000ul)
fws = 1;
DEBUG("fmcn: %i", fmcn);