Nat Jeffries / FixOV9655Drivers
Revision:
8:56384bddaba5
Parent:
6:e1d9da7fe856
--- a/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_qspi.c	Thu Nov 10 10:05:52 2016 +0100
+++ b/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_qspi.c	Thu Feb 23 14:14:09 2017 +0100
@@ -2,8 +2,8 @@
   ******************************************************************************
   * @file    stm32746g_discovery_qspi.c
   * @author  MCD Application Team
-  * @version V1.1.1
-  * @date    02-June-2016
+  * @version V2.0.0
+  * @date    30-December-2016
   * @brief   This file includes a standard driver for the N25Q128A QSPI
   *          memory mounted on STM32746G-Discovery board.
   @verbatim
@@ -133,7 +133,7 @@
   QSPIHandle.Init.FifoThreshold      = 4;
   QSPIHandle.Init.SampleShifting     = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
   QSPIHandle.Init.FlashSize          = POSITION_VAL(N25Q128A_FLASH_SIZE) - 1;
-  QSPIHandle.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_2_CYCLE;
+  QSPIHandle.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_6_CYCLE; /* Min 50ns for nonRead */
   QSPIHandle.Init.ClockMode          = QSPI_CLOCK_MODE_0;
   QSPIHandle.Init.FlashID            = QSPI_FLASH_ID_1;
   QSPIHandle.Init.DualFlash          = QSPI_DUALFLASH_DISABLE;
@@ -209,11 +209,17 @@
     return QSPI_ERROR;
   }
   
+  /* Set S# timing for Read command */
+  MODIFY_REG(QSPIHandle.Instance->DCR, QUADSPI_DCR_CSHT, QSPI_CS_HIGH_TIME_3_CYCLE);
+  
   /* Reception of the data */
   if (HAL_QSPI_Receive(&QSPIHandle, pData, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
   {
     return QSPI_ERROR;
   }
+  
+  /* Restore S# timing for nonRead commands */
+  MODIFY_REG(QSPIHandle.Instance->DCR, QUADSPI_DCR_CSHT, QSPI_CS_HIGH_TIME_6_CYCLE);
 
   return QSPI_OK;
 }
@@ -231,13 +237,7 @@
   uint32_t end_addr, current_size, current_addr;
 
   /* Calculation of the size between the write address and the end of the page */
-  current_addr = 0;
-
-  while (current_addr <= WriteAddr)
-  {
-    current_addr += N25Q128A_PAGE_SIZE;
-  }
-  current_size = current_addr - WriteAddr;
+  current_size = N25Q128A_PAGE_SIZE - (WriteAddr % N25Q128A_PAGE_SIZE);
 
   /* Check if the size of the data is less than the remaining place in the page */
   if (current_size > Size)