Wilson Tang
/
HSP_RPC_GUI
Fork of the offical HSP_RPC_GUI firmware
Fork of MAXREFDES100 firmware for MAX32620HSP
Diff: HSP/Devices/S25FS256/S25FS512.h
- Revision:
- 1:9490836294ea
- Parent:
- 0:e4a10ed6eb92
- Child:
- 3:8e9b9f5818aa
--- a/HSP/Devices/S25FS256/S25FS512.h Tue Oct 25 15:22:11 2016 +0000 +++ b/HSP/Devices/S25FS256/S25FS512.h Fri Apr 21 12:12:30 2017 -0500 @@ -36,75 +36,116 @@ #include "mbed.h" #include "QuadSpiInterface.h" + +#define IOMUX_IO_ENABLE 1 + +#define S25FS512_SPI_PORT 1 +#define S25FS512_CS_PIN 0 +#define S25FS512_CS_POLARITY 0 +#define S25FS512_CS_ACTIVITY_DELAY 0 +#define S25FS512_CS_INACTIVITY_DELAY 0 +#define S25FS512_CLK_HI 4 +#define S25FS512_CLK_LOW 4 +#define S25FS512_ALT_CLK 0 +#define S25FS512_CLK_POLARITY 0 +#define S25FS512_CLK_PHASE 0 +#define S25FS512_WRITE 1 +#define S25FS512_READ 0 + +///< Byte addresses for flash configuration +#define Address_CR1NV 0x00000002 +#define Address_CR1V 0x00800002 +#define Address_CR2NV 0x00000003 +#define Address_CR2V 0x00800003 + +#define INT_PORT_B 3 +#define INT_PIN_B 6 + + class S25FS512 { public: + + ///< @detail S25FS512 Commands + typedef enum{ + Write_Reg = 0x01, + Read_Status_Reg1 = 0x05, + Write_Enable = 0x06, + Erase_4k = 0x20, + Bulk_Erase = 0x60, + Read_Any_Reg = 0x65, + Software_Reset_Enable = 0x66, + Write_Any_Reg = 0x71, + Software_Reset = 0x99, + Read_Id = 0x9F, + Erase_64k_256k = 0xD8, + Quad_IO_Read = 0xEB, + } S25FS512_Commands_t; + S25FS512(QuadSpiInterface *_quadSpiInterface); ~S25FS512(void); QuadSpiInterface *quadSpiInterface; - /** Initialize the driver + /** @brief Initialize the driver */ - int init(void); + void init(void); - /** Detect the presence of the flash device + /** @brief Detect the presence of the flash device */ uint8_t detect(void); - /** Read the identification of the flash + /** @brief Read the identification of the flash */ int8_t readIdentification(uint8_t *dataArray, uint8_t length); - /** Bulk erase the flash device + /** @brief Bulk erase the flash device */ int8_t bulkErase_Helper(void); - /** Erase Parameter Sectors + /** @brief Erase Parameter Sectors */ int8_t parameterSectorErase_Helper(uint32_t address); - /** Write a Page + /** @brief Write a Page */ - int8_t writePage_Helper(uint32_t pageNumber, uint8_t *buffer, - uint32_t offset); + int8_t writePage_Helper(uint32_t pageNumber, uint8_t *buffer, uint32_t offset); + + /** @brief Read a Page + */ + int8_t readPages_Helper(uint32_t startPageNumber,uint32_t endPageNumber, uint8_t *buffer, uint32_t offset); - /** Read a Page - * @param - */ - int8_t readPages_Helper(uint32_t startPageNumber, uint32_t endPageNumber, - uint8_t *buffer, uint32_t offset); - - /** Erase a Sector + /** @brief Erase a Sector @param address Address of sector to erase */ + int8_t sectorErase_Helper(uint32_t address); - int8_t sectorErase_Helper(uint32_t address); - /** Scans through byte pointer for a page worth of data to see if the page is all FFs + /** @brief Scans through byte pointer for a page worth of data to see if the page is all FFs @param ptr Byte pointer to buffer to scan @return Returns a 1 if the page is empty, 0 if it is not all FFs */ - uint32_t isPageEmpty(uint8_t *ptr); - - /** Issue a software reset to the flash device + bool isPageEmpty(uint8_t *ptr); + + /** @brief Issue a software reset to the flash device */ - uint8_t reset(void); - /** Enable a hardware reset + + /** @brief Enable a hardware reset */ - uint8_t enableHWReset(void); - /** Read the id byte of this device + + /** @brief Read the id byte of this device */ - void readID(uint8_t *id); + void test_verifyPage0Empty(uint8_t *ptr, int currentPage, int pagesWrittenTo); + private: + void disableInterrupt(uint8_t state); int8_t reg_write_read_multiple_quad_last(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut, uint8_t last); int8_t reg_write_read_multiple_quad(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut); int8_t reg_write_read_multiple_4Wire(uint8_t *bufferOut, uint8_t numberOut, uint8_t *bufferIn, uint8_t numberIn); uint8_t spiWriteRead (uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData); uint8_t spiWriteRead4Wire(uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData); - int8_t writeAnyRegister(uint32_t address, uint8_t data); int8_t writeAnyRegister4Wire(uint32_t address, uint8_t data); int8_t writeRegisters(void); @@ -120,8 +161,7 @@ void waitTillNotBusy(void); int8_t sectorErase(uint32_t address); int8_t parameterSectorErase(uint32_t address); - void wait_1mS(void); - void wait_100uS(void); - void wait_10mS(void); + + uint8_t flashBuffer[257 + 10]; }; #endif /* S25FS512_H_ */