STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_nor.c
Go to the documentation of this file.
1 
85 /* Includes ------------------------------------------------------------------*/
86 #include "stm32f7xx_hal.h"
87 
96 #ifdef HAL_NOR_MODULE_ENABLED
97 
98 /* Private typedef -----------------------------------------------------------*/
99 /* Private define ------------------------------------------------------------*/
100 
105 /* Constants to define address to set to write a command */
106 #define NOR_CMD_ADDRESS_FIRST (uint16_t)0x0555
107 #define NOR_CMD_ADDRESS_FIRST_CFI (uint16_t)0x0055
108 #define NOR_CMD_ADDRESS_SECOND (uint16_t)0x02AA
109 #define NOR_CMD_ADDRESS_THIRD (uint16_t)0x0555
110 #define NOR_CMD_ADDRESS_FOURTH (uint16_t)0x0555
111 #define NOR_CMD_ADDRESS_FIFTH (uint16_t)0x02AA
112 #define NOR_CMD_ADDRESS_SIXTH (uint16_t)0x0555
113 
114 /* Constants to define data to program a command */
115 #define NOR_CMD_DATA_READ_RESET (uint16_t)0x00F0
116 #define NOR_CMD_DATA_FIRST (uint16_t)0x00AA
117 #define NOR_CMD_DATA_SECOND (uint16_t)0x0055
118 #define NOR_CMD_DATA_AUTO_SELECT (uint16_t)0x0090
119 #define NOR_CMD_DATA_PROGRAM (uint16_t)0x00A0
120 #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD (uint16_t)0x0080
121 #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH (uint16_t)0x00AA
122 #define NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH (uint16_t)0x0055
123 #define NOR_CMD_DATA_CHIP_ERASE (uint16_t)0x0010
124 #define NOR_CMD_DATA_CFI (uint16_t)0x0098
125 
126 #define NOR_CMD_DATA_BUFFER_AND_PROG (uint8_t)0x25
127 #define NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM (uint8_t)0x29
128 #define NOR_CMD_DATA_BLOCK_ERASE (uint8_t)0x30
129 
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 
138 /* Private macro -------------------------------------------------------------*/
139 /* Private variables ---------------------------------------------------------*/
144 static uint32_t uwNORMemoryDataWidth = NOR_MEMORY_8B;
145 
150 /* Private functions ---------------------------------------------------------*/
151 /* Exported functions --------------------------------------------------------*/
180 {
181  /* Check the NOR handle parameter */
182  if(hnor == NULL)
183  {
184  return HAL_ERROR;
185  }
186 
187  if(hnor->State == HAL_NOR_STATE_RESET)
188  {
189  /* Allocate lock resource and initialize it */
190  hnor->Lock = HAL_UNLOCKED;
191  /* Initialize the low level hardware (MSP) */
192  HAL_NOR_MspInit(hnor);
193  }
194 
195  /* Initialize NOR control Interface */
196  FMC_NORSRAM_Init(hnor->Instance, &(hnor->Init));
197 
198  /* Initialize NOR timing Interface */
199  FMC_NORSRAM_Timing_Init(hnor->Instance, Timing, hnor->Init.NSBank);
200 
201  /* Initialize NOR extended mode timing Interface */
202  FMC_NORSRAM_Extended_Timing_Init(hnor->Extended, ExtTiming, hnor->Init.NSBank, hnor->Init.ExtendedMode);
203 
204  /* Enable the NORSRAM device */
206 
207  /* Initialize NOR Memory Data Width*/
209  {
210  uwNORMemoryDataWidth = NOR_MEMORY_8B;
211  }
212  else
213  {
214  uwNORMemoryDataWidth = NOR_MEMORY_16B;
215  }
216 
217  /* Check the NOR controller state */
218  hnor->State = HAL_NOR_STATE_READY;
219 
220  return HAL_OK;
221 }
222 
230 {
231  /* De-Initialize the low level hardware (MSP) */
232  HAL_NOR_MspDeInit(hnor);
233 
234  /* Configure the NOR registers with their reset values */
235  FMC_NORSRAM_DeInit(hnor->Instance, hnor->Extended, hnor->Init.NSBank);
236 
237  /* Update the NOR controller state */
238  hnor->State = HAL_NOR_STATE_RESET;
239 
240  /* Release Lock */
241  __HAL_UNLOCK(hnor);
242 
243  return HAL_OK;
244 }
245 
252 __weak void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor)
253 {
254  /* Prevent unused argument(s) compilation warning */
255  UNUSED(hnor);
256 
257  /* NOTE : This function Should not be modified, when the callback is needed,
258  the HAL_NOR_MspInit could be implemented in the user file
259  */
260 }
261 
268 __weak void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor)
269 {
270  /* Prevent unused argument(s) compilation warning */
271  UNUSED(hnor);
272 
273  /* NOTE : This function Should not be modified, when the callback is needed,
274  the HAL_NOR_MspDeInit could be implemented in the user file
275  */
276 }
277 
285 __weak void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
286 {
287  /* Prevent unused argument(s) compilation warning */
288  UNUSED(hnor);
289  UNUSED(Timeout);
290 
291  /* NOTE : This function Should not be modified, when the callback is needed,
292  the HAL_NOR_MspWait could be implemented in the user file
293  */
294 }
295 
322 {
323  uint32_t deviceaddress = 0;
324 
325  /* Process Locked */
326  __HAL_LOCK(hnor);
327 
328  /* Check the NOR controller state */
329  if(hnor->State == HAL_NOR_STATE_BUSY)
330  {
331  return HAL_BUSY;
332  }
333 
334  /* Select the NOR device address */
335  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
336  {
337  deviceaddress = NOR_MEMORY_ADRESS1;
338  }
339  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
340  {
341  deviceaddress = NOR_MEMORY_ADRESS2;
342  }
343  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
344  {
345  deviceaddress = NOR_MEMORY_ADRESS3;
346  }
347  else /* FMC_NORSRAM_BANK4 */
348  {
349  deviceaddress = NOR_MEMORY_ADRESS4;
350  }
351 
352  /* Update the NOR controller state */
353  hnor->State = HAL_NOR_STATE_BUSY;
354 
355  /* Send read ID command */
356  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
357  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
358  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_AUTO_SELECT);
359 
360  /* Read the NOR IDs */
361  pNOR_ID->Manufacturer_Code = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, MC_ADDRESS);
362  pNOR_ID->Device_Code1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE1_ADDR);
363  pNOR_ID->Device_Code2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE2_ADDR);
364  pNOR_ID->Device_Code3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, DEVICE_CODE3_ADDR);
365 
366  /* Check the NOR controller state */
367  hnor->State = HAL_NOR_STATE_READY;
368 
369  /* Process unlocked */
370  __HAL_UNLOCK(hnor);
371 
372  return HAL_OK;
373 }
374 
382 {
383  uint32_t deviceaddress = 0;
384 
385  /* Process Locked */
386  __HAL_LOCK(hnor);
387 
388  /* Check the NOR controller state */
389  if(hnor->State == HAL_NOR_STATE_BUSY)
390  {
391  return HAL_BUSY;
392  }
393 
394  /* Select the NOR device address */
395  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
396  {
397  deviceaddress = NOR_MEMORY_ADRESS1;
398  }
399  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
400  {
401  deviceaddress = NOR_MEMORY_ADRESS2;
402  }
403  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
404  {
405  deviceaddress = NOR_MEMORY_ADRESS3;
406  }
407  else /* FMC_NORSRAM_BANK4 */
408  {
409  deviceaddress = NOR_MEMORY_ADRESS4;
410  }
411 
412  NOR_WRITE(deviceaddress, NOR_CMD_DATA_READ_RESET);
413 
414  /* Check the NOR controller state */
415  hnor->State = HAL_NOR_STATE_READY;
416 
417  /* Process unlocked */
418  __HAL_UNLOCK(hnor);
419 
420  return HAL_OK;
421 }
422 
431 HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
432 {
433  uint32_t deviceaddress = 0;
434 
435  /* Process Locked */
436  __HAL_LOCK(hnor);
437 
438  /* Check the NOR controller state */
439  if(hnor->State == HAL_NOR_STATE_BUSY)
440  {
441  return HAL_BUSY;
442  }
443 
444  /* Select the NOR device address */
445  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
446  {
447  deviceaddress = NOR_MEMORY_ADRESS1;
448  }
449  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
450  {
451  deviceaddress = NOR_MEMORY_ADRESS2;
452  }
453  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
454  {
455  deviceaddress = NOR_MEMORY_ADRESS3;
456  }
457  else /* FMC_NORSRAM_BANK4 */
458  {
459  deviceaddress = NOR_MEMORY_ADRESS4;
460  }
461 
462  /* Update the NOR controller state */
463  hnor->State = HAL_NOR_STATE_BUSY;
464 
465  /* Send read data command */
466  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
467  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
468  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
469 
470  /* Read the data */
471  *pData = *(__IO uint32_t *)(uint32_t)pAddress;
472 
473  /* Check the NOR controller state */
474  hnor->State = HAL_NOR_STATE_READY;
475 
476  /* Process unlocked */
477  __HAL_UNLOCK(hnor);
478 
479  return HAL_OK;
480 }
481 
490 HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
491 {
492  uint32_t deviceaddress = 0;
493 
494  /* Process Locked */
495  __HAL_LOCK(hnor);
496 
497  /* Check the NOR controller state */
498  if(hnor->State == HAL_NOR_STATE_BUSY)
499  {
500  return HAL_BUSY;
501  }
502 
503  /* Select the NOR device address */
504  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
505  {
506  deviceaddress = NOR_MEMORY_ADRESS1;
507  }
508  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
509  {
510  deviceaddress = NOR_MEMORY_ADRESS2;
511  }
512  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
513  {
514  deviceaddress = NOR_MEMORY_ADRESS3;
515  }
516  else /* FMC_NORSRAM_BANK4 */
517  {
518  deviceaddress = NOR_MEMORY_ADRESS4;
519  }
520 
521  /* Update the NOR controller state */
522  hnor->State = HAL_NOR_STATE_BUSY;
523 
524  /* Send program data command */
525  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
526  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
527  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_PROGRAM);
528 
529  /* Write the data */
530  NOR_WRITE(pAddress, *pData);
531 
532  /* Check the NOR controller state */
533  hnor->State = HAL_NOR_STATE_READY;
534 
535  /* Process unlocked */
536  __HAL_UNLOCK(hnor);
537 
538  return HAL_OK;
539 }
540 
550 HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
551 {
552  uint32_t deviceaddress = 0;
553 
554  /* Process Locked */
555  __HAL_LOCK(hnor);
556 
557  /* Check the NOR controller state */
558  if(hnor->State == HAL_NOR_STATE_BUSY)
559  {
560  return HAL_BUSY;
561  }
562 
563  /* Select the NOR device address */
564  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
565  {
566  deviceaddress = NOR_MEMORY_ADRESS1;
567  }
568  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
569  {
570  deviceaddress = NOR_MEMORY_ADRESS2;
571  }
572  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
573  {
574  deviceaddress = NOR_MEMORY_ADRESS3;
575  }
576  else /* FMC_NORSRAM_BANK4 */
577  {
578  deviceaddress = NOR_MEMORY_ADRESS4;
579  }
580 
581  /* Update the NOR controller state */
582  hnor->State = HAL_NOR_STATE_BUSY;
583 
584  /* Send read data command */
585  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
586  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
587  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_READ_RESET);
588 
589  /* Read buffer */
590  while( uwBufferSize > 0)
591  {
592  *pData++ = *(__IO uint16_t *)uwAddress;
593  uwAddress += 2;
594  uwBufferSize--;
595  }
596 
597  /* Check the NOR controller state */
598  hnor->State = HAL_NOR_STATE_READY;
599 
600  /* Process unlocked */
601  __HAL_UNLOCK(hnor);
602 
603  return HAL_OK;
604 }
605 
615 HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
616 {
617  uint16_t * p_currentaddress = (uint16_t *)NULL;
618  uint16_t * p_endaddress = (uint16_t *)NULL;
619  uint32_t lastloadedaddress = 0, deviceaddress = 0;
620 
621  /* Process Locked */
622  __HAL_LOCK(hnor);
623 
624  /* Check the NOR controller state */
625  if(hnor->State == HAL_NOR_STATE_BUSY)
626  {
627  return HAL_BUSY;
628  }
629 
630  /* Select the NOR device address */
631  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
632  {
633  deviceaddress = NOR_MEMORY_ADRESS1;
634  }
635  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
636  {
637  deviceaddress = NOR_MEMORY_ADRESS2;
638  }
639  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
640  {
641  deviceaddress = NOR_MEMORY_ADRESS3;
642  }
643  else /* FMC_NORSRAM_BANK4 */
644  {
645  deviceaddress = NOR_MEMORY_ADRESS4;
646  }
647 
648  /* Update the NOR controller state */
649  hnor->State = HAL_NOR_STATE_BUSY;
650 
651  /* Initialize variables */
652  p_currentaddress = (uint16_t*)((uint32_t)(uwAddress));
653  p_endaddress = p_currentaddress + (uwBufferSize-1);
654  lastloadedaddress = (uint32_t)(uwAddress);
655 
656  /* Issue unlock command sequence */
657  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
658  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
659 
660  /* Write Buffer Load Command */
661  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, uwAddress), NOR_CMD_DATA_BUFFER_AND_PROG);
662  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, uwAddress), (uwBufferSize - 1));
663 
664  /* Load Data into NOR Buffer */
665  while(p_currentaddress <= p_endaddress)
666  {
667  /* Store last loaded address & data value (for polling) */
668  lastloadedaddress = (uint32_t)p_currentaddress;
669 
670  NOR_WRITE(p_currentaddress, *pData++);
671 
672  p_currentaddress ++;
673  }
674 
675  NOR_WRITE((uint32_t)(lastloadedaddress), NOR_CMD_DATA_BUFFER_AND_PROG_CONFIRM);
676 
677  /* Check the NOR controller state */
678  hnor->State = HAL_NOR_STATE_READY;
679 
680  /* Process unlocked */
681  __HAL_UNLOCK(hnor);
682 
683  return HAL_OK;
684 
685 }
686 
695 HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
696 {
697  uint32_t deviceaddress = 0;
698 
699  /* Process Locked */
700  __HAL_LOCK(hnor);
701 
702  /* Check the NOR controller state */
703  if(hnor->State == HAL_NOR_STATE_BUSY)
704  {
705  return HAL_BUSY;
706  }
707 
708  /* Select the NOR device address */
709  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
710  {
711  deviceaddress = NOR_MEMORY_ADRESS1;
712  }
713  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
714  {
715  deviceaddress = NOR_MEMORY_ADRESS2;
716  }
717  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
718  {
719  deviceaddress = NOR_MEMORY_ADRESS3;
720  }
721  else /* FMC_NORSRAM_BANK4 */
722  {
723  deviceaddress = NOR_MEMORY_ADRESS4;
724  }
725 
726  /* Update the NOR controller state */
727  hnor->State = HAL_NOR_STATE_BUSY;
728 
729  /* Send block erase command sequence */
730  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
731  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
732  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
733  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
734  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
735  NOR_WRITE((uint32_t)(BlockAddress + Address), NOR_CMD_DATA_BLOCK_ERASE);
736 
737  /* Check the NOR memory status and update the controller state */
738  hnor->State = HAL_NOR_STATE_READY;
739 
740  /* Process unlocked */
741  __HAL_UNLOCK(hnor);
742 
743  return HAL_OK;
744 
745 }
746 
755 {
756  uint32_t deviceaddress = 0;
757 
758  /* Process Locked */
759  __HAL_LOCK(hnor);
760 
761  /* Check the NOR controller state */
762  if(hnor->State == HAL_NOR_STATE_BUSY)
763  {
764  return HAL_BUSY;
765  }
766 
767  /* Select the NOR device address */
768  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
769  {
770  deviceaddress = NOR_MEMORY_ADRESS1;
771  }
772  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
773  {
774  deviceaddress = NOR_MEMORY_ADRESS2;
775  }
776  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
777  {
778  deviceaddress = NOR_MEMORY_ADRESS3;
779  }
780  else /* FMC_NORSRAM_BANK4 */
781  {
782  deviceaddress = NOR_MEMORY_ADRESS4;
783  }
784 
785  /* Update the NOR controller state */
786  hnor->State = HAL_NOR_STATE_BUSY;
787 
788  /* Send NOR chip erase command sequence */
789  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST), NOR_CMD_DATA_FIRST);
790  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SECOND), NOR_CMD_DATA_SECOND);
791  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_THIRD), NOR_CMD_DATA_CHIP_BLOCK_ERASE_THIRD);
792  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FOURTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FOURTH);
793  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIFTH), NOR_CMD_DATA_CHIP_BLOCK_ERASE_FIFTH);
794  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_SIXTH), NOR_CMD_DATA_CHIP_ERASE);
795 
796  /* Check the NOR memory status and update the controller state */
797  hnor->State = HAL_NOR_STATE_READY;
798 
799  /* Process unlocked */
800  __HAL_UNLOCK(hnor);
801 
802  return HAL_OK;
803 }
804 
813 {
814  uint32_t deviceaddress = 0;
815 
816  /* Process Locked */
817  __HAL_LOCK(hnor);
818 
819  /* Check the NOR controller state */
820  if(hnor->State == HAL_NOR_STATE_BUSY)
821  {
822  return HAL_BUSY;
823  }
824 
825  /* Select the NOR device address */
826  if (hnor->Init.NSBank == FMC_NORSRAM_BANK1)
827  {
828  deviceaddress = NOR_MEMORY_ADRESS1;
829  }
830  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK2)
831  {
832  deviceaddress = NOR_MEMORY_ADRESS2;
833  }
834  else if (hnor->Init.NSBank == FMC_NORSRAM_BANK3)
835  {
836  deviceaddress = NOR_MEMORY_ADRESS3;
837  }
838  else /* FMC_NORSRAM_BANK4 */
839  {
840  deviceaddress = NOR_MEMORY_ADRESS4;
841  }
842 
843  /* Update the NOR controller state */
844  hnor->State = HAL_NOR_STATE_BUSY;
845 
846  /* Send read CFI query command */
847  NOR_WRITE(NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, NOR_CMD_ADDRESS_FIRST_CFI), NOR_CMD_DATA_CFI);
848 
849  /* read the NOR CFI information */
850  pNOR_CFI->CFI_1 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI1_ADDRESS);
851  pNOR_CFI->CFI_2 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI2_ADDRESS);
852  pNOR_CFI->CFI_3 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI3_ADDRESS);
853  pNOR_CFI->CFI_4 = *(__IO uint16_t *) NOR_ADDR_SHIFT(deviceaddress, uwNORMemoryDataWidth, CFI4_ADDRESS);
854 
855  /* Check the NOR controller state */
856  hnor->State = HAL_NOR_STATE_READY;
857 
858  /* Process unlocked */
859  __HAL_UNLOCK(hnor);
860 
861  return HAL_OK;
862 }
863 
890 {
891  /* Process Locked */
892  __HAL_LOCK(hnor);
893 
894  /* Enable write operation */
896 
897  /* Update the NOR controller state */
898  hnor->State = HAL_NOR_STATE_READY;
899 
900  /* Process unlocked */
901  __HAL_UNLOCK(hnor);
902 
903  return HAL_OK;
904 }
905 
913 {
914  /* Process Locked */
915  __HAL_LOCK(hnor);
916 
917  /* Update the SRAM controller state */
918  hnor->State = HAL_NOR_STATE_BUSY;
919 
920  /* Disable write operation */
922 
923  /* Update the NOR controller state */
925 
926  /* Process unlocked */
927  __HAL_UNLOCK(hnor);
928 
929  return HAL_OK;
930 }
931 
958 {
959  return hnor->State;
960 }
961 
971 HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
972 {
974  uint16_t tmpSR1 = 0, tmpSR2 = 0;
975  uint32_t tickstart = 0;
976 
977  /* Poll on NOR memory Ready/Busy signal ------------------------------------*/
978  HAL_NOR_MspWait(hnor, Timeout);
979 
980  /* Get the NOR memory operation status -------------------------------------*/
981 
982  /* Get tick */
983  tickstart = HAL_GetTick();
984  while((status != HAL_NOR_STATUS_SUCCESS ) && (status != HAL_NOR_STATUS_TIMEOUT))
985  {
986  /* Check for the Timeout */
987  if(Timeout != HAL_MAX_DELAY)
988  {
989  if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
990  {
991  status = HAL_NOR_STATUS_TIMEOUT;
992  }
993  }
994 
995  /* Read NOR status register (DQ6 and DQ5) */
996  tmpSR1 = *(__IO uint16_t *)Address;
997  tmpSR2 = *(__IO uint16_t *)Address;
998 
999  /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
1000  if((tmpSR1 & NOR_MASK_STATUS_DQ6) == (tmpSR2 & NOR_MASK_STATUS_DQ6))
1001  {
1002  return HAL_NOR_STATUS_SUCCESS ;
1003  }
1004 
1005  if((tmpSR1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
1006  {
1007  status = HAL_NOR_STATUS_ONGOING;
1008  }
1009 
1010  tmpSR1 = *(__IO uint16_t *)Address;
1011  tmpSR2 = *(__IO uint16_t *)Address;
1012 
1013  /* If DQ6 did not toggle between the two reads then return HAL_NOR_STATUS_SUCCESS */
1014  if((tmpSR1 & NOR_MASK_STATUS_DQ6) == (tmpSR2 & NOR_MASK_STATUS_DQ6))
1015  {
1016  return HAL_NOR_STATUS_SUCCESS;
1017  }
1018  if((tmpSR1 & NOR_MASK_STATUS_DQ5) == NOR_MASK_STATUS_DQ5)
1019  {
1020  return HAL_NOR_STATUS_ERROR;
1021  }
1022  }
1023 
1024  /* Return the operation status */
1025  return status;
1026 }
1027 
1035 #endif /* HAL_NOR_MODULE_ENABLED */
1036 
1044 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef FMC_NORSRAM_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_InitTypeDef *Init)
#define FMC_NORSRAM_BANK1
#define NOR_MEMORY_ADRESS1
#define CFI4_ADDRESS
HAL_StatusTypeDef HAL_NOR_Erase_Block(NOR_HandleTypeDef *hnor, uint32_t BlockAddress, uint32_t Address)
uint16_t Device_Code1
#define __FMC_NORSRAM_ENABLE(__INSTANCE__, __BANK__)
Enable the NORSRAM device access.
uint16_t Device_Code3
HAL_StatusTypeDef HAL_NOR_ProgramBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
#define __HAL_UNLOCK(__HANDLE__)
HAL_NOR_StatusTypeDef HAL_NOR_GetStatus(NOR_HandleTypeDef *hnor, uint32_t Address, uint32_t Timeout)
#define CFI3_ADDRESS
#define CFI2_ADDRESS
NOR handle Structure definition.
HAL_NOR_StatusTypeDef
FMC NOR Status typedef.
HAL_StatusTypeDef HAL_NOR_Init(NOR_HandleTypeDef *hnor, FMC_NORSRAM_TimingTypeDef *Timing, FMC_NORSRAM_TimingTypeDef *ExtTiming)
HAL_StatusTypeDef HAL_NOR_Read_CFI(NOR_HandleTypeDef *hnor, NOR_CFITypeDef *pNOR_CFI)
HAL_StatusTypeDef HAL_NOR_Read(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
#define NOR_WRITE(__ADDRESS__, __DATA__)
NOR memory write data to specified address.
void HAL_NOR_MspWait(NOR_HandleTypeDef *hnor, uint32_t Timeout)
#define NOR_MEMORY_ADRESS4
#define NOR_MEMORY_ADRESS3
#define CFI1_ADDRESS
FMC NORSRAM Timing parameters structure definition.
FMC NOR CFI typedef.
FMC_NORSRAM_EXTENDED_TypeDef * Extended
#define __HAL_LOCK(__HANDLE__)
__IO HAL_NOR_StateTypeDef State
#define NULL
Definition: usbd_def.h:53
#define HAL_MAX_DELAY
FMC_NORSRAM_InitTypeDef Init
#define __IO
Definition: core_cm0.h:213
HAL_StatusTypeDef HAL_NOR_WriteOperation_Disable(NOR_HandleTypeDef *hnor)
HAL_StatusTypeDef FMC_NORSRAM_Timing_Init(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank)
#define DEVICE_CODE3_ADDR
#define DEVICE_CODE2_ADDR
This file contains all the functions prototypes for the HAL module driver.
#define NOR_MEMORY_ADRESS2
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Disable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
#define MC_ADDRESS
HAL_StatusTypeDef HAL_NOR_Erase_Chip(NOR_HandleTypeDef *hnor, uint32_t Address)
HAL_NOR_StateTypeDef
HAL SRAM State structures definition.
#define DEVICE_CODE1_ADDR
#define FMC_NORSRAM_BANK3
#define UNUSED(x)
#define FMC_NORSRAM_BANK2
HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable(NOR_HandleTypeDef *hnor)
HAL_LockTypeDef Lock
HAL_StatusTypeDef HAL_NOR_DeInit(NOR_HandleTypeDef *hnor)
HAL_StatusTypeDef HAL_NOR_ReadBuffer(NOR_HandleTypeDef *hnor, uint32_t uwAddress, uint16_t *pData, uint32_t uwBufferSize)
HAL_StatusTypeDef HAL_NOR_ReturnToReadMode(NOR_HandleTypeDef *hnor)
HAL_StatusTypeDef FMC_NORSRAM_WriteOperation_Enable(FMC_NORSRAM_TypeDef *Device, uint32_t Bank)
HAL_StatusTypeDef FMC_NORSRAM_Extended_Timing_Init(FMC_NORSRAM_EXTENDED_TypeDef *Device, FMC_NORSRAM_TimingTypeDef *Timing, uint32_t Bank, uint32_t ExtendedMode)
HAL_StatusTypeDef HAL_NOR_Read_ID(NOR_HandleTypeDef *hnor, NOR_IDTypeDef *pNOR_ID)
FMC NOR ID typedef.
HAL_StatusTypeDef FMC_NORSRAM_DeInit(FMC_NORSRAM_TypeDef *Device, FMC_NORSRAM_EXTENDED_TypeDef *ExDevice, uint32_t Bank)
HAL_StatusTypeDef HAL_NOR_Program(NOR_HandleTypeDef *hnor, uint32_t *pAddress, uint16_t *pData)
void HAL_NOR_MspDeInit(NOR_HandleTypeDef *hnor)
#define FMC_NORSRAM_MEM_BUS_WIDTH_8
FMC_NORSRAM_TypeDef * Instance
HAL_StatusTypeDef
HAL Status structures definition.
uint16_t Device_Code2
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
#define NOR_MEMORY_8B
#define NOR_ADDR_SHIFT(__NOR_ADDRESS, __NOR_MEMORY_WIDTH_, __ADDRESS__)
NOR memory address shifting.
uint16_t Manufacturer_Code
#define NOR_MEMORY_16B
HAL_NOR_StateTypeDef HAL_NOR_GetState(NOR_HandleTypeDef *hnor)
void HAL_NOR_MspInit(NOR_HandleTypeDef *hnor)