Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

98 рядки
2.8 KiB

  1. /** @defgroup flash_file Flash peripheral API
  2. * @ingroup peripheral_apis
  3. * @brief SWM050 Flash API.
  4. * LGPL License Terms @ref lgpl_license
  5. * @author @htmlonly © @endhtmlonly 2019
  6. * Caleb Szalacinski <contact@skiboy.net>
  7. */
  8. /*
  9. * This file is part of the libopencm3 project.
  10. *
  11. * Copyright (C) 2019 Caleb Szalacinski <contact@skiboy.net>
  12. *
  13. * This library is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Lesser General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public License
  24. * along with this library. If not, see <http://www.gnu.org/licenses/>.
  25. */
  26. /**@{*/
  27. #include <libopencm3/swm050/flash.h>
  28. /* Internal function pointers to the ROM flash API */
  29. #define IAP_WR (void *)(0x1000AB)
  30. #define IAP_E (void *)(0x100127)
  31. uint32_t (*iap_write_read)(uint32_t *, uint32_t *, uint8_t, uint8_t) = IAP_WR;
  32. uint32_t (*iap_erase)(void) = IAP_E;
  33. /*---------------------------------------------------------------------------*/
  34. /** @brief Write to the user flash
  35. Writes words to the 0.5k user flash area.
  36. Must be performed only when the system clock is 18Mhz.
  37. @param[in] dest Destination address
  38. The memory area to copy to.
  39. From 0x00 - 0x1FC, as long as it is word-aligned
  40. @param[in] src Source address
  41. The memory area to copy from.
  42. @param[in] cnt Number of words to write
  43. From 1-128 as long as (dest + (cnt * 4)) < 0x200
  44. @return 1 if successful, 0 if error
  45. */
  46. uint32_t flash_write(uint32_t *dest, uint32_t *src, uint8_t cnt)
  47. {
  48. return iap_write_read(dest, src, cnt, 1);
  49. }
  50. /*---------------------------------------------------------------------------*/
  51. /** @brief Read from the user flash
  52. Reads words from the 0.5k user flash area.
  53. Must be performed only when the system clock is 18Mhz.
  54. @param[in] src Source address
  55. The memory area to copy from.
  56. From 0x00 - 0x1FC, as long as it is word-aligned
  57. @param[out] dest Destination address
  58. The memory area to copy to.
  59. @param[in] cnt Number of words to read
  60. From 1 - 128 as long as (src + (cnt * 4)) < 0x200
  61. @return 1 if successful, 0 if error
  62. */
  63. uint32_t flash_read(uint32_t *src, uint32_t *dest, uint8_t cnt)
  64. {
  65. return iap_write_read(src, dest, cnt, 0);
  66. }
  67. /*---------------------------------------------------------------------------*/
  68. /** @brief Erase the user flash
  69. Erases the entire 0.5k user flash area.
  70. Must be performed only when the system clock is 18Mhz.
  71. @return 1 if successful, 0 if error
  72. */
  73. uint32_t flash_erase(void)
  74. {
  75. return iap_erase();
  76. }
  77. /**@}*/