stm32l5xx_hal_icache.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /**
  2. ******************************************************************************
  3. * @file stm32l5xx_hal_icache.c
  4. * @author MCD Application Team
  5. * @brief ICACHE HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Instruction Cache (ICACHE).
  8. * + Initialization and Configuration
  9. * + Invalidate functions
  10. * + Monitoring management
  11. * + Memory address remap management
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * Copyright (c) 2019 STMicroelectronics.
  16. * All rights reserved.
  17. *
  18. * This software is licensed under terms that can be found in the LICENSE file
  19. * in the root directory of this software component.
  20. * If no LICENSE file comes with this software, it is provided AS-IS.
  21. *
  22. ******************************************************************************
  23. @verbatim
  24. ==============================================================================
  25. ##### ICACHE main features #####
  26. ==============================================================================
  27. [..]
  28. The Instruction Cache (ICACHE) is introduced on C-AHB code bus of
  29. Cortex-M33 processor to improve performance when fetching instruction
  30. and data from both internal and external memories. It allows close to
  31. zero wait states performance.
  32. (+) The ICACHE provides two performance counters (Hit and Miss),
  33. cache invalidate maintenance operation, error management and TrustZone
  34. security support.
  35. (+) The ICACHE provides additionally the possibility to remap input address
  36. falling into up to four memory regions (used to remap aliased code in
  37. external memories to the internal Code region, for execution)
  38. ===============================================================================
  39. ##### How to use this driver #####
  40. ===============================================================================
  41. [..]
  42. The ICACHE HAL driver can be used as follows:
  43. (#) Optionally configure the Instruction Cache mode with
  44. @ref HAL_ICACHE_ConfigAssociativityMode() if the default configuration
  45. does not suit the application requirements.
  46. (#) Enable and disable the Instruction Cache with respectively
  47. @ref HAL_ICACHE_Enable() and @ref HAL_ICACHE_Disable().
  48. Use @ref HAL_ICACHE_IsEnabled() to get the Instruction Cache status.
  49. (#) Initiate the cache maintenance invalidation procedure with either
  50. @ref HAL_ICACHE_Invalidate() (blocking mode) or @ref HAL_ICACHE_Invalidate_IT()
  51. (interrupt mode). When interrupt mode is used, the callback function
  52. @ref HAL_ICACHE_InvalidateCompleteCallback() is called when the invalidate
  53. procedure is complete. The function @ref HAL_ICACHE_WaitForInvalidateComplete()
  54. may be called to wait for the end of the invalidate procedure automatically
  55. initiated when disabling the Instruction Cache with @ref HAL_ICACHE_Disable().
  56. The cache operation is bypassed during the invalidation procedure.
  57. (#) Use the performance monitoring counters for Hit and Miss with the following
  58. functions: @ref HAL_ICACHE_Monitor_Start(), @ref HAL_ICACHE_Monitor_Stop(),
  59. @ref HAL_ICACHE_Monitor_Reset(), @ref HAL_ICACHE_Monitor_GetHitValue() and
  60. @ref HAL_ICACHE_Monitor_GetMissValue()
  61. (#) Enable and disable up to four regions to remap input address from external
  62. memories to the internal Code region for execution with
  63. @ref HAL_ICACHE_EnableRemapRegion() and @ref HAL_ICACHE_DisableRemapRegion()
  64. @endverbatim
  65. */
  66. /* Includes ------------------------------------------------------------------*/
  67. #include "stm32l5xx_hal.h"
  68. /** @addtogroup STM32L5xx_HAL_Driver
  69. * @{
  70. */
  71. /** @defgroup ICACHE ICACHE
  72. * @brief HAL ICACHE module driver
  73. * @{
  74. */
  75. #ifdef HAL_ICACHE_MODULE_ENABLED
  76. /* Private typedef -----------------------------------------------------------*/
  77. /* Private constants ---------------------------------------------------------*/
  78. /** @addtogroup ICACHE_Private_Constants ICACHE Private Constants
  79. * @{
  80. */
  81. #define ICACHE_INVALIDATE_TIMEOUT_VALUE 1U /* 1ms */
  82. #define ICACHE_DISABLE_TIMEOUT_VALUE 1U /* 1ms */
  83. /**
  84. * @}
  85. */
  86. /* Private macros ------------------------------------------------------------*/
  87. /** @defgroup ICACHE_Private_Macros ICACHE Private Macros
  88. * @{
  89. */
  90. #define IS_ICACHE_ASSOCIATIVITY_MODE(__MODE__) (((__MODE__) == ICACHE_1WAY) || \
  91. ((__MODE__) == ICACHE_2WAYS))
  92. #define IS_ICACHE_MONITOR_TYPE(__TYPE__) (((__TYPE__) == ICACHE_MONITOR_HIT_MISS) || \
  93. ((__TYPE__) == ICACHE_MONITOR_HIT) || \
  94. ((__TYPE__) == ICACHE_MONITOR_MISS))
  95. #define IS_ICACHE_REGION_NUMBER(__NUMBER__) ((__NUMBER__) < 4U)
  96. #define IS_ICACHE_REGION_SIZE(__SIZE__) (((__SIZE__) == ICACHE_REGIONSIZE_2MB) || \
  97. ((__SIZE__) == ICACHE_REGIONSIZE_4MB) || \
  98. ((__SIZE__) == ICACHE_REGIONSIZE_8MB) || \
  99. ((__SIZE__) == ICACHE_REGIONSIZE_16MB) || \
  100. ((__SIZE__) == ICACHE_REGIONSIZE_32MB) || \
  101. ((__SIZE__) == ICACHE_REGIONSIZE_64MB) || \
  102. ((__SIZE__) == ICACHE_REGIONSIZE_128MB))
  103. #define IS_ICACHE_REGION_TRAFFIC_ROUTE(__TRAFFICROUTE__) (((__TRAFFICROUTE__) == ICACHE_MASTER1_PORT) || \
  104. ((__TRAFFICROUTE__) == ICACHE_MASTER2_PORT))
  105. #define IS_ICACHE_REGION_OUTPUT_BURST_TYPE(__OUTPUTBURSTTYPE_) (((__OUTPUTBURSTTYPE_) == ICACHE_OUTPUT_BURST_WRAP) || \
  106. ((__OUTPUTBURSTTYPE_) == ICACHE_OUTPUT_BURST_INCR))
  107. /**
  108. * @}
  109. */
  110. /* Private variables ---------------------------------------------------------*/
  111. /* Private function prototypes -----------------------------------------------*/
  112. /* Exported functions --------------------------------------------------------*/
  113. /** @defgroup ICACHE_Exported_Functions ICACHE Exported Functions
  114. * @{
  115. */
  116. /** @defgroup ICACHE_Exported_Functions_Group1 Initialization and control functions
  117. * @brief Initialization and control functions
  118. *
  119. @verbatim
  120. ==============================================================================
  121. ##### Initialization and control functions #####
  122. ==============================================================================
  123. [..]
  124. This section provides functions allowing to initialize and control the
  125. Instruction Cache (mode, invalidate procedure, performance counters).
  126. @endverbatim
  127. * @{
  128. */
  129. /**
  130. * @brief Configure the Instruction Cache cache associativity mode selection.
  131. * @param AssociativityMode Associativity mode selection
  132. * This parameter can be one of the following values:
  133. * @arg ICACHE_1WAY 1-way cache (direct mapped cache)
  134. * @arg ICACHE_2WAYS 2-ways set associative cache (default)
  135. * @retval HAL status (HAL_OK/HAL_ERROR)
  136. */
  137. HAL_StatusTypeDef HAL_ICACHE_ConfigAssociativityMode(uint32_t AssociativityMode)
  138. {
  139. HAL_StatusTypeDef status = HAL_OK;
  140. /* Check the parameters */
  141. assert_param(IS_ICACHE_ASSOCIATIVITY_MODE(AssociativityMode));
  142. /* Check cache is not enabled */
  143. if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
  144. {
  145. status = HAL_ERROR;
  146. }
  147. else
  148. {
  149. MODIFY_REG(ICACHE->CR, ICACHE_CR_WAYSEL, AssociativityMode);
  150. }
  151. return status;
  152. }
  153. /**
  154. * @brief DeInitialize the Instruction Cache.
  155. * @retval HAL status (HAL_OK/HAL_TIMEOUT)
  156. */
  157. HAL_StatusTypeDef HAL_ICACHE_DeInit(void)
  158. {
  159. HAL_StatusTypeDef status;
  160. /* Disable cache with reset value for 2-ways set associative mode */
  161. WRITE_REG(ICACHE->CR, ICACHE_CR_WAYSEL);
  162. /* Stop monitor and reset monitor values */
  163. (void)HAL_ICACHE_Monitor_Stop(ICACHE_MONITOR_HIT_MISS);
  164. (void)HAL_ICACHE_Monitor_Reset(ICACHE_MONITOR_HIT_MISS);
  165. /* No remapped regions */
  166. (void)HAL_ICACHE_DisableRemapRegion(ICACHE_REGION_0);
  167. (void)HAL_ICACHE_DisableRemapRegion(ICACHE_REGION_1);
  168. (void)HAL_ICACHE_DisableRemapRegion(ICACHE_REGION_2);
  169. (void)HAL_ICACHE_DisableRemapRegion(ICACHE_REGION_3);
  170. /* Wait for end of invalidate cache procedure */
  171. status = HAL_ICACHE_WaitForInvalidateComplete();
  172. /* Clear any pending flags */
  173. WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF | ICACHE_FCR_CERRF);
  174. return status;
  175. }
  176. /**
  177. * @brief Enable the Instruction Cache.
  178. * @note This function always returns HAL_OK even if there is any ongoing
  179. * cache operation. The Instruction Cache is bypassed until the
  180. * cache operation completes.
  181. * @retval HAL status (HAL_OK)
  182. */
  183. HAL_StatusTypeDef HAL_ICACHE_Enable(void)
  184. {
  185. SET_BIT(ICACHE->CR, ICACHE_CR_EN);
  186. return HAL_OK;
  187. }
  188. /**
  189. * @brief Disable the Instruction Cache.
  190. * @note This function waits for the cache being disabled but
  191. * not for the end of the automatic cache invalidation procedure.
  192. * @retval HAL status (HAL_OK/HAL_TIMEOUT)
  193. */
  194. HAL_StatusTypeDef HAL_ICACHE_Disable(void)
  195. {
  196. HAL_StatusTypeDef status = HAL_OK;
  197. uint32_t tickstart;
  198. /* Make sure BSYENDF is reset before to disable the instruction cache */
  199. /* as it automatically starts a cache invalidation procedure */
  200. WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
  201. CLEAR_BIT(ICACHE->CR, ICACHE_CR_EN);
  202. /* Get tick */
  203. tickstart = HAL_GetTick();
  204. /* Wait for instruction cache being disabled */
  205. while (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
  206. {
  207. if ((HAL_GetTick() - tickstart) > ICACHE_DISABLE_TIMEOUT_VALUE)
  208. {
  209. /* New check to avoid false timeout detection in case of preemption */
  210. if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
  211. {
  212. status = HAL_TIMEOUT;
  213. break;
  214. }
  215. }
  216. }
  217. return status;
  218. }
  219. /**
  220. * @brief Check whether the Instruction Cache is enabled or not.
  221. * @retval Status (0: disabled, 1: enabled)
  222. */
  223. uint32_t HAL_ICACHE_IsEnabled(void)
  224. {
  225. return ((READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U) ? 1UL : 0UL);
  226. }
  227. /**
  228. * @brief Invalidate the Instruction Cache.
  229. * @note This function waits for the end of cache invalidation procedure
  230. * and clears the associated BSYENDF flag.
  231. * @retval HAL status (HAL_OK/HAL_ERROR/HAL_TIMEOUT)
  232. */
  233. HAL_StatusTypeDef HAL_ICACHE_Invalidate(void)
  234. {
  235. HAL_StatusTypeDef status;
  236. /* Check no ongoing operation */
  237. if (READ_BIT(ICACHE->SR, ICACHE_SR_BUSYF) != 0U)
  238. {
  239. status = HAL_ERROR;
  240. }
  241. else
  242. {
  243. /* Make sure BSYENDF is reset before to start cache invalidation */
  244. WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
  245. /* Launch cache invalidation */
  246. SET_BIT(ICACHE->CR, ICACHE_CR_CACHEINV);
  247. status = HAL_ICACHE_WaitForInvalidateComplete();
  248. }
  249. return status;
  250. }
  251. /**
  252. * @brief Invalidate the Instruction Cache with interrupt.
  253. * @note This function launches cache invalidation and returns.
  254. * User application shall resort to interrupt generation to check
  255. * the end of the cache invalidation with the BSYENDF flag and the
  256. * HAL_ICACHE_InvalidateCompleteCallback() callback.
  257. * @retval HAL status (HAL_OK/HAL_ERROR)
  258. */
  259. HAL_StatusTypeDef HAL_ICACHE_Invalidate_IT(void)
  260. {
  261. HAL_StatusTypeDef status = HAL_OK;
  262. /* Check no ongoing operation */
  263. if (READ_BIT(ICACHE->SR, ICACHE_SR_BUSYF) != 0U)
  264. {
  265. status = HAL_ERROR;
  266. }
  267. else
  268. {
  269. /* Make sure BSYENDF is reset before to start cache invalidation */
  270. WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
  271. /* Enable end of cache invalidation interrupt */
  272. SET_BIT(ICACHE->IER, ICACHE_IER_BSYENDIE);
  273. /* Launch cache invalidation */
  274. SET_BIT(ICACHE->CR, ICACHE_CR_CACHEINV);
  275. }
  276. return status;
  277. }
  278. /**
  279. * @brief Wait for the end of the Instruction Cache invalidate procedure.
  280. * @note This function checks and clears the BSYENDF flag when set.
  281. * @retval HAL status (HAL_OK/HAL_TIMEOUT)
  282. */
  283. HAL_StatusTypeDef HAL_ICACHE_WaitForInvalidateComplete(void)
  284. {
  285. HAL_StatusTypeDef status = HAL_OK;
  286. uint32_t tickstart;
  287. /* Check if ongoing invalidation operation */
  288. if (READ_BIT(ICACHE->SR, ICACHE_SR_BUSYF) != 0U)
  289. {
  290. /* Get tick */
  291. tickstart = HAL_GetTick();
  292. /* Wait for end of cache invalidation */
  293. while (READ_BIT(ICACHE->SR, ICACHE_SR_BSYENDF) == 0U)
  294. {
  295. if ((HAL_GetTick() - tickstart) > ICACHE_INVALIDATE_TIMEOUT_VALUE)
  296. {
  297. /* New check to avoid false timeout detection in case of preemption */
  298. if (READ_BIT(ICACHE->SR, ICACHE_SR_BSYENDF) == 0U)
  299. {
  300. status = HAL_TIMEOUT;
  301. break;
  302. }
  303. }
  304. }
  305. }
  306. /* Clear BSYENDF */
  307. WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
  308. return status;
  309. }
  310. /**
  311. * @brief Start the Instruction Cache performance monitoring.
  312. * @param MonitorType Monitoring type
  313. * This parameter can be one of the following values:
  314. * @arg ICACHE_MONITOR_HIT_MISS Hit & Miss monitoring
  315. * @arg ICACHE_MONITOR_HIT Hit monitoring
  316. * @arg ICACHE_MONITOR_MISS Miss monitoring
  317. * @retval HAL status (HAL_OK)
  318. */
  319. HAL_StatusTypeDef HAL_ICACHE_Monitor_Start(uint32_t MonitorType)
  320. {
  321. /* Check the parameters */
  322. assert_param(IS_ICACHE_MONITOR_TYPE(MonitorType));
  323. SET_BIT(ICACHE->CR, MonitorType);
  324. return HAL_OK;
  325. }
  326. /**
  327. * @brief Stop the Instruction Cache performance monitoring.
  328. * @note Stopping the monitoring does not reset the values.
  329. * @param MonitorType Monitoring type
  330. * This parameter can be one of the following values:
  331. * @arg ICACHE_MONITOR_HIT_MISS Hit & Miss monitoring
  332. * @arg ICACHE_MONITOR_HIT Hit monitoring
  333. * @arg ICACHE_MONITOR_MISS Miss monitoring
  334. * @retval HAL status (HAL_OK)
  335. */
  336. HAL_StatusTypeDef HAL_ICACHE_Monitor_Stop(uint32_t MonitorType)
  337. {
  338. /* Check the parameters */
  339. assert_param(IS_ICACHE_MONITOR_TYPE(MonitorType));
  340. CLEAR_BIT(ICACHE->CR, MonitorType);
  341. return HAL_OK;
  342. }
  343. /**
  344. * @brief Reset the Instruction Cache performance monitoring values.
  345. * @param MonitorType Monitoring type
  346. * This parameter can be one of the following values:
  347. * @arg ICACHE_MONITOR_HIT_MISS Hit & Miss monitoring
  348. * @arg ICACHE_MONITOR_HIT Hit monitoring
  349. * @arg ICACHE_MONITOR_MISS Miss monitoring
  350. * @retval HAL status (HAL_OK)
  351. */
  352. HAL_StatusTypeDef HAL_ICACHE_Monitor_Reset(uint32_t MonitorType)
  353. {
  354. /* Check the parameters */
  355. assert_param(IS_ICACHE_MONITOR_TYPE(MonitorType));
  356. /* Force/Release reset */
  357. SET_BIT(ICACHE->CR, (MonitorType << 2U));
  358. CLEAR_BIT(ICACHE->CR, (MonitorType << 2U));
  359. return HAL_OK;
  360. }
  361. /**
  362. * @brief Get the Instruction Cache performance Hit monitoring value.
  363. * @note Upon reaching the 32-bit maximum value, monitor does not wrap.
  364. * @retval Hit monitoring value
  365. */
  366. uint32_t HAL_ICACHE_Monitor_GetHitValue(void)
  367. {
  368. return (ICACHE->HMONR);
  369. }
  370. /**
  371. * @brief Get the Instruction Cache performance Miss monitoring value.
  372. * @note Upon reaching the 32-bit maximum value, monitor does not wrap.
  373. * @retval Miss monitoring value
  374. */
  375. uint32_t HAL_ICACHE_Monitor_GetMissValue(void)
  376. {
  377. return (ICACHE->MMONR);
  378. }
  379. /**
  380. * @}
  381. */
  382. /** @defgroup ICACHE_Exported_Functions_Group2 IRQ and callback functions
  383. * @brief IRQ and callback functions
  384. *
  385. @verbatim
  386. ==============================================================================
  387. ##### IRQ and callback functions #####
  388. ==============================================================================
  389. [..]
  390. This section provides functions allowing to handle ICACHE global interrupt
  391. and the associated callback functions.
  392. @endverbatim
  393. * @{
  394. */
  395. /**
  396. * @brief Handle the Instruction Cache interrupt request.
  397. * @note This function should be called under the ICACHE_IRQHandler().
  398. * @note This function respectively disables the interrupt and clears the
  399. * flag of any pending flag before calling the associated user callback.
  400. * @retval None
  401. */
  402. void HAL_ICACHE_IRQHandler(void)
  403. {
  404. /* Get current interrupt flags and interrupt sources value */
  405. uint32_t itflags = READ_REG(ICACHE->SR);
  406. uint32_t itsources = READ_REG(ICACHE->IER);
  407. /* Check Instruction cache Error interrupt flag */
  408. if (((itflags & itsources) & ICACHE_FLAG_ERROR) != 0U)
  409. {
  410. /* Disable error interrupt */
  411. CLEAR_BIT(ICACHE->IER, ICACHE_IER_ERRIE);
  412. /* Clear ERR pending flag */
  413. WRITE_REG(ICACHE->FCR, ICACHE_FCR_CERRF);
  414. /* Instruction cache error interrupt user callback */
  415. HAL_ICACHE_ErrorCallback();
  416. }
  417. /* Check Instruction cache BusyEnd interrupt flag */
  418. if (((itflags & itsources) & ICACHE_FLAG_BUSYEND) != 0U)
  419. {
  420. /* Disable end of cache invalidation interrupt */
  421. CLEAR_BIT(ICACHE->IER, ICACHE_IER_BSYENDIE);
  422. /* Clear BSYENDF pending flag */
  423. WRITE_REG(ICACHE->FCR, ICACHE_FCR_CBSYENDF);
  424. /* Instruction cache busyend interrupt user callback */
  425. HAL_ICACHE_InvalidateCompleteCallback();
  426. }
  427. }
  428. /**
  429. * @brief Cache invalidation complete callback.
  430. */
  431. __weak void HAL_ICACHE_InvalidateCompleteCallback(void)
  432. {
  433. /* NOTE : This function should not be modified, when the callback is needed,
  434. the HAL_ICACHE_InvalidateCompleteCallback() should be implemented in the user file
  435. */
  436. }
  437. /**
  438. * @brief Error callback.
  439. */
  440. __weak void HAL_ICACHE_ErrorCallback(void)
  441. {
  442. /* NOTE : This function should not be modified, when the callback is needed,
  443. the HAL_ICACHE_ErrorCallback() should be implemented in the user file
  444. */
  445. }
  446. /**
  447. * @}
  448. */
  449. /** @defgroup ICACHE_Exported_Functions_Group3 Memory remapped regions functions
  450. * @brief Memory remapped regions functions
  451. *
  452. @verbatim
  453. ==============================================================================
  454. ##### Memory remapped regions functions #####
  455. ==============================================================================
  456. [..]
  457. This section provides functions allowing to manage the remapping of
  458. external memories to internal Code for execution.
  459. @endverbatim
  460. * @{
  461. */
  462. /**
  463. * @brief Configure and enable a region for memory remapping.
  464. * @note The Instruction Cache and the region must be disabled.
  465. * @param Region Region number
  466. This parameter can be a value of @arg @ref ICACHE_Region
  467. * @param pRegionConfig Pointer to structure of ICACHE region configuration parameters
  468. * @retval HAL status (HAL_OK/HAL_ERROR)
  469. */
  470. HAL_StatusTypeDef HAL_ICACHE_EnableRemapRegion(uint32_t Region, const ICACHE_RegionConfigTypeDef *const pRegionConfig)
  471. {
  472. HAL_StatusTypeDef status = HAL_OK;
  473. __IO uint32_t *p_reg;
  474. uint32_t value;
  475. /* Check the parameters */
  476. assert_param(IS_ICACHE_REGION_NUMBER(Region));
  477. assert_param(IS_ICACHE_REGION_SIZE(pRegionConfig->Size));
  478. assert_param(IS_ICACHE_REGION_TRAFFIC_ROUTE(pRegionConfig->TrafficRoute));
  479. assert_param(IS_ICACHE_REGION_OUTPUT_BURST_TYPE(pRegionConfig->OutputBurstType));
  480. /* Check cache is not enabled */
  481. if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
  482. {
  483. status = HAL_ERROR;
  484. }
  485. else
  486. {
  487. /* Get region control register address */
  488. p_reg = &(ICACHE->CRR0) + (1U * Region);
  489. /* Check region is not already enabled */
  490. if ((*p_reg & ICACHE_CRRx_REN) != 0U)
  491. {
  492. status = HAL_ERROR;
  493. }
  494. else
  495. {
  496. /* Region 2MB: BaseAddress size 8 bits, RemapAddress size 11 bits */
  497. /* Region 4MB: BaseAddress size 7 bits, RemapAddress size 10 bits */
  498. /* Region 8MB: BaseAddress size 6 bits, RemapAddress size 9 bits */
  499. /* Region 16MB: BaseAddress size 5 bits, RemapAddress size 8 bits */
  500. /* Region 32MB: BaseAddress size 4 bits, RemapAddress size 7 bits */
  501. /* Region 64MB: BaseAddress size 3 bits, RemapAddress size 6 bits */
  502. /* Region 128MB: BaseAddress size 2 bits, RemapAddress size 5 bits */
  503. value = ((pRegionConfig->BaseAddress & 0x1FFFFFFFU) >> 21U) & \
  504. (0xFFU & ~(pRegionConfig->Size - 1U));
  505. value |= ((pRegionConfig->RemapAddress >> 5U) & \
  506. ((uint32_t)(0x7FFU & ~(pRegionConfig->Size - 1U)) << ICACHE_CRRx_REMAPADDR_Pos));
  507. value |= (pRegionConfig->Size << ICACHE_CRRx_RSIZE_Pos) | pRegionConfig->TrafficRoute | \
  508. pRegionConfig->OutputBurstType;
  509. *p_reg = (value | ICACHE_CRRx_REN);
  510. }
  511. }
  512. return status;
  513. }
  514. /**
  515. * @brief Disable the memory remapping for a predefined region.
  516. * @param Region Region number
  517. This parameter can be a value of @arg @ref ICACHE_Region
  518. * @retval HAL status (HAL_OK/HAL_ERROR)
  519. */
  520. HAL_StatusTypeDef HAL_ICACHE_DisableRemapRegion(uint32_t Region)
  521. {
  522. HAL_StatusTypeDef status = HAL_OK;
  523. __IO uint32_t *p_reg;
  524. /* Check the parameters */
  525. assert_param(IS_ICACHE_REGION_NUMBER(Region));
  526. /* Check cache is not enabled */
  527. if (READ_BIT(ICACHE->CR, ICACHE_CR_EN) != 0U)
  528. {
  529. status = HAL_ERROR;
  530. }
  531. else
  532. {
  533. /* Get region control register address */
  534. p_reg = &(ICACHE->CRR0) + (1U * Region);
  535. *p_reg &= ~ICACHE_CRRx_REN;
  536. }
  537. return status;
  538. }
  539. /**
  540. * @}
  541. */
  542. /**
  543. * @}
  544. */
  545. #endif /* HAL_ICACHE_MODULE_ENABLED */
  546. /**
  547. * @}
  548. */
  549. /**
  550. * @}
  551. */