⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flashcode1.lst

📁 ST公司的upsd34XX评估板固定源程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 212   1        *(FLASH_BOOT_X555) = 0xA0;                 // write 0xA0 command to program
 213   1      
 214   1        *(addr) = dat;                             // write byte to flash
 215   1        dat = dat & NVM_DATA_POLL;                 // get bit DQ7 of original dat
 216   1      
 217   1        do                      // now use dat polling method to verify successful write
 218   1         {
 219   2          poll = *(addr);                  // Read the location that was just programmed
 220   2          error = poll & NVM_ERROR;                // save timeout error bit at DQ5
 221   2          poll = poll & NVM_DATA_POLL;           // get DQ7 of poll byte read from flash
 222   2      
 223   2          if (dat == poll)                         // compare DQ7
 224   2           {
 225   3            done = TRUE;                           // dat byte programmed into flash OK,
 226   3                                                   // indicate successful exit criteria
 227   3           }
 228   2          else if (error ==  NVM_ERROR )           // check for timeout error
 229   2           {
 230   3            err = TRUE;                            // indicate timeout error occurred
 231   3           }
 232   2      
 233   2         }
 234   1        while((done == FALSE) && (err == FALSE));
 235   1      
 236   1      
 237   1        if (err == TRUE)                  // make sure timeout error and dat poll didn't
 238   1                                                   // occur simultaneously
 239   1         {
 240   2          poll = *(addr);                          // Read location in flash again
 241   2          poll = poll & NVM_DATA_POLL;           // get DQ7 of poll byte read from flash
C51 COMPILER V7.06   FLASHCODE1                                                            10/15/2004 20:55:30 PAGE 5   

 242   2          if (dat == poll)                         // compare DQ7
 243   2           {
 244   3            done = TRUE;                // dat byte programmed into flash OK at the same
 245   3                         // time timout error occured, indicate successful exit criteria
 246   3           }
 247   2          *(FLASH_BOOT_X555) = 0xF0;  // reset the flash array (short reset instruction)
 248   2                                                   // now delay 3 msec per dat sheet
 249   2         }
 250   1        return(done);     // a successful flash write returns 1, timeout error returns 0
 251   1       }
 252          
 253          #endif
 254          
 255          
 256          
 257          
 258          
 259          
 260          
 261          
 262          #ifdef _F_W_W_T
              
              unsigned char flash_write_with_toggle(addr,dat)
              /******************************************************************************
               Function   : unsigned char flash_write_with_toggle()
               Parameters : (addr,dat)
               Description: Programs a single byte, checks status using toggle method.
              
                        You'll need to include the header files generated by PSDsoft
                       Express. Important: if memory paging is used, the correct page
                      value must be set in the PSD page register prior to calling this
                                                 function.
               ******************************************************************************/
              volatile unsigned char *addr;
              unsigned char dat;
               {
                unsigned char done;
                unsigned char error;
                unsigned char err;
                volatile unsigned char toggle_A;
                volatile unsigned char toggle_B;
              
                done = FALSE;
                err = FALSE;
              
                                            //  Note:  the following constants (FLASH_BOOT_XXXX)
                                            //     are declared type volatile in the header file
                                            //    so they are not optimized away by the compiler
              
                *(FLASH_BOOT_X555) = 0xAA;     // unlock main flash, write 0xAA to addess 0xX555
                *(FLASH_BOOT_XAAA) = 0x55;     // unlock main flash, write 0x55 to addess 0xXAAA
                *(FLASH_BOOT_X555) = 0xA0;                 // write 0xA0 command to program
              
                *(addr) = dat;                             // write byte to flash
                                           // now use toggling method to verify successful write
                toggle_A = *(addr);                // Read the location that was just programmed
                toggle_A = toggle_A & NVM_DATA_TOGGLE;     // mask toggle bit at DQ6
              
                do
                 {
                  toggle_B = *(addr);        // Again read the location that was just programmed
                  error = toggle_B & NVM_ERROR;            // save timeout error flag at DQ5
C51 COMPILER V7.06   FLASHCODE1                                                            10/15/2004 20:55:30 PAGE 6   

                  toggle_B = toggle_B & NVM_DATA_TOGGLE;   // mask toggle bit at DQ6
                  if (toggle_A == toggle_B)                // compare toggle bit DQ6
                   {
                    done = TRUE;                 // bit did not toggle, dat byte programmed into
                                                  // flash OK, indicate successful exit criteria
                   }
                  else if (error ==  NVM_ERROR )           // check for timeout error
                   {
                    err = TRUE;                            // indicate timeout error occurred
                   }
                  toggle_A = toggle_B;                  // save most recent sample of toggle bit
                                                           // to compare with next sample
                 }
                while((done == FALSE) && (err == FALSE));
              
              
                if (err == TRUE)                // make sure timeout error and dat toggle didn't
                                                           // occur simultaneously
                 {
                  toggle_B = *(addr);                      // Read location in flash again
                  toggle_B = toggle_B & NVM_DATA_TOGGLE;   // mask toggle bit at DQ6
                  if (toggle_A == toggle_B)                // compare toggle bit DQ6
                   {
                    done = TRUE;                // dat byte programmed into flash OK at the same
                                 // time timout error occured, indicate successful exit criteria
                   }
                  *(FLASH_BOOT_X555) = 0xF0;  // reset the flash array (short reset instruction)
                                                           // now delay 3 msec per dat sheet
                 }
              
                return(done);     // a successful flash write returns 1, timeout error returns 0
               }
              
              #endif
 338          
 339          
 340          
 341          
 342          
 343          
 344          #ifdef _F_E_B
 345          
 346          unsigned char flash_erase_sector(volatile unsigned char xdata* flash_bulk_erase_address)
 347          /******************************************************************************
 348           Function   : unsigned char flash_erase_sector()
 349           Parameters : (volatile unsigned char xdata* flash_bulk_erase_address)
 350           Description: Erases the entire main Flash memory (all sectors).
 351          
 352                    You'll need to include the header files generated by PSDsoft
 353                   Express. Important: The address passed to this function should
 354                        be independent of memory paging or else the PSD page
 355               register value should be set to the correct page prior to calling this
 356                                             function.
 357          
 358              Note: The address that is passed in this function can be an address that
 359                resides in any Flash segment that has a chip select. For example, if
 360                fs0 and fs5 are used in the design, passing an address in this function
 361                that resides in either fs0 or fs5 will invoke the bulk erase operation.
 362           ******************************************************************************/
 363           {
 364   1        unsigned char done;
 365   1        unsigned char poll;
C51 COMPILER V7.06   FLASHCODE1                                                            10/15/2004 20:55:30 PAGE 7   

 366   1        unsigned char error;
 367   1        unsigned char err;
 368   1      
 369   1        done = FALSE;
 370   1        err = FALSE;
 371   1                                  //  Note:  the following constants (FLASH_COMMON_XXXX)
 372   1                                    //     are declared type volatile in the header file
 373   1                                    //    so they are not optimized away by the compiler
 374   1      
 375   1        *(FLASH_COMMON_X555) = 0xAA;   // unlock main flash, write 0xAA to addess 0xX555
 376   1        *(FLASH_COMMON_XAAA) = 0x55;   // unlock main flash, write 0x55 to addess 0xXAAA
 377   1        *(FLASH_COMMON_X555) = 0x80;          // write 0x80 command to erase entire chip
 378   1        *(FLASH_COMMON_X555) = 0xAA;               // continue unlock sequence
 379   1        *(FLASH_COMMON_XAAA) = 0x55;               // continue unlock sequence
 380   1         //*(FLASH_COMMON_X555) = 0x10;  // write 0x10 command to complete erase command
 381   1        *(flash_bulk_erase_address) = 0x30;     // write 0x30 to sector address to erase
 382   1      
 383   1        do                      // now use dat polling method to verify successful erase
 384   1         {
 385   2          poll = *(flash_bulk_erase_address);      // read flash status from any address
 386   2                                               // within the defined flash address space
 387   2          error = poll & NVM_ERROR;                // save timeout error bit at DQ5
 388   2          poll = poll & NVM_DATA_POLL;             // look at D7
 389   2          if (poll == NVM_DATA_POLL)               // compare DQ7
 390   2           {
 391   3            done = TRUE;             // bulk erase OK, indicate successful exit criteria
 392   3           }
 393   2          else if (error == NVM_ERROR)             // check for timeout error
 394   2           {
 395   3            err = TRUE;                            // indicate timeout error occurred
 396   3           }
 397   2         }
 398   1        while((done == FALSE) && (err == FALSE));
 399   1      
 400   1      
 401   1        if (err == TRUE)                  // make sure timeout error and dat poll didn't
 402   1                                                   // occur simultaneously
 403   1         {
 404   2          poll = *(flash_bulk_erase_address);      // Read flash status again
 405   2          poll = poll & NVM_DATA_POLL;           // get DQ7 of poll byte read from flash
 406   2          if (poll == NVM_DATA_POLL)               // compare DQ7
 407   2           {
 408   3            done = TRUE;                           // the flash erased OK at the same
 409   3                         // time timout error occured, indicate successful exit criteria
 410   3           }
 411   2          *(FLASH_COMMON_X555) = 0xF0;// reset the flash array (short reset instruction)
 412   2                                                   // now delay 3 msec per dat sheet
 413   2         }
 414   1      
 415   1        return(done);     // a successful flash erase returns 1, timeout error returns 0
 416   1      
 417   1       }
 418          
 419          
 420          
 421          
 422          
 423          unsigned char flash_boot_erase_sector(volatile unsigned char xdata* flash_bulk_erase_address)
 424          /******************************************************************************
 425           Function   : unsigned char flash_boot_erase_sector()
 426           Parameters : (volatile unsigned char xdata* flash_bulk_erase_address)
 427           Description: Erases sector in boot flash.
C51 COMPILER V7.06   FLASHCODE1                                                            10/15/2004 20:55:30 PAGE 8   

 428           ******************************************************************************/
 429           {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -