STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_nor.c
Go to the documentation of this file.
1 
67 /* Includes ------------------------------------------------------------------*/
68 #include "stm32l4xx_hal.h"
69 
70 #if defined(FMC_BANK1)
71 
76 #ifdef HAL_NOR_MODULE_ENABLED
77 
83 /* Private typedef -----------------------------------------------------------*/
84 /* Private define ------------------------------------------------------------*/
85 
90 /* Constants to define address to set to write a command */
91 #define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555
92 #define NOR_CMD_ADDRESS_FIRST_CFI (uint16_t)0x0055
93 #define NOR_CMD_ADDRESS_SECOND (uint16_t)0x02AA
94 #define NOR_CMD_ADDRESS_THIRD (uint16_t)0x0555
95 #define NOR_CMD_ADDRESS_FOURTH (uint16_t)0x0555
96 #define NOR_CMD_ADDRESS_FIFTH (uint16_t)0x02AA
97 #define NOR_CMD_ADDRESS_SIXTH (uint16_t)0x0555
98 
99 /* Constants to define data to program a command */
100 #define NOR_CMD_DATA_READ_RESET (uint16_t)0x00F0
101 #define NOR_CMD_DATA_FIRST (uint16_t)0x00AA
102 #define NOR_CMD_DATA_SECOND (uint16_t)0x0055
103 #define NOR_CMD_DATA_AUTO_SELECT (uint16_t)0x0090
104 #define NOR_CMD_DATA_PROGRAM (uint16_t)0x00A0
105 #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD (uint16_t)0x0080
106 #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH (uint16_t)0x00AA
107 #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH (uint16_t)0x0055
108 #define NOR_CMD_DATA_CHIP_ERASE (uint16_t)0x0010
109 #define NOR_CMD_DATA_CFI (uint16_t)0x0098
110 
111 #define NOR_CMD_DATA_BUFFER_AND_PROG (uint8_t)0x25
112 #define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM (uint8_t)0x29
113 #define NOR_CMD_DATA_BLOCK_ERASE (uint8_t)0x30
114 
115 /* Mask on NOR STATUS REGISTER */
116 #define NOR_MASK_STATUS_DQ5 (uint16_t)0x0020
117 #define NOR_MASK_STATUS_DQ6 (uint16_t)0x0040
118 
123 /* Private macro -------------------------------------------------------------*/
124 /* Private variables ---------------------------------------------------------*/
129 static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B;
130 
135 /* Private functions ---------------------------------------------------------*/
136 /* Exported functions --------------------------------------------------------*/
165 {
166  /* Check the NOR handle parameter */
167  if(hnor == NULL)
168  {
169  return HAL_ERROR;
170  }
171 
172  if(hnor->State == HAL_NOR_STATE_RESET)
173  {
174  /* Allocate lock resource and initialize it */
175  hnor->Lock = HAL_UNLOCKED;
176  /* Initialize the low level hardware (MSP) */
177  HAL_NOR_MspInit(hnor);
178  }
179 
180  /* Initialize NOR control Interface */
181  FMC_NORSRAM_Init(hnor->Instance, &(hnor->Init));
182 
183  /* Initialize NOR timing Interface */
184  FMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank);
185 
186  /* Initialize NOR extended mode timing Interface */
187  FMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming, hnor->Init.NSBank, hnor->Init.ExtendedMode);
188 
189  /* Enable the NORSRAM device */
190  __FMC_NORSRAM_ENABLE(hnor->Instance, hnor->Init.NSBank);
191 
192  /* Initialize NOR Memory Data Width*/
193  if (hnor->Init.MemoryDataWidth == FMC_NORSRAM_MEM_BUS_WIDTH_8)
194  {
195  uwNORMemoryDataWidth = NOR_MEMORY_8B;
196  }
197  else
198  {
199  uwNORMemoryDataWidth = NOR_MEMORY_16B;
200  }
201 
202  /* Check the NOR controller state */
203  hnor->State = HAL_NOR_STATE_READY;
204 
205  return HAL_OK;
206 }
207 
214 HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor)
215 {
216  /* De-Initialize the low level hardware (MSP) */
217  HAL_NOR_MspDeInit(hnor);
218 
219  /* Configure the NOR registers with their reset values */
220  FMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank);
221 
222  /* Update the NOR controller state */
223  hnor->State = HAL_NOR_STATE_RESET;
224 
225  /* Release Lock */
226  __HAL_UNLOCK(hnor);
227 
228  return HAL_OK;
229 }
230 
238 {
239  /* Prevent unused argument(s) compilation warning */
240  UNUSED(hnor);
241 
242  /* NOTE : This function should not be modified, when the callback is needed,
243  the HAL_NOR_MspInit could be implemented in the user file
244  */
245 }
246 
254 {
255  /* Prevent unused argument(s) compilation warning */
256  UNUSED(hnor);
257 
258  /* NOTE : This function should not be modified, when the callback is needed,
259  the HAL_NOR_MspDeInit could be implemented in the user file
260  */
261 }
262 
270 __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
271 {
272  /* Prevent unused argument(s) compilation warning */
273  UNUSED(hnor);
274  UNUSED(Timeout);
275 
276  /* NOTE : This function should not be modified, when the callback is needed,
277  the HAL_NOR_MspWait could be implemented in the user file
278  */
279 }
280 
306 HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID)
307 {
308  uint32_t deviceaddress = 0;
309 
310  /* Process Locked */
311  __HAL_LOCK(hnor);
312 
313  /* Check the NOR controller state */
314  if(hnor->State == HAL_NOR_STATE_BUSY)
315  {
316  return HAL_BUSY;
317  }
318 
319  /* Select the NOR device address */
320  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
321  {
322  deviceaddress = NOR_MEMORY_ADRESS1;
323  }
324  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
325  {
326  deviceaddress = NOR_MEMORY_ADRESS2;
327  }
328  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
329  {
330  deviceaddress = NOR_MEMORY_ADRESS3;
331  }
332  else /* FMC_NORSRAM_BANK4 */
333  {
334  deviceaddress = NOR_MEMORY_ADRESS4;
335  }
336 
337  /* Update the NOR controller state */
338  hnor->State = HAL_NOR_STATE_BUSY;
339 
340  /* Send read ID command */
341  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
342  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
343  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_AUTO_SELECT);
344 
345  /* Read the NOR IDs */
346  pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS);
347  pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE1_ADDR);
348  pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE2_ADDR);
349  pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE3_ADDR);
350 
351  /* Check the NOR controller state */
352  hnor->State = HAL_NOR_STATE_READY;
353 
354  /* Process unlocked */
355  __HAL_UNLOCK(hnor);
356 
357  return HAL_OK;
358 }
359 
367 {
368  uint32_t deviceaddress = 0;
369 
370  /* Process Locked */
371  __HAL_LOCK(hnor);
372 
373  /* Check the NOR controller state */
374  if(hnor->State == HAL_NOR_STATE_BUSY)
375  {
376  return HAL_BUSY;
377  }
378 
379  /* Select the NOR device address */
380  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
381  {
382  deviceaddress = NOR_MEMORY_ADRESS1;
383  }
384  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
385  {
386  deviceaddress = NOR_MEMORY_ADRESS2;
387  }
388  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
389  {
390  deviceaddress = NOR_MEMORY_ADRESS3;
391  }
392  else /* FMC_NORSRAM_BANK4 */
393  {
394  deviceaddress = NOR_MEMORY_ADRESS4;
395  }
396 
397  NOR_WRITE(deviceaddress, NOR_CMD_DATA_READ_RESET);
398 
399  /* Check the NOR controller state */
400  hnor->State = HAL_NOR_STATE_READY;
401 
402  /* Process unlocked */
403  __HAL_UNLOCK(hnor);
404 
405  return HAL_OK;
406 }
407 
416 HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
417 {
418  uint32_t deviceaddress = 0;
419 
420  /* Process Locked */
421  __HAL_LOCK(hnor);
422 
423  /* Check the NOR controller state */
424  if(hnor->State == HAL_NOR_STATE_BUSY)
425  {
426  return HAL_BUSY;
427  }
428 
429  /* Select the NOR device address */
430  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
431  {
432  deviceaddress = NOR_MEMORY_ADRESS1;
433  }
434  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
435  {
436  deviceaddress = NOR_MEMORY_ADRESS2;
437  }
438  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
439  {
440  deviceaddress = NOR_MEMORY_ADRESS3;
441  }
442  else /* FMC_NORSRAM_BANK4 */
443  {
444  deviceaddress = NOR_MEMORY_ADRESS4;
445  }
446 
447  /* Update the NOR controller state */
448  hnor->State = HAL_NOR_STATE_BUSY;
449 
450  /* Send read data command */
451  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
452  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
453  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
454 
455  /* Read the data */
456  *pData = *(__IO uint32_t *)(uint32_t)pAddress;
457 
458  /* Check the NOR controller state */
459  hnor->State = HAL_NOR_STATE_READY;
460 
461  /* Process unlocked */
462  __HAL_UNLOCK(hnor);
463 
464  return HAL_OK;
465 }
466 
475 HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
476 {
477  uint32_t deviceaddress = 0;
478 
479  /* Process Locked */
480  __HAL_LOCK(hnor);
481 
482  /* Check the NOR controller state */
483  if(hnor->State == HAL_NOR_STATE_BUSY)
484  {
485  return HAL_BUSY;
486  }
487 
488  /* Select the NOR device address */
489  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
490  {
491  deviceaddress = NOR_MEMORY_ADRESS1;
492  }
493  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
494  {
495  deviceaddress = NOR_MEMORY_ADRESS2;
496  }
497  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
498  {
499  deviceaddress = NOR_MEMORY_ADRESS3;
500  }
501  else /* FMC_NORSRAM_BANK4 */
502  {
503  deviceaddress = NOR_MEMORY_ADRESS4;
504  }
505 
506  /* Update the NOR controller state */
507  hnor->State = HAL_NOR_STATE_BUSY;
508 
509  /* Send program data command */
510  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
511  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
512  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM);
513 
514  /* Write the data */
515  NOR_WRITE(pAddress, *pData);
516 
517  /* Check the NOR controller state */
518  hnor->State = HAL_NOR_STATE_READY;
519 
520  /* Process unlocked */
521  __HAL_UNLOCK(hnor);
522 
523  return HAL_OK;
524 }
525 
535 HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
536 {
537  uint32_t deviceaddress = 0;
538 
539  /* Process Locked */
540  __HAL_LOCK(hnor);
541 
542  /* Check the NOR controller state */
543  if(hnor->State == HAL_NOR_STATE_BUSY)
544  {
545  return HAL_BUSY;
546  }
547 
548  /* Select the NOR device address */
549  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
550  {
551  deviceaddress = NOR_MEMORY_ADRESS1;
552  }
553  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
554  {
555  deviceaddress = NOR_MEMORY_ADRESS2;
556  }
557  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
558  {
559  deviceaddress = NOR_MEMORY_ADRESS3;
560  }
561  else /* FMC_NORSRAM_BANK4 */
562  {
563  deviceaddress = NOR_MEMORY_ADRESS4;
564  }
565 
566  /* Update the NOR controller state */
567  hnor->State = HAL_NOR_STATE_BUSY;
568 
569  /* Send read data command */
570  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
571  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
572  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
573 
574  /* Read buffer */
575  while( uwBufferSize > 0)
576  {
577  *pData++ = *(__IO uint16_t *)uwAddress;
578  uwAddress += 2;
579  uwBufferSize--;
580  }
581 
582  /* Check the NOR controller state */
583  hnor->State = HAL_NOR_STATE_READY;
584 
585  /* Process unlocked */
586  __HAL_UNLOCK(hnor);
587 
588  return HAL_OK;
589 }
590 
600 HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
601 {
602  uint16_t * p_currentaddress = (uint16_t *)NULL;
603  uint16_t * p_endaddress = (uint16_t *)NULL;
604  uint32_t lastloadedaddress = 0, deviceaddress = 0;
605 
606  /* Process Locked */
607  __HAL_LOCK(hnor);
608 
609  /* Check the NOR controller state */
610  if(hnor->State == HAL_NOR_STATE_BUSY)
611  {
612  return HAL_BUSY;
613  }
614 
615  /* Select the NOR device address */
616  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
617  {
618  deviceaddress = NOR_MEMORY_ADRESS1;
619  }
620  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
621  {
622  deviceaddress = NOR_MEMORY_ADRESS2;
623  }
624  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
625  {
626  deviceaddress = NOR_MEMORY_ADRESS3;
627  }
628  else /* FMC_NORSRAM_BANK4 */
629  {
630  deviceaddress = NOR_MEMORY_ADRESS4;
631  }
632 
633  /* Update the NOR controller state */
634  hnor->State = HAL_NOR_STATE_BUSY;
635 
636  /* Initialize variables */
637  p_currentaddress = (uint16_t*)((uint32_t)(uwAddress));
638  p_endaddress = p_currentaddress + (uwBufferSize-1);
639  lastloadedaddress = (uint32_t)(uwAddress);
640 
641  /* Issue unlock command sequence */
642  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
643  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
644 
645  /* Write Buffer Load Command */
646  NOR_WRITE((uint32_t)(p_currentaddress), NOR_CMD_DATA_BUFFER_AND_PROG);
647  NOR_WRITE((uint32_t)(p_currentaddress), (uwBufferSize-1));
648 
649  /* Load Data into NOR Buffer */
650  while(p_currentaddress <= p_endaddress)
651  {
652  /* Store last loaded address & data value (for polling) */
653  lastloadedaddress = (uint32_t)p_currentaddress;
654 
655  NOR_WRITE(p_currentaddress, *pData++);
656 
657  p_currentaddress++;
658  }
659 
660  NOR_WRITE((uint32_t)(lastloadedaddress), NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM);
661 
662  /* Check the NOR controller state */
663  hnor->State = HAL_NOR_STATE_READY;
664 
665  /* Process unlocked */
666  __HAL_UNLOCK(hnor);
667 
668  return HAL_OK;
669 
670 }
671 
680 HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
681 {
682  uint32_t deviceaddress = 0;
683 
684  /* Process Locked */
685  __HAL_LOCK(hnor);
686 
687  /* Check the NOR controller state */
688  if(hnor->State == HAL_NOR_STATE_BUSY)
689  {
690  return HAL_BUSY;
691  }
692 
693  /* Select the NOR device address */
694  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
695  {
696  deviceaddress = NOR_MEMORY_ADRESS1;
697  }
698  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
699  {
700  deviceaddress = NOR_MEMORY_ADRESS2;
701  }
702  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
703  {
704  deviceaddress = NOR_MEMORY_ADRESS3;
705  }
706  else /* FMC_NORSRAM_BANK4 */
707  {
708  deviceaddress = NOR_MEMORY_ADRESS4;
709  }
710 
711  /* Update the NOR controller state */
712  hnor->State = HAL_NOR_STATE_BUSY;
713 
714  /* Send block erase command sequence */
715  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
716  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
717  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
718  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
719  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
720  NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE);
721 
722  /* Check the NOR memory status and update the controller state */
723  hnor->State = HAL_NOR_STATE_READY;
724 
725  /* Process unlocked */
726  __HAL_UNLOCK(hnor);
727 
728  return HAL_OK;
729 
730 }
731 
739 HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
740 {
741  uint32_t deviceaddress = 0;
742 
743  /* Prevent unused argument(s) compilation warning */
744  UNUSED(Address);
745 
746  /* Process Locked */
747  __HAL_LOCK(hnor);
748 
749  /* Check the NOR controller state */
750  if(hnor->State == HAL_NOR_STATE_BUSY)
751  {
752  return HAL_BUSY;
753  }
754 
755  /* Select the NOR device address */
756  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
757  {
758  deviceaddress = NOR_MEMORY_ADRESS1;
759  }
760  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
761  {
762  deviceaddress = NOR_MEMORY_ADRESS2;
763  }
764  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
765  {
766  deviceaddress = NOR_MEMORY_ADRESS3;
767  }
768  else /* FMC_NORSRAM_BANK4 */
769  {
770  deviceaddress = NOR_MEMORY_ADRESS4;
771  }
772 
773  /* Update the NOR controller state */
774  hnor->State = HAL_NOR_STATE_BUSY;
775 
776  /* Send NOR chip erase command sequence */
777  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
778  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
779  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
780  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
781  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
782  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH), NOR_CMD_DATA_CHIP_ERASE);
783 
784  /* Check the NOR memory status and update the controller state */
785  hnor->State = HAL_NOR_STATE_READY;
786 
787  /* Process unlocked */
788  __HAL_UNLOCK(hnor);
789 
790  return HAL_OK;
791 }
792 
800 HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI)
801 {
802  uint32_t deviceaddress = 0;
803 
804  /* Process Locked */
805  __HAL_LOCK(hnor);
806 
807  /* Check the NOR controller state */
808  if(hnor->State == HAL_NOR_STATE_BUSY)
809  {
810  return HAL_BUSY;
811  }
812 
813  /* Select the NOR device address */
814  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
815  {
816  deviceaddress = NOR_MEMORY_ADRESS1;
817  }
818  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
819  {
820  deviceaddress = NOR_MEMORY_ADRESS2;
821  }
822  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
823  {
824  deviceaddress = NOR_MEMORY_ADRESS3;
825  }
826  else /* FMC_NORSRAM_BANK4 */
827  {
828  deviceaddress = NOR_MEMORY_ADRESS4;
829  }
830 
831  /* Update the NOR controller state */
832  hnor->State = HAL_NOR_STATE_BUSY;
833 
834  /* Send read CFI query command */
835  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
836 
837  /* read the NOR CFI information */
838  pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS);
839  pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS);
840  pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS);
841  pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS);
842 
843  /* Check the NOR controller state */
844  hnor->State = HAL_NOR_STATE_READY;
845 
846  /* Process unlocked */
847  __HAL_UNLOCK(hnor);
848 
849  return HAL_OK;
850 }
851 
878 {
879  /* Process Locked */
880  __HAL_LOCK(hnor);
881 
882  /* Enable write operation */
884 
885  /* Update the NOR controller state */
886  hnor->State = HAL_NOR_STATE_READY;
887 
888  /* Process unlocked */
889  __HAL_UNLOCK(hnor);
890 
891  return HAL_OK;
892 }
893 
901 {
902  /* Process Locked */
903  __HAL_LOCK(hnor);
904 
905  /* Update the SRAM controller state */
906  hnor->State = HAL_NOR_STATE_BUSY;
907 
908  /* Disable write operation */
910 
911  /* Update the NOR controller state */
912  hnor->State = HAL_NOR_STATE_PROTECTED;
913 
914  /* Process unlocked */
915  __HAL_UNLOCK(hnor);
916 
917  return HAL_OK;
918 }
919 
945 HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor)
946 {
947  /* Return NOR handle state */
948  return hnor->State;
949 }
950 
960 HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
961 {
963  uint16_t tmpSR1 = 0, tmpSR2 = 0;
964  uint32_t tickstart = 0;
965 
966  /* Poll on NOR memory Ready/Busy signal ------------------------------------*/
967  HAL_NOR_MspWait(hnor, Timeout);
968 
969  /* Get the NOR memory operation status -------------------------------------*/
970 
971  /* Get tick */
972  tickstart = HAL_GetTick();
973  while((status != HAL_NOR_STATUS_SUCCESS) && (status != HAL_NOR_STATUS_TIMEOUT))
974  {
975  /* Check for the Timeout */
976  if(Timeout != HAL_MAX_DELAY)
977  {
978  if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
979  {
980  status = HAL_NOR_STATUS_TIMEOUT;
981  }
982  }
983 
984  /* Read NOR status register (DQ6 and DQ5) */
985  tmpSR1 = *(__IO uint16_t *)Address;
986  tmpSR2 = *(__IO uint16_t *)Address;
987 
988  /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
989  if ((tmpSR1 & NOR_MASK_STATUS_DQ6) == (tmpSR2 & NOR_MASK_STATUS_DQ6))
990  {
991  return HAL_NOR_STATUS_SUCCESS;
992  }
993 
994  if((tmpSR1 & NOR_MASK_STATUS_DQ5) != NOR_MASK_STATUS_DQ5)
995  {
996  status = HAL_NOR_STATUS_ONGOING;
997  }
998 
999  tmpSR1 = *(__IO uint16_t *)Address;
1000  tmpSR2 = *(__IO uint16_t *)Address;
1001 
1002  /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
1003  if ((tmpSR1 & NOR_MASK_STATUS_DQ6) == (tmpSR2 & NOR_MASK_STATUS_DQ6))
1004  {
1005  return HAL_NOR_STATUS_SUCCESS;
1006  }
1007  if ((tmpSR1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
1008  {
1009  return HAL_NOR_STATUS_ERROR;
1010  }
1011  }
1012 
1013  /* Return the operation status */
1014  return status;
1015 }
1016 
1029 #endif /* HAL_NOR_MODULE_ENABLED */
1030 
1035 #endif /* FMC_BANK1 */
1036 
1037 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor)
Perform NOR memory De-Initialization sequence.
FMC_NORSRAM_TypeDef * Instance
static uint32_t uwNORMemoryDataWidth
void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
NOR MSP Wait for Ready/Busy signal.
FMC NOR CFI typedef.
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
Erase the specified block of the NOR memory.
HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
Return the NOR operation status.
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
Writes a half-word buffer to the NOR memory. This function must be used only with S29GL128P NOR memor...
uint16_t Device_Code1
__HAL_LOCK(hrtc)
HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
Perform the NOR memory Initialization sequence.
HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
Read a half-word buffer from the NOR memory.
HAL_StatusTypeDef FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
DeInitialize the FMC_NORSRAM peripheral.
uint16_t Manufacturer_Code
FMC_NORSRAM_EXTENDED_TypeDef * Extended
return HAL_OK
HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor)
Enable dynamically NOR write operation.
HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID)
Read NOR flash IDs.
HAL_NOR_StatusTypeDef
FMC NOR Status typedef.
HAL_StatusTypeDef FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank, uint32_t ExtendedMode)
Initialize the FMC_NORSRAM Extended mode Timing according to the specified parameters in the FMC_NORS...
FMC_NORSRAM_InitTypeDef Init
HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
Erase the entire NOR chip.
FMC NORSRAM Timing parameters structure definition.
HAL_StatusTypeDef FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_InitTypeDef *Init)
Initialize the FMC_NORSRAM device according to the specified control parameters in the FMC_NORSRAM_In...
HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor)
Return the NOR memory to Read mode.
HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
Program data to NOR memory.
FMC NOR ID typedef.
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
Disables dynamically FMC_NORSRAM write operation.
HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor)
Disable dynamically NOR write operation.
HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI)
Read NOR flash CFI IDs.
HAL_StatusTypeDef FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
Initialize the FMC_NORSRAM Timing according to the specified parameters in the FMC_NORSRAM_TimingType...
uint16_t Device_Code3
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
Enables dynamically FMC_NORSRAM write operation.
void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor)
DeInitialize the NOR MSP.
HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor)
Return the NOR controller state.
uint16_t Device_Code2
void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor)
Initialize the NOR MSP.
__IO HAL_NOR_StateTypeDef State
HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
Read data from NOR memory.
HAL_LockTypeDef Lock
NOR handle Structure definition.