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

📄 stm32f10x_flash.s79

📁 用于监视I2C通信总线
💻 S79
📖 第 1 页 / 共 3 页
字号:
//  216   /* Wait for last operation to be completed */
//  217   status = FLASH_WaitForLastOperation(EraseTimeout);
//  218   
//  219   if(status == FLASH_COMPLETE)
//  220   {
//  221     /* if the previous operation is completed, proceed to erase all pages */
//  222      FLASH->CR |= CR_MER_Set;
//  223      FLASH->CR |= CR_STRT_Set;
//  224     
//  225     /* Wait for last operation to be completed */
//  226     status = FLASH_WaitForLastOperation(EraseTimeout);
//  227 
//  228     if(status != FLASH_BUSY)
//  229     {
//  230       /* if the erase operation is completed, disable the MER Bit */
//  231       FLASH->CR &= CR_MER_Reset;
//  232     }
//  233   }	   
//  234   /* Return the Erase Status */
//  235   return status;
//  236 }
//  237 
//  238 /*******************************************************************************
//  239 * Function Name  : FLASH_EraseOptionBytes
//  240 * Description    : Erases the FLASH option bytes.
//  241 * Input          : None
//  242 * Output         : None
//  243 * Return         : FLASH Status: The returned value can be: FLASH_BUSY, 
//  244 *                  FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or 
//  245 *                  FLASH_TIMEOUT.
//  246 *******************************************************************************/
//  247 FLASH_Status FLASH_EraseOptionBytes(void)
//  248 {
//  249   FLASH_Status status = FLASH_COMPLETE;
//  250   
//  251   /* Wait for last operation to be completed */
//  252   status = FLASH_WaitForLastOperation(EraseTimeout);
//  253 
//  254   if(status == FLASH_COMPLETE)
//  255   {
//  256     /* Authorize the small information block programming */
//  257     FLASH->OPTKEYR = FLASH_KEY1;
//  258     FLASH->OPTKEYR = FLASH_KEY2;
//  259     
//  260     /* if the previous operation is completed, proceed to erase the option bytes */
//  261     FLASH->CR |= CR_OPTER_Set;
//  262     FLASH->CR |= CR_STRT_Set;
//  263 
//  264     /* Wait for last operation to be completed */
//  265     status = FLASH_WaitForLastOperation(EraseTimeout);
//  266     
//  267     if(status == FLASH_COMPLETE)
//  268     {
//  269       /* if the erase operation is completed, disable the OPTER Bit */
//  270       FLASH->CR &= CR_OPTER_Reset;
//  271        
//  272       /* Enable the Option Bytes Programming operation */
//  273       FLASH->CR |= CR_OPTPG_Set;
//  274 
//  275       /* Enable the readout access */
//  276       OB->RDP= RDP_Key; 
//  277 
//  278       /* Wait for last operation to be completed */
//  279       status = FLASH_WaitForLastOperation(ProgramTimeout);
//  280  
//  281       if(status != FLASH_BUSY)
//  282       {
//  283         /* if the program operation is completed, disable the OPTPG Bit */
//  284         FLASH->CR &= CR_OPTPG_Reset;
//  285       }
//  286     }
//  287     else
//  288     {
//  289       if (status != FLASH_BUSY)
//  290       {
//  291         /* Disable the OPTPG Bit */
//  292         FLASH->CR &= CR_OPTPG_Reset;
//  293       }
//  294     }  
//  295   }
//  296   /* Return the erase status */
//  297   return status;
//  298 }
//  299 
//  300 /*******************************************************************************
//  301 * Function Name  : FLASH_ProgramWord
//  302 * Description    : Programs a word at a specified address.
//  303 * Input          : - Address: specifies the address to be programmed.
//  304 *                  - Data: specifies the data to be programmed.
//  305 * Output         : None
//  306 * Return         : FLASH Status: The returned value can be: FLASH_BUSY, 
//  307 *                  FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or 
//  308 *                  FLASH_TIMEOUT. 
//  309 *******************************************************************************/
//  310 FLASH_Status FLASH_ProgramWord(u32 Address, u32 Data)
//  311 {
//  312   FLASH_Status status = FLASH_COMPLETE;
//  313 
//  314   /* Check the parameters */
//  315   assert_param(IS_FLASH_ADDRESS(Address));
//  316 
//  317   /* Wait for last operation to be completed */
//  318   status = FLASH_WaitForLastOperation(ProgramTimeout);
//  319   
//  320   if(status == FLASH_COMPLETE)
//  321   {
//  322     /* if the previous operation is completed, proceed to program the new first 
//  323     half word */
//  324     FLASH->CR |= CR_PG_Set;
//  325   
//  326     *(vu16*)Address = (u16)Data;
//  327 
//  328     /* Wait for last operation to be completed */
//  329     status = FLASH_WaitForLastOperation(ProgramTimeout);
//  330  
//  331     if(status == FLASH_COMPLETE)
//  332     {
//  333       /* if the previous operation is completed, proceed to program the new second 
//  334       half word */
//  335       *(vu16*)(Address + 2) = Data >> 16;
//  336     
//  337       /* Wait for last operation to be completed */
//  338       status = FLASH_WaitForLastOperation(ProgramTimeout);
//  339         
//  340       if(status != FLASH_BUSY)
//  341       {
//  342         /* Disable the PG Bit */
//  343         FLASH->CR &= CR_PG_Reset;
//  344       }
//  345     }
//  346     else
//  347     {
//  348       if (status != FLASH_BUSY)
//  349       {
//  350         /* Disable the PG Bit */
//  351         FLASH->CR &= CR_PG_Reset;
//  352       }
//  353      }
//  354   }
//  355   /* Return the Program Status */
//  356   return status;
//  357 }
//  358 
//  359 /*******************************************************************************
//  360 * Function Name  : FLASH_ProgramHalfWord
//  361 * Description    : Programs a half word at a specified address.
//  362 * Input          : - Address: specifies the address to be programmed.
//  363 *                  - Data: specifies the data to be programmed.
//  364 * Output         : None
//  365 * Return         : FLASH Status: The returned value can be: FLASH_BUSY, 
//  366 *                  FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or 
//  367 *                  FLASH_TIMEOUT. 
//  368 *******************************************************************************/
//  369 FLASH_Status FLASH_ProgramHalfWord(u32 Address, u16 Data)
//  370 {
//  371   FLASH_Status status = FLASH_COMPLETE;
//  372 
//  373   /* Check the parameters */
//  374   assert_param(IS_FLASH_ADDRESS(Address));
//  375 
//  376   /* Wait for last operation to be completed */
//  377   status = FLASH_WaitForLastOperation(ProgramTimeout);
//  378   
//  379   if(status == FLASH_COMPLETE)
//  380   {
//  381     /* if the previous operation is completed, proceed to program the new data */
//  382     FLASH->CR |= CR_PG_Set;
//  383   
//  384     *(vu16*)Address = Data;
//  385     /* Wait for last operation to be completed */
//  386     status = FLASH_WaitForLastOperation(ProgramTimeout);
//  387 
//  388     if(status != FLASH_BUSY)
//  389     {
//  390       /* if the program operation is completed, disable the PG Bit */
//  391       FLASH->CR &= CR_PG_Reset;
//  392     }
//  393   } 
//  394   /* Return the Program Status */
//  395   return status;
//  396 }
//  397 
//  398 /*******************************************************************************
//  399 * Function Name  : FLASH_ProgramOptionByteData
//  400 * Description    : Programs a half word at a specified Option Byte Data address.
//  401 * Input          : - Address: specifies the address to be programmed.
//  402 *                    This parameter can be 0x1FFFF804 or 0x1FFFF806. 
//  403 *                  - Data: specifies the data to be programmed.
//  404 * Output         : None
//  405 * Return         : FLASH Status: The returned value can be: FLASH_BUSY, 
//  406 *                  FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or 
//  407 *                  FLASH_TIMEOUT. 
//  408 *******************************************************************************/
//  409 FLASH_Status FLASH_ProgramOptionByteData(u32 Address, u8 Data)
//  410 {
//  411   FLASH_Status status = FLASH_COMPLETE;
//  412 
//  413   /* Check the parameters */
//  414   assert_param(IS_OB_DATA_ADDRESS(Address));
//  415 
//  416   status = FLASH_WaitForLastOperation(ProgramTimeout);
//  417 
//  418   if(status == FLASH_COMPLETE)
//  419   {
//  420     /* Authorize the small information block programming */
//  421     FLASH->OPTKEYR = FLASH_KEY1;
//  422     FLASH->OPTKEYR = FLASH_KEY2;
//  423 
//  424     /* Enables the Option Bytes Programming operation */
//  425     FLASH->CR |= CR_OPTPG_Set; 
//  426     *(vu16*)Address = Data;
//  427     
//  428     /* Wait for last operation to be completed */
//  429     status = FLASH_WaitForLastOperation(ProgramTimeout);
//  430 
//  431     if(status != FLASH_BUSY)
//  432     {
//  433       /* if the program operation is completed, disable the OPTPG Bit */
//  434       FLASH->CR &= CR_OPTPG_Reset;
//  435     }
//  436   }    
//  437   /* Return the Option Byte Data Program Status */
//  438   return status;      
//  439 }
//  440 
//  441 /*******************************************************************************
//  442 * Function Name  : FLASH_EnableWriteProtection
//  443 * Description    : Write protects the desired pages
//  444 * Input          : - FLASH_Pages: specifies the address of the pages to be 
//  445 *                    write protected. This parameter can be:
//  446 *                    - For STM32F10Xxx Medium-density devices (FLASH page size equal to 1 KB)
//  447 *                       - A value between FLASH_WRProt_Pages0to3 and 
//  448 *                         FLASH_WRProt_Pages124to127
//  449 *                    - For STM32F10Xxx High-density devices (FLASH page size equal to 2 KB) 
//  450 *                       - A value between FLASH_WRProt_Pages0to1 and
//  451 *                         FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to255 
//  452 *                       - FLASH_WRProt_AllPages
//  453 * Output         : None
//  454 * Return         : FLASH Status: The returned value can be: FLASH_BUSY, 
//  455 *                  FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or 
//  456 *                  FLASH_TIMEOUT.
//  457 *******************************************************************************/
//  458 FLASH_Status FLASH_EnableWriteProtection(u32 FLASH_Pages)
//  459 {
//  460   u16 WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
//  461   
//  462   FLASH_Status status = FLASH_COMPLETE;
//  463   
//  464   /* Check the parameters */
//  465   assert_param(IS_FLASH_WRPROT_PAGE(FLASH_Pages));
//  466   
//  467   FLASH_Pages = (u32)(~FLASH_Pages);
//  468   WRP0_Data = (vu16)(FLASH_Pages & WRP0_Mask);
//  469   WRP1_Data = (vu16)((FLASH_Pages & WRP1_Mask) >> 8);
//  470   WRP2_Data = (vu16)((FLASH_Pages & WRP2_Mask) >> 16);
//  471   WRP3_Data = (vu16)((FLASH_Pages & WRP3_Mask) >> 24);
//  472   
//  473   /* Wait for last operation to be completed */
//  474   status = FLASH_WaitForLastOperation(ProgramTimeout);
//  475   
//  476   if(status == FLASH_COMPLETE)
//  477   {
//  478     /* Authorizes the small information block programming */
//  479     FLASH->OPTKEYR = FLASH_KEY1;
//  480     FLASH->OPTKEYR = FLASH_KEY2;
//  481     FLASH->CR |= CR_OPTPG_Set;
//  482 
//  483     if(WRP0_Data != 0xFF)
//  484     {
//  485       OB->WRP0 = WRP0_Data;
//  486       
//  487       /* Wait for last operation to be completed */
//  488       status = FLASH_WaitForLastOperation(ProgramTimeout);
//  489     }
//  490     if((status == FLASH_COMPLETE) && (WRP1_Data != 0xFF))
//  491     {
//  492       OB->WRP1 = WRP1_Data;
//  493       
//  494       /* Wait for last operation to be completed */
//  495       status = FLASH_WaitForLastOperation(ProgramTimeout);
//  496     }
//  497 
//  498     if((status == FLASH_COMPLETE) && (WRP2_Data != 0xFF))
//  499     {
//  500       OB->WRP2 = WRP2_Data;
//  501       
//  502       /* Wait for last operation to be completed */
//  503       status = FLASH_WaitForLastOperation(ProgramTimeout);
//  504     }
//  505     
//  506     if((status == FLASH_COMPLETE)&& (WRP3_Data != 0xFF))
//  507     {
//  508       OB->WRP3 = WRP3_Data;
//  509      
//  510       /* Wait for last operation to be completed */
//  511       status = FLASH_WaitForLastOperation(ProgramTimeout);
//  512     }
//  513           
//  514     if(status != FLASH_BUSY)
//  515     {
//  516       /* if the program operation is completed, disable the OPTPG Bit */
//  517       FLASH->CR &= CR_OPTPG_Reset;
//  518     }
//  519   } 
//  520   /* Return the write protection operation Status */
//  521   return status;       
//  522 }
//  523 
//  524 /*******************************************************************************
//  525 * Function Name  : FLASH_ReadOutProtection
//  526 * Description    : Enables or disables the read out protection.
//  527 *                  If the user has already programmed the other option bytes before 
//  528 *                  calling this function, he must re-program them since this 
//  529 *                  function erases all option bytes.
//  530 * Input          : - Newstate: new state of the ReadOut Protection.
//  531 *                    This parameter can be: ENABLE or DISABLE.
//  532 * Output         : None
//  533 * Return         : FLASH Status: The returned value can be: FLASH_BUSY, 
//  534 *                  FLASH_ERROR_PG, FLASH_ERROR_WRP, FLASH_COMPLETE or 
//  535 *                  FLASH_TIMEOUT.
//  536 *******************************************************************************/
//  537 FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
//  538 {
//  539   FLASH_Status status = FLASH_COMPLETE;
//  540 
//  541   /* Check the parameters */
//  542   assert_param(IS_FUNCTIONAL_STATE(NewState));
//  543 
//  544   status = FLASH_WaitForLastOperation(EraseTimeout);
//  545 
//  546   if(status == FLASH_COMPLETE)
//  547   {
//  548     /* Authorizes the small information block programming */
//  549     FLASH->OPTKEYR = FLASH_KEY1;
//  550     FLASH->OPTKEYR = FLASH_KEY2;
//  551 
//  552     FLASH->CR |= CR_OPTER_Set;
//  553     FLASH->CR |= CR_STRT_Set;
//  554 
//  555     /* Wait for last operation to be completed */
//  556     status = FLASH_WaitForLastOperation(EraseTimeout);
//  557 
//  558     if(status == FLASH_COMPLETE)
//  559     {
//  560       /* if the erase operation is completed, disable the OPTER Bit */
//  561       FLASH->CR &= CR_OPTER_Reset;
//  562 
//  563       /* Enable the Option Bytes Programming operation */
//  564       FLASH->CR |= CR_OPTPG_Set; 
//  565 
//  566       if(NewState != DISABLE)
//  567       {
//  568         OB->RDP = 0x00;

⌨️ 快捷键说明

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