|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2018-2018 ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#ifndef MBED_QSPI_FLASH_N25Q128A_H |
| 17 | +#define MBED_QSPI_FLASH_N25Q128A_H |
| 18 | + |
| 19 | + |
| 20 | +#define QSPI_FLASH_CHIP_STRING "Micron N25Q128A" |
| 21 | + |
| 22 | +// Command for reading status register |
| 23 | +#define QSPI_CMD_RDSR 0x05 |
| 24 | +// Command for reading configuration register 0 (NONVOLATILE CONFIGURATION REGISTER) |
| 25 | +#define QSPI_CMD_RDCR0 0xB5 |
| 26 | +// Command for reading configuration register 1 (VOLATILE CONFIGURATION REGISTER) |
| 27 | +#define QSPI_CMD_RDCR1 0x85 |
| 28 | +// Command for reading configuration register 2 (ENHANCED VOLATILE CONFIGURATION REGISTER) |
| 29 | +#define QSPI_CMD_RDCR2 0x65 |
| 30 | +// Command for writing status |
| 31 | +#define QSPI_CMD_WRSR 0x01 |
| 32 | +// Command for writing configuration register 0 (NONVOLATILE CONFIGURATION REGISTER) |
| 33 | +#define QSPI_CMD_WRCR0 0xB1 |
| 34 | +// Command for writing configuration register 1 (VOLATILE CONFIGURATION REGISTER) |
| 35 | +#define QSPI_CMD_WRCR1 0x81 |
| 36 | +// Command for writing configuration register 2 (ENHANCED VOLATILE CONFIGURATION REGISTER) |
| 37 | +#define QSPI_CMD_WRCR2 0x61 |
| 38 | +// Command for reading security register |
| 39 | +#define QSPI_CMD_RDSCUR 0x2B |
| 40 | + |
| 41 | +// Command for setting Reset Enable |
| 42 | +#define QSPI_CMD_RSTEN 0x66 |
| 43 | +// Command for setting Reset |
| 44 | +#define QSPI_CMD_RST 0x99 |
| 45 | + |
| 46 | +// Command for setting write enable |
| 47 | +#define QSPI_CMD_WREN 0x06 |
| 48 | +// Command for setting write disable |
| 49 | +#define QSPI_CMD_WRDI 0x04 |
| 50 | + |
| 51 | +// WRSR operations max time [us] (datasheet max time + 15%) |
| 52 | +#define QSPI_WRSR_MAX_TIME 9200 // 8ms |
| 53 | +// general wait max time [us] |
| 54 | +#define QSPI_WAIT_MAX_TIME 100000 // 100ms |
| 55 | + |
| 56 | + |
| 57 | +// Commands for writing (page programming) |
| 58 | +#define QSPI_CMD_WRITE_1IO 0x02 // 1-1-1 mode |
| 59 | +#define QSPI_CMD_WRITE_2IO 0xD2 // 1-2-2 mode |
| 60 | +#define QSPI_CMD_WRITE_4IO 0x12 // 1-4-4 mode |
| 61 | + |
| 62 | +// write operations max time [us] (datasheet max time + 15%) |
| 63 | +#define QSPI_PAGE_PROG_MAX_TIME 5750 // 5ms |
| 64 | + |
| 65 | +#define QSPI_PAGE_SIZE 256 // 256B |
| 66 | + |
| 67 | +// Commands for reading |
| 68 | +#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode |
| 69 | +#define QSPI_CMD_READ_1IO 0x03 // 1-1-1 mode |
| 70 | +#define QSPI_CMD_READ_2IO 0xBB // 1-2-2 mode |
| 71 | +#define QSPI_CMD_READ_1I2O 0x3B // 1-1-2 mode |
| 72 | +#define QSPI_CMD_READ_4IO 0xEB // 1-4-4 mode |
| 73 | +#define QSPI_CMD_READ_1I4O 0x6B // 1-1-4 mode |
| 74 | + |
| 75 | + |
| 76 | +#define QSPI_READ_1IO_DUMMY_CYCLE 0 |
| 77 | +#define QSPI_READ_FAST_DUMMY_CYCLE 8 |
| 78 | +// 8 dummy (10 dummy when quad SPI protocol is enabled) |
| 79 | +#define QSPI_READ_2IO_DUMMY_CYCLE 8 |
| 80 | +#define QSPI_READ_1I2O_DUMMY_CYCLE 8 |
| 81 | +#define QSPI_READ_4IO_DUMMY_CYCLE 10 |
| 82 | +#define QSPI_READ_1I4O_DUMMY_CYCLE 8 |
| 83 | + |
| 84 | +// Commands for erasing |
| 85 | +#define QSPI_CMD_ERASE_SECTOR 0x20 // 4kB |
| 86 | +#define QSPI_CMD_ERASE_BLOCK_32 0x52 // 32kB |
| 87 | +#define QSPI_CMD_ERASE_BLOCK_64 0xD8 // 64kB |
| 88 | +#define QSPI_CMD_ERASE_CHIP 0x60 // or 0xC7 |
| 89 | + |
| 90 | +// erase operations max time [us] (datasheet max time + 15%) |
| 91 | +#define QSPI_ERASE_SECTOR_MAX_TIME 276000 // 240 ms |
| 92 | +#define QSPI_ERASE_BLOCK_32_MAX_TIME 3000000 // 3s |
| 93 | +#define QSPI_ERASE_BLOCK_64_MAX_TIME 3500000 // 3.5s |
| 94 | + |
| 95 | +// max frequency for basic rw operation |
| 96 | +#define QSPI_COMMON_MAX_FREQUENCY 50000000 |
| 97 | + |
| 98 | +#define QSPI_STATUS_REG_SIZE 1 |
| 99 | +#define QSPI_CONFIG_REG_0_SIZE 2 |
| 100 | +#define QSPI_CONFIG_REG_1_SIZE 1 |
| 101 | +#define QSPI_CONFIG_REG_2_SIZE 1 |
| 102 | +#define QSPI_MAX_REG_SIZE 2 |
| 103 | + |
| 104 | +// status register |
| 105 | +#define STATUS_BIT_WIP (1 << 0) // write in progress bit |
| 106 | +#define STATUS_BIT_WEL (1 << 1) // write enable latch |
| 107 | +#define STATUS_BIT_BP0 (1 << 2) // block |
| 108 | +#define STATUS_BIT_BP1 (1 << 3) // |
| 109 | +#define STATUS_BIT_BP2 (1 << 4) // |
| 110 | +#define STATUS_BIT_BP_TB (1 << 5) // Block protect top/bottom |
| 111 | +#define STATUS_BIT_BP3 (1 << 6) // |
| 112 | +#define STATUS_BIT_SRWD (1 << 7) // status register write protect |
| 113 | + |
| 114 | +// configuration register 0 (Nonvolatile Configuration Register) |
| 115 | +// bit 1, 5, reserved |
| 116 | +#define CONFIG0_BIT_LOCK (1 << 0) // Lock nonvolatile configuration register |
| 117 | +#define CONFIG0_BIT_DE (1 << 2) // Dual Enable 0 = Enabled / 1 = Disabled |
| 118 | +#define CONFIG0_BIT_QE (1 << 3) // Quad Enable 0 = Enabled / 1 = Disabled |
| 119 | +#define CONFIG0_BIT_RH (1 << 4) // Reset/hold |
| 120 | +#define CONFIG0_BIT_ODS0 (1 << 6) // Output driver strength |
| 121 | +#define CONFIG0_BIT_ODS1 (1 << 7) // Output driver strength |
| 122 | +#define CONFIG0_BIT_ODS2 (1 << 8) // Output driver strength |
| 123 | +#define CONFIG0_BIT_XIP_MODE0 (1 << 9) // XIP mode at power-on reset |
| 124 | +#define CONFIG0_BIT_XIP_MODE1 (1 << 10) // XIP mode at power-on reset |
| 125 | +#define CONFIG0_BIT_XIP_MODE2 (1 << 11) // XIP mode at power-on reset |
| 126 | +#define CONFIG0_BIT_DCYCLE0 (1 << 12) // Dummy Cycle |
| 127 | +#define CONFIG0_BIT_DCYCLE1 (1 << 13) // Dummy Cycle |
| 128 | +#define CONFIG0_BIT_DCYCLE2 (1 << 14) // Dummy Cycle |
| 129 | +#define CONFIG0_BIT_DCYCLE3 (1 << 15) // Dummy Cycle |
| 130 | +#define CONFIG0_BITS_DEFAULT 0xFFFF // reg default state |
| 131 | + |
| 132 | + |
| 133 | +// configuration register 1 (Volatile Configuration Register) |
| 134 | +// bit 2, reserved |
| 135 | +#define CONFIG1_BIT_WRAP0 (1 << 0) // Output data wrap |
| 136 | +#define CONFIG1_BIT_WRAP1 (1 << 1) // Output data wrap |
| 137 | +#define CONFIG1_BIT_XIP (1 << 3) // 0 = Enable / 1 = Disable (default) |
| 138 | +#define CONFIG1_BIT_DCYCLE0 (1 << 4) // Number of dummy clock cycles |
| 139 | +#define CONFIG1_BIT_DCYCLE1 (1 << 5) // Number of dummy clock cycles |
| 140 | +#define CONFIG1_BIT_DCYCLE2 (1 << 6) // Number of dummy clock cycles |
| 141 | +#define CONFIG1_BIT_DCYCLE3 (1 << 7) // Number of dummy clock cycles |
| 142 | +#define CONFIG1_BITS_DEFAULT 0xB // reg default state |
| 143 | + |
| 144 | + |
| 145 | +// configuration register 2 (Enhanced Volatile Configuration Register) |
| 146 | +// bit 5, reserved |
| 147 | +#define CONFIG2_BIT_ODS0 (1 << 0) // Output driver strength 111 = 30 Ohms (Default) |
| 148 | +#define CONFIG2_BIT_ODS1 (1 << 1) // Output driver strength |
| 149 | +#define CONFIG2_BIT_ODS2 (1 << 2) // Output driver strength |
| 150 | +#define CONFIG2_BIT_VPP (1 << 3) // VPP accelerator 1 = Disabled (Default) |
| 151 | +#define CONFIG2_BIT_RH (1 << 4) // Reset/hold |
| 152 | +#define CONFIG2_BIT_DE (1 << 6) // Dual I/O protocol 0 = Enabled / 1 = Disabled (Default, extended SPI protocol) |
| 153 | +#define CONFIG2_BIT_QE (1 << 7) // Quad I/O protocol 0 = Enabled / 1 = Disabled (Default, extended SPI protocol) |
| 154 | +#define CONFIG2_BITS_DEFAULT 0xDF // reg default state |
| 155 | + |
| 156 | + |
| 157 | +#define DUAL_ENABLE() \ |
| 158 | + /* TODO: add implementation */ \ |
| 159 | + return QSPI_STATUS_OK |
| 160 | + |
| 161 | + |
| 162 | +#define DUAL_DISABLE() \ |
| 163 | + /* TODO: add implementation */ \ |
| 164 | + return QSPI_STATUS_OK |
| 165 | + |
| 166 | + |
| 167 | +#define QUAD_ENABLE() \ |
| 168 | + /* TODO: add implementation */ \ |
| 169 | + return QSPI_STATUS_OK |
| 170 | + |
| 171 | + |
| 172 | +#define QUAD_DISABLE() \ |
| 173 | + /* TODO: add implementation */ \ |
| 174 | + return QSPI_STATUS_OK |
| 175 | + |
| 176 | + |
| 177 | +#define FAST_MODE_ENABLE() \ |
| 178 | + /* TODO: add implementation */ \ |
| 179 | + return QSPI_STATUS_OK |
| 180 | + |
| 181 | + |
| 182 | +#endif // MBED_QSPI_FLASH_N25Q128A_H |
0 commit comments