Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

1194 Zeilen
37 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_nor.c
  4. * @author MCD Application Team
  5. * @brief NOR HAL module driver.
  6. * This file provides a generic firmware to drive NOR memories mounted
  7. * as external device.
  8. *
  9. @verbatim
  10. ==============================================================================
  11. ##### How to use this driver #####
  12. ==============================================================================
  13. [..]
  14. This driver is a generic layered driver which contains a set of APIs used to
  15. control NOR flash memories. It uses the FMC/FSMC layer functions to interface
  16. with NOR devices. This driver is used as follows:
  17. (+) NOR flash memory configuration sequence using the function HAL_NOR_Init()
  18. with control and timing parameters for both normal and extended mode.
  19. (+) Read NOR flash memory manufacturer code and device IDs using the function
  20. HAL_NOR_Read_ID(). The read information is stored in the NOR_ID_TypeDef
  21. structure declared by the function caller.
  22. (+) Access NOR flash memory by read/write data unit operations using the functions
  23. HAL_NOR_Read(), HAL_NOR_Program().
  24. (+) Perform NOR flash erase block/chip operations using the functions
  25. HAL_NOR_Erase_Block() and HAL_NOR_Erase_Chip().
  26. (+) Read the NOR flash CFI (common flash interface) IDs using the function
  27. HAL_NOR_Read_CFI(). The read information is stored in the NOR_CFI_TypeDef
  28. structure declared by the function caller.
  29. (+) You can also control the NOR device by calling the control APIs HAL_NOR_WriteOperation_Enable()/
  30. HAL_NOR_WriteOperation_Disable() to respectively enable/disable the NOR write operation
  31. (+) You can monitor the NOR device HAL state by calling the function
  32. HAL_NOR_GetState()
  33. [..]
  34. (@) This driver is a set of generic APIs which handle standard NOR flash operations.
  35. If a NOR flash device contains different operations and/or implementations,
  36. it should be implemented separately.
  37. *** NOR HAL driver macros list ***
  38. =============================================
  39. [..]
  40. Below the list of most used macros in NOR HAL driver.
  41. (+) NOR_WRITE : NOR memory write data to specified address
  42. *** Callback registration ***
  43. =============================================
  44. [..]
  45. The compilation define USE_HAL_NOR_REGISTER_CALLBACKS when set to 1
  46. allows the user to configure dynamically the driver callbacks.
  47. Use Functions @ref HAL_NOR_RegisterCallback() to register a user callback,
  48. it allows to register following callbacks:
  49. (+) MspInitCallback : NOR MspInit.
  50. (+) MspDeInitCallback : NOR MspDeInit.
  51. This function takes as parameters the HAL peripheral handle, the Callback ID
  52. and a pointer to the user callback function.
  53. Use function @ref HAL_NOR_UnRegisterCallback() to reset a callback to the default
  54. weak (surcharged) function. It allows to reset following callbacks:
  55. (+) MspInitCallback : NOR MspInit.
  56. (+) MspDeInitCallback : NOR MspDeInit.
  57. This function) takes as parameters the HAL peripheral handle and the Callback ID.
  58. By default, after the @ref HAL_NOR_Init and if the state is HAL_NOR_STATE_RESET
  59. all callbacks are reset to the corresponding legacy weak (surcharged) functions.
  60. Exception done for MspInit and MspDeInit callbacks that are respectively
  61. reset to the legacy weak (surcharged) functions in the @ref HAL_NOR_Init
  62. and @ref HAL_NOR_DeInit only when these callbacks are null (not registered beforehand).
  63. If not, MspInit or MspDeInit are not null, the @ref HAL_NOR_Init and @ref HAL_NOR_DeInit
  64. keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
  65. Callbacks can be registered/unregistered in READY state only.
  66. Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
  67. in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
  68. during the Init/DeInit.
  69. In that case first register the MspInit/MspDeInit user callbacks
  70. using @ref HAL_NOR_RegisterCallback before calling @ref HAL_NOR_DeInit
  71. or @ref HAL_NOR_Init function.
  72. When The compilation define USE_HAL_NOR_REGISTER_CALLBACKS is set to 0 or
  73. not defined, the callback registering feature is not available
  74. and weak (surcharged) callbacks are used.
  75. @endverbatim
  76. ******************************************************************************
  77. * @attention
  78. *
  79. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  80. * All rights reserved.</center></h2>
  81. *
  82. * This software component is licensed by ST under BSD 3-Clause license,
  83. * the "License"; You may not use this file except in compliance with the
  84. * License. You may obtain a copy of the License at:
  85. * opensource.org/licenses/BSD-3-Clause
  86. *
  87. ******************************************************************************
  88. */
  89. /* Includes ------------------------------------------------------------------*/
  90. #include "stm32f4xx_hal.h"
  91. /** @addtogroup STM32F4xx_HAL_Driver
  92. * @{
  93. */
  94. /** @defgroup NOR NOR
  95. * @brief NOR driver modules
  96. * @{
  97. */
  98. #ifdef HAL_NOR_MODULE_ENABLED
  99. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  100. defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  101. defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) ||\
  102. defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
  103. /* Private typedef -----------------------------------------------------------*/
  104. /* Private define ------------------------------------------------------------*/
  105. /** @defgroup NOR_Private_Defines NOR Private Defines
  106. * @{
  107. */
  108. /* Constants to define address to set to write a command */
  109. #define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555
  110. #define NOR_CMD_ADDRESS_FIRST_CFI (uint16_t)0x0055
  111. #define NOR_CMD_ADDRESS_SECOND (uint16_t)0x02AA
  112. #define NOR_CMD_ADDRESS_THIRD (uint16_t)0x0555
  113. #define NOR_CMD_ADDRESS_FOURTH (uint16_t)0x0555
  114. #define NOR_CMD_ADDRESS_FIFTH (uint16_t)0x02AA
  115. #define NOR_CMD_ADDRESS_SIXTH (uint16_t)0x0555
  116. /* Constants to define data to program a command */
  117. #define NOR_CMD_DATA_READ_RESET (uint16_t)0x00F0
  118. #define NOR_CMD_DATA_FIRST (uint16_t)0x00AA
  119. #define NOR_CMD_DATA_SECOND (uint16_t)0x0055
  120. #define NOR_CMD_DATA_AUTO_SELECT (uint16_t)0x0090
  121. #define NOR_CMD_DATA_PROGRAM (uint16_t)0x00A0
  122. #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD (uint16_t)0x0080
  123. #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH (uint16_t)0x00AA
  124. #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH (uint16_t)0x0055
  125. #define NOR_CMD_DATA_CHIP_ERASE (uint16_t)0x0010
  126. #define NOR_CMD_DATA_CFI (uint16_t)0x0098
  127. #define NOR_CMD_DATA_BUFFER_AND_PROG (uint8_t)0x25
  128. #define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM (uint8_t)0x29
  129. #define NOR_CMD_DATA_BLOCK_ERASE (uint8_t)0x30
  130. /* Mask on NOR STATUS REGISTER */
  131. #define NOR_MASK_STATUS_DQ5 (uint16_t)0x0020
  132. #define NOR_MASK_STATUS_DQ6 (uint16_t)0x0040
  133. /**
  134. * @}
  135. */
  136. /* Private macro -------------------------------------------------------------*/
  137. /* Private variables ---------------------------------------------------------*/
  138. /** @defgroup NOR_Private_Variables NOR Private Variables
  139. * @{
  140. */
  141. static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B;
  142. /**
  143. * @}
  144. */
  145. /* Private functions ---------------------------------------------------------*/
  146. /* Exported functions --------------------------------------------------------*/
  147. /** @defgroup NOR_Exported_Functions NOR Exported Functions
  148. * @{
  149. */
  150. /** @defgroup NOR_Exported_Functions_Group1 Initialization and de-initialization functions
  151. * @brief Initialization and Configuration functions
  152. *
  153. @verbatim
  154. ==============================================================================
  155. ##### NOR Initialization and de_initialization functions #####
  156. ==============================================================================
  157. [..]
  158. This section provides functions allowing to initialize/de-initialize
  159. the NOR memory
  160. @endverbatim
  161. * @{
  162. */
  163. /**
  164. * @brief Perform the NOR memory Initialization sequence
  165. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  166. * the configuration information for NOR module.
  167. * @param Timing pointer to NOR control timing structure
  168. * @param ExtTiming pointer to NOR extended mode timing structure
  169. * @retval HAL status
  170. */
  171. HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
  172. {
  173. /* Check the NOR handle parameter */
  174. if(hnor == NULL)
  175. {
  176. return HAL_ERROR;
  177. }
  178. if(hnor->State == HAL_NOR_STATE_RESET)
  179. {
  180. /* Allocate lock resource and initialize it */
  181. hnor->Lock = HAL_UNLOCKED;
  182. #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
  183. if(hnor->MspInitCallback == NULL)
  184. {
  185. hnor->MspInitCallback = HAL_NOR_MspInit;
  186. }
  187. /* Init the low level hardware */
  188. hnor->MspInitCallback(hnor);
  189. #else
  190. /* Initialize the low level hardware (MSP) */
  191. HAL_NOR_MspInit(hnor);
  192. #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */
  193. }
  194. /* Initialize NOR control Interface */
  195. FMC_NORSRAM_Init(hnor->Instance, &(hnor->Init));
  196. /* Initialize NOR timing Interface */
  197. FMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank);
  198. /* Initialize NOR extended mode timing Interface */
  199. FMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming, hnor->Init.NSBank, hnor->Init.ExtendedMode);
  200. /* Enable the NORSRAM device */
  201. __FMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank);
  202. /* Initialize NOR Memory Data Width*/
  203. if (hnor->Init.MemoryDataWidth == FMC_NORSRAM_MEM_BUS_WIDTH_8)
  204. {
  205. uwNORMemoryDataWidth = NOR_MEMORY_8B;
  206. }
  207. else
  208. {
  209. uwNORMemoryDataWidth = NOR_MEMORY_16B;
  210. }
  211. /* Check the NOR controller state */
  212. hnor->State = HAL_NOR_STATE_READY;
  213. return HAL_OK;
  214. }
  215. /**
  216. * @brief Perform NOR memory De-Initialization sequence
  217. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  218. * the configuration information for NOR module.
  219. * @retval HAL status
  220. */
  221. HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor)
  222. {
  223. #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
  224. if(hnor->MspDeInitCallback == NULL)
  225. {
  226. hnor->MspDeInitCallback = HAL_NOR_MspDeInit;
  227. }
  228. /* DeInit the low level hardware */
  229. hnor->MspDeInitCallback(hnor);
  230. #else
  231. /* De-Initialize the low level hardware (MSP) */
  232. HAL_NOR_MspDeInit(hnor);
  233. #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */
  234. /* Configure the NOR registers with their reset values */
  235. FMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank);
  236. /* Update the NOR controller state */
  237. hnor->State = HAL_NOR_STATE_RESET;
  238. /* Release Lock */
  239. __HAL_UNLOCK(hnor);
  240. return HAL_OK;
  241. }
  242. /**
  243. * @brief NOR MSP Init
  244. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  245. * the configuration information for NOR module.
  246. * @retval None
  247. */
  248. __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor)
  249. {
  250. /* Prevent unused argument(s) compilation warning */
  251. UNUSED(hnor);
  252. /* NOTE : This function Should not be modified, when the callback is needed,
  253. the HAL_NOR_MspInit could be implemented in the user file
  254. */
  255. }
  256. /**
  257. * @brief NOR MSP DeInit
  258. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  259. * the configuration information for NOR module.
  260. * @retval None
  261. */
  262. __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor)
  263. {
  264. /* Prevent unused argument(s) compilation warning */
  265. UNUSED(hnor);
  266. /* NOTE : This function Should not be modified, when the callback is needed,
  267. the HAL_NOR_MspDeInit could be implemented in the user file
  268. */
  269. }
  270. /**
  271. * @brief NOR MSP Wait for Ready/Busy signal
  272. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  273. * the configuration information for NOR module.
  274. * @param Timeout Maximum timeout value
  275. * @retval None
  276. */
  277. __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
  278. {
  279. /* Prevent unused argument(s) compilation warning */
  280. UNUSED(hnor);
  281. UNUSED(Timeout);
  282. /* NOTE : This function Should not be modified, when the callback is needed,
  283. the HAL_NOR_MspWait could be implemented in the user file
  284. */
  285. }
  286. /**
  287. * @}
  288. */
  289. /** @defgroup NOR_Exported_Functions_Group2 Input and Output functions
  290. * @brief Input Output and memory control functions
  291. *
  292. @verbatim
  293. ==============================================================================
  294. ##### NOR Input and Output functions #####
  295. ==============================================================================
  296. [..]
  297. This section provides functions allowing to use and control the NOR memory
  298. @endverbatim
  299. * @{
  300. */
  301. /**
  302. * @brief Read NOR flash IDs
  303. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  304. * the configuration information for NOR module.
  305. * @param pNOR_ID pointer to NOR ID structure
  306. * @retval HAL status
  307. */
  308. HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID)
  309. {
  310. uint32_t deviceaddress = 0U;
  311. /* Process Locked */
  312. __HAL_LOCK(hnor);
  313. /* Check the NOR controller state */
  314. if(hnor->State == HAL_NOR_STATE_BUSY)
  315. {
  316. return HAL_BUSY;
  317. }
  318. /* Select the NOR device address */
  319. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  320. {
  321. deviceaddress = NOR_MEMORY_ADRESS1;
  322. }
  323. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  324. {
  325. deviceaddress = NOR_MEMORY_ADRESS2;
  326. }
  327. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  328. {
  329. deviceaddress = NOR_MEMORY_ADRESS3;
  330. }
  331. else /* FMC_NORSRAM_BANK4 */
  332. {
  333. deviceaddress = NOR_MEMORY_ADRESS4;
  334. }
  335. /* Update the NOR controller state */
  336. hnor->State = HAL_NOR_STATE_BUSY;
  337. /* Send read ID command */
  338. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  339. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  340. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_AUTO_SELECT);
  341. /* Read the NOR IDs */
  342. pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS);
  343. pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE1_ADDR);
  344. pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE2_ADDR);
  345. pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE3_ADDR);
  346. /* Check the NOR controller state */
  347. hnor->State = HAL_NOR_STATE_READY;
  348. /* Process unlocked */
  349. __HAL_UNLOCK(hnor);
  350. return HAL_OK;
  351. }
  352. /**
  353. * @brief Returns the NOR memory to Read mode.
  354. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  355. * the configuration information for NOR module.
  356. * @retval HAL status
  357. */
  358. HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor)
  359. {
  360. uint32_t deviceaddress = 0U;
  361. /* Process Locked */
  362. __HAL_LOCK(hnor);
  363. /* Check the NOR controller state */
  364. if(hnor->State == HAL_NOR_STATE_BUSY)
  365. {
  366. return HAL_BUSY;
  367. }
  368. /* Select the NOR device address */
  369. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  370. {
  371. deviceaddress = NOR_MEMORY_ADRESS1;
  372. }
  373. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  374. {
  375. deviceaddress = NOR_MEMORY_ADRESS2;
  376. }
  377. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  378. {
  379. deviceaddress = NOR_MEMORY_ADRESS3;
  380. }
  381. else /* FMC_NORSRAM_BANK4 */
  382. {
  383. deviceaddress = NOR_MEMORY_ADRESS4;
  384. }
  385. NOR_WRITE(deviceaddress, NOR_CMD_DATA_READ_RESET);
  386. /* Check the NOR controller state */
  387. hnor->State = HAL_NOR_STATE_READY;
  388. /* Process unlocked */
  389. __HAL_UNLOCK(hnor);
  390. return HAL_OK;
  391. }
  392. /**
  393. * @brief Read data from NOR memory
  394. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  395. * the configuration information for NOR module.
  396. * @param pAddress pointer to Device address
  397. * @param pData pointer to read data
  398. * @retval HAL status
  399. */
  400. HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
  401. {
  402. uint32_t deviceaddress = 0U;
  403. /* Process Locked */
  404. __HAL_LOCK(hnor);
  405. /* Check the NOR controller state */
  406. if(hnor->State == HAL_NOR_STATE_BUSY)
  407. {
  408. return HAL_BUSY;
  409. }
  410. /* Select the NOR device address */
  411. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  412. {
  413. deviceaddress = NOR_MEMORY_ADRESS1;
  414. }
  415. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  416. {
  417. deviceaddress = NOR_MEMORY_ADRESS2;
  418. }
  419. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  420. {
  421. deviceaddress = NOR_MEMORY_ADRESS3;
  422. }
  423. else /* FMC_NORSRAM_BANK4 */
  424. {
  425. deviceaddress = NOR_MEMORY_ADRESS4;
  426. }
  427. /* Update the NOR controller state */
  428. hnor->State = HAL_NOR_STATE_BUSY;
  429. /* Send read data command */
  430. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  431. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  432. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
  433. /* Read the data */
  434. *pData = *(__IO uint32_t *)(uint32_t)pAddress;
  435. /* Check the NOR controller state */
  436. hnor->State = HAL_NOR_STATE_READY;
  437. /* Process unlocked */
  438. __HAL_UNLOCK(hnor);
  439. return HAL_OK;
  440. }
  441. /**
  442. * @brief Program data to NOR memory
  443. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  444. * the configuration information for NOR module.
  445. * @param pAddress Device address
  446. * @param pData pointer to the data to write
  447. * @retval HAL status
  448. */
  449. HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
  450. {
  451. uint32_t deviceaddress = 0U;
  452. /* Process Locked */
  453. __HAL_LOCK(hnor);
  454. /* Check the NOR controller state */
  455. if(hnor->State == HAL_NOR_STATE_BUSY)
  456. {
  457. return HAL_BUSY;
  458. }
  459. /* Select the NOR device address */
  460. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  461. {
  462. deviceaddress = NOR_MEMORY_ADRESS1;
  463. }
  464. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  465. {
  466. deviceaddress = NOR_MEMORY_ADRESS2;
  467. }
  468. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  469. {
  470. deviceaddress = NOR_MEMORY_ADRESS3;
  471. }
  472. else /* FMC_NORSRAM_BANK4 */
  473. {
  474. deviceaddress = NOR_MEMORY_ADRESS4;
  475. }
  476. /* Update the NOR controller state */
  477. hnor->State = HAL_NOR_STATE_BUSY;
  478. /* Send program data command */
  479. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  480. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  481. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM);
  482. /* Write the data */
  483. NOR_WRITE(pAddress, *pData);
  484. /* Check the NOR controller state */
  485. hnor->State = HAL_NOR_STATE_READY;
  486. /* Process unlocked */
  487. __HAL_UNLOCK(hnor);
  488. return HAL_OK;
  489. }
  490. /**
  491. * @brief Reads a half-word buffer from the NOR memory.
  492. * @param hnor pointer to the NOR handle
  493. * @param uwAddress NOR memory internal address to read from.
  494. * @param pData pointer to the buffer that receives the data read from the
  495. * NOR memory.
  496. * @param uwBufferSize number of Half word to read.
  497. * @retval HAL status
  498. */
  499. HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
  500. {
  501. uint32_t deviceaddress = 0U;
  502. /* Process Locked */
  503. __HAL_LOCK(hnor);
  504. /* Check the NOR controller state */
  505. if(hnor->State == HAL_NOR_STATE_BUSY)
  506. {
  507. return HAL_BUSY;
  508. }
  509. /* Select the NOR device address */
  510. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  511. {
  512. deviceaddress = NOR_MEMORY_ADRESS1;
  513. }
  514. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  515. {
  516. deviceaddress = NOR_MEMORY_ADRESS2;
  517. }
  518. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  519. {
  520. deviceaddress = NOR_MEMORY_ADRESS3;
  521. }
  522. else /* FMC_NORSRAM_BANK4 */
  523. {
  524. deviceaddress = NOR_MEMORY_ADRESS4;
  525. }
  526. /* Update the NOR controller state */
  527. hnor->State = HAL_NOR_STATE_BUSY;
  528. /* Send read data command */
  529. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  530. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  531. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
  532. /* Read buffer */
  533. while( uwBufferSize > 0U)
  534. {
  535. *pData++ = *(__IO uint16_t *)uwAddress;
  536. uwAddress += 2U;
  537. uwBufferSize--;
  538. }
  539. /* Check the NOR controller state */
  540. hnor->State = HAL_NOR_STATE_READY;
  541. /* Process unlocked */
  542. __HAL_UNLOCK(hnor);
  543. return HAL_OK;
  544. }
  545. /**
  546. * @brief Writes a half-word buffer to the NOR memory. This function must be used
  547. only with S29GL128P NOR memory.
  548. * @param hnor pointer to the NOR handle
  549. * @param uwAddress NOR memory internal start write address
  550. * @param pData pointer to source data buffer.
  551. * @param uwBufferSize Size of the buffer to write
  552. * @retval HAL status
  553. */
  554. HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
  555. {
  556. uint16_t * p_currentaddress = (uint16_t *)NULL;
  557. uint16_t * p_endaddress = (uint16_t *)NULL;
  558. uint32_t lastloadedaddress = 0U, deviceaddress = 0U;
  559. /* Process Locked */
  560. __HAL_LOCK(hnor);
  561. /* Check the NOR controller state */
  562. if(hnor->State == HAL_NOR_STATE_BUSY)
  563. {
  564. return HAL_BUSY;
  565. }
  566. /* Select the NOR device address */
  567. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  568. {
  569. deviceaddress = NOR_MEMORY_ADRESS1;
  570. }
  571. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  572. {
  573. deviceaddress = NOR_MEMORY_ADRESS2;
  574. }
  575. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  576. {
  577. deviceaddress = NOR_MEMORY_ADRESS3;
  578. }
  579. else /* FMC_NORSRAM_BANK4 */
  580. {
  581. deviceaddress = NOR_MEMORY_ADRESS4;
  582. }
  583. /* Update the NOR controller state */
  584. hnor->State = HAL_NOR_STATE_BUSY;
  585. /* Initialize variables */
  586. p_currentaddress = (uint16_t*)((uint32_t)(uwAddress));
  587. p_endaddress = p_currentaddress + (uwBufferSize-1U);
  588. lastloadedaddress = (uint32_t)(uwAddress);
  589. /* Issue unlock command sequence */
  590. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  591. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  592. /* Write Buffer Load Command */
  593. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG);
  594. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, uwAddress), (uwBufferSize - 1U));
  595. /* Load Data into NOR Buffer */
  596. while(p_currentaddress <= p_endaddress)
  597. {
  598. /* Store last loaded address & data value (for polling) */
  599. lastloadedaddress = (uint32_t)p_currentaddress;
  600. NOR_WRITE(p_currentaddress, *pData++);
  601. p_currentaddress ++;
  602. }
  603. NOR_WRITE((uint32_t)(lastloadedaddress), NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM);
  604. /* Check the NOR controller state */
  605. hnor->State = HAL_NOR_STATE_READY;
  606. /* Process unlocked */
  607. __HAL_UNLOCK(hnor);
  608. return HAL_OK;
  609. }
  610. /**
  611. * @brief Erase the specified block of the NOR memory
  612. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  613. * the configuration information for NOR module.
  614. * @param BlockAddress Block to erase address
  615. * @param Address Device address
  616. * @retval HAL status
  617. */
  618. HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
  619. {
  620. uint32_t deviceaddress = 0U;
  621. /* Process Locked */
  622. __HAL_LOCK(hnor);
  623. /* Check the NOR controller state */
  624. if(hnor->State == HAL_NOR_STATE_BUSY)
  625. {
  626. return HAL_BUSY;
  627. }
  628. /* Select the NOR device address */
  629. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  630. {
  631. deviceaddress = NOR_MEMORY_ADRESS1;
  632. }
  633. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  634. {
  635. deviceaddress = NOR_MEMORY_ADRESS2;
  636. }
  637. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  638. {
  639. deviceaddress = NOR_MEMORY_ADRESS3;
  640. }
  641. else /* FMC_NORSRAM_BANK4 */
  642. {
  643. deviceaddress = NOR_MEMORY_ADRESS4;
  644. }
  645. /* Update the NOR controller state */
  646. hnor->State = HAL_NOR_STATE_BUSY;
  647. /* Send block erase command sequence */
  648. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  649. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  650. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
  651. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
  652. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
  653. NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE);
  654. /* Check the NOR memory status and update the controller state */
  655. hnor->State = HAL_NOR_STATE_READY;
  656. /* Process unlocked */
  657. __HAL_UNLOCK(hnor);
  658. return HAL_OK;
  659. }
  660. /**
  661. * @brief Erase the entire NOR chip.
  662. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  663. * the configuration information for NOR module.
  664. * @param Address Device address
  665. * @retval HAL status
  666. */
  667. HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
  668. {
  669. uint32_t deviceaddress = 0U;
  670. /* Prevent unused argument(s) compilation warning */
  671. UNUSED(Address);
  672. /* Process Locked */
  673. __HAL_LOCK(hnor);
  674. /* Check the NOR controller state */
  675. if(hnor->State == HAL_NOR_STATE_BUSY)
  676. {
  677. return HAL_BUSY;
  678. }
  679. /* Select the NOR device address */
  680. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  681. {
  682. deviceaddress = NOR_MEMORY_ADRESS1;
  683. }
  684. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  685. {
  686. deviceaddress = NOR_MEMORY_ADRESS2;
  687. }
  688. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  689. {
  690. deviceaddress = NOR_MEMORY_ADRESS3;
  691. }
  692. else /* FMC_NORSRAM_BANK4 */
  693. {
  694. deviceaddress = NOR_MEMORY_ADRESS4;
  695. }
  696. /* Update the NOR controller state */
  697. hnor->State = HAL_NOR_STATE_BUSY;
  698. /* Send NOR chip erase command sequence */
  699. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  700. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  701. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
  702. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
  703. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
  704. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH), NOR_CMD_DATA_CHIP_ERASE);
  705. /* Check the NOR memory status and update the controller state */
  706. hnor->State = HAL_NOR_STATE_READY;
  707. /* Process unlocked */
  708. __HAL_UNLOCK(hnor);
  709. return HAL_OK;
  710. }
  711. /**
  712. * @brief Read NOR flash CFI IDs
  713. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  714. * the configuration information for NOR module.
  715. * @param pNOR_CFI pointer to NOR CFI IDs structure
  716. * @retval HAL status
  717. */
  718. HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI)
  719. {
  720. uint32_t deviceaddress = 0U;
  721. /* Process Locked */
  722. __HAL_LOCK(hnor);
  723. /* Check the NOR controller state */
  724. if(hnor->State == HAL_NOR_STATE_BUSY)
  725. {
  726. return HAL_BUSY;
  727. }
  728. /* Select the NOR device address */
  729. if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
  730. {
  731. deviceaddress = NOR_MEMORY_ADRESS1;
  732. }
  733. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
  734. {
  735. deviceaddress = NOR_MEMORY_ADRESS2;
  736. }
  737. else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
  738. {
  739. deviceaddress = NOR_MEMORY_ADRESS3;
  740. }
  741. else /* FMC_NORSRAM_BANK4 */
  742. {
  743. deviceaddress = NOR_MEMORY_ADRESS4;
  744. }
  745. /* Update the NOR controller state */
  746. hnor->State = HAL_NOR_STATE_BUSY;
  747. /* Send read CFI query command */
  748. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
  749. /* read the NOR CFI information */
  750. pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS);
  751. pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS);
  752. pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS);
  753. pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS);
  754. /* Check the NOR controller state */
  755. hnor->State = HAL_NOR_STATE_READY;
  756. /* Process unlocked */
  757. __HAL_UNLOCK(hnor);
  758. return HAL_OK;
  759. }
  760. #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
  761. /**
  762. * @brief Register a User NOR Callback
  763. * To be used instead of the weak (surcharged) predefined callback
  764. * @param hnor : NOR handle
  765. * @param CallbackId : ID of the callback to be registered
  766. * This parameter can be one of the following values:
  767. * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID
  768. * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID
  769. * @param pCallback : pointer to the Callback function
  770. * @retval status
  771. */
  772. HAL_StatusTypeDef HAL_NOR_RegisterCallback (NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId, pNOR_CallbackTypeDef pCallback)
  773. {
  774. HAL_StatusTypeDef status = HAL_OK;
  775. HAL_NOR_StateTypeDef state;
  776. if(pCallback == NULL)
  777. {
  778. return HAL_ERROR;
  779. }
  780. /* Process locked */
  781. __HAL_LOCK(hnor);
  782. state = hnor->State;
  783. if((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED))
  784. {
  785. switch (CallbackId)
  786. {
  787. case HAL_NOR_MSP_INIT_CB_ID :
  788. hnor->MspInitCallback = pCallback;
  789. break;
  790. case HAL_NOR_MSP_DEINIT_CB_ID :
  791. hnor->MspDeInitCallback = pCallback;
  792. break;
  793. default :
  794. /* update return status */
  795. status = HAL_ERROR;
  796. break;
  797. }
  798. }
  799. else
  800. {
  801. /* update return status */
  802. status = HAL_ERROR;
  803. }
  804. /* Release Lock */
  805. __HAL_UNLOCK(hnor);
  806. return status;
  807. }
  808. /**
  809. * @brief Unregister a User NOR Callback
  810. * NOR Callback is redirected to the weak (surcharged) predefined callback
  811. * @param hnor : NOR handle
  812. * @param CallbackId : ID of the callback to be unregistered
  813. * This parameter can be one of the following values:
  814. * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID
  815. * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID
  816. * @retval status
  817. */
  818. HAL_StatusTypeDef HAL_NOR_UnRegisterCallback (NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId)
  819. {
  820. HAL_StatusTypeDef status = HAL_OK;
  821. HAL_NOR_StateTypeDef state;
  822. /* Process locked */
  823. __HAL_LOCK(hnor);
  824. state = hnor->State;
  825. if((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED))
  826. {
  827. switch (CallbackId)
  828. {
  829. case HAL_NOR_MSP_INIT_CB_ID :
  830. hnor->MspInitCallback = HAL_NOR_MspInit;
  831. break;
  832. case HAL_NOR_MSP_DEINIT_CB_ID :
  833. hnor->MspDeInitCallback = HAL_NOR_MspDeInit;
  834. break;
  835. default :
  836. /* update return status */
  837. status = HAL_ERROR;
  838. break;
  839. }
  840. }
  841. else
  842. {
  843. /* update return status */
  844. status = HAL_ERROR;
  845. }
  846. /* Release Lock */
  847. __HAL_UNLOCK(hnor);
  848. return status;
  849. }
  850. #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */
  851. /**
  852. * @}
  853. */
  854. /** @defgroup NOR_Exported_Functions_Group3 NOR Control functions
  855. * @brief management functions
  856. *
  857. @verbatim
  858. ==============================================================================
  859. ##### NOR Control functions #####
  860. ==============================================================================
  861. [..]
  862. This subsection provides a set of functions allowing to control dynamically
  863. the NOR interface.
  864. @endverbatim
  865. * @{
  866. */
  867. /**
  868. * @brief Enables dynamically NOR write operation.
  869. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  870. * the configuration information for NOR module.
  871. * @retval HAL status
  872. */
  873. HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor)
  874. {
  875. /* Process Locked */
  876. __HAL_LOCK(hnor);
  877. /* Enable write operation */
  878. FMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank);
  879. /* Update the NOR controller state */
  880. hnor->State = HAL_NOR_STATE_READY;
  881. /* Process unlocked */
  882. __HAL_UNLOCK(hnor);
  883. return HAL_OK;
  884. }
  885. /**
  886. * @brief Disables dynamically NOR write operation.
  887. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  888. * the configuration information for NOR module.
  889. * @retval HAL status
  890. */
  891. HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor)
  892. {
  893. /* Process Locked */
  894. __HAL_LOCK(hnor);
  895. /* Update the SRAM controller state */
  896. hnor->State = HAL_NOR_STATE_BUSY;
  897. /* Disable write operation */
  898. FMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank);
  899. /* Update the NOR controller state */
  900. hnor->State = HAL_NOR_STATE_PROTECTED;
  901. /* Process unlocked */
  902. __HAL_UNLOCK(hnor);
  903. return HAL_OK;
  904. }
  905. /**
  906. * @}
  907. */
  908. /** @defgroup NOR_Exported_Functions_Group4 NOR State functions
  909. * @brief Peripheral State functions
  910. *
  911. @verbatim
  912. ==============================================================================
  913. ##### NOR State functions #####
  914. ==============================================================================
  915. [..]
  916. This subsection permits to get in run-time the status of the NOR controller
  917. and the data flow.
  918. @endverbatim
  919. * @{
  920. */
  921. /**
  922. * @brief return the NOR controller state
  923. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  924. * the configuration information for NOR module.
  925. * @retval NOR controller state
  926. */
  927. HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor)
  928. {
  929. return hnor->State;
  930. }
  931. /**
  932. * @brief Returns the NOR operation status.
  933. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  934. * the configuration information for NOR module.
  935. * @param Address Device address
  936. * @param Timeout NOR programming Timeout
  937. * @retval NOR_Status: The returned value can be: HAL_NOR_STATUS_SUCCESS, HAL_NOR_STATUS_ERROR
  938. * or HAL_NOR_STATUS_TIMEOUT
  939. */
  940. HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
  941. {
  942. HAL_NOR_StatusTypeDef status = HAL_NOR_STATUS_ONGOING;
  943. uint16_t tmpSR1 = 0, tmpSR2 = 0;
  944. uint32_t tickstart = 0U;
  945. /* Poll on NOR memory Ready/Busy signal ------------------------------------*/
  946. HAL_NOR_MspWait(hnor, Timeout);
  947. /* Get the NOR memory operation status -------------------------------------*/
  948. /* Get tick */
  949. tickstart = HAL_GetTick();
  950. while((status != HAL_NOR_STATUS_SUCCESS ) && (status != HAL_NOR_STATUS_TIMEOUT))
  951. {
  952. /* Check for the Timeout */
  953. if(Timeout != HAL_MAX_DELAY)
  954. {
  955. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  956. {
  957. status = HAL_NOR_STATUS_TIMEOUT;
  958. }
  959. }
  960. /* Read NOR status register (DQ6 and DQ5) */
  961. tmpSR1 = *(__IO uint16_t *)Address;
  962. tmpSR2 = *(__IO uint16_t *)Address;
  963. /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
  964. if((tmpSR1 & NOR_MASK_STATUS_DQ6) == (tmpSR2 & NOR_MASK_STATUS_DQ6))
  965. {
  966. return HAL_NOR_STATUS_SUCCESS ;
  967. }
  968. if((tmpSR1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
  969. {
  970. status = HAL_NOR_STATUS_ONGOING;
  971. }
  972. tmpSR1 = *(__IO uint16_t *)Address;
  973. tmpSR2 = *(__IO uint16_t *)Address;
  974. /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
  975. if((tmpSR1 & NOR_MASK_STATUS_DQ6) == (tmpSR2 & NOR_MASK_STATUS_DQ6))
  976. {
  977. return HAL_NOR_STATUS_SUCCESS;
  978. }
  979. if((tmpSR1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
  980. {
  981. return HAL_NOR_STATUS_ERROR;
  982. }
  983. }
  984. /* Return the operation status */
  985. return status;
  986. }
  987. /**
  988. * @}
  989. */
  990. /**
  991. * @}
  992. */
  993. #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx ||\
  994. STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\
  995. STM32F479xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx ||\
  996. STM32F423xx */
  997. #endif /* HAL_NOR_MODULE_ENABLED */
  998. /**
  999. * @}
  1000. */
  1001. /**
  1002. * @}
  1003. */
  1004. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/