Implementation of the QSPI-Flash driver for the DISCO-STM32F746NG board. Allows usage of the MICRON 128Mb Quad-SPI Flash memory present on the board. Ported from library QSPI_DISCO_L476VG from ST.
QSPI_DISCO_F746NG.h@0:f391cd8f34c1, 2015-11-15 (annotated)
- Committer:
- capsavon
- Date:
- Sun Nov 15 14:29:29 2015 +0000
- Revision:
- 0:f391cd8f34c1
Corrected QSPI implementation.; Pins alternate function corrected (AF10 -> AF9).; Prescaler value corrected (0 -> 3).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
capsavon | 0:f391cd8f34c1 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
capsavon | 0:f391cd8f34c1 | 2 | * |
capsavon | 0:f391cd8f34c1 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
capsavon | 0:f391cd8f34c1 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
capsavon | 0:f391cd8f34c1 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
capsavon | 0:f391cd8f34c1 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
capsavon | 0:f391cd8f34c1 | 7 | * Software is furnished to do so, subject to the following conditions: |
capsavon | 0:f391cd8f34c1 | 8 | * |
capsavon | 0:f391cd8f34c1 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
capsavon | 0:f391cd8f34c1 | 10 | * substantial portions of the Software. |
capsavon | 0:f391cd8f34c1 | 11 | * |
capsavon | 0:f391cd8f34c1 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
capsavon | 0:f391cd8f34c1 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
capsavon | 0:f391cd8f34c1 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
capsavon | 0:f391cd8f34c1 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
capsavon | 0:f391cd8f34c1 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
capsavon | 0:f391cd8f34c1 | 17 | */ |
capsavon | 0:f391cd8f34c1 | 18 | |
capsavon | 0:f391cd8f34c1 | 19 | #ifndef __QSPI_DISCO_F746NG_H |
capsavon | 0:f391cd8f34c1 | 20 | #define __QSPI_DISCO_F746NG_H |
capsavon | 0:f391cd8f34c1 | 21 | |
capsavon | 0:f391cd8f34c1 | 22 | #ifdef TARGET_DISCO_F746NG |
capsavon | 0:f391cd8f34c1 | 23 | |
capsavon | 0:f391cd8f34c1 | 24 | #include "mbed.h" |
capsavon | 0:f391cd8f34c1 | 25 | #include "stm32746g_discovery_qspi.h" |
capsavon | 0:f391cd8f34c1 | 26 | |
capsavon | 0:f391cd8f34c1 | 27 | /* |
capsavon | 0:f391cd8f34c1 | 28 | Class to drive the QSPI external memory (N25Q128A device) |
capsavon | 0:f391cd8f34c1 | 29 | present on DISCO_F746NG board. |
capsavon | 0:f391cd8f34c1 | 30 | |
capsavon | 0:f391cd8f34c1 | 31 | Usage: |
capsavon | 0:f391cd8f34c1 | 32 | |
capsavon | 0:f391cd8f34c1 | 33 | */ |
capsavon | 0:f391cd8f34c1 | 34 | class QSPI_DISCO_F746NG |
capsavon | 0:f391cd8f34c1 | 35 | { |
capsavon | 0:f391cd8f34c1 | 36 | |
capsavon | 0:f391cd8f34c1 | 37 | public: |
capsavon | 0:f391cd8f34c1 | 38 | //! Constructor |
capsavon | 0:f391cd8f34c1 | 39 | QSPI_DISCO_F746NG(); |
capsavon | 0:f391cd8f34c1 | 40 | |
capsavon | 0:f391cd8f34c1 | 41 | //! Destructor |
capsavon | 0:f391cd8f34c1 | 42 | ~QSPI_DISCO_F746NG(); |
capsavon | 0:f391cd8f34c1 | 43 | |
capsavon | 0:f391cd8f34c1 | 44 | /** |
capsavon | 0:f391cd8f34c1 | 45 | * @brief Initializes the QSPI interface. |
capsavon | 0:f391cd8f34c1 | 46 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 47 | */ |
capsavon | 0:f391cd8f34c1 | 48 | uint8_t Init(void); |
capsavon | 0:f391cd8f34c1 | 49 | |
capsavon | 0:f391cd8f34c1 | 50 | /** |
capsavon | 0:f391cd8f34c1 | 51 | * @brief De-Initializes the QSPI interface. |
capsavon | 0:f391cd8f34c1 | 52 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 53 | */ |
capsavon | 0:f391cd8f34c1 | 54 | uint8_t DeInit(void); |
capsavon | 0:f391cd8f34c1 | 55 | |
capsavon | 0:f391cd8f34c1 | 56 | /** |
capsavon | 0:f391cd8f34c1 | 57 | * @brief Reads an amount of data from the QSPI memory. |
capsavon | 0:f391cd8f34c1 | 58 | * @param pData: Pointer to data to be read |
capsavon | 0:f391cd8f34c1 | 59 | * @param ReadAddr: Read start address |
capsavon | 0:f391cd8f34c1 | 60 | * @param Size: Size of data to read |
capsavon | 0:f391cd8f34c1 | 61 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 62 | */ |
capsavon | 0:f391cd8f34c1 | 63 | uint8_t Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size); |
capsavon | 0:f391cd8f34c1 | 64 | |
capsavon | 0:f391cd8f34c1 | 65 | /** |
capsavon | 0:f391cd8f34c1 | 66 | * @brief Writes an amount of data to the QSPI memory. |
capsavon | 0:f391cd8f34c1 | 67 | * @param pData: Pointer to data to be written |
capsavon | 0:f391cd8f34c1 | 68 | * @param WriteAddr: Write start address |
capsavon | 0:f391cd8f34c1 | 69 | * @param Size: Size of data to write |
capsavon | 0:f391cd8f34c1 | 70 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 71 | */ |
capsavon | 0:f391cd8f34c1 | 72 | uint8_t Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size); |
capsavon | 0:f391cd8f34c1 | 73 | |
capsavon | 0:f391cd8f34c1 | 74 | /** |
capsavon | 0:f391cd8f34c1 | 75 | * @brief Erases the specified block of the QSPI memory. |
capsavon | 0:f391cd8f34c1 | 76 | * @param BlockAddress: Block address to erase |
capsavon | 0:f391cd8f34c1 | 77 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 78 | */ |
capsavon | 0:f391cd8f34c1 | 79 | uint8_t Erase_Block(uint32_t BlockAddress); |
capsavon | 0:f391cd8f34c1 | 80 | |
capsavon | 0:f391cd8f34c1 | 81 | /** |
capsavon | 0:f391cd8f34c1 | 82 | * @brief Erases the specified sector of the QSPI memory. |
capsavon | 0:f391cd8f34c1 | 83 | * @param Sector: Sector address to erase (0 to 255); |
capsavon | 0:f391cd8f34c1 | 84 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 85 | * @note This function is non blocking meaning that sector erase |
capsavon | 0:f391cd8f34c1 | 86 | * operation is started but not completed when the function |
capsavon | 0:f391cd8f34c1 | 87 | * returns. Application has to call GetStatus(); |
capsavon | 0:f391cd8f34c1 | 88 | * to know when the device is available again (i.e. erase operation |
capsavon | 0:f391cd8f34c1 | 89 | * completed);. |
capsavon | 0:f391cd8f34c1 | 90 | */ |
capsavon | 0:f391cd8f34c1 | 91 | uint8_t Erase_Sector(uint32_t Sector); |
capsavon | 0:f391cd8f34c1 | 92 | |
capsavon | 0:f391cd8f34c1 | 93 | /** |
capsavon | 0:f391cd8f34c1 | 94 | * @brief Erases the entire QSPI memory. |
capsavon | 0:f391cd8f34c1 | 95 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 96 | */ |
capsavon | 0:f391cd8f34c1 | 97 | uint8_t Erase_Chip(void); |
capsavon | 0:f391cd8f34c1 | 98 | |
capsavon | 0:f391cd8f34c1 | 99 | /** |
capsavon | 0:f391cd8f34c1 | 100 | * @brief Reads current status of the QSPI memory. |
capsavon | 0:f391cd8f34c1 | 101 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 102 | */ |
capsavon | 0:f391cd8f34c1 | 103 | uint8_t GetStatus(void); |
capsavon | 0:f391cd8f34c1 | 104 | |
capsavon | 0:f391cd8f34c1 | 105 | /** |
capsavon | 0:f391cd8f34c1 | 106 | * @brief Return the configuration of the QSPI memory. |
capsavon | 0:f391cd8f34c1 | 107 | * @param pInfo: pointer on the configuration structure |
capsavon | 0:f391cd8f34c1 | 108 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 109 | */ |
capsavon | 0:f391cd8f34c1 | 110 | uint8_t GetInfo(QSPI_Info* pInfo); |
capsavon | 0:f391cd8f34c1 | 111 | |
capsavon | 0:f391cd8f34c1 | 112 | /** |
capsavon | 0:f391cd8f34c1 | 113 | * @brief Configure the QSPI in memory-mapped mode |
capsavon | 0:f391cd8f34c1 | 114 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 115 | */ |
capsavon | 0:f391cd8f34c1 | 116 | uint8_t EnableMemoryMappedMode(void); |
capsavon | 0:f391cd8f34c1 | 117 | |
capsavon | 0:f391cd8f34c1 | 118 | /** |
capsavon | 0:f391cd8f34c1 | 119 | * @brief This function suspends an ongoing erase command. |
capsavon | 0:f391cd8f34c1 | 120 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 121 | */ |
capsavon | 0:f391cd8f34c1 | 122 | uint8_t SuspendErase(void); |
capsavon | 0:f391cd8f34c1 | 123 | |
capsavon | 0:f391cd8f34c1 | 124 | /** |
capsavon | 0:f391cd8f34c1 | 125 | * @brief This function resumes a paused erase command. |
capsavon | 0:f391cd8f34c1 | 126 | * @retval QSPI memory status |
capsavon | 0:f391cd8f34c1 | 127 | */ |
capsavon | 0:f391cd8f34c1 | 128 | uint8_t ResumeErase(void); |
capsavon | 0:f391cd8f34c1 | 129 | |
capsavon | 0:f391cd8f34c1 | 130 | private: |
capsavon | 0:f391cd8f34c1 | 131 | |
capsavon | 0:f391cd8f34c1 | 132 | }; |
capsavon | 0:f391cd8f34c1 | 133 | |
capsavon | 0:f391cd8f34c1 | 134 | #else |
capsavon | 0:f391cd8f34c1 | 135 | #error "This class must be used with DISCO_F746NG board only." |
capsavon | 0:f391cd8f34c1 | 136 | #endif // TARGET_DISCO_F746NG |
capsavon | 0:f391cd8f34c1 | 137 | |
capsavon | 0:f391cd8f34c1 | 138 | #endif |