![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.cpp@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2016 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | |
kadonotakashi | 0:8fdf9a60065b | 17 | #include "DataFlashBlockDevice.h" |
kadonotakashi | 0:8fdf9a60065b | 18 | #include "mbed_critical.h" |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | #include <inttypes.h> |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | /* constants */ |
kadonotakashi | 0:8fdf9a60065b | 23 | #define DATAFLASH_READ_SIZE 1 |
kadonotakashi | 0:8fdf9a60065b | 24 | #define DATAFLASH_PROG_SIZE 1 |
kadonotakashi | 0:8fdf9a60065b | 25 | #define DATAFLASH_TIMEOUT 10000 |
kadonotakashi | 0:8fdf9a60065b | 26 | #define DATAFLASH_ID_MATCH 0x1F20 |
kadonotakashi | 0:8fdf9a60065b | 27 | #define DATAFLASH_ID_DENSITY_MASK 0x001F |
kadonotakashi | 0:8fdf9a60065b | 28 | #define DATAFLASH_PAGE_SIZE_256 0x0100 |
kadonotakashi | 0:8fdf9a60065b | 29 | #define DATAFLASH_PAGE_SIZE_264 0x0108 |
kadonotakashi | 0:8fdf9a60065b | 30 | #define DATAFLASH_PAGE_SIZE_512 0x0200 |
kadonotakashi | 0:8fdf9a60065b | 31 | #define DATAFLASH_PAGE_SIZE_528 0x0210 |
kadonotakashi | 0:8fdf9a60065b | 32 | #define DATAFLASH_BLOCK_SIZE_2K 0x0800 |
kadonotakashi | 0:8fdf9a60065b | 33 | #define DATAFLASH_BLOCK_SIZE_2K1 0x0840 |
kadonotakashi | 0:8fdf9a60065b | 34 | #define DATAFLASH_BLOCK_SIZE_4K 0x1000 |
kadonotakashi | 0:8fdf9a60065b | 35 | #define DATAFLASH_BLOCK_SIZE_4K1 0x1080 |
kadonotakashi | 0:8fdf9a60065b | 36 | #define DATAFLASH_PAGE_BIT_264 9 |
kadonotakashi | 0:8fdf9a60065b | 37 | #define DATAFLASH_PAGE_BIT_528 10 |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | /* enable debug */ |
kadonotakashi | 0:8fdf9a60065b | 40 | #ifndef DATAFLASH_DEBUG |
kadonotakashi | 0:8fdf9a60065b | 41 | #define DATAFLASH_DEBUG 0 |
kadonotakashi | 0:8fdf9a60065b | 42 | #endif /* DATAFLASH_DEBUG */ |
kadonotakashi | 0:8fdf9a60065b | 43 | |
kadonotakashi | 0:8fdf9a60065b | 44 | #if DATAFLASH_DEBUG |
kadonotakashi | 0:8fdf9a60065b | 45 | #define DEBUG_PRINTF(...) printf(__VA_ARGS__) |
kadonotakashi | 0:8fdf9a60065b | 46 | #else |
kadonotakashi | 0:8fdf9a60065b | 47 | #define DEBUG_PRINTF(...) |
kadonotakashi | 0:8fdf9a60065b | 48 | #endif |
kadonotakashi | 0:8fdf9a60065b | 49 | |
kadonotakashi | 0:8fdf9a60065b | 50 | void _print_status(uint16_t status); |
kadonotakashi | 0:8fdf9a60065b | 51 | |
kadonotakashi | 0:8fdf9a60065b | 52 | /* non-exhaustive opcode list */ |
kadonotakashi | 0:8fdf9a60065b | 53 | enum opcode { |
kadonotakashi | 0:8fdf9a60065b | 54 | DATAFLASH_OP_NOP = 0x00, |
kadonotakashi | 0:8fdf9a60065b | 55 | DATAFLASH_OP_STATUS = 0xD7, |
kadonotakashi | 0:8fdf9a60065b | 56 | DATAFLASH_OP_ID = 0x9F, |
kadonotakashi | 0:8fdf9a60065b | 57 | DATAFLASH_OP_READ_LOW_POWER = 0x01, |
kadonotakashi | 0:8fdf9a60065b | 58 | DATAFLASH_OP_READ_LOW_FREQUENCY = 0x03, |
kadonotakashi | 0:8fdf9a60065b | 59 | DATAFLASH_OP_PROGRAM_DIRECT = 0x02, // Program through Buffer 1 without Built-In Erase |
kadonotakashi | 0:8fdf9a60065b | 60 | DATAFLASH_OP_PROGRAM_DIRECT_WITH_ERASE = 0x82, |
kadonotakashi | 0:8fdf9a60065b | 61 | DATAFLASH_OP_ERASE_BLOCK = 0x50, |
kadonotakashi | 0:8fdf9a60065b | 62 | }; |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | /* non-exhaustive command list */ |
kadonotakashi | 0:8fdf9a60065b | 65 | enum command { |
kadonotakashi | 0:8fdf9a60065b | 66 | DATAFLASH_COMMAND_WRITE_DISABLE = 0x3D2A7FA9, |
kadonotakashi | 0:8fdf9a60065b | 67 | DATAFLASH_COMMAND_WRITE_ENABLE = 0x3D2A7F9A, |
kadonotakashi | 0:8fdf9a60065b | 68 | DATAFLASH_COMMAND_BINARY_PAGE_SIZE = 0x3D2A80A6, |
kadonotakashi | 0:8fdf9a60065b | 69 | DATAFLASH_COMMAND_DATAFLASH_PAGE_SIZE = 0x3D2A80A7, |
kadonotakashi | 0:8fdf9a60065b | 70 | }; |
kadonotakashi | 0:8fdf9a60065b | 71 | |
kadonotakashi | 0:8fdf9a60065b | 72 | /* bit masks for interpreting the status register */ |
kadonotakashi | 0:8fdf9a60065b | 73 | enum status_bit { |
kadonotakashi | 0:8fdf9a60065b | 74 | DATAFLASH_BIT_READY = (0x01 << 15), |
kadonotakashi | 0:8fdf9a60065b | 75 | DATAFLASH_BIT_COMPARE = (0x01 << 14), |
kadonotakashi | 0:8fdf9a60065b | 76 | DATAFLASH_BIT_DENSITY = (0x0F << 10), |
kadonotakashi | 0:8fdf9a60065b | 77 | DATAFLASH_BIT_PROTECT = (0x01 << 9), |
kadonotakashi | 0:8fdf9a60065b | 78 | DATAFLASH_BIT_PAGE_SIZE = (0x01 << 8), |
kadonotakashi | 0:8fdf9a60065b | 79 | |
kadonotakashi | 0:8fdf9a60065b | 80 | DATAFLASH_BIT_ERASE_PROGRAM_ERROR = (0x01 << 5), |
kadonotakashi | 0:8fdf9a60065b | 81 | DATAFLASH_BIT_SECTOR_LOCKDOWN = (0x01 << 3), |
kadonotakashi | 0:8fdf9a60065b | 82 | DATAFLASH_BIT_PROGRAM_SUSPEND_2 = (0x01 << 2), |
kadonotakashi | 0:8fdf9a60065b | 83 | DATAFLASH_BIT_PROGRAM_SUSPEND_1 = (0x01 << 1), |
kadonotakashi | 0:8fdf9a60065b | 84 | DATAFLASH_BIT_ERASE_SUSPEND = (0x01 << 0), |
kadonotakashi | 0:8fdf9a60065b | 85 | }; |
kadonotakashi | 0:8fdf9a60065b | 86 | |
kadonotakashi | 0:8fdf9a60065b | 87 | /* bit masks for detecting density from status register */ |
kadonotakashi | 0:8fdf9a60065b | 88 | enum status_density { |
kadonotakashi | 0:8fdf9a60065b | 89 | DATAFLASH_STATUS_DENSITY_2_MBIT = (0x05 << 10), |
kadonotakashi | 0:8fdf9a60065b | 90 | DATAFLASH_STATUS_DENSITY_4_MBIT = (0x07 << 10), |
kadonotakashi | 0:8fdf9a60065b | 91 | DATAFLASH_STATUS_DENSITY_8_MBIT = (0x09 << 10), |
kadonotakashi | 0:8fdf9a60065b | 92 | DATAFLASH_STATUS_DENSITY_16_MBIT = (0x0B << 10), |
kadonotakashi | 0:8fdf9a60065b | 93 | DATAFLASH_STATUS_DENSITY_32_MBIT = (0x0D << 10), |
kadonotakashi | 0:8fdf9a60065b | 94 | DATAFLASH_STATUS_DENSITY_64_MBIT = (0x0F << 10), |
kadonotakashi | 0:8fdf9a60065b | 95 | }; |
kadonotakashi | 0:8fdf9a60065b | 96 | |
kadonotakashi | 0:8fdf9a60065b | 97 | /* code for calculating density */ |
kadonotakashi | 0:8fdf9a60065b | 98 | enum id_density { |
kadonotakashi | 0:8fdf9a60065b | 99 | DATAFLASH_ID_DENSITY_2_MBIT = 0x03, |
kadonotakashi | 0:8fdf9a60065b | 100 | DATAFLASH_ID_DENSITY_4_MBIT = 0x04, |
kadonotakashi | 0:8fdf9a60065b | 101 | DATAFLASH_ID_DENSITY_8_MBIT = 0x05, |
kadonotakashi | 0:8fdf9a60065b | 102 | DATAFLASH_ID_DENSITY_16_MBIT = 0x06, |
kadonotakashi | 0:8fdf9a60065b | 103 | DATAFLASH_ID_DENSITY_32_MBIT = 0x07, |
kadonotakashi | 0:8fdf9a60065b | 104 | DATAFLASH_ID_DENSITY_64_MBIT = 0x08, |
kadonotakashi | 0:8fdf9a60065b | 105 | }; |
kadonotakashi | 0:8fdf9a60065b | 106 | |
kadonotakashi | 0:8fdf9a60065b | 107 | /* typical duration in milliseconds for each operation */ |
kadonotakashi | 0:8fdf9a60065b | 108 | enum timing { |
kadonotakashi | 0:8fdf9a60065b | 109 | DATAFLASH_TIMING_ERASE_PROGRAM_PAGE = 17, |
kadonotakashi | 0:8fdf9a60065b | 110 | DATAFLASH_TIMING_PROGRAM_PAGE = 3, |
kadonotakashi | 0:8fdf9a60065b | 111 | DATAFLASH_TIMING_ERASE_PAGE = 12, |
kadonotakashi | 0:8fdf9a60065b | 112 | DATAFLASH_TIMING_ERASE_BLOCK = 45, |
kadonotakashi | 0:8fdf9a60065b | 113 | DATAFLASH_TIMING_ERASE_SECTOR = 700, |
kadonotakashi | 0:8fdf9a60065b | 114 | DATAFLASH_TIMING_ERASE_CHIP = 45000 |
kadonotakashi | 0:8fdf9a60065b | 115 | }; |
kadonotakashi | 0:8fdf9a60065b | 116 | |
kadonotakashi | 0:8fdf9a60065b | 117 | /* frequency domains */ |
kadonotakashi | 0:8fdf9a60065b | 118 | enum frequency { |
kadonotakashi | 0:8fdf9a60065b | 119 | DATAFLASH_LOW_POWER_FREQUENCY = 15000000, |
kadonotakashi | 0:8fdf9a60065b | 120 | DATAFLASH_LOW_FREQUENCY = 50000000, |
kadonotakashi | 0:8fdf9a60065b | 121 | DATAFLASH_HIGH_FREQUENCY = 85000000, |
kadonotakashi | 0:8fdf9a60065b | 122 | DATAFLASH_HIGHEST_FREQUENCY = 104000000 |
kadonotakashi | 0:8fdf9a60065b | 123 | }; |
kadonotakashi | 0:8fdf9a60065b | 124 | |
kadonotakashi | 0:8fdf9a60065b | 125 | /* number of dummy bytes required in each frequency domain */ |
kadonotakashi | 0:8fdf9a60065b | 126 | enum dummy { |
kadonotakashi | 0:8fdf9a60065b | 127 | DATAFLASH_LOW_POWER_BYTES = 0, |
kadonotakashi | 0:8fdf9a60065b | 128 | DATAFLASH_LOW_FREQUENCY_BYTES = 0, |
kadonotakashi | 0:8fdf9a60065b | 129 | DATAFLASH_HIGH_FREQUENCY_BYTES = 1, |
kadonotakashi | 0:8fdf9a60065b | 130 | DATAFLASH_HIGHEST_FREQUENCY_BYTES = 2 |
kadonotakashi | 0:8fdf9a60065b | 131 | }; |
kadonotakashi | 0:8fdf9a60065b | 132 | |
kadonotakashi | 0:8fdf9a60065b | 133 | DataFlashBlockDevice::DataFlashBlockDevice(PinName mosi, |
kadonotakashi | 0:8fdf9a60065b | 134 | PinName miso, |
kadonotakashi | 0:8fdf9a60065b | 135 | PinName sclk, |
kadonotakashi | 0:8fdf9a60065b | 136 | PinName cs, |
kadonotakashi | 0:8fdf9a60065b | 137 | int freq, |
kadonotakashi | 0:8fdf9a60065b | 138 | PinName nwp) |
kadonotakashi | 0:8fdf9a60065b | 139 | : _spi(mosi, miso, sclk), |
kadonotakashi | 0:8fdf9a60065b | 140 | _cs(cs, 1), |
kadonotakashi | 0:8fdf9a60065b | 141 | _nwp(nwp), |
kadonotakashi | 0:8fdf9a60065b | 142 | _device_size(0), |
kadonotakashi | 0:8fdf9a60065b | 143 | _page_size(0), |
kadonotakashi | 0:8fdf9a60065b | 144 | _block_size(0), |
kadonotakashi | 0:8fdf9a60065b | 145 | _is_initialized(0), |
kadonotakashi | 0:8fdf9a60065b | 146 | _init_ref_count(0) |
kadonotakashi | 0:8fdf9a60065b | 147 | { |
kadonotakashi | 0:8fdf9a60065b | 148 | /* check that frequency is within range */ |
kadonotakashi | 0:8fdf9a60065b | 149 | if (freq > DATAFLASH_LOW_FREQUENCY) { |
kadonotakashi | 0:8fdf9a60065b | 150 | |
kadonotakashi | 0:8fdf9a60065b | 151 | /* cap frequency at the highest supported one */ |
kadonotakashi | 0:8fdf9a60065b | 152 | _spi.frequency(DATAFLASH_LOW_FREQUENCY); |
kadonotakashi | 0:8fdf9a60065b | 153 | |
kadonotakashi | 0:8fdf9a60065b | 154 | } else { |
kadonotakashi | 0:8fdf9a60065b | 155 | /* freqency is valid, use as-is */ |
kadonotakashi | 0:8fdf9a60065b | 156 | _spi.frequency(freq); |
kadonotakashi | 0:8fdf9a60065b | 157 | } |
kadonotakashi | 0:8fdf9a60065b | 158 | |
kadonotakashi | 0:8fdf9a60065b | 159 | /* write protect chip if pin is connected */ |
kadonotakashi | 0:8fdf9a60065b | 160 | if (nwp != NC) { |
kadonotakashi | 0:8fdf9a60065b | 161 | _nwp = 0; |
kadonotakashi | 0:8fdf9a60065b | 162 | } |
kadonotakashi | 0:8fdf9a60065b | 163 | } |
kadonotakashi | 0:8fdf9a60065b | 164 | |
kadonotakashi | 0:8fdf9a60065b | 165 | int DataFlashBlockDevice::init() |
kadonotakashi | 0:8fdf9a60065b | 166 | { |
kadonotakashi | 0:8fdf9a60065b | 167 | DEBUG_PRINTF("init\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 168 | |
kadonotakashi | 0:8fdf9a60065b | 169 | if (!_is_initialized) { |
kadonotakashi | 0:8fdf9a60065b | 170 | _init_ref_count = 0; |
kadonotakashi | 0:8fdf9a60065b | 171 | } |
kadonotakashi | 0:8fdf9a60065b | 172 | |
kadonotakashi | 0:8fdf9a60065b | 173 | uint32_t val = core_util_atomic_incr_u32(&_init_ref_count, 1); |
kadonotakashi | 0:8fdf9a60065b | 174 | |
kadonotakashi | 0:8fdf9a60065b | 175 | if (val != 1) { |
kadonotakashi | 0:8fdf9a60065b | 176 | return BD_ERROR_OK; |
kadonotakashi | 0:8fdf9a60065b | 177 | } |
kadonotakashi | 0:8fdf9a60065b | 178 | |
kadonotakashi | 0:8fdf9a60065b | 179 | int result = BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 180 | |
kadonotakashi | 0:8fdf9a60065b | 181 | /* read ID register to validate model and set dimensions */ |
kadonotakashi | 0:8fdf9a60065b | 182 | uint16_t id = _get_register(DATAFLASH_OP_ID); |
kadonotakashi | 0:8fdf9a60065b | 183 | |
kadonotakashi | 0:8fdf9a60065b | 184 | DEBUG_PRINTF("id: %04X\r\n", id & DATAFLASH_ID_MATCH); |
kadonotakashi | 0:8fdf9a60065b | 185 | |
kadonotakashi | 0:8fdf9a60065b | 186 | /* get status register to verify the page size mode */ |
kadonotakashi | 0:8fdf9a60065b | 187 | uint16_t status = _get_register(DATAFLASH_OP_STATUS); |
kadonotakashi | 0:8fdf9a60065b | 188 | |
kadonotakashi | 0:8fdf9a60065b | 189 | /* manufacture ID match */ |
kadonotakashi | 0:8fdf9a60065b | 190 | if ((id & DATAFLASH_ID_MATCH) == DATAFLASH_ID_MATCH) { |
kadonotakashi | 0:8fdf9a60065b | 191 | |
kadonotakashi | 0:8fdf9a60065b | 192 | /* calculate density */ |
kadonotakashi | 0:8fdf9a60065b | 193 | _device_size = 0x8000 << (id & DATAFLASH_ID_DENSITY_MASK); |
kadonotakashi | 0:8fdf9a60065b | 194 | |
kadonotakashi | 0:8fdf9a60065b | 195 | bool binary_page_size = true; |
kadonotakashi | 0:8fdf9a60065b | 196 | |
kadonotakashi | 0:8fdf9a60065b | 197 | /* check if device is configured for binary page sizes */ |
kadonotakashi | 0:8fdf9a60065b | 198 | if ((status & DATAFLASH_BIT_PAGE_SIZE) == DATAFLASH_BIT_PAGE_SIZE) { |
kadonotakashi | 0:8fdf9a60065b | 199 | DEBUG_PRINTF("Page size is binary\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 200 | |
kadonotakashi | 0:8fdf9a60065b | 201 | #if MBED_CONF_DATAFLASH_DATAFLASH_SIZE |
kadonotakashi | 0:8fdf9a60065b | 202 | /* send reconfiguration command */ |
kadonotakashi | 0:8fdf9a60065b | 203 | _write_command(DATAFLASH_COMMAND_DATAFLASH_PAGE_SIZE, NULL, 0); |
kadonotakashi | 0:8fdf9a60065b | 204 | |
kadonotakashi | 0:8fdf9a60065b | 205 | /* wait for device to be ready and update return code */ |
kadonotakashi | 0:8fdf9a60065b | 206 | result = _sync(); |
kadonotakashi | 0:8fdf9a60065b | 207 | |
kadonotakashi | 0:8fdf9a60065b | 208 | /* set binary flag */ |
kadonotakashi | 0:8fdf9a60065b | 209 | binary_page_size = false; |
kadonotakashi | 0:8fdf9a60065b | 210 | #else |
kadonotakashi | 0:8fdf9a60065b | 211 | /* set binary flag */ |
kadonotakashi | 0:8fdf9a60065b | 212 | binary_page_size = true; |
kadonotakashi | 0:8fdf9a60065b | 213 | #endif |
kadonotakashi | 0:8fdf9a60065b | 214 | } else { |
kadonotakashi | 0:8fdf9a60065b | 215 | DEBUG_PRINTF("Page size is not binary\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 216 | |
kadonotakashi | 0:8fdf9a60065b | 217 | #if MBED_CONF_DATAFLASH_BINARY_SIZE |
kadonotakashi | 0:8fdf9a60065b | 218 | /* send reconfiguration command */ |
kadonotakashi | 0:8fdf9a60065b | 219 | _write_command(DATAFLASH_COMMAND_BINARY_PAGE_SIZE, NULL, 0); |
kadonotakashi | 0:8fdf9a60065b | 220 | |
kadonotakashi | 0:8fdf9a60065b | 221 | /* wait for device to be ready and update return code */ |
kadonotakashi | 0:8fdf9a60065b | 222 | result = _sync(); |
kadonotakashi | 0:8fdf9a60065b | 223 | |
kadonotakashi | 0:8fdf9a60065b | 224 | /* set binary flag */ |
kadonotakashi | 0:8fdf9a60065b | 225 | binary_page_size = true; |
kadonotakashi | 0:8fdf9a60065b | 226 | #else |
kadonotakashi | 0:8fdf9a60065b | 227 | /* set binary flag */ |
kadonotakashi | 0:8fdf9a60065b | 228 | binary_page_size = false; |
kadonotakashi | 0:8fdf9a60065b | 229 | #endif |
kadonotakashi | 0:8fdf9a60065b | 230 | } |
kadonotakashi | 0:8fdf9a60065b | 231 | |
kadonotakashi | 0:8fdf9a60065b | 232 | /* set page program size and block erase size */ |
kadonotakashi | 0:8fdf9a60065b | 233 | switch (id & DATAFLASH_ID_DENSITY_MASK) { |
kadonotakashi | 0:8fdf9a60065b | 234 | case DATAFLASH_ID_DENSITY_2_MBIT: |
kadonotakashi | 0:8fdf9a60065b | 235 | case DATAFLASH_ID_DENSITY_4_MBIT: |
kadonotakashi | 0:8fdf9a60065b | 236 | case DATAFLASH_ID_DENSITY_8_MBIT: |
kadonotakashi | 0:8fdf9a60065b | 237 | case DATAFLASH_ID_DENSITY_64_MBIT: |
kadonotakashi | 0:8fdf9a60065b | 238 | if (binary_page_size) { |
kadonotakashi | 0:8fdf9a60065b | 239 | _page_size = DATAFLASH_PAGE_SIZE_256; |
kadonotakashi | 0:8fdf9a60065b | 240 | _block_size = DATAFLASH_BLOCK_SIZE_2K; |
kadonotakashi | 0:8fdf9a60065b | 241 | } else { |
kadonotakashi | 0:8fdf9a60065b | 242 | _page_size = DATAFLASH_PAGE_SIZE_264; |
kadonotakashi | 0:8fdf9a60065b | 243 | _block_size = DATAFLASH_BLOCK_SIZE_2K1; |
kadonotakashi | 0:8fdf9a60065b | 244 | |
kadonotakashi | 0:8fdf9a60065b | 245 | /* adjust device size */ |
kadonotakashi | 0:8fdf9a60065b | 246 | _device_size = (_device_size / DATAFLASH_PAGE_SIZE_256) * |
kadonotakashi | 0:8fdf9a60065b | 247 | DATAFLASH_PAGE_SIZE_264; |
kadonotakashi | 0:8fdf9a60065b | 248 | } |
kadonotakashi | 0:8fdf9a60065b | 249 | break; |
kadonotakashi | 0:8fdf9a60065b | 250 | case DATAFLASH_ID_DENSITY_16_MBIT: |
kadonotakashi | 0:8fdf9a60065b | 251 | case DATAFLASH_ID_DENSITY_32_MBIT: |
kadonotakashi | 0:8fdf9a60065b | 252 | if (binary_page_size) { |
kadonotakashi | 0:8fdf9a60065b | 253 | _page_size = DATAFLASH_PAGE_SIZE_512; |
kadonotakashi | 0:8fdf9a60065b | 254 | _block_size = DATAFLASH_BLOCK_SIZE_4K; |
kadonotakashi | 0:8fdf9a60065b | 255 | } else { |
kadonotakashi | 0:8fdf9a60065b | 256 | _page_size = DATAFLASH_PAGE_SIZE_528; |
kadonotakashi | 0:8fdf9a60065b | 257 | _block_size = DATAFLASH_BLOCK_SIZE_4K1; |
kadonotakashi | 0:8fdf9a60065b | 258 | |
kadonotakashi | 0:8fdf9a60065b | 259 | /* adjust device size */ |
kadonotakashi | 0:8fdf9a60065b | 260 | _device_size = (_device_size / DATAFLASH_PAGE_SIZE_512) * |
kadonotakashi | 0:8fdf9a60065b | 261 | DATAFLASH_PAGE_SIZE_528; |
kadonotakashi | 0:8fdf9a60065b | 262 | } |
kadonotakashi | 0:8fdf9a60065b | 263 | break; |
kadonotakashi | 0:8fdf9a60065b | 264 | default: |
kadonotakashi | 0:8fdf9a60065b | 265 | break; |
kadonotakashi | 0:8fdf9a60065b | 266 | } |
kadonotakashi | 0:8fdf9a60065b | 267 | |
kadonotakashi | 0:8fdf9a60065b | 268 | DEBUG_PRINTF("density: %" PRIu16 "\r\n", id & DATAFLASH_ID_DENSITY_MASK); |
kadonotakashi | 0:8fdf9a60065b | 269 | DEBUG_PRINTF("size: %" PRIu32 "\r\n", _device_size); |
kadonotakashi | 0:8fdf9a60065b | 270 | DEBUG_PRINTF("page: %" PRIu16 "\r\n", _page_size); |
kadonotakashi | 0:8fdf9a60065b | 271 | DEBUG_PRINTF("block: %" PRIu16 "\r\n", _block_size); |
kadonotakashi | 0:8fdf9a60065b | 272 | |
kadonotakashi | 0:8fdf9a60065b | 273 | /* device successfully detected, set OK error code */ |
kadonotakashi | 0:8fdf9a60065b | 274 | result = BD_ERROR_OK; |
kadonotakashi | 0:8fdf9a60065b | 275 | } |
kadonotakashi | 0:8fdf9a60065b | 276 | |
kadonotakashi | 0:8fdf9a60065b | 277 | /* write protect device when idle */ |
kadonotakashi | 0:8fdf9a60065b | 278 | _write_enable(false); |
kadonotakashi | 0:8fdf9a60065b | 279 | |
kadonotakashi | 0:8fdf9a60065b | 280 | if (result == BD_ERROR_OK) { |
kadonotakashi | 0:8fdf9a60065b | 281 | _is_initialized = true; |
kadonotakashi | 0:8fdf9a60065b | 282 | } |
kadonotakashi | 0:8fdf9a60065b | 283 | |
kadonotakashi | 0:8fdf9a60065b | 284 | return result; |
kadonotakashi | 0:8fdf9a60065b | 285 | } |
kadonotakashi | 0:8fdf9a60065b | 286 | |
kadonotakashi | 0:8fdf9a60065b | 287 | int DataFlashBlockDevice::deinit() |
kadonotakashi | 0:8fdf9a60065b | 288 | { |
kadonotakashi | 0:8fdf9a60065b | 289 | DEBUG_PRINTF("deinit\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 290 | |
kadonotakashi | 0:8fdf9a60065b | 291 | if (!_is_initialized) { |
kadonotakashi | 0:8fdf9a60065b | 292 | _init_ref_count = 0; |
kadonotakashi | 0:8fdf9a60065b | 293 | return BD_ERROR_OK; |
kadonotakashi | 0:8fdf9a60065b | 294 | } |
kadonotakashi | 0:8fdf9a60065b | 295 | |
kadonotakashi | 0:8fdf9a60065b | 296 | uint32_t val = core_util_atomic_decr_u32(&_init_ref_count, 1); |
kadonotakashi | 0:8fdf9a60065b | 297 | |
kadonotakashi | 0:8fdf9a60065b | 298 | if (val) { |
kadonotakashi | 0:8fdf9a60065b | 299 | return BD_ERROR_OK; |
kadonotakashi | 0:8fdf9a60065b | 300 | } |
kadonotakashi | 0:8fdf9a60065b | 301 | |
kadonotakashi | 0:8fdf9a60065b | 302 | _is_initialized = false; |
kadonotakashi | 0:8fdf9a60065b | 303 | return BD_ERROR_OK; |
kadonotakashi | 0:8fdf9a60065b | 304 | } |
kadonotakashi | 0:8fdf9a60065b | 305 | |
kadonotakashi | 0:8fdf9a60065b | 306 | int DataFlashBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) |
kadonotakashi | 0:8fdf9a60065b | 307 | { |
kadonotakashi | 0:8fdf9a60065b | 308 | DEBUG_PRINTF("read: %p %" PRIX64 " %" PRIX64 "\r\n", buffer, addr, size); |
kadonotakashi | 0:8fdf9a60065b | 309 | |
kadonotakashi | 0:8fdf9a60065b | 310 | if (!_is_initialized) { |
kadonotakashi | 0:8fdf9a60065b | 311 | return BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 312 | } |
kadonotakashi | 0:8fdf9a60065b | 313 | |
kadonotakashi | 0:8fdf9a60065b | 314 | int result = BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 315 | |
kadonotakashi | 0:8fdf9a60065b | 316 | /* check parameters are valid and the read is within bounds */ |
kadonotakashi | 0:8fdf9a60065b | 317 | if (is_valid_read(addr, size) && buffer) { |
kadonotakashi | 0:8fdf9a60065b | 318 | |
kadonotakashi | 0:8fdf9a60065b | 319 | uint8_t *external_buffer = static_cast<uint8_t *>(buffer); |
kadonotakashi | 0:8fdf9a60065b | 320 | |
kadonotakashi | 0:8fdf9a60065b | 321 | /* activate device */ |
kadonotakashi | 0:8fdf9a60065b | 322 | _cs = 0; |
kadonotakashi | 0:8fdf9a60065b | 323 | |
kadonotakashi | 0:8fdf9a60065b | 324 | /* send read opcode */ |
kadonotakashi | 0:8fdf9a60065b | 325 | _spi.write(DATAFLASH_OP_READ_LOW_FREQUENCY); |
kadonotakashi | 0:8fdf9a60065b | 326 | |
kadonotakashi | 0:8fdf9a60065b | 327 | /* translate address */ |
kadonotakashi | 0:8fdf9a60065b | 328 | uint32_t address = _translate_address(addr); |
kadonotakashi | 0:8fdf9a60065b | 329 | |
kadonotakashi | 0:8fdf9a60065b | 330 | DEBUG_PRINTF("address: %" PRIX32 "\r\n", address); |
kadonotakashi | 0:8fdf9a60065b | 331 | |
kadonotakashi | 0:8fdf9a60065b | 332 | /* send read address */ |
kadonotakashi | 0:8fdf9a60065b | 333 | _spi.write((address >> 16) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 334 | _spi.write((address >> 8) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 335 | _spi.write(address & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 336 | |
kadonotakashi | 0:8fdf9a60065b | 337 | /* clock out one byte at a time and store in external buffer */ |
kadonotakashi | 0:8fdf9a60065b | 338 | for (uint32_t index = 0; index < size; index++) { |
kadonotakashi | 0:8fdf9a60065b | 339 | external_buffer[index] = _spi.write(DATAFLASH_OP_NOP); |
kadonotakashi | 0:8fdf9a60065b | 340 | } |
kadonotakashi | 0:8fdf9a60065b | 341 | |
kadonotakashi | 0:8fdf9a60065b | 342 | /* deactivate device */ |
kadonotakashi | 0:8fdf9a60065b | 343 | _cs = 1; |
kadonotakashi | 0:8fdf9a60065b | 344 | |
kadonotakashi | 0:8fdf9a60065b | 345 | result = BD_ERROR_OK; |
kadonotakashi | 0:8fdf9a60065b | 346 | } |
kadonotakashi | 0:8fdf9a60065b | 347 | |
kadonotakashi | 0:8fdf9a60065b | 348 | return result; |
kadonotakashi | 0:8fdf9a60065b | 349 | } |
kadonotakashi | 0:8fdf9a60065b | 350 | |
kadonotakashi | 0:8fdf9a60065b | 351 | int DataFlashBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size) |
kadonotakashi | 0:8fdf9a60065b | 352 | { |
kadonotakashi | 0:8fdf9a60065b | 353 | DEBUG_PRINTF("program: %p %" PRIX64 " %" PRIX64 "\r\n", buffer, addr, size); |
kadonotakashi | 0:8fdf9a60065b | 354 | |
kadonotakashi | 0:8fdf9a60065b | 355 | if (!_is_initialized) { |
kadonotakashi | 0:8fdf9a60065b | 356 | return BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 357 | } |
kadonotakashi | 0:8fdf9a60065b | 358 | |
kadonotakashi | 0:8fdf9a60065b | 359 | int result = BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 360 | |
kadonotakashi | 0:8fdf9a60065b | 361 | /* check parameters are valid and the write is within bounds */ |
kadonotakashi | 0:8fdf9a60065b | 362 | if (is_valid_program(addr, size) && buffer) { |
kadonotakashi | 0:8fdf9a60065b | 363 | |
kadonotakashi | 0:8fdf9a60065b | 364 | const uint8_t *external_buffer = static_cast<const uint8_t *>(buffer); |
kadonotakashi | 0:8fdf9a60065b | 365 | |
kadonotakashi | 0:8fdf9a60065b | 366 | /* Each write command can only cover one page at a time. |
kadonotakashi | 0:8fdf9a60065b | 367 | Find page and current page offset for handling unaligned writes. |
kadonotakashi | 0:8fdf9a60065b | 368 | */ |
kadonotakashi | 0:8fdf9a60065b | 369 | uint32_t page_number = addr / _page_size; |
kadonotakashi | 0:8fdf9a60065b | 370 | uint32_t page_offset = addr % _page_size; |
kadonotakashi | 0:8fdf9a60065b | 371 | |
kadonotakashi | 0:8fdf9a60065b | 372 | /* disable write protection */ |
kadonotakashi | 0:8fdf9a60065b | 373 | _write_enable(true); |
kadonotakashi | 0:8fdf9a60065b | 374 | |
kadonotakashi | 0:8fdf9a60065b | 375 | /* continue until all bytes have been written */ |
kadonotakashi | 0:8fdf9a60065b | 376 | uint32_t bytes_written = 0; |
kadonotakashi | 0:8fdf9a60065b | 377 | while (bytes_written < size) { |
kadonotakashi | 0:8fdf9a60065b | 378 | |
kadonotakashi | 0:8fdf9a60065b | 379 | /* find remaining bytes to be written */ |
kadonotakashi | 0:8fdf9a60065b | 380 | uint32_t bytes_remaining = size - bytes_written; |
kadonotakashi | 0:8fdf9a60065b | 381 | |
kadonotakashi | 0:8fdf9a60065b | 382 | /* cap the value at the page size and offset */ |
kadonotakashi | 0:8fdf9a60065b | 383 | if (bytes_remaining > (_page_size - page_offset)) { |
kadonotakashi | 0:8fdf9a60065b | 384 | bytes_remaining = _page_size - page_offset; |
kadonotakashi | 0:8fdf9a60065b | 385 | } |
kadonotakashi | 0:8fdf9a60065b | 386 | |
kadonotakashi | 0:8fdf9a60065b | 387 | /* Write one page, bytes_written keeps track of the progress, |
kadonotakashi | 0:8fdf9a60065b | 388 | page_number is the page address, and page_offset is non-zero for |
kadonotakashi | 0:8fdf9a60065b | 389 | unaligned writes. |
kadonotakashi | 0:8fdf9a60065b | 390 | */ |
kadonotakashi | 0:8fdf9a60065b | 391 | result = _write_page(&external_buffer[bytes_written], |
kadonotakashi | 0:8fdf9a60065b | 392 | page_number, |
kadonotakashi | 0:8fdf9a60065b | 393 | page_offset, |
kadonotakashi | 0:8fdf9a60065b | 394 | bytes_remaining); |
kadonotakashi | 0:8fdf9a60065b | 395 | |
kadonotakashi | 0:8fdf9a60065b | 396 | /* update loop variables upon success otherwise break loop */ |
kadonotakashi | 0:8fdf9a60065b | 397 | if (result == BD_ERROR_OK) { |
kadonotakashi | 0:8fdf9a60065b | 398 | bytes_written += bytes_remaining; |
kadonotakashi | 0:8fdf9a60065b | 399 | page_number++; |
kadonotakashi | 0:8fdf9a60065b | 400 | |
kadonotakashi | 0:8fdf9a60065b | 401 | /* After the first successful write, |
kadonotakashi | 0:8fdf9a60065b | 402 | all subsequent writes will be aligned. |
kadonotakashi | 0:8fdf9a60065b | 403 | */ |
kadonotakashi | 0:8fdf9a60065b | 404 | page_offset = 0; |
kadonotakashi | 0:8fdf9a60065b | 405 | } else { |
kadonotakashi | 0:8fdf9a60065b | 406 | break; |
kadonotakashi | 0:8fdf9a60065b | 407 | } |
kadonotakashi | 0:8fdf9a60065b | 408 | } |
kadonotakashi | 0:8fdf9a60065b | 409 | |
kadonotakashi | 0:8fdf9a60065b | 410 | /* enable write protection */ |
kadonotakashi | 0:8fdf9a60065b | 411 | _write_enable(false); |
kadonotakashi | 0:8fdf9a60065b | 412 | } |
kadonotakashi | 0:8fdf9a60065b | 413 | |
kadonotakashi | 0:8fdf9a60065b | 414 | return result; |
kadonotakashi | 0:8fdf9a60065b | 415 | } |
kadonotakashi | 0:8fdf9a60065b | 416 | |
kadonotakashi | 0:8fdf9a60065b | 417 | int DataFlashBlockDevice::erase(bd_addr_t addr, bd_size_t size) |
kadonotakashi | 0:8fdf9a60065b | 418 | { |
kadonotakashi | 0:8fdf9a60065b | 419 | DEBUG_PRINTF("erase: %" PRIX64 " %" PRIX64 "\r\n", addr, size); |
kadonotakashi | 0:8fdf9a60065b | 420 | |
kadonotakashi | 0:8fdf9a60065b | 421 | if (!_is_initialized) { |
kadonotakashi | 0:8fdf9a60065b | 422 | return BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 423 | } |
kadonotakashi | 0:8fdf9a60065b | 424 | |
kadonotakashi | 0:8fdf9a60065b | 425 | int result = BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 426 | |
kadonotakashi | 0:8fdf9a60065b | 427 | /* check parameters are valid and the erase is within bounds */ |
kadonotakashi | 0:8fdf9a60065b | 428 | if (is_valid_erase(addr, size)) { |
kadonotakashi | 0:8fdf9a60065b | 429 | |
kadonotakashi | 0:8fdf9a60065b | 430 | /* disable write protection */ |
kadonotakashi | 0:8fdf9a60065b | 431 | _write_enable(true); |
kadonotakashi | 0:8fdf9a60065b | 432 | |
kadonotakashi | 0:8fdf9a60065b | 433 | /* erase one block at a time until the full size has been erased */ |
kadonotakashi | 0:8fdf9a60065b | 434 | uint32_t erased = 0; |
kadonotakashi | 0:8fdf9a60065b | 435 | while (erased < size) { |
kadonotakashi | 0:8fdf9a60065b | 436 | |
kadonotakashi | 0:8fdf9a60065b | 437 | /* set block erase opcode */ |
kadonotakashi | 0:8fdf9a60065b | 438 | uint32_t command = DATAFLASH_OP_ERASE_BLOCK; |
kadonotakashi | 0:8fdf9a60065b | 439 | |
kadonotakashi | 0:8fdf9a60065b | 440 | /* translate address */ |
kadonotakashi | 0:8fdf9a60065b | 441 | uint32_t address = _translate_address(addr); |
kadonotakashi | 0:8fdf9a60065b | 442 | |
kadonotakashi | 0:8fdf9a60065b | 443 | /* set block address */ |
kadonotakashi | 0:8fdf9a60065b | 444 | command = (command << 8) | ((address >> 16) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 445 | command = (command << 8) | ((address >> 8) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 446 | command = (command << 8) | (address & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 447 | |
kadonotakashi | 0:8fdf9a60065b | 448 | /* send command to device */ |
kadonotakashi | 0:8fdf9a60065b | 449 | _write_command(command, NULL, 0); |
kadonotakashi | 0:8fdf9a60065b | 450 | |
kadonotakashi | 0:8fdf9a60065b | 451 | /* wait until device is ready and update return value */ |
kadonotakashi | 0:8fdf9a60065b | 452 | result = _sync(); |
kadonotakashi | 0:8fdf9a60065b | 453 | |
kadonotakashi | 0:8fdf9a60065b | 454 | /* if erase failed, break loop */ |
kadonotakashi | 0:8fdf9a60065b | 455 | if (result != BD_ERROR_OK) { |
kadonotakashi | 0:8fdf9a60065b | 456 | break; |
kadonotakashi | 0:8fdf9a60065b | 457 | } |
kadonotakashi | 0:8fdf9a60065b | 458 | |
kadonotakashi | 0:8fdf9a60065b | 459 | /* update loop variables */ |
kadonotakashi | 0:8fdf9a60065b | 460 | addr += _block_size; |
kadonotakashi | 0:8fdf9a60065b | 461 | erased += _block_size; |
kadonotakashi | 0:8fdf9a60065b | 462 | } |
kadonotakashi | 0:8fdf9a60065b | 463 | |
kadonotakashi | 0:8fdf9a60065b | 464 | /* enable write protection */ |
kadonotakashi | 0:8fdf9a60065b | 465 | _write_enable(false); |
kadonotakashi | 0:8fdf9a60065b | 466 | } |
kadonotakashi | 0:8fdf9a60065b | 467 | |
kadonotakashi | 0:8fdf9a60065b | 468 | return result; |
kadonotakashi | 0:8fdf9a60065b | 469 | } |
kadonotakashi | 0:8fdf9a60065b | 470 | |
kadonotakashi | 0:8fdf9a60065b | 471 | bd_size_t DataFlashBlockDevice::get_read_size() const |
kadonotakashi | 0:8fdf9a60065b | 472 | { |
kadonotakashi | 0:8fdf9a60065b | 473 | DEBUG_PRINTF("read size: %d\r\n", DATAFLASH_READ_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 474 | |
kadonotakashi | 0:8fdf9a60065b | 475 | return DATAFLASH_READ_SIZE; |
kadonotakashi | 0:8fdf9a60065b | 476 | } |
kadonotakashi | 0:8fdf9a60065b | 477 | |
kadonotakashi | 0:8fdf9a60065b | 478 | bd_size_t DataFlashBlockDevice::get_program_size() const |
kadonotakashi | 0:8fdf9a60065b | 479 | { |
kadonotakashi | 0:8fdf9a60065b | 480 | DEBUG_PRINTF("program size: %d\r\n", DATAFLASH_PROG_SIZE); |
kadonotakashi | 0:8fdf9a60065b | 481 | |
kadonotakashi | 0:8fdf9a60065b | 482 | return DATAFLASH_PROG_SIZE; |
kadonotakashi | 0:8fdf9a60065b | 483 | } |
kadonotakashi | 0:8fdf9a60065b | 484 | |
kadonotakashi | 0:8fdf9a60065b | 485 | bd_size_t DataFlashBlockDevice::get_erase_size() const |
kadonotakashi | 0:8fdf9a60065b | 486 | { |
kadonotakashi | 0:8fdf9a60065b | 487 | DEBUG_PRINTF("erase size: %" PRIX16 "\r\n", _block_size); |
kadonotakashi | 0:8fdf9a60065b | 488 | |
kadonotakashi | 0:8fdf9a60065b | 489 | return _block_size; |
kadonotakashi | 0:8fdf9a60065b | 490 | } |
kadonotakashi | 0:8fdf9a60065b | 491 | |
kadonotakashi | 0:8fdf9a60065b | 492 | bd_size_t DataFlashBlockDevice::get_erase_size(bd_addr_t addr) const |
kadonotakashi | 0:8fdf9a60065b | 493 | { |
kadonotakashi | 0:8fdf9a60065b | 494 | DEBUG_PRINTF("erase size: %" PRIX16 "\r\n", _block_size); |
kadonotakashi | 0:8fdf9a60065b | 495 | |
kadonotakashi | 0:8fdf9a60065b | 496 | return _block_size; |
kadonotakashi | 0:8fdf9a60065b | 497 | } |
kadonotakashi | 0:8fdf9a60065b | 498 | |
kadonotakashi | 0:8fdf9a60065b | 499 | bd_size_t DataFlashBlockDevice::size() const |
kadonotakashi | 0:8fdf9a60065b | 500 | { |
kadonotakashi | 0:8fdf9a60065b | 501 | DEBUG_PRINTF("device size: %" PRIX32 "\r\n", _device_size); |
kadonotakashi | 0:8fdf9a60065b | 502 | |
kadonotakashi | 0:8fdf9a60065b | 503 | return _device_size; |
kadonotakashi | 0:8fdf9a60065b | 504 | } |
kadonotakashi | 0:8fdf9a60065b | 505 | |
kadonotakashi | 0:8fdf9a60065b | 506 | /** |
kadonotakashi | 0:8fdf9a60065b | 507 | * @brief Function for reading a specific register. |
kadonotakashi | 0:8fdf9a60065b | 508 | * @details Used for reading either the Status Register or Manufacture and ID Register. |
kadonotakashi | 0:8fdf9a60065b | 509 | * |
kadonotakashi | 0:8fdf9a60065b | 510 | * @param opcode Register to be read. |
kadonotakashi | 0:8fdf9a60065b | 511 | * @return value. |
kadonotakashi | 0:8fdf9a60065b | 512 | */ |
kadonotakashi | 0:8fdf9a60065b | 513 | uint16_t DataFlashBlockDevice::_get_register(uint8_t opcode) |
kadonotakashi | 0:8fdf9a60065b | 514 | { |
kadonotakashi | 0:8fdf9a60065b | 515 | DEBUG_PRINTF("_get_register: %" PRIX8 "\r\n", opcode); |
kadonotakashi | 0:8fdf9a60065b | 516 | |
kadonotakashi | 0:8fdf9a60065b | 517 | /* activate device */ |
kadonotakashi | 0:8fdf9a60065b | 518 | _cs = 0; |
kadonotakashi | 0:8fdf9a60065b | 519 | |
kadonotakashi | 0:8fdf9a60065b | 520 | /* write opcode */ |
kadonotakashi | 0:8fdf9a60065b | 521 | _spi.write(opcode); |
kadonotakashi | 0:8fdf9a60065b | 522 | |
kadonotakashi | 0:8fdf9a60065b | 523 | /* read and store result */ |
kadonotakashi | 0:8fdf9a60065b | 524 | int status = (_spi.write(DATAFLASH_OP_NOP)); |
kadonotakashi | 0:8fdf9a60065b | 525 | status = (status << 8) | (_spi.write(DATAFLASH_OP_NOP)); |
kadonotakashi | 0:8fdf9a60065b | 526 | |
kadonotakashi | 0:8fdf9a60065b | 527 | /* deactivate device */ |
kadonotakashi | 0:8fdf9a60065b | 528 | _cs = 1; |
kadonotakashi | 0:8fdf9a60065b | 529 | |
kadonotakashi | 0:8fdf9a60065b | 530 | return status; |
kadonotakashi | 0:8fdf9a60065b | 531 | } |
kadonotakashi | 0:8fdf9a60065b | 532 | |
kadonotakashi | 0:8fdf9a60065b | 533 | /** |
kadonotakashi | 0:8fdf9a60065b | 534 | * @brief Function for sending command and data to device. |
kadonotakashi | 0:8fdf9a60065b | 535 | * @details The command can be an opcode with address and data or |
kadonotakashi | 0:8fdf9a60065b | 536 | * a 4 byte command without data. |
kadonotakashi | 0:8fdf9a60065b | 537 | * |
kadonotakashi | 0:8fdf9a60065b | 538 | * The supported frequencies and the opcode used do not |
kadonotakashi | 0:8fdf9a60065b | 539 | * require dummy bytes to be sent after command. |
kadonotakashi | 0:8fdf9a60065b | 540 | * |
kadonotakashi | 0:8fdf9a60065b | 541 | * @param command Opcode with address or 4 byte command. |
kadonotakashi | 0:8fdf9a60065b | 542 | * @param buffer Data to be sent after command. |
kadonotakashi | 0:8fdf9a60065b | 543 | * @param size Size of buffer. |
kadonotakashi | 0:8fdf9a60065b | 544 | */ |
kadonotakashi | 0:8fdf9a60065b | 545 | void DataFlashBlockDevice::_write_command(uint32_t command, const uint8_t *buffer, uint32_t size) |
kadonotakashi | 0:8fdf9a60065b | 546 | { |
kadonotakashi | 0:8fdf9a60065b | 547 | DEBUG_PRINTF("_write_command: %" PRIX32 " %p %" PRIX32 "\r\n", command, buffer, size); |
kadonotakashi | 0:8fdf9a60065b | 548 | |
kadonotakashi | 0:8fdf9a60065b | 549 | /* activate device */ |
kadonotakashi | 0:8fdf9a60065b | 550 | _cs = 0; |
kadonotakashi | 0:8fdf9a60065b | 551 | |
kadonotakashi | 0:8fdf9a60065b | 552 | /* send command (opcode with data or 4 byte command) */ |
kadonotakashi | 0:8fdf9a60065b | 553 | _spi.write((command >> 24) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 554 | _spi.write((command >> 16) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 555 | _spi.write((command >> 8) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 556 | _spi.write(command & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 557 | |
kadonotakashi | 0:8fdf9a60065b | 558 | /* send optional data */ |
kadonotakashi | 0:8fdf9a60065b | 559 | if (buffer && size) { |
kadonotakashi | 0:8fdf9a60065b | 560 | for (uint32_t index = 0; index < size; index++) { |
kadonotakashi | 0:8fdf9a60065b | 561 | _spi.write(buffer[index]); |
kadonotakashi | 0:8fdf9a60065b | 562 | } |
kadonotakashi | 0:8fdf9a60065b | 563 | } |
kadonotakashi | 0:8fdf9a60065b | 564 | |
kadonotakashi | 0:8fdf9a60065b | 565 | /* deactivate device */ |
kadonotakashi | 0:8fdf9a60065b | 566 | _cs = 1; |
kadonotakashi | 0:8fdf9a60065b | 567 | } |
kadonotakashi | 0:8fdf9a60065b | 568 | |
kadonotakashi | 0:8fdf9a60065b | 569 | /** |
kadonotakashi | 0:8fdf9a60065b | 570 | * @brief Enable and disable write protection. |
kadonotakashi | 0:8fdf9a60065b | 571 | * |
kadonotakashi | 0:8fdf9a60065b | 572 | * @param enable Boolean for enabling or disabling write protection. |
kadonotakashi | 0:8fdf9a60065b | 573 | */ |
kadonotakashi | 0:8fdf9a60065b | 574 | void DataFlashBlockDevice::_write_enable(bool enable) |
kadonotakashi | 0:8fdf9a60065b | 575 | { |
kadonotakashi | 0:8fdf9a60065b | 576 | DEBUG_PRINTF("_write_enable: %d\r\n", enable); |
kadonotakashi | 0:8fdf9a60065b | 577 | |
kadonotakashi | 0:8fdf9a60065b | 578 | /* enable writing, disable write protection */ |
kadonotakashi | 0:8fdf9a60065b | 579 | if (enable) { |
kadonotakashi | 0:8fdf9a60065b | 580 | /* if not-write-protected pin is connected, select it */ |
kadonotakashi | 0:8fdf9a60065b | 581 | if (_nwp.is_connected()) { |
kadonotakashi | 0:8fdf9a60065b | 582 | _nwp = 1; |
kadonotakashi | 0:8fdf9a60065b | 583 | } |
kadonotakashi | 0:8fdf9a60065b | 584 | |
kadonotakashi | 0:8fdf9a60065b | 585 | /* send 4 byte command enabling writes */ |
kadonotakashi | 0:8fdf9a60065b | 586 | _write_command(DATAFLASH_COMMAND_WRITE_ENABLE, NULL, 0); |
kadonotakashi | 0:8fdf9a60065b | 587 | } else { |
kadonotakashi | 0:8fdf9a60065b | 588 | |
kadonotakashi | 0:8fdf9a60065b | 589 | /* if not-write-protected pin is connected, deselect it */ |
kadonotakashi | 0:8fdf9a60065b | 590 | if (_nwp.is_connected()) { |
kadonotakashi | 0:8fdf9a60065b | 591 | _nwp = 0; |
kadonotakashi | 0:8fdf9a60065b | 592 | } |
kadonotakashi | 0:8fdf9a60065b | 593 | |
kadonotakashi | 0:8fdf9a60065b | 594 | /* send 4 byte command disabling writes */ |
kadonotakashi | 0:8fdf9a60065b | 595 | _write_command(DATAFLASH_COMMAND_WRITE_DISABLE, NULL, 0); |
kadonotakashi | 0:8fdf9a60065b | 596 | } |
kadonotakashi | 0:8fdf9a60065b | 597 | } |
kadonotakashi | 0:8fdf9a60065b | 598 | |
kadonotakashi | 0:8fdf9a60065b | 599 | /** |
kadonotakashi | 0:8fdf9a60065b | 600 | * @brief Sleep and poll status register until device is ready for next command. |
kadonotakashi | 0:8fdf9a60065b | 601 | * |
kadonotakashi | 0:8fdf9a60065b | 602 | * @return BlockDevice compatible error code. |
kadonotakashi | 0:8fdf9a60065b | 603 | */ |
kadonotakashi | 0:8fdf9a60065b | 604 | int DataFlashBlockDevice::_sync(void) |
kadonotakashi | 0:8fdf9a60065b | 605 | { |
kadonotakashi | 0:8fdf9a60065b | 606 | DEBUG_PRINTF("_sync\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 607 | |
kadonotakashi | 0:8fdf9a60065b | 608 | /* default return value if operation times out */ |
kadonotakashi | 0:8fdf9a60065b | 609 | int result = BD_ERROR_DEVICE_ERROR; |
kadonotakashi | 0:8fdf9a60065b | 610 | |
kadonotakashi | 0:8fdf9a60065b | 611 | /* Poll device until a hard coded timeout is reached. |
kadonotakashi | 0:8fdf9a60065b | 612 | The polling interval is based on the typical page program time. |
kadonotakashi | 0:8fdf9a60065b | 613 | */ |
kadonotakashi | 0:8fdf9a60065b | 614 | for (uint32_t timeout = 0; |
kadonotakashi | 0:8fdf9a60065b | 615 | timeout < DATAFLASH_TIMEOUT; |
kadonotakashi | 0:8fdf9a60065b | 616 | timeout += DATAFLASH_TIMING_ERASE_PROGRAM_PAGE) { |
kadonotakashi | 0:8fdf9a60065b | 617 | |
kadonotakashi | 0:8fdf9a60065b | 618 | /* get status register */ |
kadonotakashi | 0:8fdf9a60065b | 619 | uint16_t status = _get_register(DATAFLASH_OP_STATUS); |
kadonotakashi | 0:8fdf9a60065b | 620 | |
kadonotakashi | 0:8fdf9a60065b | 621 | /* erase/program bit set, exit with error code set */ |
kadonotakashi | 0:8fdf9a60065b | 622 | if (status & DATAFLASH_BIT_ERASE_PROGRAM_ERROR) { |
kadonotakashi | 0:8fdf9a60065b | 623 | DEBUG_PRINTF("DATAFLASH_BIT_ERASE_PROGRAM_ERROR\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 624 | break; |
kadonotakashi | 0:8fdf9a60065b | 625 | /* device ready, set OK code set */ |
kadonotakashi | 0:8fdf9a60065b | 626 | } else if (status & DATAFLASH_BIT_READY) { |
kadonotakashi | 0:8fdf9a60065b | 627 | DEBUG_PRINTF("DATAFLASH_BIT_READY\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 628 | result = BD_ERROR_OK; |
kadonotakashi | 0:8fdf9a60065b | 629 | break; |
kadonotakashi | 0:8fdf9a60065b | 630 | /* wait the typical write period before trying again */ |
kadonotakashi | 0:8fdf9a60065b | 631 | } else { |
kadonotakashi | 0:8fdf9a60065b | 632 | DEBUG_PRINTF("wait_ms: %d\r\n", DATAFLASH_TIMING_ERASE_PROGRAM_PAGE); |
kadonotakashi | 0:8fdf9a60065b | 633 | wait_ms(DATAFLASH_TIMING_ERASE_PROGRAM_PAGE); |
kadonotakashi | 0:8fdf9a60065b | 634 | } |
kadonotakashi | 0:8fdf9a60065b | 635 | } |
kadonotakashi | 0:8fdf9a60065b | 636 | |
kadonotakashi | 0:8fdf9a60065b | 637 | return result; |
kadonotakashi | 0:8fdf9a60065b | 638 | } |
kadonotakashi | 0:8fdf9a60065b | 639 | |
kadonotakashi | 0:8fdf9a60065b | 640 | /** |
kadonotakashi | 0:8fdf9a60065b | 641 | * @brief Write single page. |
kadonotakashi | 0:8fdf9a60065b | 642 | * @details Address can be unaligned. |
kadonotakashi | 0:8fdf9a60065b | 643 | * |
kadonotakashi | 0:8fdf9a60065b | 644 | * @param buffer Data to write. |
kadonotakashi | 0:8fdf9a60065b | 645 | * @param addr Address to write from. |
kadonotakashi | 0:8fdf9a60065b | 646 | * @param size Bytes to write. Can at most be the full page. |
kadonotakashi | 0:8fdf9a60065b | 647 | * @return BlockDevice error code. |
kadonotakashi | 0:8fdf9a60065b | 648 | */ |
kadonotakashi | 0:8fdf9a60065b | 649 | int DataFlashBlockDevice::_write_page(const uint8_t *buffer, |
kadonotakashi | 0:8fdf9a60065b | 650 | uint32_t page, |
kadonotakashi | 0:8fdf9a60065b | 651 | uint32_t offset, |
kadonotakashi | 0:8fdf9a60065b | 652 | uint32_t size) |
kadonotakashi | 0:8fdf9a60065b | 653 | { |
kadonotakashi | 0:8fdf9a60065b | 654 | DEBUG_PRINTF("_write_page: %p %" PRIX32 " %" PRIX32 "\r\n", buffer, page, size); |
kadonotakashi | 0:8fdf9a60065b | 655 | |
kadonotakashi | 0:8fdf9a60065b | 656 | uint32_t command = DATAFLASH_OP_NOP; |
kadonotakashi | 0:8fdf9a60065b | 657 | |
kadonotakashi | 0:8fdf9a60065b | 658 | /* opcode for writing directly to device, in a single command, |
kadonotakashi | 0:8fdf9a60065b | 659 | assuming the page has been erased before hand. |
kadonotakashi | 0:8fdf9a60065b | 660 | */ |
kadonotakashi | 0:8fdf9a60065b | 661 | command = DATAFLASH_OP_PROGRAM_DIRECT; |
kadonotakashi | 0:8fdf9a60065b | 662 | |
kadonotakashi | 0:8fdf9a60065b | 663 | uint32_t address = 0; |
kadonotakashi | 0:8fdf9a60065b | 664 | |
kadonotakashi | 0:8fdf9a60065b | 665 | /* convert page number and offset into device address based on address format */ |
kadonotakashi | 0:8fdf9a60065b | 666 | if (_page_size == DATAFLASH_PAGE_SIZE_264) { |
kadonotakashi | 0:8fdf9a60065b | 667 | address = (page << DATAFLASH_PAGE_BIT_264) | offset; |
kadonotakashi | 0:8fdf9a60065b | 668 | } else if (_page_size == DATAFLASH_PAGE_SIZE_528) { |
kadonotakashi | 0:8fdf9a60065b | 669 | address = (page << DATAFLASH_PAGE_BIT_528) | offset; |
kadonotakashi | 0:8fdf9a60065b | 670 | } else { |
kadonotakashi | 0:8fdf9a60065b | 671 | address = (page * _page_size) | offset; |
kadonotakashi | 0:8fdf9a60065b | 672 | } |
kadonotakashi | 0:8fdf9a60065b | 673 | |
kadonotakashi | 0:8fdf9a60065b | 674 | /* set write address */ |
kadonotakashi | 0:8fdf9a60065b | 675 | command = (command << 8) | ((address >> 16) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 676 | command = (command << 8) | ((address >> 8) & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 677 | command = (command << 8) | (address & 0xFF); |
kadonotakashi | 0:8fdf9a60065b | 678 | |
kadonotakashi | 0:8fdf9a60065b | 679 | /* send write command with data */ |
kadonotakashi | 0:8fdf9a60065b | 680 | _write_command(command, buffer, size); |
kadonotakashi | 0:8fdf9a60065b | 681 | |
kadonotakashi | 0:8fdf9a60065b | 682 | /* wait until device is ready before continuing */ |
kadonotakashi | 0:8fdf9a60065b | 683 | int result = _sync(); |
kadonotakashi | 0:8fdf9a60065b | 684 | |
kadonotakashi | 0:8fdf9a60065b | 685 | return result; |
kadonotakashi | 0:8fdf9a60065b | 686 | } |
kadonotakashi | 0:8fdf9a60065b | 687 | |
kadonotakashi | 0:8fdf9a60065b | 688 | /** |
kadonotakashi | 0:8fdf9a60065b | 689 | * @brief Translate address. |
kadonotakashi | 0:8fdf9a60065b | 690 | * @details If the device is configured for non-binary page sizes, |
kadonotakashi | 0:8fdf9a60065b | 691 | * the address is translated from binary to non-binary form. |
kadonotakashi | 0:8fdf9a60065b | 692 | * |
kadonotakashi | 0:8fdf9a60065b | 693 | * @param addr Binary address. |
kadonotakashi | 0:8fdf9a60065b | 694 | * @return Address in format expected by device. |
kadonotakashi | 0:8fdf9a60065b | 695 | */ |
kadonotakashi | 0:8fdf9a60065b | 696 | uint32_t DataFlashBlockDevice::_translate_address(bd_addr_t addr) |
kadonotakashi | 0:8fdf9a60065b | 697 | { |
kadonotakashi | 0:8fdf9a60065b | 698 | uint32_t address = addr; |
kadonotakashi | 0:8fdf9a60065b | 699 | |
kadonotakashi | 0:8fdf9a60065b | 700 | /* translate address if page size is non-binary */ |
kadonotakashi | 0:8fdf9a60065b | 701 | if (_page_size == DATAFLASH_PAGE_SIZE_264) { |
kadonotakashi | 0:8fdf9a60065b | 702 | address = ((addr / DATAFLASH_PAGE_SIZE_264) << DATAFLASH_PAGE_BIT_264) | |
kadonotakashi | 0:8fdf9a60065b | 703 | (addr % DATAFLASH_PAGE_SIZE_264); |
kadonotakashi | 0:8fdf9a60065b | 704 | } else if (_page_size == DATAFLASH_PAGE_SIZE_528) { |
kadonotakashi | 0:8fdf9a60065b | 705 | address = ((addr / DATAFLASH_PAGE_SIZE_528) << DATAFLASH_PAGE_BIT_528) | |
kadonotakashi | 0:8fdf9a60065b | 706 | (addr % DATAFLASH_PAGE_SIZE_528); |
kadonotakashi | 0:8fdf9a60065b | 707 | } |
kadonotakashi | 0:8fdf9a60065b | 708 | |
kadonotakashi | 0:8fdf9a60065b | 709 | return address; |
kadonotakashi | 0:8fdf9a60065b | 710 | } |
kadonotakashi | 0:8fdf9a60065b | 711 | |
kadonotakashi | 0:8fdf9a60065b | 712 | /** |
kadonotakashi | 0:8fdf9a60065b | 713 | * @brief Internal function for printing out each bit set in status register. |
kadonotakashi | 0:8fdf9a60065b | 714 | * |
kadonotakashi | 0:8fdf9a60065b | 715 | * @param status Status register. |
kadonotakashi | 0:8fdf9a60065b | 716 | */ |
kadonotakashi | 0:8fdf9a60065b | 717 | void _print_status(uint16_t status) |
kadonotakashi | 0:8fdf9a60065b | 718 | { |
kadonotakashi | 0:8fdf9a60065b | 719 | #if DATAFLASH_DEBUG |
kadonotakashi | 0:8fdf9a60065b | 720 | DEBUG_PRINTF("%04X\r\n", status); |
kadonotakashi | 0:8fdf9a60065b | 721 | |
kadonotakashi | 0:8fdf9a60065b | 722 | /* device is ready (after write/erase) */ |
kadonotakashi | 0:8fdf9a60065b | 723 | if (status & DATAFLASH_BIT_READY) { |
kadonotakashi | 0:8fdf9a60065b | 724 | DEBUG_PRINTF("DATAFLASH_BIT_READY\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 725 | } |
kadonotakashi | 0:8fdf9a60065b | 726 | |
kadonotakashi | 0:8fdf9a60065b | 727 | /* Buffer comparison failed */ |
kadonotakashi | 0:8fdf9a60065b | 728 | if (status & DATAFLASH_BIT_COMPARE) { |
kadonotakashi | 0:8fdf9a60065b | 729 | DEBUG_PRINTF("DATAFLASH_BIT_COMPARE\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 730 | } |
kadonotakashi | 0:8fdf9a60065b | 731 | |
kadonotakashi | 0:8fdf9a60065b | 732 | /* device size is 2 MB */ |
kadonotakashi | 0:8fdf9a60065b | 733 | if (status & DATAFLASH_STATUS_DENSITY_2_MBIT) { |
kadonotakashi | 0:8fdf9a60065b | 734 | DEBUG_PRINTF("DATAFLASH_STATUS_DENSITY_2_MBIT\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 735 | } |
kadonotakashi | 0:8fdf9a60065b | 736 | |
kadonotakashi | 0:8fdf9a60065b | 737 | /* device size is 4 MB */ |
kadonotakashi | 0:8fdf9a60065b | 738 | if (status & DATAFLASH_STATUS_DENSITY_4_MBIT) { |
kadonotakashi | 0:8fdf9a60065b | 739 | DEBUG_PRINTF("DATAFLASH_STATUS_DENSITY_4_MBIT\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 740 | } |
kadonotakashi | 0:8fdf9a60065b | 741 | |
kadonotakashi | 0:8fdf9a60065b | 742 | /* device size is 8 MB */ |
kadonotakashi | 0:8fdf9a60065b | 743 | if (status & DATAFLASH_STATUS_DENSITY_8_MBIT) { |
kadonotakashi | 0:8fdf9a60065b | 744 | DEBUG_PRINTF("DATAFLASH_STATUS_DENSITY_8_MBIT\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 745 | } |
kadonotakashi | 0:8fdf9a60065b | 746 | |
kadonotakashi | 0:8fdf9a60065b | 747 | /* device size is 16 MB */ |
kadonotakashi | 0:8fdf9a60065b | 748 | if (status & DATAFLASH_STATUS_DENSITY_16_MBIT) { |
kadonotakashi | 0:8fdf9a60065b | 749 | DEBUG_PRINTF("DATAFLASH_STATUS_DENSITY_16_MBIT\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 750 | } |
kadonotakashi | 0:8fdf9a60065b | 751 | |
kadonotakashi | 0:8fdf9a60065b | 752 | /* device size is 32 MB */ |
kadonotakashi | 0:8fdf9a60065b | 753 | if (status & DATAFLASH_STATUS_DENSITY_32_MBIT) { |
kadonotakashi | 0:8fdf9a60065b | 754 | DEBUG_PRINTF("DATAFLASH_STATUS_DENSITY_32_MBIT\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 755 | } |
kadonotakashi | 0:8fdf9a60065b | 756 | |
kadonotakashi | 0:8fdf9a60065b | 757 | /* device size is 64 MB */ |
kadonotakashi | 0:8fdf9a60065b | 758 | if (status & DATAFLASH_STATUS_DENSITY_64_MBIT) { |
kadonotakashi | 0:8fdf9a60065b | 759 | DEBUG_PRINTF("DATAFLASH_STATUS_DENSITY_64_MBIT\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 760 | } |
kadonotakashi | 0:8fdf9a60065b | 761 | |
kadonotakashi | 0:8fdf9a60065b | 762 | /* sector protectino enabled */ |
kadonotakashi | 0:8fdf9a60065b | 763 | if (status & DATAFLASH_BIT_PROTECT) { |
kadonotakashi | 0:8fdf9a60065b | 764 | DEBUG_PRINTF("DATAFLASH_BIT_PROTECT\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 765 | } |
kadonotakashi | 0:8fdf9a60065b | 766 | |
kadonotakashi | 0:8fdf9a60065b | 767 | /* page size is a power of 2 */ |
kadonotakashi | 0:8fdf9a60065b | 768 | if (status & DATAFLASH_BIT_PAGE_SIZE) { |
kadonotakashi | 0:8fdf9a60065b | 769 | DEBUG_PRINTF("DATAFLASH_BIT_PAGE_SIZE\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 770 | } |
kadonotakashi | 0:8fdf9a60065b | 771 | |
kadonotakashi | 0:8fdf9a60065b | 772 | /* erase/program error */ |
kadonotakashi | 0:8fdf9a60065b | 773 | if (status & DATAFLASH_BIT_ERASE_PROGRAM_ERROR) { |
kadonotakashi | 0:8fdf9a60065b | 774 | DEBUG_PRINTF("DATAFLASH_BIT_ERASE_PROGRAM_ERROR\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 775 | } |
kadonotakashi | 0:8fdf9a60065b | 776 | |
kadonotakashi | 0:8fdf9a60065b | 777 | /* sector lockdown still possible */ |
kadonotakashi | 0:8fdf9a60065b | 778 | if (status & DATAFLASH_BIT_SECTOR_LOCKDOWN) { |
kadonotakashi | 0:8fdf9a60065b | 779 | DEBUG_PRINTF("DATAFLASH_BIT_SECTOR_LOCKDOWN\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 780 | } |
kadonotakashi | 0:8fdf9a60065b | 781 | |
kadonotakashi | 0:8fdf9a60065b | 782 | /* program operation suspended while using buffer 2 */ |
kadonotakashi | 0:8fdf9a60065b | 783 | if (status & DATAFLASH_BIT_PROGRAM_SUSPEND_2) { |
kadonotakashi | 0:8fdf9a60065b | 784 | DEBUG_PRINTF("DATAFLASH_BIT_PROGRAM_SUSPEND_2\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 785 | } |
kadonotakashi | 0:8fdf9a60065b | 786 | |
kadonotakashi | 0:8fdf9a60065b | 787 | /* program operation suspended while using buffer 1 */ |
kadonotakashi | 0:8fdf9a60065b | 788 | if (status & DATAFLASH_BIT_PROGRAM_SUSPEND_1) { |
kadonotakashi | 0:8fdf9a60065b | 789 | DEBUG_PRINTF("DATAFLASH_BIT_PROGRAM_SUSPEND_1\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 790 | } |
kadonotakashi | 0:8fdf9a60065b | 791 | |
kadonotakashi | 0:8fdf9a60065b | 792 | /* erase has been suspended */ |
kadonotakashi | 0:8fdf9a60065b | 793 | if (status & DATAFLASH_BIT_ERASE_SUSPEND) { |
kadonotakashi | 0:8fdf9a60065b | 794 | DEBUG_PRINTF("DATAFLASH_BIT_ERASE_SUSPEND\r\n"); |
kadonotakashi | 0:8fdf9a60065b | 795 | } |
kadonotakashi | 0:8fdf9a60065b | 796 | #endif |
kadonotakashi | 0:8fdf9a60065b | 797 | } |