STM32F469NI Discovery board drivers

Dependents:   DISCO-F469NI_LCDTS_GUI_demo Configurable_Robots DISCO-F469NI_LCD_demo DISCO-F469NI_SD_demo ... more

Committer:
Jerome Coutant
Date:
Tue May 16 10:50:26 2017 +0200
Revision:
2:123b894b49dd
Child:
3:3cdfcc4f7c9d
STM32Cube_FW_BSP_DISCO_F469NI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jerome Coutant 2:123b894b49dd 1 /**
Jerome Coutant 2:123b894b49dd 2 ******************************************************************************
Jerome Coutant 2:123b894b49dd 3 * @file stm32469i_discovery_qspi.c
Jerome Coutant 2:123b894b49dd 4 * @author MCD Application Team
Jerome Coutant 2:123b894b49dd 5 * @version V2.0.0
Jerome Coutant 2:123b894b49dd 6 * @date 27-January-2017
Jerome Coutant 2:123b894b49dd 7 * @brief This file includes a standard driver for the N25Q128A QSPI
Jerome Coutant 2:123b894b49dd 8 * memory mounted on STM32469I-Discovery board.
Jerome Coutant 2:123b894b49dd 9 @verbatim
Jerome Coutant 2:123b894b49dd 10 ==============================================================================
Jerome Coutant 2:123b894b49dd 11 ##### How to use this driver #####
Jerome Coutant 2:123b894b49dd 12 ==============================================================================
Jerome Coutant 2:123b894b49dd 13 [..]
Jerome Coutant 2:123b894b49dd 14 (#) This driver is used to drive the N25Q128A QSPI external
Jerome Coutant 2:123b894b49dd 15 memory mounted on STM32469I-Discovery board.
Jerome Coutant 2:123b894b49dd 16
Jerome Coutant 2:123b894b49dd 17 (#) This driver need a specific component driver N25Q128A to be included with.
Jerome Coutant 2:123b894b49dd 18
Jerome Coutant 2:123b894b49dd 19 (#) Initialization steps:
Jerome Coutant 2:123b894b49dd 20 (++) Initialize the QPSI external memory using the BSP_QSPI_Init() function. This
Jerome Coutant 2:123b894b49dd 21 function includes the MSP layer hardware resources initialization and the
Jerome Coutant 2:123b894b49dd 22 QSPI interface with the external memory.
Jerome Coutant 2:123b894b49dd 23
Jerome Coutant 2:123b894b49dd 24 (#) QSPI memory operations
Jerome Coutant 2:123b894b49dd 25 (++) QSPI memory can be accessed with read/write operations once it is
Jerome Coutant 2:123b894b49dd 26 initialized.
Jerome Coutant 2:123b894b49dd 27 Read/write operation can be performed with AHB access using the functions
Jerome Coutant 2:123b894b49dd 28 BSP_QSPI_Read()/BSP_QSPI_Write().
Jerome Coutant 2:123b894b49dd 29 (++) The function BSP_QSPI_GetInfo() returns the configuration of the QSPI memory.
Jerome Coutant 2:123b894b49dd 30 (see the QSPI memory data sheet)
Jerome Coutant 2:123b894b49dd 31 (++) Perform erase block operation using the function BSP_QSPI_Erase_Block() and by
Jerome Coutant 2:123b894b49dd 32 specifying the block address. You can perform an erase operation of the whole
Jerome Coutant 2:123b894b49dd 33 chip by calling the function BSP_QSPI_Erase_Chip().
Jerome Coutant 2:123b894b49dd 34 (++) The function BSP_QSPI_GetStatus() returns the current status of the QSPI memory.
Jerome Coutant 2:123b894b49dd 35 (see the QSPI memory data sheet)
Jerome Coutant 2:123b894b49dd 36 @endverbatim
Jerome Coutant 2:123b894b49dd 37 ******************************************************************************
Jerome Coutant 2:123b894b49dd 38 * @attention
Jerome Coutant 2:123b894b49dd 39 *
Jerome Coutant 2:123b894b49dd 40 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
Jerome Coutant 2:123b894b49dd 41 *
Jerome Coutant 2:123b894b49dd 42 * Redistribution and use in source and binary forms, with or without modification,
Jerome Coutant 2:123b894b49dd 43 * are permitted provided that the following conditions are met:
Jerome Coutant 2:123b894b49dd 44 * 1. Redistributions of source code must retain the above copyright notice,
Jerome Coutant 2:123b894b49dd 45 * this list of conditions and the following disclaimer.
Jerome Coutant 2:123b894b49dd 46 * 2. Redistributions in binary form must reproduce the above copyright notice,
Jerome Coutant 2:123b894b49dd 47 * this list of conditions and the following disclaimer in the documentation
Jerome Coutant 2:123b894b49dd 48 * and/or other materials provided with the distribution.
Jerome Coutant 2:123b894b49dd 49 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Jerome Coutant 2:123b894b49dd 50 * may be used to endorse or promote products derived from this software
Jerome Coutant 2:123b894b49dd 51 * without specific prior written permission.
Jerome Coutant 2:123b894b49dd 52 *
Jerome Coutant 2:123b894b49dd 53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Jerome Coutant 2:123b894b49dd 54 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Jerome Coutant 2:123b894b49dd 55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jerome Coutant 2:123b894b49dd 56 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Jerome Coutant 2:123b894b49dd 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Jerome Coutant 2:123b894b49dd 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Jerome Coutant 2:123b894b49dd 59 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Jerome Coutant 2:123b894b49dd 60 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Jerome Coutant 2:123b894b49dd 61 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Jerome Coutant 2:123b894b49dd 62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jerome Coutant 2:123b894b49dd 63 *
Jerome Coutant 2:123b894b49dd 64 ******************************************************************************
Jerome Coutant 2:123b894b49dd 65 */
Jerome Coutant 2:123b894b49dd 66
Jerome Coutant 2:123b894b49dd 67 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 2:123b894b49dd 68 #include "stm32469i_discovery_qspi.h"
Jerome Coutant 2:123b894b49dd 69
Jerome Coutant 2:123b894b49dd 70 /** @addtogroup BSP
Jerome Coutant 2:123b894b49dd 71 * @{
Jerome Coutant 2:123b894b49dd 72 */
Jerome Coutant 2:123b894b49dd 73
Jerome Coutant 2:123b894b49dd 74 /** @addtogroup STM32469I_Discovery
Jerome Coutant 2:123b894b49dd 75 * @{
Jerome Coutant 2:123b894b49dd 76 */
Jerome Coutant 2:123b894b49dd 77
Jerome Coutant 2:123b894b49dd 78 /** @defgroup STM32469I_Discovery_QSPI STM32469I Discovery QSPI
Jerome Coutant 2:123b894b49dd 79 * @{
Jerome Coutant 2:123b894b49dd 80 */
Jerome Coutant 2:123b894b49dd 81
Jerome Coutant 2:123b894b49dd 82
Jerome Coutant 2:123b894b49dd 83 /* Private variables ---------------------------------------------------------*/
Jerome Coutant 2:123b894b49dd 84
Jerome Coutant 2:123b894b49dd 85
Jerome Coutant 2:123b894b49dd 86 /** @defgroup STM32469I_Discovery_QSPI_Private_Variables STM32469I Discovery QSPI Private Variables
Jerome Coutant 2:123b894b49dd 87 * @{
Jerome Coutant 2:123b894b49dd 88 */
Jerome Coutant 2:123b894b49dd 89 QSPI_HandleTypeDef QSPIHandle;
Jerome Coutant 2:123b894b49dd 90
Jerome Coutant 2:123b894b49dd 91 /**
Jerome Coutant 2:123b894b49dd 92 * @}
Jerome Coutant 2:123b894b49dd 93 */
Jerome Coutant 2:123b894b49dd 94
Jerome Coutant 2:123b894b49dd 95
Jerome Coutant 2:123b894b49dd 96
Jerome Coutant 2:123b894b49dd 97 /* Private functions ---------------------------------------------------------*/
Jerome Coutant 2:123b894b49dd 98
Jerome Coutant 2:123b894b49dd 99 /** @defgroup STM32469I_Discovery_QSPI_Private_Functions STM32469I Discovery QSPI Private Functions
Jerome Coutant 2:123b894b49dd 100 * @{
Jerome Coutant 2:123b894b49dd 101 */
Jerome Coutant 2:123b894b49dd 102 static uint8_t QSPI_ResetMemory (QSPI_HandleTypeDef *hqspi);
Jerome Coutant 2:123b894b49dd 103 static uint8_t QSPI_DummyCyclesCfg (QSPI_HandleTypeDef *hqspi);
Jerome Coutant 2:123b894b49dd 104 static uint8_t QSPI_WriteEnable (QSPI_HandleTypeDef *hqspi);
Jerome Coutant 2:123b894b49dd 105 static uint8_t QSPI_AutoPollingMemReady (QSPI_HandleTypeDef *hqspi, uint32_t Timeout);
Jerome Coutant 2:123b894b49dd 106
Jerome Coutant 2:123b894b49dd 107
Jerome Coutant 2:123b894b49dd 108 /**
Jerome Coutant 2:123b894b49dd 109 * @}
Jerome Coutant 2:123b894b49dd 110 */
Jerome Coutant 2:123b894b49dd 111
Jerome Coutant 2:123b894b49dd 112 /** @defgroup STM32469I_Discovery_QSPI_Exported_Functions STM32469I Discovery QSPI Exported Functions
Jerome Coutant 2:123b894b49dd 113 * @{
Jerome Coutant 2:123b894b49dd 114 */
Jerome Coutant 2:123b894b49dd 115
Jerome Coutant 2:123b894b49dd 116 /**
Jerome Coutant 2:123b894b49dd 117 * @brief Initializes the QSPI interface.
Jerome Coutant 2:123b894b49dd 118 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 119 */
Jerome Coutant 2:123b894b49dd 120 uint8_t BSP_QSPI_Init(void)
Jerome Coutant 2:123b894b49dd 121 {
Jerome Coutant 2:123b894b49dd 122 QSPIHandle.Instance = QUADSPI;
Jerome Coutant 2:123b894b49dd 123
Jerome Coutant 2:123b894b49dd 124 /* Call the DeInit function to reset the driver */
Jerome Coutant 2:123b894b49dd 125 if (HAL_QSPI_DeInit(&QSPIHandle) != HAL_OK)
Jerome Coutant 2:123b894b49dd 126 {
Jerome Coutant 2:123b894b49dd 127 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 128 }
Jerome Coutant 2:123b894b49dd 129
Jerome Coutant 2:123b894b49dd 130 /* System level initialization */
Jerome Coutant 2:123b894b49dd 131 BSP_QSPI_MspInit(&QSPIHandle, NULL);
Jerome Coutant 2:123b894b49dd 132
Jerome Coutant 2:123b894b49dd 133 /* QSPI initialization */
Jerome Coutant 2:123b894b49dd 134 QSPIHandle.Init.ClockPrescaler = 1; /* QSPI Freq= 180 MHz / (1+1) = 90 MHz */
Jerome Coutant 2:123b894b49dd 135 QSPIHandle.Init.FifoThreshold = 1;
Jerome Coutant 2:123b894b49dd 136 QSPIHandle.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
Jerome Coutant 2:123b894b49dd 137 QSPIHandle.Init.FlashSize = POSITION_VAL(N25Q128A_FLASH_SIZE) - 1;
Jerome Coutant 2:123b894b49dd 138 QSPIHandle.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_5_CYCLE;
Jerome Coutant 2:123b894b49dd 139 QSPIHandle.Init.ClockMode = QSPI_CLOCK_MODE_0;
Jerome Coutant 2:123b894b49dd 140 QSPIHandle.Init.FlashID = QSPI_FLASH_ID_1;
Jerome Coutant 2:123b894b49dd 141 QSPIHandle.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
Jerome Coutant 2:123b894b49dd 142
Jerome Coutant 2:123b894b49dd 143 if (HAL_QSPI_Init(&QSPIHandle) != HAL_OK)
Jerome Coutant 2:123b894b49dd 144 {
Jerome Coutant 2:123b894b49dd 145 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 146 }
Jerome Coutant 2:123b894b49dd 147
Jerome Coutant 2:123b894b49dd 148 /* QSPI memory reset */
Jerome Coutant 2:123b894b49dd 149 if (QSPI_ResetMemory(&QSPIHandle) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 150 {
Jerome Coutant 2:123b894b49dd 151 return QSPI_NOT_SUPPORTED;
Jerome Coutant 2:123b894b49dd 152 }
Jerome Coutant 2:123b894b49dd 153
Jerome Coutant 2:123b894b49dd 154
Jerome Coutant 2:123b894b49dd 155 /* Configuration of the dummy cucles on QSPI memory side */
Jerome Coutant 2:123b894b49dd 156 if (QSPI_DummyCyclesCfg(&QSPIHandle) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 157 {
Jerome Coutant 2:123b894b49dd 158 return QSPI_NOT_SUPPORTED;
Jerome Coutant 2:123b894b49dd 159 }
Jerome Coutant 2:123b894b49dd 160
Jerome Coutant 2:123b894b49dd 161 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 162 }
Jerome Coutant 2:123b894b49dd 163
Jerome Coutant 2:123b894b49dd 164 /**
Jerome Coutant 2:123b894b49dd 165 * @brief De-Initializes the QSPI interface.
Jerome Coutant 2:123b894b49dd 166 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 167 */
Jerome Coutant 2:123b894b49dd 168 uint8_t BSP_QSPI_DeInit(void)
Jerome Coutant 2:123b894b49dd 169 {
Jerome Coutant 2:123b894b49dd 170 QSPIHandle.Instance = QUADSPI;
Jerome Coutant 2:123b894b49dd 171
Jerome Coutant 2:123b894b49dd 172 /* Call the DeInit function to reset the driver */
Jerome Coutant 2:123b894b49dd 173 if (HAL_QSPI_DeInit(&QSPIHandle) != HAL_OK)
Jerome Coutant 2:123b894b49dd 174 {
Jerome Coutant 2:123b894b49dd 175 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 176 }
Jerome Coutant 2:123b894b49dd 177
Jerome Coutant 2:123b894b49dd 178 /* System level De-initialization */
Jerome Coutant 2:123b894b49dd 179 BSP_QSPI_MspDeInit(&QSPIHandle, NULL);
Jerome Coutant 2:123b894b49dd 180
Jerome Coutant 2:123b894b49dd 181 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 182 }
Jerome Coutant 2:123b894b49dd 183
Jerome Coutant 2:123b894b49dd 184 /**
Jerome Coutant 2:123b894b49dd 185 * @brief Reads an amount of data from the QSPI memory.
Jerome Coutant 2:123b894b49dd 186 * @param pData: Pointer to data to be read
Jerome Coutant 2:123b894b49dd 187 * @param ReadAddr: Read start address
Jerome Coutant 2:123b894b49dd 188 * @param Size: Size of data to read
Jerome Coutant 2:123b894b49dd 189 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 190 */
Jerome Coutant 2:123b894b49dd 191 uint8_t BSP_QSPI_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size)
Jerome Coutant 2:123b894b49dd 192 {
Jerome Coutant 2:123b894b49dd 193 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 194
Jerome Coutant 2:123b894b49dd 195 /* Initialize the read command */
Jerome Coutant 2:123b894b49dd 196 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 197 s_command.Instruction = QUAD_INOUT_FAST_READ_CMD;
Jerome Coutant 2:123b894b49dd 198 s_command.AddressMode = QSPI_ADDRESS_4_LINES;
Jerome Coutant 2:123b894b49dd 199 s_command.AddressSize = QSPI_ADDRESS_24_BITS;
Jerome Coutant 2:123b894b49dd 200 s_command.Address = ReadAddr;
Jerome Coutant 2:123b894b49dd 201 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 202 s_command.DataMode = QSPI_DATA_4_LINES;
Jerome Coutant 2:123b894b49dd 203 s_command.DummyCycles = N25Q128A_DUMMY_CYCLES_READ_QUAD;
Jerome Coutant 2:123b894b49dd 204 s_command.NbData = Size;
Jerome Coutant 2:123b894b49dd 205 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 206 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 207 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 208
Jerome Coutant 2:123b894b49dd 209 /* Configure the command */
Jerome Coutant 2:123b894b49dd 210 if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 211 {
Jerome Coutant 2:123b894b49dd 212 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 213 }
Jerome Coutant 2:123b894b49dd 214
Jerome Coutant 2:123b894b49dd 215 /* Set S# timing for Read command: Min 20ns for N25Q128A memory */
Jerome Coutant 2:123b894b49dd 216 MODIFY_REG(QSPIHandle.Instance->DCR, QUADSPI_DCR_CSHT, QSPI_CS_HIGH_TIME_2_CYCLE);
Jerome Coutant 2:123b894b49dd 217
Jerome Coutant 2:123b894b49dd 218 /* Reception of the data */
Jerome Coutant 2:123b894b49dd 219 if (HAL_QSPI_Receive(&QSPIHandle, pData, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 220 {
Jerome Coutant 2:123b894b49dd 221 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 222 }
Jerome Coutant 2:123b894b49dd 223
Jerome Coutant 2:123b894b49dd 224 /* Restore S# timing for nonRead commands */
Jerome Coutant 2:123b894b49dd 225 MODIFY_REG(QSPIHandle.Instance->DCR, QUADSPI_DCR_CSHT, QSPI_CS_HIGH_TIME_5_CYCLE);
Jerome Coutant 2:123b894b49dd 226
Jerome Coutant 2:123b894b49dd 227 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 228 }
Jerome Coutant 2:123b894b49dd 229
Jerome Coutant 2:123b894b49dd 230 /**
Jerome Coutant 2:123b894b49dd 231 * @brief Writes an amount of data to the QSPI memory.
Jerome Coutant 2:123b894b49dd 232 * @param pData: Pointer to data to be written
Jerome Coutant 2:123b894b49dd 233 * @param WriteAddr: Write start address
Jerome Coutant 2:123b894b49dd 234 * @param Size: Size of data to write
Jerome Coutant 2:123b894b49dd 235 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 236 */
Jerome Coutant 2:123b894b49dd 237 uint8_t BSP_QSPI_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size)
Jerome Coutant 2:123b894b49dd 238 {
Jerome Coutant 2:123b894b49dd 239 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 240 uint32_t end_addr, current_size, current_addr;
Jerome Coutant 2:123b894b49dd 241
Jerome Coutant 2:123b894b49dd 242 /* Calculation of the size between the write address and the end of the page */
Jerome Coutant 2:123b894b49dd 243 current_size = N25Q128A_PAGE_SIZE - (WriteAddr % N25Q128A_PAGE_SIZE);
Jerome Coutant 2:123b894b49dd 244
Jerome Coutant 2:123b894b49dd 245 /* Check if the size of the data is less than the remaining place in the page */
Jerome Coutant 2:123b894b49dd 246 if (current_size > Size)
Jerome Coutant 2:123b894b49dd 247 {
Jerome Coutant 2:123b894b49dd 248 current_size = Size;
Jerome Coutant 2:123b894b49dd 249 }
Jerome Coutant 2:123b894b49dd 250
Jerome Coutant 2:123b894b49dd 251 /* Initialize the address variables */
Jerome Coutant 2:123b894b49dd 252 current_addr = WriteAddr;
Jerome Coutant 2:123b894b49dd 253 end_addr = WriteAddr + Size;
Jerome Coutant 2:123b894b49dd 254
Jerome Coutant 2:123b894b49dd 255 /* Initialize the program command */
Jerome Coutant 2:123b894b49dd 256 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 257 s_command.Instruction = EXT_QUAD_IN_FAST_PROG_CMD;
Jerome Coutant 2:123b894b49dd 258 s_command.AddressMode = QSPI_ADDRESS_4_LINES;
Jerome Coutant 2:123b894b49dd 259 s_command.AddressSize = QSPI_ADDRESS_24_BITS;
Jerome Coutant 2:123b894b49dd 260 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 261 s_command.DataMode = QSPI_DATA_4_LINES;
Jerome Coutant 2:123b894b49dd 262 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 263 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 264 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 265 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 266
Jerome Coutant 2:123b894b49dd 267 /* Perform the write page by page */
Jerome Coutant 2:123b894b49dd 268 do
Jerome Coutant 2:123b894b49dd 269 {
Jerome Coutant 2:123b894b49dd 270 s_command.Address = current_addr;
Jerome Coutant 2:123b894b49dd 271 s_command.NbData = current_size;
Jerome Coutant 2:123b894b49dd 272
Jerome Coutant 2:123b894b49dd 273 /* Enable write operations */
Jerome Coutant 2:123b894b49dd 274 if (QSPI_WriteEnable(&QSPIHandle) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 275 {
Jerome Coutant 2:123b894b49dd 276 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 277 }
Jerome Coutant 2:123b894b49dd 278
Jerome Coutant 2:123b894b49dd 279 /* Configure the command */
Jerome Coutant 2:123b894b49dd 280 if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 281 {
Jerome Coutant 2:123b894b49dd 282 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 283 }
Jerome Coutant 2:123b894b49dd 284
Jerome Coutant 2:123b894b49dd 285 /* Transmission of the data */
Jerome Coutant 2:123b894b49dd 286 if (HAL_QSPI_Transmit(&QSPIHandle, pData, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 287 {
Jerome Coutant 2:123b894b49dd 288 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 289 }
Jerome Coutant 2:123b894b49dd 290
Jerome Coutant 2:123b894b49dd 291 /* Configure automatic polling mode to wait for end of program */
Jerome Coutant 2:123b894b49dd 292 if (QSPI_AutoPollingMemReady(&QSPIHandle, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 293 {
Jerome Coutant 2:123b894b49dd 294 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 295 }
Jerome Coutant 2:123b894b49dd 296
Jerome Coutant 2:123b894b49dd 297 /* Update the address and size variables for next page programming */
Jerome Coutant 2:123b894b49dd 298 current_addr += current_size;
Jerome Coutant 2:123b894b49dd 299 pData += current_size;
Jerome Coutant 2:123b894b49dd 300 current_size = ((current_addr + N25Q128A_PAGE_SIZE) > end_addr) ? (end_addr - current_addr) : N25Q128A_PAGE_SIZE;
Jerome Coutant 2:123b894b49dd 301 } while (current_addr < end_addr);
Jerome Coutant 2:123b894b49dd 302
Jerome Coutant 2:123b894b49dd 303 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 304 }
Jerome Coutant 2:123b894b49dd 305
Jerome Coutant 2:123b894b49dd 306 /**
Jerome Coutant 2:123b894b49dd 307 * @brief Erases the specified block of the QSPI memory.
Jerome Coutant 2:123b894b49dd 308 * @param BlockAddress: Block address to erase
Jerome Coutant 2:123b894b49dd 309 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 310 */
Jerome Coutant 2:123b894b49dd 311 uint8_t BSP_QSPI_Erase_Block(uint32_t BlockAddress)
Jerome Coutant 2:123b894b49dd 312 {
Jerome Coutant 2:123b894b49dd 313 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 314
Jerome Coutant 2:123b894b49dd 315 /* Initialize the erase command */
Jerome Coutant 2:123b894b49dd 316 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 317 s_command.Instruction = SUBSECTOR_ERASE_CMD;
Jerome Coutant 2:123b894b49dd 318 s_command.AddressMode = QSPI_ADDRESS_1_LINE;
Jerome Coutant 2:123b894b49dd 319 s_command.AddressSize = QSPI_ADDRESS_24_BITS;
Jerome Coutant 2:123b894b49dd 320 s_command.Address = BlockAddress;
Jerome Coutant 2:123b894b49dd 321 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 322 s_command.DataMode = QSPI_DATA_NONE;
Jerome Coutant 2:123b894b49dd 323 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 324 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 325 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 326 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 327
Jerome Coutant 2:123b894b49dd 328 /* Enable write operations */
Jerome Coutant 2:123b894b49dd 329 if (QSPI_WriteEnable(&QSPIHandle) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 330 {
Jerome Coutant 2:123b894b49dd 331 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 332 }
Jerome Coutant 2:123b894b49dd 333
Jerome Coutant 2:123b894b49dd 334 /* Send the command */
Jerome Coutant 2:123b894b49dd 335 if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 336 {
Jerome Coutant 2:123b894b49dd 337 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 338 }
Jerome Coutant 2:123b894b49dd 339
Jerome Coutant 2:123b894b49dd 340 /* Configure automatic polling mode to wait for end of erase */
Jerome Coutant 2:123b894b49dd 341 if (QSPI_AutoPollingMemReady(&QSPIHandle, N25Q128A_SUBSECTOR_ERASE_MAX_TIME) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 342 {
Jerome Coutant 2:123b894b49dd 343 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 344 }
Jerome Coutant 2:123b894b49dd 345
Jerome Coutant 2:123b894b49dd 346 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 347 }
Jerome Coutant 2:123b894b49dd 348
Jerome Coutant 2:123b894b49dd 349 /**
Jerome Coutant 2:123b894b49dd 350 * @brief Erases the entire QSPI memory.
Jerome Coutant 2:123b894b49dd 351 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 352 */
Jerome Coutant 2:123b894b49dd 353 uint8_t BSP_QSPI_Erase_Chip(void)
Jerome Coutant 2:123b894b49dd 354 {
Jerome Coutant 2:123b894b49dd 355 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 356
Jerome Coutant 2:123b894b49dd 357 /* Initialize the erase command */
Jerome Coutant 2:123b894b49dd 358 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 359 s_command.Instruction = BULK_ERASE_CMD;
Jerome Coutant 2:123b894b49dd 360 s_command.AddressMode = QSPI_ADDRESS_NONE;
Jerome Coutant 2:123b894b49dd 361 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 362 s_command.DataMode = QSPI_DATA_NONE;
Jerome Coutant 2:123b894b49dd 363 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 364 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 365 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 366 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 367
Jerome Coutant 2:123b894b49dd 368 /* Enable write operations */
Jerome Coutant 2:123b894b49dd 369 if (QSPI_WriteEnable(&QSPIHandle) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 370 {
Jerome Coutant 2:123b894b49dd 371 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 372 }
Jerome Coutant 2:123b894b49dd 373
Jerome Coutant 2:123b894b49dd 374 /* Send the command */
Jerome Coutant 2:123b894b49dd 375 if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 376 {
Jerome Coutant 2:123b894b49dd 377 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 378 }
Jerome Coutant 2:123b894b49dd 379
Jerome Coutant 2:123b894b49dd 380 /* Configure automatic polling mode to wait for end of erase */
Jerome Coutant 2:123b894b49dd 381 if (QSPI_AutoPollingMemReady(&QSPIHandle, N25Q128A_BULK_ERASE_MAX_TIME) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 382 {
Jerome Coutant 2:123b894b49dd 383 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 384 }
Jerome Coutant 2:123b894b49dd 385
Jerome Coutant 2:123b894b49dd 386 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 387 }
Jerome Coutant 2:123b894b49dd 388
Jerome Coutant 2:123b894b49dd 389 /**
Jerome Coutant 2:123b894b49dd 390 * @brief Reads current status of the QSPI memory.
Jerome Coutant 2:123b894b49dd 391 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 392 */
Jerome Coutant 2:123b894b49dd 393 uint8_t BSP_QSPI_GetStatus(void)
Jerome Coutant 2:123b894b49dd 394 {
Jerome Coutant 2:123b894b49dd 395 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 396 uint8_t reg;
Jerome Coutant 2:123b894b49dd 397
Jerome Coutant 2:123b894b49dd 398 /* Initialize the read flag status register command */
Jerome Coutant 2:123b894b49dd 399 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 400 s_command.Instruction = READ_FLAG_STATUS_REG_CMD;
Jerome Coutant 2:123b894b49dd 401 s_command.AddressMode = QSPI_ADDRESS_NONE;
Jerome Coutant 2:123b894b49dd 402 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 403 s_command.DataMode = QSPI_DATA_1_LINE;
Jerome Coutant 2:123b894b49dd 404 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 405 s_command.NbData = 1;
Jerome Coutant 2:123b894b49dd 406 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 407 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 408 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 409
Jerome Coutant 2:123b894b49dd 410 /* Configure the command */
Jerome Coutant 2:123b894b49dd 411 if (HAL_QSPI_Command(&QSPIHandle, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 412 {
Jerome Coutant 2:123b894b49dd 413 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 414 }
Jerome Coutant 2:123b894b49dd 415
Jerome Coutant 2:123b894b49dd 416 /* Reception of the data */
Jerome Coutant 2:123b894b49dd 417 if (HAL_QSPI_Receive(&QSPIHandle, &reg, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 418 {
Jerome Coutant 2:123b894b49dd 419 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 420 }
Jerome Coutant 2:123b894b49dd 421
Jerome Coutant 2:123b894b49dd 422 /* Check the value of the register */
Jerome Coutant 2:123b894b49dd 423 if ((reg & (N25Q128A_FSR_PRERR | N25Q128A_FSR_VPPERR | N25Q128A_FSR_PGERR | N25Q128A_FSR_ERERR)) != 0)
Jerome Coutant 2:123b894b49dd 424 {
Jerome Coutant 2:123b894b49dd 425 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 426 }
Jerome Coutant 2:123b894b49dd 427 else if ((reg & (N25Q128A_FSR_PGSUS | N25Q128A_FSR_ERSUS)) != 0)
Jerome Coutant 2:123b894b49dd 428 {
Jerome Coutant 2:123b894b49dd 429 return QSPI_SUSPENDED;
Jerome Coutant 2:123b894b49dd 430 }
Jerome Coutant 2:123b894b49dd 431 else if ((reg & N25Q128A_FSR_READY) != 0)
Jerome Coutant 2:123b894b49dd 432 {
Jerome Coutant 2:123b894b49dd 433 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 434 }
Jerome Coutant 2:123b894b49dd 435 else
Jerome Coutant 2:123b894b49dd 436 {
Jerome Coutant 2:123b894b49dd 437 return QSPI_BUSY;
Jerome Coutant 2:123b894b49dd 438 }
Jerome Coutant 2:123b894b49dd 439 }
Jerome Coutant 2:123b894b49dd 440
Jerome Coutant 2:123b894b49dd 441 /**
Jerome Coutant 2:123b894b49dd 442 * @brief Reads the configuration of the memory and fills QspiInfo struct
Jerome Coutant 2:123b894b49dd 443 * @param pInfo pointer to Info structure
Jerome Coutant 2:123b894b49dd 444 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 445 */
Jerome Coutant 2:123b894b49dd 446 uint8_t BSP_QSPI_GetInfo(QSPI_InfoTypeDef* pInfo)
Jerome Coutant 2:123b894b49dd 447 {
Jerome Coutant 2:123b894b49dd 448 /* Configure the structure with the memory configuration */
Jerome Coutant 2:123b894b49dd 449 pInfo->FlashSize = N25Q128A_FLASH_SIZE;
Jerome Coutant 2:123b894b49dd 450 pInfo->EraseSectorSize = N25Q128A_SUBSECTOR_SIZE;
Jerome Coutant 2:123b894b49dd 451 pInfo->EraseSectorsNumber = (N25Q128A_FLASH_SIZE/N25Q128A_SUBSECTOR_SIZE);
Jerome Coutant 2:123b894b49dd 452 pInfo->ProgPageSize = N25Q128A_PAGE_SIZE;
Jerome Coutant 2:123b894b49dd 453 pInfo->ProgPagesNumber = (N25Q128A_FLASH_SIZE/N25Q128A_PAGE_SIZE);
Jerome Coutant 2:123b894b49dd 454
Jerome Coutant 2:123b894b49dd 455 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 456 }
Jerome Coutant 2:123b894b49dd 457
Jerome Coutant 2:123b894b49dd 458 /**
Jerome Coutant 2:123b894b49dd 459 * @brief Configure the QSPI in memory-mapped mode
Jerome Coutant 2:123b894b49dd 460 * @retval QSPI memory status
Jerome Coutant 2:123b894b49dd 461 */
Jerome Coutant 2:123b894b49dd 462 uint8_t BSP_QSPI_EnableMemoryMappedMode(void)
Jerome Coutant 2:123b894b49dd 463 {
Jerome Coutant 2:123b894b49dd 464 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 465 QSPI_MemoryMappedTypeDef s_mem_mapped_cfg;
Jerome Coutant 2:123b894b49dd 466
Jerome Coutant 2:123b894b49dd 467 /* Configure the command for the read instruction */
Jerome Coutant 2:123b894b49dd 468 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 469 s_command.Instruction = QUAD_INOUT_FAST_READ_CMD;
Jerome Coutant 2:123b894b49dd 470 s_command.AddressMode = QSPI_ADDRESS_4_LINES;
Jerome Coutant 2:123b894b49dd 471 s_command.AddressSize = QSPI_ADDRESS_24_BITS;
Jerome Coutant 2:123b894b49dd 472 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 473 s_command.DataMode = QSPI_DATA_4_LINES;
Jerome Coutant 2:123b894b49dd 474 s_command.DummyCycles = N25Q128A_DUMMY_CYCLES_READ_QUAD;
Jerome Coutant 2:123b894b49dd 475 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 476 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 477 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 478
Jerome Coutant 2:123b894b49dd 479 /* Configure the memory mapped mode */
Jerome Coutant 2:123b894b49dd 480 s_mem_mapped_cfg.TimeOutActivation = QSPI_TIMEOUT_COUNTER_DISABLE;
Jerome Coutant 2:123b894b49dd 481
Jerome Coutant 2:123b894b49dd 482 if (HAL_QSPI_MemoryMapped(&QSPIHandle, &s_command, &s_mem_mapped_cfg) != HAL_OK)
Jerome Coutant 2:123b894b49dd 483 {
Jerome Coutant 2:123b894b49dd 484 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 485 }
Jerome Coutant 2:123b894b49dd 486
Jerome Coutant 2:123b894b49dd 487 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 488 }
Jerome Coutant 2:123b894b49dd 489
Jerome Coutant 2:123b894b49dd 490 /**
Jerome Coutant 2:123b894b49dd 491 * @}
Jerome Coutant 2:123b894b49dd 492 */
Jerome Coutant 2:123b894b49dd 493
Jerome Coutant 2:123b894b49dd 494 /** @defgroup STM32469I_Discovery_QSPI_Private_Functions STM32469I Discovery QSPI Private Functions
Jerome Coutant 2:123b894b49dd 495 * @{
Jerome Coutant 2:123b894b49dd 496 */
Jerome Coutant 2:123b894b49dd 497
Jerome Coutant 2:123b894b49dd 498 /**
Jerome Coutant 2:123b894b49dd 499 * @brief QSPI MSP Initialization
Jerome Coutant 2:123b894b49dd 500 * This function configures the hardware resources used in this example:
Jerome Coutant 2:123b894b49dd 501 * - Peripheral's clock enable
Jerome Coutant 2:123b894b49dd 502 * - Peripheral's GPIO Configuration
Jerome Coutant 2:123b894b49dd 503 * - NVIC configuration for QSPI interrupt
Jerome Coutant 2:123b894b49dd 504 */
Jerome Coutant 2:123b894b49dd 505 __weak void BSP_QSPI_MspInit(QSPI_HandleTypeDef *hqspi, void *Params)
Jerome Coutant 2:123b894b49dd 506 {
Jerome Coutant 2:123b894b49dd 507 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 2:123b894b49dd 508
Jerome Coutant 2:123b894b49dd 509 /*##-1- Enable peripherals and GPIO Clocks #################################*/
Jerome Coutant 2:123b894b49dd 510 /* Enable the QuadSPI memory interface clock */
Jerome Coutant 2:123b894b49dd 511 QSPI_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 512 /* Reset the QuadSPI memory interface */
Jerome Coutant 2:123b894b49dd 513 QSPI_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 514 QSPI_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 515 /* Enable GPIO clocks */
Jerome Coutant 2:123b894b49dd 516 QSPI_CS_GPIO_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 517 QSPI_DX_CLK_GPIO_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 518
Jerome Coutant 2:123b894b49dd 519 /*##-2- Configure peripheral GPIO ##########################################*/
Jerome Coutant 2:123b894b49dd 520 /* QSPI CS GPIO pin configuration */
Jerome Coutant 2:123b894b49dd 521 gpio_init_structure.Pin = QSPI_CS_PIN;
Jerome Coutant 2:123b894b49dd 522 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
Jerome Coutant 2:123b894b49dd 523 gpio_init_structure.Pull = GPIO_PULLUP;
Jerome Coutant 2:123b894b49dd 524 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
Jerome Coutant 2:123b894b49dd 525 gpio_init_structure.Alternate = GPIO_AF10_QSPI;
Jerome Coutant 2:123b894b49dd 526 HAL_GPIO_Init(QSPI_CS_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 2:123b894b49dd 527
Jerome Coutant 2:123b894b49dd 528 /* QSPI CLK GPIO pin configuration */
Jerome Coutant 2:123b894b49dd 529 gpio_init_structure.Pin = QSPI_CLK_PIN;
Jerome Coutant 2:123b894b49dd 530 gpio_init_structure.Pull = GPIO_NOPULL;
Jerome Coutant 2:123b894b49dd 531 gpio_init_structure.Alternate = GPIO_AF9_QSPI;
Jerome Coutant 2:123b894b49dd 532 HAL_GPIO_Init(QSPI_CLK_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 2:123b894b49dd 533
Jerome Coutant 2:123b894b49dd 534 /* QSPI D0 and D1 GPIO pin configuration */
Jerome Coutant 2:123b894b49dd 535 gpio_init_structure.Pin = (QSPI_D0_PIN | QSPI_D1_PIN);
Jerome Coutant 2:123b894b49dd 536 gpio_init_structure.Alternate = GPIO_AF10_QSPI;
Jerome Coutant 2:123b894b49dd 537 HAL_GPIO_Init(QSPI_DX_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 2:123b894b49dd 538
Jerome Coutant 2:123b894b49dd 539 /* QSPI D2 and D3 GPIO pin configuration */
Jerome Coutant 2:123b894b49dd 540 gpio_init_structure.Pin = (QSPI_D2_PIN | QSPI_D3_PIN) ;
Jerome Coutant 2:123b894b49dd 541 gpio_init_structure.Alternate = GPIO_AF9_QSPI;
Jerome Coutant 2:123b894b49dd 542 HAL_GPIO_Init(QSPI_DX_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 2:123b894b49dd 543
Jerome Coutant 2:123b894b49dd 544 /*##-3- Configure the NVIC for QSPI #########################################*/
Jerome Coutant 2:123b894b49dd 545 /* NVIC configuration for QSPI interrupt */
Jerome Coutant 2:123b894b49dd 546 HAL_NVIC_SetPriority(QUADSPI_IRQn, 0x0F, 0);
Jerome Coutant 2:123b894b49dd 547 HAL_NVIC_EnableIRQ(QUADSPI_IRQn);
Jerome Coutant 2:123b894b49dd 548
Jerome Coutant 2:123b894b49dd 549 }
Jerome Coutant 2:123b894b49dd 550
Jerome Coutant 2:123b894b49dd 551 /**
Jerome Coutant 2:123b894b49dd 552 * @brief QSPI MSP De-Initialization
Jerome Coutant 2:123b894b49dd 553 * This function frees the hardware resources used in this example:
Jerome Coutant 2:123b894b49dd 554 * - Disable the Peripheral's clock
Jerome Coutant 2:123b894b49dd 555 * - Revert GPIO and NVIC configuration to their default state
Jerome Coutant 2:123b894b49dd 556 */
Jerome Coutant 2:123b894b49dd 557 __weak void BSP_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi, void *Params)
Jerome Coutant 2:123b894b49dd 558 {
Jerome Coutant 2:123b894b49dd 559 /*##-1- Disable the NVIC for QSPI ###########################################*/
Jerome Coutant 2:123b894b49dd 560 HAL_NVIC_DisableIRQ(QUADSPI_IRQn);
Jerome Coutant 2:123b894b49dd 561
Jerome Coutant 2:123b894b49dd 562 /*##-2- Disable peripherals and GPIO Clocks ################################*/
Jerome Coutant 2:123b894b49dd 563 /* De-Configure QSPI pins */
Jerome Coutant 2:123b894b49dd 564 HAL_GPIO_DeInit(QSPI_CS_GPIO_PORT, QSPI_CS_PIN);
Jerome Coutant 2:123b894b49dd 565 HAL_GPIO_DeInit(QSPI_CLK_GPIO_PORT, QSPI_CLK_PIN);
Jerome Coutant 2:123b894b49dd 566 HAL_GPIO_DeInit(QSPI_DX_GPIO_PORT, QSPI_D0_PIN);
Jerome Coutant 2:123b894b49dd 567 HAL_GPIO_DeInit(QSPI_DX_GPIO_PORT, QSPI_D1_PIN);
Jerome Coutant 2:123b894b49dd 568 HAL_GPIO_DeInit(QSPI_DX_GPIO_PORT, QSPI_D2_PIN);
Jerome Coutant 2:123b894b49dd 569 HAL_GPIO_DeInit(QSPI_DX_GPIO_PORT, QSPI_D3_PIN);
Jerome Coutant 2:123b894b49dd 570
Jerome Coutant 2:123b894b49dd 571 /*##-3- Reset peripherals ##################################################*/
Jerome Coutant 2:123b894b49dd 572 /* Reset the QuadSPI memory interface */
Jerome Coutant 2:123b894b49dd 573 QSPI_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 574 QSPI_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 575
Jerome Coutant 2:123b894b49dd 576 /* Disable the QuadSPI memory interface clock */
Jerome Coutant 2:123b894b49dd 577 QSPI_CLK_DISABLE();
Jerome Coutant 2:123b894b49dd 578 }
Jerome Coutant 2:123b894b49dd 579
Jerome Coutant 2:123b894b49dd 580 /**
Jerome Coutant 2:123b894b49dd 581 * @brief This function reset the QSPI memory.
Jerome Coutant 2:123b894b49dd 582 * @param hqspi: QSPI handle
Jerome Coutant 2:123b894b49dd 583 */
Jerome Coutant 2:123b894b49dd 584 static uint8_t QSPI_ResetMemory(QSPI_HandleTypeDef *hqspi)
Jerome Coutant 2:123b894b49dd 585 {
Jerome Coutant 2:123b894b49dd 586 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 587
Jerome Coutant 2:123b894b49dd 588 /* Initialize the reset enable command */
Jerome Coutant 2:123b894b49dd 589 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 590 s_command.Instruction = RESET_ENABLE_CMD;
Jerome Coutant 2:123b894b49dd 591 s_command.AddressMode = QSPI_ADDRESS_NONE;
Jerome Coutant 2:123b894b49dd 592 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 593 s_command.DataMode = QSPI_DATA_NONE;
Jerome Coutant 2:123b894b49dd 594 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 595 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 596 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 597 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 598
Jerome Coutant 2:123b894b49dd 599 /* Send the command */
Jerome Coutant 2:123b894b49dd 600 if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 601 {
Jerome Coutant 2:123b894b49dd 602 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 603 }
Jerome Coutant 2:123b894b49dd 604
Jerome Coutant 2:123b894b49dd 605 /* Send the reset memory command */
Jerome Coutant 2:123b894b49dd 606 s_command.Instruction = RESET_MEMORY_CMD;
Jerome Coutant 2:123b894b49dd 607 if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 608 {
Jerome Coutant 2:123b894b49dd 609 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 610 }
Jerome Coutant 2:123b894b49dd 611
Jerome Coutant 2:123b894b49dd 612 /* Configure automatic polling mode to wait the memory is ready */
Jerome Coutant 2:123b894b49dd 613 if (QSPI_AutoPollingMemReady(hqspi, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 614 {
Jerome Coutant 2:123b894b49dd 615 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 616 }
Jerome Coutant 2:123b894b49dd 617
Jerome Coutant 2:123b894b49dd 618 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 619 }
Jerome Coutant 2:123b894b49dd 620
Jerome Coutant 2:123b894b49dd 621 /**
Jerome Coutant 2:123b894b49dd 622 * @brief This function configure the dummy cycles on memory side.
Jerome Coutant 2:123b894b49dd 623 * @param hqspi: QSPI handle
Jerome Coutant 2:123b894b49dd 624 */
Jerome Coutant 2:123b894b49dd 625 static uint8_t QSPI_DummyCyclesCfg(QSPI_HandleTypeDef *hqspi)
Jerome Coutant 2:123b894b49dd 626 {
Jerome Coutant 2:123b894b49dd 627 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 628 uint8_t reg;
Jerome Coutant 2:123b894b49dd 629
Jerome Coutant 2:123b894b49dd 630 /* Initialize the read volatile configuration register command */
Jerome Coutant 2:123b894b49dd 631 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 632 s_command.Instruction = READ_VOL_CFG_REG_CMD;
Jerome Coutant 2:123b894b49dd 633 s_command.AddressMode = QSPI_ADDRESS_NONE;
Jerome Coutant 2:123b894b49dd 634 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 635 s_command.DataMode = QSPI_DATA_1_LINE;
Jerome Coutant 2:123b894b49dd 636 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 637 s_command.NbData = 1;
Jerome Coutant 2:123b894b49dd 638 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 639 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 640 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 641
Jerome Coutant 2:123b894b49dd 642 /* Configure the command */
Jerome Coutant 2:123b894b49dd 643 if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 644 {
Jerome Coutant 2:123b894b49dd 645 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 646 }
Jerome Coutant 2:123b894b49dd 647
Jerome Coutant 2:123b894b49dd 648 /* Reception of the data */
Jerome Coutant 2:123b894b49dd 649 if (HAL_QSPI_Receive(hqspi, &reg, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 650 {
Jerome Coutant 2:123b894b49dd 651 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 652 }
Jerome Coutant 2:123b894b49dd 653
Jerome Coutant 2:123b894b49dd 654 /* Enable write operations */
Jerome Coutant 2:123b894b49dd 655 if (QSPI_WriteEnable(hqspi) != QSPI_OK)
Jerome Coutant 2:123b894b49dd 656 {
Jerome Coutant 2:123b894b49dd 657 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 658 }
Jerome Coutant 2:123b894b49dd 659
Jerome Coutant 2:123b894b49dd 660 /* Update volatile configuration register (with new dummy cycles) */
Jerome Coutant 2:123b894b49dd 661 s_command.Instruction = WRITE_VOL_CFG_REG_CMD;
Jerome Coutant 2:123b894b49dd 662 MODIFY_REG(reg, N25Q128A_VCR_NB_DUMMY, (N25Q128A_DUMMY_CYCLES_READ_QUAD << POSITION_VAL(N25Q128A_VCR_NB_DUMMY)));
Jerome Coutant 2:123b894b49dd 663
Jerome Coutant 2:123b894b49dd 664 /* Configure the write volatile configuration register command */
Jerome Coutant 2:123b894b49dd 665 if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 666 {
Jerome Coutant 2:123b894b49dd 667 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 668 }
Jerome Coutant 2:123b894b49dd 669
Jerome Coutant 2:123b894b49dd 670 /* Transmission of the data */
Jerome Coutant 2:123b894b49dd 671 if (HAL_QSPI_Transmit(hqspi, &reg, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 672 {
Jerome Coutant 2:123b894b49dd 673 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 674 }
Jerome Coutant 2:123b894b49dd 675
Jerome Coutant 2:123b894b49dd 676 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 677 }
Jerome Coutant 2:123b894b49dd 678
Jerome Coutant 2:123b894b49dd 679 /**
Jerome Coutant 2:123b894b49dd 680 * @brief This function send a Write Enable and wait it is effective.
Jerome Coutant 2:123b894b49dd 681 * @param hqspi: QSPI handle
Jerome Coutant 2:123b894b49dd 682 */
Jerome Coutant 2:123b894b49dd 683 static uint8_t QSPI_WriteEnable(QSPI_HandleTypeDef *hqspi)
Jerome Coutant 2:123b894b49dd 684 {
Jerome Coutant 2:123b894b49dd 685 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 686 QSPI_AutoPollingTypeDef s_config;
Jerome Coutant 2:123b894b49dd 687
Jerome Coutant 2:123b894b49dd 688 /* Enable write operations */
Jerome Coutant 2:123b894b49dd 689 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 690 s_command.Instruction = WRITE_ENABLE_CMD;
Jerome Coutant 2:123b894b49dd 691 s_command.AddressMode = QSPI_ADDRESS_NONE;
Jerome Coutant 2:123b894b49dd 692 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 693 s_command.DataMode = QSPI_DATA_NONE;
Jerome Coutant 2:123b894b49dd 694 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 695 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 696 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 697 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 698
Jerome Coutant 2:123b894b49dd 699 if (HAL_QSPI_Command(hqspi, &s_command, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 700 {
Jerome Coutant 2:123b894b49dd 701 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 702 }
Jerome Coutant 2:123b894b49dd 703
Jerome Coutant 2:123b894b49dd 704 /* Configure automatic polling mode to wait for write enabling */
Jerome Coutant 2:123b894b49dd 705 s_config.Match = N25Q128A_SR_WREN;
Jerome Coutant 2:123b894b49dd 706 s_config.Mask = N25Q128A_SR_WREN;
Jerome Coutant 2:123b894b49dd 707 s_config.MatchMode = QSPI_MATCH_MODE_AND;
Jerome Coutant 2:123b894b49dd 708 s_config.StatusBytesSize = 1;
Jerome Coutant 2:123b894b49dd 709 s_config.Interval = 0x10;
Jerome Coutant 2:123b894b49dd 710 s_config.AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE;
Jerome Coutant 2:123b894b49dd 711
Jerome Coutant 2:123b894b49dd 712 s_command.Instruction = READ_STATUS_REG_CMD;
Jerome Coutant 2:123b894b49dd 713 s_command.DataMode = QSPI_DATA_1_LINE;
Jerome Coutant 2:123b894b49dd 714
Jerome Coutant 2:123b894b49dd 715 if (HAL_QSPI_AutoPolling(hqspi, &s_command, &s_config, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
Jerome Coutant 2:123b894b49dd 716 {
Jerome Coutant 2:123b894b49dd 717 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 718 }
Jerome Coutant 2:123b894b49dd 719
Jerome Coutant 2:123b894b49dd 720 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 721 }
Jerome Coutant 2:123b894b49dd 722
Jerome Coutant 2:123b894b49dd 723 /**
Jerome Coutant 2:123b894b49dd 724 * @brief This function read the SR of the memory and wait the EOP.
Jerome Coutant 2:123b894b49dd 725 * @param hqspi: QSPI handle
Jerome Coutant 2:123b894b49dd 726 * @param Timeout: timeout value before returning an error
Jerome Coutant 2:123b894b49dd 727 */
Jerome Coutant 2:123b894b49dd 728 static uint8_t QSPI_AutoPollingMemReady(QSPI_HandleTypeDef *hqspi, uint32_t Timeout)
Jerome Coutant 2:123b894b49dd 729 {
Jerome Coutant 2:123b894b49dd 730 QSPI_CommandTypeDef s_command;
Jerome Coutant 2:123b894b49dd 731 QSPI_AutoPollingTypeDef s_config;
Jerome Coutant 2:123b894b49dd 732
Jerome Coutant 2:123b894b49dd 733 /* Configure automatic polling mode to wait for memory ready */
Jerome Coutant 2:123b894b49dd 734 s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
Jerome Coutant 2:123b894b49dd 735 s_command.Instruction = READ_STATUS_REG_CMD;
Jerome Coutant 2:123b894b49dd 736 s_command.AddressMode = QSPI_ADDRESS_NONE;
Jerome Coutant 2:123b894b49dd 737 s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
Jerome Coutant 2:123b894b49dd 738 s_command.DataMode = QSPI_DATA_1_LINE;
Jerome Coutant 2:123b894b49dd 739 s_command.DummyCycles = 0;
Jerome Coutant 2:123b894b49dd 740 s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
Jerome Coutant 2:123b894b49dd 741 s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
Jerome Coutant 2:123b894b49dd 742 s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
Jerome Coutant 2:123b894b49dd 743
Jerome Coutant 2:123b894b49dd 744 s_config.Match = 0;
Jerome Coutant 2:123b894b49dd 745 s_config.Mask = N25Q128A_SR_WIP;
Jerome Coutant 2:123b894b49dd 746 s_config.MatchMode = QSPI_MATCH_MODE_AND;
Jerome Coutant 2:123b894b49dd 747 s_config.StatusBytesSize = 1;
Jerome Coutant 2:123b894b49dd 748 s_config.Interval = 0x10;
Jerome Coutant 2:123b894b49dd 749 s_config.AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE;
Jerome Coutant 2:123b894b49dd 750
Jerome Coutant 2:123b894b49dd 751 if (HAL_QSPI_AutoPolling(hqspi, &s_command, &s_config, Timeout) != HAL_OK)
Jerome Coutant 2:123b894b49dd 752 {
Jerome Coutant 2:123b894b49dd 753 return QSPI_ERROR;
Jerome Coutant 2:123b894b49dd 754 }
Jerome Coutant 2:123b894b49dd 755
Jerome Coutant 2:123b894b49dd 756 return QSPI_OK;
Jerome Coutant 2:123b894b49dd 757 }
Jerome Coutant 2:123b894b49dd 758 /**
Jerome Coutant 2:123b894b49dd 759 * @}
Jerome Coutant 2:123b894b49dd 760 */
Jerome Coutant 2:123b894b49dd 761
Jerome Coutant 2:123b894b49dd 762 /**
Jerome Coutant 2:123b894b49dd 763 * @}
Jerome Coutant 2:123b894b49dd 764 */
Jerome Coutant 2:123b894b49dd 765
Jerome Coutant 2:123b894b49dd 766 /**
Jerome Coutant 2:123b894b49dd 767 * @}
Jerome Coutant 2:123b894b49dd 768 */
Jerome Coutant 2:123b894b49dd 769
Jerome Coutant 2:123b894b49dd 770 /**
Jerome Coutant 2:123b894b49dd 771 * @}
Jerome Coutant 2:123b894b49dd 772 */
Jerome Coutant 2:123b894b49dd 773
Jerome Coutant 2:123b894b49dd 774 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Jerome Coutant 2:123b894b49dd 775