Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

107 rader
2.9 KiB

  1. /** @defgroup flash_file FLASH peripheral API
  2. *
  3. * @ingroup peripheral_apis
  4. */
  5. /*
  6. * This file is part of the libopencm3 project.
  7. *
  8. * Copyright (C) 2017 Matthew Lai @m@matthewlai.ca>
  9. * Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
  10. * Copyright (C) 2010 Mark Butler <mbutler@physics.otago.ac.nz>
  11. *
  12. * This library is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * along with this library. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**@{*/
  26. #include <libopencm3/stm32/flash.h>
  27. /*---------------------------------------------------------------------------*/
  28. /** @brief Issue Pipeline Stall
  29. Issue a pipeline stall to make sure all write operations completed.
  30. RM0385: After performing a data write operation and before polling the BSY bit
  31. to be cleared, the software can issue a DSB instruction to guarantee the
  32. completion of a previous data write operation.
  33. */
  34. static inline void flash_pipeline_stall(void)
  35. {
  36. __asm__ volatile("dsb":::"memory");
  37. }
  38. /*---------------------------------------------------------------------------*/
  39. /** @brief Wait until Last Operation has Ended
  40. This loops indefinitely until an operation (write or erase) has completed by
  41. testing the busy flag.
  42. */
  43. void flash_wait_for_last_operation(void)
  44. {
  45. flash_pipeline_stall();
  46. while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
  47. }
  48. /*---------------------------------------------------------------------------*/
  49. /** @brief Clear the Erase Sequence Error Flag
  50. This flag is set when an erase operation is performed with control register has
  51. not been correctly set.
  52. */
  53. void flash_clear_erserr_flag(void)
  54. {
  55. FLASH_SR |= FLASH_SR_ERSERR;
  56. }
  57. /*---------------------------------------------------------------------------*/
  58. /** @brief Clear All Status Flags
  59. Program error, end of operation, write protect error.
  60. */
  61. void flash_clear_status_flags(void)
  62. {
  63. flash_clear_erserr_flag();
  64. flash_clear_pgaerr_flag();
  65. flash_clear_wrperr_flag();
  66. flash_clear_pgperr_flag();
  67. flash_clear_eop_flag();
  68. }
  69. /*---------------------------------------------------------------------------*/
  70. /** @brief Enable the ART Cache
  71. */
  72. void flash_art_enable(void)
  73. {
  74. FLASH_ACR |= FLASH_ACR_ARTEN;
  75. }
  76. /*---------------------------------------------------------------------------*/
  77. /** @brief Reset the ART Cache
  78. The ART cache must be disabled for this to have effect.
  79. */
  80. void flash_art_reset(void)
  81. {
  82. FLASH_ACR |= FLASH_ACR_ARTRST;
  83. }
  84. /**@}*/