am_hal_otp.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //*****************************************************************************
  2. //
  3. // am_hal_otp.c
  4. //! @file
  5. //!
  6. //! @brief Functions for handling the OTP interface.
  7. //
  8. //*****************************************************************************
  9. //*****************************************************************************
  10. //
  11. // Copyright (c) 2017, Ambiq Micro
  12. // All rights reserved.
  13. //
  14. // Redistribution and use in source and binary forms, with or without
  15. // modification, are permitted provided that the following conditions are met:
  16. //
  17. // 1. Redistributions of source code must retain the above copyright notice,
  18. // this list of conditions and the following disclaimer.
  19. //
  20. // 2. Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the distribution.
  23. //
  24. // 3. Neither the name of the copyright holder nor the names of its
  25. // contributors may be used to endorse or promote products derived from this
  26. // software without specific prior written permission.
  27. //
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  32. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  35. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. // POSSIBILITY OF SUCH DAMAGE.
  39. //
  40. // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
  41. //
  42. //*****************************************************************************
  43. #include "am_mcu_apollo.h"
  44. #include "am_hal_flash.h"
  45. //*****************************************************************************
  46. //
  47. //! THIS FUNCTION IS DEPRECATED!
  48. //! Use the respective HAL flash function instead.
  49. //!
  50. // @brief Check if debugger is currently locked out.
  51. //
  52. // @param None.
  53. //
  54. // Determine if the debugger is already locked out.
  55. //
  56. // @return non-zero if debugger is currently locked out.
  57. // Specifically:
  58. // 0 = debugger is not locked out.
  59. // 1 = debugger is locked out.
  60. //
  61. //*****************************************************************************
  62. int
  63. am_hal_otp_is_debugger_lockedout(void)
  64. {
  65. return am_hal_flash_debugger_disable_check();
  66. }
  67. //*****************************************************************************
  68. //
  69. //! THIS FUNCTION IS DEPRECATED!
  70. //! Use the respective HAL flash function instead.
  71. //!
  72. // @brief Lock out debugger access.
  73. //
  74. // @param None.
  75. //
  76. // This function locks out access by a debugger.
  77. //
  78. // @return 0 if lockout was successful or if lockout was already enabled.
  79. //
  80. //*****************************************************************************
  81. int
  82. am_hal_otp_debugger_lockout(void)
  83. {
  84. return am_hal_flash_debugger_disable();
  85. }
  86. //*****************************************************************************
  87. //
  88. //! THIS FUNCTION IS DEPRECATED!
  89. //! Use the respective HAL flash function instead.
  90. //!
  91. // @brief Lock out SRAM access.
  92. //
  93. // @param None.
  94. //
  95. // This function locks out access by a debugger to SRAM.
  96. //
  97. // @return 0 if lockout was successful or if lockout was already enabled.
  98. // Low byte=0xff, byte 1 contains current value of lockout.
  99. // Else, return value from HAL programming function.
  100. //
  101. //*****************************************************************************
  102. int
  103. am_hal_otp_sram_lockout(void)
  104. {
  105. return am_hal_flash_wipe_sram_enable();
  106. }
  107. //*****************************************************************************
  108. //
  109. //! THIS FUNCTION IS DEPRECATED!
  110. //! Use the respective HAL flash function instead.
  111. //!
  112. // @brief Set copy (read) protection.
  113. //
  114. // @param @u32BegAddr The beginning address to be copy protected.
  115. // @u32EndAddr The ending address to be copy protected.
  116. //
  117. // @note For Apollo, the u32BegAddr parameter should be on a 16KB boundary, and
  118. // the u32EndAddr parameter should be on a (16KB-1) boundary. Otherwise
  119. // both parameters will be truncated/expanded to do so.
  120. // For example, if u32BegAddr=0x1000 and u32EndAddr=0xC200, the actual
  121. // range that protected is: 0x0 - 0xFFFF.
  122. //
  123. // This function enables copy protection on a given flash address range.
  124. //
  125. // @return 0 if copy protection was successfully enabled.
  126. //
  127. //*****************************************************************************
  128. int
  129. am_hal_otp_set_copy_protection(uint32_t u32BegAddr, uint32_t u32EndAddr)
  130. {
  131. return am_hal_flash_copy_protect_set((uint32_t*)u32BegAddr,
  132. (uint32_t*)u32EndAddr);
  133. }
  134. //*****************************************************************************
  135. //
  136. //! THIS FUNCTION IS DEPRECATED!
  137. //! Use the respective HAL flash function instead.
  138. //!
  139. // @brief Set write protection.
  140. //
  141. // @param @u32BegAddr The beginning address to be write protected.
  142. // @u32EndAddr The ending address to be write protected.
  143. //
  144. // @note For Apollo, the u32BegAddr parameter should be on a 16KB boundary, and
  145. // the u32EndAddr parameter should be on a (16KB-1) boundary. Otherwise
  146. // both parameters will be truncated/expanded to do so.
  147. // For example, if u32BegAddr=0x1000 and u32EndAddr=0xC200, the actual
  148. // range that protected is: 0x0 - 0xFFFF.
  149. //
  150. // This function enables write protection on a given flash address range.
  151. //
  152. // @return 0 if write protection was successfully enabled.
  153. //
  154. //*****************************************************************************
  155. int
  156. am_hal_otp_set_write_protection(uint32_t u32BegAddr, uint32_t u32EndAddr)
  157. {
  158. return am_hal_flash_write_protect_set((uint32_t*)u32BegAddr,
  159. (uint32_t*)u32EndAddr);
  160. }
  161. //*****************************************************************************
  162. //
  163. // End Doxygen group.
  164. //! @}
  165. //
  166. //*****************************************************************************