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

📄 flashcode1.lst

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

 242   2                      if (dat == poll)        // compare DQ7 
 243   2      
 244   2                              done = TRUE;     // dat byte programmed into flash OK at the same
 245   2                                               // time timout error occured, indicate successful 
 246   2                                              // exit criteria
 247   2      
 248   2                      *(FLASH_BOOT_X555) = 0xF0;  // reset the flash array (short reset instruction) 
 249   2                              // now delay 3 msec per dat sheet
 250   2          }
 251   1      
 252   1              return(done);         // a successful flash write returns 1, timeout error returns 0
 253   1      }
 254          
 255          
 256          #endif
 257          
 258          
 259          
 260          /*
 261          Module: flash_write_with_toggle
 262          Programs a single byte, checks status using toggle method.
 263          You'll need to include the header files generated by PSDsoft
 264          Express. Important: if memory paging is used, the correct page 
 265          value must be set in the PSD page register prior to calling this 
 266          function.
 267          */
 268          
 269          #ifdef _F_W_W_T
              
              unsigned char flash_write_with_toggle(addr,dat) 
              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
C51 COMPILER V7.06   FLASHCODE1                                                            10/10/2004 20:51:48 PAGE 6   

              
                              error = toggle_B & NVM_ERROR;   // save timeout error flag at DQ5
              
                              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
 346          
 347          
 348          
 349          /*
 350          Module: flash_erase_bulk
 351          Erases the entire main Flash memory (all sectors).
 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          #ifdef _F_E_B
 365          
C51 COMPILER V7.06   FLASHCODE1                                                            10/10/2004 20:51:48 PAGE 7   

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

⌨️ 快捷键说明

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