stm32f4xx_hal.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal.c
  4. * @author MCD Application Team
  5. * @brief HAL module driver.
  6. * This is the common part of the HAL initialization
  7. *
  8. @verbatim
  9. ==============================================================================
  10. ##### How to use this driver #####
  11. ==============================================================================
  12. [..]
  13. The common HAL driver contains a set of generic and common APIs that can be
  14. used by the PPP peripheral drivers and the user to start using the HAL.
  15. [..]
  16. The HAL contains two APIs' categories:
  17. (+) Common HAL APIs
  18. (+) Services HAL APIs
  19. @endverbatim
  20. ******************************************************************************
  21. * @attention
  22. *
  23. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  24. *
  25. * Redistribution and use in source and binary forms, with or without modification,
  26. * are permitted provided that the following conditions are met:
  27. * 1. Redistributions of source code must retain the above copyright notice,
  28. * this list of conditions and the following disclaimer.
  29. * 2. Redistributions in binary form must reproduce the above copyright notice,
  30. * this list of conditions and the following disclaimer in the documentation
  31. * and/or other materials provided with the distribution.
  32. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  33. * may be used to endorse or promote products derived from this software
  34. * without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  37. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  40. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  42. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  43. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  45. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "stm32f4xx_hal.h"
  51. #include <linux/types.h>
  52. #include <linux/jiffies.h>
  53. /** @addtogroup STM32F4xx_HAL_Driver
  54. * @{
  55. */
  56. /** \brief Structure type to access the System Timer (SysTick).
  57. * */
  58. //typedef struct
  59. //{
  60. // __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
  61. // __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
  62. // __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
  63. // __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
  64. //} SysTick_Type;
  65. //
  66. //#define SysTick ((SysTick_Type*)0xE000ED00UL)
  67. /** @defgroup HAL HAL
  68. * @brief HAL module driver.
  69. * @{
  70. */
  71. /* Private typedef -----------------------------------------------------------*/
  72. /* Private define ------------------------------------------------------------*/
  73. /** @addtogroup HAL_Private_Constants
  74. * @{
  75. */
  76. /**
  77. * @brief STM32F4xx HAL Driver version number V1.7.4
  78. */
  79. #define __STM32F4xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
  80. #define __STM32F4xx_HAL_VERSION_SUB1 (0x07U) /*!< [23:16] sub1 version */
  81. #define __STM32F4xx_HAL_VERSION_SUB2 (0x04U) /*!< [15:8] sub2 version */
  82. #define __STM32F4xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
  83. #define __STM32F4xx_HAL_VERSION ((__STM32F4xx_HAL_VERSION_MAIN << 24U)\
  84. |(__STM32F4xx_HAL_VERSION_SUB1 << 16U)\
  85. |(__STM32F4xx_HAL_VERSION_SUB2 << 8U )\
  86. |(__STM32F4xx_HAL_VERSION_RC))
  87. #define IDCODE_DEVID_MASK 0x00000FFFU
  88. /* ------------ RCC registers bit address in the alias region ----------- */
  89. #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE)
  90. /* --- MEMRMP Register ---*/
  91. /* Alias word address of UFB_MODE bit */
  92. #define MEMRMP_OFFSET SYSCFG_OFFSET
  93. #define UFB_MODE_BIT_NUMBER SYSCFG_MEMRMP_UFB_MODE_Pos
  94. #define UFB_MODE_BB (uint32_t)(PERIPH_BB_BASE + (MEMRMP_OFFSET * 32U) + (UFB_MODE_BIT_NUMBER * 4U))
  95. /* --- CMPCR Register ---*/
  96. /* Alias word address of CMP_PD bit */
  97. #define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20U)
  98. #define CMP_PD_BIT_NUMBER SYSCFG_CMPCR_CMP_PD_Pos
  99. #define CMPCR_CMP_PD_BB (uint32_t)(PERIPH_BB_BASE + (CMPCR_OFFSET * 32U) + (CMP_PD_BIT_NUMBER * 4U))
  100. /* --- MCHDLYCR Register ---*/
  101. /* Alias word address of BSCKSEL bit */
  102. #define MCHDLYCR_OFFSET (SYSCFG_OFFSET + 0x30U)
  103. #define BSCKSEL_BIT_NUMBER SYSCFG_MCHDLYCR_BSCKSEL_Pos
  104. #define MCHDLYCR_BSCKSEL_BB (uint32_t)(PERIPH_BB_BASE + (MCHDLYCR_OFFSET * 32U) + (BSCKSEL_BIT_NUMBER * 4U))
  105. /**
  106. * @}
  107. */
  108. /* Private macro -------------------------------------------------------------*/
  109. /* Private variables ---------------------------------------------------------*/
  110. /** @addtogroup HAL_Private_Variables
  111. * @{
  112. */
  113. __IO uint32_t uwTick;
  114. uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
  115. HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
  116. /**
  117. * @}
  118. */
  119. /* Private function prototypes -----------------------------------------------*/
  120. /* Private functions ---------------------------------------------------------*/
  121. /** @defgroup HAL_Exported_Functions HAL Exported Functions
  122. * @{
  123. */
  124. /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
  125. * @brief Initialization and de-initialization functions
  126. *
  127. @verbatim
  128. ===============================================================================
  129. ##### Initialization and Configuration functions #####
  130. ===============================================================================
  131. [..] This section provides functions allowing to:
  132. (+) Initializes the Flash interface the NVIC allocation and initial clock
  133. configuration. It initializes the systick also when timeout is needed
  134. and the backup domain when enabled.
  135. (+) De-Initializes common part of the HAL.
  136. (+) Configure the time base source to have 1ms time base with a dedicated
  137. Tick interrupt priority.
  138. (++) SysTick timer is used by default as source of time base, but user
  139. can eventually implement his proper time base source (a general purpose
  140. timer for example or other time source), keeping in mind that Time base
  141. duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  142. handled in milliseconds basis.
  143. (++) Time base configuration function (HAL_InitTick ()) is called automatically
  144. at the beginning of the program after reset by HAL_Init() or at any time
  145. when clock is configured, by HAL_RCC_ClockConfig().
  146. (++) Source of time base is configured to generate interrupts at regular
  147. time intervals. Care must be taken if HAL_Delay() is called from a
  148. peripheral ISR process, the Tick interrupt line must have higher priority
  149. (numerically lower) than the peripheral interrupt. Otherwise the caller
  150. ISR process will be blocked.
  151. (++) functions affecting time base configurations are declared as __weak
  152. to make override possible in case of other implementations in user file.
  153. @endverbatim
  154. * @{
  155. */
  156. /**
  157. * @brief This function is used to initialize the HAL Library; it must be the first
  158. * instruction to be executed in the main program (before to call any other
  159. * HAL function), it performs the following:
  160. * Configure the Flash prefetch, instruction and Data caches.
  161. * Configures the SysTick to generate an interrupt each 1 millisecond,
  162. * which is clocked by the HSI (at this stage, the clock is not yet
  163. * configured and thus the system is running from the internal HSI at 16 MHz).
  164. * Set NVIC Group Priority to 4.
  165. * Calls the HAL_MspInit() callback function defined in user file
  166. * "stm32f4xx_hal_msp.c" to do the global low level hardware initialization
  167. *
  168. * @note SysTick is used as time base for the HAL_Delay() function, the application
  169. * need to ensure that the SysTick time base is always set to 1 millisecond
  170. * to have correct HAL operation.
  171. * @retval HAL status
  172. */
  173. HAL_StatusTypeDef HAL_Init(void)
  174. {
  175. // /* Configure Flash prefetch, Instruction cache, Data cache */
  176. //#if (INSTRUCTION_CACHE_ENABLE != 0U)
  177. // __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
  178. //#endif /* INSTRUCTION_CACHE_ENABLE */
  179. //
  180. //#if (DATA_CACHE_ENABLE != 0U)
  181. // __HAL_FLASH_DATA_CACHE_ENABLE();
  182. //#endif /* DATA_CACHE_ENABLE */
  183. //
  184. //#if (PREFETCH_ENABLE != 0U)
  185. // __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
  186. //#endif /* PREFETCH_ENABLE */
  187. //
  188. // /* Set Interrupt Group Priority */
  189. // HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  190. //
  191. // /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
  192. // HAL_InitTick(TICK_INT_PRIORITY);
  193. //
  194. // /* Init the low level hardware */
  195. // HAL_MspInit();
  196. //
  197. // /* Return function status */
  198. return HAL_OK;
  199. }
  200. /**
  201. * @brief This function de-Initializes common part of the HAL and stops the systick.
  202. * This function is optional.
  203. * @retval HAL status
  204. */
  205. HAL_StatusTypeDef HAL_DeInit(void)
  206. {
  207. // /* Reset of all peripherals */
  208. // __HAL_RCC_APB1_FORCE_RESET();
  209. // __HAL_RCC_APB1_RELEASE_RESET();
  210. //
  211. // __HAL_RCC_APB2_FORCE_RESET();
  212. // __HAL_RCC_APB2_RELEASE_RESET();
  213. //
  214. // __HAL_RCC_AHB1_FORCE_RESET();
  215. // __HAL_RCC_AHB1_RELEASE_RESET();
  216. //
  217. // __HAL_RCC_AHB2_FORCE_RESET();
  218. // __HAL_RCC_AHB2_RELEASE_RESET();
  219. //
  220. // __HAL_RCC_AHB3_FORCE_RESET();
  221. // __HAL_RCC_AHB3_RELEASE_RESET();
  222. //
  223. // /* De-Init the low level hardware */
  224. // HAL_MspDeInit();
  225. //
  226. // /* Return function status */
  227. return HAL_OK;
  228. }
  229. /**
  230. * @brief Initialize the MSP.
  231. * @retval None
  232. */
  233. __weak void HAL_MspInit(void)
  234. {
  235. /* NOTE : This function should not be modified, when the callback is needed,
  236. the HAL_MspInit could be implemented in the user file
  237. */
  238. }
  239. /**
  240. * @brief DeInitializes the MSP.
  241. * @retval None
  242. */
  243. __weak void HAL_MspDeInit(void)
  244. {
  245. /* NOTE : This function should not be modified, when the callback is needed,
  246. the HAL_MspDeInit could be implemented in the user file
  247. */
  248. }
  249. /**
  250. * @brief This function configures the source of the time base.
  251. * The time source is configured to have 1ms time base with a dedicated
  252. * Tick interrupt priority.
  253. * @note This function is called automatically at the beginning of program after
  254. * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
  255. * @note In the default implementation, SysTick timer is the source of time base.
  256. * It is used to generate interrupts at regular time intervals.
  257. * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
  258. * The SysTick interrupt must have higher priority (numerically lower)
  259. * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
  260. * The function is declared as __weak to be overwritten in case of other
  261. * implementation in user file.
  262. * @param TickPriority Tick interrupt priority.
  263. * @retval HAL status
  264. */
  265. __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
  266. {
  267. // /* Configure the SysTick to have interrupt in 1ms time basis*/
  268. // if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
  269. // {
  270. // return HAL_ERROR;
  271. // }
  272. //
  273. // /* Configure the SysTick IRQ priority */
  274. // if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  275. // {
  276. // HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
  277. // uwTickPrio = TickPriority;
  278. // }
  279. // else
  280. // {
  281. // return HAL_ERROR;
  282. // }
  283. //
  284. // /* Return function status */
  285. return HAL_OK;
  286. }
  287. /**
  288. * @}
  289. */
  290. /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
  291. * @brief HAL Control functions
  292. *
  293. @verbatim
  294. ===============================================================================
  295. ##### HAL Control functions #####
  296. ===============================================================================
  297. [..] This section provides functions allowing to:
  298. (+) Provide a tick value in millisecond
  299. (+) Provide a blocking delay in millisecond
  300. (+) Suspend the time base source interrupt
  301. (+) Resume the time base source interrupt
  302. (+) Get the HAL API driver version
  303. (+) Get the device identifier
  304. (+) Get the device revision identifier
  305. (+) Enable/Disable Debug module during SLEEP mode
  306. (+) Enable/Disable Debug module during STOP mode
  307. (+) Enable/Disable Debug module during STANDBY mode
  308. @endverbatim
  309. * @{
  310. */
  311. /**
  312. * @brief This function is called to increment a global variable "uwTick"
  313. * used as application time base.
  314. * @note In the default implementation, this variable is incremented each 1ms
  315. * in SysTick ISR.
  316. * @note This function is declared as __weak to be overwritten in case of other
  317. * implementations in user file.
  318. * @retval None
  319. */
  320. __weak void HAL_IncTick(void)
  321. {
  322. // uwTick += uwTickFreq;
  323. }
  324. /**
  325. * @brief Provides a tick value in millisecond.
  326. * @note This function is declared as __weak to be overwritten in case of other
  327. * implementations in user file.
  328. * @retval tick value
  329. */
  330. __weak uint32_t HAL_GetTick(void)
  331. {
  332. // return uwTick;
  333. return jiffies;
  334. }
  335. /**
  336. * @brief This function returns a tick priority.
  337. * @retval tick priority
  338. */
  339. uint32_t HAL_GetTickPrio(void)
  340. {
  341. return uwTickPrio;
  342. }
  343. /**
  344. * @brief Set new tick Freq.
  345. * @retval Status
  346. */
  347. HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
  348. {
  349. // HAL_StatusTypeDef status = HAL_OK;
  350. // assert_param(IS_TICKFREQ(Freq));
  351. //
  352. // if (uwTickFreq != Freq)
  353. // {
  354. // uwTickFreq = Freq;
  355. //
  356. // /* Apply the new tick Freq */
  357. // status = HAL_InitTick(uwTickPrio);
  358. // }
  359. //
  360. // return status;
  361. return HAL_OK;
  362. }
  363. /**
  364. * @brief Return tick frequency.
  365. * @retval tick period in Hz
  366. */
  367. HAL_TickFreqTypeDef HAL_GetTickFreq(void)
  368. {
  369. // return uwTickFreq;
  370. return HZ;
  371. }
  372. /**
  373. * @brief This function provides minimum delay (in milliseconds) based
  374. * on variable incremented.
  375. * @note In the default implementation , SysTick timer is the source of time base.
  376. * It is used to generate interrupts at regular time intervals where uwTick
  377. * is incremented.
  378. * @note This function is declared as __weak to be overwritten in case of other
  379. * implementations in user file.
  380. * @param Delay specifies the delay time length, in milliseconds.
  381. * @retval None
  382. */
  383. __weak void HAL_Delay(uint32_t Delay)
  384. {
  385. // uint32_t tickstart = HAL_GetTick();
  386. // uint32_t wait = Delay;
  387. /* Add a freq to guarantee minimum wait */
  388. // if (wait < HAL_MAX_DELAY)
  389. // {
  390. // wait += (uint32_t)(uwTickFreq);
  391. // }
  392. //while((HAL_GetTick() - tickstart) < wait)
  393. // {
  394. //}
  395. }
  396. /**
  397. * @brief Suspend Tick increment.
  398. * @note In the default implementation , SysTick timer is the source of time base. It is
  399. * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
  400. * is called, the SysTick interrupt will be disabled and so Tick increment
  401. * is suspended.
  402. * @note This function is declared as __weak to be overwritten in case of other
  403. * implementations in user file.
  404. * @retval None
  405. */
  406. __weak void HAL_SuspendTick(void)
  407. {
  408. /* Disable SysTick Interrupt */
  409. // SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
  410. }
  411. /**
  412. * @brief Resume Tick increment.
  413. * @note In the default implementation , SysTick timer is the source of time base. It is
  414. * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
  415. * is called, the SysTick interrupt will be enabled and so Tick increment
  416. * is resumed.
  417. * @note This function is declared as __weak to be overwritten in case of other
  418. * implementations in user file.
  419. * @retval None
  420. */
  421. __weak void HAL_ResumeTick(void)
  422. {
  423. /* Enable SysTick Interrupt */
  424. //SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
  425. }
  426. /**
  427. * @brief Returns the HAL revision
  428. * @retval version : 0xXYZR (8bits for each decimal, R for RC)
  429. */
  430. uint32_t HAL_GetHalVersion(void)
  431. {
  432. return __STM32F4xx_HAL_VERSION;
  433. }
  434. /**
  435. * @brief Returns the device revision identifier.
  436. * @retval Device revision identifier
  437. */
  438. uint32_t HAL_GetREVID(void)
  439. {
  440. return((DBGMCU->IDCODE) >> 16U);
  441. }
  442. /**
  443. * @brief Returns the device identifier.
  444. * @retval Device identifier
  445. */
  446. uint32_t HAL_GetDEVID(void)
  447. {
  448. return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
  449. }
  450. /**
  451. * @brief Enable the Debug Module during SLEEP mode
  452. * @retval None
  453. */
  454. void HAL_DBGMCU_EnableDBGSleepMode(void)
  455. {
  456. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
  457. }
  458. /**
  459. * @brief Disable the Debug Module during SLEEP mode
  460. * @retval None
  461. */
  462. void HAL_DBGMCU_DisableDBGSleepMode(void)
  463. {
  464. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
  465. }
  466. /**
  467. * @brief Enable the Debug Module during STOP mode
  468. * @retval None
  469. */
  470. void HAL_DBGMCU_EnableDBGStopMode(void)
  471. {
  472. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
  473. }
  474. /**
  475. * @brief Disable the Debug Module during STOP mode
  476. * @retval None
  477. */
  478. void HAL_DBGMCU_DisableDBGStopMode(void)
  479. {
  480. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
  481. }
  482. /**
  483. * @brief Enable the Debug Module during STANDBY mode
  484. * @retval None
  485. */
  486. void HAL_DBGMCU_EnableDBGStandbyMode(void)
  487. {
  488. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
  489. }
  490. /**
  491. * @brief Disable the Debug Module during STANDBY mode
  492. * @retval None
  493. */
  494. void HAL_DBGMCU_DisableDBGStandbyMode(void)
  495. {
  496. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
  497. }
  498. /**
  499. * @brief Enables the I/O Compensation Cell.
  500. * @note The I/O compensation cell can be used only when the device supply
  501. * voltage ranges from 2.4 to 3.6 V.
  502. * @retval None
  503. */
  504. void HAL_EnableCompensationCell(void)
  505. {
  506. *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)ENABLE;
  507. }
  508. /**
  509. * @brief Power-down the I/O Compensation Cell.
  510. * @note The I/O compensation cell can be used only when the device supply
  511. * voltage ranges from 2.4 to 3.6 V.
  512. * @retval None
  513. */
  514. void HAL_DisableCompensationCell(void)
  515. {
  516. *(__IO uint32_t *)CMPCR_CMP_PD_BB = (uint32_t)DISABLE;
  517. }
  518. /**
  519. * @brief Return the unique device identifier (UID based on 96 bits)
  520. * @param UID pointer to 3 words array.
  521. * @retval Device identifier
  522. */
  523. void HAL_GetUID(uint32_t *UID)
  524. {
  525. UID[0] = (uint32_t)(READ_REG(*((uint32_t *)UID_BASE)));
  526. UID[1] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
  527. UID[2] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
  528. }
  529. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\
  530. defined(STM32F469xx) || defined(STM32F479xx)
  531. /**
  532. * @brief Enables the Internal FLASH Bank Swapping.
  533. *
  534. * @note This function can be used only for STM32F42xxx/43xxx devices.
  535. *
  536. * @note Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000)
  537. * and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000)
  538. *
  539. * @retval None
  540. */
  541. void HAL_EnableMemorySwappingBank(void)
  542. {
  543. *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)ENABLE;
  544. }
  545. /**
  546. * @brief Disables the Internal FLASH Bank Swapping.
  547. *
  548. * @note This function can be used only for STM32F42xxx/43xxx devices.
  549. *
  550. * @note The default state : Flash Bank1 mapped at 0x08000000 (and aliased @0x00000000)
  551. * and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000)
  552. *
  553. * @retval None
  554. */
  555. void HAL_DisableMemorySwappingBank(void)
  556. {
  557. *(__IO uint32_t *)UFB_MODE_BB = (uint32_t)DISABLE;
  558. }
  559. #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */
  560. /**
  561. * @}
  562. */
  563. /**
  564. * @}
  565. */
  566. /**
  567. * @}
  568. */
  569. /**
  570. * @}
  571. */
  572. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/