This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Trouble programming the AM29F800B Flash Device

I am working with the AM29F800B Flash. I earlier struggled to get the new Flashing Algorithm but was successful in creating an algorithm with the help from this forum.
Now I am able to erase the Flash Device but I'm still having trouble in writing to the Flash device.
Kindly suggest some tips on programming the Flash.

Parents
  • Hallo,

    As soon as you can erase the flash, writing to it should not be a problem. In your e-mail you have to specify more details in order to be answered correctly. Nevertheless, here are some tips.

    1) Double check whether you work with address space correctly. Check if your MCU's A1 address line is connected to the A0 of the flash (a typical h/w implementation for word organized memory). In this case you will need construction like this (pay attention to the << shift):

    #define FWr(X, Y) *(unsigned int volatile far *) (FLASHBASE+((X)<<1))= (Y)
    #define FRd(X)    *(unsigned int volatile far *) (FLASHBASE+((X)<<1))
    

    in order to access the flash correctly to perform write/read operations. Do not forget to define your FLASHBASE (typically this is 0x0)

    2) Now, assume: a) you have your data transferred successfully to the target's (external) RAM space, b) chip has been erased. All you need now, is to call a function similar to that shown below:

    // ************************************************
    // Baklanov N., Oct-2007
    // Write buffer buf[] to the AM29F800BT flash
    // ************************************************
    static int buf2amd(long address, WORD n, WORD far *buf) {
     WORD far *wPtr= &buf[0];
     WORD W;
     WORD status, old_status, err= 0;
    
     while(1) {
       W= *wPtr++;
       FWr(0x555, 0xAA);
       FWr(0x2AA, 0x55);
       FWr(0x555, 0xA0);
       FWr(address, W);
    
       address+= 1L;
    
       old_status= FRd(0x0);              // any allowed address
    
       while(1) { // --------------------------------------
          status= FRd(0x0);   // 40h: DQ6, Toggle bit I
          if((status & 0x40) ==
             (old_status & 0x40)) {
                     // DQ6 is not toggling anymore ...
            break;   // ... means that the erase op. has completed
          };
          // we are here IF the DQ6 is toggling, i.e. erasing is in progress
          if( (status & 0x20) ) { // DQ5= 1 means flash has exceeded time-out
               old_status= FRd(0x0);
               status= FRd(0x0);
               if((status & 0x40) ==
                  (old_status & 0x40)) {  // DQ6 is not toggling ...
                   break;   // ... erase op. has completed
               };
               err= 1;      // DQ6 toggled means flash has a problem
               break;
          };
          old_status= status;
       }; // while(1) : waiting flash ---------------------
       if(err) break;
    
       n--;
       if(!n) break;
     };  // main loop to write whole next array
    
     return err;
    }
    
    

    3) You may also want to reset flash:

    FWr(0L, 0xF0);      // reset AMD
    

    before accessing it, to make sure the chip is out of autoselect mode (if you had recenly read ID out).

    4) And... do not forget to bypass those flash addresses which are inherently assigned to internal MCU's space. E.g., for C167CS it would be the 00'E000h ... 00'FFFFh window - see datasheet.

    Regards,
    Nikolay.

Reply
  • Hallo,

    As soon as you can erase the flash, writing to it should not be a problem. In your e-mail you have to specify more details in order to be answered correctly. Nevertheless, here are some tips.

    1) Double check whether you work with address space correctly. Check if your MCU's A1 address line is connected to the A0 of the flash (a typical h/w implementation for word organized memory). In this case you will need construction like this (pay attention to the << shift):

    #define FWr(X, Y) *(unsigned int volatile far *) (FLASHBASE+((X)<<1))= (Y)
    #define FRd(X)    *(unsigned int volatile far *) (FLASHBASE+((X)<<1))
    

    in order to access the flash correctly to perform write/read operations. Do not forget to define your FLASHBASE (typically this is 0x0)

    2) Now, assume: a) you have your data transferred successfully to the target's (external) RAM space, b) chip has been erased. All you need now, is to call a function similar to that shown below:

    // ************************************************
    // Baklanov N., Oct-2007
    // Write buffer buf[] to the AM29F800BT flash
    // ************************************************
    static int buf2amd(long address, WORD n, WORD far *buf) {
     WORD far *wPtr= &buf[0];
     WORD W;
     WORD status, old_status, err= 0;
    
     while(1) {
       W= *wPtr++;
       FWr(0x555, 0xAA);
       FWr(0x2AA, 0x55);
       FWr(0x555, 0xA0);
       FWr(address, W);
    
       address+= 1L;
    
       old_status= FRd(0x0);              // any allowed address
    
       while(1) { // --------------------------------------
          status= FRd(0x0);   // 40h: DQ6, Toggle bit I
          if((status & 0x40) ==
             (old_status & 0x40)) {
                     // DQ6 is not toggling anymore ...
            break;   // ... means that the erase op. has completed
          };
          // we are here IF the DQ6 is toggling, i.e. erasing is in progress
          if( (status & 0x20) ) { // DQ5= 1 means flash has exceeded time-out
               old_status= FRd(0x0);
               status= FRd(0x0);
               if((status & 0x40) ==
                  (old_status & 0x40)) {  // DQ6 is not toggling ...
                   break;   // ... erase op. has completed
               };
               err= 1;      // DQ6 toggled means flash has a problem
               break;
          };
          old_status= status;
       }; // while(1) : waiting flash ---------------------
       if(err) break;
    
       n--;
       if(!n) break;
     };  // main loop to write whole next array
    
     return err;
    }
    
    

    3) You may also want to reset flash:

    FWr(0L, 0xF0);      // reset AMD
    

    before accessing it, to make sure the chip is out of autoselect mode (if you had recenly read ID out).

    4) And... do not forget to bypass those flash addresses which are inherently assigned to internal MCU's space. E.g., for C167CS it would be the 00'E000h ... 00'FFFFh window - see datasheet.

    Regards,
    Nikolay.

Children