n32g45x_dbg.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_dbg.c
  29. * @author Nations
  30. * @version v1.0.2
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #include "n32g45x_dbg.h"
  35. /** @addtogroup N32G45X_StdPeriph_Driver
  36. * @{
  37. */
  38. /** @addtogroup DBG
  39. * @brief DBG driver modules
  40. * @{
  41. */
  42. /** @addtogroup DBGMCU_Private_TypesDefinitions
  43. * @{
  44. */
  45. /**
  46. * @}
  47. */
  48. /** @addtogroup DBGMCU_Private_Defines
  49. * @{
  50. */
  51. #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
  52. /**
  53. * @}
  54. */
  55. /** @addtogroup DBGMCU_Private_Macros
  56. * @{
  57. */
  58. /**
  59. * @}
  60. */
  61. /** @addtogroup DBGMCU_Private_Variables
  62. * @{
  63. */
  64. /**
  65. * @}
  66. */
  67. /** @addtogroup DBGMCU_Private_FunctionPrototypes
  68. * @{
  69. */
  70. /**
  71. * @}
  72. */
  73. /** @addtogroup DBGMCU_Private_Functions
  74. * @{
  75. */
  76. /**
  77. * @brief Returns the UCID.
  78. * @return UCID
  79. */
  80. void GetUCID(uint8_t *UCIDbuf)
  81. {
  82. uint8_t num = 0;
  83. uint32_t* ucid_addr = (uint32_t*)0;
  84. uint32_t temp = 0;
  85. if (0xFFFFFFFF == *(uint32_t*)(0x1FFFF260))
  86. {
  87. ucid_addr = (uint32_t*)UCID_BASE;
  88. }
  89. else
  90. {
  91. ucid_addr = (uint32_t*)(0x1FFFF260);
  92. }
  93. for (num = 0; num < UCID_LENGTH;)
  94. {
  95. temp = *(__IO uint32_t*)(ucid_addr++);
  96. UCIDbuf[num++] = (temp & 0xFF);
  97. UCIDbuf[num++] = (temp & 0xFF00) >> 8;
  98. UCIDbuf[num++] = (temp & 0xFF0000) >> 16;
  99. UCIDbuf[num++] = (temp & 0xFF000000) >> 24;
  100. }
  101. }
  102. /**
  103. * @brief Returns the UID.
  104. * @return UID
  105. */
  106. void GetUID(uint8_t *UIDbuf)
  107. {
  108. uint8_t num = 0;
  109. uint32_t* uid_addr = (uint32_t*)0;
  110. uint32_t temp = 0;
  111. if (0xFFFFFFFF == *(uint32_t*)(0x1FFFF270))
  112. {
  113. uid_addr = (uint32_t*)UID_BASE;
  114. }
  115. else
  116. {
  117. uid_addr = (uint32_t*)(0x1FFFF270);
  118. }
  119. for (num = 0; num < UID_LENGTH;)
  120. {
  121. temp = *(__IO uint32_t*)(uid_addr++);
  122. UIDbuf[num++] = (temp & 0xFF);
  123. UIDbuf[num++] = (temp & 0xFF00) >> 8;
  124. UIDbuf[num++] = (temp & 0xFF0000) >> 16;
  125. UIDbuf[num++] = (temp & 0xFF000000) >> 24;
  126. }
  127. }
  128. /**
  129. * @brief Returns the DBGMCU_ID.
  130. * @return DBGMCU_ID
  131. */
  132. void GetDBGMCU_ID(uint8_t *DBGMCU_IDbuf)
  133. {
  134. uint8_t num = 0;
  135. uint32_t* dbgid_addr = (uint32_t*)0;
  136. uint32_t temp = 0;
  137. dbgid_addr = (uint32_t*)DBGMCU_ID_BASE;
  138. for (num = 0; num < DBGMCU_ID_LENGTH;)
  139. {
  140. temp = *(__IO uint32_t*)(dbgid_addr++);
  141. DBGMCU_IDbuf[num++] = (temp & 0xFF);
  142. DBGMCU_IDbuf[num++] = (temp & 0xFF00) >> 8;
  143. DBGMCU_IDbuf[num++] = (temp & 0xFF0000) >> 16;
  144. DBGMCU_IDbuf[num++] = (temp & 0xFF000000) >> 24;
  145. }
  146. }
  147. /**
  148. * @brief Returns the device revision number.
  149. * @return Device revision identifier
  150. */
  151. uint32_t DBG_GetRevNum(void)
  152. {
  153. return (DBG->ID & 0x00FF);
  154. }
  155. /**
  156. * @brief Returns the device identifier.
  157. * @return Device identifier
  158. */
  159. uint32_t DBG_GetDevNum(void)
  160. {
  161. uint32_t id = DBG->ID;
  162. return ((id & 0x00F00000) >> 20) | ((id & 0xFF00) >> 4);
  163. }
  164. /**
  165. * @brief Configures the specified peripheral and low power mode behavior
  166. * when the MCU under Debug mode.
  167. * @param DBG_Periph specifies the peripheral and low power mode.
  168. * This parameter can be any combination of the following values:
  169. * @arg DBG_SLEEP Keep debugger connection during SLEEP mode
  170. * @arg DBG_STOP Keep debugger connection during STOP mode
  171. * @arg DBG_STDBY Keep debugger connection during STANDBY mode
  172. * @arg DBG_IWDG_STOP Debug IWDG stopped when Core is halted
  173. * @arg DBG_WWDG_STOP Debug WWDG stopped when Core is halted
  174. * @arg DBG_TIM1_STOP TIM1 counter stopped when Core is halted
  175. * @arg DBG_TIM2_STOP TIM2 counter stopped when Core is halted
  176. * @arg DBG_TIM3_STOP TIM3 counter stopped when Core is halted
  177. * @arg DBG_TIM4_STOP TIM4 counter stopped when Core is halted
  178. * @arg DBG_CAN1_STOP Debug CAN2 stopped when Core is halted
  179. * @arg DBG_I2C1SMBUS_TIMEOUT I2C1 SMBUS timeout mode stopped when Core is halted
  180. * @arg DBG_I2C2SMBUS_TIMEOUT I2C2 SMBUS timeout mode stopped when Core is halted
  181. * @arg DBG_TIM8_STOP TIM8 counter stopped when Core is halted
  182. * @arg DBG_TIM5_STOP TIM5 counter stopped when Core is halted
  183. * @arg DBG_TIM6_STOP TIM6 counter stopped when Core is halted
  184. * @arg DBG_TIM7_STOP TIM7 counter stopped when Core is halted
  185. * @arg DBG_CAN2_STOP Debug CAN2 stopped when Core is halted
  186. * @param Cmd new state of the specified peripheral in Debug mode.
  187. * This parameter can be: ENABLE or DISABLE.
  188. */
  189. void DBG_ConfigPeriph(uint32_t DBG_Periph, FunctionalState Cmd)
  190. {
  191. /* Check the parameters */
  192. assert_param(IS_DBGMCU_PERIPH(DBG_Periph));
  193. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  194. if (Cmd != DISABLE)
  195. {
  196. DBG->CTRL |= DBG_Periph;
  197. }
  198. else
  199. {
  200. DBG->CTRL &= ~DBG_Periph;
  201. }
  202. }
  203. /**
  204. * @brief Get FLASH size of this chip.
  205. *
  206. * @return FLASH size in bytes.
  207. */
  208. uint32_t DBG_GetFlashSize(void)
  209. {
  210. return (DBG->ID & 0x000F0000);
  211. }
  212. /**
  213. * @brief Get SRAM size of this chip.
  214. *
  215. * @return SRAM size in bytes.
  216. */
  217. uint32_t DBG_GetSramSize(void)
  218. {
  219. return (((DBG->ID & 0xF0000000) >> 28) + 1) << 14;
  220. }
  221. /**
  222. * @}
  223. */
  224. /**
  225. * @}
  226. */
  227. /**
  228. * @}
  229. */