X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Farm%2Fhw%2Finit_at91.c;h=1bba1c223e044aaceecb5ebe4570b7ecef5cc186;hb=e444d916197e4345dd2bbd85800d8544c2699096;hp=9c3eeb208c92fc03ff5062490598e8de25928dfb;hpb=5e046ad751e05b325e5337bd26b22e340ac8ad67;p=bertos.git diff --git a/bertos/cpu/arm/hw/init_at91.c b/bertos/cpu/arm/hw/init_at91.c index 9c3eeb20..1bba1c22 100644 --- a/bertos/cpu/arm/hw/init_at91.c +++ b/bertos/cpu/arm/hw/init_at91.c @@ -150,8 +150,22 @@ void __init2(void); */ void __init1(void) { - /* Use 2 cycles for flash access. */ - MC_FMR = MC_FWS_2R3W; + /* + * Compute number of master clock cycles in 1.5us. + * Needed by flash writing functions. + * The maximum FMCN value is 0xFF and 0 can be used only if + * master clock is less than 33kHz. + */ + #define MCN DIV_ROUNDUP(CPU_FREQ, 666667UL) + #define FMCN (CPU_FREQ <= 33333UL ? 0 : (MCN < 0xFF ? MCN : 0xFF)) + + #if CPU_FREQ < 30000000UL + /* Use 1 cycles for flash access. */ + MC_FMR = FMCN << MC_FMCN_SHIFT | MC_FWS_1R2W; + #else + /* Use 2 cycles for flash access. */ + MC_FMR = FMCN << MC_FMCN_SHIFT | MC_FWS_2R3W; + #endif /* Disable all interrupts. Useful for debugging w/o target reset. */ AIC_EOICR = 0xFFFFFFFF;