Wilson Tang
/
HSP_RPC_GUI
Fork of the offical HSP_RPC_GUI firmware
Fork of MAXREFDES100 firmware for MAX32620HSP
HSP/Devices/S25FS256/S25FS512.h@4:18155622d30a, 2020-01-28 (annotated)
- Committer:
- wt8008
- Date:
- Tue Jan 28 20:22:16 2020 +0000
- Revision:
- 4:18155622d30a
- Parent:
- 3:8e9b9f5818aa
Update Maxim's USBDevice project to the latest version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbradshaw | 0:e4a10ed6eb92 | 1 | /******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
jbradshaw | 0:e4a10ed6eb92 | 3 | * |
jbradshaw | 0:e4a10ed6eb92 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
jbradshaw | 0:e4a10ed6eb92 | 5 | * copy of this software and associated documentation files (the "Software"), |
jbradshaw | 0:e4a10ed6eb92 | 6 | * to deal in the Software without restriction, including without limitation |
jbradshaw | 0:e4a10ed6eb92 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
jbradshaw | 0:e4a10ed6eb92 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
jbradshaw | 0:e4a10ed6eb92 | 9 | * Software is furnished to do so, subject to the following conditions: |
jbradshaw | 0:e4a10ed6eb92 | 10 | * |
jbradshaw | 0:e4a10ed6eb92 | 11 | * The above copyright notice and this permission notice shall be included |
jbradshaw | 0:e4a10ed6eb92 | 12 | * in all copies or substantial portions of the Software. |
jbradshaw | 0:e4a10ed6eb92 | 13 | * |
jbradshaw | 0:e4a10ed6eb92 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
jbradshaw | 0:e4a10ed6eb92 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
jbradshaw | 0:e4a10ed6eb92 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
jbradshaw | 0:e4a10ed6eb92 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
jbradshaw | 0:e4a10ed6eb92 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
jbradshaw | 0:e4a10ed6eb92 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
jbradshaw | 0:e4a10ed6eb92 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
jbradshaw | 0:e4a10ed6eb92 | 21 | * |
jbradshaw | 0:e4a10ed6eb92 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 24 | * Products, Inc. Branding Policy. |
jbradshaw | 0:e4a10ed6eb92 | 25 | * |
jbradshaw | 0:e4a10ed6eb92 | 26 | * The mere transfer of this software does not imply any licenses |
jbradshaw | 0:e4a10ed6eb92 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
jbradshaw | 0:e4a10ed6eb92 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
jbradshaw | 0:e4a10ed6eb92 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
jbradshaw | 0:e4a10ed6eb92 | 30 | * ownership rights. |
jbradshaw | 0:e4a10ed6eb92 | 31 | ******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 32 | */ |
jbradshaw | 0:e4a10ed6eb92 | 33 | #ifndef S25FS512_H_ |
jbradshaw | 0:e4a10ed6eb92 | 34 | #define S25FS512_H_ |
jbradshaw | 0:e4a10ed6eb92 | 35 | |
jbradshaw | 0:e4a10ed6eb92 | 36 | #include "mbed.h" |
jbradshaw | 0:e4a10ed6eb92 | 37 | #include "QuadSpiInterface.h" |
jbradshaw | 0:e4a10ed6eb92 | 38 | |
jbradshaw | 1:9490836294ea | 39 | |
jbradshaw | 3:8e9b9f5818aa | 40 | #define ADDRESS_INC_4K 0x1000 |
jbradshaw | 3:8e9b9f5818aa | 41 | #define ADDRESS_INC_32K 0x8000 |
jbradshaw | 3:8e9b9f5818aa | 42 | #define ADDRESS_INC_64K 0x10000 |
jbradshaw | 3:8e9b9f5818aa | 43 | |
jbradshaw | 3:8e9b9f5818aa | 44 | #define ADDRESS_4K_START 0x0 |
jbradshaw | 3:8e9b9f5818aa | 45 | #define ADDRESS_4K_END 0x8000 |
jbradshaw | 3:8e9b9f5818aa | 46 | |
jbradshaw | 3:8e9b9f5818aa | 47 | #define ADDRESS_32K_START 0x8000 |
jbradshaw | 3:8e9b9f5818aa | 48 | #define ADDRESS_32k_END 0x10000 |
jbradshaw | 3:8e9b9f5818aa | 49 | |
jbradshaw | 3:8e9b9f5818aa | 50 | #define ADDRESS_64K_START 0x10000 |
jbradshaw | 3:8e9b9f5818aa | 51 | #define ADDRESS_64k_END 0x2000000 |
jbradshaw | 3:8e9b9f5818aa | 52 | |
jbradshaw | 3:8e9b9f5818aa | 53 | #define SIZE_OF_EXTERNAL_FLASH 0x2000000 // 33,554,432 Bytes |
jbradshaw | 3:8e9b9f5818aa | 54 | #define SIZE_OF_PAGE 0x100 |
jbradshaw | 3:8e9b9f5818aa | 55 | |
jbradshaw | 1:9490836294ea | 56 | #define IOMUX_IO_ENABLE 1 |
jbradshaw | 1:9490836294ea | 57 | |
jbradshaw | 1:9490836294ea | 58 | #define S25FS512_SPI_PORT 1 |
jbradshaw | 1:9490836294ea | 59 | #define S25FS512_CS_PIN 0 |
jbradshaw | 1:9490836294ea | 60 | #define S25FS512_CS_POLARITY 0 |
jbradshaw | 1:9490836294ea | 61 | #define S25FS512_CS_ACTIVITY_DELAY 0 |
jbradshaw | 1:9490836294ea | 62 | #define S25FS512_CS_INACTIVITY_DELAY 0 |
jbradshaw | 1:9490836294ea | 63 | #define S25FS512_CLK_HI 4 |
jbradshaw | 1:9490836294ea | 64 | #define S25FS512_CLK_LOW 4 |
jbradshaw | 1:9490836294ea | 65 | #define S25FS512_ALT_CLK 0 |
jbradshaw | 1:9490836294ea | 66 | #define S25FS512_CLK_POLARITY 0 |
jbradshaw | 1:9490836294ea | 67 | #define S25FS512_CLK_PHASE 0 |
jbradshaw | 1:9490836294ea | 68 | #define S25FS512_WRITE 1 |
jbradshaw | 1:9490836294ea | 69 | #define S25FS512_READ 0 |
jbradshaw | 1:9490836294ea | 70 | |
jbradshaw | 1:9490836294ea | 71 | ///< Byte addresses for flash configuration |
jbradshaw | 1:9490836294ea | 72 | #define Address_CR1NV 0x00000002 |
jbradshaw | 1:9490836294ea | 73 | #define Address_CR1V 0x00800002 |
jbradshaw | 1:9490836294ea | 74 | #define Address_CR2NV 0x00000003 |
jbradshaw | 1:9490836294ea | 75 | #define Address_CR2V 0x00800003 |
jbradshaw | 1:9490836294ea | 76 | |
jbradshaw | 1:9490836294ea | 77 | #define INT_PORT_B 3 |
jbradshaw | 1:9490836294ea | 78 | #define INT_PIN_B 6 |
jbradshaw | 1:9490836294ea | 79 | |
jbradshaw | 1:9490836294ea | 80 | |
jbradshaw | 0:e4a10ed6eb92 | 81 | class S25FS512 { |
jbradshaw | 0:e4a10ed6eb92 | 82 | public: |
jbradshaw | 1:9490836294ea | 83 | |
jbradshaw | 1:9490836294ea | 84 | ///< @detail S25FS512 Commands |
jbradshaw | 1:9490836294ea | 85 | typedef enum{ |
jbradshaw | 1:9490836294ea | 86 | Write_Reg = 0x01, |
jbradshaw | 1:9490836294ea | 87 | Read_Status_Reg1 = 0x05, |
jbradshaw | 1:9490836294ea | 88 | Write_Enable = 0x06, |
jbradshaw | 1:9490836294ea | 89 | Erase_4k = 0x20, |
jbradshaw | 1:9490836294ea | 90 | Bulk_Erase = 0x60, |
jbradshaw | 1:9490836294ea | 91 | Read_Any_Reg = 0x65, |
jbradshaw | 1:9490836294ea | 92 | Software_Reset_Enable = 0x66, |
jbradshaw | 1:9490836294ea | 93 | Write_Any_Reg = 0x71, |
jbradshaw | 1:9490836294ea | 94 | Software_Reset = 0x99, |
jbradshaw | 1:9490836294ea | 95 | Read_Id = 0x9F, |
jbradshaw | 1:9490836294ea | 96 | Erase_64k_256k = 0xD8, |
jbradshaw | 1:9490836294ea | 97 | Quad_IO_Read = 0xEB, |
jbradshaw | 1:9490836294ea | 98 | } S25FS512_Commands_t; |
jbradshaw | 1:9490836294ea | 99 | |
jbradshaw | 0:e4a10ed6eb92 | 100 | S25FS512(QuadSpiInterface *_quadSpiInterface); |
jbradshaw | 0:e4a10ed6eb92 | 101 | ~S25FS512(void); |
jbradshaw | 0:e4a10ed6eb92 | 102 | |
jbradshaw | 0:e4a10ed6eb92 | 103 | QuadSpiInterface *quadSpiInterface; |
jbradshaw | 0:e4a10ed6eb92 | 104 | |
jbradshaw | 1:9490836294ea | 105 | /** @brief Initialize the driver |
jbradshaw | 0:e4a10ed6eb92 | 106 | */ |
jbradshaw | 1:9490836294ea | 107 | void init(void); |
jbradshaw | 0:e4a10ed6eb92 | 108 | |
jbradshaw | 1:9490836294ea | 109 | /** @brief Detect the presence of the flash device |
jbradshaw | 0:e4a10ed6eb92 | 110 | */ |
jbradshaw | 0:e4a10ed6eb92 | 111 | uint8_t detect(void); |
jbradshaw | 0:e4a10ed6eb92 | 112 | |
jbradshaw | 1:9490836294ea | 113 | /** @brief Read the identification of the flash |
jbradshaw | 0:e4a10ed6eb92 | 114 | */ |
jbradshaw | 0:e4a10ed6eb92 | 115 | int8_t readIdentification(uint8_t *dataArray, uint8_t length); |
jbradshaw | 0:e4a10ed6eb92 | 116 | |
jbradshaw | 1:9490836294ea | 117 | /** @brief Bulk erase the flash device |
jbradshaw | 0:e4a10ed6eb92 | 118 | */ |
jbradshaw | 0:e4a10ed6eb92 | 119 | int8_t bulkErase_Helper(void); |
jbradshaw | 0:e4a10ed6eb92 | 120 | |
jbradshaw | 1:9490836294ea | 121 | /** @brief Erase Parameter Sectors |
jbradshaw | 0:e4a10ed6eb92 | 122 | */ |
jbradshaw | 0:e4a10ed6eb92 | 123 | int8_t parameterSectorErase_Helper(uint32_t address); |
jbradshaw | 0:e4a10ed6eb92 | 124 | |
jbradshaw | 1:9490836294ea | 125 | /** @brief Write a Page |
jbradshaw | 0:e4a10ed6eb92 | 126 | */ |
jbradshaw | 1:9490836294ea | 127 | int8_t writePage_Helper(uint32_t pageNumber, uint8_t *buffer, uint32_t offset); |
jbradshaw | 1:9490836294ea | 128 | |
jbradshaw | 1:9490836294ea | 129 | /** @brief Read a Page |
jbradshaw | 1:9490836294ea | 130 | */ |
jbradshaw | 1:9490836294ea | 131 | int8_t readPages_Helper(uint32_t startPageNumber,uint32_t endPageNumber, uint8_t *buffer, uint32_t offset); |
jbradshaw | 0:e4a10ed6eb92 | 132 | |
jbradshaw | 1:9490836294ea | 133 | /** @brief Erase a Sector |
jbradshaw | 0:e4a10ed6eb92 | 134 | @param address Address of sector to erase |
jbradshaw | 0:e4a10ed6eb92 | 135 | */ |
jbradshaw | 1:9490836294ea | 136 | int8_t sectorErase_Helper(uint32_t address); |
jbradshaw | 0:e4a10ed6eb92 | 137 | |
jbradshaw | 1:9490836294ea | 138 | /** @brief Scans through byte pointer for a page worth of data to see if the page is all FFs |
jbradshaw | 0:e4a10ed6eb92 | 139 | @param ptr Byte pointer to buffer to scan |
jbradshaw | 0:e4a10ed6eb92 | 140 | @return Returns a 1 if the page is empty, 0 if it is not all FFs |
jbradshaw | 0:e4a10ed6eb92 | 141 | */ |
jbradshaw | 1:9490836294ea | 142 | bool isPageEmpty(uint8_t *ptr); |
jbradshaw | 1:9490836294ea | 143 | |
jbradshaw | 1:9490836294ea | 144 | /** @brief Issue a software reset to the flash device |
jbradshaw | 0:e4a10ed6eb92 | 145 | */ |
jbradshaw | 0:e4a10ed6eb92 | 146 | uint8_t reset(void); |
jbradshaw | 1:9490836294ea | 147 | |
jbradshaw | 1:9490836294ea | 148 | /** @brief Enable a hardware reset |
jbradshaw | 0:e4a10ed6eb92 | 149 | */ |
jbradshaw | 0:e4a10ed6eb92 | 150 | uint8_t enableHWReset(void); |
jbradshaw | 1:9490836294ea | 151 | |
jbradshaw | 1:9490836294ea | 152 | /** @brief Read the id byte of this device |
jbradshaw | 0:e4a10ed6eb92 | 153 | */ |
jbradshaw | 0:e4a10ed6eb92 | 154 | void readID(uint8_t *id); |
jbradshaw | 0:e4a10ed6eb92 | 155 | |
jbradshaw | 1:9490836294ea | 156 | void test_verifyPage0Empty(uint8_t *ptr, int currentPage, int pagesWrittenTo); |
jbradshaw | 1:9490836294ea | 157 | |
jbradshaw | 3:8e9b9f5818aa | 158 | int8_t readPartialPage_Helper(uint32_t pageNumber, uint8_t *buffer, uint32_t count); |
jbradshaw | 3:8e9b9f5818aa | 159 | |
jbradshaw | 0:e4a10ed6eb92 | 160 | private: |
jbradshaw | 1:9490836294ea | 161 | void disableInterrupt(uint8_t state); |
jbradshaw | 0:e4a10ed6eb92 | 162 | int8_t reg_write_read_multiple_quad_last(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut, uint8_t last); |
jbradshaw | 0:e4a10ed6eb92 | 163 | int8_t reg_write_read_multiple_quad(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut); |
jbradshaw | 0:e4a10ed6eb92 | 164 | int8_t reg_write_read_multiple_4Wire(uint8_t *bufferOut, uint8_t numberOut, uint8_t *bufferIn, uint8_t numberIn); |
jbradshaw | 0:e4a10ed6eb92 | 165 | uint8_t spiWriteRead (uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData); |
jbradshaw | 0:e4a10ed6eb92 | 166 | uint8_t spiWriteRead4Wire(uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData); |
jbradshaw | 0:e4a10ed6eb92 | 167 | int8_t writeAnyRegister(uint32_t address, uint8_t data); |
jbradshaw | 0:e4a10ed6eb92 | 168 | int8_t writeAnyRegister4Wire(uint32_t address, uint8_t data); |
jbradshaw | 0:e4a10ed6eb92 | 169 | int8_t writeRegisters(void); |
jbradshaw | 0:e4a10ed6eb92 | 170 | uint8_t wren(void); |
jbradshaw | 0:e4a10ed6eb92 | 171 | int setQuadMode(void); |
jbradshaw | 0:e4a10ed6eb92 | 172 | int wren4Wire(void); |
jbradshaw | 0:e4a10ed6eb92 | 173 | // int8_t setQuadMode(); |
jbradshaw | 0:e4a10ed6eb92 | 174 | int8_t readAnyRegister(uint32_t address, uint8_t *data, uint32_t length); |
jbradshaw | 0:e4a10ed6eb92 | 175 | int8_t bulkErase(void); |
jbradshaw | 0:e4a10ed6eb92 | 176 | int8_t pageProgram(uint32_t address, uint8_t *buffer); |
jbradshaw | 0:e4a10ed6eb92 | 177 | int8_t quadIoRead_Pages(uint32_t address, uint8_t *buffer, uint32_t numberOfPages); |
jbradshaw | 0:e4a10ed6eb92 | 178 | int8_t checkBusy(void); |
jbradshaw | 0:e4a10ed6eb92 | 179 | void waitTillNotBusy(void); |
jbradshaw | 0:e4a10ed6eb92 | 180 | int8_t sectorErase(uint32_t address); |
jbradshaw | 0:e4a10ed6eb92 | 181 | int8_t parameterSectorErase(uint32_t address); |
jbradshaw | 3:8e9b9f5818aa | 182 | int8_t quadIoRead_PartialPage(uint32_t address, uint8_t *buffer, uint32_t numberOfBytesInPage); |
jbradshaw | 1:9490836294ea | 183 | |
jbradshaw | 1:9490836294ea | 184 | uint8_t flashBuffer[257 + 10]; |
jbradshaw | 0:e4a10ed6eb92 | 185 | }; |
jbradshaw | 0:e4a10ed6eb92 | 186 | #endif /* S25FS512_H_ */ |