- Thu Aug 31, 2006 3:18 am
#18173
Hi,
the flash timing of an at91sam7 is incorrectly set (written to the read-only FSR instead of to the FMR, zero wait-states regardless of clock speed).
This only hurts when the target runs faster than the default 32kHz CPU clock.
The patch below fixes this.
Cheers
Anders
the flash timing of an at91sam7 is incorrectly set (written to the read-only FSR instead of to the FMR, zero wait-states regardless of clock speed).
This only hurts when the target runs faster than the default 32kHz CPU clock.
The patch below fixes this.
Cheers
Anders
Code: Select all
Fix the timing calculations and write the result to the correct register.
Signed-off-by: Anders Larsen <al@alarsen.net>
---
src/flash/at91sam7.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
Index: b/src/flash/at91sam7.c
===================================================================
--- a/src/flash/at91sam7.c
+++ b/src/flash/at91sam7.c
@@ -206,7 +206,7 @@ void at91sam7_read_clock_info(flash_bank
/* Setup the timimg registers for nvbits or normal flash */
void at91sam7_set_flash_mode(flash_bank_t *bank,int mode)
{
- u32 fmcn, fmr;
+ u32 fmr, fmcn = 0, fws = 0;
at91sam7_flash_bank_t *at91sam7_info = bank->driver_priv;
target_t *target = at91sam7_info->target;
@@ -220,12 +220,14 @@ void at91sam7_set_flash_mode(flash_bank_
fmcn = (at91sam7_info->mck_freq/666666ul)+1;
/* Only allow fmcn=0 if clock period is > 30 us. */
- if (at91sam7_info->mck_freq <= 33333)
+ if (at91sam7_info->mck_freq <= 33333333ul)
fmcn = 0;
+ else
+ fws = 1;
DEBUG("fmcn: %i", fmcn);
- fmr = fmcn<<16;
- target->type->write_memory(target, MC_FSR, 4, 1, (u8 *)&fmr);
+ fmr = fmcn << 16 | fws << 8;
+ target->type->write_memory(target, MC_FMR, 4, 1, (u8 *)&fmr);
}
at91sam7_info->flashmode = mode;
}