Class to drive the QSPI external memory (N25Q128A device) present on DISCO_F746NG board.

Dependents:   F746_Fourier_series_of_square_wave_01 F746_AudioOutQSPI DISCO-F746-Dessiccateur-V1 DISCO-F746NG_Monttory_Base ... more

Committer:
bcostm
Date:
Mon Jan 04 15:19:45 2016 +0000
Revision:
0:be9d625054cd
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:be9d625054cd 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
bcostm 0:be9d625054cd 2 *
bcostm 0:be9d625054cd 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bcostm 0:be9d625054cd 4 * and associated documentation files (the "Software"), to deal in the Software without
bcostm 0:be9d625054cd 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
bcostm 0:be9d625054cd 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
bcostm 0:be9d625054cd 7 * Software is furnished to do so, subject to the following conditions:
bcostm 0:be9d625054cd 8 *
bcostm 0:be9d625054cd 9 * The above copyright notice and this permission notice shall be included in all copies or
bcostm 0:be9d625054cd 10 * substantial portions of the Software.
bcostm 0:be9d625054cd 11 *
bcostm 0:be9d625054cd 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bcostm 0:be9d625054cd 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bcostm 0:be9d625054cd 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bcostm 0:be9d625054cd 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bcostm 0:be9d625054cd 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bcostm 0:be9d625054cd 17 */
bcostm 0:be9d625054cd 18
bcostm 0:be9d625054cd 19 #ifndef __QSPI_DISCO_F746NG_H
bcostm 0:be9d625054cd 20 #define __QSPI_DISCO_F746NG_H
bcostm 0:be9d625054cd 21
bcostm 0:be9d625054cd 22 #ifdef TARGET_DISCO_F746NG
bcostm 0:be9d625054cd 23
bcostm 0:be9d625054cd 24 #include "mbed.h"
bcostm 0:be9d625054cd 25 #include "stm32746g_discovery_qspi.h"
bcostm 0:be9d625054cd 26
bcostm 0:be9d625054cd 27 /*
bcostm 0:be9d625054cd 28 Class to drive the QSPI external memory (N25Q128A device)
bcostm 0:be9d625054cd 29 present on DISCO_F746NG board.
bcostm 0:be9d625054cd 30
bcostm 0:be9d625054cd 31 Usage:
bcostm 0:be9d625054cd 32
bcostm 0:be9d625054cd 33 #include "mbed.h"
bcostm 0:be9d625054cd 34 #include "QSPI_DISCO_F746NG.h"
bcostm 0:be9d625054cd 35
bcostm 0:be9d625054cd 36 QSPI_DISCO_F746NG qspi;
bcostm 0:be9d625054cd 37
bcostm 0:be9d625054cd 38 #define BUFFER_SIZE ((uint32_t)32)
bcostm 0:be9d625054cd 39 #define WRITE_READ_ADDR ((uint32_t)0x0050)
bcostm 0:be9d625054cd 40
bcostm 0:be9d625054cd 41 int main()
bcostm 0:be9d625054cd 42 {
bcostm 0:be9d625054cd 43 uint8_t WriteBuffer[BUFFER_SIZE] = "Hello World";
bcostm 0:be9d625054cd 44 uint8_t ReadBuffer[BUFFER_SIZE];
bcostm 0:be9d625054cd 45
bcostm 0:be9d625054cd 46 qspi.Init();
bcostm 0:be9d625054cd 47
bcostm 0:be9d625054cd 48 // Erase memory
bcostm 0:be9d625054cd 49 qspi.Erase_Block(WRITE_READ_ADDR);
bcostm 0:be9d625054cd 50
bcostm 0:be9d625054cd 51 // Write memory
bcostm 0:be9d625054cd 52 qspi.Write(WriteBuffer, WRITE_READ_ADDR, 11);
bcostm 0:be9d625054cd 53
bcostm 0:be9d625054cd 54 // Read memory
bcostm 0:be9d625054cd 55 qspi.Read(ReadBuffer, WRITE_READ_ADDR, 11);
bcostm 0:be9d625054cd 56 ReadBuffer[11] = '\0';
bcostm 0:be9d625054cd 57 printf("Buffer read [%s]\n", ReadBuffer);
bcostm 0:be9d625054cd 58 }
bcostm 0:be9d625054cd 59
bcostm 0:be9d625054cd 60 */
bcostm 0:be9d625054cd 61 class QSPI_DISCO_F746NG
bcostm 0:be9d625054cd 62 {
bcostm 0:be9d625054cd 63
bcostm 0:be9d625054cd 64 public:
bcostm 0:be9d625054cd 65 //! Constructor
bcostm 0:be9d625054cd 66 QSPI_DISCO_F746NG();
bcostm 0:be9d625054cd 67
bcostm 0:be9d625054cd 68 //! Destructor
bcostm 0:be9d625054cd 69 ~QSPI_DISCO_F746NG();
bcostm 0:be9d625054cd 70
bcostm 0:be9d625054cd 71 /**
bcostm 0:be9d625054cd 72 * @brief Initializes the QSPI interface.
bcostm 0:be9d625054cd 73 * @retval QSPI memory status
bcostm 0:be9d625054cd 74 */
bcostm 0:be9d625054cd 75 uint8_t Init(void);
bcostm 0:be9d625054cd 76
bcostm 0:be9d625054cd 77 /**
bcostm 0:be9d625054cd 78 * @brief De-Initializes the QSPI interface.
bcostm 0:be9d625054cd 79 * @retval QSPI memory status
bcostm 0:be9d625054cd 80 */
bcostm 0:be9d625054cd 81 uint8_t DeInit(void);
bcostm 0:be9d625054cd 82
bcostm 0:be9d625054cd 83 /**
bcostm 0:be9d625054cd 84 * @brief Reads an amount of data from the QSPI memory.
bcostm 0:be9d625054cd 85 * @param pData: Pointer to data to be read
bcostm 0:be9d625054cd 86 * @param ReadAddr: Read start address
bcostm 0:be9d625054cd 87 * @param Size: Size of data to read
bcostm 0:be9d625054cd 88 * @retval QSPI memory status
bcostm 0:be9d625054cd 89 */
bcostm 0:be9d625054cd 90 uint8_t Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size);
bcostm 0:be9d625054cd 91
bcostm 0:be9d625054cd 92 /**
bcostm 0:be9d625054cd 93 * @brief Writes an amount of data to the QSPI memory.
bcostm 0:be9d625054cd 94 * @param pData: Pointer to data to be written
bcostm 0:be9d625054cd 95 * @param WriteAddr: Write start address
bcostm 0:be9d625054cd 96 * @param Size: Size of data to write
bcostm 0:be9d625054cd 97 * @retval QSPI memory status
bcostm 0:be9d625054cd 98 */
bcostm 0:be9d625054cd 99 uint8_t Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size);
bcostm 0:be9d625054cd 100
bcostm 0:be9d625054cd 101 /**
bcostm 0:be9d625054cd 102 * @brief Erases the specified block of the QSPI memory.
bcostm 0:be9d625054cd 103 * @param BlockAddress: Block address to erase
bcostm 0:be9d625054cd 104 * @retval QSPI memory status
bcostm 0:be9d625054cd 105 */
bcostm 0:be9d625054cd 106 uint8_t Erase_Block(uint32_t BlockAddress);
bcostm 0:be9d625054cd 107
bcostm 0:be9d625054cd 108 /**
bcostm 0:be9d625054cd 109 * @brief Erases the entire QSPI memory.
bcostm 0:be9d625054cd 110 * @retval QSPI memory status
bcostm 0:be9d625054cd 111 */
bcostm 0:be9d625054cd 112 uint8_t Erase_Chip(void);
bcostm 0:be9d625054cd 113
bcostm 0:be9d625054cd 114 /**
bcostm 0:be9d625054cd 115 * @brief Reads current status of the QSPI memory.
bcostm 0:be9d625054cd 116 * @retval QSPI memory status
bcostm 0:be9d625054cd 117 */
bcostm 0:be9d625054cd 118 uint8_t GetStatus(void);
bcostm 0:be9d625054cd 119
bcostm 0:be9d625054cd 120 /**
bcostm 0:be9d625054cd 121 * @brief Return the configuration of the QSPI memory.
bcostm 0:be9d625054cd 122 * @param pInfo: pointer on the configuration structure
bcostm 0:be9d625054cd 123 * @retval QSPI memory status
bcostm 0:be9d625054cd 124 */
bcostm 0:be9d625054cd 125 uint8_t GetInfo(QSPI_Info* pInfo);
bcostm 0:be9d625054cd 126
bcostm 0:be9d625054cd 127 /**
bcostm 0:be9d625054cd 128 * @brief Configure the QSPI in memory-mapped mode
bcostm 0:be9d625054cd 129 * @retval QSPI memory status
bcostm 0:be9d625054cd 130 */
bcostm 0:be9d625054cd 131 uint8_t EnableMemoryMappedMode(void);
bcostm 0:be9d625054cd 132
bcostm 0:be9d625054cd 133 private:
bcostm 0:be9d625054cd 134
bcostm 0:be9d625054cd 135 };
bcostm 0:be9d625054cd 136
bcostm 0:be9d625054cd 137 #else
bcostm 0:be9d625054cd 138 #error "This class must be used with DISCO_F746NG board only."
bcostm 0:be9d625054cd 139 #endif // TARGET_DISCO_F746NG
bcostm 0:be9d625054cd 140
bcostm 0:be9d625054cd 141 #endif