stm32f1xx_hal_nor.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_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. ******************************************************************************
  10. * @attention
  11. *
  12. * Copyright (c) 2016 STMicroelectronics.
  13. * All rights reserved.
  14. *
  15. * This software is licensed under terms that can be found in the LICENSE file
  16. * in the root directory of this software component.
  17. * If no LICENSE file comes with this software, it is provided AS-IS.
  18. *
  19. ******************************************************************************
  20. @verbatim
  21. ==============================================================================
  22. ##### How to use this driver #####
  23. ==============================================================================
  24. [..]
  25. This driver is a generic layered driver which contains a set of APIs used to
  26. control NOR flash memories. It uses the FSMC layer functions to interface
  27. with NOR devices. This driver is used as follows:
  28. (+) NOR flash memory configuration sequence using the function HAL_NOR_Init()
  29. with control and timing parameters for both normal and extended mode.
  30. (+) Read NOR flash memory manufacturer code and device IDs using the function
  31. HAL_NOR_Read_ID(). The read information is stored in the NOR_ID_TypeDef
  32. structure declared by the function caller.
  33. (+) Access NOR flash memory by read/write data unit operations using the functions
  34. HAL_NOR_Read(), HAL_NOR_Program().
  35. (+) Perform NOR flash erase block/chip operations using the functions
  36. HAL_NOR_Erase_Block() and HAL_NOR_Erase_Chip().
  37. (+) Read the NOR flash CFI (common flash interface) IDs using the function
  38. HAL_NOR_Read_CFI(). The read information is stored in the NOR_CFI_TypeDef
  39. structure declared by the function caller.
  40. (+) You can also control the NOR device by calling the control APIs HAL_NOR_WriteOperation_Enable()/
  41. HAL_NOR_WriteOperation_Disable() to respectively enable/disable the NOR write operation
  42. (+) You can monitor the NOR device HAL state by calling the function
  43. HAL_NOR_GetState()
  44. [..]
  45. (@) This driver is a set of generic APIs which handle standard NOR flash operations.
  46. If a NOR flash device contains different operations and/or implementations,
  47. it should be implemented separately.
  48. *** NOR HAL driver macros list ***
  49. =============================================
  50. [..]
  51. Below the list of most used macros in NOR HAL driver.
  52. (+) NOR_WRITE : NOR memory write data to specified address
  53. *** Callback registration ***
  54. =============================================
  55. [..]
  56. The compilation define USE_HAL_NOR_REGISTER_CALLBACKS when set to 1
  57. allows the user to configure dynamically the driver callbacks.
  58. Use Functions HAL_NOR_RegisterCallback() to register a user callback,
  59. it allows to register following callbacks:
  60. (+) MspInitCallback : NOR MspInit.
  61. (+) MspDeInitCallback : NOR MspDeInit.
  62. This function takes as parameters the HAL peripheral handle, the Callback ID
  63. and a pointer to the user callback function.
  64. Use function HAL_NOR_UnRegisterCallback() to reset a callback to the default
  65. weak (overridden) function. It allows to reset following callbacks:
  66. (+) MspInitCallback : NOR MspInit.
  67. (+) MspDeInitCallback : NOR MspDeInit.
  68. This function) takes as parameters the HAL peripheral handle and the Callback ID.
  69. By default, after the HAL_NOR_Init and if the state is HAL_NOR_STATE_RESET
  70. all callbacks are reset to the corresponding legacy weak (overridden) functions.
  71. Exception done for MspInit and MspDeInit callbacks that are respectively
  72. reset to the legacy weak (overridden) functions in the HAL_NOR_Init
  73. and HAL_NOR_DeInit only when these callbacks are null (not registered beforehand).
  74. If not, MspInit or MspDeInit are not null, the HAL_NOR_Init and HAL_NOR_DeInit
  75. keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
  76. Callbacks can be registered/unregistered in READY state only.
  77. Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
  78. in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
  79. during the Init/DeInit.
  80. In that case first register the MspInit/MspDeInit user callbacks
  81. using HAL_NOR_RegisterCallback before calling HAL_NOR_DeInit
  82. or HAL_NOR_Init function.
  83. When The compilation define USE_HAL_NOR_REGISTER_CALLBACKS is set to 0 or
  84. not defined, the callback registering feature is not available
  85. and weak (overridden) callbacks are used.
  86. @endverbatim
  87. ******************************************************************************
  88. */
  89. /* Includes ------------------------------------------------------------------*/
  90. #include "stm32f1xx_hal.h"
  91. #if defined(FSMC_BANK1)
  92. /** @addtogroup STM32F1xx_HAL_Driver
  93. * @{
  94. */
  95. #ifdef HAL_NOR_MODULE_ENABLED
  96. /** @defgroup NOR NOR
  97. * @brief NOR driver modules
  98. * @{
  99. */
  100. /* Private typedef -----------------------------------------------------------*/
  101. /* Private define ------------------------------------------------------------*/
  102. /** @defgroup NOR_Private_Defines NOR Private Defines
  103. * @{
  104. */
  105. /* Constants to define address to set to write a command */
  106. #define NOR_CMD_ADDRESS_FIRST_BYTE (uint16_t)0x0AAA
  107. #define NOR_CMD_ADDRESS_FIRST_CFI_BYTE (uint16_t)0x00AA
  108. #define NOR_CMD_ADDRESS_SECOND_BYTE (uint16_t)0x0555
  109. #define NOR_CMD_ADDRESS_THIRD_BYTE (uint16_t)0x0AAA
  110. #define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555
  111. #define NOR_CMD_ADDRESS_FIRST_CFI (uint16_t)0x0055
  112. #define NOR_CMD_ADDRESS_SECOND (uint16_t)0x02AA
  113. #define NOR_CMD_ADDRESS_THIRD (uint16_t)0x0555
  114. #define NOR_CMD_ADDRESS_FOURTH (uint16_t)0x0555
  115. #define NOR_CMD_ADDRESS_FIFTH (uint16_t)0x02AA
  116. #define NOR_CMD_ADDRESS_SIXTH (uint16_t)0x0555
  117. /* Constants to define data to program a command */
  118. #define NOR_CMD_DATA_READ_RESET (uint16_t)0x00F0
  119. #define NOR_CMD_DATA_FIRST (uint16_t)0x00AA
  120. #define NOR_CMD_DATA_SECOND (uint16_t)0x0055
  121. #define NOR_CMD_DATA_AUTO_SELECT (uint16_t)0x0090
  122. #define NOR_CMD_DATA_PROGRAM (uint16_t)0x00A0
  123. #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD (uint16_t)0x0080
  124. #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH (uint16_t)0x00AA
  125. #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH (uint16_t)0x0055
  126. #define NOR_CMD_DATA_CHIP_ERASE (uint16_t)0x0010
  127. #define NOR_CMD_DATA_CFI (uint16_t)0x0098
  128. #define NOR_CMD_DATA_BUFFER_AND_PROG (uint8_t)0x25
  129. #define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM (uint8_t)0x29
  130. #define NOR_CMD_DATA_BLOCK_ERASE (uint8_t)0x30
  131. #define NOR_CMD_READ_ARRAY (uint16_t)0x00FF
  132. #define NOR_CMD_WORD_PROGRAM (uint16_t)0x0040
  133. #define NOR_CMD_BUFFERED_PROGRAM (uint16_t)0x00E8
  134. #define NOR_CMD_CONFIRM (uint16_t)0x00D0
  135. #define NOR_CMD_BLOCK_ERASE (uint16_t)0x0020
  136. #define NOR_CMD_BLOCK_UNLOCK (uint16_t)0x0060
  137. #define NOR_CMD_READ_STATUS_REG (uint16_t)0x0070
  138. #define NOR_CMD_CLEAR_STATUS_REG (uint16_t)0x0050
  139. /* Mask on NOR STATUS REGISTER */
  140. #define NOR_MASK_STATUS_DQ4 (uint16_t)0x0010
  141. #define NOR_MASK_STATUS_DQ5 (uint16_t)0x0020
  142. #define NOR_MASK_STATUS_DQ6 (uint16_t)0x0040
  143. #define NOR_MASK_STATUS_DQ7 (uint16_t)0x0080
  144. /* Address of the primary command set */
  145. #define NOR_ADDRESS_COMMAND_SET (uint16_t)0x0013
  146. /* Command set code assignment (defined in JEDEC JEP137B version may 2004) */
  147. #define NOR_INTEL_SHARP_EXT_COMMAND_SET (uint16_t)0x0001 /* Supported in this driver */
  148. #define NOR_AMD_FUJITSU_COMMAND_SET (uint16_t)0x0002 /* Supported in this driver */
  149. #define NOR_INTEL_STANDARD_COMMAND_SET (uint16_t)0x0003 /* Not Supported in this driver */
  150. #define NOR_AMD_FUJITSU_EXT_COMMAND_SET (uint16_t)0x0004 /* Not Supported in this driver */
  151. #define NOR_WINDBOND_STANDARD_COMMAND_SET (uint16_t)0x0006 /* Not Supported in this driver */
  152. #define NOR_MITSUBISHI_STANDARD_COMMAND_SET (uint16_t)0x0100 /* Not Supported in this driver */
  153. #define NOR_MITSUBISHI_EXT_COMMAND_SET (uint16_t)0x0101 /* Not Supported in this driver */
  154. #define NOR_PAGE_WRITE_COMMAND_SET (uint16_t)0x0102 /* Not Supported in this driver */
  155. #define NOR_INTEL_PERFORMANCE_COMMAND_SET (uint16_t)0x0200 /* Not Supported in this driver */
  156. #define NOR_INTEL_DATA_COMMAND_SET (uint16_t)0x0210 /* Not Supported in this driver */
  157. /**
  158. * @}
  159. */
  160. /* Private macro -------------------------------------------------------------*/
  161. /* Private variables ---------------------------------------------------------*/
  162. /** @defgroup NOR_Private_Variables NOR Private Variables
  163. * @{
  164. */
  165. static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B;
  166. /**
  167. * @}
  168. */
  169. /* Private functions ---------------------------------------------------------*/
  170. /* Exported functions --------------------------------------------------------*/
  171. /** @defgroup NOR_Exported_Functions NOR Exported Functions
  172. * @{
  173. */
  174. /** @defgroup NOR_Exported_Functions_Group1 Initialization and de-initialization functions
  175. * @brief Initialization and Configuration functions
  176. *
  177. @verbatim
  178. ==============================================================================
  179. ##### NOR Initialization and de_initialization functions #####
  180. ==============================================================================
  181. [..]
  182. This section provides functions allowing to initialize/de-initialize
  183. the NOR memory
  184. @endverbatim
  185. * @{
  186. */
  187. /**
  188. * @brief Perform the NOR memory Initialization sequence
  189. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  190. * the configuration information for NOR module.
  191. * @param Timing pointer to NOR control timing structure
  192. * @param ExtTiming pointer to NOR extended mode timing structure
  193. * @retval HAL status
  194. */
  195. HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FSMC_NORSRAM_TimingTypeDef *Timing,
  196. FSMC_NORSRAM_TimingTypeDef *ExtTiming)
  197. {
  198. uint32_t deviceaddress;
  199. HAL_StatusTypeDef status = HAL_OK;
  200. /* Check the NOR handle parameter */
  201. if (hnor == NULL)
  202. {
  203. return HAL_ERROR;
  204. }
  205. if (hnor->State == HAL_NOR_STATE_RESET)
  206. {
  207. /* Allocate lock resource and initialize it */
  208. hnor->Lock = HAL_UNLOCKED;
  209. #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
  210. if (hnor->MspInitCallback == NULL)
  211. {
  212. hnor->MspInitCallback = HAL_NOR_MspInit;
  213. }
  214. /* Init the low level hardware */
  215. hnor->MspInitCallback(hnor);
  216. #else
  217. /* Initialize the low level hardware (MSP) */
  218. HAL_NOR_MspInit(hnor);
  219. #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */
  220. }
  221. /* Initialize NOR control Interface */
  222. (void)FSMC_NORSRAM_Init(hnor->Instance, &(hnor->Init));
  223. /* Initialize NOR timing Interface */
  224. (void)FSMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank);
  225. /* Initialize NOR extended mode timing Interface */
  226. (void)FSMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming,
  227. hnor->Init.NSBank, hnor->Init.ExtendedMode);
  228. /* Enable the NORSRAM device */
  229. __FSMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank);
  230. /* Initialize NOR Memory Data Width*/
  231. if (hnor->Init.MemoryDataWidth == FSMC_NORSRAM_MEM_BUS_WIDTH_8)
  232. {
  233. uwNORMemoryDataWidth = NOR_MEMORY_8B;
  234. }
  235. else
  236. {
  237. uwNORMemoryDataWidth = NOR_MEMORY_16B;
  238. }
  239. /* Initialize the NOR controller state */
  240. hnor->State = HAL_NOR_STATE_READY;
  241. /* Select the NOR device address */
  242. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  243. {
  244. deviceaddress = NOR_MEMORY_ADRESS1;
  245. }
  246. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  247. {
  248. deviceaddress = NOR_MEMORY_ADRESS2;
  249. }
  250. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  251. {
  252. deviceaddress = NOR_MEMORY_ADRESS3;
  253. }
  254. else /* FSMC_NORSRAM_BANK4 */
  255. {
  256. deviceaddress = NOR_MEMORY_ADRESS4;
  257. }
  258. if (hnor->Init.WriteOperation == FSMC_WRITE_OPERATION_DISABLE)
  259. {
  260. (void)FSMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank);
  261. /* Update the NOR controller state */
  262. hnor->State = HAL_NOR_STATE_PROTECTED;
  263. }
  264. else
  265. {
  266. /* Get the value of the command set */
  267. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  268. {
  269. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI_BYTE),
  270. NOR_CMD_DATA_CFI);
  271. }
  272. else
  273. {
  274. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
  275. }
  276. hnor->CommandSet = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_ADDRESS_COMMAND_SET);
  277. status = HAL_NOR_ReturnToReadMode(hnor);
  278. }
  279. return status;
  280. }
  281. /**
  282. * @brief Perform NOR memory De-Initialization sequence
  283. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  284. * the configuration information for NOR module.
  285. * @retval HAL status
  286. */
  287. HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor)
  288. {
  289. #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
  290. if (hnor->MspDeInitCallback == NULL)
  291. {
  292. hnor->MspDeInitCallback = HAL_NOR_MspDeInit;
  293. }
  294. /* DeInit the low level hardware */
  295. hnor->MspDeInitCallback(hnor);
  296. #else
  297. /* De-Initialize the low level hardware (MSP) */
  298. HAL_NOR_MspDeInit(hnor);
  299. #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */
  300. /* Configure the NOR registers with their reset values */
  301. (void)FSMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank);
  302. /* Reset the NOR controller state */
  303. hnor->State = HAL_NOR_STATE_RESET;
  304. /* Release Lock */
  305. __HAL_UNLOCK(hnor);
  306. return HAL_OK;
  307. }
  308. /**
  309. * @brief NOR MSP Init
  310. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  311. * the configuration information for NOR module.
  312. * @retval None
  313. */
  314. __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor)
  315. {
  316. /* Prevent unused argument(s) compilation warning */
  317. UNUSED(hnor);
  318. /* NOTE : This function Should not be modified, when the callback is needed,
  319. the HAL_NOR_MspInit could be implemented in the user file
  320. */
  321. }
  322. /**
  323. * @brief NOR MSP DeInit
  324. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  325. * the configuration information for NOR module.
  326. * @retval None
  327. */
  328. __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor)
  329. {
  330. /* Prevent unused argument(s) compilation warning */
  331. UNUSED(hnor);
  332. /* NOTE : This function Should not be modified, when the callback is needed,
  333. the HAL_NOR_MspDeInit could be implemented in the user file
  334. */
  335. }
  336. /**
  337. * @brief NOR MSP Wait for Ready/Busy signal
  338. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  339. * the configuration information for NOR module.
  340. * @param Timeout Maximum timeout value
  341. * @retval None
  342. */
  343. __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
  344. {
  345. /* Prevent unused argument(s) compilation warning */
  346. UNUSED(hnor);
  347. UNUSED(Timeout);
  348. /* NOTE : This function Should not be modified, when the callback is needed,
  349. the HAL_NOR_MspWait could be implemented in the user file
  350. */
  351. }
  352. /**
  353. * @}
  354. */
  355. /** @defgroup NOR_Exported_Functions_Group2 Input and Output functions
  356. * @brief Input Output and memory control functions
  357. *
  358. @verbatim
  359. ==============================================================================
  360. ##### NOR Input and Output functions #####
  361. ==============================================================================
  362. [..]
  363. This section provides functions allowing to use and control the NOR memory
  364. @endverbatim
  365. * @{
  366. */
  367. /**
  368. * @brief Read NOR flash IDs
  369. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  370. * the configuration information for NOR module.
  371. * @param pNOR_ID pointer to NOR ID structure
  372. * @retval HAL status
  373. */
  374. HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID)
  375. {
  376. uint32_t deviceaddress;
  377. HAL_NOR_StateTypeDef state;
  378. HAL_StatusTypeDef status = HAL_OK;
  379. /* Check the NOR controller state */
  380. state = hnor->State;
  381. if (state == HAL_NOR_STATE_BUSY)
  382. {
  383. return HAL_BUSY;
  384. }
  385. else if (state == HAL_NOR_STATE_PROTECTED)
  386. {
  387. return HAL_ERROR;
  388. }
  389. else if (state == HAL_NOR_STATE_READY)
  390. {
  391. /* Process Locked */
  392. __HAL_LOCK(hnor);
  393. /* Update the NOR controller state */
  394. hnor->State = HAL_NOR_STATE_BUSY;
  395. /* Select the NOR device address */
  396. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  397. {
  398. deviceaddress = NOR_MEMORY_ADRESS1;
  399. }
  400. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  401. {
  402. deviceaddress = NOR_MEMORY_ADRESS2;
  403. }
  404. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  405. {
  406. deviceaddress = NOR_MEMORY_ADRESS3;
  407. }
  408. else /* FSMC_NORSRAM_BANK4 */
  409. {
  410. deviceaddress = NOR_MEMORY_ADRESS4;
  411. }
  412. /* Send read ID command */
  413. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  414. {
  415. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  416. {
  417. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
  418. NOR_CMD_DATA_FIRST);
  419. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
  420. NOR_CMD_DATA_SECOND);
  421. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
  422. NOR_CMD_DATA_AUTO_SELECT);
  423. }
  424. else
  425. {
  426. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  427. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  428. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
  429. NOR_CMD_DATA_AUTO_SELECT);
  430. }
  431. }
  432. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  433. {
  434. NOR_WRITE(deviceaddress, NOR_CMD_DATA_AUTO_SELECT);
  435. }
  436. else
  437. {
  438. /* Primary command set not supported by the driver */
  439. status = HAL_ERROR;
  440. }
  441. if (status != HAL_ERROR)
  442. {
  443. /* Read the NOR IDs */
  444. pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS);
  445. pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
  446. DEVICE_CODE1_ADDR);
  447. pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
  448. DEVICE_CODE2_ADDR);
  449. pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth,
  450. DEVICE_CODE3_ADDR);
  451. }
  452. /* Check the NOR controller state */
  453. hnor->State = state;
  454. /* Process unlocked */
  455. __HAL_UNLOCK(hnor);
  456. }
  457. else
  458. {
  459. return HAL_ERROR;
  460. }
  461. return status;
  462. }
  463. /**
  464. * @brief Returns the NOR memory to Read mode.
  465. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  466. * the configuration information for NOR module.
  467. * @retval HAL status
  468. */
  469. HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor)
  470. {
  471. uint32_t deviceaddress;
  472. HAL_NOR_StateTypeDef state;
  473. HAL_StatusTypeDef status = HAL_OK;
  474. /* Check the NOR controller state */
  475. state = hnor->State;
  476. if (state == HAL_NOR_STATE_BUSY)
  477. {
  478. return HAL_BUSY;
  479. }
  480. else if (state == HAL_NOR_STATE_PROTECTED)
  481. {
  482. return HAL_ERROR;
  483. }
  484. else if (state == HAL_NOR_STATE_READY)
  485. {
  486. /* Process Locked */
  487. __HAL_LOCK(hnor);
  488. /* Update the NOR controller state */
  489. hnor->State = HAL_NOR_STATE_BUSY;
  490. /* Select the NOR device address */
  491. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  492. {
  493. deviceaddress = NOR_MEMORY_ADRESS1;
  494. }
  495. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  496. {
  497. deviceaddress = NOR_MEMORY_ADRESS2;
  498. }
  499. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  500. {
  501. deviceaddress = NOR_MEMORY_ADRESS3;
  502. }
  503. else /* FSMC_NORSRAM_BANK4 */
  504. {
  505. deviceaddress = NOR_MEMORY_ADRESS4;
  506. }
  507. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  508. {
  509. NOR_WRITE(deviceaddress, NOR_CMD_DATA_READ_RESET);
  510. }
  511. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  512. {
  513. NOR_WRITE(deviceaddress, NOR_CMD_READ_ARRAY);
  514. }
  515. else
  516. {
  517. /* Primary command set not supported by the driver */
  518. status = HAL_ERROR;
  519. }
  520. /* Check the NOR controller state */
  521. hnor->State = state;
  522. /* Process unlocked */
  523. __HAL_UNLOCK(hnor);
  524. }
  525. else
  526. {
  527. return HAL_ERROR;
  528. }
  529. return status;
  530. }
  531. /**
  532. * @brief Read data from NOR memory
  533. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  534. * the configuration information for NOR module.
  535. * @param pAddress pointer to Device address
  536. * @param pData pointer to read data
  537. * @retval HAL status
  538. */
  539. HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
  540. {
  541. uint32_t deviceaddress;
  542. HAL_NOR_StateTypeDef state;
  543. HAL_StatusTypeDef status = HAL_OK;
  544. /* Check the NOR controller state */
  545. state = hnor->State;
  546. if (state == HAL_NOR_STATE_BUSY)
  547. {
  548. return HAL_BUSY;
  549. }
  550. else if (state == HAL_NOR_STATE_PROTECTED)
  551. {
  552. return HAL_ERROR;
  553. }
  554. else if (state == HAL_NOR_STATE_READY)
  555. {
  556. /* Process Locked */
  557. __HAL_LOCK(hnor);
  558. /* Update the NOR controller state */
  559. hnor->State = HAL_NOR_STATE_BUSY;
  560. /* Select the NOR device address */
  561. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  562. {
  563. deviceaddress = NOR_MEMORY_ADRESS1;
  564. }
  565. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  566. {
  567. deviceaddress = NOR_MEMORY_ADRESS2;
  568. }
  569. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  570. {
  571. deviceaddress = NOR_MEMORY_ADRESS3;
  572. }
  573. else /* FSMC_NORSRAM_BANK4 */
  574. {
  575. deviceaddress = NOR_MEMORY_ADRESS4;
  576. }
  577. /* Send read data command */
  578. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  579. {
  580. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  581. {
  582. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
  583. NOR_CMD_DATA_FIRST);
  584. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
  585. NOR_CMD_DATA_SECOND);
  586. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
  587. NOR_CMD_DATA_READ_RESET);
  588. }
  589. else
  590. {
  591. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  592. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  593. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
  594. NOR_CMD_DATA_READ_RESET);
  595. }
  596. }
  597. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  598. {
  599. NOR_WRITE(pAddress, NOR_CMD_READ_ARRAY);
  600. }
  601. else
  602. {
  603. /* Primary command set not supported by the driver */
  604. status = HAL_ERROR;
  605. }
  606. if (status != HAL_ERROR)
  607. {
  608. /* Read the data */
  609. *pData = (uint16_t)(*(__IO uint32_t *)pAddress);
  610. }
  611. /* Check the NOR controller state */
  612. hnor->State = state;
  613. /* Process unlocked */
  614. __HAL_UNLOCK(hnor);
  615. }
  616. else
  617. {
  618. return HAL_ERROR;
  619. }
  620. return status;
  621. }
  622. /**
  623. * @brief Program data to NOR memory
  624. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  625. * the configuration information for NOR module.
  626. * @param pAddress Device address
  627. * @param pData pointer to the data to write
  628. * @retval HAL status
  629. */
  630. HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
  631. {
  632. uint32_t deviceaddress;
  633. HAL_StatusTypeDef status = HAL_OK;
  634. /* Check the NOR controller state */
  635. if (hnor->State == HAL_NOR_STATE_BUSY)
  636. {
  637. return HAL_BUSY;
  638. }
  639. else if (hnor->State == HAL_NOR_STATE_READY)
  640. {
  641. /* Process Locked */
  642. __HAL_LOCK(hnor);
  643. /* Update the NOR controller state */
  644. hnor->State = HAL_NOR_STATE_BUSY;
  645. /* Select the NOR device address */
  646. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  647. {
  648. deviceaddress = NOR_MEMORY_ADRESS1;
  649. }
  650. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  651. {
  652. deviceaddress = NOR_MEMORY_ADRESS2;
  653. }
  654. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  655. {
  656. deviceaddress = NOR_MEMORY_ADRESS3;
  657. }
  658. else /* FSMC_NORSRAM_BANK4 */
  659. {
  660. deviceaddress = NOR_MEMORY_ADRESS4;
  661. }
  662. /* Send program data command */
  663. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  664. {
  665. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  666. {
  667. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
  668. NOR_CMD_DATA_FIRST);
  669. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
  670. NOR_CMD_DATA_SECOND);
  671. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
  672. NOR_CMD_DATA_PROGRAM);
  673. }
  674. else
  675. {
  676. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  677. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  678. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM);
  679. }
  680. }
  681. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  682. {
  683. NOR_WRITE(pAddress, NOR_CMD_WORD_PROGRAM);
  684. }
  685. else
  686. {
  687. /* Primary command set not supported by the driver */
  688. status = HAL_ERROR;
  689. }
  690. if (status != HAL_ERROR)
  691. {
  692. /* Write the data */
  693. NOR_WRITE(pAddress, *pData);
  694. }
  695. /* Check the NOR controller state */
  696. hnor->State = HAL_NOR_STATE_READY;
  697. /* Process unlocked */
  698. __HAL_UNLOCK(hnor);
  699. }
  700. else
  701. {
  702. return HAL_ERROR;
  703. }
  704. return status;
  705. }
  706. /**
  707. * @brief Reads a half-word buffer from the NOR memory.
  708. * @param hnor pointer to the NOR handle
  709. * @param uwAddress NOR memory internal address to read from.
  710. * @param pData pointer to the buffer that receives the data read from the
  711. * NOR memory.
  712. * @param uwBufferSize number of Half word to read.
  713. * @retval HAL status
  714. */
  715. HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData,
  716. uint32_t uwBufferSize)
  717. {
  718. uint32_t deviceaddress;
  719. uint32_t size = uwBufferSize;
  720. uint32_t address = uwAddress;
  721. uint16_t *data = pData;
  722. HAL_NOR_StateTypeDef state;
  723. HAL_StatusTypeDef status = HAL_OK;
  724. /* Check the NOR controller state */
  725. state = hnor->State;
  726. if (state == HAL_NOR_STATE_BUSY)
  727. {
  728. return HAL_BUSY;
  729. }
  730. else if (state == HAL_NOR_STATE_PROTECTED)
  731. {
  732. return HAL_ERROR;
  733. }
  734. else if (state == HAL_NOR_STATE_READY)
  735. {
  736. /* Process Locked */
  737. __HAL_LOCK(hnor);
  738. /* Update the NOR controller state */
  739. hnor->State = HAL_NOR_STATE_BUSY;
  740. /* Select the NOR device address */
  741. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  742. {
  743. deviceaddress = NOR_MEMORY_ADRESS1;
  744. }
  745. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  746. {
  747. deviceaddress = NOR_MEMORY_ADRESS2;
  748. }
  749. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  750. {
  751. deviceaddress = NOR_MEMORY_ADRESS3;
  752. }
  753. else /* FSMC_NORSRAM_BANK4 */
  754. {
  755. deviceaddress = NOR_MEMORY_ADRESS4;
  756. }
  757. /* Send read data command */
  758. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  759. {
  760. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  761. {
  762. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
  763. NOR_CMD_DATA_FIRST);
  764. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
  765. NOR_CMD_DATA_SECOND);
  766. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
  767. NOR_CMD_DATA_READ_RESET);
  768. }
  769. else
  770. {
  771. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  772. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  773. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
  774. NOR_CMD_DATA_READ_RESET);
  775. }
  776. }
  777. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  778. {
  779. NOR_WRITE(deviceaddress, NOR_CMD_READ_ARRAY);
  780. }
  781. else
  782. {
  783. /* Primary command set not supported by the driver */
  784. status = HAL_ERROR;
  785. }
  786. if (status != HAL_ERROR)
  787. {
  788. /* Read buffer */
  789. while (size > 0U)
  790. {
  791. *data = *(__IO uint16_t *)address;
  792. data++;
  793. address += 2U;
  794. size--;
  795. }
  796. }
  797. /* Check the NOR controller state */
  798. hnor->State = state;
  799. /* Process unlocked */
  800. __HAL_UNLOCK(hnor);
  801. }
  802. else
  803. {
  804. return HAL_ERROR;
  805. }
  806. return status;
  807. }
  808. /**
  809. * @brief Writes a half-word buffer to the NOR memory. This function must be used
  810. only with S29GL128P NOR memory.
  811. * @param hnor pointer to the NOR handle
  812. * @param uwAddress NOR memory internal start write address
  813. * @param pData pointer to source data buffer.
  814. * @param uwBufferSize Size of the buffer to write
  815. * @retval HAL status
  816. */
  817. HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData,
  818. uint32_t uwBufferSize)
  819. {
  820. uint16_t *p_currentaddress;
  821. const uint16_t *p_endaddress;
  822. uint16_t *data = pData;
  823. uint32_t deviceaddress;
  824. HAL_StatusTypeDef status = HAL_OK;
  825. /* Check the NOR controller state */
  826. if (hnor->State == HAL_NOR_STATE_BUSY)
  827. {
  828. return HAL_BUSY;
  829. }
  830. else if (hnor->State == HAL_NOR_STATE_READY)
  831. {
  832. /* Process Locked */
  833. __HAL_LOCK(hnor);
  834. /* Update the NOR controller state */
  835. hnor->State = HAL_NOR_STATE_BUSY;
  836. /* Select the NOR device address */
  837. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  838. {
  839. deviceaddress = NOR_MEMORY_ADRESS1;
  840. }
  841. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  842. {
  843. deviceaddress = NOR_MEMORY_ADRESS2;
  844. }
  845. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  846. {
  847. deviceaddress = NOR_MEMORY_ADRESS3;
  848. }
  849. else /* FSMC_NORSRAM_BANK4 */
  850. {
  851. deviceaddress = NOR_MEMORY_ADRESS4;
  852. }
  853. /* Initialize variables */
  854. p_currentaddress = (uint16_t *)(deviceaddress + uwAddress);
  855. p_endaddress = (uint16_t *)(deviceaddress + uwAddress + (2U * (uwBufferSize - 1U)));
  856. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  857. {
  858. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  859. {
  860. /* Issue unlock command sequence */
  861. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
  862. NOR_CMD_DATA_FIRST);
  863. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
  864. NOR_CMD_DATA_SECOND);
  865. }
  866. else
  867. {
  868. /* Issue unlock command sequence */
  869. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  870. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  871. }
  872. /* Write Buffer Load Command */
  873. NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG);
  874. NOR_WRITE((deviceaddress + uwAddress), (uint16_t)(uwBufferSize - 1U));
  875. }
  876. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  877. {
  878. /* Write Buffer Load Command */
  879. NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_BUFFERED_PROGRAM);
  880. NOR_WRITE((deviceaddress + uwAddress), (uint16_t)(uwBufferSize - 1U));
  881. }
  882. else
  883. {
  884. /* Primary command set not supported by the driver */
  885. status = HAL_ERROR;
  886. }
  887. if (status != HAL_ERROR)
  888. {
  889. /* Load Data into NOR Buffer */
  890. while (p_currentaddress <= p_endaddress)
  891. {
  892. NOR_WRITE(p_currentaddress, *data);
  893. data++;
  894. p_currentaddress ++;
  895. }
  896. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  897. {
  898. NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM);
  899. }
  900. else /* => hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET */
  901. {
  902. NOR_WRITE((deviceaddress + uwAddress), NOR_CMD_CONFIRM);
  903. }
  904. }
  905. /* Check the NOR controller state */
  906. hnor->State = HAL_NOR_STATE_READY;
  907. /* Process unlocked */
  908. __HAL_UNLOCK(hnor);
  909. }
  910. else
  911. {
  912. return HAL_ERROR;
  913. }
  914. return status;
  915. }
  916. /**
  917. * @brief Erase the specified block of the NOR memory
  918. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  919. * the configuration information for NOR module.
  920. * @param BlockAddress Block to erase address
  921. * @param Address Device address
  922. * @retval HAL status
  923. */
  924. HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
  925. {
  926. uint32_t deviceaddress;
  927. HAL_StatusTypeDef status = HAL_OK;
  928. /* Check the NOR controller state */
  929. if (hnor->State == HAL_NOR_STATE_BUSY)
  930. {
  931. return HAL_BUSY;
  932. }
  933. else if (hnor->State == HAL_NOR_STATE_READY)
  934. {
  935. /* Process Locked */
  936. __HAL_LOCK(hnor);
  937. /* Update the NOR controller state */
  938. hnor->State = HAL_NOR_STATE_BUSY;
  939. /* Select the NOR device address */
  940. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  941. {
  942. deviceaddress = NOR_MEMORY_ADRESS1;
  943. }
  944. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  945. {
  946. deviceaddress = NOR_MEMORY_ADRESS2;
  947. }
  948. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  949. {
  950. deviceaddress = NOR_MEMORY_ADRESS3;
  951. }
  952. else /* FSMC_NORSRAM_BANK4 */
  953. {
  954. deviceaddress = NOR_MEMORY_ADRESS4;
  955. }
  956. /* Send block erase command sequence */
  957. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  958. {
  959. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  960. {
  961. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
  962. NOR_CMD_DATA_FIRST);
  963. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
  964. NOR_CMD_DATA_SECOND);
  965. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
  966. NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
  967. }
  968. else
  969. {
  970. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  971. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  972. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
  973. NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
  974. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH),
  975. NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
  976. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH),
  977. NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
  978. }
  979. NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE);
  980. }
  981. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  982. {
  983. NOR_WRITE((BlockAddress + Address), NOR_CMD_BLOCK_UNLOCK);
  984. NOR_WRITE((BlockAddress + Address), NOR_CMD_CONFIRM);
  985. NOR_WRITE((BlockAddress + Address), NOR_CMD_BLOCK_ERASE);
  986. NOR_WRITE((BlockAddress + Address), NOR_CMD_CONFIRM);
  987. }
  988. else
  989. {
  990. /* Primary command set not supported by the driver */
  991. status = HAL_ERROR;
  992. }
  993. /* Check the NOR memory status and update the controller state */
  994. hnor->State = HAL_NOR_STATE_READY;
  995. /* Process unlocked */
  996. __HAL_UNLOCK(hnor);
  997. }
  998. else
  999. {
  1000. return HAL_ERROR;
  1001. }
  1002. return status;
  1003. }
  1004. /**
  1005. * @brief Erase the entire NOR chip.
  1006. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  1007. * the configuration information for NOR module.
  1008. * @param Address Device address
  1009. * @retval HAL status
  1010. */
  1011. HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
  1012. {
  1013. uint32_t deviceaddress;
  1014. HAL_StatusTypeDef status = HAL_OK;
  1015. UNUSED(Address);
  1016. /* Check the NOR controller state */
  1017. if (hnor->State == HAL_NOR_STATE_BUSY)
  1018. {
  1019. return HAL_BUSY;
  1020. }
  1021. else if (hnor->State == HAL_NOR_STATE_READY)
  1022. {
  1023. /* Process Locked */
  1024. __HAL_LOCK(hnor);
  1025. /* Update the NOR controller state */
  1026. hnor->State = HAL_NOR_STATE_BUSY;
  1027. /* Select the NOR device address */
  1028. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  1029. {
  1030. deviceaddress = NOR_MEMORY_ADRESS1;
  1031. }
  1032. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  1033. {
  1034. deviceaddress = NOR_MEMORY_ADRESS2;
  1035. }
  1036. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  1037. {
  1038. deviceaddress = NOR_MEMORY_ADRESS3;
  1039. }
  1040. else /* FSMC_NORSRAM_BANK4 */
  1041. {
  1042. deviceaddress = NOR_MEMORY_ADRESS4;
  1043. }
  1044. /* Send NOR chip erase command sequence */
  1045. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  1046. {
  1047. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  1048. {
  1049. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_BYTE),
  1050. NOR_CMD_DATA_FIRST);
  1051. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND_BYTE),
  1052. NOR_CMD_DATA_SECOND);
  1053. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD_BYTE),
  1054. NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
  1055. }
  1056. else
  1057. {
  1058. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
  1059. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
  1060. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD),
  1061. NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
  1062. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH),
  1063. NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
  1064. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH),
  1065. NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
  1066. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH),
  1067. NOR_CMD_DATA_CHIP_ERASE);
  1068. }
  1069. }
  1070. else
  1071. {
  1072. /* Primary command set not supported by the driver */
  1073. status = HAL_ERROR;
  1074. }
  1075. /* Check the NOR memory status and update the controller state */
  1076. hnor->State = HAL_NOR_STATE_READY;
  1077. /* Process unlocked */
  1078. __HAL_UNLOCK(hnor);
  1079. }
  1080. else
  1081. {
  1082. return HAL_ERROR;
  1083. }
  1084. return status;
  1085. }
  1086. /**
  1087. * @brief Read NOR flash CFI IDs
  1088. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  1089. * the configuration information for NOR module.
  1090. * @param pNOR_CFI pointer to NOR CFI IDs structure
  1091. * @retval HAL status
  1092. */
  1093. HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI)
  1094. {
  1095. uint32_t deviceaddress;
  1096. HAL_NOR_StateTypeDef state;
  1097. /* Check the NOR controller state */
  1098. state = hnor->State;
  1099. if (state == HAL_NOR_STATE_BUSY)
  1100. {
  1101. return HAL_BUSY;
  1102. }
  1103. else if (state == HAL_NOR_STATE_PROTECTED)
  1104. {
  1105. return HAL_ERROR;
  1106. }
  1107. else if (state == HAL_NOR_STATE_READY)
  1108. {
  1109. /* Process Locked */
  1110. __HAL_LOCK(hnor);
  1111. /* Update the NOR controller state */
  1112. hnor->State = HAL_NOR_STATE_BUSY;
  1113. /* Select the NOR device address */
  1114. if (hnor->Init.NSBank == FSMC_NORSRAM_BANK1)
  1115. {
  1116. deviceaddress = NOR_MEMORY_ADRESS1;
  1117. }
  1118. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK2)
  1119. {
  1120. deviceaddress = NOR_MEMORY_ADRESS2;
  1121. }
  1122. else if (hnor->Init.NSBank == FSMC_NORSRAM_BANK3)
  1123. {
  1124. deviceaddress = NOR_MEMORY_ADRESS3;
  1125. }
  1126. else /* FSMC_NORSRAM_BANK4 */
  1127. {
  1128. deviceaddress = NOR_MEMORY_ADRESS4;
  1129. }
  1130. /* Send read CFI query command */
  1131. if (uwNORMemoryDataWidth == NOR_MEMORY_8B)
  1132. {
  1133. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI_BYTE),
  1134. NOR_CMD_DATA_CFI);
  1135. }
  1136. else
  1137. {
  1138. NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
  1139. }
  1140. /* read the NOR CFI information */
  1141. pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS);
  1142. pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS);
  1143. pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS);
  1144. pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS);
  1145. /* Check the NOR controller state */
  1146. hnor->State = state;
  1147. /* Process unlocked */
  1148. __HAL_UNLOCK(hnor);
  1149. }
  1150. else
  1151. {
  1152. return HAL_ERROR;
  1153. }
  1154. return HAL_OK;
  1155. }
  1156. #if (USE_HAL_NOR_REGISTER_CALLBACKS == 1)
  1157. /**
  1158. * @brief Register a User NOR Callback
  1159. * To be used to override the weak predefined callback
  1160. * @param hnor : NOR handle
  1161. * @param CallbackId : ID of the callback to be registered
  1162. * This parameter can be one of the following values:
  1163. * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID
  1164. * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID
  1165. * @param pCallback : pointer to the Callback function
  1166. * @retval status
  1167. */
  1168. HAL_StatusTypeDef HAL_NOR_RegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId,
  1169. pNOR_CallbackTypeDef pCallback)
  1170. {
  1171. HAL_StatusTypeDef status = HAL_OK;
  1172. HAL_NOR_StateTypeDef state;
  1173. if (pCallback == NULL)
  1174. {
  1175. return HAL_ERROR;
  1176. }
  1177. state = hnor->State;
  1178. if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED))
  1179. {
  1180. switch (CallbackId)
  1181. {
  1182. case HAL_NOR_MSP_INIT_CB_ID :
  1183. hnor->MspInitCallback = pCallback;
  1184. break;
  1185. case HAL_NOR_MSP_DEINIT_CB_ID :
  1186. hnor->MspDeInitCallback = pCallback;
  1187. break;
  1188. default :
  1189. /* update return status */
  1190. status = HAL_ERROR;
  1191. break;
  1192. }
  1193. }
  1194. else
  1195. {
  1196. /* update return status */
  1197. status = HAL_ERROR;
  1198. }
  1199. return status;
  1200. }
  1201. /**
  1202. * @brief Unregister a User NOR Callback
  1203. * NOR Callback is redirected to the weak predefined callback
  1204. * @param hnor : NOR handle
  1205. * @param CallbackId : ID of the callback to be unregistered
  1206. * This parameter can be one of the following values:
  1207. * @arg @ref HAL_NOR_MSP_INIT_CB_ID NOR MspInit callback ID
  1208. * @arg @ref HAL_NOR_MSP_DEINIT_CB_ID NOR MspDeInit callback ID
  1209. * @retval status
  1210. */
  1211. HAL_StatusTypeDef HAL_NOR_UnRegisterCallback(NOR_HandleTypeDef *hnor, HAL_NOR_CallbackIDTypeDef CallbackId)
  1212. {
  1213. HAL_StatusTypeDef status = HAL_OK;
  1214. HAL_NOR_StateTypeDef state;
  1215. state = hnor->State;
  1216. if ((state == HAL_NOR_STATE_READY) || (state == HAL_NOR_STATE_RESET) || (state == HAL_NOR_STATE_PROTECTED))
  1217. {
  1218. switch (CallbackId)
  1219. {
  1220. case HAL_NOR_MSP_INIT_CB_ID :
  1221. hnor->MspInitCallback = HAL_NOR_MspInit;
  1222. break;
  1223. case HAL_NOR_MSP_DEINIT_CB_ID :
  1224. hnor->MspDeInitCallback = HAL_NOR_MspDeInit;
  1225. break;
  1226. default :
  1227. /* update return status */
  1228. status = HAL_ERROR;
  1229. break;
  1230. }
  1231. }
  1232. else
  1233. {
  1234. /* update return status */
  1235. status = HAL_ERROR;
  1236. }
  1237. return status;
  1238. }
  1239. #endif /* (USE_HAL_NOR_REGISTER_CALLBACKS) */
  1240. /**
  1241. * @}
  1242. */
  1243. /** @defgroup NOR_Exported_Functions_Group3 NOR Control functions
  1244. * @brief management functions
  1245. *
  1246. @verbatim
  1247. ==============================================================================
  1248. ##### NOR Control functions #####
  1249. ==============================================================================
  1250. [..]
  1251. This subsection provides a set of functions allowing to control dynamically
  1252. the NOR interface.
  1253. @endverbatim
  1254. * @{
  1255. */
  1256. /**
  1257. * @brief Enables dynamically NOR write operation.
  1258. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  1259. * the configuration information for NOR module.
  1260. * @retval HAL status
  1261. */
  1262. HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor)
  1263. {
  1264. /* Check the NOR controller state */
  1265. if (hnor->State == HAL_NOR_STATE_PROTECTED)
  1266. {
  1267. /* Process Locked */
  1268. __HAL_LOCK(hnor);
  1269. /* Update the NOR controller state */
  1270. hnor->State = HAL_NOR_STATE_BUSY;
  1271. /* Enable write operation */
  1272. (void)FSMC_NORSRAM_WriteOperation_Enable(hnor->Instance, hnor->Init.NSBank);
  1273. /* Update the NOR controller state */
  1274. hnor->State = HAL_NOR_STATE_READY;
  1275. /* Process unlocked */
  1276. __HAL_UNLOCK(hnor);
  1277. }
  1278. else
  1279. {
  1280. return HAL_ERROR;
  1281. }
  1282. return HAL_OK;
  1283. }
  1284. /**
  1285. * @brief Disables dynamically NOR write operation.
  1286. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  1287. * the configuration information for NOR module.
  1288. * @retval HAL status
  1289. */
  1290. HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor)
  1291. {
  1292. /* Check the NOR controller state */
  1293. if (hnor->State == HAL_NOR_STATE_READY)
  1294. {
  1295. /* Process Locked */
  1296. __HAL_LOCK(hnor);
  1297. /* Update the NOR controller state */
  1298. hnor->State = HAL_NOR_STATE_BUSY;
  1299. /* Disable write operation */
  1300. (void)FSMC_NORSRAM_WriteOperation_Disable(hnor->Instance, hnor->Init.NSBank);
  1301. /* Update the NOR controller state */
  1302. hnor->State = HAL_NOR_STATE_PROTECTED;
  1303. /* Process unlocked */
  1304. __HAL_UNLOCK(hnor);
  1305. }
  1306. else
  1307. {
  1308. return HAL_ERROR;
  1309. }
  1310. return HAL_OK;
  1311. }
  1312. /**
  1313. * @}
  1314. */
  1315. /** @defgroup NOR_Exported_Functions_Group4 NOR State functions
  1316. * @brief Peripheral State functions
  1317. *
  1318. @verbatim
  1319. ==============================================================================
  1320. ##### NOR State functions #####
  1321. ==============================================================================
  1322. [..]
  1323. This subsection permits to get in run-time the status of the NOR controller
  1324. and the data flow.
  1325. @endverbatim
  1326. * @{
  1327. */
  1328. /**
  1329. * @brief return the NOR controller state
  1330. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  1331. * the configuration information for NOR module.
  1332. * @retval NOR controller state
  1333. */
  1334. HAL_NOR_StateTypeDef HAL_NOR_GetState(const NOR_HandleTypeDef *hnor)
  1335. {
  1336. return hnor->State;
  1337. }
  1338. /**
  1339. * @brief Returns the NOR operation status.
  1340. * @param hnor pointer to a NOR_HandleTypeDef structure that contains
  1341. * the configuration information for NOR module.
  1342. * @param Address Device address
  1343. * @param Timeout NOR programming Timeout
  1344. * @retval NOR_Status The returned value can be: HAL_NOR_STATUS_SUCCESS, HAL_NOR_STATUS_ERROR
  1345. * or HAL_NOR_STATUS_TIMEOUT
  1346. */
  1347. HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
  1348. {
  1349. HAL_NOR_StatusTypeDef status = HAL_NOR_STATUS_ONGOING;
  1350. uint16_t tmpsr1;
  1351. uint16_t tmpsr2;
  1352. uint32_t tickstart;
  1353. /* Poll on NOR memory Ready/Busy signal ------------------------------------*/
  1354. HAL_NOR_MspWait(hnor, Timeout);
  1355. /* Get the NOR memory operation status -------------------------------------*/
  1356. /* Get tick */
  1357. tickstart = HAL_GetTick();
  1358. if (hnor->CommandSet == NOR_AMD_FUJITSU_COMMAND_SET)
  1359. {
  1360. while ((status != HAL_NOR_STATUS_SUCCESS) && (status != HAL_NOR_STATUS_TIMEOUT))
  1361. {
  1362. /* Check for the Timeout */
  1363. if (Timeout != HAL_MAX_DELAY)
  1364. {
  1365. if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
  1366. {
  1367. status = HAL_NOR_STATUS_TIMEOUT;
  1368. }
  1369. }
  1370. /* Read NOR status register (DQ6 and DQ5) */
  1371. tmpsr1 = *(__IO uint16_t *)Address;
  1372. tmpsr2 = *(__IO uint16_t *)Address;
  1373. /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
  1374. if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6))
  1375. {
  1376. return HAL_NOR_STATUS_SUCCESS ;
  1377. }
  1378. if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
  1379. {
  1380. status = HAL_NOR_STATUS_ONGOING;
  1381. }
  1382. tmpsr1 = *(__IO uint16_t *)Address;
  1383. tmpsr2 = *(__IO uint16_t *)Address;
  1384. /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
  1385. if ((tmpsr1 & NOR_MASK_STATUS_DQ6) == (tmpsr2 & NOR_MASK_STATUS_DQ6))
  1386. {
  1387. return HAL_NOR_STATUS_SUCCESS;
  1388. }
  1389. if ((tmpsr1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
  1390. {
  1391. return HAL_NOR_STATUS_ERROR;
  1392. }
  1393. }
  1394. }
  1395. else if (hnor->CommandSet == NOR_INTEL_SHARP_EXT_COMMAND_SET)
  1396. {
  1397. do
  1398. {
  1399. NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG);
  1400. tmpsr2 = *(__IO uint16_t *)(Address);
  1401. /* Check for the Timeout */
  1402. if (Timeout != HAL_MAX_DELAY)
  1403. {
  1404. if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
  1405. {
  1406. return HAL_NOR_STATUS_TIMEOUT;
  1407. }
  1408. }
  1409. } while ((tmpsr2 & NOR_MASK_STATUS_DQ7) == 0U);
  1410. NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG);
  1411. tmpsr1 = *(__IO uint16_t *)(Address);
  1412. if ((tmpsr1 & (NOR_MASK_STATUS_DQ5 | NOR_MASK_STATUS_DQ4)) != 0U)
  1413. {
  1414. /* Clear the Status Register */
  1415. NOR_WRITE(Address, NOR_CMD_READ_STATUS_REG);
  1416. status = HAL_NOR_STATUS_ERROR;
  1417. }
  1418. else
  1419. {
  1420. status = HAL_NOR_STATUS_SUCCESS;
  1421. }
  1422. }
  1423. else
  1424. {
  1425. /* Primary command set not supported by the driver */
  1426. status = HAL_NOR_STATUS_ERROR;
  1427. }
  1428. /* Return the operation status */
  1429. return status;
  1430. }
  1431. /**
  1432. * @}
  1433. */
  1434. /**
  1435. * @}
  1436. */
  1437. /**
  1438. * @}
  1439. */
  1440. #endif /* HAL_NOR_MODULE_ENABLED */
  1441. /**
  1442. * @}
  1443. */
  1444. #endif /* FSMC_BANK1 */