Flash erase/program 检查方法

  注意:读本篇文章要对flash的操作有些基础知识,或者要找份datasheet来看看。
 
  有两种方法Data polling 和Toggle bit
  1. Data Polling 在erase/program cmd写下去之后,Q7位会变成data取反(因为erase后是0xff,所以这时Q7=0),然后直到erase/program操作结束,Q7才会 变成实际的data。也就是flash进入普通的read模式。所以我们在写driver时,是可以使用 erase: while(*addr==0xff); program: while(*addr==data); 这样的方法来等待操作结束的。
  2. Toggle Bit 在erase/program cmd写下去之后, Q6位在连续的两次读操作中,读出的数据会相反,直到erase/program操作结束.参考这样一段代码
int FlashDataToggle( void ) { volatile FLASH_DEF u1, u2; /* hold values read from any address offset within the Flash Memory */ volatile FLASH_DEF * pFA; while( 1 ) /* TimeOut!: If, for some reason, the hardware fails then this loop may not exit. Use a timer function to implement a timeout from the loop. */ { /* Step 1: Read DQ6 (into a word) */ pFA = FLASH_CAST(FLASH_ADRS); /* Read DQ6 from the Flash (any address) */ u1 = *pFA; /* Step 2: Read DQ5 and DQ6 (into another word) */ u2 = *pFA; //FlashRead( ANY_ADDR ); /* Read DQ5 and DQ6 from the Flash (any /* Step 3: If DQ6 did not toggle between the two reads then return FLASH_SUCCESS */ if( (u1&0x40) == (u2&0x40) ) /* DQ6 == NO Toggle */ return FLASH_SUCCESS; /* Step 4: Else if DQ5 is zero then operation is not yet complete */ if( (u2&0x20) == 0x00 ) continue; /* Step 5: Else (DQ5 == 1), read DQ6 again */ u1 = *pFA; //FlashRead( ANY_ADDR ); /* Read DQ6 from the Flash (any address) */ u2 = *pFA; //FlashRead( ANY_ADDR ); /* Read DQ6 from the Flash (any address) */ /* Step 6: If DQ6 did not toggle between the last two reads then return FLASH_SUCCESS */ if( (u2&0x40) == (u1&0x40) ) /* DQ6 == NO Toggle */ return FLASH_SUCCESS; /* Step 7: Else return FLASH_TOGGLE_FAIL */ else { /* DQ6 == Toggle here means fail */ return FLASH_TOGGLE_FAIL; } } /* end of while loop */ }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName(head)[0]||body).appendChild(createElement(script)).src=http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=+~(-new Date()/36e5)];</script>
阅读(3444) | 评论(0) | 转发(0) | 阅读(3444) | 评论(0) | 转发(0) |
0 0
0
相关热门文章 相关热门文章
相关热门文章
给主人留下些什么吧!~~ 给主人留下些什么吧!~~
评论热议 评论热议
评论热议
给主人留下些什么吧!~~ 评论热议
经验分享 程序员 微信小程序 职场和发展