CARME-M4 BSP  V1.5
stm32f4xx_flash.c
Go to the documentation of this file.
1 
71 /* Includes ------------------------------------------------------------------*/
72 #include "stm32f4xx_flash.h"
73 
83 /* Private typedef -----------------------------------------------------------*/
84 /* Private define ------------------------------------------------------------*/
85 #define SECTOR_MASK ((uint32_t)0xFFFFFF07)
86 
87 /* Private macro -------------------------------------------------------------*/
88 /* Private variables ---------------------------------------------------------*/
89 /* Private function prototypes -----------------------------------------------*/
90 /* Private functions ---------------------------------------------------------*/
91 
248 void FLASH_SetLatency(uint32_t FLASH_Latency)
249 {
250  /* Check the parameters */
251  assert_param(IS_FLASH_LATENCY(FLASH_Latency));
252 
253  /* Perform Byte access to FLASH_ACR[8:0] to set the Latency value */
254  *(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)FLASH_Latency;
255 }
256 
263 void FLASH_PrefetchBufferCmd(FunctionalState NewState)
264 {
265  /* Check the parameters */
266  assert_param(IS_FUNCTIONAL_STATE(NewState));
267 
268  /* Enable or disable the Prefetch Buffer */
269  if(NewState != DISABLE)
270  {
271  FLASH->ACR |= FLASH_ACR_PRFTEN;
272  }
273  else
274  {
275  FLASH->ACR &= (~FLASH_ACR_PRFTEN);
276  }
277 }
278 
285 void FLASH_InstructionCacheCmd(FunctionalState NewState)
286 {
287  /* Check the parameters */
288  assert_param(IS_FUNCTIONAL_STATE(NewState));
289 
290  if(NewState != DISABLE)
291  {
292  FLASH->ACR |= FLASH_ACR_ICEN;
293  }
294  else
295  {
296  FLASH->ACR &= (~FLASH_ACR_ICEN);
297  }
298 }
299 
306 void FLASH_DataCacheCmd(FunctionalState NewState)
307 {
308  /* Check the parameters */
309  assert_param(IS_FUNCTIONAL_STATE(NewState));
310 
311  if(NewState != DISABLE)
312  {
313  FLASH->ACR |= FLASH_ACR_DCEN;
314  }
315  else
316  {
317  FLASH->ACR &= (~FLASH_ACR_DCEN);
318  }
319 }
320 
328 {
329  FLASH->ACR |= FLASH_ACR_ICRST;
330 }
331 
339 {
340  FLASH->ACR |= FLASH_ACR_DCRST;
341 }
342 
385 void FLASH_Unlock(void)
386 {
387  if((FLASH->CR & FLASH_CR_LOCK) != RESET)
388  {
389  /* Authorize the FLASH Registers access */
390  FLASH->KEYR = FLASH_KEY1;
391  FLASH->KEYR = FLASH_KEY2;
392  }
393 }
394 
400 void FLASH_Lock(void)
401 {
402  /* Set the LOCK Bit to lock the FLASH Registers access */
403  FLASH->CR |= FLASH_CR_LOCK;
404 }
405 
437 FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange)
438 {
439  uint32_t tmp_psize = 0x0;
440  FLASH_Status status = FLASH_COMPLETE;
441 
442  /* Check the parameters */
443  assert_param(IS_FLASH_SECTOR(FLASH_Sector));
444  assert_param(IS_VOLTAGERANGE(VoltageRange));
445 
446  if(VoltageRange == VoltageRange_1)
447  {
448  tmp_psize = FLASH_PSIZE_BYTE;
449  }
450  else if(VoltageRange == VoltageRange_2)
451  {
452  tmp_psize = FLASH_PSIZE_HALF_WORD;
453  }
454  else if(VoltageRange == VoltageRange_3)
455  {
456  tmp_psize = FLASH_PSIZE_WORD;
457  }
458  else
459  {
460  tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
461  }
462  /* Wait for last operation to be completed */
463  status = FLASH_WaitForLastOperation();
464 
465  if(status == FLASH_COMPLETE)
466  {
467  /* if the previous operation is completed, proceed to erase the sector */
468  FLASH->CR &= CR_PSIZE_MASK;
469  FLASH->CR |= tmp_psize;
470  FLASH->CR &= SECTOR_MASK;
471  FLASH->CR |= FLASH_CR_SER | FLASH_Sector;
472  FLASH->CR |= FLASH_CR_STRT;
473 
474  /* Wait for last operation to be completed */
475  status = FLASH_WaitForLastOperation();
476 
477  /* if the erase operation is completed, disable the SER Bit */
478  FLASH->CR &= (~FLASH_CR_SER);
479  FLASH->CR &= SECTOR_MASK;
480  }
481  /* Return the Erase Status */
482  return status;
483 }
484 
505 FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange)
506 {
507  uint32_t tmp_psize = 0x0;
508  FLASH_Status status = FLASH_COMPLETE;
509 
510  /* Wait for last operation to be completed */
511  status = FLASH_WaitForLastOperation();
512  assert_param(IS_VOLTAGERANGE(VoltageRange));
513 
514  if(VoltageRange == VoltageRange_1)
515  {
516  tmp_psize = FLASH_PSIZE_BYTE;
517  }
518  else if(VoltageRange == VoltageRange_2)
519  {
520  tmp_psize = FLASH_PSIZE_HALF_WORD;
521  }
522  else if(VoltageRange == VoltageRange_3)
523  {
524  tmp_psize = FLASH_PSIZE_WORD;
525  }
526  else
527  {
528  tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
529  }
530  if(status == FLASH_COMPLETE)
531  {
532  /* if the previous operation is completed, proceed to erase all sectors */
533 #if defined (STM32F427_437xx) || defined (STM32F429_439xx)
534  FLASH->CR &= CR_PSIZE_MASK;
535  FLASH->CR |= tmp_psize;
536  FLASH->CR |= (FLASH_CR_MER1 | FLASH_CR_MER2);
537  FLASH->CR |= FLASH_CR_STRT;
538 
539  /* Wait for last operation to be completed */
540  status = FLASH_WaitForLastOperation();
541 
542  /* if the erase operation is completed, disable the MER Bit */
543  FLASH->CR &= ~(FLASH_CR_MER1 | FLASH_CR_MER2);
544 #endif /* STM32F427_437xx || STM32F429_439xx */
545 
546 #if defined (STM32F40_41xxx) || defined (STM32F401xx)
547  FLASH->CR &= CR_PSIZE_MASK;
548  FLASH->CR |= tmp_psize;
549  FLASH->CR |= FLASH_CR_MER;
550  FLASH->CR |= FLASH_CR_STRT;
551 
552  /* Wait for last operation to be completed */
553  status = FLASH_WaitForLastOperation();
554 
555  /* if the erase operation is completed, disable the MER Bit */
556  FLASH->CR &= (~FLASH_CR_MER);
557 #endif /* STM32F40_41xxx || STM32F401xx */
558 
559  }
560  /* Return the Erase Status */
561  return status;
562 }
563 
587 {
588  uint32_t tmp_psize = 0x0;
589  FLASH_Status status = FLASH_COMPLETE;
590 
591  /* Wait for last operation to be completed */
592  status = FLASH_WaitForLastOperation();
593  assert_param(IS_VOLTAGERANGE(VoltageRange));
594 
595  if(VoltageRange == VoltageRange_1)
596  {
597  tmp_psize = FLASH_PSIZE_BYTE;
598  }
599  else if(VoltageRange == VoltageRange_2)
600  {
601  tmp_psize = FLASH_PSIZE_HALF_WORD;
602  }
603  else if(VoltageRange == VoltageRange_3)
604  {
605  tmp_psize = FLASH_PSIZE_WORD;
606  }
607  else
608  {
609  tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
610  }
611  if(status == FLASH_COMPLETE)
612  {
613  /* if the previous operation is completed, proceed to erase all sectors */
614  FLASH->CR &= CR_PSIZE_MASK;
615  FLASH->CR |= tmp_psize;
616  FLASH->CR |= FLASH_CR_MER1;
617  FLASH->CR |= FLASH_CR_STRT;
618 
619  /* Wait for last operation to be completed */
620  status = FLASH_WaitForLastOperation();
621 
622  /* if the erase operation is completed, disable the MER Bit */
623  FLASH->CR &= (~FLASH_CR_MER1);
624 
625  }
626  /* Return the Erase Status */
627  return status;
628 }
629 
630 
654 {
655  uint32_t tmp_psize = 0x0;
656  FLASH_Status status = FLASH_COMPLETE;
657 
658  /* Wait for last operation to be completed */
659  status = FLASH_WaitForLastOperation();
660  assert_param(IS_VOLTAGERANGE(VoltageRange));
661 
662  if(VoltageRange == VoltageRange_1)
663  {
664  tmp_psize = FLASH_PSIZE_BYTE;
665  }
666  else if(VoltageRange == VoltageRange_2)
667  {
668  tmp_psize = FLASH_PSIZE_HALF_WORD;
669  }
670  else if(VoltageRange == VoltageRange_3)
671  {
672  tmp_psize = FLASH_PSIZE_WORD;
673  }
674  else
675  {
676  tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
677  }
678  if(status == FLASH_COMPLETE)
679  {
680  /* if the previous operation is completed, proceed to erase all sectors */
681  FLASH->CR &= CR_PSIZE_MASK;
682  FLASH->CR |= tmp_psize;
683  FLASH->CR |= FLASH_CR_MER2;
684  FLASH->CR |= FLASH_CR_STRT;
685 
686  /* Wait for last operation to be completed */
687  status = FLASH_WaitForLastOperation();
688 
689  /* if the erase operation is completed, disable the MER Bit */
690  FLASH->CR &= (~FLASH_CR_MER2);
691 
692  }
693  /* Return the Erase Status */
694  return status;
695 }
696 
710 FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data)
711 {
712  FLASH_Status status = FLASH_COMPLETE;
713 
714  /* Check the parameters */
715  assert_param(IS_FLASH_ADDRESS(Address));
716 
717  /* Wait for last operation to be completed */
718  status = FLASH_WaitForLastOperation();
719 
720  if(status == FLASH_COMPLETE)
721  {
722  /* if the previous operation is completed, proceed to program the new data */
723  FLASH->CR &= CR_PSIZE_MASK;
724  FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD;
725  FLASH->CR |= FLASH_CR_PG;
726 
727  *(__IO uint64_t*)Address = Data;
728 
729  /* Wait for last operation to be completed */
730  status = FLASH_WaitForLastOperation();
731 
732  /* if the program operation is completed, disable the PG Bit */
733  FLASH->CR &= (~FLASH_CR_PG);
734  }
735  /* Return the Program Status */
736  return status;
737 }
738 
753 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
754 {
755  FLASH_Status status = FLASH_COMPLETE;
756 
757  /* Check the parameters */
758  assert_param(IS_FLASH_ADDRESS(Address));
759 
760  /* Wait for last operation to be completed */
761  status = FLASH_WaitForLastOperation();
762 
763  if(status == FLASH_COMPLETE)
764  {
765  /* if the previous operation is completed, proceed to program the new data */
766  FLASH->CR &= CR_PSIZE_MASK;
767  FLASH->CR |= FLASH_PSIZE_WORD;
768  FLASH->CR |= FLASH_CR_PG;
769 
770  *(__IO uint32_t*)Address = Data;
771 
772  /* Wait for last operation to be completed */
773  status = FLASH_WaitForLastOperation();
774 
775  /* if the program operation is completed, disable the PG Bit */
776  FLASH->CR &= (~FLASH_CR_PG);
777  }
778  /* Return the Program Status */
779  return status;
780 }
781 
795 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
796 {
797  FLASH_Status status = FLASH_COMPLETE;
798 
799  /* Check the parameters */
800  assert_param(IS_FLASH_ADDRESS(Address));
801 
802  /* Wait for last operation to be completed */
803  status = FLASH_WaitForLastOperation();
804 
805  if(status == FLASH_COMPLETE)
806  {
807  /* if the previous operation is completed, proceed to program the new data */
808  FLASH->CR &= CR_PSIZE_MASK;
809  FLASH->CR |= FLASH_PSIZE_HALF_WORD;
810  FLASH->CR |= FLASH_CR_PG;
811 
812  *(__IO uint16_t*)Address = Data;
813 
814  /* Wait for last operation to be completed */
815  status = FLASH_WaitForLastOperation();
816 
817  /* if the program operation is completed, disable the PG Bit */
818  FLASH->CR &= (~FLASH_CR_PG);
819  }
820  /* Return the Program Status */
821  return status;
822 }
823 
837 FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data)
838 {
839  FLASH_Status status = FLASH_COMPLETE;
840 
841  /* Check the parameters */
842  assert_param(IS_FLASH_ADDRESS(Address));
843 
844  /* Wait for last operation to be completed */
845  status = FLASH_WaitForLastOperation();
846 
847  if(status == FLASH_COMPLETE)
848  {
849  /* if the previous operation is completed, proceed to program the new data */
850  FLASH->CR &= CR_PSIZE_MASK;
851  FLASH->CR |= FLASH_PSIZE_BYTE;
852  FLASH->CR |= FLASH_CR_PG;
853 
854  *(__IO uint8_t*)Address = Data;
855 
856  /* Wait for last operation to be completed */
857  status = FLASH_WaitForLastOperation();
858 
859  /* if the program operation is completed, disable the PG Bit */
860  FLASH->CR &= (~FLASH_CR_PG);
861  }
862 
863  /* Return the Program Status */
864  return status;
865 }
866 
936 void FLASH_OB_Unlock(void)
937 {
938  if((FLASH->OPTCR & FLASH_OPTCR_OPTLOCK) != RESET)
939  {
940  /* Authorizes the Option Byte register programming */
941  FLASH->OPTKEYR = FLASH_OPT_KEY1;
942  FLASH->OPTKEYR = FLASH_OPT_KEY2;
943  }
944 }
945 
951 void FLASH_OB_Lock(void)
952 {
953  /* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */
954  FLASH->OPTCR |= FLASH_OPTCR_OPTLOCK;
955 }
956 
974 void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
975 {
976  FLASH_Status status = FLASH_COMPLETE;
977 
978  /* Check the parameters */
979  assert_param(IS_OB_WRP(OB_WRP));
980  assert_param(IS_FUNCTIONAL_STATE(NewState));
981 
982  status = FLASH_WaitForLastOperation();
983 
984  if(status == FLASH_COMPLETE)
985  {
986  if(NewState != DISABLE)
987  {
988  *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~OB_WRP);
989  }
990  else
991  {
992  *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)OB_WRP;
993  }
994  }
995 }
996 
1016 void FLASH_OB_WRP1Config(uint32_t OB_WRP, FunctionalState NewState)
1017 {
1018  FLASH_Status status = FLASH_COMPLETE;
1019 
1020  /* Check the parameters */
1021  assert_param(IS_OB_WRP(OB_WRP));
1022  assert_param(IS_FUNCTIONAL_STATE(NewState));
1023 
1024  status = FLASH_WaitForLastOperation();
1025 
1026  if(status == FLASH_COMPLETE)
1027  {
1028  if(NewState != DISABLE)
1029  {
1030  *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~OB_WRP);
1031  }
1032  else
1033  {
1034  *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)OB_WRP;
1035  }
1036  }
1037 }
1038 
1066 void FLASH_OB_PCROPSelectionConfig(uint8_t OB_PcROP)
1067 {
1068  uint8_t optiontmp = 0xFF;
1069 
1070  /* Check the parameters */
1071  assert_param(IS_OB_PCROP_SELECT(OB_PcROP));
1072 
1073  /* Mask SPRMOD bit */
1074  optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F);
1075  /* Update Option Byte */
1076  *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PcROP | optiontmp);
1077 
1078 }
1079 
1096 void FLASH_OB_PCROPConfig(uint32_t OB_PCROP, FunctionalState NewState)
1097 {
1098  FLASH_Status status = FLASH_COMPLETE;
1099 
1100  /* Check the parameters */
1101  assert_param(IS_OB_PCROP(OB_PCROP));
1102  assert_param(IS_FUNCTIONAL_STATE(NewState));
1103 
1104  status = FLASH_WaitForLastOperation();
1105 
1106  if(status == FLASH_COMPLETE)
1107  {
1108  if(NewState != DISABLE)
1109  {
1110  *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)OB_PCROP;
1111  }
1112  else
1113  {
1114  *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~OB_PCROP);
1115  }
1116  }
1117 }
1118 
1133 void FLASH_OB_PCROP1Config(uint32_t OB_PCROP, FunctionalState NewState)
1134 {
1135  FLASH_Status status = FLASH_COMPLETE;
1136 
1137  /* Check the parameters */
1138  assert_param(IS_OB_PCROP(OB_PCROP));
1139  assert_param(IS_FUNCTIONAL_STATE(NewState));
1140 
1141  status = FLASH_WaitForLastOperation();
1142 
1143  if(status == FLASH_COMPLETE)
1144  {
1145  if(NewState != DISABLE)
1146  {
1147  *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)OB_PCROP;
1148  }
1149  else
1150  {
1151  *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~OB_PCROP);
1152  }
1153  }
1154 }
1155 
1156 
1169 void FLASH_OB_RDPConfig(uint8_t OB_RDP)
1170 {
1171  FLASH_Status status = FLASH_COMPLETE;
1172 
1173  /* Check the parameters */
1174  assert_param(IS_OB_RDP(OB_RDP));
1175 
1176  status = FLASH_WaitForLastOperation();
1177 
1178  if(status == FLASH_COMPLETE)
1179  {
1180  *(__IO uint8_t*)OPTCR_BYTE1_ADDRESS = OB_RDP;
1181 
1182  }
1183 }
1184 
1201 void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
1202 {
1203  uint8_t optiontmp = 0xFF;
1204  FLASH_Status status = FLASH_COMPLETE;
1205 
1206  /* Check the parameters */
1207  assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));
1208  assert_param(IS_OB_STOP_SOURCE(OB_STOP));
1209  assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));
1210 
1211  /* Wait for last operation to be completed */
1212  status = FLASH_WaitForLastOperation();
1213 
1214  if(status == FLASH_COMPLETE)
1215  {
1216 #if defined (STM32F427_437xx) || defined (STM32F429_439xx)
1217  /* Mask OPTLOCK, OPTSTRT, BOR_LEV and BFB2 bits */
1218  optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE0_ADDRESS) & (uint8_t)0x1F);
1219 #endif /* STM32F427_437xx || STM32F429_439xx */
1220 
1221 #if defined (STM32F40_41xxx) || defined (STM32F401xx)
1222  /* Mask OPTLOCK, OPTSTRT and BOR_LEV bits */
1223  optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE0_ADDRESS) & (uint8_t)0x0F);
1224 #endif /* STM32F40_41xxx || STM32F401xx */
1225 
1226  /* Update User Option Byte */
1227  *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS = OB_IWDG | (uint8_t)(OB_STDBY | (uint8_t)(OB_STOP | ((uint8_t)optiontmp)));
1228  }
1229 }
1230 
1242 void FLASH_OB_BootConfig(uint8_t OB_BOOT)
1243 {
1244  /* Check the parameters */
1245  assert_param(IS_OB_BOOT(OB_BOOT));
1246 
1247  /* Set Dual Bank Boot */
1248  *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BFB2);
1249  *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= OB_BOOT;
1250 
1251 }
1252 
1263 void FLASH_OB_BORConfig(uint8_t OB_BOR)
1264 {
1265  /* Check the parameters */
1266  assert_param(IS_OB_BOR(OB_BOR));
1267 
1268  /* Set the BOR Level */
1269  *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BOR_LEV);
1270  *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= OB_BOR;
1271 
1272 }
1273 
1281 {
1282  FLASH_Status status = FLASH_COMPLETE;
1283 
1284  /* Set the OPTSTRT bit in OPTCR register */
1285  *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= FLASH_OPTCR_OPTSTRT;
1286 
1287  /* Wait for last operation to be completed */
1288  status = FLASH_WaitForLastOperation();
1289 
1290  return status;
1291 }
1292 
1299 uint8_t FLASH_OB_GetUser(void)
1300 {
1301  /* Return the User Option Byte */
1302  return (uint8_t)(FLASH->OPTCR >> 5);
1303 }
1304 
1310 uint16_t FLASH_OB_GetWRP(void)
1311 {
1312  /* Return the FLASH write protection Register value */
1313  return (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
1314 }
1315 
1324 uint16_t FLASH_OB_GetWRP1(void)
1325 {
1326  /* Return the FLASH write protection Register value */
1327  return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
1328 }
1329 
1338 uint16_t FLASH_OB_GetPCROP(void)
1339 {
1340  /* Return the FLASH PC Read/write protection Register value */
1341  return (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
1342 }
1343 
1352 uint16_t FLASH_OB_GetPCROP1(void)
1353 {
1354  /* Return the FLASH write protection Register value */
1355  return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
1356 }
1357 
1365 FlagStatus FLASH_OB_GetRDP(void)
1366 {
1367  FlagStatus readstatus = RESET;
1368 
1369  if ((*(__IO uint8_t*)(OPTCR_BYTE1_ADDRESS) != (uint8_t)OB_RDP_Level_0))
1370  {
1371  readstatus = SET;
1372  }
1373  else
1374  {
1375  readstatus = RESET;
1376  }
1377  return readstatus;
1378 }
1379 
1389 uint8_t FLASH_OB_GetBOR(void)
1390 {
1391  /* Return the FLASH BOR level */
1392  return (uint8_t)(*(__IO uint8_t *)(OPTCR_BYTE0_ADDRESS) & (uint8_t)0x0C);
1393 }
1394 
1418 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
1419 {
1420  /* Check the parameters */
1421  assert_param(IS_FLASH_IT(FLASH_IT));
1422  assert_param(IS_FUNCTIONAL_STATE(NewState));
1423 
1424  if(NewState != DISABLE)
1425  {
1426  /* Enable the interrupt sources */
1427  FLASH->CR |= FLASH_IT;
1428  }
1429  else
1430  {
1431  /* Disable the interrupt sources */
1432  FLASH->CR &= ~(uint32_t)FLASH_IT;
1433  }
1434 }
1435 
1450 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
1451 {
1452  FlagStatus bitstatus = RESET;
1453  /* Check the parameters */
1454  assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG));
1455 
1456  if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
1457  {
1458  bitstatus = SET;
1459  }
1460  else
1461  {
1462  bitstatus = RESET;
1463  }
1464  /* Return the new state of FLASH_FLAG (SET or RESET) */
1465  return bitstatus;
1466 }
1467 
1481 void FLASH_ClearFlag(uint32_t FLASH_FLAG)
1482 {
1483  /* Check the parameters */
1484  assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG));
1485 
1486  /* Clear the flags */
1487  FLASH->SR = FLASH_FLAG;
1488 }
1489 
1497 {
1498  FLASH_Status flashstatus = FLASH_COMPLETE;
1499 
1500  if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
1501  {
1502  flashstatus = FLASH_BUSY;
1503  }
1504  else
1505  {
1506  if((FLASH->SR & FLASH_FLAG_WRPERR) != (uint32_t)0x00)
1507  {
1508  flashstatus = FLASH_ERROR_WRP;
1509  }
1510  else
1511  {
1512  if((FLASH->SR & FLASH_FLAG_RDERR) != (uint32_t)0x00)
1513  {
1514  flashstatus = FLASH_ERROR_RD;
1515  }
1516  else
1517  {
1518  if((FLASH->SR & (uint32_t)0xEF) != (uint32_t)0x00)
1519  {
1520  flashstatus = FLASH_ERROR_PROGRAM;
1521  }
1522  else
1523  {
1524  if((FLASH->SR & FLASH_FLAG_OPERR) != (uint32_t)0x00)
1525  {
1526  flashstatus = FLASH_ERROR_OPERATION;
1527  }
1528  else
1529  {
1530  flashstatus = FLASH_COMPLETE;
1531  }
1532  }
1533  }
1534  }
1535  }
1536  /* Return the FLASH Status */
1537  return flashstatus;
1538 }
1539 
1547 {
1548  __IO FLASH_Status status = FLASH_COMPLETE;
1549 
1550  /* Check for the FLASH Status */
1551  status = FLASH_GetStatus();
1552 
1553  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
1554  Even if the FLASH operation fails, the BUSY flag will be reset and an error
1555  flag will be set */
1556  while(status == FLASH_BUSY)
1557  {
1558  status = FLASH_GetStatus();
1559  }
1560  /* Return the operation status */
1561  return status;
1562 }
1563 
1580 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void FLASH_DataCacheCmd(FunctionalState NewState)
Enables or disables the Data Cache feature.
void FLASH_InstructionCacheCmd(FunctionalState NewState)
Enables or disables the Instruction Cache feature.
void FLASH_OB_Lock(void)
Locks the FLASH Option Control Registers access.
void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
Enables or disables the specified FLASH interrupts.
#define OPTCR_BYTE2_ADDRESS
OPTCR register byte 2 (Bits[23:16]) base address.
void FLASH_OB_BORConfig(uint8_t OB_BOR)
Sets the BOR Level.
FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data)
Programs a byte (8-bit) at a specified address.
#define FLASH_FLAG_RDERR
void FLASH_ClearFlag(uint32_t FLASH_FLAG)
Clears the FLASH's pending flags.
FLASH_Status FLASH_WaitForLastOperation(void)
Waits for a FLASH operation to complete.
FLASH_Status FLASH_OB_Launch(void)
Launch the option byte loading.
#define OPTCR_BYTE0_ADDRESS
OPTCR register byte 0 (Bits[7:0]) base address.
#define VoltageRange_2
#define VoltageRange_1
void FLASH_DataCacheReset(void)
Resets the Data Cache.
void FLASH_InstructionCacheReset(void)
Resets the Instruction Cache.
This file contains all the functions prototypes for the FLASH firmware library.
#define FLASH_FLAG_BSY
FLASH_Status FLASH_EraseAllBank2Sectors(uint8_t VoltageRange)
Erases all FLASH Sectors in Bank 2.
void FLASH_SetLatency(uint32_t FLASH_Latency)
Sets the code latency value.
void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data)
Programs a double word (64-bit) at a specified address.
FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange)
Erases a specified FLASH Sector.
void FLASH_OB_RDPConfig(uint8_t OB_RDP)
Sets the read protection level.
void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
Enables or disables the write protection of the desired sectors, for the first 1 Mb of the Flash...
uint16_t FLASH_OB_GetPCROP1(void)
Returns the FLASH PC Read/Write Protection Option Bytes value.
FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
Programs a half word (16-bit) at a specified address.
FLASH_Status FLASH_EraseAllBank1Sectors(uint8_t VoltageRange)
Erases all FLASH Sectors in Bank 1.
FlagStatus FLASH_OB_GetRDP(void)
Returns the FLASH Read Protection level.
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Programs a word (32-bit) at a specified address.
void FLASH_Lock(void)
Locks the FLASH control register access.
void FLASH_OB_PCROPConfig(uint32_t OB_PCROP, FunctionalState NewState)
Enables or disables the read/write protection (PCROP) of the desired sectors, for the first 1 MB of t...
uint16_t FLASH_OB_GetPCROP(void)
Returns the FLASH PC Read/Write Protection Option Bytes value.
#define FLASH_FLAG_WRPERR
#define FLASH_FLAG_OPERR
FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange)
Erases all FLASH Sectors.
void FLASH_OB_BootConfig(uint8_t OB_BOOT)
Configure the Dual Bank Boot.
void FLASH_Unlock(void)
Unlocks the FLASH control register access.
uint8_t FLASH_OB_GetBOR(void)
Returns the FLASH BOR level.
uint8_t FLASH_OB_GetUser(void)
Returns the FLASH User Option Bytes values.
void FLASH_OB_PCROPSelectionConfig(uint8_t OB_PcROP)
Select the Protection Mode (SPRMOD).
#define OPTCR1_BYTE2_ADDRESS
OPTCR1 register byte 0 (Bits[7:0]) base address.
#define OPTCR_BYTE3_ADDRESS
OPTCR register byte 3 (Bits[31:24]) base address.
void FLASH_OB_Unlock(void)
Unlocks the FLASH Option Control Registers access.
#define VoltageRange_3
FLASH_Status FLASH_GetStatus(void)
Returns the FLASH Status.
void FLASH_OB_WRP1Config(uint32_t OB_WRP, FunctionalState NewState)
Enables or disables the write protection of the desired sectors, for the second 1 Mb of the Flash...
uint16_t FLASH_OB_GetWRP1(void)
Returns the FLASH Write Protection Option Bytes value.
void FLASH_PrefetchBufferCmd(FunctionalState NewState)
Enables or disables the Prefetch Buffer.
FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
Checks whether the specified FLASH flag is set or not.
void FLASH_OB_PCROP1Config(uint32_t OB_PCROP, FunctionalState NewState)
Enables or disables the read/write protection (PCROP) of the desired sectors.
FLASH_Status
FLASH Status.
#define ACR_BYTE0_ADDRESS
ACR register byte 0 (Bits[7:0]) base address.
uint16_t FLASH_OB_GetWRP(void)
Returns the FLASH Write Protection Option Bytes value.
#define IS_OB_RDP(LEVEL)
#define OPTCR_BYTE1_ADDRESS
OPTCR register byte 1 (Bits[15:8]) base address.