[En-Nut-Discussion] Problems writing to flash in Ethernut 3

Harald Kipp harald.kipp at egnite.de
Fri Mar 17 18:12:34 CET 2006


The flash is used in 16-bit mode, while you are
using 8-bit mode. Also volatile is required at
certain points. Otherwise your code may not work
with compiler optimization.

This code should work:

typedef unsigned short flashdat_t;
typedef volatile unsigned short * flashptr_t;
typedef unsigned long flashadr_t;

static unsigned long FlashWaitReady(flashptr_t addr, flashdat_t data)
{
     volatile long tmo = 0x1000000;

     while(*addr != data) {
         if (--tmo <= 0) {
             return 1;
         }
     }
     return 0;
}

unsigned long FlashIdentifier(flashptr_t base)
{
     unsigned long id;

     base[0x555] = 0xAA;
     base[0xAAA] = 0x55;
     base[0x555] = 0x90;
     id = base[0];
     id <<= 16;
     id |= base[1];
     base[0x555] = 0xAA;
     base[0xAAA] = 0x55;
     base[0x555] = 0xF0;

     return id;
}

unsigned long FlashEraseSector(flashptr_t base, flashptr_t addr)
{
     base[0x555] = 0xAA;
     base[0xAAA] = 0x55;
     base[0x555] = 0x80;
     base[0x555] = 0xAA;
     base[0xAAA] = 0x55;
     *addr = 0x30;

     return FlashWaitReady(addr, (flashdat_t)0xFFFF);
}

unsigned long FlashWrite(flashptr_t base, flashptr_t addr, flashdat_t data)
{
     base[0x555] = 0xAA;
     base[0xAAA] = 0x55;
     base[0x555] = 0xA0;
     *addr = data;

     return FlashWaitReady(addr, data);
}

Harald

At 16:59 17.03.2006 +0100, you wrote:

>     unsigned char *puntero=(unsigned char *)0x10000000;
>
>     NutSleep(2000);
>     puntero[0x555]=0xAA;
>     puntero[0xAAA]=0x55;
>     puntero[0x555]=0xA0;
>     puntero[0x10001]=0x30;
>     NutSleep(1000);
>     valor=puntero[0x010001]; // Read the value
>     sprintf(cadena2,"Leo: %X",valor);
>     ezlcd_print(global_lcd,NULL,cadena2); // print it at the LCD
>
>But I always read 0xFF




More information about the En-Nut-Discussion mailing list