MAX30001-MAX32630FTHR SYS EvKit
Dependencies: USBDevice max32630fthr
Max30001 EVKIT Summary
The MAX30001 EVKIT SYS-MBED Evaluation System (EV System) is used to evaluates the MAX30001 sensor, which is an ECG (electrocardiogram), biopotential and bioimpedance analog front end solution for wearable applications. The full EV System consists of the MAX32630FTHR Development board (DEV board) and MAX30001 sensor board and the evaluation software. The EvKit features EKG, PACE, RtoR (R-peak timing), Bio-Z, and raw data logging.
The MAX30001 EVKIT SYS-MBED evaluation system is assembled, tested and contains the necessary circuitry and connections to evaluate the MAX30001 sensor.
When evaluated as an EV System, the MAX32630FTHR board provides the necessary logic rails, master clock, SPI, USB-to-Serial interfaces that are needed to evaluate the MAX30001 sensor board. MAX32630FTHR can be used as an independent development platform. Another wiki page for that platform is available here.
Communication with the DEV board is facilitated by Windows 7, Windows 8 and Windows 10 compatible software that provides a simple and intuitive graphical user interface (GUI).
HSP/Devices/S25FS256/S25FS512.cpp@2:e2ce56bb0d2e, 2018-04-12 (annotated)
- Committer:
- Emre.Eken
- Date:
- Thu Apr 12 13:47:56 2018 +0300
- Revision:
- 2:e2ce56bb0d2e
- Parent:
- 0:8e4630a71eb1
main.cpp path is changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 1 | /******************************************************************************* |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 3 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 5 | * copy of this software and associated documentation files (the "Software"), |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 6 | * to deal in the Software without restriction, including without limitation |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 9 | * Software is furnished to do so, subject to the following conditions: |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 10 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 11 | * The above copyright notice and this permission notice shall be included |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 12 | * in all copies or substantial portions of the Software. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 13 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 21 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 24 | * Products, Inc. Branding Policy. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 25 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 26 | * The mere transfer of this software does not imply any licenses |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 30 | * ownership rights. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 31 | ******************************************************************************* |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 32 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 33 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 34 | // |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 35 | // Flash Non-Volatile Memory |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 36 | // U27 S25FS512 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 37 | // Nimitz SPIM1 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 38 | // |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 39 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 40 | #include "mbed.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 41 | #include "S25FS512.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 42 | #include "QuadSpiInterface.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 43 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 44 | #define IOMUX_IO_ENABLE 1 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 45 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 46 | #define S25FS512_SPI_PORT 1 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 47 | #define S25FS512_CS_PIN 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 48 | #define S25FS512_CS_POLARITY 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 49 | #define S25FS512_CS_ACTIVITY_DELAY 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 50 | #define S25FS512_CS_INACTIVITY_DELAY 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 51 | #define S25FS512_CLK_HI 4 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 52 | #define S25FS512_CLK_LOW 4 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 53 | #define S25FS512_ALT_CLK 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 54 | #define S25FS512_CLK_POLARITY 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 55 | #define S25FS512_CLK_PHASE 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 56 | #define S25FS512_WRITE 1 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 57 | #define S25FS512_READ 0 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 58 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 59 | #define INT_PORT_B 3 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 60 | #define INT_PIN_B 6 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 61 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 62 | uint8_t flashBuffer[257 + 10]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 63 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 64 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 65 | S25FS512::S25FS512(QuadSpiInterface *_quadSpiInterface) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 66 | this->quadSpiInterface = _quadSpiInterface; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 67 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 68 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 69 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 70 | S25FS512::~S25FS512(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 71 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 72 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 73 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 74 | int S25FS512::init(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 75 | setQuadMode(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 76 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 77 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 78 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 79 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 80 | int S25FS512::wren4Wire(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 81 | uint8_t cmdArray[8]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 82 | // Send WREN |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 83 | cmdArray[0] = 0x06; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 84 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 85 | return reg_write_read_multiple_4Wire(cmdArray, 1, flashBuffer, 1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 86 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 87 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 88 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 89 | uint8_t S25FS512::wren(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 90 | uint8_t cmdArray[8]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 91 | // Send WREN |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 92 | cmdArray[0] = 0x06; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 93 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 94 | return reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 95 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 96 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 97 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 98 | int8_t S25FS512::reg_write_read_multiple_quad_last(uint8_t *bufferOut, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 99 | uint8_t numberOut, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 100 | uint8_t *bufferIn, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 101 | uint8_t numberIn, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 102 | uint8_t last) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 103 | int32_t success = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 104 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 105 | success = quadSpiInterface->SPI_Transmit( |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 106 | bufferOut, numberOut, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 107 | bufferIn, numberIn, (int)last); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 108 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 109 | if (success != 0) return -1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 110 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 111 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 112 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 113 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 114 | int8_t S25FS512::reg_write_read_multiple_4Wire(uint8_t *bufferOut, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 115 | uint8_t numberOut, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 116 | uint8_t *bufferIn, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 117 | uint8_t numberIn) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 118 | int32_t success = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 119 | success = quadSpiInterface->SPI_Transmit4Wire(bufferOut, numberOut, bufferIn, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 120 | numberIn, (int)1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 121 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 122 | if (success != 0) return -1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 123 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 124 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 125 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 126 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 127 | int8_t S25FS512::reg_write_read_multiple_quad(uint8_t *bufferOut, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 128 | uint8_t numberOut, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 129 | uint8_t *bufferIn, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 130 | uint8_t numberIn) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 131 | int8_t ret; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 132 | ret = reg_write_read_multiple_quad_last(bufferOut, numberOut, bufferIn, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 133 | numberIn, 1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 134 | return ret; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 135 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 136 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 137 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 138 | void S25FS512::readID(uint8_t *id) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 139 | uint8_t cmd = 0x9F; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 140 | reg_write_read_multiple_quad(&cmd, 1, id, 4); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 141 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 142 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 143 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 144 | int8_t S25FS512::writeAnyRegister(uint32_t address, uint8_t data) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 145 | uint8_t cmdArray[5]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 146 | cmdArray[0] = 0x71; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 147 | cmdArray[1] = (address >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 148 | cmdArray[2] = (address >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 149 | cmdArray[3] = (address >> 0) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 150 | cmdArray[4] = data; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 151 | return reg_write_read_multiple_quad(cmdArray, 5, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 152 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 153 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 154 | int8_t S25FS512::writeAnyRegister4Wire(uint32_t address, uint8_t data) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 155 | uint8_t cmdArray[5]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 156 | cmdArray[0] = 0x71; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 157 | cmdArray[1] = (address >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 158 | cmdArray[2] = (address >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 159 | cmdArray[3] = (address >> 0) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 160 | cmdArray[4] = data; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 161 | return reg_write_read_multiple_4Wire(cmdArray, 5, flashBuffer, 5); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 162 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 163 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 164 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 165 | int8_t S25FS512::writeRegisters(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 166 | uint8_t cmdArray[3]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 167 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 168 | cmdArray[0] = 0x01; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 169 | cmdArray[1] = 0x00; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 170 | cmdArray[2] = 0x02; // set Quad to 1 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 171 | reg_write_read_multiple_quad(cmdArray, 3, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 172 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 173 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 174 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 175 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 176 | int8_t S25FS512::readAnyRegister(uint32_t address, uint8_t *data, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 177 | uint32_t length) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 178 | uint8_t cmdArray[4]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 179 | cmdArray[0] = 0x65; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 180 | cmdArray[1] = (address >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 181 | cmdArray[2] = (address >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 182 | cmdArray[3] = (address >> 0) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 183 | return reg_write_read_multiple_quad(cmdArray, 4, data, length); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 184 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 185 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 186 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 187 | int8_t S25FS512::bulkErase(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 188 | uint8_t cmdArray[1]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 189 | cmdArray[0] = 0x60; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 190 | return reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 191 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 192 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 193 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 194 | int8_t S25FS512::pageProgram(uint32_t address, uint8_t *buffer) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 195 | uint32_t i; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 196 | uint8_t cmdArray[5 + 256]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 197 | uint8_t *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 198 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 199 | // for (i = 0; i < 256; i++) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 200 | // dataArray[i] = i; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 201 | //} |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 202 | cmdArray[0] = 0x02; // 0x71; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 203 | // cmdArray[1] = (address >> 24) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 204 | cmdArray[1] = (address >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 205 | cmdArray[2] = (address >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 206 | cmdArray[3] = (address >> 0) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 207 | for (i = 0; i < 256; i++) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 208 | cmdArray[4 + i] = buffer[i]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 209 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 210 | // reg_write_read_multiple_quad(cmdArray,256 + 4,flashBuffer,256 + 4); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 211 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 212 | ptr = cmdArray; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 213 | reg_write_read_multiple_quad_last(ptr, 4 + 64, flashBuffer, 0, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 214 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 215 | ptr += (4 + 64); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 216 | reg_write_read_multiple_quad_last(ptr, 64, flashBuffer, 0, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 217 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 218 | ptr += 64; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 219 | reg_write_read_multiple_quad_last(ptr, 64, flashBuffer, 0, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 220 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 221 | ptr += 64; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 222 | reg_write_read_multiple_quad_last(ptr, 64, flashBuffer, 0, 1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 223 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 224 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 225 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 226 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 227 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 228 | int8_t S25FS512::quadIoRead_Pages(uint32_t address, uint8_t *buffer, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 229 | uint32_t numberOfPages) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 230 | uint8_t cmdArray[5]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 231 | uint8_t *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 232 | uint8_t last; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 233 | uint32_t i; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 234 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 235 | cmdArray[0] = 0xEB; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 236 | cmdArray[1] = (address >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 237 | cmdArray[2] = (address >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 238 | cmdArray[3] = (address >> 0) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 239 | ptr = buffer; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 240 | last = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 241 | // only send the command |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 242 | reg_write_read_multiple_quad_last(cmdArray, 4, ptr, 0, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 243 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 244 | reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 5, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 245 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 246 | for (i = 0; i < numberOfPages; i++) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 247 | reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 248 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 249 | ptr += 64; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 250 | reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 251 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 252 | ptr += 64; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 253 | reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 254 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 255 | ptr += 64; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 256 | // check if this is the last page |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 257 | if ((i + 1) == numberOfPages) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 258 | last = 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 259 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 260 | reg_write_read_multiple_quad_last(cmdArray, 0, ptr, 64, last); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 261 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 262 | ptr += 64; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 263 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 264 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 265 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 266 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 267 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 268 | int8_t S25FS512::checkBusy(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 269 | uint8_t cmdArray[5]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 270 | cmdArray[0] = 0x05; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 271 | reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 2); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 272 | return flashBuffer[1] & 0x1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 273 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 274 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 275 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 276 | void S25FS512::waitTillNotBusy(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 277 | while (checkBusy() == 1) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 278 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 279 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 280 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 281 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 282 | int8_t S25FS512::sectorErase(uint32_t address) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 283 | uint8_t cmdArray[5]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 284 | cmdArray[0] = 0xD8; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 285 | cmdArray[1] = (address >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 286 | cmdArray[2] = (address >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 287 | cmdArray[3] = (address >> 0) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 288 | return reg_write_read_multiple_quad(cmdArray, 4, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 289 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 290 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 291 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 292 | int8_t S25FS512::parameterSectorErase(uint32_t address) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 293 | uint8_t cmdArray[5]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 294 | cmdArray[0] = 0x20; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 295 | cmdArray[1] = (address >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 296 | cmdArray[2] = (address >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 297 | cmdArray[3] = (address >> 0) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 298 | reg_write_read_multiple_quad(cmdArray, 4, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 299 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 300 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 301 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 302 | #define ONE_MS (32768 / 500) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 303 | #define ONEHUNDRED_US (32768 / 1000) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 304 | #define TEM_MS (32768 / 50) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 305 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 306 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 307 | void S25FS512::wait_1mS(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 308 | wait_ms(1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 309 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 310 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 311 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 312 | void S25FS512::wait_100uS(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 313 | wait_us(100); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 314 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 315 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 316 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 317 | void S25FS512::wait_10mS(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 318 | wait_ms(10); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 319 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 320 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 321 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 322 | int8_t S25FS512::readIdentification(uint8_t *dataArray, uint8_t length) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 323 | // 4QIOR = 0x9F |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 324 | uint8_t cmdArray[1]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 325 | cmdArray[0] = 0x9F; // read ID command |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 326 | return reg_write_read_multiple_quad(cmdArray, 1, dataArray, length); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 327 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 328 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 329 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 330 | uint8_t S25FS512::reset(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 331 | uint8_t cmdArray[8]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 332 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 333 | cmdArray[0] = 0x66; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 334 | reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 335 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 336 | cmdArray[0] = 0x99; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 337 | reg_write_read_multiple_quad(cmdArray, 1, flashBuffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 338 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 339 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 340 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 341 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 342 | uint8_t S25FS512::enableHWReset(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 343 | uint8_t data[8]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 344 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 345 | // CR2V Configuration Register-2 Volatile |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 346 | // bit 5 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 347 | readAnyRegister(0x00800003, data, 8); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 348 | writeAnyRegister(0x00800003, 0x64); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 349 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 350 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 351 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 352 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 353 | uint8_t S25FS512::detect(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 354 | uint8_t array[8]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 355 | uint8_t array2[8]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 356 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 357 | // Send WREN |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 358 | wren(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 359 | // Send WREN |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 360 | wren(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 361 | // delay |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 362 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 363 | // Send WREN |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 364 | wren(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 365 | // delay |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 366 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 367 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 368 | // Send write any register cmd |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 369 | writeAnyRegister(0x0003, 0x48); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 370 | // delay |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 371 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 372 | array[0] = 0x9F; // read ID command |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 373 | reg_write_read_multiple_quad(array, 1, array2, 7); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 374 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 375 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 376 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 377 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 378 | int S25FS512::setQuadMode(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 379 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 380 | wren4Wire(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 381 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 382 | writeAnyRegister4Wire(0x800002, 0x02); // set Quad = 1 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 383 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 384 | wren4Wire(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 385 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 386 | writeAnyRegister4Wire(0x800003, 0x48); // set 8 latency, set QPI 4-4-4 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 387 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 388 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 389 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 390 | uint32_t S25FS512::isPageEmpty(uint8_t *ptr) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 391 | int i; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 392 | for (i = 0; i < 256; i++) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 393 | if (ptr[i] != 0xFF) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 394 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 395 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 396 | return 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 397 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 398 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 399 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 400 | int8_t S25FS512::parameterSectorErase_Helper(uint32_t address) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 401 | waitTillNotBusy(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 402 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 403 | wren(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 404 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 405 | parameterSectorErase(address); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 406 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 407 | waitTillNotBusy(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 408 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 409 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 410 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 411 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 412 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 413 | int8_t S25FS512::sectorErase_Helper(uint32_t address) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 414 | waitTillNotBusy(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 415 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 416 | wren(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 417 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 418 | if (address < 0x8000) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 419 | parameterSectorErase(address); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 420 | } else { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 421 | sectorErase(address); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 422 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 423 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 424 | waitTillNotBusy(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 425 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 426 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 427 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 428 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 429 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 430 | int8_t S25FS512::bulkErase_Helper(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 431 | waitTillNotBusy(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 432 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 433 | wren(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 434 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 435 | bulkErase(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 436 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 437 | waitTillNotBusy(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 438 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 439 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 440 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 441 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 442 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 443 | // write a page worth of data (256 bytes) from buffer, offset defined where in |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 444 | // the buffer to begin write |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 445 | int8_t S25FS512::writePage_Helper(uint32_t pageNumber, uint8_t *buffer, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 446 | uint32_t offset) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 447 | uint8_t *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 448 | waitTillNotBusy(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 449 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 450 | wren(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 451 | ptr = &buffer[offset]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 452 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 453 | pageProgram(pageNumber << 8, ptr); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 454 | wait_1mS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 455 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 456 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 457 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 458 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 459 | // read pages from flash into buffer, offset defined where in the buffer use |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 460 | int8_t S25FS512::readPages_Helper(uint32_t startPageNumber, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 461 | uint32_t endPageNumber, uint8_t *buffer, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 462 | uint32_t offset) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 463 | uint8_t *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 464 | uint32_t page; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 465 | ptr = &buffer[offset]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 466 | for (page = startPageNumber; page <= endPageNumber; page++) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 467 | wait_100uS(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 468 | quadIoRead_Pages((uint32_t)(page << 8), (uint8_t *)ptr, 1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 469 | ptr += 0x100; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 470 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 471 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 472 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 473 |