Subversion Repositories DashDisplay

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 5
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_flash.c
3
  * @file    stm32f1xx_hal_flash.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.0.1
5
  * @version V1.0.4
6
  * @date    31-July-2015
6
  * @date    29-April-2016
7
  * @brief   FLASH HAL module driver.
7
  * @brief   FLASH HAL module driver.
8
  *          This file provides firmware functions to manage the following
8
  *          This file provides firmware functions to manage the following
9
  *          functionalities of the internal FLASH memory:
9
  *          functionalities of the internal FLASH memory:
10
  *           + Program operations functions
10
  *           + Program operations functions
11
  *           + Memory Control functions
11
  *           + Memory Control functions
Line 61... Line 61...
61
        (++) Get error flag status          
61
        (++) Get error flag status          
62
 
62
 
63
  [..] In addition to these function, this driver includes a set of macros allowing
63
  [..] In addition to these function, this driver includes a set of macros allowing
64
       to handle the following operations:
64
       to handle the following operations:
65
     
65
     
66
      (+) Set the latency
66
      (+) Set/Get the latency
67
      (+) Enable/Disable the prefetch buffer
67
      (+) Enable/Disable the prefetch buffer
68
      (+) Enable/Disable the half cycle access
68
      (+) Enable/Disable the half cycle access
69
      (+) Enable/Disable the FLASH interrupts
69
      (+) Enable/Disable the FLASH interrupts
70
      (+) Monitor the FLASH flags status
70
      (+) Monitor the FLASH flags status
71
         
71
         
72
  @endverbatim
72
  @endverbatim
73
  ******************************************************************************
73
  ******************************************************************************
74
  * @attention
74
  * @attention
75
  *
75
  *
76
  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
76
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
77
  *
77
  *
78
  * Redistribution and use in source and binary forms, with or without modification,
78
  * Redistribution and use in source and binary forms, with or without modification,
79
  * are permitted provided that the following conditions are met:
79
  * are permitted provided that the following conditions are met:
80
  *   1. Redistributions of source code must retain the above copyright notice,
80
  *   1. Redistributions of source code must retain the above copyright notice,
81
  *      this list of conditions and the following disclaimer.
81
  *      this list of conditions and the following disclaimer.
Line 173... Line 173...
173
  * @note   If an erase and a program operations are requested simultaneously,    
173
  * @note   If an erase and a program operations are requested simultaneously,    
174
  *         the erase operation is performed before the program one.
174
  *         the erase operation is performed before the program one.
175
  *  
175
  *  
176
  * @note   FLASH should be previously erased before new programmation (only exception to this
176
  * @note   FLASH should be previously erased before new programmation (only exception to this
177
  *         is when 0x0000 is programmed)
177
  *         is when 0x0000 is programmed)
178
  *  
178
  *
179
  * @param  TypeProgram:  Indicate the way to program at a specified address.
179
  * @param  TypeProgram:  Indicate the way to program at a specified address.
180
  *                       This parameter can be a value of @ref FLASH_Type_Program
180
  *                       This parameter can be a value of @ref FLASH_Type_Program
181
  * @param  Address:      Specifies the address to be programmed.
181
  * @param  Address:      Specifies the address to be programmed.
182
  * @param  Data:         Specifies the data to be programmed
182
  * @param  Data:         Specifies the data to be programmed
183
  *
183
  *
Line 272... Line 272...
272
  * @note   The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
272
  * @note   The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
273
  *         The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
273
  *         The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
274
  *
274
  *
275
  * @note   If an erase and a program operations are requested simultaneously,    
275
  * @note   If an erase and a program operations are requested simultaneously,    
276
  *         the erase operation is performed before the program one.
276
  *         the erase operation is performed before the program one.
277
  *  
277
  *
278
  * @param  TypeProgram: Indicate the way to program at a specified address.
278
  * @param  TypeProgram: Indicate the way to program at a specified address.
279
  *                      This parameter can be a value of @ref FLASH_Type_Program
279
  *                      This parameter can be a value of @ref FLASH_Type_Program
280
  * @param  Address:     Specifies the address to be programmed.
280
  * @param  Address:     Specifies the address to be programmed.
281
  * @param  Data:        Specifies the data to be programmed
281
  * @param  Data:        Specifies the data to be programmed
282
  *
282
  *
