|
| 1 | +// SPDX-FileCopyrightText: 2019 Ha Thach for Adafruit Industries |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +// The MIT License (MIT) |
| 6 | +// Copyright (c) 2019 Ha Thach for Adafruit Industries |
| 7 | + |
| 8 | +#include <SPI.h> |
| 9 | +#include <SdFat.h> |
| 10 | + |
| 11 | +#include <Adafruit_SPIFlash.h> |
| 12 | + |
| 13 | +#define CS_PIN 10 |
| 14 | + |
| 15 | +Adafruit_FlashTransport_SPI flashTransport(CS_PIN, SPI); |
| 16 | +Adafruit_SPIFlash flash(&flashTransport); |
| 17 | + |
| 18 | +/* If you want to use a specific flash device, for example for a custom built |
| 19 | + board, first look for it in Adafruit_SPIFlash\src\flash_devices.h |
| 20 | + * If it isn't in there you need to create your own definition like the |
| 21 | + W25Q80DLX_EXAMPLE example below. |
| 22 | + * These definitions need to be edited to match information on the data sheet |
| 23 | + of the flash device that you want to use. |
| 24 | + * If you are not sure what the manufacture ID, memory type and capacity values |
| 25 | + should be, try running the sketch anyway and look at the serial output |
| 26 | + * The flash device will report these values to you as a single hexadecimal |
| 27 | + value (the JDEC ID) |
| 28 | + * For example, the first device on the list - the W25Q80DLX - will report its |
| 29 | + JDEC ID as 0xef4014, which is made of these three values: |
| 30 | + * manufacturer_id = 0xef |
| 31 | + * memory_type = 0x40 |
| 32 | + * capacity = 0x14 |
| 33 | + * With this macro properly defined you can then create an array of device |
| 34 | + definitions as shown below, this can include any from the list of devices in |
| 35 | + flash_devices.h, and any you define yourself here |
| 36 | + * You need to update the variable on line 71 to reflect the number of items in |
| 37 | + the array |
| 38 | + * You also need to uncomment line 84 and comment out line 81 so this array |
| 39 | + will be passed to the flash memory driver. |
| 40 | + * |
| 41 | + * Example of a user defined flash memory device: |
| 42 | + #define W25Q80DLX_EXAMPLE \ |
| 43 | + { \ |
| 44 | + .total_size = 1*1024*1024, \ |
| 45 | + .start_up_time_us = 5000, .manufacturer_id = 0xef, \ |
| 46 | + .memory_type = 0x40, .capacity = 0x14, .max_clock_speed_mhz = 80, \ |
| 47 | + .quad_enable_bit_mask = 0x02, .has_sector_protection = false, \ |
| 48 | + .supports_fast_read = true, .supports_qspi = true, \ |
| 49 | + .supports_qspi_writes = false, .write_status_register_split = false, \ |
| 50 | + .single_status_byte = false, .is_fram = false, \ |
| 51 | + } |
| 52 | + */ |
| 53 | + |
| 54 | +/* |
| 55 | + * Create an array of data structures and fill it with the settings we defined |
| 56 | + * above. We are using two devices, but more can be added if you want. |
| 57 | + */ |
| 58 | +// static const SPIFlash_Device_t my_flash_devices[] = { |
| 59 | +// W25Q80DLX_EXAMPLE, |
| 60 | +// }; |
| 61 | +/* |
| 62 | + * Specify the number of different devices that are listed in the array we just |
| 63 | + * created. If you add more devices to the array, update this value to match. |
| 64 | + */ |
| 65 | +// const int flashDevices = 1; |
| 66 | + |
| 67 | +// the setup function runs once when you press reset or power the board |
| 68 | +void setup() { |
| 69 | + Serial.begin(115200); |
| 70 | + while (!Serial) { |
| 71 | + delay(100); // wait for native usb |
| 72 | + } |
| 73 | + |
| 74 | + Serial.println("Adafruit Serial Flash Info example"); |
| 75 | + flash.begin(); |
| 76 | + |
| 77 | + // Using a flash device not already listed? Start the flash memory by passing |
| 78 | + // it the array of device settings defined above, and the number of elements |
| 79 | + // in the array. |
| 80 | + |
| 81 | + // flash.begin(my_flash_devices, flashDevices); |
| 82 | + |
| 83 | + Serial.print("JEDEC ID: 0x"); |
| 84 | + Serial.println(flash.getJEDECID(), HEX); |
| 85 | + Serial.print("Flash size: "); |
| 86 | + Serial.print(flash.size() / 1024); |
| 87 | + Serial.println(" KB"); |
| 88 | +} |
| 89 | + |
| 90 | +void loop() { |
| 91 | + // nothing to do |
| 92 | +} |
0 commit comments