[En-Nut-Discussion] AT91 MC_FMR_EFC1 in nutinit.c

Bob Wirka bobwirka at yahoo.com
Fri Oct 4 15:11:17 CEST 2013


/nut/arch/arm/os/nutinit.c needs to initialize MC_FMR_EFC1 for 7X512 devices.


Working with ethernut-4.10.3 on an AT91SAM7X512. Looks like the code is the same in 5.1.0.

NutInit() properly initializes the flash mode register for the first bank, but not the second. This results in improper programming of flash in the second bank. At91EfcCmdEx() would return before programming was complete. This caused programming errors (unless you added a delay after programming a page). It also causes your code to go into the weeds if your firmware image is larger than 256K and extends into the second bank.


My mod is:

#if defined(MCU_AT91SAM7X) || defined (MCU_AT91SAM7S) || defined(MCU_AT91SAM7SE)
    {
        uint32_t freq = NutGetCpuClock();
        /* Set Flash Waite state. */
        outr(MC_FMR_EFC0, ((((freq + freq / 2) / 1000000UL) & 0xFF) << 16) | MC_FWS_2R3W);
#if defined(MCU_AT91SAM7X512)
        outr(MC_FMR_EFC1, ((((freq + freq / 2) / 1000000UL) & 0xFF) << 16) | MC_FWS_2R3W);
#endif
    }
#endif


Hope this helps.

Bob Wirka
Realtime Control Works


More information about the En-Nut-Discussion mailing list