Line 357... Line 357...
357
    (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
357
    (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
358
#else
358
#else
359
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
359
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
360
#endif /* FLASH_BANK2_END */
360
#endif /* FLASH_BANK2_END */
361
  {
361
  {
-
 
362
    /*return the faulty address*/
-
 
363
    addresstmp = pFlash.Address;
-
 
364
    /* Reset address */
-
 
365
    pFlash.Address = 0xFFFFFFFF;
-
 
366
 
362
    /*Save the Error code*/
367
    /*Save the Error code*/
363
    FLASH_SetErrorCode();
368
    FLASH_SetErrorCode();
364
   
369
   
365
    /* FLASH error interrupt user callback */
370
    /* FLASH error interrupt user callback */
366
    HAL_FLASH_OperationErrorCallback(pFlash.Address);
371
    HAL_FLASH_OperationErrorCallback(addresstmp);
367
 
372
 
368
    /* Reset address and stop the procedure ongoing*/
373
    /* Stop the procedure ongoing*/
369
    pFlash.Address = 0xFFFFFFFF;
-
 
370
    pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
374
    pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
371
  }
375
  }
372
 
376
 
373
  /* Check FLASH End of Operation flag  */
377
  /* Check FLASH End of Operation flag  */
374
#if defined(FLASH_BANK2_END)
378
#if defined(FLASH_BANK2_END)
Line 389... Line 393...
389
      if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
393
      if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
390
      {
394
      {
391
        /* Nb of pages to erased can be decreased */
395
        /* Nb of pages to erased can be decreased */
392
        pFlash.DataRemaining--;
396
        pFlash.DataRemaining--;
393
 
397
 
394
        /* Indicate user which page address has been erased*/
-
 
395
        HAL_FLASH_EndOfOperationCallback(pFlash.Address);
-
 
396
 
-
 
397
        /* Check if there are still pages to erase*/
398
        /* Check if there are still pages to erase*/
398
        if(pFlash.DataRemaining != 0)
399
        if(pFlash.DataRemaining != 0)
399
        {
400
        {
400
          /* Increment page address to next page */
-
 
401
          pFlash.Address += FLASH_PAGE_SIZE;
-
 
402
          addresstmp = pFlash.Address;
401
          addresstmp = pFlash.Address;
-
 
402
          /*Indicate user which sector has been erased*/
-
 
403
          HAL_FLASH_EndOfOperationCallback(addresstmp);
403
 
404
 
-
 
405
          /*Increment sector number*/
-
 
406
          addresstmp = pFlash.Address + FLASH_PAGE_SIZE;
-
 
407
          pFlash.Address = addresstmp;
-
 
408
 
404
          /* Operation is completed, disable the PER Bit */
409
          /* If the erase operation is completed, disable the PER Bit */
405
          CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
410
          CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
406
 
411
 
407
          FLASH_PageErase(addresstmp);
412
          FLASH_PageErase(addresstmp);
408
        }
413
        }
409
        else
414
        else
410
        {
415
        {
411
          /*No more pages to Erase*/
416
          /*No more pages to Erase, user callback can be called.*/
412
 
-
 
413
          /*Reset Address and stop Erase pages procedure*/
417
          /*Reset Sector and stop Erase pages procedure*/
414
          pFlash.Address = 0xFFFFFFFF;
418
          pFlash.Address = addresstmp = 0xFFFFFFFF;
415
          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
419
          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
-
 
420
          /* FLASH EOP interrupt user callback */
-
 
421
          HAL_FLASH_EndOfOperationCallback(addresstmp);
416
        }
422
        }
417
      }
423
      }
418
      else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
424
      else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
419
      {
425
      {
420
        /* Operation is completed, disable the MER Bit */
426
        /* Operation is completed, disable the MER Bit */
Line 494... Line 500...
494
      if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
500
      if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
495
      {
501
      {
496
        /* Nb of pages to erased can be decreased */
502
        /* Nb of pages to erased can be decreased */
497
        pFlash.DataRemaining--;
503
        pFlash.DataRemaining--;
498
       
504
       
499
        /* Indicate user which page address has been erased*/
-
 
500
        HAL_FLASH_EndOfOperationCallback(pFlash.Address);
-
 
501
       
-
 
502
        /* Check if there are still pages to erase*/
505
        /* Check if there are still pages to erase*/
503
        if(pFlash.DataRemaining != 0)
506
        if(pFlash.DataRemaining != 0)
504
        {
507
        {
-
 
508
          /* Indicate user which page address has been erased*/
-
 
509
          HAL_FLASH_EndOfOperationCallback(pFlash.Address);
-
 
510
       
505
          /* Increment page address to next page */
511
          /* Increment page address to next page */
506
          pFlash.Address += FLASH_PAGE_SIZE;
512
          pFlash.Address += FLASH_PAGE_SIZE;
507
          addresstmp = pFlash.Address;
513
          addresstmp = pFlash.Address;
508
 
514
 
509
          /* Operation is completed, disable the PER Bit */
515
          /* Operation is completed, disable the PER Bit */
Line 516... Line 522...
516
          /*No more pages to Erase*/
522
          /*No more pages to Erase*/
517
         
523
         
518
          /*Reset Address and stop Erase pages procedure*/
524
          /*Reset Address and stop Erase pages procedure*/
519
          pFlash.Address = 0xFFFFFFFF;
525
          pFlash.Address = 0xFFFFFFFF;
520
          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
526
          pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
-
 
527
 
-
 
528
          /* FLASH EOP interrupt user callback */
-
 
529
          HAL_FLASH_EndOfOperationCallback(pFlash.Address);
521
        }
530
        }
522
      }
531
      }
523
      else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
532
      else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
524
      {
533
      {
525
        /* Operation is completed, disable the MER Bit */
534
        /* Operation is completed, disable the MER Bit */
Line 607... Line 616...
607
/**
616
/**
608
  * @brief  FLASH end of operation interrupt callback
617
  * @brief  FLASH end of operation interrupt callback
609
  * @param  ReturnValue: The value saved in this parameter depends on the ongoing procedure
618
  * @param  ReturnValue: The value saved in this parameter depends on the ongoing procedure
610
  *                 - Mass Erase: No return value expected
619
  *                 - Mass Erase: No return value expected
611
  *                 - Pages Erase: Address of the page which has been erased
620
  *                 - Pages Erase: Address of the page which has been erased
-
 
621
  *                    (if 0xFFFFFFFF, it means that all the selected pages have been erased)
612
  *                 - Program: Address which was selected for data program
622
  *                 - Program: Address which was selected for data program
613
  * @retval none
623
  * @retval none
614
  */
624
  */
615
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
625
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
616
{
626
{
-
 
627
  /* Prevent unused argument(s) compilation warning */
-
 
628
  UNUSED(ReturnValue);
617
  /* NOTE : This function Should not be modified, when the callback is needed,
629
  /* NOTE : This function Should not be modified, when the callback is needed,
618
            the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
630
            the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
619
   */
631
   */
620
}
632
}
621
 
633
 
Line 627... Line 639...
627
  *                 - Program: Address which was selected for data program
639
  *                 - Program: Address which was selected for data program
628
  * @retval none
640
  * @retval none
629
  */
641
  */
630
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
642
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
631
{
643
{
-
 
644
  /* Prevent unused argument(s) compilation warning */
-
 
645
  UNUSED(ReturnValue);
632
  /* NOTE : This function Should not be modified, when the callback is needed,
646
  /* NOTE : This function Should not be modified, when the callback is needed,
633
            the HAL_FLASH_OperationErrorCallback could be implemented in the user file
647
            the HAL_FLASH_OperationErrorCallback could be implemented in the user file
634
   */
648
   */
635
}
649
}
636
 
650
 
Line 785... Line 799...
785
  */
799
  */
786
 
800
 
787
/** @addtogroup FLASH_Private_Functions
801
/** @addtogroup FLASH_Private_Functions
788
 * @{
802
 * @{
789
 */
803
 */
-
 
804
 
790
/**
805
/**
791
  * @brief  Program a half-word (16-bit) at a specified address.
806
  * @brief  Program a half-word (16-bit) at a specified address.
792
  * @param  Address: specifies the address to be programmed.
807
  * @param  Address: specifies the address to be programmed.
793
  * @param  Data: specifies the data to be programmed.
808
  * @param  Data: specifies the data to be programmed.
794
  * @retval None
809
  * @retval None
Line 817... Line 832...
817
  *(__IO uint16_t*)Address = Data;
832
  *(__IO uint16_t*)Address = Data;
818
}
833
}
819
 
834
 
820
/**
835
/**
821
  * @brief  Wait for a FLASH operation to complete.
836
  * @brief  Wait for a FLASH operation to complete.
822
  * @param  Timeout: maximum flash operationtimeout
837
  * @param  Timeout: maximum flash operation timeout
823
  * @retval HAL_StatusTypeDef HAL Status
838
  * @retval HAL_StatusTypeDef HAL Status
824
  */
839
  */
825
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
840
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
826
{
841
{
827
  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
842
  /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
Line 846... Line 861...
846
  {
861
  {
847
    /* Clear FLASH End of Operation pending bit */
862
    /* Clear FLASH End of Operation pending bit */
848
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
863
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
849
  }
864
  }
850
 
865
 
851
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR) || \
866
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)  ||
-
 
867
     __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) ||
852
     __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
868
     __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
853
  {
869
  {
854
    /*Save the error code*/
870
    /*Save the error code*/
855
    FLASH_SetErrorCode();
871
    FLASH_SetErrorCode();
856
    return HAL_ERROR;
872
    return HAL_ERROR;
857
  }
873
  }
858
 
874
 
859
  /* If there is no error flag set */
875
  /* If there is no error flag set */
860
  return HAL_OK;
876
  return HAL_OK;
861
 
-
 
862
}
877
}
863
 
878
 
864
#if defined(FLASH_BANK2_END)
879
#if defined(FLASH_BANK2_END)
865
/**
880
/**
866
  * @brief  Wait for a FLASH BANK2 operation to complete.
881
  * @brief  Wait for a FLASH BANK2 operation to complete.