Fork of the offical HSP_RPC_GUI firmware

Dependencies:   USBDevice

Fork of MAXREFDES100 firmware for MAX32620HSP

Committer:
jbradshaw
Date:
Fri Apr 21 12:12:30 2017 -0500
Revision:
1:9490836294ea
Parent:
0:e4a10ed6eb92
Child:
3:8e9b9f5818aa
Flash device is now fully utilized for datalog of sensor data

Who changed what in which revision?

UserRevisionLine numberNew 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 1:9490836294ea 40 #define IOMUX_IO_ENABLE 1
jbradshaw 1:9490836294ea 41
jbradshaw 1:9490836294ea 42 #define S25FS512_SPI_PORT 1
jbradshaw 1:9490836294ea 43 #define S25FS512_CS_PIN 0
jbradshaw 1:9490836294ea 44 #define S25FS512_CS_POLARITY 0
jbradshaw 1:9490836294ea 45 #define S25FS512_CS_ACTIVITY_DELAY 0
jbradshaw 1:9490836294ea 46 #define S25FS512_CS_INACTIVITY_DELAY 0
jbradshaw 1:9490836294ea 47 #define S25FS512_CLK_HI 4
jbradshaw 1:9490836294ea 48 #define S25FS512_CLK_LOW 4
jbradshaw 1:9490836294ea 49 #define S25FS512_ALT_CLK 0
jbradshaw 1:9490836294ea 50 #define S25FS512_CLK_POLARITY 0
jbradshaw 1:9490836294ea 51 #define S25FS512_CLK_PHASE 0
jbradshaw 1:9490836294ea 52 #define S25FS512_WRITE 1
jbradshaw 1:9490836294ea 53 #define S25FS512_READ 0
jbradshaw 1:9490836294ea 54
jbradshaw 1:9490836294ea 55 ///< Byte addresses for flash configuration
jbradshaw 1:9490836294ea 56 #define Address_CR1NV 0x00000002
jbradshaw 1:9490836294ea 57 #define Address_CR1V 0x00800002
jbradshaw 1:9490836294ea 58 #define Address_CR2NV 0x00000003
jbradshaw 1:9490836294ea 59 #define Address_CR2V 0x00800003
jbradshaw 1:9490836294ea 60
jbradshaw 1:9490836294ea 61 #define INT_PORT_B 3
jbradshaw 1:9490836294ea 62 #define INT_PIN_B 6
jbradshaw 1:9490836294ea 63
jbradshaw 1:9490836294ea 64
jbradshaw 0:e4a10ed6eb92 65 class S25FS512 {
jbradshaw 0:e4a10ed6eb92 66 public:
jbradshaw 1:9490836294ea 67
jbradshaw 1:9490836294ea 68 ///< @detail S25FS512 Commands
jbradshaw 1:9490836294ea 69 typedef enum{
jbradshaw 1:9490836294ea 70 Write_Reg = 0x01,
jbradshaw 1:9490836294ea 71 Read_Status_Reg1 = 0x05,
jbradshaw 1:9490836294ea 72 Write_Enable = 0x06,
jbradshaw 1:9490836294ea 73 Erase_4k = 0x20,
jbradshaw 1:9490836294ea 74 Bulk_Erase = 0x60,
jbradshaw 1:9490836294ea 75 Read_Any_Reg = 0x65,
jbradshaw 1:9490836294ea 76 Software_Reset_Enable = 0x66,
jbradshaw 1:9490836294ea 77 Write_Any_Reg = 0x71,
jbradshaw 1:9490836294ea 78 Software_Reset = 0x99,
jbradshaw 1:9490836294ea 79 Read_Id = 0x9F,
jbradshaw 1:9490836294ea 80 Erase_64k_256k = 0xD8,
jbradshaw 1:9490836294ea 81 Quad_IO_Read = 0xEB,
jbradshaw 1:9490836294ea 82 } S25FS512_Commands_t;
jbradshaw 1:9490836294ea 83
jbradshaw 0:e4a10ed6eb92 84 S25FS512(QuadSpiInterface *_quadSpiInterface);
jbradshaw 0:e4a10ed6eb92 85 ~S25FS512(void);
jbradshaw 0:e4a10ed6eb92 86
jbradshaw 0:e4a10ed6eb92 87 QuadSpiInterface *quadSpiInterface;
jbradshaw 0:e4a10ed6eb92 88
jbradshaw 1:9490836294ea 89 /** @brief Initialize the driver
jbradshaw 0:e4a10ed6eb92 90 */
jbradshaw 1:9490836294ea 91 void init(void);
jbradshaw 0:e4a10ed6eb92 92
jbradshaw 1:9490836294ea 93 /** @brief Detect the presence of the flash device
jbradshaw 0:e4a10ed6eb92 94 */
jbradshaw 0:e4a10ed6eb92 95 uint8_t detect(void);
jbradshaw 0:e4a10ed6eb92 96
jbradshaw 1:9490836294ea 97 /** @brief Read the identification of the flash
jbradshaw 0:e4a10ed6eb92 98 */
jbradshaw 0:e4a10ed6eb92 99 int8_t readIdentification(uint8_t *dataArray, uint8_t length);
jbradshaw 0:e4a10ed6eb92 100
jbradshaw 1:9490836294ea 101 /** @brief Bulk erase the flash device
jbradshaw 0:e4a10ed6eb92 102 */
jbradshaw 0:e4a10ed6eb92 103 int8_t bulkErase_Helper(void);
jbradshaw 0:e4a10ed6eb92 104
jbradshaw 1:9490836294ea 105 /** @brief Erase Parameter Sectors
jbradshaw 0:e4a10ed6eb92 106 */
jbradshaw 0:e4a10ed6eb92 107 int8_t parameterSectorErase_Helper(uint32_t address);
jbradshaw 0:e4a10ed6eb92 108
jbradshaw 1:9490836294ea 109 /** @brief Write a Page
jbradshaw 0:e4a10ed6eb92 110 */
jbradshaw 1:9490836294ea 111 int8_t writePage_Helper(uint32_t pageNumber, uint8_t *buffer, uint32_t offset);
jbradshaw 1:9490836294ea 112
jbradshaw 1:9490836294ea 113 /** @brief Read a Page
jbradshaw 1:9490836294ea 114 */
jbradshaw 1:9490836294ea 115 int8_t readPages_Helper(uint32_t startPageNumber,uint32_t endPageNumber, uint8_t *buffer, uint32_t offset);
jbradshaw 0:e4a10ed6eb92 116
jbradshaw 1:9490836294ea 117 /** @brief Erase a Sector
jbradshaw 0:e4a10ed6eb92 118 @param address Address of sector to erase
jbradshaw 0:e4a10ed6eb92 119 */
jbradshaw 1:9490836294ea 120 int8_t sectorErase_Helper(uint32_t address);
jbradshaw 0:e4a10ed6eb92 121
jbradshaw 1:9490836294ea 122 /** @brief Scans through byte pointer for a page worth of data to see if the page is all FFs
jbradshaw 0:e4a10ed6eb92 123 @param ptr Byte pointer to buffer to scan
jbradshaw 0:e4a10ed6eb92 124 @return Returns a 1 if the page is empty, 0 if it is not all FFs
jbradshaw 0:e4a10ed6eb92 125 */
jbradshaw 1:9490836294ea 126 bool isPageEmpty(uint8_t *ptr);
jbradshaw 1:9490836294ea 127
jbradshaw 1:9490836294ea 128 /** @brief Issue a software reset to the flash device
jbradshaw 0:e4a10ed6eb92 129 */
jbradshaw 0:e4a10ed6eb92 130 uint8_t reset(void);
jbradshaw 1:9490836294ea 131
jbradshaw 1:9490836294ea 132 /** @brief Enable a hardware reset
jbradshaw 0:e4a10ed6eb92 133 */
jbradshaw 0:e4a10ed6eb92 134 uint8_t enableHWReset(void);
jbradshaw 1:9490836294ea 135
jbradshaw 1:9490836294ea 136 /** @brief Read the id byte of this device
jbradshaw 0:e4a10ed6eb92 137 */
jbradshaw 0:e4a10ed6eb92 138 void readID(uint8_t *id);
jbradshaw 0:e4a10ed6eb92 139
jbradshaw 1:9490836294ea 140 void test_verifyPage0Empty(uint8_t *ptr, int currentPage, int pagesWrittenTo);
jbradshaw 1:9490836294ea 141
jbradshaw 0:e4a10ed6eb92 142 private:
jbradshaw 1:9490836294ea 143 void disableInterrupt(uint8_t state);
jbradshaw 0:e4a10ed6eb92 144 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 145 int8_t reg_write_read_multiple_quad(uint8_t *dataIn, uint8_t numberIn, uint8_t *dataOut, uint8_t numberOut);
jbradshaw 0:e4a10ed6eb92 146 int8_t reg_write_read_multiple_4Wire(uint8_t *bufferOut, uint8_t numberOut, uint8_t *bufferIn, uint8_t numberIn);
jbradshaw 0:e4a10ed6eb92 147 uint8_t spiWriteRead (uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData);
jbradshaw 0:e4a10ed6eb92 148 uint8_t spiWriteRead4Wire(uint8_t writeNumber,uint8_t *writeData, uint8_t readNumber, uint8_t *readData);
jbradshaw 0:e4a10ed6eb92 149 int8_t writeAnyRegister(uint32_t address, uint8_t data);
jbradshaw 0:e4a10ed6eb92 150 int8_t writeAnyRegister4Wire(uint32_t address, uint8_t data);
jbradshaw 0:e4a10ed6eb92 151 int8_t writeRegisters(void);
jbradshaw 0:e4a10ed6eb92 152 uint8_t wren(void);
jbradshaw 0:e4a10ed6eb92 153 int setQuadMode(void);
jbradshaw 0:e4a10ed6eb92 154 int wren4Wire(void);
jbradshaw 0:e4a10ed6eb92 155 // int8_t setQuadMode();
jbradshaw 0:e4a10ed6eb92 156 int8_t readAnyRegister(uint32_t address, uint8_t *data, uint32_t length);
jbradshaw 0:e4a10ed6eb92 157 int8_t bulkErase(void);
jbradshaw 0:e4a10ed6eb92 158 int8_t pageProgram(uint32_t address, uint8_t *buffer);
jbradshaw 0:e4a10ed6eb92 159 int8_t quadIoRead_Pages(uint32_t address, uint8_t *buffer, uint32_t numberOfPages);
jbradshaw 0:e4a10ed6eb92 160 int8_t checkBusy(void);
jbradshaw 0:e4a10ed6eb92 161 void waitTillNotBusy(void);
jbradshaw 0:e4a10ed6eb92 162 int8_t sectorErase(uint32_t address);
jbradshaw 0:e4a10ed6eb92 163 int8_t parameterSectorErase(uint32_t address);
jbradshaw 1:9490836294ea 164
jbradshaw 1:9490836294ea 165 uint8_t flashBuffer[257 + 10];
jbradshaw 0:e4a10ed6eb92 166 };
jbradshaw 0:e4a10ed6eb92 167 #endif /* S25FS512_H_ */