Compare commits
No commits in common. "gh-pages" and "master" have entirely different histories.
0
.codespell/exclude-file.txt
Normal file
6
.codespell/ignore-words.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
synopsys
|
||||||
|
sie
|
||||||
|
inout
|
||||||
|
busses
|
||||||
|
thre
|
||||||
|
|
||||||
10
.codespellrc
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# See: https://github.com/codespell-project/codespell#using-a-config-file
|
||||||
|
[codespell]
|
||||||
|
# In the event of a false positive, add the problematic word, in all lowercase, to 'ignore-words.txt' (one word per line).
|
||||||
|
# Or copy & paste the whole problematic line to 'exclude-file.txt'
|
||||||
|
ignore-words = .codespell/ignore-words.txt
|
||||||
|
exclude-file = .codespell/exclude-file.txt
|
||||||
|
check-filenames =
|
||||||
|
check-hidden =
|
||||||
|
count =
|
||||||
|
skip = .git
|
||||||
92
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
name: Bug Report
|
||||||
|
description: Report a problem
|
||||||
|
labels: 'Bug'
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
It's okay to leave some blank if it doesn't apply to your problem.
|
||||||
|
|
||||||
|
- type: dropdown
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
options:
|
||||||
|
- Linux
|
||||||
|
- MacOS
|
||||||
|
- RaspberryPi OS
|
||||||
|
- Windows 7
|
||||||
|
- Windows 10
|
||||||
|
- Windows 11
|
||||||
|
- Others
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: IDE version
|
||||||
|
placeholder: e.g Arduino 1.8.15
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Board
|
||||||
|
placeholder: e.g Feather nRF52840 Express
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: BSP version
|
||||||
|
description: Can be found under "Board Manager" menu
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: SPIFlash Library version
|
||||||
|
placeholder: "Release version or github latest"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Sketch as attached file if not stock example
|
||||||
|
placeholder: |
|
||||||
|
e.g examples/flash_info
|
||||||
|
If it is custom sketch, please provide links to your minimal sources or as attached files.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: What happened ?
|
||||||
|
placeholder: A clear and concise description of what the bug is.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: How to reproduce ?
|
||||||
|
placeholder: |
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. See error
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Debug Log as attached txt file
|
||||||
|
placeholder: |
|
||||||
|
Debug log where the issue occurred as attached txt file, best with comments to explain the actual events.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: If applicable, add screenshots to help explain your problem.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Adafruit Support Forum
|
||||||
|
url: https://forums.adafruit.com
|
||||||
|
about: If you have other questions or need help, post it here.
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: Feature
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
117
.github/workflows/githubci.yml
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on: [pull_request, push, repository_dispatch]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pre-commit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Run pre-commit
|
||||||
|
uses: pre-commit/action@v3.0.0
|
||||||
|
|
||||||
|
- name: Checkout adafruit/ci-arduino
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: adafruit/ci-arduino
|
||||||
|
path: ci
|
||||||
|
|
||||||
|
- name: pre-install
|
||||||
|
run: bash ci/actions_install.sh
|
||||||
|
|
||||||
|
# clang is already run as part of pre-commit
|
||||||
|
# - name: clang
|
||||||
|
# run: python3 ci/run-clang-format.py -r src/arduino
|
||||||
|
|
||||||
|
- name: doxygen
|
||||||
|
env:
|
||||||
|
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||||
|
PRETTYNAME : "Adafruit SPIFlash Library"
|
||||||
|
run: bash ci/doxy_gen_and_deploy.sh
|
||||||
|
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
arduino-platform:
|
||||||
|
- 'cpx_ada'
|
||||||
|
- 'feather_m0_express'
|
||||||
|
- 'metro_m0'
|
||||||
|
- 'feather_m4_express'
|
||||||
|
- 'metro_m4'
|
||||||
|
- 'grand_central'
|
||||||
|
- 'neotrellis_m4'
|
||||||
|
- 'pyportal'
|
||||||
|
- 'pyportal_titano'
|
||||||
|
- 'matrixportal'
|
||||||
|
- 'pybadge'
|
||||||
|
- 'metroesp32s2'
|
||||||
|
- 'nrf52840'
|
||||||
|
- 'cpb'
|
||||||
|
- 'clue'
|
||||||
|
- 'feather_rp2040'
|
||||||
|
- 'uno'
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Checkout adafruit/ci-arduino
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: adafruit/ci-arduino
|
||||||
|
path: ci
|
||||||
|
|
||||||
|
- name: pre-install
|
||||||
|
run: bash ci/actions_install.sh
|
||||||
|
|
||||||
|
- name: test platforms
|
||||||
|
run: python3 ci/build_platform.py ${{ matrix.arduino-platform }}
|
||||||
|
|
||||||
|
- name: Move build artifacts into place
|
||||||
|
run: |
|
||||||
|
mkdir build
|
||||||
|
find -name "*.uf2" -ls
|
||||||
|
for i in examples/*/build/*/*.uf2; do if [ -f $i ]; then j=${i##*/}; j=${j%%*.}; mv $i build/$j-${{ matrix.arduino-platform }}.uf2; fi done
|
||||||
|
|
||||||
|
- name: Upload build artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ github.event.repository.name }}.${{ github.sha }}.${{ matrix.arduino-platform }}
|
||||||
|
path: |
|
||||||
|
build/*.hex
|
||||||
|
build/*.bin
|
||||||
|
build/*.uf2
|
||||||
|
|
||||||
|
- name: Zip release files
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: |
|
||||||
|
if [ -d build ]; then
|
||||||
|
(
|
||||||
|
echo "Built from Adafruit SPIFlash Library `git describe --tags` for ${{ matrix.arduino-platform }}"
|
||||||
|
echo "Source code: https://github.com/adafruit/Adafruit_SPIFlash"
|
||||||
|
echo "Adafruit Learning System: https://learn.adafruit.com/"
|
||||||
|
) > build/README.txt
|
||||||
|
cd build && zip -9 -o ${{ matrix.arduino-platform }}.zip *.hex *.bin *.uf2 *.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: build/${{ matrix.arduino-platform }}.zip
|
||||||
|
fail_on_unmatched_files: false
|
||||||
|
body: "Select the zip file corresponding to your board from the list below."
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
|
|
||||||
26
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||||
|
rev: v15.0.7
|
||||||
|
hooks:
|
||||||
|
- id: clang-format
|
||||||
|
exclude: |
|
||||||
|
(?x)^(
|
||||||
|
examples/SdFat_format|
|
||||||
|
tools
|
||||||
|
)
|
||||||
|
types_or: [c++, c, header]
|
||||||
|
|
||||||
|
- repo: https://github.com/codespell-project/codespell
|
||||||
|
rev: v2.2.4
|
||||||
|
hooks:
|
||||||
|
- id: codespell
|
||||||
|
args: [-w]
|
||||||
|
exclude: |
|
||||||
|
(?x)^(
|
||||||
|
examples/SdFat_format/ff.c|
|
||||||
|
examples/SdFat_format/ff.h
|
||||||
|
)
|
||||||
7
LICENSE
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
Copyright 2017 Adafruit Industries, LLC
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
20
README.md
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Adafruit SPI Flash
|
||||||
|
|
||||||
|
[](https://github.com/adafruit/Adafruit_SPIFlash/actions) [](https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
Arduino library for external (Q)SPI flash device.
|
||||||
|
|
||||||
|
## Supported Cores
|
||||||
|
|
||||||
|
- [adafruit/Adafruit_nRF52_Arduino](https://github.com/adafruit/Adafruit_nRF52_Arduino)
|
||||||
|
- [adafruit/ArduinoCore-samd](https://github.com/adafruit/ArduinoCore-samd)
|
||||||
|
- [earlephilhower/arduino-pico](https://github.com/earlephilhower/arduino-pico)
|
||||||
|
- [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Support SPI interfaces for all cores
|
||||||
|
- Support QSPI interfaces for nRF52 and SAMD51
|
||||||
|
- Support FRAM flash devices
|
||||||
|
- Provide raw flash access APIs
|
||||||
|
- Implement block device APIs from SdFat's BaseBlockDRiver with caching to facilitate FAT filesystem on flash device
|
||||||
54
examples/SdFat_Flash_and_SDcard/SdFat_Flash_and_SDcard.ino
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
// Adafruit Grand Central M4 QSPI Flash and SD Card Setup Example
|
||||||
|
// Author: Joshua Scoggins
|
||||||
|
//
|
||||||
|
// This is an example of how to bring up both the QSPI Flash and SD Card found
|
||||||
|
// on the Adafruit Grand Central M4. This example will setup both the QSPI
|
||||||
|
// Flash and SD card (if present) and display information about the QSPI flash.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash onboardFlash(&flashTransport);
|
||||||
|
SdFat onboardSdCard;
|
||||||
|
|
||||||
|
constexpr int getSDCardPin() noexcept {
|
||||||
|
#ifdef SDCARD_SS_PIN
|
||||||
|
return SDCARD_SS_PIN;
|
||||||
|
#else
|
||||||
|
// modify to fit your needs
|
||||||
|
// by default, pin 4 is the SD_CS pin used by the Adafruit 1.8" TFT SD Shield
|
||||||
|
return 4;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
// wait for native usb
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.print("Starting up onboard QSPI Flash...");
|
||||||
|
onboardFlash.begin();
|
||||||
|
Serial.println("Done");
|
||||||
|
Serial.println("Onboard Flash information");
|
||||||
|
Serial.print("JEDEC ID: 0x");
|
||||||
|
Serial.println(onboardFlash.getJEDECID(), HEX);
|
||||||
|
Serial.print("Flash size: ");
|
||||||
|
Serial.print(onboardFlash.size() / 1024);
|
||||||
|
Serial.println(" KB");
|
||||||
|
Serial.print("Starting up SD Card...");
|
||||||
|
if (!onboardSdCard.begin(getSDCardPin())) {
|
||||||
|
Serial.println("No card found (is one inserted?)");
|
||||||
|
} else {
|
||||||
|
Serial.println("Card found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
82
examples/SdFat_Flash_and_SDcard/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
63
examples/SdFat_OpenNext/SdFat_OpenNext.ino
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Print size, modify date/time, and name for all files in root.
|
||||||
|
*/
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
|
||||||
|
#include "Adafruit_SPIFlash.h"
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system object from SdFat
|
||||||
|
FatVolume fatfs;
|
||||||
|
|
||||||
|
File32 root;
|
||||||
|
File32 file;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// Init external flash
|
||||||
|
flash.begin();
|
||||||
|
|
||||||
|
// Init file system on the flash
|
||||||
|
fatfs.begin(&flash);
|
||||||
|
|
||||||
|
// Wait for USB Serial
|
||||||
|
while (!Serial) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!root.open("/")) {
|
||||||
|
Serial.println("open root failed");
|
||||||
|
}
|
||||||
|
// Open next file in root.
|
||||||
|
// Warning, openNext starts at the current directory position
|
||||||
|
// so a rewind of the directory may be required.
|
||||||
|
while (file.openNext(&root, O_RDONLY)) {
|
||||||
|
file.printFileSize(&Serial);
|
||||||
|
Serial.write(' ');
|
||||||
|
file.printModifyDateTime(&Serial);
|
||||||
|
Serial.write(' ');
|
||||||
|
file.printName(&Serial);
|
||||||
|
if (file.isDir()) {
|
||||||
|
// Indicate a directory.
|
||||||
|
Serial.write('/');
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.getError()) {
|
||||||
|
Serial.println("openNext failed");
|
||||||
|
} else {
|
||||||
|
Serial.println("Done!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void loop() {}
|
||||||
82
examples/SdFat_OpenNext/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
95
examples/SdFat_ReadWrite/SdFat_ReadWrite.ino
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
SD card read/write
|
||||||
|
|
||||||
|
This example shows how to read and write data to and from an SD card file
|
||||||
|
The circuit:
|
||||||
|
* SD card attached to SPI bus as follows:
|
||||||
|
** MOSI - pin 11
|
||||||
|
** MISO - pin 12
|
||||||
|
** CLK - pin 13
|
||||||
|
|
||||||
|
created Nov 2010
|
||||||
|
by David A. Mellis
|
||||||
|
modified 9 Apr 2012
|
||||||
|
by Tom Igoe
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
|
||||||
|
#include "Adafruit_SPIFlash.h"
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system object from SdFat
|
||||||
|
FatVolume fatfs;
|
||||||
|
File32 myFile;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Open serial communications and wait for port to open:
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(
|
||||||
|
10); // wait for serial port to connect. Needed for native USB port only
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Initializing Filesystem on external flash...");
|
||||||
|
|
||||||
|
// Init external flash
|
||||||
|
flash.begin();
|
||||||
|
|
||||||
|
// Open file system on the flash
|
||||||
|
if (!fatfs.begin(&flash)) {
|
||||||
|
Serial.println("Error: filesystem is not existed. Please try SdFat_format "
|
||||||
|
"example to make one.");
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("initialization done.");
|
||||||
|
|
||||||
|
// open the file. note that only one file can be open at a time,
|
||||||
|
// so you have to close this one before opening another.
|
||||||
|
myFile = fatfs.open("test.txt", FILE_WRITE);
|
||||||
|
|
||||||
|
// if the file opened okay, write to it:
|
||||||
|
if (myFile) {
|
||||||
|
Serial.print("Writing to test.txt...");
|
||||||
|
myFile.println("testing 1, 2, 3.");
|
||||||
|
// close the file:
|
||||||
|
myFile.close();
|
||||||
|
Serial.println("done.");
|
||||||
|
} else {
|
||||||
|
// if the file didn't open, print an error:
|
||||||
|
Serial.println("error opening test.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-open the file for reading:
|
||||||
|
myFile = fatfs.open("test.txt");
|
||||||
|
if (myFile) {
|
||||||
|
Serial.println("test.txt:");
|
||||||
|
|
||||||
|
// read from the file until there's nothing else in it:
|
||||||
|
while (myFile.available()) {
|
||||||
|
Serial.write(myFile.read());
|
||||||
|
}
|
||||||
|
// close the file:
|
||||||
|
myFile.close();
|
||||||
|
} else {
|
||||||
|
// if the file didn't open, print an error:
|
||||||
|
Serial.println("error opening test.txt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// nothing happens after setup
|
||||||
|
}
|
||||||
82
examples/SdFat_ReadWrite/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
115
examples/SdFat_circuitpython/SdFat_circuitpython.ino
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
// Adafruit M0 Express CircuitPython Flash Example
|
||||||
|
// Author: Tony DiCola
|
||||||
|
//
|
||||||
|
// This is an example of reading and writing data from Arduino
|
||||||
|
// to the M0 Express flash filesystem used by CircuitPython.
|
||||||
|
// You can create, update, and read files on the CircuitPython
|
||||||
|
// filesystem in an Arduino sketch and then later load CircuitPython
|
||||||
|
// to interact with the same files. This example will print out
|
||||||
|
// the contents of boot.py and main.py (if found) and add a line
|
||||||
|
// to a data.txt file on CircuitPython's filesystem.
|
||||||
|
//
|
||||||
|
// Note before you use this sketch you must load CircuitPython
|
||||||
|
// on your M0 Express. This will create the filesystem and
|
||||||
|
// initialize it, then you can load this example and read/write
|
||||||
|
// files on the board.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// - Modify the pins and type of fatfs object in the config
|
||||||
|
// section below if necessary (usually not necessary).
|
||||||
|
// - Upload this sketch to your M0 express board.
|
||||||
|
// - Open the serial monitor at 115200 baud. You should see the
|
||||||
|
// example start to run and messages printed to the monitor.
|
||||||
|
// If you don't see anything close the serial monitor, press
|
||||||
|
// the board reset button, wait a few seconds, then open the
|
||||||
|
// serial monitor again.
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system object from SdFat
|
||||||
|
FatVolume fatfs;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port and wait for it to open before continuing.
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.println("Adafruit SPIFlash CircuitPython Example");
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
Serial.println("Error, failed to initialize flash chip!");
|
||||||
|
while (1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.print("Flash chip JEDEC ID: 0x");
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
|
||||||
|
// First call begin to mount the filesystem. Check that it returns true
|
||||||
|
// to make sure the filesystem was mounted.
|
||||||
|
if (!fatfs.begin(&flash)) {
|
||||||
|
Serial.println("Failed to mount filesystem!");
|
||||||
|
Serial.println("Was CircuitPython loaded on the board first to create the "
|
||||||
|
"filesystem?");
|
||||||
|
while (1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println("Mounted filesystem!");
|
||||||
|
|
||||||
|
// Check if a boot.py exists and print it out.
|
||||||
|
if (fatfs.exists("boot.py")) {
|
||||||
|
File32 bootPy = fatfs.open("boot.py", FILE_READ);
|
||||||
|
Serial.println("Printing boot.py...");
|
||||||
|
while (bootPy.available()) {
|
||||||
|
char c = bootPy.read();
|
||||||
|
Serial.print(c);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
} else {
|
||||||
|
Serial.println("No boot.py found...");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a main.py exists and print it out:
|
||||||
|
if (fatfs.exists("code.py")) {
|
||||||
|
File32 mainPy = fatfs.open("code.py", FILE_READ);
|
||||||
|
Serial.println("Printing code.py...");
|
||||||
|
while (mainPy.available()) {
|
||||||
|
char c = mainPy.read();
|
||||||
|
Serial.print(c);
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
} else {
|
||||||
|
Serial.println("No code.py found...");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create or append to a data.txt file and add a new line
|
||||||
|
// to the end of it. CircuitPython code can later open and
|
||||||
|
// see this file too!
|
||||||
|
File32 data = fatfs.open("data.txt", FILE_WRITE);
|
||||||
|
if (data) {
|
||||||
|
// Write a new line to the file:
|
||||||
|
data.println("Hello CircuitPython from Arduino!");
|
||||||
|
data.close();
|
||||||
|
// See the other fatfs examples like fatfs_full_usage and fatfs_datalogging
|
||||||
|
// for more examples of interacting with files.
|
||||||
|
Serial.println("Wrote a new line to the end of data.txt!");
|
||||||
|
} else {
|
||||||
|
Serial.println("Error, failed to open data file for writing!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Finished!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Nothing to do in the loop.
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
82
examples/SdFat_circuitpython/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,162 @@
|
||||||
|
// Adafruit M0 Express CircuitPython Repair
|
||||||
|
// Author: Limor Fried
|
||||||
|
//
|
||||||
|
/*
|
||||||
|
* This script can be useful if you seriously bork up your CircuitPython
|
||||||
|
* install. It will find any files named main.py, boot.py, main.txt, code.py
|
||||||
|
* or code.txt and move them to backup files. its a tad slow but then you
|
||||||
|
* can reload circuitpython safely. This example right now is only for
|
||||||
|
* the Metro M0 Express & Circuit Playground M0 but i have a...
|
||||||
|
*
|
||||||
|
* TODO: automagically detect if it's Feather/Metro/CircuitPlayground!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system object from SdFat
|
||||||
|
FatVolume fatfs;
|
||||||
|
|
||||||
|
#define NEOPIN 40 // neopixel pin
|
||||||
|
#define BUFFERSIZ 200
|
||||||
|
|
||||||
|
Adafruit_NeoPixel pixel = Adafruit_NeoPixel(1, NEOPIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
// while (!Serial);
|
||||||
|
delay(1000); // small delay in case we want to watch it on the serial port
|
||||||
|
Serial.println("Adafruit Express CircuitPython Flash Repair");
|
||||||
|
|
||||||
|
pixel.begin(); // This initializes the NeoPixel library
|
||||||
|
pixel.setBrightness(30); // not too bright!
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
Serial.println("Error, failed to initialize flash chip!");
|
||||||
|
error(1);
|
||||||
|
}
|
||||||
|
Serial.print("Flash chip JEDEC ID: 0x");
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
|
||||||
|
// First call begin to mount the filesystem. Check that it returns true
|
||||||
|
// to make sure the filesystem was mounted.
|
||||||
|
if (!fatfs.begin(&flash)) {
|
||||||
|
Serial.println("Failed to mount filesystem!");
|
||||||
|
Serial.println("Was CircuitPython loaded on the board first to create the "
|
||||||
|
"filesystem?");
|
||||||
|
error(3);
|
||||||
|
}
|
||||||
|
Serial.println("Mounted filesystem!");
|
||||||
|
|
||||||
|
moveFile("boot.py", "bootpy.bak");
|
||||||
|
moveFile("main.py", "mainpy.bak");
|
||||||
|
moveFile("main.txt", "maintxt.bak");
|
||||||
|
moveFile("code.py", "codepy.bak");
|
||||||
|
moveFile("code.txt", "codetxt.bak");
|
||||||
|
|
||||||
|
Serial.println("Finished!");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t i = 0;
|
||||||
|
void loop() {
|
||||||
|
// white pixel pulse -> we're done
|
||||||
|
pixel.setPixelColor(0, pixel.Color(i, i, i));
|
||||||
|
pixel.show();
|
||||||
|
i++;
|
||||||
|
delay(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean moveFile(const char *file, const char *dest) {
|
||||||
|
if (!fatfs.exists(file)) {
|
||||||
|
Serial.print(file);
|
||||||
|
Serial.println(" not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (fatfs.exists(dest)) {
|
||||||
|
Serial.println("Found old backup, removing...");
|
||||||
|
if (!fatfs.remove(dest)) {
|
||||||
|
Serial.println("Error, couldn't delete ");
|
||||||
|
Serial.print(dest);
|
||||||
|
Serial.println(" file!");
|
||||||
|
error(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel.setPixelColor(0, pixel.Color(100, 100, 0));
|
||||||
|
pixel.show();
|
||||||
|
|
||||||
|
File32 source = fatfs.open(file, FILE_READ);
|
||||||
|
File32 backup = fatfs.open(dest, FILE_WRITE);
|
||||||
|
Serial.println("Making backup!");
|
||||||
|
Serial.println("\n---------------------\n");
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int avail = source.available();
|
||||||
|
// Serial.print("**Available bytes: "); Serial.print(avail);
|
||||||
|
// Serial.print("**");
|
||||||
|
if (avail == 0) {
|
||||||
|
Serial.println("\n---------------------\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int toread = min(BUFFERSIZ - 1, avail);
|
||||||
|
char buffer[BUFFERSIZ];
|
||||||
|
|
||||||
|
int numread = source.read(buffer, toread);
|
||||||
|
if (numread != toread) {
|
||||||
|
Serial.print("Failed to read ");
|
||||||
|
Serial.print(toread);
|
||||||
|
Serial.print(" bytes, got ");
|
||||||
|
Serial.print(numread);
|
||||||
|
error(5);
|
||||||
|
}
|
||||||
|
buffer[toread] = 0;
|
||||||
|
Serial.print(buffer);
|
||||||
|
if ((int)backup.write(buffer, toread) != toread) {
|
||||||
|
Serial.println("Error, couldn't write data to backup file!");
|
||||||
|
error(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel.setPixelColor(0, pixel.Color(100, 0, 100));
|
||||||
|
pixel.show();
|
||||||
|
|
||||||
|
Serial.print("Original file size: ");
|
||||||
|
Serial.println(source.size());
|
||||||
|
Serial.print("Backup file size: ");
|
||||||
|
Serial.println(backup.size());
|
||||||
|
backup.close();
|
||||||
|
if (source.size() == backup.size()) {
|
||||||
|
if (!fatfs.remove(file)) {
|
||||||
|
Serial.print("Error, couldn't delete ");
|
||||||
|
Serial.println(file);
|
||||||
|
error(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pixel.setPixelColor(0, pixel.Color(0, 100, 0));
|
||||||
|
pixel.show();
|
||||||
|
delay(100);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void error(uint8_t i) {
|
||||||
|
while (1) {
|
||||||
|
for (int x = 0; x < i; x++) {
|
||||||
|
pixel.setPixelColor(0, pixel.Color(100, 0, 0));
|
||||||
|
pixel.show();
|
||||||
|
delay(200);
|
||||||
|
pixel.setPixelColor(0, pixel.Color(0, 0, 0));
|
||||||
|
pixel.show();
|
||||||
|
delay(200);
|
||||||
|
}
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
examples/SdFat_circuitpython_backupFiles/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
95
examples/SdFat_datalogging/SdFat_datalogging.ino
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
// Adafruit SPI Flash FatFs Simple Datalogging Example
|
||||||
|
// Author: Tony DiCola
|
||||||
|
//
|
||||||
|
// This is a simple dataloging example using the SPI Flash
|
||||||
|
// FatFs library. The example will open a file on the SPI
|
||||||
|
// flash and append new lines of data every minute. Note that
|
||||||
|
// you MUST have a flash chip that's formatted with a flash
|
||||||
|
// filesystem before running. See the fatfs_format example
|
||||||
|
// to perform this formatting.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// - Modify the pins and type of fatfs object in the config
|
||||||
|
// section below if necessary (usually not necessary).
|
||||||
|
// - Upload this sketch to your M0 express board.
|
||||||
|
// - Open the serial monitor at 115200 baud. You should see the
|
||||||
|
// example print a message every minute when it writes a new
|
||||||
|
// value to the data logging file.
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system object from SdFat
|
||||||
|
FatVolume fatfs;
|
||||||
|
|
||||||
|
// Configuration for the datalogging file:
|
||||||
|
#define FILE_NAME "data.csv"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port and wait for it to open before continuing.
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.println("Adafruit SPI Flash FatFs Simple Datalogging Example");
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
Serial.println("Error, failed to initialize flash chip!");
|
||||||
|
while (1) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.print("Flash chip JEDEC ID: 0x");
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
|
||||||
|
// First call begin to mount the filesystem. Check that it returns true
|
||||||
|
// to make sure the filesystem was mounted.
|
||||||
|
if (!fatfs.begin(&flash)) {
|
||||||
|
Serial.println("Error, failed to mount newly formatted filesystem!");
|
||||||
|
Serial.println(
|
||||||
|
"Was the flash chip formatted with the fatfs_format example?");
|
||||||
|
while (1) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println("Mounted filesystem!");
|
||||||
|
|
||||||
|
Serial.println("Logging data every 60 seconds...");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Open the datalogging file for writing. The FILE_WRITE mode will open
|
||||||
|
// the file for appending, i.e. it will add new data to the end of the file.
|
||||||
|
File32 dataFile = fatfs.open(FILE_NAME, FILE_WRITE);
|
||||||
|
// Check that the file opened successfully and write a line to it.
|
||||||
|
if (dataFile) {
|
||||||
|
// Take a new data reading from a sensor, etc. For this example just
|
||||||
|
// make up a random number.
|
||||||
|
int reading = random(0, 100);
|
||||||
|
// Write a line to the file. You can use all the same print functions
|
||||||
|
// as if you're writing to the serial monitor. For example to write
|
||||||
|
// two CSV (commas separated) values:
|
||||||
|
dataFile.print("Sensor #1");
|
||||||
|
dataFile.print(",");
|
||||||
|
dataFile.print(reading, DEC);
|
||||||
|
dataFile.println();
|
||||||
|
// Finally close the file when done writing. This is smart to do to make
|
||||||
|
// sure all the data is written to the file.
|
||||||
|
dataFile.close();
|
||||||
|
Serial.println("Wrote new measurement to data file!");
|
||||||
|
} else {
|
||||||
|
Serial.println("Failed to open data file for writing!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Trying again in 60 seconds...");
|
||||||
|
|
||||||
|
// Wait 60 seconds.
|
||||||
|
delay(60000L);
|
||||||
|
}
|
||||||
82
examples/SdFat_datalogging/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
210
examples/SdFat_format/SdFat_format.ino
Normal file
|
|
@ -0,0 +1,210 @@
|
||||||
|
// Adafruit SPI Flash FatFs Format Example
|
||||||
|
// Author: Tony DiCola
|
||||||
|
//
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// !! NOTE: YOU WILL ERASE ALL DATA BY RUNNING THIS SKETCH! !!
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// - Modify the pins and type of fatfs object in the config
|
||||||
|
// section below if necessary (usually not necessary).
|
||||||
|
// - Upload this sketch to your M0 express board.
|
||||||
|
// - Open the serial monitor at 115200 baud. You should see a
|
||||||
|
// prompt to confirm formatting. If you don't see the prompt
|
||||||
|
// close the serial monitor, press the board reset button,
|
||||||
|
// wait a few seconds, then open the serial monitor again.
|
||||||
|
// - Type OK and enter to confirm the format when prompted.
|
||||||
|
// - Partitioning and formatting will take about 30-60 seconds.
|
||||||
|
// Once formatted a message will be printed to notify you that
|
||||||
|
// it is finished.
|
||||||
|
//
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
// Since SdFat doesn't fully support FAT12 such as format a new flash
|
||||||
|
// We will use Elm Cham's fatfs f_mkfs() to format
|
||||||
|
#include "ff.h"
|
||||||
|
#include "diskio.h"
|
||||||
|
|
||||||
|
// up to 11 characters
|
||||||
|
#define DISK_LABEL "EXT FLASH"
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
FatVolume fatfs;
|
||||||
|
|
||||||
|
void format_fat12(void) {
|
||||||
|
// Working buffer for f_mkfs.
|
||||||
|
#ifdef __AVR__
|
||||||
|
uint8_t workbuf[512];
|
||||||
|
#else
|
||||||
|
uint8_t workbuf[4096];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Elm Cham's fatfs objects
|
||||||
|
FATFS elmchamFatfs;
|
||||||
|
|
||||||
|
// Make filesystem.
|
||||||
|
FRESULT r = f_mkfs("", FM_FAT, 0, workbuf, sizeof(workbuf));
|
||||||
|
if (r != FR_OK) {
|
||||||
|
Serial.print(F("Error, f_mkfs failed with error code: "));
|
||||||
|
Serial.println(r, DEC);
|
||||||
|
while (1)
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
// mount to set disk label
|
||||||
|
r = f_mount(&elmchamFatfs, "0:", 1);
|
||||||
|
if (r != FR_OK) {
|
||||||
|
Serial.print(F("Error, f_mount failed with error code: "));
|
||||||
|
Serial.println(r, DEC);
|
||||||
|
while (1)
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting label
|
||||||
|
Serial.println(F("Setting disk label to: " DISK_LABEL));
|
||||||
|
r = f_setlabel(DISK_LABEL);
|
||||||
|
if (r != FR_OK) {
|
||||||
|
Serial.print(F("Error, f_setlabel failed with error code: "));
|
||||||
|
Serial.println(r, DEC);
|
||||||
|
while (1)
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
// unmount
|
||||||
|
f_unmount("0:");
|
||||||
|
|
||||||
|
// sync to make sure all data is written to flash
|
||||||
|
flash.syncBlocks();
|
||||||
|
|
||||||
|
Serial.println(F("Formatted flash!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void check_fat12(void) {
|
||||||
|
// Check new filesystem
|
||||||
|
if (!fatfs.begin(&flash)) {
|
||||||
|
Serial.println(F("Error, failed to mount newly formatted filesystem!"));
|
||||||
|
while (1)
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port and wait for it to open before continuing.
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial)
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
Serial.println(F("Adafruit SPI Flash FatFs Format Example"));
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
Serial.println(F("Error, failed to initialize flash chip!"));
|
||||||
|
while (1)
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print(F("Flash chip JEDEC ID: 0x"));
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
Serial.print(F("Flash size: "));
|
||||||
|
Serial.print(flash.size() / 1024);
|
||||||
|
Serial.println(F(" KB"));
|
||||||
|
|
||||||
|
// Uncomment to flash LED while writing to flash
|
||||||
|
// flash.setIndicator(LED_BUILTIN, true);
|
||||||
|
|
||||||
|
// Wait for user to send OK to continue.
|
||||||
|
Serial.setTimeout(
|
||||||
|
30000); // Increase timeout to print message less frequently.
|
||||||
|
do {
|
||||||
|
Serial.println(F("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
"!!!!!!!!!!!!"));
|
||||||
|
Serial.println(F("This sketch will ERASE ALL DATA on the flash chip and "
|
||||||
|
"format it with a new filesystem!"));
|
||||||
|
Serial.println(F("Type OK (all caps) and press enter to continue."));
|
||||||
|
Serial.println(F("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
"!!!!!!!!!!!!"));
|
||||||
|
} while (!Serial.find((char *)"OK"));
|
||||||
|
|
||||||
|
// Call fatfs begin and passed flash object to initialize file system
|
||||||
|
Serial.println(
|
||||||
|
F("Creating and formatting FAT filesystem (this takes ~60 seconds)..."));
|
||||||
|
|
||||||
|
format_fat12();
|
||||||
|
|
||||||
|
check_fat12();
|
||||||
|
|
||||||
|
// Done!
|
||||||
|
Serial.println(
|
||||||
|
F("Flash chip successfully formatted with new empty filesystem!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Nothing to be done in the main loop.
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// fatfs diskio
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
DSTATUS disk_status(BYTE pdrv) {
|
||||||
|
(void)pdrv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DSTATUS disk_initialize(BYTE pdrv) {
|
||||||
|
(void)pdrv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DRESULT disk_read(BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||||
|
BYTE *buff, /* Data buffer to store read data */
|
||||||
|
DWORD sector, /* Start sector in LBA */
|
||||||
|
UINT count /* Number of sectors to read */
|
||||||
|
) {
|
||||||
|
(void)pdrv;
|
||||||
|
return flash.readBlocks(sector, buff, count) ? RES_OK : RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
DRESULT disk_write(BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||||
|
const BYTE *buff, /* Data to be written */
|
||||||
|
DWORD sector, /* Start sector in LBA */
|
||||||
|
UINT count /* Number of sectors to write */
|
||||||
|
) {
|
||||||
|
(void)pdrv;
|
||||||
|
return flash.writeBlocks(sector, buff, count) ? RES_OK : RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
DRESULT disk_ioctl(BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||||
|
BYTE cmd, /* Control code */
|
||||||
|
void *buff /* Buffer to send/receive control data */
|
||||||
|
) {
|
||||||
|
(void)pdrv;
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case CTRL_SYNC:
|
||||||
|
flash.syncBlocks();
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
|
case GET_SECTOR_COUNT:
|
||||||
|
*((DWORD *)buff) = flash.size() / 512;
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
|
case GET_SECTOR_SIZE:
|
||||||
|
*((WORD *)buff) = 512;
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
|
case GET_BLOCK_SIZE:
|
||||||
|
*((DWORD *)buff) = 8; // erase block size in units of sector size
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return RES_PARERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
77
examples/SdFat_format/diskio.h
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*-----------------------------------------------------------------------/
|
||||||
|
/ Low level disk interface module include file (C)ChaN, 2014 /
|
||||||
|
/-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef _DISKIO_DEFINED
|
||||||
|
#define _DISKIO_DEFINED
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Status of Disk Functions */
|
||||||
|
typedef BYTE DSTATUS;
|
||||||
|
|
||||||
|
/* Results of Disk Functions */
|
||||||
|
typedef enum {
|
||||||
|
RES_OK = 0, /* 0: Successful */
|
||||||
|
RES_ERROR, /* 1: R/W Error */
|
||||||
|
RES_WRPRT, /* 2: Write Protected */
|
||||||
|
RES_NOTRDY, /* 3: Not Ready */
|
||||||
|
RES_PARERR /* 4: Invalid Parameter */
|
||||||
|
} DRESULT;
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------*/
|
||||||
|
/* Prototypes for disk control functions */
|
||||||
|
|
||||||
|
|
||||||
|
DSTATUS disk_initialize (BYTE pdrv);
|
||||||
|
DSTATUS disk_status (BYTE pdrv);
|
||||||
|
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||||
|
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||||
|
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||||
|
|
||||||
|
|
||||||
|
/* Disk Status Bits (DSTATUS) */
|
||||||
|
|
||||||
|
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||||
|
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||||
|
#define STA_PROTECT 0x04 /* Write protected */
|
||||||
|
|
||||||
|
|
||||||
|
/* Command code for disk_ioctrl function */
|
||||||
|
|
||||||
|
/* Generic command (Used by FatFs) */
|
||||||
|
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
|
||||||
|
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
|
||||||
|
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||||
|
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||||
|
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||||
|
|
||||||
|
/* Generic command (Not used by FatFs) */
|
||||||
|
#define CTRL_POWER 5 /* Get/Set power status */
|
||||||
|
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||||
|
#define CTRL_EJECT 7 /* Eject media */
|
||||||
|
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||||
|
|
||||||
|
/* MMC/SDC specific ioctl command */
|
||||||
|
#define MMC_GET_TYPE 10 /* Get card type */
|
||||||
|
#define MMC_GET_CSD 11 /* Get CSD */
|
||||||
|
#define MMC_GET_CID 12 /* Get CID */
|
||||||
|
#define MMC_GET_OCR 13 /* Get OCR */
|
||||||
|
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||||
|
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
|
||||||
|
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
|
||||||
|
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
|
||||||
|
|
||||||
|
/* ATA/CF specific ioctl command */
|
||||||
|
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||||
|
#define ATA_GET_MODEL 21 /* Get model name */
|
||||||
|
#define ATA_GET_SN 22 /* Get serial number */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
6554
examples/SdFat_format/ff.c
Normal file
405
examples/SdFat_format/ff.h
Normal file
|
|
@ -0,0 +1,405 @@
|
||||||
|
/*----------------------------------------------------------------------------/
|
||||||
|
/ FatFs - Generic FAT Filesystem module R0.13c /
|
||||||
|
/-----------------------------------------------------------------------------/
|
||||||
|
/
|
||||||
|
/ Copyright (C) 2018, ChaN, all right reserved.
|
||||||
|
/
|
||||||
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||||
|
/ source and binary forms, with or without modification, are permitted provided
|
||||||
|
/ that the following condition is met:
|
||||||
|
|
||||||
|
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
/ this condition and the following disclaimer.
|
||||||
|
/
|
||||||
|
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||||
|
/ and any warranties related to this software are DISCLAIMED.
|
||||||
|
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||||
|
/ by use of this software.
|
||||||
|
/
|
||||||
|
/----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FF_DEFINED
|
||||||
|
#define FF_DEFINED 86604 /* Revision ID */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ffconf.h" /* FatFs configuration options */
|
||||||
|
|
||||||
|
#if FF_DEFINED != FFCONF_DEF
|
||||||
|
#error Wrong configuration file (ffconf.h).
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Integer types used for FatFs API */
|
||||||
|
|
||||||
|
#if defined(_WIN32) /* Main development platform */
|
||||||
|
#define FF_INTDEF 2
|
||||||
|
#include <windows.h>
|
||||||
|
typedef unsigned __int64 QWORD;
|
||||||
|
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
||||||
|
#define FF_INTDEF 2
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||||
|
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||||
|
typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||||
|
typedef uint16_t WCHAR; /* 16-bit unsigned integer */
|
||||||
|
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||||
|
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||||
|
#else /* Earlier than C99 */
|
||||||
|
#define FF_INTDEF 1
|
||||||
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||||
|
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||||
|
typedef unsigned short WORD; /* 16-bit unsigned integer */
|
||||||
|
typedef unsigned short WCHAR; /* 16-bit unsigned integer */
|
||||||
|
typedef unsigned long DWORD; /* 32-bit unsigned integer */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Definitions of volume management */
|
||||||
|
|
||||||
|
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||||
|
typedef struct {
|
||||||
|
BYTE pd; /* Physical drive number */
|
||||||
|
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||||
|
} PARTITION;
|
||||||
|
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FF_STR_VOLUME_ID
|
||||||
|
#ifndef FF_VOLUME_STRS
|
||||||
|
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Type of path name strings on FatFs API */
|
||||||
|
|
||||||
|
#ifndef _INC_TCHAR
|
||||||
|
#define _INC_TCHAR
|
||||||
|
|
||||||
|
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
||||||
|
typedef WCHAR TCHAR;
|
||||||
|
#define _T(x) L ## x
|
||||||
|
#define _TEXT(x) L ## x
|
||||||
|
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
|
||||||
|
typedef char TCHAR;
|
||||||
|
#define _T(x) u8 ## x
|
||||||
|
#define _TEXT(x) u8 ## x
|
||||||
|
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
|
||||||
|
typedef DWORD TCHAR;
|
||||||
|
#define _T(x) U ## x
|
||||||
|
#define _TEXT(x) U ## x
|
||||||
|
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
|
||||||
|
#error Wrong FF_LFN_UNICODE setting
|
||||||
|
#else /* ANSI/OEM code in SBCS/DBCS */
|
||||||
|
typedef char TCHAR;
|
||||||
|
#define _T(x) x
|
||||||
|
#define _TEXT(x) x
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Type of file size variables */
|
||||||
|
|
||||||
|
#if FF_FS_EXFAT
|
||||||
|
#if FF_INTDEF != 2
|
||||||
|
#error exFAT feature wants C99 or later
|
||||||
|
#endif
|
||||||
|
typedef QWORD FSIZE_t;
|
||||||
|
#else
|
||||||
|
typedef DWORD FSIZE_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Filesystem object structure (FATFS) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||||
|
BYTE pdrv; /* Associated physical drive */
|
||||||
|
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||||
|
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||||
|
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||||
|
WORD id; /* Volume mount ID */
|
||||||
|
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||||
|
WORD csize; /* Cluster size [sectors] */
|
||||||
|
#if FF_MAX_SS != FF_MIN_SS
|
||||||
|
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||||
|
#endif
|
||||||
|
#if FF_USE_LFN
|
||||||
|
WCHAR* lfnbuf; /* LFN working buffer */
|
||||||
|
#endif
|
||||||
|
#if FF_FS_EXFAT
|
||||||
|
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
||||||
|
#endif
|
||||||
|
#if FF_FS_REENTRANT
|
||||||
|
FF_SYNC_t sobj; /* Identifier of sync object */
|
||||||
|
#endif
|
||||||
|
#if !FF_FS_READONLY
|
||||||
|
DWORD last_clst; /* Last allocated cluster */
|
||||||
|
DWORD free_clst; /* Number of free clusters */
|
||||||
|
#endif
|
||||||
|
#if FF_FS_RPATH
|
||||||
|
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||||
|
#if FF_FS_EXFAT
|
||||||
|
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
|
||||||
|
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
|
||||||
|
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||||
|
DWORD fsize; /* Size of an FAT [sectors] */
|
||||||
|
DWORD volbase; /* Volume base sector */
|
||||||
|
DWORD fatbase; /* FAT base sector */
|
||||||
|
DWORD dirbase; /* Root directory base sector/cluster */
|
||||||
|
DWORD database; /* Data base sector */
|
||||||
|
#if FF_FS_EXFAT
|
||||||
|
DWORD bitbase; /* Allocation bitmap base sector */
|
||||||
|
#endif
|
||||||
|
DWORD winsect; /* Current sector appearing in the win[] */
|
||||||
|
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||||
|
} FATFS;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Object ID and allocation information (FFOBJID) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FATFS* fs; /* Pointer to the hosting volume of this object */
|
||||||
|
WORD id; /* Hosting volume mount ID */
|
||||||
|
BYTE attr; /* Object attribute */
|
||||||
|
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
||||||
|
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
||||||
|
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
||||||
|
#if FF_FS_EXFAT
|
||||||
|
DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
|
||||||
|
DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
|
||||||
|
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
|
||||||
|
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
|
||||||
|
DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
|
||||||
|
#endif
|
||||||
|
#if FF_FS_LOCK
|
||||||
|
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||||
|
#endif
|
||||||
|
} FFOBJID;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* File object structure (FIL) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
|
||||||
|
BYTE flag; /* File status flags */
|
||||||
|
BYTE err; /* Abort flag (error code) */
|
||||||
|
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||||
|
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||||
|
DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||||
|
#if !FF_FS_READONLY
|
||||||
|
DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||||
|
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||||
|
#endif
|
||||||
|
#if FF_USE_FASTSEEK
|
||||||
|
DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
|
||||||
|
#endif
|
||||||
|
#if !FF_FS_TINY
|
||||||
|
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
|
||||||
|
#endif
|
||||||
|
} FIL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Directory object structure (DIR) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FFOBJID obj; /* Object identifier */
|
||||||
|
DWORD dptr; /* Current read/write offset */
|
||||||
|
DWORD clust; /* Current cluster */
|
||||||
|
DWORD sect; /* Current sector (0:Read operation has terminated) */
|
||||||
|
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||||
|
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||||
|
#if FF_USE_LFN
|
||||||
|
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
|
||||||
|
#endif
|
||||||
|
#if FF_USE_FIND
|
||||||
|
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||||
|
#endif
|
||||||
|
} DIR;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* File information structure (FILINFO) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FSIZE_t fsize; /* File size */
|
||||||
|
WORD fdate; /* Modified date */
|
||||||
|
WORD ftime; /* Modified time */
|
||||||
|
BYTE fattrib; /* File attribute */
|
||||||
|
#if FF_USE_LFN
|
||||||
|
TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
|
||||||
|
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
||||||
|
#else
|
||||||
|
TCHAR fname[12 + 1]; /* File name */
|
||||||
|
#endif
|
||||||
|
} FILINFO;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* File function return code (FRESULT) */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
FR_OK = 0, /* (0) Succeeded */
|
||||||
|
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||||
|
FR_INT_ERR, /* (2) Assertion failed */
|
||||||
|
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||||
|
FR_NO_FILE, /* (4) Could not find the file */
|
||||||
|
FR_NO_PATH, /* (5) Could not find the path */
|
||||||
|
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||||
|
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||||
|
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||||
|
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||||
|
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||||
|
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||||
|
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||||
|
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||||
|
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
||||||
|
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||||
|
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||||
|
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||||
|
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
||||||
|
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||||
|
} FRESULT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------*/
|
||||||
|
/* FatFs module application interface */
|
||||||
|
|
||||||
|
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||||
|
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||||
|
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
||||||
|
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
||||||
|
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||||
|
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||||
|
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||||
|
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||||
|
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||||
|
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||||
|
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||||
|
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
|
||||||
|
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||||
|
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||||
|
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||||
|
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||||
|
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||||
|
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||||
|
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||||
|
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||||
|
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||||
|
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||||
|
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||||
|
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||||
|
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||||
|
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
|
||||||
|
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||||
|
FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */
|
||||||
|
FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */
|
||||||
|
FRESULT f_setcp (WORD cp); /* Set current code page */
|
||||||
|
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||||
|
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||||
|
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||||
|
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||||
|
|
||||||
|
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
||||||
|
#define f_error(fp) ((fp)->err)
|
||||||
|
#define f_tell(fp) ((fp)->fptr)
|
||||||
|
#define f_size(fp) ((fp)->obj.objsize)
|
||||||
|
#define f_rewind(fp) f_lseek((fp), 0)
|
||||||
|
#define f_rewinddir(dp) f_readdir((dp), 0)
|
||||||
|
#define f_rmdir(path) f_unlink(path)
|
||||||
|
#define f_unmount(path) f_mount(0, path, 0)
|
||||||
|
|
||||||
|
#ifndef EOF
|
||||||
|
#define EOF (-1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------*/
|
||||||
|
/* Additional user defined functions */
|
||||||
|
|
||||||
|
/* RTC function */
|
||||||
|
#if !FF_FS_READONLY && !FF_FS_NORTC
|
||||||
|
DWORD get_fattime (void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* LFN support functions */
|
||||||
|
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
||||||
|
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
||||||
|
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
||||||
|
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
||||||
|
#endif
|
||||||
|
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||||
|
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||||
|
void ff_memfree (void* mblock); /* Free memory block */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Sync functions */
|
||||||
|
#if FF_FS_REENTRANT
|
||||||
|
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
|
||||||
|
int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
|
||||||
|
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
|
||||||
|
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------*/
|
||||||
|
/* Flags and offset address */
|
||||||
|
|
||||||
|
|
||||||
|
/* File access mode and open method flags (3rd argument of f_open) */
|
||||||
|
#define FA_READ 0x01
|
||||||
|
#define FA_WRITE 0x02
|
||||||
|
#define FA_OPEN_EXISTING 0x00
|
||||||
|
#define FA_CREATE_NEW 0x04
|
||||||
|
#define FA_CREATE_ALWAYS 0x08
|
||||||
|
#define FA_OPEN_ALWAYS 0x10
|
||||||
|
#define FA_OPEN_APPEND 0x30
|
||||||
|
|
||||||
|
/* Fast seek controls (2nd argument of f_lseek) */
|
||||||
|
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
|
||||||
|
|
||||||
|
/* Format options (2nd argument of f_mkfs) */
|
||||||
|
#define FM_FAT 0x01
|
||||||
|
#define FM_FAT32 0x02
|
||||||
|
#define FM_EXFAT 0x04
|
||||||
|
#define FM_ANY 0x07
|
||||||
|
#define FM_SFD 0x08
|
||||||
|
|
||||||
|
/* Filesystem type (FATFS.fs_type) */
|
||||||
|
#define FS_FAT12 1
|
||||||
|
#define FS_FAT16 2
|
||||||
|
#define FS_FAT32 3
|
||||||
|
#define FS_EXFAT 4
|
||||||
|
|
||||||
|
/* File attribute bits for directory entry (FILINFO.fattrib) */
|
||||||
|
#define AM_RDO 0x01 /* Read only */
|
||||||
|
#define AM_HID 0x02 /* Hidden */
|
||||||
|
#define AM_SYS 0x04 /* System */
|
||||||
|
#define AM_DIR 0x10 /* Directory */
|
||||||
|
#define AM_ARC 0x20 /* Archive */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* FF_DEFINED */
|
||||||
288
examples/SdFat_format/ffconf.h
Normal file
|
|
@ -0,0 +1,288 @@
|
||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ FatFs Functional Configurations
|
||||||
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define FFCONF_DEF 86604 /* Revision ID */
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ Function Configurations
|
||||||
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define FF_FS_READONLY 0
|
||||||
|
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
|
||||||
|
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
|
||||||
|
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
|
||||||
|
/ and optional writing functions as well. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_MINIMIZE 3
|
||||||
|
/* This option defines minimization level to remove some basic API functions.
|
||||||
|
/
|
||||||
|
/ 0: Basic functions are fully enabled.
|
||||||
|
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
|
||||||
|
/ are removed.
|
||||||
|
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||||
|
/ 3: f_lseek() function is removed in addition to 2. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_STRFUNC 0
|
||||||
|
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
|
||||||
|
/
|
||||||
|
/ 0: Disable string functions.
|
||||||
|
/ 1: Enable without LF-CRLF conversion.
|
||||||
|
/ 2: Enable with LF-CRLF conversion. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_FIND 0
|
||||||
|
/* This option switches filtered directory read functions, f_findfirst() and
|
||||||
|
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_MKFS 1
|
||||||
|
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_FASTSEEK 0
|
||||||
|
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_EXPAND 0
|
||||||
|
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_CHMOD 0
|
||||||
|
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
|
||||||
|
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_LABEL 1
|
||||||
|
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||||
|
/ (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_FORWARD 0
|
||||||
|
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ Locale and Namespace Configurations
|
||||||
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define FF_CODE_PAGE 437
|
||||||
|
/* This option specifies the OEM code page to be used on the target system.
|
||||||
|
/ Incorrect code page setting can cause a file open failure.
|
||||||
|
/
|
||||||
|
/ 437 - U.S.
|
||||||
|
/ 720 - Arabic
|
||||||
|
/ 737 - Greek
|
||||||
|
/ 771 - KBL
|
||||||
|
/ 775 - Baltic
|
||||||
|
/ 850 - Latin 1
|
||||||
|
/ 852 - Latin 2
|
||||||
|
/ 855 - Cyrillic
|
||||||
|
/ 857 - Turkish
|
||||||
|
/ 860 - Portuguese
|
||||||
|
/ 861 - Icelandic
|
||||||
|
/ 862 - Hebrew
|
||||||
|
/ 863 - Canadian French
|
||||||
|
/ 864 - Arabic
|
||||||
|
/ 865 - Nordic
|
||||||
|
/ 866 - Russian
|
||||||
|
/ 869 - Greek 2
|
||||||
|
/ 932 - Japanese (DBCS)
|
||||||
|
/ 936 - Simplified Chinese (DBCS)
|
||||||
|
/ 949 - Korean (DBCS)
|
||||||
|
/ 950 - Traditional Chinese (DBCS)
|
||||||
|
/ 0 - Include all code pages above and configured by f_setcp()
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_LFN 0
|
||||||
|
#define FF_MAX_LFN 255
|
||||||
|
/* The FF_USE_LFN switches the support for LFN (long file name).
|
||||||
|
/
|
||||||
|
/ 0: Disable LFN. FF_MAX_LFN has no effect.
|
||||||
|
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||||
|
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||||
|
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||||
|
/
|
||||||
|
/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
|
||||||
|
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
||||||
|
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
||||||
|
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
||||||
|
/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN
|
||||||
|
/ specification.
|
||||||
|
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||||
|
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||||
|
/ ff_memfree() in ffsystem.c, need to be added to the project. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_LFN_UNICODE 0
|
||||||
|
/* This option switches the character encoding on the API when LFN is enabled.
|
||||||
|
/
|
||||||
|
/ 0: ANSI/OEM in current CP (TCHAR = char)
|
||||||
|
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
|
||||||
|
/ 2: Unicode in UTF-8 (TCHAR = char)
|
||||||
|
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
|
||||||
|
/
|
||||||
|
/ Also behavior of string I/O functions will be affected by this option.
|
||||||
|
/ When LFN is not enabled, this option has no effect. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_LFN_BUF 255
|
||||||
|
#define FF_SFN_BUF 12
|
||||||
|
/* This set of options defines size of file name members in the FILINFO structure
|
||||||
|
/ which is used to read out directory items. These values should be sufficient for
|
||||||
|
/ the file names to read. The maximum possible length of the read file name depends
|
||||||
|
/ on character encoding. When LFN is not enabled, these options have no effect. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_STRF_ENCODE 3
|
||||||
|
/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(),
|
||||||
|
/ f_putc(), f_puts and f_printf() convert the character encoding in it.
|
||||||
|
/ This option selects assumption of character encoding ON THE FILE to be
|
||||||
|
/ read/written via those functions.
|
||||||
|
/
|
||||||
|
/ 0: ANSI/OEM in current CP
|
||||||
|
/ 1: Unicode in UTF-16LE
|
||||||
|
/ 2: Unicode in UTF-16BE
|
||||||
|
/ 3: Unicode in UTF-8
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_RPATH 0
|
||||||
|
/* This option configures support for relative path.
|
||||||
|
/
|
||||||
|
/ 0: Disable relative path and remove related functions.
|
||||||
|
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
|
||||||
|
/ 2: f_getcwd() function is available in addition to 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ Drive/Volume Configurations
|
||||||
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define FF_VOLUMES 1
|
||||||
|
/* Number of volumes (logical drives) to be used. (1-10) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_STR_VOLUME_ID 0
|
||||||
|
#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
|
||||||
|
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
|
||||||
|
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
|
||||||
|
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
|
||||||
|
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid
|
||||||
|
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
|
||||||
|
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
|
||||||
|
/ not defined, a user defined volume string table needs to be defined as:
|
||||||
|
/
|
||||||
|
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_MULTI_PARTITION 0
|
||||||
|
/* This option switches support for multiple volumes on the physical drive.
|
||||||
|
/ By default (0), each logical drive number is bound to the same physical drive
|
||||||
|
/ number and only an FAT volume found on the physical drive will be mounted.
|
||||||
|
/ When this function is enabled (1), each logical drive number can be bound to
|
||||||
|
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
|
||||||
|
/ function will be available. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_MIN_SS 512
|
||||||
|
#define FF_MAX_SS 512
|
||||||
|
/* This set of options configures the range of sector size to be supported. (512,
|
||||||
|
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
|
||||||
|
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||||
|
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
|
||||||
|
/ for variable sector size mode and disk_ioctl() function needs to implement
|
||||||
|
/ GET_SECTOR_SIZE command. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_TRIM 0
|
||||||
|
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
||||||
|
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
||||||
|
/ disk_ioctl() function. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_NOFSINFO 0
|
||||||
|
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||||
|
/ option, and f_getfree() function at first time after volume mount will force
|
||||||
|
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||||
|
/
|
||||||
|
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||||
|
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||||
|
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||||
|
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ System Configurations
|
||||||
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define FF_FS_TINY 0
|
||||||
|
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
||||||
|
/ At the tiny configuration, size of file object (FIL) is shrunk FF_MAX_SS bytes.
|
||||||
|
/ Instead of private sector buffer eliminated from the file object, common sector
|
||||||
|
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_EXFAT 0
|
||||||
|
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
|
||||||
|
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
|
||||||
|
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_NORTC 1
|
||||||
|
#define FF_NORTC_MON 1
|
||||||
|
#define FF_NORTC_MDAY 1
|
||||||
|
#define FF_NORTC_YEAR 2019
|
||||||
|
/* The option FF_FS_NORTC switches timestamp function. If the system does not have
|
||||||
|
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
|
||||||
|
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
|
||||||
|
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
|
||||||
|
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
||||||
|
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
||||||
|
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
||||||
|
/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_LOCK 0
|
||||||
|
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
|
||||||
|
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
|
||||||
|
/ is 1.
|
||||||
|
/
|
||||||
|
/ 0: Disable file lock function. To avoid volume corruption, application program
|
||||||
|
/ should avoid illegal open, remove and rename to the open objects.
|
||||||
|
/ >0: Enable file lock function. The value defines how many files/sub-directories
|
||||||
|
/ can be opened simultaneously under file lock control. Note that the file
|
||||||
|
/ lock control is independent of re-entrancy. */
|
||||||
|
|
||||||
|
|
||||||
|
/* #include <somertos.h> // O/S definitions */
|
||||||
|
#define FF_FS_REENTRANT 0
|
||||||
|
#define FF_FS_TIMEOUT 1000
|
||||||
|
#define FF_SYNC_t HANDLE
|
||||||
|
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
|
||||||
|
/ module itself. Note that regardless of this option, file access to different
|
||||||
|
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
||||||
|
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
||||||
|
/ to the same volume is under control of this function.
|
||||||
|
/
|
||||||
|
/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
|
||||||
|
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||||
|
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||||
|
/ function, must be added to the project. Samples are available in
|
||||||
|
/ option/syscall.c.
|
||||||
|
/
|
||||||
|
/ The FF_FS_TIMEOUT defines timeout period in unit of time tick.
|
||||||
|
/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
|
||||||
|
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
|
||||||
|
/ included somewhere in the scope of ff.h. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--- End of configuration options ---*/
|
||||||
82
examples/SdFat_format/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD core or AVR core
|
||||||
|
// Use stand SPI/SS for avr port.
|
||||||
|
// Note: For AVR, cache will be disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
289
examples/SdFat_full_usage/SdFat_full_usage.ino
Normal file
|
|
@ -0,0 +1,289 @@
|
||||||
|
// Adafruit SPI Flash FatFs Full Usage Example
|
||||||
|
// Author: Tony DiCola
|
||||||
|
//
|
||||||
|
// This is an example of all the functions in the SPI Flash
|
||||||
|
// FatFs library. Note that you MUST have a flash chip that's
|
||||||
|
// formatted with a flash filesystem before running. See the
|
||||||
|
// fatfs_format example to perform this formatting.
|
||||||
|
//
|
||||||
|
// In general the API for this library closely follows the API
|
||||||
|
// for the Arduino SD card library. However instead of interacting
|
||||||
|
// with a global SD object you create an instance of a fatfs class
|
||||||
|
// and use its open, exists, etc. functions. See the SD library
|
||||||
|
// reference for more inspiration and examples to adapt:
|
||||||
|
// https://www.arduino.cc/en/reference/SD
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// - Modify the pins and type of fatfs object in the config
|
||||||
|
// section below if necessary (usually not necessary).
|
||||||
|
// - Upload this sketch to your M0 express board.
|
||||||
|
// - Open the serial monitor at 115200 baud. You should see the
|
||||||
|
// example start to run and messages printed to the monitor.
|
||||||
|
// If you don't see anything close the serial monitor, press
|
||||||
|
// the board reset button, wait a few seconds, then open the
|
||||||
|
// serial monitor again.
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system object from SdFat
|
||||||
|
FatVolume fatfs;
|
||||||
|
|
||||||
|
#define D_TEST "/test"
|
||||||
|
#define D_TEST_FOO_BAR "/test/foo/bar"
|
||||||
|
#define D_TEST_FOO_BAZ "/test/foo/baz"
|
||||||
|
|
||||||
|
#define F_TEST_TEST_TXT "/test/test.txt"
|
||||||
|
#define F_TEST_FOO_TEST2_TXT "/test/foo/test2.txt"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port and wait for it to open before continuing.
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.println(F("Adafruit SPI Flash FatFs Full Usage Example"));
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
Serial.println(F("Error, failed to initialize flash chip!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.print(F("Flash chip JEDEC ID: 0x"));
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
|
||||||
|
// First call begin to mount the filesystem. Check that it returns true
|
||||||
|
// to make sure the filesystem was mounted.
|
||||||
|
if (!fatfs.begin(&flash)) {
|
||||||
|
Serial.println(F("Error, failed to mount newly formatted filesystem!"));
|
||||||
|
Serial.println(
|
||||||
|
F("Was the flash chip formatted with the SdFat_format example?"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println(F("Mounted filesystem!"));
|
||||||
|
|
||||||
|
// Check if a directory called 'test' exists and create it if not there.
|
||||||
|
// Note you should _not_ add a trailing slash (like '/test/') to directory
|
||||||
|
// names! You can use the same exists function to check for the existence of a
|
||||||
|
// file too.
|
||||||
|
if (!fatfs.exists(D_TEST)) {
|
||||||
|
Serial.println(F("Test directory not found, creating..."));
|
||||||
|
|
||||||
|
// Use mkdir to create directory (note you should _not_ have a trailing
|
||||||
|
// slash).
|
||||||
|
fatfs.mkdir(D_TEST);
|
||||||
|
|
||||||
|
if (!fatfs.exists(D_TEST)) {
|
||||||
|
Serial.println(F("Error, failed to create directory!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Created directory!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can also create all the parent subdirectories automatically with mkdir.
|
||||||
|
// For example to create the hierarchy /test/foo/bar:
|
||||||
|
Serial.println(F("Creating deep folder structure..."));
|
||||||
|
if (!fatfs.exists(D_TEST_FOO_BAR)) {
|
||||||
|
Serial.println(F("Creating " D_TEST_FOO_BAR));
|
||||||
|
fatfs.mkdir(D_TEST_FOO_BAR);
|
||||||
|
|
||||||
|
if (!fatfs.exists(D_TEST_FOO_BAR)) {
|
||||||
|
Serial.println(F("Error, failed to create directory!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Created directory!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This will create the hierarchy /test/foo/baz, even when /test/foo already
|
||||||
|
// exists:
|
||||||
|
if (!fatfs.exists(D_TEST_FOO_BAZ)) {
|
||||||
|
Serial.println(F("Creating " D_TEST_FOO_BAZ));
|
||||||
|
fatfs.mkdir(D_TEST_FOO_BAZ);
|
||||||
|
|
||||||
|
if (!fatfs.exists(D_TEST_FOO_BAZ)) {
|
||||||
|
Serial.println(F("Error, failed to create directory!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Created directory!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a file in the test directory and write data to it.
|
||||||
|
// Note the FILE_WRITE parameter which tells the library you intend to
|
||||||
|
// write to the file. This will create the file if it doesn't exist,
|
||||||
|
// otherwise it will open the file and start appending new data to the
|
||||||
|
// end of it.
|
||||||
|
File32 writeFile = fatfs.open(F_TEST_TEST_TXT, FILE_WRITE);
|
||||||
|
if (!writeFile) {
|
||||||
|
Serial.println(F("Error, failed to open " F_TEST_TEST_TXT " for writing!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println(F("Opened file " F_TEST_TEST_TXT " for writing/appending..."));
|
||||||
|
|
||||||
|
// Once open for writing you can print to the file as if you're printing
|
||||||
|
// to the serial terminal, the same functions are available.
|
||||||
|
writeFile.println("Hello world!");
|
||||||
|
writeFile.print("Hello number: ");
|
||||||
|
writeFile.println(123, DEC);
|
||||||
|
writeFile.print("Hello hex number: 0x");
|
||||||
|
writeFile.println(123, HEX);
|
||||||
|
|
||||||
|
// Close the file when finished writing.
|
||||||
|
writeFile.close();
|
||||||
|
Serial.println(F("Wrote to file " F_TEST_TEST_TXT "!"));
|
||||||
|
|
||||||
|
// Now open the same file but for reading.
|
||||||
|
File32 readFile = fatfs.open(F_TEST_TEST_TXT, FILE_READ);
|
||||||
|
if (!readFile) {
|
||||||
|
Serial.println(F("Error, failed to open " F_TEST_TEST_TXT " for reading!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read data using the same read, find, readString, etc. functions as when
|
||||||
|
// using the serial class. See SD library File class for more documentation:
|
||||||
|
// https://www.arduino.cc/en/reference/SD
|
||||||
|
// Read a line of data:
|
||||||
|
String line = readFile.readStringUntil('\n');
|
||||||
|
Serial.print(F("First line of test.txt: "));
|
||||||
|
Serial.println(line);
|
||||||
|
|
||||||
|
// You can get the current position, remaining data, and total size of the
|
||||||
|
// file:
|
||||||
|
Serial.print(F("Total size of test.txt (bytes): "));
|
||||||
|
Serial.println(readFile.size(), DEC);
|
||||||
|
Serial.print(F("Current position in test.txt: "));
|
||||||
|
Serial.println(readFile.position(), DEC);
|
||||||
|
Serial.print(F("Available data to read in test.txt: "));
|
||||||
|
Serial.println(readFile.available(), DEC);
|
||||||
|
|
||||||
|
// And a few other interesting attributes of a file:
|
||||||
|
char readName[64];
|
||||||
|
readFile.getName(readName, sizeof(readName));
|
||||||
|
Serial.print(F("File name: "));
|
||||||
|
Serial.println(readName);
|
||||||
|
Serial.print(F("Is file a directory? "));
|
||||||
|
Serial.println(readFile.isDirectory() ? F("Yes") : F("No"));
|
||||||
|
|
||||||
|
// You can seek around inside the file relative to the start of the file.
|
||||||
|
// For example to skip back to the start (position 0):
|
||||||
|
if (!readFile.seek(0)) {
|
||||||
|
Serial.println(F("Error, failed to seek back to start of file!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// And finally to read all the data and print it out a character at a time
|
||||||
|
// (stopping when end of file is reached):
|
||||||
|
Serial.println(F("Entire contents of test.txt:"));
|
||||||
|
while (readFile.available()) {
|
||||||
|
char c = readFile.read();
|
||||||
|
Serial.print(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the file when finished reading.
|
||||||
|
readFile.close();
|
||||||
|
|
||||||
|
// You can open a directory to list all the children (files and directories).
|
||||||
|
// Just like the SD library the File type represents either a file or
|
||||||
|
// directory.
|
||||||
|
File32 testDir = fatfs.open(D_TEST);
|
||||||
|
if (!testDir) {
|
||||||
|
Serial.println(F("Error, failed to open test directory!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!testDir.isDirectory()) {
|
||||||
|
Serial.println(F("Error, expected test to be a directory!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println(F("Listing children of directory " D_TEST ":"));
|
||||||
|
File32 child = testDir.openNextFile();
|
||||||
|
while (child) {
|
||||||
|
char filename[64];
|
||||||
|
child.getName(filename, sizeof(filename));
|
||||||
|
|
||||||
|
// Print the file name and mention if it's a directory.
|
||||||
|
Serial.print(F("- "));
|
||||||
|
Serial.print(filename);
|
||||||
|
if (child.isDirectory()) {
|
||||||
|
Serial.print(F(" (directory)"));
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
// Keep calling openNextFile to get a new file.
|
||||||
|
// When you're done enumerating files an unopened one will
|
||||||
|
// be returned (i.e. testing it for true/false like at the
|
||||||
|
// top of this while loop will fail).
|
||||||
|
child = testDir.openNextFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If you want to list the files in the directory again call
|
||||||
|
// rewindDirectory(). Then openNextFile will start from the
|
||||||
|
// top again.
|
||||||
|
testDir.rewindDirectory();
|
||||||
|
|
||||||
|
// Delete a file with the remove command. For example create a test2.txt file
|
||||||
|
// inside /test/foo and then delete it.
|
||||||
|
File32 test2File = fatfs.open(F_TEST_FOO_TEST2_TXT, FILE_WRITE);
|
||||||
|
test2File.close();
|
||||||
|
Serial.println(F("Deleting " F_TEST_FOO_TEST2_TXT "..."));
|
||||||
|
if (!fatfs.remove(F_TEST_FOO_TEST2_TXT)) {
|
||||||
|
Serial.println(F("Error, couldn't delete " F_TEST_FOO_TEST2_TXT " file!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println(F("Deleted file!"));
|
||||||
|
|
||||||
|
// Delete a directory with the rmdir command. Be careful as
|
||||||
|
// this will delete EVERYTHING in the directory at all levels!
|
||||||
|
// I.e. this is like running a recursive delete, rm -rf *, in
|
||||||
|
// unix filesystems!
|
||||||
|
Serial.println(F("Deleting /test directory and everything inside it..."));
|
||||||
|
if (!testDir.rmRfStar()) {
|
||||||
|
Serial.println(F("Error, couldn't delete test directory!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check that test is really deleted.
|
||||||
|
if (fatfs.exists(D_TEST)) {
|
||||||
|
Serial.println(F("Error, test directory was not deleted!"));
|
||||||
|
while (1) {
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println(F("Test directory was deleted!"));
|
||||||
|
|
||||||
|
Serial.println(F("Finished!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Nothing to be done in the main loop.
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
82
examples/SdFat_full_usage/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
92
examples/SdFat_print_file/SdFat_print_file.ino
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
// Adafruit SPI Flash FatFs Simple Datalogging Example
|
||||||
|
// Author: Tony DiCola
|
||||||
|
//
|
||||||
|
// This is a simple example that opens a file and prints its
|
||||||
|
// entire contents to the serial monitor. Note that
|
||||||
|
// you MUST have a flash chip that's formatted with a flash
|
||||||
|
// filesystem before running, and there should be some sort
|
||||||
|
// of text file on it to open and read. See the fatfs_format
|
||||||
|
// example to perform this formatting, and the fatfs_datalogging
|
||||||
|
// example to write a simple text file.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// - Modify the pins and type of fatfs object in the config
|
||||||
|
// section below if necessary (usually not necessary).
|
||||||
|
// - Upload this sketch to your M0 express board.
|
||||||
|
// - Open the serial monitor at 115200 baud. You should see the
|
||||||
|
// example start to run and messages printed to the monitor.
|
||||||
|
// If you don't see anything close the serial monitor, press
|
||||||
|
// the board reset button, wait a few seconds, then open the
|
||||||
|
// serial monitor again.
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system object from SdFat
|
||||||
|
FatVolume fatfs;
|
||||||
|
|
||||||
|
// Configuration for the file to open and read:
|
||||||
|
#define FILE_NAME "test2.txt"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port and wait for it to open before continuing.
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.println("Adafruit SPI Flash FatFs Simple File Printing Example");
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
Serial.println("Error, failed to initialize flash chip!");
|
||||||
|
while (1) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.print("Flash chip JEDEC ID: 0x");
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
|
||||||
|
// First call begin to mount the filesystem. Check that it returns true
|
||||||
|
// to make sure the filesystem was mounted.
|
||||||
|
if (!fatfs.begin(&flash)) {
|
||||||
|
Serial.println("Error, failed to mount newly formatted filesystem!");
|
||||||
|
Serial.println(
|
||||||
|
"Was the flash chip formatted with the fatfs_format example?");
|
||||||
|
while (1) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println("Mounted filesystem!");
|
||||||
|
|
||||||
|
// Open the file for reading and check that it was successfully opened.
|
||||||
|
// The FILE_READ mode will open the file for reading.
|
||||||
|
File32 dataFile = fatfs.open(FILE_NAME, FILE_READ);
|
||||||
|
if (dataFile) {
|
||||||
|
// File was opened, now print out data character by character until at the
|
||||||
|
// end of the file.
|
||||||
|
Serial.println("Opened file, printing contents below:");
|
||||||
|
while (dataFile.available()) {
|
||||||
|
// Use the read function to read the next character.
|
||||||
|
// You can alternatively use other functions like readUntil, readString,
|
||||||
|
// etc. See the fatfs_full_usage example for more details.
|
||||||
|
char c = dataFile.read();
|
||||||
|
Serial.print(c);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.print("Failed to open file \"");
|
||||||
|
Serial.print(FILE_NAME);
|
||||||
|
Serial.print("\" !! Does it exist?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Nothing to do in main loop.
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
82
examples/SdFat_print_file/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
82
examples/flash_erase/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
79
examples/flash_erase/flash_erase.ino
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
// Adafruit SPI Flash Total Erase
|
||||||
|
// Author: Tony DiCola
|
||||||
|
//
|
||||||
|
// This example will perform a complete erase of ALL data on the SPI
|
||||||
|
// flash. This is handy to reset the flash into a known empty state
|
||||||
|
// and fix potential filesystem or other corruption issues.
|
||||||
|
//
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// !! NOTE: YOU WILL ERASE ALL DATA BY RUNNING THIS SKETCH! !!
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// - Modify the pins and type of fatfs object in the config
|
||||||
|
// section below if necessary (usually not necessary).
|
||||||
|
// - Upload this sketch to your M0 express board.
|
||||||
|
// - Open the serial monitor at 115200 baud. You should see a
|
||||||
|
// prompt to confirm formatting. If you don't see the prompt
|
||||||
|
// close the serial monitor, press the board reset button,
|
||||||
|
// wait a few seconds, then open the serial monitor again.
|
||||||
|
// - Type OK and enter to confirm the format when prompted,
|
||||||
|
// the flash chip will be erased.
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port and wait for it to open before continuing.
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.println("Adafruit SPI Flash Total Erase Example");
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
Serial.println("Error, failed to initialize flash chip!");
|
||||||
|
while (1) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.print("Flash chip JEDEC ID: 0x");
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
|
||||||
|
// Wait for user to send OK to continue.
|
||||||
|
// Increase timeout to print message less frequently.
|
||||||
|
Serial.setTimeout(30000);
|
||||||
|
do {
|
||||||
|
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
"!!!!!!!!!!");
|
||||||
|
Serial.println("This sketch will ERASE ALL DATA on the flash chip!");
|
||||||
|
Serial.println("Type OK (all caps) and press enter to continue.");
|
||||||
|
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
"!!!!!!!!!!");
|
||||||
|
} while (!Serial.find((char *)"OK"));
|
||||||
|
|
||||||
|
Serial.println("Erasing flash chip in 10 seconds...");
|
||||||
|
Serial.println(
|
||||||
|
"Note you will see stat and other debug output printed repeatedly.");
|
||||||
|
Serial.println(
|
||||||
|
"Let it run for ~30 seconds until the flash erase is finished.");
|
||||||
|
Serial.println("An error or success message will be printed when complete.");
|
||||||
|
|
||||||
|
if (!flash.eraseChip()) {
|
||||||
|
Serial.println("Failed to erase chip!");
|
||||||
|
}
|
||||||
|
|
||||||
|
flash.waitUntilReady();
|
||||||
|
Serial.println("Successfully erased chip!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Nothing to do in the loop.
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
0
examples/flash_erase_express/.clue.generate
Normal file
0
examples/flash_erase_express/.cpb.generate
Normal file
0
examples/flash_erase_express/.cpx_ada.generate
Normal file
0
examples/flash_erase_express/.feather_rp2040.generate
Normal file
0
examples/flash_erase_express/.grand_central.generate
Normal file
0
examples/flash_erase_express/.matrixportal.generate
Normal file
0
examples/flash_erase_express/.metro_m0.generate
Normal file
0
examples/flash_erase_express/.metro_m4.generate
Normal file
0
examples/flash_erase_express/.metroesp32s2.generate
Normal file
0
examples/flash_erase_express/.neotrellis_m4.generate
Normal file
0
examples/flash_erase_express/.nrf52840.generate
Normal file
0
examples/flash_erase_express/.pybadge.generate
Normal file
0
examples/flash_erase_express/.pyportal.generate
Normal file
0
examples/flash_erase_express/.pyportal_titano.generate
Normal file
82
examples/flash_erase_express/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
96
examples/flash_erase_express/flash_erase_express.ino
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
// Adafruit SPI Flash Total Erase
|
||||||
|
// Authors: Tony DiCola, Dan Halbert
|
||||||
|
//
|
||||||
|
// This example will perform a complete erase of ALL data on the SPI
|
||||||
|
// flash. This is handy to reset the flash into a known empty state
|
||||||
|
// and fix potential filesystem or other corruption issues.
|
||||||
|
//
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// !! NOTE: YOU WILL ERASE ALL DATA BY RUNNING THIS SKETCH! !!
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// - Modify the pins and type of fatfs object in the config
|
||||||
|
// section below if necessary (usually not necessary).
|
||||||
|
// - Upload this sketch to your M0 express board.
|
||||||
|
// - Upon starting the board Neopixel will be blue
|
||||||
|
// - About 13 seconds later, the Neopixel should starting flashing
|
||||||
|
// green once per second. This indicates the SPI flash has been
|
||||||
|
// erased and all is well.
|
||||||
|
// - If the Nexopixel starts flashing red two or three times a second,
|
||||||
|
// an error has occurred.
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// On-board status Neopixel.
|
||||||
|
#if defined(ARDUINO_TRELLIS_M4)
|
||||||
|
#define PIN_NEOPIXEL 10
|
||||||
|
#elif defined(ARDUINO_PYPORTAL_M4) || defined(ADAFRUIT_PYPORTAL_M4_TITANO)
|
||||||
|
#define PIN_NEOPIXEL 2
|
||||||
|
#elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS)
|
||||||
|
#define PIN_NEOPIXEL 8
|
||||||
|
#else
|
||||||
|
// something else?
|
||||||
|
#warning "PIN_NEOPIXEL is not defined/detected, default to 8"
|
||||||
|
#define PIN_NEOPIXEL 8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Adafruit_NeoPixel pixel =
|
||||||
|
Adafruit_NeoPixel(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
||||||
|
uint32_t BLUE = pixel.Color(0, 0, 100);
|
||||||
|
uint32_t GREEN = pixel.Color(0, 100, 0);
|
||||||
|
uint32_t YELLOW = pixel.Color(100, 100, 0);
|
||||||
|
uint32_t RED = pixel.Color(100, 0, 0);
|
||||||
|
uint32_t OFF = pixel.Color(0, 0, 0);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Start with a blue pixel.
|
||||||
|
pixel.begin();
|
||||||
|
pixel.setBrightness(30);
|
||||||
|
pixel.setPixelColor(0, BLUE);
|
||||||
|
pixel.show();
|
||||||
|
|
||||||
|
// Initialize flash library and check its chip ID.
|
||||||
|
if (!flash.begin()) {
|
||||||
|
// blink red
|
||||||
|
blink(2, RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel.setPixelColor(0, YELLOW);
|
||||||
|
pixel.show();
|
||||||
|
|
||||||
|
if (!flash.eraseChip()) {
|
||||||
|
blink(3, RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
flash.waitUntilReady();
|
||||||
|
blink(1, GREEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Nothing to do in the loop.
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void blink(int times, uint32_t color) {
|
||||||
|
while (1) {
|
||||||
|
for (int i = 0; i < times; i++) {
|
||||||
|
pixel.setPixelColor(0, color);
|
||||||
|
pixel.show();
|
||||||
|
delay(100);
|
||||||
|
pixel.setPixelColor(0, OFF);
|
||||||
|
pixel.show();
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
examples/flash_info/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
98
examples/flash_info/flash_info.ino
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
// The MIT License (MIT)
|
||||||
|
// Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
/* If you want to use a specific flash device, for example for a custom built
|
||||||
|
board, first look for it in Adafruit_SPIFlash\src\flash_devices.h
|
||||||
|
* If it isn't in there you need to create your own definition like the
|
||||||
|
W25Q80DLX_EXAMPLE example below.
|
||||||
|
* These definitions need to be edited to match information on the data sheet
|
||||||
|
of the flash device that you want to use.
|
||||||
|
* If you are not sure what the manufacture ID, memory type and capacity values
|
||||||
|
should be, try running the sketch anyway and look at the serial output
|
||||||
|
* The flash device will report these values to you as a single hexadecimal
|
||||||
|
value (the JDEC ID)
|
||||||
|
* For example, the first device on the list - the W25Q80DLX - will report its
|
||||||
|
JDEC ID as 0xef4014, which is made of these three values:
|
||||||
|
* manufacturer_id = 0xef
|
||||||
|
* memory_type = 0x40
|
||||||
|
* capacity = 0x14
|
||||||
|
* With this macro properly defined you can then create an array of device
|
||||||
|
definitions as shown below, this can include any from the list of devices in
|
||||||
|
flash_devices.h, and any you define yourself here
|
||||||
|
* You need to update the variable on line 71 to reflect the number of items in
|
||||||
|
the array
|
||||||
|
* You also need to uncomment line 84 and comment out line 81 so this array
|
||||||
|
will be passed to the flash memory driver.
|
||||||
|
*
|
||||||
|
* Example of a user defined flash memory device:
|
||||||
|
#define W25Q80DLX_EXAMPLE \
|
||||||
|
{ \
|
||||||
|
.total_size = 1*1024*1024, \
|
||||||
|
.start_up_time_us = 5000, .manufacturer_id = 0xef, \
|
||||||
|
.memory_type = 0x40, .capacity = 0x14, .max_clock_speed_mhz = 80, \
|
||||||
|
.quad_enable_bit_mask = 0x02, .has_sector_protection = false, \
|
||||||
|
.supports_fast_read = true, .supports_qspi = true, \
|
||||||
|
.supports_qspi_writes = false, .write_status_register_split = false, \
|
||||||
|
.single_status_byte = false, .is_fram = false, \
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create an array of data structures and fill it with the settings we defined
|
||||||
|
* above. We are using two devices, but more can be added if you want.
|
||||||
|
*/
|
||||||
|
// static const SPIFlash_Device_t my_flash_devices[] = {
|
||||||
|
// W25Q80DLX_EXAMPLE,
|
||||||
|
// };
|
||||||
|
/*
|
||||||
|
* Specify the number of different devices that are listed in the array we just
|
||||||
|
* created. If you add more devices to the array, update this value to match.
|
||||||
|
*/
|
||||||
|
// const int flashDevices = 1;
|
||||||
|
|
||||||
|
// the setup function runs once when you press reset or power the board
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(100); // wait for native usb
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Adafruit Serial Flash Info example");
|
||||||
|
flash.begin();
|
||||||
|
|
||||||
|
// Using a flash device not already listed? Start the flash memory by passing
|
||||||
|
// it the array of device settings defined above, and the number of elements
|
||||||
|
// in the array.
|
||||||
|
// flash.begin(my_flash_devices, flashDevices);
|
||||||
|
|
||||||
|
uint32_t jedec_id = flash.getJEDECID();
|
||||||
|
Serial.print("JEDEC ID: 0x");
|
||||||
|
Serial.println(jedec_id, HEX);
|
||||||
|
Serial.print("Flash size (usable): ");
|
||||||
|
Serial.print(flash.size() / 1024);
|
||||||
|
Serial.println(" KB");
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_RP2040
|
||||||
|
// For rp2 since flash device is also used for storing code, the flash.size()
|
||||||
|
// only return usable flash size for data which is dictated by e.g Menu->Flash
|
||||||
|
// Size -> 2MB (Sketch 1920KB, FS 64KB) --> size = 64KB For reference purpose,
|
||||||
|
// we only try to find and print actual flash device size using JEDEC here
|
||||||
|
Serial.print("Flash size (raw): ");
|
||||||
|
Serial.print(1 << ((jedec_id & 0xff) - 10));
|
||||||
|
Serial.println(" KB");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
82
examples/flash_manipulator/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
209
examples/flash_manipulator/flash_manipulator.ino
Normal file
|
|
@ -0,0 +1,209 @@
|
||||||
|
/* This is my go-to example for erasing, dumping, writing and verifying SPI
|
||||||
|
* flash! */
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_SPIFlash.h>
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// file system on SD card
|
||||||
|
SdFat sd;
|
||||||
|
|
||||||
|
#define SD_CS 10
|
||||||
|
#define MAXPAGESIZE 256
|
||||||
|
|
||||||
|
File32 dataFile;
|
||||||
|
uint8_t buffer[MAXPAGESIZE], buffer2[MAXPAGESIZE];
|
||||||
|
uint32_t results;
|
||||||
|
|
||||||
|
void error(const char *str) {
|
||||||
|
Serial.println(str);
|
||||||
|
while (1) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
flash.begin();
|
||||||
|
|
||||||
|
Serial.println(F("Adafruit Serial Flash Manipulator example"));
|
||||||
|
Serial.print(F("JEDEC ID: "));
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
Serial.print(F("Flash size: "));
|
||||||
|
Serial.println(flash.size());
|
||||||
|
|
||||||
|
Serial.print("Initializing SD card... ");
|
||||||
|
// see if the card is present and can be initialized:
|
||||||
|
if (!sd.begin(SD_CS, SD_SCK_MHZ(50))) {
|
||||||
|
Serial.println("Card failed, or not present");
|
||||||
|
// don't do anything more:
|
||||||
|
while (1) {
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
while (Serial.available()) {
|
||||||
|
Serial.read();
|
||||||
|
}
|
||||||
|
Serial.println(F("FLASH DUMPER - Hello! Press E (rase), W (rite), V (erify), "
|
||||||
|
"or D (ump) to begin"));
|
||||||
|
|
||||||
|
while (!Serial.available())
|
||||||
|
;
|
||||||
|
char cmd = toupper(Serial.read());
|
||||||
|
|
||||||
|
uint16_t pagesize = flash.pageSize();
|
||||||
|
Serial.print(F("Page size: "));
|
||||||
|
Serial.println(pagesize);
|
||||||
|
|
||||||
|
if (cmd == 'D') {
|
||||||
|
// open the file. note that only one file can be open at a time,
|
||||||
|
// so you have to close this one before opening another.
|
||||||
|
// Open up the file we're going to log to!
|
||||||
|
dataFile = sd.open(F("flshdump.bin"), FILE_WRITE);
|
||||||
|
if (!dataFile) {
|
||||||
|
error("error opening flshdump.bin");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("Dumping FLASH to disk"));
|
||||||
|
for (uint32_t page = 0; page < flash.numPages(); page++) {
|
||||||
|
memset(buffer, 0, pagesize);
|
||||||
|
Serial.print(F("// Reading page "));
|
||||||
|
Serial.println(page);
|
||||||
|
uint16_t r = flash.readBuffer(page * pagesize, buffer, pagesize);
|
||||||
|
// Serial.print(r); Serial.print(' '); PrintHex(buffer, r);
|
||||||
|
dataFile.write(buffer, r);
|
||||||
|
}
|
||||||
|
dataFile.flush();
|
||||||
|
dataFile.close();
|
||||||
|
}
|
||||||
|
if (cmd == 'E') {
|
||||||
|
Serial.println(F("Erasing chip"));
|
||||||
|
flash.eraseChip();
|
||||||
|
}
|
||||||
|
if (cmd == 'V') {
|
||||||
|
dataFile = sd.open("flshdump.bin", FILE_READ);
|
||||||
|
if (!dataFile) {
|
||||||
|
error("error opening flshdump.bin");
|
||||||
|
}
|
||||||
|
Serial.println(F("Verifying FLASH from disk"));
|
||||||
|
for (uint32_t page = 0; page < flash.numPages(); page++) {
|
||||||
|
memset(buffer, 0, pagesize);
|
||||||
|
memset(buffer2, 0, pagesize);
|
||||||
|
|
||||||
|
Serial.print(F("// Verifying page "));
|
||||||
|
Serial.println(page);
|
||||||
|
|
||||||
|
uint32_t r = flash.readBuffer(page * pagesize, buffer, pagesize);
|
||||||
|
if (r != pagesize) {
|
||||||
|
error("Flash read failure");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r != (uint32_t)dataFile.read(buffer2, r)) {
|
||||||
|
error("SD read failure");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(buffer, buffer2, r) != 0) {
|
||||||
|
PrintHex(buffer, r);
|
||||||
|
PrintHex(buffer2, r);
|
||||||
|
Serial.println(F("verification failed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println(F("Done!"));
|
||||||
|
dataFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd == 'W') {
|
||||||
|
dataFile = sd.open("flshdump.bin", FILE_READ);
|
||||||
|
if (!dataFile) {
|
||||||
|
error("error opening flshdump.bin");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("Writing FLASH from disk"));
|
||||||
|
for (uint32_t page = 0; page < flash.numPages(); page++) {
|
||||||
|
memset(buffer, 0, pagesize);
|
||||||
|
|
||||||
|
int16_t r = dataFile.read(buffer, pagesize);
|
||||||
|
if (r == 0)
|
||||||
|
break;
|
||||||
|
Serial.print(F("// Writing page "));
|
||||||
|
Serial.println(page);
|
||||||
|
|
||||||
|
if (r != (int)flash.writeBuffer(page * r, buffer, r)) {
|
||||||
|
error("Flash write failure");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println(("Done!"));
|
||||||
|
dataFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Prints a hexadecimal value in plain characters, along with
|
||||||
|
the char equivalents in the following format:
|
||||||
|
|
||||||
|
00 00 00 00 00 00 ......
|
||||||
|
|
||||||
|
@param data Pointer to the byte data
|
||||||
|
@param numBytes Data length in bytes
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void PrintHexChar(const byte *data, const uint32_t numBytes) {
|
||||||
|
uint32_t szPos;
|
||||||
|
for (szPos = 0; szPos < numBytes; szPos++) {
|
||||||
|
// Append leading 0 for small values
|
||||||
|
if (data[szPos] <= 0xF)
|
||||||
|
Serial.print(F("0"));
|
||||||
|
Serial.print(data[szPos], HEX);
|
||||||
|
if ((numBytes > 1) && (szPos != numBytes - 1)) {
|
||||||
|
Serial.print(F(" "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.print(F(" "));
|
||||||
|
for (szPos = 0; szPos < numBytes; szPos++) {
|
||||||
|
if (data[szPos] <= 0x1F)
|
||||||
|
Serial.print('.');
|
||||||
|
else
|
||||||
|
Serial.write(data[szPos]);
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Prints a hexadecimal value in plain characters
|
||||||
|
|
||||||
|
@param data Pointer to the byte data
|
||||||
|
@param numBytes Data length in bytes
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void PrintHex(const byte *data, const uint32_t numBytes) {
|
||||||
|
uint32_t szPos;
|
||||||
|
for (szPos = 0; szPos < numBytes; szPos++) {
|
||||||
|
Serial.print(F("0x"));
|
||||||
|
// Append leading 0 for small values
|
||||||
|
if (data[szPos] <= 0xF)
|
||||||
|
Serial.print(F("0"));
|
||||||
|
Serial.print(data[szPos], HEX);
|
||||||
|
if ((numBytes > 1) && (szPos != numBytes - 1)) {
|
||||||
|
Serial.print(F(" "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
}
|
||||||
82
examples/flash_sector_dump/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
77
examples/flash_sector_dump/flash_sector_dump.ino
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
// The MIT License (MIT)
|
||||||
|
// Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||||
|
|
||||||
|
#include "SPI.h"
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
|
||||||
|
#include "Adafruit_SPIFlash.h"
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
// the setup function runs once when you press reset or power the board
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(10); // wait for native usb
|
||||||
|
}
|
||||||
|
|
||||||
|
flash.begin();
|
||||||
|
|
||||||
|
Serial.println("Adafruit Serial Flash Sector Dump example");
|
||||||
|
Serial.print("JEDEC ID: ");
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
Serial.print("Flash size: ");
|
||||||
|
Serial.println(flash.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void dump_sector(uint32_t sector) {
|
||||||
|
uint8_t buf[4096];
|
||||||
|
memset(buf, 0xff, sizeof(buf));
|
||||||
|
|
||||||
|
flash.readBuffer(sector * 4096, buf, 4096);
|
||||||
|
|
||||||
|
for (uint32_t row = 0; row < sizeof(buf) / 16; row++) {
|
||||||
|
if (row == 0)
|
||||||
|
Serial.print("0");
|
||||||
|
if (row < 16)
|
||||||
|
Serial.print("0");
|
||||||
|
Serial.print(row * 16, HEX);
|
||||||
|
Serial.print(" : ");
|
||||||
|
|
||||||
|
for (uint32_t col = 0; col < 16; col++) {
|
||||||
|
uint8_t val = buf[row * 16 + col];
|
||||||
|
|
||||||
|
if (val < 16)
|
||||||
|
Serial.print("0");
|
||||||
|
Serial.print(val, HEX);
|
||||||
|
|
||||||
|
Serial.print(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
Serial.print("Enter the sector number to dump: ");
|
||||||
|
while (!Serial.available()) {
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sector = Serial.parseInt();
|
||||||
|
int sector_max = (int)flash.size() / 4096;
|
||||||
|
|
||||||
|
Serial.println(sector); // echo
|
||||||
|
|
||||||
|
if (sector < sector_max) {
|
||||||
|
dump_sector(sector);
|
||||||
|
} else {
|
||||||
|
Serial.println("Invalid sector number");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
delay(10); // a bit of delay
|
||||||
|
}
|
||||||
82
examples/flash_speedtest/flash_config.h
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASH_CONFIG_H_
|
||||||
|
#define FLASH_CONFIG_H_
|
||||||
|
|
||||||
|
// Un-comment to run example with custom SPI and SS e.g with FRAM breakout
|
||||||
|
// #define CUSTOM_CS A5
|
||||||
|
// #define CUSTOM_SPI SPI
|
||||||
|
|
||||||
|
#if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
// ESP32 use same flash device that store code for file system.
|
||||||
|
// SPIFlash will parse partition.cvs to detect FATFS partition to use
|
||||||
|
Adafruit_FlashTransport_ESP32 flashTransport;
|
||||||
|
|
||||||
|
#elif defined(ARDUINO_ARCH_RP2040)
|
||||||
|
// RP2040 use same flash device that store code for file system. Therefore we
|
||||||
|
// only need to specify start address and size (no need SPI or SS)
|
||||||
|
// By default (start=0, size=0), values that match file system setting in
|
||||||
|
// 'Tools->Flash Size' menu selection will be used.
|
||||||
|
Adafruit_FlashTransport_RP2040 flashTransport;
|
||||||
|
|
||||||
|
// To be compatible with CircuitPython partition scheme (start_address = 1 MB,
|
||||||
|
// size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
|
||||||
|
// subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
|
||||||
|
// following line:
|
||||||
|
// Adafruit_FlashTransport_RP2040
|
||||||
|
// flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
|
||||||
|
// Adafruit_FlashTransport_RP2040::CPY_SIZE);
|
||||||
|
// Adafruit_FlashTransport_RP2040_CPY flashTransport;
|
||||||
|
#else
|
||||||
|
|
||||||
|
// On-board external flash (QSPI or SPI) macros should already
|
||||||
|
// defined in your board variant if supported
|
||||||
|
// - EXTERNAL_FLASH_USE_QSPI
|
||||||
|
// - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
|
||||||
|
|
||||||
|
#if defined(EXTERNAL_FLASH_USE_QSPI)
|
||||||
|
Adafruit_FlashTransport_QSPI flashTransport;
|
||||||
|
|
||||||
|
#elif defined(EXTERNAL_FLASH_USE_SPI)
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
|
||||||
|
EXTERNAL_FLASH_USE_SPI);
|
||||||
|
|
||||||
|
#elif defined(__AVR__) || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
|
||||||
|
|
||||||
|
// Circuit Playground Express built with Arduino SAMD instead of Adafruit SAMD
|
||||||
|
// core or AVR core Use stand SPI/SS for avr port. Note: For AVR, cache will be
|
||||||
|
// disable due to lack of memory.
|
||||||
|
Adafruit_FlashTransport_SPI flashTransport(SS, SPI);
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error No (Q)SPI flash are defined for your board !
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
145
examples/flash_speedtest/flash_speedtest.ino
Normal file
|
|
@ -0,0 +1,145 @@
|
||||||
|
// The MIT License (MIT)
|
||||||
|
// Copyright (c) 2019 Ha Thach for Adafruit Industries
|
||||||
|
|
||||||
|
#include "SdFat_Adafruit_Fork.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include "Adafruit_SPIFlash.h"
|
||||||
|
|
||||||
|
// for flashTransport definition
|
||||||
|
#include "flash_config.h"
|
||||||
|
|
||||||
|
Adafruit_SPIFlash flash(&flashTransport);
|
||||||
|
|
||||||
|
#ifdef __AVR__
|
||||||
|
#define BUFSIZE 512
|
||||||
|
#else
|
||||||
|
#define BUFSIZE 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TEST_WHOLE_CHIP 1
|
||||||
|
|
||||||
|
#ifdef LED_BUILTIN
|
||||||
|
uint8_t led_pin = LED_BUILTIN;
|
||||||
|
#else
|
||||||
|
uint8_t led_pin = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 4 byte aligned buffer has best result with nRF QSPI
|
||||||
|
uint8_t bufwrite[BUFSIZE] __attribute__((aligned(4)));
|
||||||
|
uint8_t bufread[BUFSIZE] __attribute__((aligned(4)));
|
||||||
|
|
||||||
|
// the setup function runs once when you press reset or power the board
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial) {
|
||||||
|
delay(100); // wait for native usb
|
||||||
|
}
|
||||||
|
flash.begin();
|
||||||
|
|
||||||
|
pinMode(led_pin, OUTPUT);
|
||||||
|
flash.setIndicator(led_pin, true);
|
||||||
|
|
||||||
|
Serial.println("Adafruit Serial Flash Speed Test example");
|
||||||
|
Serial.print("JEDEC ID: ");
|
||||||
|
Serial.println(flash.getJEDECID(), HEX);
|
||||||
|
Serial.print("Flash size: ");
|
||||||
|
Serial.println(flash.size());
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
write_and_compare(0xAA);
|
||||||
|
write_and_compare(0x55);
|
||||||
|
|
||||||
|
Serial.println("Speed test is completed.");
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_speed(const char *text, uint32_t count, uint32_t ms) {
|
||||||
|
Serial.print(text);
|
||||||
|
Serial.print(count);
|
||||||
|
Serial.print(" bytes in ");
|
||||||
|
Serial.print(ms / 1000.0F, 2);
|
||||||
|
Serial.println(" seconds.");
|
||||||
|
|
||||||
|
Serial.print("Speed: ");
|
||||||
|
Serial.print((count / 1000.0F) / (ms / 1000.0F), 2);
|
||||||
|
Serial.println(" KB/s.\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool write_and_compare(uint8_t pattern) {
|
||||||
|
uint32_t ms;
|
||||||
|
|
||||||
|
Serial.println("Erase chip");
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
#if TEST_WHOLE_CHIP
|
||||||
|
uint32_t const flash_sz = flash.size();
|
||||||
|
flash.eraseChip();
|
||||||
|
#else
|
||||||
|
uint32_t const flash_sz = 4096;
|
||||||
|
flash.eraseSector(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
flash.waitUntilReady();
|
||||||
|
|
||||||
|
// write all
|
||||||
|
memset(bufwrite, (int)pattern, sizeof(bufwrite));
|
||||||
|
Serial.print("Write flash with 0x");
|
||||||
|
Serial.println(pattern, HEX);
|
||||||
|
Serial.flush();
|
||||||
|
ms = millis();
|
||||||
|
|
||||||
|
for (uint32_t addr = 0; addr < flash_sz; addr += sizeof(bufwrite)) {
|
||||||
|
flash.writeBuffer(addr, bufwrite, sizeof(bufwrite));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ms_write = millis() - ms;
|
||||||
|
print_speed("Write ", flash_sz, ms_write);
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
// read and compare
|
||||||
|
Serial.println("Read flash and compare");
|
||||||
|
Serial.flush();
|
||||||
|
uint32_t ms_read = 0;
|
||||||
|
for (uint32_t addr = 0; addr < flash_sz; addr += sizeof(bufread)) {
|
||||||
|
memset(bufread, 0, sizeof(bufread));
|
||||||
|
|
||||||
|
ms = millis();
|
||||||
|
flash.readBuffer(addr, bufread, sizeof(bufread));
|
||||||
|
ms_read += millis() - ms;
|
||||||
|
|
||||||
|
if (memcmp(bufwrite, bufread, BUFSIZE)) {
|
||||||
|
Serial.print("Error: flash contents mismatched at address 0x");
|
||||||
|
Serial.println(addr, HEX);
|
||||||
|
for (uint32_t i = 0; i < sizeof(bufread); i++) {
|
||||||
|
if (i != 0)
|
||||||
|
Serial.print(' ');
|
||||||
|
if ((i % 16 == 0)) {
|
||||||
|
Serial.println();
|
||||||
|
if (i < 0x100)
|
||||||
|
Serial.print('0');
|
||||||
|
if (i < 0x010)
|
||||||
|
Serial.print('0');
|
||||||
|
Serial.print(i, HEX);
|
||||||
|
Serial.print(": ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bufread[i] < 0x10)
|
||||||
|
Serial.print('0');
|
||||||
|
Serial.print(bufread[i], HEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print_speed("Read ", flash_sz, ms_read);
|
||||||
|
Serial.flush();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
BIN
html/bc_s.png
|
Before Width: | Height: | Size: 676 B |
BIN
html/bdwn.png
|
Before Width: | Height: | Size: 147 B |
BIN
html/closed.png
|
Before Width: | Height: | Size: 132 B |
BIN
html/doc.png
|
Before Width: | Height: | Size: 746 B |
1596
html/doxygen.css
BIN
html/doxygen.png
|
Before Width: | Height: | Size: 3.7 KiB |
|
|
@ -1,97 +0,0 @@
|
||||||
function toggleVisibility(linkObj)
|
|
||||||
{
|
|
||||||
var base = $(linkObj).attr('id');
|
|
||||||
var summary = $('#'+base+'-summary');
|
|
||||||
var content = $('#'+base+'-content');
|
|
||||||
var trigger = $('#'+base+'-trigger');
|
|
||||||
var src=$(trigger).attr('src');
|
|
||||||
if (content.is(':visible')===true) {
|
|
||||||
content.hide();
|
|
||||||
summary.show();
|
|
||||||
$(linkObj).addClass('closed').removeClass('opened');
|
|
||||||
$(trigger).attr('src',src.substring(0,src.length-8)+'closed.png');
|
|
||||||
} else {
|
|
||||||
content.show();
|
|
||||||
summary.hide();
|
|
||||||
$(linkObj).removeClass('closed').addClass('opened');
|
|
||||||
$(trigger).attr('src',src.substring(0,src.length-10)+'open.png');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateStripes()
|
|
||||||
{
|
|
||||||
$('table.directory tr').
|
|
||||||
removeClass('even').filter(':visible:even').addClass('even');
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleLevel(level)
|
|
||||||
{
|
|
||||||
$('table.directory tr').each(function() {
|
|
||||||
var l = this.id.split('_').length-1;
|
|
||||||
var i = $('#img'+this.id.substring(3));
|
|
||||||
var a = $('#arr'+this.id.substring(3));
|
|
||||||
if (l<level+1) {
|
|
||||||
i.removeClass('iconfopen iconfclosed').addClass('iconfopen');
|
|
||||||
a.html('▼');
|
|
||||||
$(this).show();
|
|
||||||
} else if (l==level+1) {
|
|
||||||
i.removeClass('iconfclosed iconfopen').addClass('iconfclosed');
|
|
||||||
a.html('►');
|
|
||||||
$(this).show();
|
|
||||||
} else {
|
|
||||||
$(this).hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
updateStripes();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleFolder(id)
|
|
||||||
{
|
|
||||||
// the clicked row
|
|
||||||
var currentRow = $('#row_'+id);
|
|
||||||
|
|
||||||
// all rows after the clicked row
|
|
||||||
var rows = currentRow.nextAll("tr");
|
|
||||||
|
|
||||||
var re = new RegExp('^row_'+id+'\\d+_$', "i"); //only one sub
|
|
||||||
|
|
||||||
// only match elements AFTER this one (can't hide elements before)
|
|
||||||
var childRows = rows.filter(function() { return this.id.match(re); });
|
|
||||||
|
|
||||||
// first row is visible we are HIDING
|
|
||||||
if (childRows.filter(':first').is(':visible')===true) {
|
|
||||||
// replace down arrow by right arrow for current row
|
|
||||||
var currentRowSpans = currentRow.find("span");
|
|
||||||
currentRowSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
|
|
||||||
currentRowSpans.filter(".arrow").html('►');
|
|
||||||
rows.filter("[id^=row_"+id+"]").hide(); // hide all children
|
|
||||||
} else { // we are SHOWING
|
|
||||||
// replace right arrow by down arrow for current row
|
|
||||||
var currentRowSpans = currentRow.find("span");
|
|
||||||
currentRowSpans.filter(".iconfclosed").removeClass("iconfclosed").addClass("iconfopen");
|
|
||||||
currentRowSpans.filter(".arrow").html('▼');
|
|
||||||
// replace down arrows by right arrows for child rows
|
|
||||||
var childRowsSpans = childRows.find("span");
|
|
||||||
childRowsSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
|
|
||||||
childRowsSpans.filter(".arrow").html('►');
|
|
||||||
childRows.show(); //show all children
|
|
||||||
}
|
|
||||||
updateStripes();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function toggleInherit(id)
|
|
||||||
{
|
|
||||||
var rows = $('tr.inherit.'+id);
|
|
||||||
var img = $('tr.inherit_header.'+id+' img');
|
|
||||||
var src = $(img).attr('src');
|
|
||||||
if (rows.filter(':first').is(':visible')===true) {
|
|
||||||
rows.css('display','none');
|
|
||||||
$(img).attr('src',src.substring(0,src.length-8)+'closed.png');
|
|
||||||
} else {
|
|
||||||
rows.css('display','table-row'); // using show() causes jump in firefox
|
|
||||||
$(img).attr('src',src.substring(0,src.length-10)+'open.png');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 616 B |
|
Before Width: | Height: | Size: 597 B |
|
|
@ -1,73 +0,0 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
||||||
<meta name="generator" content="Doxygen 1.8.13"/>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
||||||
<title>Adafruit SPIFlash Library: Main Page</title>
|
|
||||||
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
||||||
<script type="text/javascript" src="jquery.js"></script>
|
|
||||||
<script type="text/javascript" src="dynsections.js"></script>
|
|
||||||
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
||||||
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
||||||
<script type="text/javascript" src="search/search.js"></script>
|
|
||||||
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
||||||
<div id="titlearea">
|
|
||||||
<table cellspacing="0" cellpadding="0">
|
|
||||||
<tbody>
|
|
||||||
<tr style="height: 56px;">
|
|
||||||
<td id="projectalign" style="padding-left: 0.5em;">
|
|
||||||
<div id="projectname">Adafruit SPIFlash Library
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<!-- end header part -->
|
|
||||||
<!-- Generated by Doxygen 1.8.13 -->
|
|
||||||
<script type="text/javascript">
|
|
||||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript" src="menudata.js"></script>
|
|
||||||
<script type="text/javascript" src="menu.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$(function() {
|
|
||||||
initMenu('',true,false,'search.php','Search');
|
|
||||||
$(document).ready(function() { init_search(); });
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<div id="main-nav"></div>
|
|
||||||
</div><!-- top -->
|
|
||||||
<!-- window showing the filter options -->
|
|
||||||
<div id="MSearchSelectWindow"
|
|
||||||
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
||||||
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
||||||
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- iframe showing the search results (closed by default) -->
|
|
||||||
<div id="MSearchResultsWindow">
|
|
||||||
<iframe src="javascript:void(0)" frameborder="0"
|
|
||||||
name="MSearchResults" id="MSearchResults">
|
|
||||||
</iframe>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="header">
|
|
||||||
<div class="headertitle">
|
|
||||||
<div class="title">Adafruit SPIFlash Library Documentation</div> </div>
|
|
||||||
</div><!--header-->
|
|
||||||
<div class="contents">
|
|
||||||
</div><!-- contents -->
|
|
||||||
<!-- start footer part -->
|
|
||||||
<hr class="footer"/><address class="footer"><small>
|
|
||||||
Generated by  <a href="http://www.doxygen.org/index.html">
|
|
||||||
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
||||||
</a> 1.8.13
|
|
||||||
</small></address>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
87
html/jquery.js
vendored
26
html/menu.js
|
|
@ -1,26 +0,0 @@
|
||||||
function initMenu(relPath,searchEnabled,serverSide,searchPage,search) {
|
|
||||||
function makeTree(data,relPath) {
|
|
||||||
var result='';
|
|
||||||
if ('children' in data) {
|
|
||||||
result+='<ul>';
|
|
||||||
for (var i in data.children) {
|
|
||||||
result+='<li><a href="'+relPath+data.children[i].url+'">'+
|
|
||||||
data.children[i].text+'</a>'+
|
|
||||||
makeTree(data.children[i],relPath)+'</li>';
|
|
||||||
}
|
|
||||||
result+='</ul>';
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#main-nav').append(makeTree(menudata,relPath));
|
|
||||||
$('#main-nav').children(':first').addClass('sm sm-dox').attr('id','main-menu');
|
|
||||||
if (searchEnabled) {
|
|
||||||
if (serverSide) {
|
|
||||||
$('#main-menu').append('<li style="float:right"><div id="MSearchBox" class="MSearchBoxInactive"><div class="left"><form id="FSearchBox" action="'+searchPage+'" method="get"><img id="MSearchSelect" src="'+relPath+'search/mag.png" alt=""/><input type="text" id="MSearchField" name="query" value="'+search+'" size="20" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)"></form></div><div class="right"></div></div></li>');
|
|
||||||
} else {
|
|
||||||
$('#main-menu').append('<li style="float:right"><div id="MSearchBox" class="MSearchBoxInactive"><span class="left"><img id="MSearchSelect" src="'+relPath+'search/mag_sel.png" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" alt=""/><input type="text" id="MSearchField" value="'+search+'" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)" onkeyup="searchBox.OnSearchFieldChange(event)"/></span><span class="right"><a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="'+relPath+'search/close.png" alt=""/></a></span></div></li>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$('#main-menu').smartmenus();
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
var menudata={children:[
|
|
||||||
{text:"Main Page",url:"index.html"}]}
|
|
||||||
BIN
html/nav_f.png
|
Before Width: | Height: | Size: 153 B |
BIN
html/nav_g.png
|
Before Width: | Height: | Size: 95 B |
BIN
html/nav_h.png
|
Before Width: | Height: | Size: 98 B |
BIN
html/open.png
|
Before Width: | Height: | Size: 123 B |
|
Before Width: | Height: | Size: 273 B |
|
Before Width: | Height: | Size: 563 B |
|
|
@ -1,12 +0,0 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html><head><title></title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
||||||
<link rel="stylesheet" type="text/css" href="search.css"/>
|
|
||||||
<script type="text/javascript" src="search.js"></script>
|
|
||||||
</head>
|
|
||||||
<body class="SRPage">
|
|
||||||
<div id="SRIndex">
|
|
||||||
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,271 +0,0 @@
|
||||||
/*---------------- Search Box */
|
|
||||||
|
|
||||||
#FSearchBox {
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
#MSearchBox {
|
|
||||||
white-space : nowrap;
|
|
||||||
float: none;
|
|
||||||
margin-top: 8px;
|
|
||||||
right: 0px;
|
|
||||||
width: 170px;
|
|
||||||
height: 24px;
|
|
||||||
z-index: 102;
|
|
||||||
}
|
|
||||||
|
|
||||||
#MSearchBox .left
|
|
||||||
{
|
|
||||||
display:block;
|
|
||||||
position:absolute;
|
|
||||||
left:10px;
|
|
||||||
width:20px;
|
|
||||||
height:19px;
|
|
||||||
background:url('search_l.png') no-repeat;
|
|
||||||
background-position:right;
|
|
||||||
}
|
|
||||||
|
|
||||||
#MSearchSelect {
|
|
||||||
display:block;
|
|
||||||
position:absolute;
|
|
||||||
width:20px;
|
|
||||||
height:19px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.left #MSearchSelect {
|
|
||||||
left:4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.right #MSearchSelect {
|
|
||||||
right:5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#MSearchField {
|
|
||||||
display:block;
|
|
||||||
position:absolute;
|
|
||||||
height:19px;
|
|
||||||
background:url('search_m.png') repeat-x;
|
|
||||||
border:none;
|
|
||||||
width:115px;
|
|
||||||
margin-left:20px;
|
|
||||||
padding-left:4px;
|
|
||||||
color: #909090;
|
|
||||||
outline: none;
|
|
||||||
font: 9pt Arial, Verdana, sans-serif;
|
|
||||||
-webkit-border-radius: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#FSearchBox #MSearchField {
|
|
||||||
margin-left:15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#MSearchBox .right {
|
|
||||||
display:block;
|
|
||||||
position:absolute;
|
|
||||||
right:10px;
|
|
||||||
top:8px;
|
|
||||||
width:20px;
|
|
||||||
height:19px;
|
|
||||||
background:url('search_r.png') no-repeat;
|
|
||||||
background-position:left;
|
|
||||||
}
|
|
||||||
|
|
||||||
#MSearchClose {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
top: 4px;
|
|
||||||
background : none;
|
|
||||||
border: none;
|
|
||||||
margin: 0px 4px 0px 0px;
|
|
||||||
padding: 0px 0px;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.left #MSearchClose {
|
|
||||||
left: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.right #MSearchClose {
|
|
||||||
right: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.MSearchBoxActive #MSearchField {
|
|
||||||
color: #000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------- Search filter selection */
|
|
||||||
|
|
||||||
#MSearchSelectWindow {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
left: 0; top: 0;
|
|
||||||
border: 1px solid #90A5CE;
|
|
||||||
background-color: #F9FAFC;
|
|
||||||
z-index: 10001;
|
|
||||||
padding-top: 4px;
|
|
||||||
padding-bottom: 4px;
|
|
||||||
-moz-border-radius: 4px;
|
|
||||||
-webkit-border-top-left-radius: 4px;
|
|
||||||
-webkit-border-top-right-radius: 4px;
|
|
||||||
-webkit-border-bottom-left-radius: 4px;
|
|
||||||
-webkit-border-bottom-right-radius: 4px;
|
|
||||||
-webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
|
|
||||||
}
|
|
||||||
|
|
||||||
.SelectItem {
|
|
||||||
font: 8pt Arial, Verdana, sans-serif;
|
|
||||||
padding-left: 2px;
|
|
||||||
padding-right: 12px;
|
|
||||||
border: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.SelectionMark {
|
|
||||||
margin-right: 4px;
|
|
||||||
font-family: monospace;
|
|
||||||
outline-style: none;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.SelectItem {
|
|
||||||
display: block;
|
|
||||||
outline-style: none;
|
|
||||||
color: #000000;
|
|
||||||
text-decoration: none;
|
|
||||||
padding-left: 6px;
|
|
||||||
padding-right: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.SelectItem:focus,
|
|
||||||
a.SelectItem:active {
|
|
||||||
color: #000000;
|
|
||||||
outline-style: none;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.SelectItem:hover {
|
|
||||||
color: #FFFFFF;
|
|
||||||
background-color: #3D578C;
|
|
||||||
outline-style: none;
|
|
||||||
text-decoration: none;
|
|
||||||
cursor: pointer;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------- Search results window */
|
|
||||||
|
|
||||||
iframe#MSearchResults {
|
|
||||||
width: 60ex;
|
|
||||||
height: 15em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#MSearchResultsWindow {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
left: 0; top: 0;
|
|
||||||
border: 1px solid #000;
|
|
||||||
background-color: #EEF1F7;
|
|
||||||
z-index:10000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------- */
|
|
||||||
|
|
||||||
|
|
||||||
#SRIndex {
|
|
||||||
clear:both;
|
|
||||||
padding-bottom: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.SREntry {
|
|
||||||
font-size: 10pt;
|
|
||||||
padding-left: 1ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.SRPage .SREntry {
|
|
||||||
font-size: 8pt;
|
|
||||||
padding: 1px 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
body.SRPage {
|
|
||||||
margin: 5px 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.SRChildren {
|
|
||||||
padding-left: 3ex; padding-bottom: .5em
|
|
||||||
}
|
|
||||||
|
|
||||||
.SRPage .SRChildren {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.SRSymbol {
|
|
||||||
font-weight: bold;
|
|
||||||
color: #425E97;
|
|
||||||
font-family: Arial, Verdana, sans-serif;
|
|
||||||
text-decoration: none;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.SRScope {
|
|
||||||
display: block;
|
|
||||||
color: #425E97;
|
|
||||||
font-family: Arial, Verdana, sans-serif;
|
|
||||||
text-decoration: none;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.SRSymbol:focus, a.SRSymbol:active,
|
|
||||||
a.SRScope:focus, a.SRScope:active {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.SRScope {
|
|
||||||
padding-left: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.SRPage .SRStatus {
|
|
||||||
padding: 2px 5px;
|
|
||||||
font-size: 8pt;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.SRResult {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
DIV.searchresults {
|
|
||||||
margin-left: 10px;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------- External search page results */
|
|
||||||
|
|
||||||
.searchresult {
|
|
||||||
background-color: #F0F3F8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pages b {
|
|
||||||
color: white;
|
|
||||||
padding: 5px 5px 3px 5px;
|
|
||||||
background-image: url("../tab_a.png");
|
|
||||||
background-repeat: repeat-x;
|
|
||||||
text-shadow: 0 1px 1px #000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pages {
|
|
||||||
line-height: 17px;
|
|
||||||
margin-left: 4px;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hl {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
#searchresults {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searchpages {
|
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,791 +0,0 @@
|
||||||
function convertToId(search)
|
|
||||||
{
|
|
||||||
var result = '';
|
|
||||||
for (i=0;i<search.length;i++)
|
|
||||||
{
|
|
||||||
var c = search.charAt(i);
|
|
||||||
var cn = c.charCodeAt(0);
|
|
||||||
if (c.match(/[a-z0-9\u0080-\uFFFF]/))
|
|
||||||
{
|
|
||||||
result+=c;
|
|
||||||
}
|
|
||||||
else if (cn<16)
|
|
||||||
{
|
|
||||||
result+="_0"+cn.toString(16);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result+="_"+cn.toString(16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getXPos(item)
|
|
||||||
{
|
|
||||||
var x = 0;
|
|
||||||
if (item.offsetWidth)
|
|
||||||
{
|
|
||||||
while (item && item!=document.body)
|
|
||||||
{
|
|
||||||
x += item.offsetLeft;
|
|
||||||
item = item.offsetParent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getYPos(item)
|
|
||||||
{
|
|
||||||
var y = 0;
|
|
||||||
if (item.offsetWidth)
|
|
||||||
{
|
|
||||||
while (item && item!=document.body)
|
|
||||||
{
|
|
||||||
y += item.offsetTop;
|
|
||||||
item = item.offsetParent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A class handling everything associated with the search panel.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
name - The name of the global variable that will be
|
|
||||||
storing this instance. Is needed to be able to set timeouts.
|
|
||||||
resultPath - path to use for external files
|
|
||||||
*/
|
|
||||||
function SearchBox(name, resultsPath, inFrame, label)
|
|
||||||
{
|
|
||||||
if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
|
|
||||||
|
|
||||||
// ---------- Instance variables
|
|
||||||
this.name = name;
|
|
||||||
this.resultsPath = resultsPath;
|
|
||||||
this.keyTimeout = 0;
|
|
||||||
this.keyTimeoutLength = 500;
|
|
||||||
this.closeSelectionTimeout = 300;
|
|
||||||
this.lastSearchValue = "";
|
|
||||||
this.lastResultsPage = "";
|
|
||||||
this.hideTimeout = 0;
|
|
||||||
this.searchIndex = 0;
|
|
||||||
this.searchActive = false;
|
|
||||||
this.insideFrame = inFrame;
|
|
||||||
this.searchLabel = label;
|
|
||||||
|
|
||||||
// ----------- DOM Elements
|
|
||||||
|
|
||||||
this.DOMSearchField = function()
|
|
||||||
{ return document.getElementById("MSearchField"); }
|
|
||||||
|
|
||||||
this.DOMSearchSelect = function()
|
|
||||||
{ return document.getElementById("MSearchSelect"); }
|
|
||||||
|
|
||||||
this.DOMSearchSelectWindow = function()
|
|
||||||
{ return document.getElementById("MSearchSelectWindow"); }
|
|
||||||
|
|
||||||
this.DOMPopupSearchResults = function()
|
|
||||||
{ return document.getElementById("MSearchResults"); }
|
|
||||||
|
|
||||||
this.DOMPopupSearchResultsWindow = function()
|
|
||||||
{ return document.getElementById("MSearchResultsWindow"); }
|
|
||||||
|
|
||||||
this.DOMSearchClose = function()
|
|
||||||
{ return document.getElementById("MSearchClose"); }
|
|
||||||
|
|
||||||
this.DOMSearchBox = function()
|
|
||||||
{ return document.getElementById("MSearchBox"); }
|
|
||||||
|
|
||||||
// ------------ Event Handlers
|
|
||||||
|
|
||||||
// Called when focus is added or removed from the search field.
|
|
||||||
this.OnSearchFieldFocus = function(isActive)
|
|
||||||
{
|
|
||||||
this.Activate(isActive);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.OnSearchSelectShow = function()
|
|
||||||
{
|
|
||||||
var searchSelectWindow = this.DOMSearchSelectWindow();
|
|
||||||
var searchField = this.DOMSearchSelect();
|
|
||||||
|
|
||||||
if (this.insideFrame)
|
|
||||||
{
|
|
||||||
var left = getXPos(searchField);
|
|
||||||
var top = getYPos(searchField);
|
|
||||||
left += searchField.offsetWidth + 6;
|
|
||||||
top += searchField.offsetHeight;
|
|
||||||
|
|
||||||
// show search selection popup
|
|
||||||
searchSelectWindow.style.display='block';
|
|
||||||
left -= searchSelectWindow.offsetWidth;
|
|
||||||
searchSelectWindow.style.left = left + 'px';
|
|
||||||
searchSelectWindow.style.top = top + 'px';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var left = getXPos(searchField);
|
|
||||||
var top = getYPos(searchField);
|
|
||||||
top += searchField.offsetHeight;
|
|
||||||
|
|
||||||
// show search selection popup
|
|
||||||
searchSelectWindow.style.display='block';
|
|
||||||
searchSelectWindow.style.left = left + 'px';
|
|
||||||
searchSelectWindow.style.top = top + 'px';
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop selection hide timer
|
|
||||||
if (this.hideTimeout)
|
|
||||||
{
|
|
||||||
clearTimeout(this.hideTimeout);
|
|
||||||
this.hideTimeout=0;
|
|
||||||
}
|
|
||||||
return false; // to avoid "image drag" default event
|
|
||||||
}
|
|
||||||
|
|
||||||
this.OnSearchSelectHide = function()
|
|
||||||
{
|
|
||||||
this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
|
|
||||||
this.closeSelectionTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when the content of the search field is changed.
|
|
||||||
this.OnSearchFieldChange = function(evt)
|
|
||||||
{
|
|
||||||
if (this.keyTimeout) // kill running timer
|
|
||||||
{
|
|
||||||
clearTimeout(this.keyTimeout);
|
|
||||||
this.keyTimeout = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
var e = (evt) ? evt : window.event; // for IE
|
|
||||||
if (e.keyCode==40 || e.keyCode==13)
|
|
||||||
{
|
|
||||||
if (e.shiftKey==1)
|
|
||||||
{
|
|
||||||
this.OnSearchSelectShow();
|
|
||||||
var win=this.DOMSearchSelectWindow();
|
|
||||||
for (i=0;i<win.childNodes.length;i++)
|
|
||||||
{
|
|
||||||
var child = win.childNodes[i]; // get span within a
|
|
||||||
if (child.className=='SelectItem')
|
|
||||||
{
|
|
||||||
child.focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (window.frames.MSearchResults.searchResults)
|
|
||||||
{
|
|
||||||
var elem = window.frames.MSearchResults.searchResults.NavNext(0);
|
|
||||||
if (elem) elem.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (e.keyCode==27) // Escape out of the search field
|
|
||||||
{
|
|
||||||
this.DOMSearchField().blur();
|
|
||||||
this.DOMPopupSearchResultsWindow().style.display = 'none';
|
|
||||||
this.DOMSearchClose().style.display = 'none';
|
|
||||||
this.lastSearchValue = '';
|
|
||||||
this.Activate(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// strip whitespaces
|
|
||||||
var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
|
|
||||||
|
|
||||||
if (searchValue != this.lastSearchValue) // search value has changed
|
|
||||||
{
|
|
||||||
if (searchValue != "") // non-empty search
|
|
||||||
{
|
|
||||||
// set timer for search update
|
|
||||||
this.keyTimeout = setTimeout(this.name + '.Search()',
|
|
||||||
this.keyTimeoutLength);
|
|
||||||
}
|
|
||||||
else // empty search field
|
|
||||||
{
|
|
||||||
this.DOMPopupSearchResultsWindow().style.display = 'none';
|
|
||||||
this.DOMSearchClose().style.display = 'none';
|
|
||||||
this.lastSearchValue = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.SelectItemCount = function(id)
|
|
||||||
{
|
|
||||||
var count=0;
|
|
||||||
var win=this.DOMSearchSelectWindow();
|
|
||||||
for (i=0;i<win.childNodes.length;i++)
|
|
||||||
{
|
|
||||||
var child = win.childNodes[i]; // get span within a
|
|
||||||
if (child.className=='SelectItem')
|
|
||||||
{
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.SelectItemSet = function(id)
|
|
||||||
{
|
|
||||||
var i,j=0;
|
|
||||||
var win=this.DOMSearchSelectWindow();
|
|
||||||
for (i=0;i<win.childNodes.length;i++)
|
|
||||||
{
|
|
||||||
var child = win.childNodes[i]; // get span within a
|
|
||||||
if (child.className=='SelectItem')
|
|
||||||
{
|
|
||||||
var node = child.firstChild;
|
|
||||||
if (j==id)
|
|
||||||
{
|
|
||||||
node.innerHTML='•';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
node.innerHTML=' ';
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when an search filter selection is made.
|
|
||||||
// set item with index id as the active item
|
|
||||||
this.OnSelectItem = function(id)
|
|
||||||
{
|
|
||||||
this.searchIndex = id;
|
|
||||||
this.SelectItemSet(id);
|
|
||||||
var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
|
|
||||||
if (searchValue!="" && this.searchActive) // something was found -> do a search
|
|
||||||
{
|
|
||||||
this.Search();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.OnSearchSelectKey = function(evt)
|
|
||||||
{
|
|
||||||
var e = (evt) ? evt : window.event; // for IE
|
|
||||||
if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
|
|
||||||
{
|
|
||||||
this.searchIndex++;
|
|
||||||
this.OnSelectItem(this.searchIndex);
|
|
||||||
}
|
|
||||||
else if (e.keyCode==38 && this.searchIndex>0) // Up
|
|
||||||
{
|
|
||||||
this.searchIndex--;
|
|
||||||
this.OnSelectItem(this.searchIndex);
|
|
||||||
}
|
|
||||||
else if (e.keyCode==13 || e.keyCode==27)
|
|
||||||
{
|
|
||||||
this.OnSelectItem(this.searchIndex);
|
|
||||||
this.CloseSelectionWindow();
|
|
||||||
this.DOMSearchField().focus();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------- Actions
|
|
||||||
|
|
||||||
// Closes the results window.
|
|
||||||
this.CloseResultsWindow = function()
|
|
||||||
{
|
|
||||||
this.DOMPopupSearchResultsWindow().style.display = 'none';
|
|
||||||
this.DOMSearchClose().style.display = 'none';
|
|
||||||
this.Activate(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.CloseSelectionWindow = function()
|
|
||||||
{
|
|
||||||
this.DOMSearchSelectWindow().style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Performs a search.
|
|
||||||
this.Search = function()
|
|
||||||
{
|
|
||||||
this.keyTimeout = 0;
|
|
||||||
|
|
||||||
// strip leading whitespace
|
|
||||||
var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
|
|
||||||
|
|
||||||
var code = searchValue.toLowerCase().charCodeAt(0);
|
|
||||||
var idxChar = searchValue.substr(0, 1).toLowerCase();
|
|
||||||
if ( 0xD800 <= code && code <= 0xDBFF && searchValue > 1) // surrogate pair
|
|
||||||
{
|
|
||||||
idxChar = searchValue.substr(0, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
var resultsPage;
|
|
||||||
var resultsPageWithSearch;
|
|
||||||
var hasResultsPage;
|
|
||||||
|
|
||||||
var idx = indexSectionsWithContent[this.searchIndex].indexOf(idxChar);
|
|
||||||
if (idx!=-1)
|
|
||||||
{
|
|
||||||
var hexCode=idx.toString(16);
|
|
||||||
resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
|
|
||||||
resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
|
|
||||||
hasResultsPage = true;
|
|
||||||
}
|
|
||||||
else // nothing available for this search term
|
|
||||||
{
|
|
||||||
resultsPage = this.resultsPath + '/nomatches.html';
|
|
||||||
resultsPageWithSearch = resultsPage;
|
|
||||||
hasResultsPage = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.frames.MSearchResults.location = resultsPageWithSearch;
|
|
||||||
var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
|
|
||||||
|
|
||||||
if (domPopupSearchResultsWindow.style.display!='block')
|
|
||||||
{
|
|
||||||
var domSearchBox = this.DOMSearchBox();
|
|
||||||
this.DOMSearchClose().style.display = 'inline';
|
|
||||||
if (this.insideFrame)
|
|
||||||
{
|
|
||||||
var domPopupSearchResults = this.DOMPopupSearchResults();
|
|
||||||
domPopupSearchResultsWindow.style.position = 'relative';
|
|
||||||
domPopupSearchResultsWindow.style.display = 'block';
|
|
||||||
var width = document.body.clientWidth - 8; // the -8 is for IE :-(
|
|
||||||
domPopupSearchResultsWindow.style.width = width + 'px';
|
|
||||||
domPopupSearchResults.style.width = width + 'px';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var domPopupSearchResults = this.DOMPopupSearchResults();
|
|
||||||
var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth;
|
|
||||||
var top = getYPos(domSearchBox) + 20; // domSearchBox.offsetHeight + 1;
|
|
||||||
domPopupSearchResultsWindow.style.display = 'block';
|
|
||||||
left -= domPopupSearchResults.offsetWidth;
|
|
||||||
domPopupSearchResultsWindow.style.top = top + 'px';
|
|
||||||
domPopupSearchResultsWindow.style.left = left + 'px';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lastSearchValue = searchValue;
|
|
||||||
this.lastResultsPage = resultsPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------- Activation Functions
|
|
||||||
|
|
||||||
// Activates or deactivates the search panel, resetting things to
|
|
||||||
// their default values if necessary.
|
|
||||||
this.Activate = function(isActive)
|
|
||||||
{
|
|
||||||
if (isActive || // open it
|
|
||||||
this.DOMPopupSearchResultsWindow().style.display == 'block'
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.DOMSearchBox().className = 'MSearchBoxActive';
|
|
||||||
|
|
||||||
var searchField = this.DOMSearchField();
|
|
||||||
|
|
||||||
if (searchField.value == this.searchLabel) // clear "Search" term upon entry
|
|
||||||
{
|
|
||||||
searchField.value = '';
|
|
||||||
this.searchActive = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!isActive) // directly remove the panel
|
|
||||||
{
|
|
||||||
this.DOMSearchBox().className = 'MSearchBoxInactive';
|
|
||||||
this.DOMSearchField().value = this.searchLabel;
|
|
||||||
this.searchActive = false;
|
|
||||||
this.lastSearchValue = ''
|
|
||||||
this.lastResultsPage = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
// The class that handles everything on the search results page.
|
|
||||||
function SearchResults(name)
|
|
||||||
{
|
|
||||||
// The number of matches from the last run of <Search()>.
|
|
||||||
this.lastMatchCount = 0;
|
|
||||||
this.lastKey = 0;
|
|
||||||
this.repeatOn = false;
|
|
||||||
|
|
||||||
// Toggles the visibility of the passed element ID.
|
|
||||||
this.FindChildElement = function(id)
|
|
||||||
{
|
|
||||||
var parentElement = document.getElementById(id);
|
|
||||||
var element = parentElement.firstChild;
|
|
||||||
|
|
||||||
while (element && element!=parentElement)
|
|
||||||
{
|
|
||||||
if (element.nodeName == 'DIV' && element.className == 'SRChildren')
|
|
||||||
{
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.nodeName == 'DIV' && element.hasChildNodes())
|
|
||||||
{
|
|
||||||
element = element.firstChild;
|
|
||||||
}
|
|
||||||
else if (element.nextSibling)
|
|
||||||
{
|
|
||||||
element = element.nextSibling;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
element = element.parentNode;
|
|
||||||
}
|
|
||||||
while (element && element!=parentElement && !element.nextSibling);
|
|
||||||
|
|
||||||
if (element && element!=parentElement)
|
|
||||||
{
|
|
||||||
element = element.nextSibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Toggle = function(id)
|
|
||||||
{
|
|
||||||
var element = this.FindChildElement(id);
|
|
||||||
if (element)
|
|
||||||
{
|
|
||||||
if (element.style.display == 'block')
|
|
||||||
{
|
|
||||||
element.style.display = 'none';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
element.style.display = 'block';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Searches for the passed string. If there is no parameter,
|
|
||||||
// it takes it from the URL query.
|
|
||||||
//
|
|
||||||
// Always returns true, since other documents may try to call it
|
|
||||||
// and that may or may not be possible.
|
|
||||||
this.Search = function(search)
|
|
||||||
{
|
|
||||||
if (!search) // get search word from URL
|
|
||||||
{
|
|
||||||
search = window.location.search;
|
|
||||||
search = search.substring(1); // Remove the leading '?'
|
|
||||||
search = unescape(search);
|
|
||||||
}
|
|
||||||
|
|
||||||
search = search.replace(/^ +/, ""); // strip leading spaces
|
|
||||||
search = search.replace(/ +$/, ""); // strip trailing spaces
|
|
||||||
search = search.toLowerCase();
|
|
||||||
search = convertToId(search);
|
|
||||||
|
|
||||||
var resultRows = document.getElementsByTagName("div");
|
|
||||||
var matches = 0;
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
while (i < resultRows.length)
|
|
||||||
{
|
|
||||||
var row = resultRows.item(i);
|
|
||||||
if (row.className == "SRResult")
|
|
||||||
{
|
|
||||||
var rowMatchName = row.id.toLowerCase();
|
|
||||||
rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
|
|
||||||
|
|
||||||
if (search.length<=rowMatchName.length &&
|
|
||||||
rowMatchName.substr(0, search.length)==search)
|
|
||||||
{
|
|
||||||
row.style.display = 'block';
|
|
||||||
matches++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
row.style.display = 'none';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
document.getElementById("Searching").style.display='none';
|
|
||||||
if (matches == 0) // no results
|
|
||||||
{
|
|
||||||
document.getElementById("NoMatches").style.display='block';
|
|
||||||
}
|
|
||||||
else // at least one result
|
|
||||||
{
|
|
||||||
document.getElementById("NoMatches").style.display='none';
|
|
||||||
}
|
|
||||||
this.lastMatchCount = matches;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the first item with index index or higher that is visible
|
|
||||||
this.NavNext = function(index)
|
|
||||||
{
|
|
||||||
var focusItem;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
var focusName = 'Item'+index;
|
|
||||||
focusItem = document.getElementById(focusName);
|
|
||||||
if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (!focusItem) // last element
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
focusItem=null;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
return focusItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.NavPrev = function(index)
|
|
||||||
{
|
|
||||||
var focusItem;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
var focusName = 'Item'+index;
|
|
||||||
focusItem = document.getElementById(focusName);
|
|
||||||
if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (!focusItem) // last element
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
focusItem=null;
|
|
||||||
index--;
|
|
||||||
}
|
|
||||||
return focusItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ProcessKeys = function(e)
|
|
||||||
{
|
|
||||||
if (e.type == "keydown")
|
|
||||||
{
|
|
||||||
this.repeatOn = false;
|
|
||||||
this.lastKey = e.keyCode;
|
|
||||||
}
|
|
||||||
else if (e.type == "keypress")
|
|
||||||
{
|
|
||||||
if (!this.repeatOn)
|
|
||||||
{
|
|
||||||
if (this.lastKey) this.repeatOn = true;
|
|
||||||
return false; // ignore first keypress after keydown
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (e.type == "keyup")
|
|
||||||
{
|
|
||||||
this.lastKey = 0;
|
|
||||||
this.repeatOn = false;
|
|
||||||
}
|
|
||||||
return this.lastKey!=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Nav = function(evt,itemIndex)
|
|
||||||
{
|
|
||||||
var e = (evt) ? evt : window.event; // for IE
|
|
||||||
if (e.keyCode==13) return true;
|
|
||||||
if (!this.ProcessKeys(e)) return false;
|
|
||||||
|
|
||||||
if (this.lastKey==38) // Up
|
|
||||||
{
|
|
||||||
var newIndex = itemIndex-1;
|
|
||||||
var focusItem = this.NavPrev(newIndex);
|
|
||||||
if (focusItem)
|
|
||||||
{
|
|
||||||
var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
|
|
||||||
if (child && child.style.display == 'block') // children visible
|
|
||||||
{
|
|
||||||
var n=0;
|
|
||||||
var tmpElem;
|
|
||||||
while (1) // search for last child
|
|
||||||
{
|
|
||||||
tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
|
|
||||||
if (tmpElem)
|
|
||||||
{
|
|
||||||
focusItem = tmpElem;
|
|
||||||
}
|
|
||||||
else // found it!
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (focusItem)
|
|
||||||
{
|
|
||||||
focusItem.focus();
|
|
||||||
}
|
|
||||||
else // return focus to search field
|
|
||||||
{
|
|
||||||
parent.document.getElementById("MSearchField").focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.lastKey==40) // Down
|
|
||||||
{
|
|
||||||
var newIndex = itemIndex+1;
|
|
||||||
var focusItem;
|
|
||||||
var item = document.getElementById('Item'+itemIndex);
|
|
||||||
var elem = this.FindChildElement(item.parentNode.parentNode.id);
|
|
||||||
if (elem && elem.style.display == 'block') // children visible
|
|
||||||
{
|
|
||||||
focusItem = document.getElementById('Item'+itemIndex+'_c0');
|
|
||||||
}
|
|
||||||
if (!focusItem) focusItem = this.NavNext(newIndex);
|
|
||||||
if (focusItem) focusItem.focus();
|
|
||||||
}
|
|
||||||
else if (this.lastKey==39) // Right
|
|
||||||
{
|
|
||||||
var item = document.getElementById('Item'+itemIndex);
|
|
||||||
var elem = this.FindChildElement(item.parentNode.parentNode.id);
|
|
||||||
if (elem) elem.style.display = 'block';
|
|
||||||
}
|
|
||||||
else if (this.lastKey==37) // Left
|
|
||||||
{
|
|
||||||
var item = document.getElementById('Item'+itemIndex);
|
|
||||||
var elem = this.FindChildElement(item.parentNode.parentNode.id);
|
|
||||||
if (elem) elem.style.display = 'none';
|
|
||||||
}
|
|
||||||
else if (this.lastKey==27) // Escape
|
|
||||||
{
|
|
||||||
parent.searchBox.CloseResultsWindow();
|
|
||||||
parent.document.getElementById("MSearchField").focus();
|
|
||||||
}
|
|
||||||
else if (this.lastKey==13) // Enter
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.NavChild = function(evt,itemIndex,childIndex)
|
|
||||||
{
|
|
||||||
var e = (evt) ? evt : window.event; // for IE
|
|
||||||
if (e.keyCode==13) return true;
|
|
||||||
if (!this.ProcessKeys(e)) return false;
|
|
||||||
|
|
||||||
if (this.lastKey==38) // Up
|
|
||||||
{
|
|
||||||
if (childIndex>0)
|
|
||||||
{
|
|
||||||
var newIndex = childIndex-1;
|
|
||||||
document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
|
|
||||||
}
|
|
||||||
else // already at first child, jump to parent
|
|
||||||
{
|
|
||||||
document.getElementById('Item'+itemIndex).focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.lastKey==40) // Down
|
|
||||||
{
|
|
||||||
var newIndex = childIndex+1;
|
|
||||||
var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
|
|
||||||
if (!elem) // last child, jump to parent next parent
|
|
||||||
{
|
|
||||||
elem = this.NavNext(itemIndex+1);
|
|
||||||
}
|
|
||||||
if (elem)
|
|
||||||
{
|
|
||||||
elem.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (this.lastKey==27) // Escape
|
|
||||||
{
|
|
||||||
parent.searchBox.CloseResultsWindow();
|
|
||||||
parent.document.getElementById("MSearchField").focus();
|
|
||||||
}
|
|
||||||
else if (this.lastKey==13) // Enter
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setKeyActions(elem,action)
|
|
||||||
{
|
|
||||||
elem.setAttribute('onkeydown',action);
|
|
||||||
elem.setAttribute('onkeypress',action);
|
|
||||||
elem.setAttribute('onkeyup',action);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setClassAttr(elem,attr)
|
|
||||||
{
|
|
||||||
elem.setAttribute('class',attr);
|
|
||||||
elem.setAttribute('className',attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createResults()
|
|
||||||
{
|
|
||||||
var results = document.getElementById("SRResults");
|
|
||||||
for (var e=0; e<searchData.length; e++)
|
|
||||||
{
|
|
||||||
var id = searchData[e][0];
|
|
||||||
var srResult = document.createElement('div');
|
|
||||||
srResult.setAttribute('id','SR_'+id);
|
|
||||||
setClassAttr(srResult,'SRResult');
|
|
||||||
var srEntry = document.createElement('div');
|
|
||||||
setClassAttr(srEntry,'SREntry');
|
|
||||||
var srLink = document.createElement('a');
|
|
||||||
srLink.setAttribute('id','Item'+e);
|
|
||||||
setKeyActions(srLink,'return searchResults.Nav(event,'+e+')');
|
|
||||||
setClassAttr(srLink,'SRSymbol');
|
|
||||||
srLink.innerHTML = searchData[e][1][0];
|
|
||||||
srEntry.appendChild(srLink);
|
|
||||||
if (searchData[e][1].length==2) // single result
|
|
||||||
{
|
|
||||||
srLink.setAttribute('href',searchData[e][1][1][0]);
|
|
||||||
if (searchData[e][1][1][1])
|
|
||||||
{
|
|
||||||
srLink.setAttribute('target','_parent');
|
|
||||||
}
|
|
||||||
var srScope = document.createElement('span');
|
|
||||||
setClassAttr(srScope,'SRScope');
|
|
||||||
srScope.innerHTML = searchData[e][1][1][2];
|
|
||||||
srEntry.appendChild(srScope);
|
|
||||||
}
|
|
||||||
else // multiple results
|
|
||||||
{
|
|
||||||
srLink.setAttribute('href','javascript:searchResults.Toggle("SR_'+id+'")');
|
|
||||||
var srChildren = document.createElement('div');
|
|
||||||
setClassAttr(srChildren,'SRChildren');
|
|
||||||
for (var c=0; c<searchData[e][1].length-1; c++)
|
|
||||||
{
|
|
||||||
var srChild = document.createElement('a');
|
|
||||||
srChild.setAttribute('id','Item'+e+'_c'+c);
|
|
||||||
setKeyActions(srChild,'return searchResults.NavChild(event,'+e+','+c+')');
|
|
||||||
setClassAttr(srChild,'SRScope');
|
|
||||||
srChild.setAttribute('href',searchData[e][1][c+1][0]);
|
|
||||||
if (searchData[e][1][c+1][1])
|
|
||||||
{
|
|
||||||
srChild.setAttribute('target','_parent');
|
|
||||||
}
|
|
||||||
srChild.innerHTML = searchData[e][1][c+1][2];
|
|
||||||
srChildren.appendChild(srChild);
|
|
||||||
}
|
|
||||||
srEntry.appendChild(srChildren);
|
|
||||||
}
|
|
||||||
srResult.appendChild(srEntry);
|
|
||||||
results.appendChild(srResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function init_search()
|
|
||||||
{
|
|
||||||
var results = document.getElementById("MSearchSelectWindow");
|
|
||||||
for (var key in indexSectionLabels)
|
|
||||||
{
|
|
||||||
var link = document.createElement('a');
|
|
||||||
link.setAttribute('class','SelectItem');
|
|
||||||
link.setAttribute('onclick','searchBox.OnSelectItem('+key+')');
|
|
||||||
link.href='javascript:void(0)';
|
|
||||||
link.innerHTML='<span class="SelectionMark"> </span>'+indexSectionLabels[key];
|
|
||||||
results.appendChild(link);
|
|
||||||
}
|
|
||||||
searchBox.OnSelectItem(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 604 B |
|
Before Width: | Height: | Size: 158 B |
|
Before Width: | Height: | Size: 612 B |
|
|
@ -1,12 +0,0 @@
|
||||||
var indexSectionsWithContent =
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
var indexSectionNames =
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
var indexSectionLabels =
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 314 B |
|
Before Width: | Height: | Size: 853 B |
BIN
html/sync_on.png
|
Before Width: | Height: | Size: 845 B |
BIN
html/tab_a.png
|
Before Width: | Height: | Size: 142 B |
BIN
html/tab_b.png
|
Before Width: | Height: | Size: 169 B |
BIN
html/tab_h.png
|
Before Width: | Height: | Size: 177 B |
BIN
html/tab_s.png
|
Before Width: | Height: | Size: 184 B |
11
index.html
|
|
@ -1,11 +0,0 @@
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html lang="en-US">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="refresh" content="1;url=html/index.html">
|
|
||||||
<title>Page Redirection</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
If you are not redirected automatically, follow the <a href="html/index.html">link to the documentation</a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
10
library.properties
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
name=Adafruit SPIFlash
|
||||||
|
version=5.1.1
|
||||||
|
author=Adafruit
|
||||||
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
|
sentence=SPI Flash filesystem support for FAT and CircuitPython FS support from within Arduino
|
||||||
|
paragraph=SPI Flash filesystem support for FAT and CircuitPython FS support from within Arduino
|
||||||
|
category=Data Storage
|
||||||
|
url=https://github.com/adafruit/Adafruit_SPIFlash
|
||||||
|
architectures=*
|
||||||
|
depends=Adafruit NeoPixel, SdFat - Adafruit Fork
|
||||||
135
src/Adafruit_FlashCache.cpp
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 hathach for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Adafruit_FlashCache.h"
|
||||||
|
#include "Adafruit_SPIFlashBase.h"
|
||||||
|
|
||||||
|
#if SPIFLASH_DEBUG
|
||||||
|
#define SPICACHE_LOG(_new_addr) \
|
||||||
|
do { \
|
||||||
|
Serial.print(__FUNCTION__); \
|
||||||
|
Serial.print(": flush sector = "); \
|
||||||
|
Serial.print(_addr / 512); \
|
||||||
|
Serial.print(", new sector = "); \
|
||||||
|
Serial.println(_new_addr / 512); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define SPICACHE_LOG(_new_addr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define INVALID_ADDR 0xffffffff
|
||||||
|
|
||||||
|
static inline uint32_t sector_of(uint32_t addr) {
|
||||||
|
return addr & ~(SFLASH_SECTOR_SIZE - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t offset_of(uint32_t addr) {
|
||||||
|
return addr & (SFLASH_SECTOR_SIZE - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Adafruit_FlashCache::Adafruit_FlashCache(void) { _addr = INVALID_ADDR; }
|
||||||
|
|
||||||
|
bool Adafruit_FlashCache::sync(Adafruit_SPIFlashBase *fl) {
|
||||||
|
if (_addr == INVALID_ADDR) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fl->eraseSector(_addr / SFLASH_SECTOR_SIZE);
|
||||||
|
fl->writeBuffer(_addr, _buf, SFLASH_SECTOR_SIZE);
|
||||||
|
|
||||||
|
_addr = INVALID_ADDR;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_FlashCache::write(Adafruit_SPIFlashBase *fl, uint32_t address,
|
||||||
|
void const *src, uint32_t len) {
|
||||||
|
uint8_t const *src8 = (uint8_t const *)src;
|
||||||
|
uint32_t remain = len;
|
||||||
|
|
||||||
|
// Program up to sector boundary each loop
|
||||||
|
while (remain) {
|
||||||
|
uint32_t const sector_addr = sector_of(address);
|
||||||
|
uint32_t const offset = offset_of(address);
|
||||||
|
|
||||||
|
uint32_t wr_bytes = SFLASH_SECTOR_SIZE - offset;
|
||||||
|
wr_bytes = min(remain, wr_bytes);
|
||||||
|
|
||||||
|
// Flash sector changes, flush old and update new cache
|
||||||
|
if (sector_addr != _addr) {
|
||||||
|
SPICACHE_LOG(sector_addr);
|
||||||
|
this->sync(fl);
|
||||||
|
_addr = sector_addr;
|
||||||
|
|
||||||
|
// read a whole page from flash
|
||||||
|
fl->readBuffer(sector_addr, _buf, SFLASH_SECTOR_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(_buf + offset, src8, wr_bytes);
|
||||||
|
|
||||||
|
// adjust for next run
|
||||||
|
src8 += wr_bytes;
|
||||||
|
remain -= wr_bytes;
|
||||||
|
address += wr_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_FlashCache::read(Adafruit_SPIFlashBase *fl, uint32_t address,
|
||||||
|
uint8_t *buffer, uint32_t count) {
|
||||||
|
// overwrite with cache value if available
|
||||||
|
if ((_addr != INVALID_ADDR) &&
|
||||||
|
!(address < _addr && address + count <= _addr) &&
|
||||||
|
!(address >= _addr + SFLASH_SECTOR_SIZE)) {
|
||||||
|
int32_t dst_off = _addr - address;
|
||||||
|
int32_t src_off = 0;
|
||||||
|
|
||||||
|
if (dst_off < 0) {
|
||||||
|
src_off = -dst_off;
|
||||||
|
dst_off = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t cache_bytes = min((int32_t)(SFLASH_SECTOR_SIZE - src_off),
|
||||||
|
(int32_t)(count - dst_off));
|
||||||
|
|
||||||
|
// start to cached
|
||||||
|
if (dst_off) {
|
||||||
|
fl->readBuffer(address, buffer, dst_off);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cached
|
||||||
|
memcpy(buffer + dst_off, _buf + src_off, cache_bytes);
|
||||||
|
|
||||||
|
// cached to end
|
||||||
|
uint32_t copied = (uint32_t)(dst_off + cache_bytes);
|
||||||
|
if (copied < count) {
|
||||||
|
fl->readBuffer(address + copied, buffer + copied, count - copied);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fl->readBuffer(address, buffer, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
49
src/Adafruit_FlashCache.h
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 hathach for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADAFRUIT_FLASHCACHE_H_
|
||||||
|
#define ADAFRUIT_FLASHCACHE_H_
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
class Adafruit_SPIFlashBase;
|
||||||
|
|
||||||
|
class Adafruit_FlashCache {
|
||||||
|
private:
|
||||||
|
uint8_t _buf[4096] __attribute__((aligned(4))); // must be sector size
|
||||||
|
uint32_t _addr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Adafruit_FlashCache(void);
|
||||||
|
|
||||||
|
bool sync(Adafruit_SPIFlashBase *fl);
|
||||||
|
bool write(Adafruit_SPIFlashBase *fl, uint32_t dst, void const *src,
|
||||||
|
uint32_t len);
|
||||||
|
bool read(Adafruit_SPIFlashBase *fl, uint32_t addr, uint8_t *dst,
|
||||||
|
uint32_t count);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ADAFRUIT_FLASHCACHE_H_ */
|
||||||
147
src/Adafruit_FlashTransport.h
Normal file
|
|
@ -0,0 +1,147 @@
|
||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 hathach for Adafruit Industries
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADAFRUIT_FLASHTRANSPORT_H_
|
||||||
|
#define ADAFRUIT_FLASHTRANSPORT_H_
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SFLASH_CMD_READ = 0x03, // Single Read
|
||||||
|
SFLASH_CMD_FAST_READ = 0x0B, // Fast Read
|
||||||
|
SFLASH_CMD_QUAD_READ = 0x6B, // 1 line address, 4 line data
|
||||||
|
|
||||||
|
SFLASH_CMD_READ_JEDEC_ID = 0x9f,
|
||||||
|
|
||||||
|
SFLASH_CMD_PAGE_PROGRAM = 0x02,
|
||||||
|
SFLASH_CMD_QUAD_PAGE_PROGRAM = 0x32, // 1 line address, 4 line data
|
||||||
|
|
||||||
|
SFLASH_CMD_READ_STATUS = 0x05,
|
||||||
|
SFLASH_CMD_READ_STATUS2 = 0x35,
|
||||||
|
|
||||||
|
SFLASH_CMD_WRITE_STATUS = 0x01,
|
||||||
|
SFLASH_CMD_WRITE_STATUS2 = 0x31,
|
||||||
|
|
||||||
|
SFLASH_CMD_ENABLE_RESET = 0x66,
|
||||||
|
SFLASH_CMD_RESET = 0x99,
|
||||||
|
|
||||||
|
SFLASH_CMD_WRITE_ENABLE = 0x06,
|
||||||
|
SFLASH_CMD_WRITE_DISABLE = 0x04,
|
||||||
|
|
||||||
|
SFLASH_CMD_ERASE_PAGE = 0x81,
|
||||||
|
SFLASH_CMD_ERASE_SECTOR = 0x20,
|
||||||
|
SFLASH_CMD_ERASE_BLOCK = 0xD8,
|
||||||
|
SFLASH_CMD_ERASE_CHIP = 0xC7,
|
||||||
|
|
||||||
|
SFLASH_CMD_4_BYTE_ADDR = 0xB7,
|
||||||
|
SFLASH_CMD_3_BYTE_ADDR = 0xE9,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Constant that is (mostly) true to all external flash devices
|
||||||
|
enum {
|
||||||
|
SFLASH_BLOCK_SIZE = 64 * 1024UL,
|
||||||
|
SFLASH_SECTOR_SIZE = 4 * 1024,
|
||||||
|
SFLASH_PAGE_SIZE = 256,
|
||||||
|
};
|
||||||
|
|
||||||
|
class Adafruit_FlashTransport {
|
||||||
|
public:
|
||||||
|
virtual void begin(void) = 0;
|
||||||
|
virtual void end(void) = 0;
|
||||||
|
|
||||||
|
virtual bool supportQuadMode(void) = 0;
|
||||||
|
|
||||||
|
/// Set clock speed in hertz
|
||||||
|
/// @param write_hz Write clock speed in hertz
|
||||||
|
/// @param read_hz Read clock speed in hertz
|
||||||
|
virtual void setClockSpeed(uint32_t write_hz, uint32_t read_hz) = 0;
|
||||||
|
|
||||||
|
/// Execute a single byte command e.g Reset, Write Enable
|
||||||
|
/// @param command command code
|
||||||
|
/// @return true if success
|
||||||
|
virtual bool runCommand(uint8_t command) = 0;
|
||||||
|
|
||||||
|
/// Execute a command with response data e.g Read Status, Read JEDEC
|
||||||
|
/// @param command command code
|
||||||
|
/// @param response buffer to hold data
|
||||||
|
/// @param len number of bytes to read
|
||||||
|
/// @return true if success
|
||||||
|
virtual bool readCommand(uint8_t command, uint8_t *response,
|
||||||
|
uint32_t len) = 0;
|
||||||
|
|
||||||
|
/// Execute a command with data e.g Write Status,
|
||||||
|
/// @param command command code
|
||||||
|
/// @param data writing data
|
||||||
|
/// @param len number of bytes to read
|
||||||
|
/// @return true if success
|
||||||
|
virtual bool writeCommand(uint8_t command, uint8_t const *data,
|
||||||
|
uint32_t len) = 0;
|
||||||
|
|
||||||
|
/// Erase external flash by address
|
||||||
|
/// @param command can be sector erase (0x20) or block erase 0xD8
|
||||||
|
/// @param address address to be erased
|
||||||
|
/// @return true if success
|
||||||
|
virtual bool eraseCommand(uint8_t command, uint32_t address) = 0;
|
||||||
|
|
||||||
|
/// Read data from external flash contents. Typically it is implemented by
|
||||||
|
/// quad read command 0x6B
|
||||||
|
/// @param addr address to read
|
||||||
|
/// @param buffer buffer to hold data
|
||||||
|
/// @param len number of byte to read
|
||||||
|
/// @return true if success
|
||||||
|
virtual bool readMemory(uint32_t addr, uint8_t *buffer, uint32_t len) = 0;
|
||||||
|
|
||||||
|
/// Write data to external flash contents, flash sector must be previously
|
||||||
|
/// erased first. Typically it uses quad write command 0x32
|
||||||
|
/// @param addr address to read
|
||||||
|
/// @param data writing data
|
||||||
|
/// @param len number of byte to read
|
||||||
|
/// @return true if success
|
||||||
|
virtual bool writeMemory(uint32_t addr, uint8_t const *data,
|
||||||
|
uint32_t len) = 0;
|
||||||
|
|
||||||
|
void setAddressLength(uint8_t addr_len) { _addr_len = addr_len; }
|
||||||
|
void setReadCommand(uint8_t cmd_read) { _cmd_read = cmd_read; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Number of bytes for address
|
||||||
|
uint8_t _addr_len;
|
||||||
|
|
||||||
|
// Command use for read operation
|
||||||
|
uint8_t _cmd_read;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "qspi/Adafruit_FlashTransport_QSPI.h"
|
||||||
|
#include "spi/Adafruit_FlashTransport_SPI.h"
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
#include "esp32/Adafruit_FlashTransport_ESP32.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_RP2040
|
||||||
|
#include "rp2040/Adafruit_FlashTransport_RP2040.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ADAFRUIT_FLASHTRANSPORT_H_ */
|
||||||