From 41a0990fed573fbff1f6aaee21ffd321ef97c959 Mon Sep 17 00:00:00 2001 From: Prajwal Bhattaram Date: Sun, 30 Aug 2015 21:14:50 +1000 Subject: [PATCH] v1.3.0 final --- Changes.log | 9 + LICENSE | 1350 ++++++------- README.md | 209 +- SPIFlash.cpp | 1718 ++++++++++------- SPIFlash.h | 221 ++- examples/Data_writer/Data_writer.ino | 88 + examples/Diagnostics/Diagnostics.ino | 209 ++ examples/TestFlash/TestFlash.ino | 161 +- examples/TestFlash/command_list.ino | 40 +- ...nbond Flash Instructions - Comparison.xlsx | Bin 0 -> 41353 bytes keywords.txt | 93 +- library.properties | 18 +- 12 files changed, 2518 insertions(+), 1598 deletions(-) create mode 100644 Changes.log create mode 100644 examples/Data_writer/Data_writer.ino create mode 100644 examples/Diagnostics/Diagnostics.ino create mode 100644 extras/Winbond Flash Instructions - Comparison.xlsx diff --git a/Changes.log b/Changes.log new file mode 100644 index 0000000..1e315dd --- /dev/null +++ b/Changes.log @@ -0,0 +1,9 @@ +--> Updated ReadMe.md has all information needed to use the library. +--> v1.3.0 is faster and lighter than previous versions. +--> The library is optimised to work with the following Winbond Flash modules W25X05CL, W25X10BV, W25X20BV, W25X40BV, W25Q80BV, W25Q16BV, W25Q32BV, W25Q64BV, W25Q128BV & W25Q256FV. +--> _addressCheck() built into every read/write function. +--> _errorCheck() built into every write function. +--> The library now supports readAnything() & writeAnything(). +--> There are now specific functions for reading and writing different types of variables - refer to ReadMe.md for further details. +--> All Read/Write functions now carry out a series of checks to keep data corruption to a minimum +--> Added a diagnostic function to enable error code generation and checking - Follow instruction in the "Diagnostics.ino" example diff --git a/LICENSE b/LICENSE index 733c072..f015d11 100644 --- a/LICENSE +++ b/LICENSE @@ -1,675 +1,675 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. - + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + diff --git a/README.md b/README.md index 46d62d9..4c82ed7 100644 --- a/README.md +++ b/README.md @@ -1,88 +1,121 @@ -# SPIFlash -### Arduino library for Winbond Flash W25Q80BV - Download the latest stable release (v1.2.1) from here. Please report any bugs in issues. - -This library is for the W25Q80BV serial flash memory chip. In its current form it enables reading and writing bytes from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes; sector, block and chip erase; and powering down for low power operation. - -- The W25Q80BV has a capacity of 64 Mbits (1 Megabyte) which consists of 4096 pages of 256 bytes each. -- Its memory registers are arranged in 16 blocks of 64KB each -- Byte addresses are 24 bit and range from 0x00000 to 0xFFFFF (00000 to 1048575 - decimal) - -#### Installation -- Click on the 'Download zip' button to the right. -- Unzip the archive and rename resulting folder to 'SPIFlash' -- Move the folder to your libraries folder (~/sketches/libraries) - -#### Usage - -The library is called by declaring the```SPIFLASH flash(csPin)``` constructor where 'flash' can be replaced by a user constructor of choice and 'csPin' is the Chip Select pin for the flash module. -Make sure to include ```#include``` when you include ```#include```. - -###### Notes on Address overflow and Error checking -- The library has Address overflow enabled by default - i.e. if the last address read/written from/to, in any function, is 0xFFFFF then, the next address read/written from/to is 0x00000. This can be disabled by setting the optional last 'overflow' argument in the constructor to false - For eg. call the constructor ```SPIFlash(csPin, false)``` instead of ```SPIFlash(csPin)```. -- All write functions have Error checking turned on by default - i.e. every byte written to the flash memory will be checked against the data stored on the Arduino. Users who require greater write speeds can disable this function by setting an optional last 'errorCheck' argument in any write function to false - For eg. call the function ```writePage(page_number, *data_buffer, false)``` instead of ```writePage(page_number, *data_buffer)```. - -The library enables the following functions: -
-##### getID () -Fetches the JEDEC ID as a 32 bit number. -
-##### Continuous read/write commands -###### readBytes(page_number, offset, *data_buffer) -Reads an array of bytes starting from a specific location in a page. Takes the page number (0-4095), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be read from the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of n **bytes**. 'n' is determined by the amount of storage available on the Arduino board. -###### writeBytes(page_number, offset, *data_buffer) -Writes an array of bytes starting from a specific location in a page. Takes the page number (0-4095), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be written to the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of 'n' **bytes**. The number of bytes - 'n' - is determined by the amount of storage available on the Arduino board. -
-##### Read commands -###### readByte(page_number, offset) -Reads a byte of data from a specific location on a page. Takes the page number (0-4095) and offset of data byte within page (0-255) as arguments. -###### readPage(page_number, *data_buffer, outputType) -Reads a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. Setting an outputType of 1 enables output in hexadecimal while an outputType of 2 enables output in decimal, CSV - over Serial. -
-##### Write commands -###### writeByte(page, offset, data) -Writes a byte of data to a specific location on a page. Takes the page number (0-4095), offset of data byte within page (0-255) and one byte of data (0-255) as arguments. -###### writePage(page_number, *data_buffer) -Writes a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. -
-##### Erase commands -###### eraseSector(page_number) -Erases one 4KB sector - 16 pages - containing the page to be erased. The sectors are numbered 0 - 255 containing 16 pages each. -Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255. -###### eraseBlock32K(page_number) -Erases one 32KB block - 128 pages - containing the page to be erased. The blocks are numbered 0 - 31 containing 128 pages each. -Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31. -###### eraseBlock64K(page_number) -Erases one 64KB block - 256 pages - containing the page to be erased. The blocks are numbered 0 - 15 containing 256 pages each. -// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15. -###### eraseChip() -Erases entire chip. Use with care. -
-##### Suspend/Resume commands -###### suspendProg() -Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). Page Program, Write Status Register, Erase instructions are not allowed. Erase suspend is only allowed during Block/Sector erase. Program suspend is only allowed during Page/Quad Page Program -###### resumeProg() -Resumes previously suspended Block Erase/Sector Erase/Page Program. -
-##### Power operation commands -###### powerDown() -Puts device in low power state. Useful for battery powered operations. Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4). In powerDown() the chip will only respond to powerUp() -###### powerUp() -//Wakes chip from low power state. -
-##### readAllPages() -Reads all pages on Flash chip and dumps it to Serial stream. This function is useful when extracting data from a flash chip onto a computer as a text file. - -###### How to get data off Flash memory via Serial -(Works only for Unix based Operating Systems) - - - Make sure you include code to let you dump entire flash memory/specific page's content to Serial (Refer to the code in the _TestFlash.h_ for details on how to do this) - - Connect your arduino to the computer. - - Open the Arduino IDE, the IDE's Serial Monitor, and an OSX POSIX terminal. - - Type the following command into the terminal window. ```% tail -f /dev/tty.usbmodem1411 > FlashDump.txt``` Make sure to replace the _/dev/tty.usbmodem1411_ with the port your arduino is connected to. (You can find this in Tools --> Ports in Arduino IDE 1.6.x) - - Then type the command to read all pages into the Serial console. If you use my code from the example file the command is ```read_all_pages``` - - Wait a few seconds before typing ```Ctrl+C``` to end the tail process - - Check that you have actually recieved all the data by typing ```% cat FlashDump.txt```. This should output the entire textfile into your terminal window. - - - +# SPIFlash +### Arduino library for Winbond Flash Memory Chips + Download the latest stable release (v1.3.0) from here. Please report any bugs in issues. + +This library is for a the Winbond serial flash memory chips. In its current form it enables reading and writing bytes from and to various locations; reading and writing pages of bytes; continous reading/writing of data from/to arrays of bytes; sector, block and chip erase; and powering down for low power operation. + +- For details of the Winbond Flash chips compatible with this library please refer to the Excel spreadsheet in the Extras folder. + +#### Installation +- Click on the 'Download zip' button to the right. +- Unzip the archive and rename resulting folder to 'SPIFlash' +- Move the folder to your libraries folder (~/sketches/libraries) + +#### Usage + +The library is called by declaring the```SPIFLASH flash(csPin)``` constructor where 'flash' can be replaced by a user constructor of choice and 'csPin' is the Chip Select pin for the flash module. +Make sure to include ```#include``` when you include ```#include```. +Also make sure to include ```flash.begin()``` in ```void setup()```. This enables the library to detect the type of flash chip installed and load the right parameters. + +###### Notes on Address overflow and Error checking +- The library has Address overflow enabled by default - i.e. if the last address read/written from/to, in any function, is 0xFFFFF then, the next address read/written from/to is 0x00000. This can be disabled by setting the optional last 'overflow' argument in the constructor to false - For eg. call the constructor ```SPIFlash(csPin, false)``` instead of ```SPIFlash(csPin)```. +- All write functions have Error checking turned on by default - i.e. every byte written to the flash memory will be checked against the data stored on the Arduino. Users who require greater write speeds can disable this function by setting an optional last 'errorCheck' argument in any write function to false - For eg. call the function ```writePage(page_number, *data_buffer, false)``` instead of ```writePage(page_number, *data_buffer)```. + +The library enables the following functions: +
+##### Primary commands +###### begin() +Must be called at the start in setup(). This function detects the type of chip being used and sets parameters accordingly +###### getID() +Fetches the JEDEC ID as a 32 bit number. +
+##### Read commands +###### readAnything(page_number, offset, value) +Reads _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-4095), the offset of the data within page (0-255) and the variable/struct to write the data back to, as arguments. +###### readByte(page_number, offset) +Reads a _byte_ (unsigned 8 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the byte within page (0-255) as arguments. +###### readChar(page_number, offset) +Reads a _char_ (signed 8 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the char within page (0-255) as arguments. +###### readWord(page_number, offset) +Reads a _word_ (unsigned 16 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the word within page (0-255) as arguments. +###### readShort(page_number, offset) +Reads a _short_ (signed 16 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the short within page (0-255) as arguments. +###### readULong(page_number, offset) +Reads an _unsigned long_ (unsigned 32 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the unsigned long within page (0-255) as arguments. +###### readLong(page_number, offset) +Reads a _long_ (signed 32 bit value) from a specific location on a page. Takes the page number (0-4095) and offset of the long within page (0-255) as arguments. +###### readFloat(page_number, offset) +Reads a _float_ (decimal value) from a specific location on a page. Takes the page number (0-4095) and offset of the float within page (0-255) as arguments. +###### readPage(page_number, *data_buffer) +Reads a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. +
+##### Write commands +###### writeByte(page, offset, data) +Writes a byte of data to a specific location on a page. Takes the page number (0-4095), offset of data byte within page (0-255) and one byte of data (0-255) as arguments. +###### writeChar(page_number, offset, data) +Writes a _char_ (signed 8 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the char and one char of data within page (0-255) as arguments. +###### writeWord(page_number, offset, data) +Writes a _word_ (unsigned 16 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the word and one word of data within page (0-255) as arguments. +###### writeShort(page_number, offset, data) +Writes a _short_ (signed 16 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the short and one short of data within page (0-255) as arguments. +###### writeULong(page_number, offset, data) +Writes an _unsigned long_ (unsigned 32 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the unsigned long and one unsigned long of data within page (0-255) as arguments. +###### writeLong(page_number, offset, data) +Writes a _long_ (signed 32 bit value) to a specific location on a page. Takes the page number (0-4095), the offset of the long and one long of data within page (0-255) as arguments. +###### writeFloat(page_number, offset, data) +Writes a _float_ (decimal value) to a specific location on a page. Takes the page number (0-4095), the offset of the float and one float of data within page (0-255) as arguments. +###### writePage(page_number, *data_buffer) +Writes a page worth of data into a data buffer array for further use. ```uint8_t data_buffer[256];``` The data buffer **must** be an array of 256 bytes. +###### writeAnything(page_number, offset, value) +Writes _any type of variable/struct_ (any sized value) from a specific location on a page. Takes the page number (0-4095), the offset of the data within page (0-255) and the variable/struct to write the data from, as arguments. +
+##### Continuous read/write commands +###### readBytes(page_number, offset, *data_buffer) +Reads an array of bytes starting from a specific location in a page. Takes the page number (0-4095), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be read from the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of n **bytes**. 'n' is determined by the amount of storage available on the Arduino board. +###### writeBytes(page_number, offset, *data_buffer) +Writes an array of bytes starting from a specific location in a page. Takes the page number (0-4095), offset of data byte within page (0-255) and a data_buffer - i.e. an array of bytes to be written to the flash memory - as arguments. ```uint8_t data_buffer[n];``` The data buffer **must** be an array of 'n' **bytes**. The number of bytes - 'n' - is determined by the amount of storage available on the Arduino board. +
+##### Erase commands +###### eraseSector(page_number) +Erases one 4KB sector - 16 pages - containing the page to be erased. The sectors are numbered 0 - 255 containing 16 pages each. +Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255. +###### eraseBlock32K(page_number) +Erases one 32KB block - 128 pages - containing the page to be erased. The blocks are numbered 0 - 31 containing 128 pages each. +Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31. +###### eraseBlock64K(page_number) +Erases one 64KB block - 256 pages - containing the page to be erased. The blocks are numbered 0 - 15 containing 256 pages each. +// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15. +###### eraseChip() +Erases entire chip. Use with care. +
+##### Suspend/Resume commands +###### suspendProg() +Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). Page Program, Write Status Register, Erase instructions are not allowed. Erase suspend is only allowed during Block/Sector erase. Program suspend is only allowed during Page/Quad Page Program +###### resumeProg() +Resumes previously suspended Block Erase/Sector Erase/Page Program. +
+##### Power operation commands +###### powerDown() +Puts device in low power state. Useful for battery powered operations. Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4). In powerDown() the chip will only respond to powerUp() +###### powerUp() +//Wakes chip from low power state. +
+##### printPage(page_number, outputType) +Reads a page worth of data into a data buffer array for further useand prints to a Serial stream at 115200 baud by default. (The baudrate can be changed by calling ```Serial.begin()``` at a different baudrate in ``` void setup()```)Setting an outputType of 1 enables output in hexadecimal while an outputType of 2 enables output in decimal, CSV - over Serial. +
+##### printAllPages() +Reads all pages on Flash chip and dumps it to Serial stream. This function is useful when extracting data from a flash chip onto a computer as a text file. + +###### How to get data off Flash memory via Serial +(Works only for Unix based Operating Systems) + + - Make sure you include code to let you dump entire flash memory/specific page's content to Serial (Refer to the code in the _TestFlash.h_ for details on how to do this) + - Connect your arduino to the computer. + - Open the Arduino IDE, the IDE's Serial Monitor, and an OSX POSIX terminal. + - Type the following command into the terminal window. ```% tail -f /dev/tty.usbmodem1411 > FlashDump.txt``` Make sure to replace the _/dev/tty.usbmodem1411_ with the port your arduino is connected to. (You can find this in Tools --> Ports in Arduino IDE 1.6.x) + - Then type the command to read all pages into the Serial console. If you use my code from the example file the command is ```read_all_pages``` + - Wait a few seconds before typing ```Ctrl+C``` to end the tail process + - Check that you have actually recieved all the data by typing ```% cat FlashDump.txt```. This should output the entire textfile into your terminal window. + + + diff --git a/SPIFlash.cpp b/SPIFlash.cpp index bf5b4ba..393948b 100644 --- a/SPIFlash.cpp +++ b/SPIFlash.cpp @@ -1,654 +1,1064 @@ -/* Arduino SPIFlash Library v.1.2.2 - * Copyright (C) 2015 by Prajwal Bhattaram - * Modified by Prajwal Bhattaram - 26/08/2015 - * - * This file is part of the Arduino SPIFlash Library. This library is for - * W25Q80BV serial flash memory. In its current form it enables reading - * and writing bytes from and to various locations, reading and writing pages, - * sector, block and chip erase, powering down for low power operation and - * continuous read functions. - * - * This Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License v3.0 - * along with the Arduino SPIFlash Library. If not, see - * . - */ -#include "SPIFlash.h" -#include -#include - -#define PAGEPROG 0x02 -#define READDATA 0x03 -#define WRITEDISABLE 0x04 -#define READSTAT1 0x05 -#define WRITEENABLE 0x06 -#define SECTORERASE 0x20 -#define BLOCK32ERASE 0x52 -#define CHIPERASE 0x60 -#define SUSPEND 0x75 -#define ID 0x90 -#define RESUME 0x7A -#define JEDECID 0x9f -#define RELEASE 0xAB -#define POWERDOWN 0xB9 -#define BLOCK64ERASE 0xD8 - -#define BUSY 0x01 -#define WRTEN 0x02 - -#define arrayLen(x) (sizeof(x) / sizeof(*x)) - -// Currently library works only with W25Q80BV -#define CAPACITY 1L * 1024L * 1024L - -//#define CHIP_SELECT *cs_port |= ~cs_mask; -//#define CHIP_DESELECT *cs_port &= cs_mask; -#define xfer(n) SPI.transfer(n) - -// Constructor -SPIFlash::SPIFlash(uint8_t cs, bool overflow) { - //cs_mask = digitalPinToBitMask(cs); - SPI.begin(); - SPI.setDataMode(0); - SPI.setBitOrder(MSBFIRST); - chipSelect = cs; - pageOverflow = overflow; - pinMode(cs, OUTPUT); -} - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -// Private functions used by read, write and erase operations // -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// - -//Selects chip -void SPIFlash::_chipSelect() { - digitalWrite(chipSelect, HIGH); - digitalWrite(chipSelect, LOW); -} - -//Deselects chip -void SPIFlash::_chipDeselect() { - digitalWrite(chipSelect, HIGH); -} - -// Select chip and issue command - data to follow -void SPIFlash::_cmd(uint8_t c) { - _chipSelect(); - (void)xfer(c); -} - -// Polls the status register 1 until busy flag is cleared or timeout -bool SPIFlash::_notBusy(uint32_t timeout) { - uint8_t state; - uint32_t startTime = millis(); - - do { - _cmd(READSTAT1); - state = xfer(0); - _chipDeselect(); - if((millis()-startTime) > timeout) - return false; - } while(state & BUSY); - return true; -} - -//Enables writing to chip by setting the WRITEENABLE bit -bool SPIFlash::_writeEnable(void) { - uint8_t state; - - _cmd(WRITEENABLE); - _chipDeselect(); - - //verifies that WRITE is enabled - _cmd(READSTAT1); - state = xfer(0); - _chipDeselect(); - return (state & WRTEN) ? true : false; -} - -//Disables writing to chip by setting the Write Enable Latch (WEL) bit in the Status Register to 0 -//_writeDisable() is not required under the following conditions because the Write Enable Latch (WEL) flag is cleared to 0 -// i.e. to write disable state: -// Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, Chip Erase, Write Status Register, -// Erase Security Register and Program Security register -bool SPIFlash::_writeDisable(void) { - _cmd(WRITEDISABLE); - _chipDeselect(); -} - -//Empties the values stored in any array by setting all the values of all the bits in the array to 1 -void SPIFlash::_empty(uint8_t *array) { - int i; - for (i = 0; i < arrayLen(array); ++i) - array[i] = 0xFF; -} - - -//Gets address from page number and offset. Takes two arguments: -// 1. page_number --> Any page number from 0 to 4095 -// 2. offset --> Any offset within the page - from 0 to 255 -uint32_t SPIFlash::_getAddress(uint16_t page_number, uint8_t offset) { - uint32_t address = page_number << 8; - address += offset; - return address; -} - - -// Checks for presence of chip by requesting JEDEC ID -bool SPIFlash::_getJedecId (byte *b1, byte *b2, byte *b3) { - _cmd(JEDECID); - *b1 = xfer(0); // manufacturer id - *b2 = xfer(0); // memory type - *b3 = xfer(0); // capacity - _chipDeselect(); - if (!_notBusy()) - return false; - return true; -} - -//Checks to see if pageOverflow is permitted and assists with determining next address to write to. -uint8_t SPIFlash::_addressCheck(uint32_t address) -{ - if (address > 0xFFFFF) { - if (!pageOverflow) { - return (1); - } - else - return (2); - } - else if (address < 0xFFFFF) { - return (0); - } -} - -//Initiates read operation - but data is not read yet -bool SPIFlash::_beginRead(uint32_t address) { - if((address >= CAPACITY) || !_notBusy()) - return false; - - _cmd(READDATA); - (void)xfer(address >> 16); - (void)xfer(address >> 8); - (void)xfer(address); - - //SPI data lines are left open until _endProcess() is called - - return true; -} - -//Reads next byte. Call 'n' times to read 'n' number of bytes. Should be called after _beginRead() -uint8_t SPIFlash::_readNextByte(void) { - return xfer(0); -} - -//Initiates write operation - but data is not written yet -bool SPIFlash::_beginWrite(uint32_t address) { - if((address >= CAPACITY) || !_notBusy()) - return false; - - _cmd(PAGEPROG); - (void)xfer(address >> 16); - (void)xfer(address >> 8); - (void)xfer(address); - - //SPI data lines are left open until _endProcess() is called - - return true; -} - -//Writes next byte. Call 'n' times to read 'n' number of bytes. Should be called after _beginWrite() -bool SPIFlash::_writeNextByte(uint8_t c) { - xfer(c); - return true; -} - -//Stops all operations. Should be called after all the required data is read/written from repeated _readNextByte()/_writeNextByte() calls -void SPIFlash::_endProcess(void) { - _chipDeselect(); - delay(3); -} - -//Prints hex/dec formatted data from page reads - for debugging -void SPIFlash::_printPageBytes(uint8_t *data_buffer, uint8_t outputType) { - char buffer[10]; - for (int a = 0; a < 16; ++a) { - for (int b = 0; b < 16; ++b) { - if (outputType == 1) { - sprintf(buffer, "%02x", data_buffer[a * 16 + b]); - Serial.print(buffer); - } - else if (outputType == 2) { - uint8_t x = data_buffer[a * 16 + b]; - if (x < 10) Serial.print("0"); - if (x < 100) Serial.print("0"); - Serial.print(x); - Serial.print(','); - } - } - Serial.println(); - } -} - - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -// Public functions used for read, write and erase operations // -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// - -//Checks for and initiates the chip by requesting JEDEC ID which is returned as a 32 bit int -uint32_t SPIFlash::getID(void) { - - byte b1, b2, b3; - _getJedecId(&b1, &b2, &b3); - char buffer[64]; - sprintf(buffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3); - Serial.println(buffer); -} - -// Reads a byte of data from a specific location in a page. Takes two arguments - -// 1. page --> Any page number from 0 to 4095 -// 2. offset --> Any offset within the page - from 0 to 255 -uint8_t SPIFlash::readByte(uint16_t page_number, uint8_t offset) { - if(!_notBusy() || page_number >= 4096 || offset >= 256) - return false; - - uint32_t address = _getAddress(page_number, offset); - _beginRead(address); - uint8_t var = _readNextByte(); - _endProcess(); - return var; -} - -// Reads an array of bytes starting from a specific location in a page. Takes three arguments - -// 1. page --> Any page number from 0 to 4095 -// 2. offset --> Any offset within the page - from 0 to 255 -// 3. data_buffer --> The array of bytes to be written to from the flash memory - starting at the offset on the page indicated -bool SPIFlash::readBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer) { - if(!_notBusy() || page_number >= 4096 || offset >= 256) - return false; - - uint32_t address = _getAddress(page_number, offset); - uint16_t length = arrayLen(data_buffer); - _beginRead(address); - for (int a = 0; a < length; ++a) { - data_buffer[a] = _readNextByte(); - address++; - uint8_t addressCheck = _addressCheck(address); - - switch (addressCheck) { - case 0: // Not at end of memory - break; - - case 1: // At end of memory - (!pageOverflow) - Serial.println(F("End of memory bank")); - while (1); - break; - - case 2: // At end of memory - (pageOverflow) - address = 0x00; - break; - } - - } - _endProcess(); - - return true; -} - -// Reads a page of data into a page buffer -bool SPIFlash::readPage(uint16_t page_number, uint8_t *data_buffer) { - if(!_notBusy() || page_number >= 4096) - return false; - - uint8_t offset = 0; - uint32_t address = _getAddress(page_number, offset); - - _beginRead(address); - for (int a = 0; a < 256; ++a) { - data_buffer[a] = _readNextByte(); - } - _endProcess(); - - return true; -} - -// Writes a byte of data to a specific location in a page. Takes four arguments - -// 1. page --> Any page number from 0 to 4095 -// 2. offset --> Any offset within the page - from 0 to 255 -// 3. data --> One byte of data to be written to a particular location on a page -// 4. errorCheck --> Turned on by default. Checks for writing errors -// WARNING: You can only write to previously erased memory locations (see datasheet). -// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) -bool SPIFlash::writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck) { - if(!_notBusy() || !_writeEnable() || page_number >= 4096 || offset >= 256) - return false; - - uint32_t address = _getAddress(page_number, offset); - _beginWrite(address); - _writeNextByte(data); - _endProcess(); - - if (errorCheck) - { - _beginRead(address); - bool result = data == _readNextByte() ? true : false; - _endProcess(); - return result; - } - else - return true; - -} - -// Writes an array of bytes starting from a specific location in a page. Takes four arguments - -// 1. page --> Any page number from 0 to 4095 -// 2. offset --> Any offset within the page - from 0 to 255 -// 3. data --> An array of bytes to be written to the flash memory - starting at the offset on the page indicated -// 4. errorCheck --> Turned on by default. Checks for writing errors -// WARNING: You can only write to previously erased memory locations (see datasheet). -// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) -bool SPIFlash::writeBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, bool errorCheck) { - if(!_notBusy() || !_writeEnable() || page_number >= 4096 || offset >= 256) - return false; - - uint32_t address = _getAddress(page_number, offset); - - uint16_t n; - uint16_t maxBytes = 256-(address%256); // Force the first set of bytes to stay within the first page - uint16_t data_offset = 0; - - uint16_t length = arrayLen(data_buffer); - - while (length > 0) - { - n = (length<=maxBytes) ? length : maxBytes; - _beginWrite(address); - for (uint16_t i = 0; i < n; ++i) - _writeNextByte(data_buffer[data_offset+i]); - _endProcess(); - - address += n; // Adjust the address and remaining bytes by what we've just transferred. - uint8_t addressCheck = _addressCheck(address); - - switch (addressCheck) { - case 0: // Not at end of memory - break; - - case 1: // At end of memory - (!pageOverflow) - Serial.println(F("Out of memory.")); - while (1); - break; - - case 2: // At end of memory - (pageOverflow) - address = 0x00; - break; - } - data_offset += n; - length -= n; - maxBytes = 256; // Now we can do up to 256 bytes per loop - } - - if (errorCheck) - { - address = _getAddress(page_number, offset); - length = arrayLen(data_buffer); - _beginRead(address); - while (length > 0) { - uint16_t j; - if (data_buffer[j++] == _readNextByte()) - length--; - else - return false; - } - _endProcess(); - return true; - } - else - return true; - -} - -// Writes a page of data from a data_buffer array. Make sure the sizeOf(uint8_t data_buffer[]) == 256. -// errorCheck --> Turned on by default. Checks for writing errors. -// WARNING: You can only write to previously erased memory locations (see datasheet). -// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) -bool SPIFlash::writePage(uint16_t page_number, uint8_t *data_buffer, bool errorCheck) { - if(!_notBusy() || !_writeEnable() || page_number >= 4096) - return false; - - char buffer[28]; - uint32_t address = _getAddress(page_number); - - _beginWrite(address); - for (uint16_t i = 0; i < 256; ++i) - _writeNextByte(data_buffer[i]); - _endProcess(); - - if (errorCheck) - { - _beginRead(address); - uint16_t i; - for (i = 0; i < 256; ++i) - { - if (data_buffer[i] != _readNextByte()) - return false; - } - sprintf(buffer, "Writing page (%04x) done", page_number); - Serial.println(buffer); - return true; - } - else - { - sprintf(buffer, "Writing page (%04x) done", page_number); - Serial.println(buffer); - return true; - } -} - -//Erases one 4k sector containing the page to be erased. The sectors are numbered 0 - 255 containing 16 pages each. -// Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 -bool SPIFlash::eraseSector(uint16_t page_number) { - if(!_notBusy() || !_writeEnable()) - return false; - - uint32_t address = _getAddress(page_number); - _cmd(SECTORERASE); - (void)xfer(address >> 16); - (void)xfer(address >> 8); - (void)xfer(0); - _chipDeselect(); - - if(!_notBusy(1000L)) - return false; //Datasheet says erasing a sector takes 400ms max - - //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 - // i.e. to write disable state upon the following conditions: - // Power-up, Write Disable, Page Program, Quad Page Program, ``Sector Erase``, Block Erase, Chip Erase, Write Status Register, - // Erase Security Register and Program Security register - - return true; -} - -//Erases one 32k block containing the page to be erased. The blocks are numbered 0 - 31 containing 128 pages each. -// Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31 -bool SPIFlash::eraseBlock32K(uint16_t page_number) { - if(!_notBusy() || !_writeEnable()) - return false; - - uint32_t address = _getAddress(page_number); - _cmd(BLOCK32ERASE); - (void)xfer(address >> 16); - (void)xfer(address >> 8); - (void)xfer(0); - _chipDeselect(); - - if(!_notBusy(1000L)) - return false; //Datasheet says erasing a sector takes 400ms max - - //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 - // i.e. to write disable state upon the following conditions: - // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, - // Erase Security Register and Program Security register - - return true; -} - -//Erases one 64k block containing the page to be erased. The blocks are numbered 0 - 15 containing 256 pages each. -// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15 -bool SPIFlash::eraseBlock64K(uint16_t page_number) { - if(!_notBusy() || !_writeEnable()) - return false; - - uint32_t address = _getAddress(page_number); - _cmd(BLOCK64ERASE); - (void)xfer(address >> 16); - (void)xfer(address >> 8); - (void)xfer(0); - _chipDeselect(); - - if(!_notBusy(1000L)) - return false; //Datasheet says erasing a sector takes 400ms max - - //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 - // i.e. to write disable state upon the following conditions: - // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, - // Erase Security Register and Program Security register - - return true; -} - -//Erases whole chip. Think twice before using. -bool SPIFlash::eraseChip(void) { - if(!_notBusy() || !_writeEnable()) - return false; - - _cmd(CHIPERASE); - _chipDeselect(); - - if(!_notBusy(10000L)) - return false; //Datasheet says erasing chip takes 6s max - - //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 - // i.e. to write disable state upon the following conditions: - // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, ``Chip Erase``, Write Status Register, - // Erase Security Register and Program Security register - - return true; - -} - -//Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). -//Page Program, Write Status Register, Erase instructions are not allowed. -//Erase suspend is only allowed during Block/Sector erase. -//Program suspend is only allowed during Page/Quad Page Program -bool SPIFlash::suspendProg(void) { - if(_notBusy()) - return false; - - _cmd(SUSPEND); - _chipDeselect(); - - delay(20); //Max suspend enable time according to the Datasheet - - if(!_notBusy()) - return false; -} - -//Resumes previously suspended Block Erase/Sector Erase/Page Program. -bool SPIFlash::resumeProg(void) { - if(!_notBusy()) - return false; - - _cmd(RESUME); - _chipDeselect(); - - if(_notBusy()) - return false; - - return true; - -} - -//Puts device in low power state. Good for battery powered operations. -//Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4) -//In powerDown() the chip will only respond to powerUp() -bool SPIFlash::powerDown(void) { - if(!_notBusy()) - return false; - - _cmd(POWERDOWN); - _chipDeselect(); - - delay(3); //Max powerDown enable time according to the Datasheet - - if(_writeEnable()) //Tries to read STAT1. If STAT1 is accessible, chip has not powered down - { - _writeDisable(); - return false; - } - - return true; -} - -//Wakes chip from low power state. -bool SPIFlash::powerUp(void) { - if(!_notBusy()) - return false; - - _cmd(RELEASE); - _chipDeselect(); - - delay(3); //Max release enable time according to the Datasheet - - if(_writeEnable()) //Tries to read STAT1. If STAT1 is accessible, chip has powered up - { - _writeDisable(); - return true; - } - - return false; -} - - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -// These functions return data to Serial stream. // -// Declares Serial.begin() if not previously declared. // -// Initiates Serial at 38400 baud. // -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// - -//Reads a page of data and prints it to Serial stream. Make sure the sizeOf(uint8_t data_buffer[]) == 256. -void SPIFlash::printPage(uint16_t page_number, uint8_t outputType) { - if(!Serial) - Serial.begin(38400); - - char buffer[24]; - sprintf(buffer, "Reading page (%04x)", page_number); - Serial.println(buffer); - - uint8_t data_buffer[256]; - readPage(page_number, data_buffer); - _printPageBytes(data_buffer, outputType); -} - -//Reads all pages on Flash chip and dumps it to Serial stream. -//This function is useful when extracting data from a flash chip onto a computer as a text file. -void SPIFlash::printAllPages(uint8_t outputType) { - if(!Serial) - Serial.begin(38400); - - Serial.println("Reading all pages"); - uint8_t data_buffer[256]; - - for (int a = 0; a < 4096; ++a) { - readPage(a, data_buffer); - _printPageBytes(data_buffer, outputType); - } -} +/* Arduino SPIFlash Library v.1.3.0 + * Copyright (C) 2015 by Prajwal Bhattaram + * Modified by Prajwal Bhattaram - 30/08/2015 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * W25Q80BV serial flash memory. In its current form it enables reading + * and writing bytes from and to various locations, reading and writing pages, + * sector, block and chip erase, powering down for low power operation and + * continuous read functions. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ +#include "SPIFlash.h" +#include +#include + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Uncomment the code below to run a diagnostic if your flash // +// does not respond // +// // +// Error codes will be generated and errors will be printed to Serial // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +//#define RUNDIAGNOSTIC // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +#define _MANID 0xEF +#define PAGESIZE 0x100 + +#define MANID 0x90 +#define PAGEPROG 0x02 +#define READDATA 0x03 +#define WRITEDISABLE 0x04 +#define READSTAT1 0x05 +#define WRITEENABLE 0x06 +#define SECTORERASE 0x20 +#define BLOCK32ERASE 0x52 +#define CHIPERASE 0x60 +#define SUSPEND 0x75 +#define ID 0x90 +#define RESUME 0x7A +#define JEDECID 0x9f +#define RELEASE 0xAB +#define POWERDOWN 0xB9 +#define BLOCK64ERASE 0xD8 + +#define BUSY 0x01 +#define WRTEN 0x02 + +#define arrayLen(x) (sizeof(x) / sizeof(*x)) +#define lengthOf(x) (sizeof(x))/sizeof(byte) + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// List of Error codes // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + #ifdef RUNDIAGNOSTIC + + #define SUCCESS 0x00 + #define CALLBEGIN 0x01 + #define UNKNOWNCHIP 0x02 + #define UNKNOWNCAP 0x03 + #define CHIPBUSY 0x04 + #define OUTOFBOUNDS 0x05 + #define CANTENWRITE 0x06 + #define OUTOFMEM 0x07 + #define OUTOFPAGE 0x08 + + #endif + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//#define CHIP_SELECT *cs_port |= ~cs_mask; +//#define CHIP_DESELECT *cs_port &= cs_mask; +#define xfer(n) SPI.transfer(n) + +// Constructor +SPIFlash::SPIFlash(uint8_t cs, bool overflow) { + //cs_mask = digitalPinToBitMask(cs); + SPI.begin(); + SPI.setDataMode(0); + SPI.setBitOrder(MSBFIRST); + chipSelect = cs; + pageOverflow = overflow; + pinMode(cs, OUTPUT); +} + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Private functions used by read, write and erase operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//Selects chip +void SPIFlash::_chipSelect() { + digitalWrite(chipSelect, HIGH); + digitalWrite(chipSelect, LOW); +} + +//Deselects chip +void SPIFlash::_chipDeselect() { + digitalWrite(chipSelect, HIGH); +} + +// Select chip and issue command - data to follow +void SPIFlash::_cmd(uint8_t c) { + _chipSelect(); + (void)xfer(c); +} + +// Polls the status register 1 until busy flag is cleared or timeout +bool SPIFlash::_notBusy(uint32_t timeout) { + uint8_t state; + uint32_t startTime = millis(); + + do { + _cmd(READSTAT1); + state = xfer(0); + _chipDeselect(); + if((millis()-startTime) > timeout){ + #ifdef RUNDIAGNOSTIC + errorcode = CHIPBUSY; + _errorCodeCheck(); + while(1); + #endif + + return false; + } + } while(state & BUSY); + return true; +} + +//Enables writing to chip by setting the WRITEENABLE bit +bool SPIFlash::_writeEnable(void) { + uint8_t state; + + _cmd(WRITEENABLE); + _chipDeselect(); + + //verifies that WRITE is enabled + _cmd(READSTAT1); + state = xfer(0); + _chipDeselect(); + if(state & WRTEN) + return true; + else { + #ifdef RUNDIAGNOSTIC + errorcode = CANTENWRITE; + _errorCodeCheck(); + while(1); + #endif + + return false; + } +} + +//Disables writing to chip by setting the Write Enable Latch (WEL) bit in the Status Register to 0 +//_writeDisable() is not required under the following conditions because the Write Enable Latch (WEL) flag is cleared to 0 +// i.e. to write disable state: +// Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, Chip Erase, Write Status Register, +// Erase Security Register and Program Security register +bool SPIFlash::_writeDisable(void) { + _cmd(WRITEDISABLE); + _chipDeselect(); +} + +//Empties the values stored in any array by setting all the values of all the bits in the array to 1 +void SPIFlash::_empty(uint8_t *array) { + int i; + for (i = 0; i < arrayLen(array); ++i) + array[i] = 0xFF; +} + +#ifdef RUNDIAGNOSTIC +//Checks the errorcode on the current function and issues an error notice +void SPIFlash::_errorCodeCheck(void) { + switch (errorcode) { + case SUCCESS: + Serial.println("Operation successful."); + break; + + case CALLBEGIN: + Serial.println ("Please make sure .begin() has been called in setup()."); + break; + + case UNKNOWNCHIP: + Serial.println("Unknown chip manufacturer."); + break; + + case UNKNOWNCAP: + Serial.println("Unknown chip capacity."); + break; + + case CHIPBUSY: + Serial.println("Chip busy."); + break; + + case OUTOFBOUNDS: + Serial.println("Address out of bounds. Please check if .begin() has been called in setup()."); + break; + + case CANTENWRITE: + Serial.println("Unable to _writeEnable. Check wiring/chip."); + break; + + case OUTOFMEM: + Serial.println("Pagenumber outside maximum"); + break; + + case OUTOFPAGE: + Serial.println("Offset is outside page"); + break; + + default: + break; + } +} +#endif + +//Gets address from page number and offset. Takes two arguments: +// 1. page_number --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +uint32_t SPIFlash::_getAddress(uint16_t page_number, uint8_t offset) { + uint32_t address = page_number; + address = (address << 8) + offset; + if (!_addressCheck(address)){ + #ifdef RUNDIAGNOSTIC + errorcode = OUTOFBOUNDS; + _errorCodeCheck(); + while(1); + #endif + } + else + return address; +} + +//Checks the device ID to establish storage parameters +bool SPIFlash::_getManId(uint8_t *b1, uint8_t *b2) { + if(!_notBusy()) + return false; + _cmd(MANID); + xfer(0); + xfer(0); + xfer(0); + *b1 = xfer(0); + *b2 = xfer(0); + _chipDeselect(); + return true; +} + +//Checks for presence of chip by requesting JEDEC ID +bool SPIFlash::_getJedecId(uint8_t *b1, uint8_t *b2, uint8_t *b3) { + if(!_notBusy()) + return false; + _cmd(JEDECID); + *b1 = xfer(0); // manufacturer id + *b2 = xfer(0); // memory type + *b3 = xfer(0);// capacity + _chipDeselect(); + return true; +} + +//Checks to see if pageOverflow is permitted and assists with determining next address to read/write. +//Sets the global address variable +bool SPIFlash::_addressCheck(uint32_t address) +{ + if (address >= capacity) { + if (!pageOverflow) + return false; // At end of memory - (!pageOverflow) + + else { + address = 0x00; // At end of memory - (pageOverflow) + return true; + } + + } + else if (address < capacity) { + address = address; + return true; // Not at end of memory + } +} + +//Double checks all parameters before calling a Read +uint32_t SPIFlash::_prepRead(uint16_t page_number, uint8_t offset) { + if(!_notBusy()) + return false; + + uint32_t address = _getAddress(page_number, offset); + return address; + + return true; +} +//Initiates read operation - but data is not read yet +void SPIFlash::_beginRead(uint32_t address) { + + _cmd(READDATA); + (void)xfer(address >> 16); + (void)xfer(address >> 8); + (void)xfer(address); + + //SPI data lines are left open until _endProcess() is called +} + +//Reads next byte. Call 'n' times to read 'n' number of bytes. Should be called after _beginRead() +uint8_t SPIFlash::_readNextByte(void) { + return xfer(0); +} + +//Reads a byte of data from a specific location in a page. Takes one argument - +// 1. address --> address to read from +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) + uint8_t SPIFlash::_readByte(uint32_t address) { + uint8_t data; + if(!_notBusy()||!_addressCheck(address)) + return false; + _beginRead(address); + data = _readNextByte(); + _endProcess(); + + return data; + + } + +//Double checks all parameters before initiating a write +uint32_t SPIFlash::_prepWrite(uint16_t page_number, uint8_t offset) { + if(!_notBusy()||!_writeEnable()) + return false; + + uint32_t address = _getAddress(page_number, offset); + return address; +} + +//Initiates write operation - but data is not written yet +bool SPIFlash::_beginWrite(uint32_t address) { + + _cmd(PAGEPROG); + (void)xfer(address >> 16); + (void)xfer(address >> 8); + (void)xfer(address); + + //SPI data lines are left open until _endProcess() is called + + return true; +} + +//Writes next byte. Call 'n' times to read 'n' number of bytes. Should be called after _beginWrite() +bool SPIFlash::_writeNextByte(uint8_t c) { + xfer(c); + return true; +} + +// Writes a byte of data to a specific location in a page. Takes three arguments - +// 1. address --> address to write to +// 2. data --> One byte of data to be written to a particular location on a page +// 3. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::_writeByte(uint32_t address, uint8_t data, bool errorCheck) { + + if(!_notBusy()||!_writeEnable()||!_addressCheck(address)) + return false; + + _beginWrite(address); + _writeNextByte(data); + _endProcess(); + + if (errorCheck) + { + _beginRead(address); + uint8_t result = _readNextByte(); + _endProcess(); + + /*Serial.print("Data: "); + Serial.println(data); + Serial.print("Result: "); + Serial.println(result);*/ + + return data == result ? true : false; + } + else + return true; + + } + +//Stops all operations. Should be called after all the required data is read/written from repeated _readNextByte()/_writeNextByte() calls +void SPIFlash::_endProcess(void) { + _chipDeselect(); + delay(3); +} + + +//Prints hex/dec formatted data from page reads - for debugging +void SPIFlash::_printPageBytes(uint8_t *data_buffer, uint8_t outputType) { + char buffer[10]; + for (int a = 0; a < 16; ++a) { + for (int b = 0; b < 16; ++b) { + if (outputType == 1) { + sprintf(buffer, "%02x", data_buffer[a * 16 + b]); + Serial.print(buffer); + } + else if (outputType == 2) { + uint8_t x = data_buffer[a * 16 + b]; + if (x < 10) Serial.print("0"); + if (x < 100) Serial.print("0"); + Serial.print(x); + Serial.print(','); + } + } + Serial.println(); + } +} + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Public functions used for read, write and erase operations // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//Identifies chip and establishes parameters +void SPIFlash::begin() { + //Get Manfucturer/Device ID so the library can identify the chip + uint8_t manID, devID ; + _getManId(&manID, &devID); + + if (manID != _MANID){ //If the chip is not a Winbond Chip + while(1); + #ifdef RUNDIAGNOSTIC + errorcode = UNKNOWNCHIP; //Error code for unidentified chip + _errorCodeCheck(); + #endif + } + + //Check flash memory type and identify capacity + uint8_t i; + //capacity; + for (i = 0; i < sizeof(devType); i++) + { + if (devID == devType[i]) + capacity = memSize[i]; + } + if (capacity == 0) { + while(1); + #ifdef RUNDIAGNOSTIC + errorcode = UNKNOWNCAP; //Error code for unidentified capacity + _errorCodeCheck(); + #endif + } + + maxPage = capacity/PAGESIZE; + + #ifdef RUNDIAGNOSTIC + char buffer[64]; + sprintf(buffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %lu\nmaxPage: %d", manID, devID, capacity, maxPage); + Serial.println(buffer); + errorcode = SUCCESS; //Successful chip detect + _errorCodeCheck(); + #endif + +} + +//Checks for and initiates the chip by requesting JEDEC ID which is returned as a 32 bit int +uint16_t SPIFlash::getManID() { + uint8_t b1, b2; + _getManId(&b1, &b2); + uint32_t id = b1; + id = (id << 8)|(b2 << 0); + return id; +} + +//Checks for and initiates the chip by requesting JEDEC ID which is returned as a 32 bit int +uint32_t SPIFlash::getJEDECID() { + uint8_t b1, b2, b3; + _getJedecId(&b1, &b2, &b3); + uint32_t id = b1; + id = (id << 8)|(b2 << 0); + id = (id << 8)|(b3 << 0); + return id; +} + +// Reads a byte of data from a specific location in a page. Takes two arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +uint8_t SPIFlash::readByte(uint16_t page_number, uint8_t offset) { + uint32_t address = _prepRead(page_number, offset); + + uint8_t data; + _beginRead(address); + data = _readNextByte(); + _endProcess(); + return data; +} + +// Reads a char of data from a specific location in a page. Takes two arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +int8_t SPIFlash::readChar(uint16_t page_number, uint8_t offset) { + uint32_t address = _prepRead(page_number, offset); + int8_t data; + _beginRead(address); + data = _readNextByte(); + _endProcess(); + return data; +} + +// Reads an array of bytes starting from a specific location in a page. Takes three arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data_buffer --> The array of bytes to be read from the flash memory - starting at the offset on the page indicated +void SPIFlash::readBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer) { + uint32_t address = _prepRead(page_number, offset); + uint16_t length = arrayLen(data_buffer); + _beginRead(address); + for (int a = 0; a < length; a++) { + data_buffer[a] = _readNextByte(); + _addressCheck(address++); + } + _endProcess(); +} + +// Reads an unsigned int of data from a specific location in a page. Takes two arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +uint16_t SPIFlash::readWord(uint16_t page_number, uint8_t offset) { + uint32_t address = _prepRead(page_number, offset); + union + { + byte b[sizeof(uint16_t)]; + uint16_t I; + } data; + _beginRead(address); + for (int i=0; i < (sizeof(int16_t)); i++) { + data.b[i] = _readNextByte(); + } + _endProcess(); + return data.I; +} + +// Reads a signed int of data from a specific location in a page. Takes two arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +int16_t SPIFlash::readShort(uint16_t page_number, uint8_t offset) { + uint32_t address = _prepRead(page_number, offset); + union + { + byte b[sizeof(int16_t)]; + int16_t s; + } data; + _beginRead(address); + for (int i=0; i < (sizeof(int16_t)); i++) { + data.b[i] = _readNextByte(); + } + _endProcess(); + return data.s; +} + +// Reads an unsigned long of data from a specific location in a page. Takes two arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +uint32_t SPIFlash::readULong(uint16_t page_number, uint8_t offset) { + uint32_t address = _prepRead(page_number, offset); + union + { + byte b[sizeof(uint32_t)]; + uint32_t l; + } data; + _beginRead(address); + for (int i=0; i < (sizeof(uint32_t)); i++) { + data.b[i] = _readNextByte(); + } + _endProcess(); + return data.l; +} + +// Reads a signed long of data from a specific location in a page. Takes two arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +int32_t SPIFlash::readLong(uint16_t page_number, uint8_t offset) { + uint32_t address = _prepRead(page_number, offset); + union + { + byte b[sizeof(int32_t)]; + int32_t l; + } data; + _beginRead(address); + for (int i=0; i < (sizeof(int32_t)); i++) { + data.b[i] = _readNextByte(); + } + _endProcess(); + return data.l; +} + +// Reads a signed long of data from a specific location in a page. Takes two arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +float SPIFlash::readFloat(uint16_t page_number, uint8_t offset) { + uint32_t address = _prepRead(page_number, offset); + union + { + byte b[(sizeof(float))]; + float f; + } data; + _beginRead(address); + for (int i=0; i < (sizeof(float)); i++) { + data.b[i] = _readNextByte(); + } + _endProcess(); + return data.f; +} + +// Reads a page of data into a page buffer +void SPIFlash::readPage(uint16_t page_number, uint8_t *data_buffer) { + uint32_t address = _prepRead(page_number); + _beginRead(address); + for (int a = 0; a < 256; ++a) { + data_buffer[a] = _readNextByte(); + } + _endProcess(); +} + +// Writes a byte of data to a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One byte of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + _beginWrite(address); + _writeNextByte(data); + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data); + +} + +// Writes a byte of data to a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> One byte of data to be written to a particular location on a page +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeChar(uint16_t page_number, uint8_t offset, int8_t data, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + _beginWrite(address); + _writeNextByte(data); + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data); + +} + +// Writes an array of bytes starting from a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> An array of bytes to be written to the flash memory - starting at the offset on the page indicated +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + uint16_t n; + uint16_t maxBytes = PAGESIZE-(address % PAGESIZE); // Force the first set of bytes to stay within the first page + uint16_t data_offset = 0; + + uint16_t length = arrayLen(data_buffer); + _beginWrite(address); + + while (length > 0) + { + n = (length<=maxBytes) ? length : maxBytes; + for (uint16_t i = 0; i < n; ++i) + _writeNextByte(data_buffer[data_offset+i]); + if (!_addressCheck(address+=n)) + return false; // Adjust the address and remaining bytes by what we've just transferred. + data_offset += n; + length -= n; + maxBytes = 256; // Now we can do up to 256 bytes per loop + } + return true; +} + +// Writes an unsigned int as two bytes starting from a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> An int to be written to the flash memory - starting at the offset on the page indicated +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeWord(uint16_t page_number, uint8_t offset, uint16_t data, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + union + { + uint8_t b[sizeof(data)]; + uint16_t w; + } var; + var.w = data; + _beginWrite(address); + for (int j = 0; j < (sizeof(data)); j++) { + _writeNextByte(var.b[j]); + } + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data); +} + +// Writes a signed int as two bytes starting from a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> An int to be written to the flash memory - starting at the offset on the page indicated +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeShort(uint16_t page_number, uint8_t offset, int16_t data, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + union + { + uint8_t b[sizeof(data)]; + int16_t s; + } var; + var.s = data; + _beginWrite(address); + for (int j = 0; j < (sizeof(data)); j++) { + _writeNextByte(var.b[j]); + } + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data); +} + +// Writes an unsigned long as four bytes starting from a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> A long to be written to the flash memory - starting at the offset on the page indicated +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeULong(uint16_t page_number, uint8_t offset, uint32_t data, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + union + { + uint8_t b[sizeof(data)]; + uint32_t l; + } var; + var.l = data; + _beginWrite(address); + for (int j = 0; j < (sizeof(data)); j++) { + _writeNextByte(var.b[j]); + } + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data); +} + +// Writes a signed long as four bytes starting from a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> A long to be written to the flash memory - starting at the offset on the page indicated +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeLong(uint16_t page_number, uint8_t offset, int32_t data, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + union + { + uint8_t b[sizeof(data)]; + int32_t l; + } var; + var.l = data; + _beginWrite(address); + for (int j = 0; j < (sizeof(data)); j++) { + _writeNextByte(var.b[j]); + } + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data); +} + +// Writes a float as four bytes starting from a specific location in a page. Takes four arguments - +// 1. page --> Any page number from 0 to maxPage +// 2. offset --> Any offset within the page - from 0 to 255 +// 3. data --> A long to be written to the flash memory - starting at the offset on the page indicated +// 4. errorCheck --> Turned on by default. Checks for writing errors +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writeFloat(uint16_t page_number, uint8_t offset, float data, bool errorCheck) { + uint32_t address = _prepWrite(page_number, offset); + + union + { + uint8_t b[sizeof(data)]; + float f; + } var; + var.f = data; + _beginWrite(address); + for (int j = 0; j < (sizeof(data)); j++) { + _writeNextByte(var.b[j]); + } + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data); +} + +// Writes a page of data from a data_buffer array. Make sure the sizeOf(uint8_t data_buffer[]) == 256. +// errorCheck --> Turned on by default. Checks for writing errors. +// WARNING: You can only write to previously erased memory locations (see datasheet). +// Use the eraseSector()/eraseBlock32K/eraseBlock64K commands to first clear memory (write 0xFFs) +bool SPIFlash::writePage(uint16_t page_number, uint8_t *data_buffer, bool errorCheck) { + uint32_t address = _prepWrite(page_number); + + _beginWrite(address); + for (uint16_t i = 0; i < PAGESIZE; ++i) + _writeNextByte(data_buffer[i]); + _endProcess(); + + if (!errorCheck) + return true; + else + return _writeErrorCheck(address, data_buffer); + + #ifdef RUNDIAGNOSTIC + char buffer[64]; + sprintf(buffer, "Writing page (%04x) done", page_number); + Serial.println(buffer); + #endif +} + + +//Erases one 4k sector containing the page to be erased. The sectors are numbered 0 - 255 containing 16 pages each. +// Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 +bool SPIFlash::eraseSector(uint16_t page_number) { + if(!_notBusy()||!_writeEnable()) + return false; + + uint32_t address = _getAddress(page_number); + + _cmd(SECTORERASE); + (void)xfer(address >> 16); + (void)xfer(address >> 8); + (void)xfer(0); + _chipDeselect(); + + if(!_notBusy(410L)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, ``Sector Erase``, Block Erase, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} + +//Erases one 32k block containing the page to be erased. The blocks are numbered 0 - 31 containing 128 pages each. +// Page 0-127 --> Block 0; Page 128-255 --> Block 1;......Page 3968-4095 --> Block 31 +bool SPIFlash::eraseBlock32K(uint16_t page_number) { + if(!_notBusy()||!_writeEnable()) + return false; + + uint32_t address = _getAddress(page_number); + + _cmd(BLOCK32ERASE); + (void)xfer(address >> 16); + (void)xfer(address >> 8); + (void)xfer(0); + _chipDeselect(); + + if(!_notBusy(410L)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} + +//Erases one 64k block containing the page to be erased. The blocks are numbered 0 - 15 containing 256 pages each. +// Page 0-255 --> Block 0; Page 256-511 --> Block 1;......Page 3840-4095 --> Block 15 +bool SPIFlash::eraseBlock64K(uint16_t page_number) { + if(!_notBusy()||!_writeEnable()) + return false; + + uint32_t address = _getAddress(page_number); + + _cmd(BLOCK64ERASE); + (void)xfer(address >> 16); + (void)xfer(address >> 8); + (void)xfer(0); + _chipDeselect(); + + if(!_notBusy(410L)) + return false; //Datasheet says erasing a sector takes 400ms max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, ``Block Erase``, Chip Erase, Write Status Register, + // Erase Security Register and Program Security register + + return true; +} + +//Erases whole chip. Think twice before using. +bool SPIFlash::eraseChip(void) { + if(!_notBusy()||!_writeEnable()) + return false; + + _cmd(CHIPERASE); + _chipDeselect(); + + if(!_notBusy(7000L)) + return false; //Datasheet says erasing chip takes 6s max + + //_writeDisable(); //_writeDisable() is not required because the Write Enable Latch (WEL) flag is cleared to 0 + // i.e. to write disable state upon the following conditions: + // Power-up, Write Disable, Page Program, Quad Page Program, Sector Erase, Block Erase, ``Chip Erase``, Write Status Register, + // Erase Security Register and Program Security register + + return true; + +} + +//Suspends current Block Erase/Sector Erase/Page Program. Does not suspend chipErase(). +//Page Program, Write Status Register, Erase instructions are not allowed. +//Erase suspend is only allowed during Block/Sector erase. +//Program suspend is only allowed during Page/Quad Page Program +bool SPIFlash::suspendProg(void) { + if(!_notBusy()) + return false; + + _cmd(SUSPEND); + _chipDeselect(); + + if(!_notBusy(20L)) //Max suspend Enable time according to datasheet + return false; +} + +//Resumes previously suspended Block Erase/Sector Erase/Page Program. +bool SPIFlash::resumeProg(void) { + if(!_notBusy()) + return false; + + _cmd(RESUME); + _chipDeselect(); + + if(_notBusy()) + return false; + + return true; + +} + +//Puts device in low power state. Good for battery powered operations. +//Typical current consumption during power-down is 1mA with a maximum of 5mA. (Datasheet 7.4) +//In powerDown() the chip will only respond to powerUp() +bool SPIFlash::powerDown(void) { + if(!_notBusy()) + return false; + + _cmd(POWERDOWN); + _chipDeselect(); + + delay(3); //Max powerDown enable time according to the Datasheet + + if(_writeEnable()) //Tries to read STAT1. If STAT1 is accessible, chip has not powered down + { + _writeDisable(); + return false; + } + + return true; +} + +//Wakes chip from low power state. +bool SPIFlash::powerUp(void) { + if(!_notBusy()) + return false; + + _cmd(RELEASE); + _chipDeselect(); + + delay(3); //Max release enable time according to the Datasheet + + if(_writeEnable()) //Tries to read STAT1. If STAT1 is accessible, chip has powered up + { + _writeDisable(); + return true; + } + + return false; +} + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// These functions return data to Serial stream. // +// Declares Serial.begin() if not previously declared. // +// Initiates Serial at 115200 baud. // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +//Reads a page of data and prints it to Serial stream. Make sure the sizeOf(uint8_t data_buffer[]) == 256. +void SPIFlash::printPage(uint16_t page_number, uint8_t outputType) { + if(!Serial) + Serial.begin(115200); + + char buffer[24]; + sprintf(buffer, "Reading page (%04x)", page_number); + Serial.println(buffer); + + uint8_t data_buffer[256]; + readPage(page_number, data_buffer); + _printPageBytes(data_buffer, outputType); +} + +//Reads all pages on Flash chip and dumps it to Serial stream. +//This function is useful when extracting data from a flash chip onto a computer as a text file. +void SPIFlash::printAllPages(uint8_t outputType) { + if(!Serial) + Serial.begin(115200); + + Serial.println("Reading all pages"); + uint8_t data_buffer[256]; + + for (int a = 0; a < 4096; ++a) { + readPage(a, data_buffer); + _printPageBytes(data_buffer, outputType); + } +} diff --git a/SPIFlash.h b/SPIFlash.h index 952c561..d529ffd 100644 --- a/SPIFlash.h +++ b/SPIFlash.h @@ -1,76 +1,145 @@ -/* Arduino SPIFlash Library v.1.2.1 - * Copyright (C) 2015 by Prajwal Bhattaram - * Modified by Prajwal Bhattaram - 21/06/2015 - * - * This file is part of the Arduino SPIFlash Library. This library is for - * W25Q80BV serial flash memory. In its current form it enables reading - * and writing bytes from and to various locations, reading and writing pages, - * sector, block and chip erase, powering down for low power operation and - * continuous read functions. - * - * This Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License v3.0 - * along with the Arduino SPIFlash Library. If not, see - * . - */ -#ifndef SPIFLASH_H -#define SPIFLASH_H - -#include - -class SPIFlash { -public: - SPIFlash(uint8_t cs = 10, bool overflow = true); - uint32_t getID(void); - bool readBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer), - readPage(uint16_t page_number, uint8_t *data_buffer), - writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck = true), - writeBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, bool errorCheck = true), - writePage(uint16_t page_number, uint8_t *data_buffer, bool errorCheck = true), - eraseSector(uint16_t page_number), - eraseBlock32K(uint16_t page_number), - eraseBlock64K(uint16_t page_number), - eraseChip(void), - suspendProg(void), - resumeProg(void), - powerDown(void), - powerUp(void); - void printPage(uint16_t page_number, uint8_t outputType), - printAllPages(uint8_t outputType); - uint8_t readByte(uint16_t page_number, uint8_t offset); - - -private: - void _chipSelect(void), - _chipDeselect(void), - _cmd(uint8_t c), - _endProcess(void), - _empty(uint8_t *array), - _printPageBytes(uint8_t *data_buffer, uint8_t outputType); - bool _notBusy(uint32_t timeout = 100L), - _beginRead(uint32_t address), - _beginWrite(uint32_t address), - _writeNextByte(uint8_t c), - _writeEnable(void), - _writeDisable(void), - _getJedecId(uint8_t *b1, uint8_t *b2, uint8_t *b3); - uint8_t _readNextByte(void), - _addressCheck(uint32_t address); - uint32_t _getAddress(uint16_t page_number, uint8_t offset = 0); - - volatile uint8_t *cs_port; - uint8_t cs_mask; - uint8_t chipSelect; - bool pageOverflow; -}; - -#endif // _SPIFLASH_H_ +/* Arduino SPIFlash Library v.1.3.0 + * Copyright (C) 2015 by Prajwal Bhattaram + * Modified by Prajwal Bhattaram - 30/08/2015 + * + * This file is part of the Arduino SPIFlash Library. This library is for + * W25Q80BV serial flash memory. In its current form it enables reading + * and writing bytes from and to various locations, reading and writing pages, + * sector, block and chip erase, powering down for low power operation and + * continuous read functions. + * + * This Library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License v3.0 + * along with the Arduino SPIFlash Library. If not, see + * . + */ +#ifndef SPIFLASH_H +#define SPIFLASH_H + +#include + +class SPIFlash { +public: + SPIFlash(uint8_t cs = 10, bool overflow = true); + uint16_t getManID(); + uint32_t getJEDECID(); + bool readByte(uint16_t page_number, uint8_t offset, uint8_t data); + bool writeByte(uint16_t page_number, uint8_t offset, uint8_t data, bool errorCheck = true); + bool writeBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer, bool errorCheck = true); + bool writeChar(uint16_t page_number, uint8_t offset, int8_t data, bool errorCheck = true); + bool writeShort(uint16_t page_number, uint8_t offset, int16_t data, bool errorCheck = true); + bool writeWord(uint16_t page_number, uint8_t offset, uint16_t data, bool errorCheck = true); + bool writeLong(uint16_t page_number, uint8_t offset, int32_t data, bool errorCheck = true); + bool writeULong(uint16_t page_number, uint8_t offset, uint32_t data, bool errorCheck = true); + bool writeFloat(uint16_t page_number, uint8_t offset, float data, bool errorCheck = true); + bool writePage(uint16_t page_number, uint8_t *data_buffer, bool errorCheck = true); + bool eraseSector(uint16_t page_number); + bool eraseBlock32K(uint16_t page_number); + bool eraseBlock64K(uint16_t page_number); + bool eraseChip(void); + bool suspendProg(void); + bool resumeProg(void); + bool powerDown(void); + bool powerUp(void); + void begin(); + void readBytes(uint16_t page_number, uint8_t offset, uint8_t *data_buffer); + void readPage(uint16_t page_number, uint8_t *data_buffer); + void printPage(uint16_t page_number, uint8_t outputType); + void printAllPages(uint8_t outputType); + int8_t readChar(uint16_t page_number, uint8_t offset); + uint8_t readByte(uint16_t page_number, uint8_t offset); + int16_t readShort(uint16_t page_number, uint8_t offset); + uint16_t readWord(uint16_t page_number, uint8_t offset); + int32_t readLong(uint16_t page_number, uint8_t offset); + uint32_t readULong(uint16_t page_number, uint8_t offset); + float readFloat(uint16_t page_number, uint8_t offset); + template uint32_t writeAnything(uint16_t page_number, uint8_t offset, const T& value); + template uint32_t readAnything(uint16_t page_number, uint8_t offset, T& value); + + +private: + void _chipSelect(void); + void _chipDeselect(void); + void _cmd(uint8_t c); + void _endProcess(void); + void _errorCodeCheck(void); + void _empty(uint8_t *array); + void _beginRead(uint32_t address); + void _printPageBytes(uint8_t *data_buffer, uint8_t outputType); + bool _notBusy(uint32_t timeout = 10L); + bool _addressCheck(uint32_t address); + bool _beginWrite(uint32_t address); + bool _readPage(uint16_t page_number, uint8_t *page_buffer); + bool _writeNextByte(uint8_t c); + bool _writeEnable(void); + bool _writeDisable(void); + bool _getJedecId(uint8_t *b1, uint8_t *b2, uint8_t *b3); + bool _getManId(uint8_t *b1, uint8_t *b2); + bool _writeByte(uint32_t address, uint8_t data, bool errorCheck = true); + uint8_t _readNextByte(void); + uint8_t _readByte(uint32_t address); + uint32_t _getAddress(uint16_t page_number, uint8_t offset = 0); + uint32_t _prepRead(uint16_t page_number, uint8_t offset = 0); + uint32_t _prepWrite(uint16_t page_number, uint8_t offset = 0); + template bool _writeErrorCheck(uint32_t address, const T& value); + + volatile uint8_t *cs_port; + uint8_t cs_mask; + uint8_t chipSelect; + uint32_t capacity, maxPage, errorcode; + bool pageOverflow; + const uint8_t devType[10] = {0x5, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}; + const uint32_t memSize[10] = {64L * 1024L, 128L * 1024L, 256L * 1024L, 512L * 1024L, 1L * 1024L * 1024L, + 2L * 1024L * 1024L, 4L * 1024L * 1024L, 8L * 1024L * 1024L, 16L * 1024L * 1024L}; +}; + +template uint32_t SPIFlash::writeAnything(uint16_t page_number, uint8_t offset, const T& value) +{ + uint32_t address = _getAddress(page_number, offset); + Serial.println(address); + const byte* p = (const byte*)(const void*)&value; + uint16_t i; + for (i = 0; i < sizeof(value); i++){ + _writeByte(address++, *p++); + } + return i; +} + +template uint32_t SPIFlash::readAnything(uint16_t page_number, uint8_t offset, T& value) +{ + uint32_t address = _getAddress(page_number, offset); + uint8_t errorcode; + Serial.println(address); + byte* p = (byte*)(void*)&value; + uint16_t i; + for (i = 0; i < sizeof(value); i++) { + *p++ = _readByte(address++); + } + return i; +} + +template bool SPIFlash::_writeErrorCheck(uint32_t address, const T& value) +{ + const byte* p = (const byte*)(const void*)&value; + uint16_t i = 0; + _beginRead(address); + for(i = 0; i < (sizeof(value));i++) + { + if (*p++ != _readNextByte()) + return false; + } + _endProcess(); + return true; +} + + +#endif // _SPIFLASH_H_ \ No newline at end of file diff --git a/examples/Data_writer/Data_writer.ino b/examples/Data_writer/Data_writer.ino new file mode 100644 index 0000000..44ce759 --- /dev/null +++ b/examples/Data_writer/Data_writer.ino @@ -0,0 +1,88 @@ +#include +#include + +#define SENSOR + +const int LDR = A0; +const int cs = 10; + + +SPIFlash flash(cs); + + +struct Configuration { + float lux; + float vOut; // voltage ouput from potential divider to Anolg input + float RLDR; // Resistance calculation of potential divider with LDR + bool light; + uint8_t adc; +}; +Configuration configuration; + +void setup() { + Serial.begin(115200); + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + Serial.println(); +} + +void loop() { + #ifndef SENSOR + configuration.lux = 98.43; + configuration.vOut = 4.84; + configuration.RLDR = 889.32; + configuration.light = true; + configuration.adc = 5; + #endif + #ifdef SENSOR + readLDR(); + #endif + //currentAddress = flash.writeAnything(0, 0, configuration); + + Serial.print("Saving amount at: "); + Serial.println(flash.writeAnything(2, 4, configuration)); + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + + Serial.println("Saved!"); + configuration.lux = 0; + configuration.vOut = 0; + configuration.RLDR = 0; + configuration.light = 0; + configuration.adc = 0; + Serial.println(); + Serial.println("Local values set to 0"); + Serial.println(); + Serial.print("Reading back from: "); + Serial.println(flash.readAnything(2, 4, configuration)); + flash.eraseSector(2); + + Serial.println("After reading"); + Serial.println(configuration.lux); + Serial.println(configuration.vOut); + Serial.println(configuration.RLDR); + Serial.println(configuration.light); + Serial.println(configuration.adc); + + while(1){} + +} + +void readLDR() +{ + configuration.adc = analogRead(LDR); + configuration.vOut = (configuration.adc * 0.0048828125); // vOut = Output voltage from potential Divider. [vOut = ADC * (Vin / 1024)] + configuration.RLDR = (10.0 * (5 - configuration.vOut)) / configuration.vOut; // Equation to calculate Resistance of LDR, [R-LDR =(R1 (Vin - vOut))/ vOut]. R1 is in KOhms + // R1 = 10 KOhms , Vin = 5.0 Vdc. + configuration.lux = (500 / configuration.RLDR); +} + + + diff --git a/examples/Diagnostics/Diagnostics.ino b/examples/Diagnostics/Diagnostics.ino new file mode 100644 index 0000000..345cc70 --- /dev/null +++ b/examples/Diagnostics/Diagnostics.ino @@ -0,0 +1,209 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Diagnostics.ino // +// SPIFlash library // +// v 1.3.0 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Prajwal Bhattaram // +// Created: 30.08.15 // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// // +// For a full diagnostics rundown - with error codes and details of the errors // +// uncomment #define RUNDIAGNOSTIC in SPIFlash.cpp in the library before compiling // +// and loading this application onto your Arduino. // +// // +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + +#include +#include +const int cs = 10; +uint8_t pageBuffer[256]; +char printBuffer[128]; + +struct Test { + word s1; + float s2; + long s3; + bool s4; + uint8_t s5; +}; +Test test; + +uint8_t _byte = 35; +int8_t _char = -110; +uint16_t _word = 4520; +int16_t _short = -1250; +uint32_t _uLong = 876532; +int32_t _long = -10959; +float _float = 3.1415; + +SPIFlash flash(cs); + +void setup() { + Serial.begin(115200); + Serial.print(F("Initialising Flash memory")); + for (int i = 0; i < 10; ++i) + { + Serial.print(F(".")); + } + Serial.println(); + flash.begin(); + Serial.println(); + Serial.println(); + + ID(); + writeData(); +} + +void loop() { + +} + +void ID() { + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Get ID ")); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + uint8_t b1, b2; + uint16_t b3; + uint32_t JEDEC = flash.getJEDECID(); + uint16_t ManID = flash.getManID(); + b1 = (ManID >> 8); + b2 = (ManID >> 0); + b3 = (JEDEC >> 0); + clearprintBuffer(); + sprintf(printBuffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3); + Serial.println(printBuffer); + clearprintBuffer(); + sprintf(printBuffer, "JEDEC ID: %04lxh", JEDEC); + Serial.println(printBuffer); +} + +void writeData() { + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Write Data ")); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + + test.s1 = 31325; + test.s2 = 4.84; + test.s3 = 880932; + test.s4 = true; + test.s5 = 5; + + flash.writeByte(1920, 4, _byte); + flash.writeChar(1920, 5, _char); + flash.writeWord(1920, 6, _word); + flash.writeShort(1920, 8, _short); + flash.writeULong(1920, 10, _uLong); + flash.writeLong(1920, 14, _long); + flash.writeFloat(1920, 18, _float); + + Serial.println("Data Written\t\t||\t\tData Read\t\t||\t\tMatch"); + + Serial.print(_byte); + Serial.print("\t\t||\t\t"); + Serial.print(flash.readByte(1920, 4)); + Serial.print("\t\t||\t\t"); + if (_byte == flash.readByte(1920, 4)) + Serial.print("True"); + else + Serial.print("False"); + + Serial.print(_char); + Serial.print("\t\t||\t\t"); + Serial.print(flash.readChar(1920, 5)); + Serial.print("\t\t||\t\t"); + if (_char == flash.readChar(1920, 5)) + Serial.print("True"); + else + Serial.print("False"); + + Serial.print(_word); + Serial.print("\t\t||\t\t"); + Serial.print(flash.readWord(1920, 6)); + Serial.print("\t\t||\t\t"); + if (_word == flash.readWord(1920, 6)) + Serial.print("True"); + else + Serial.print("False"); + + Serial.print(_short); + Serial.print("\t\t||\t\t"); + Serial.print(flash.readShort(1920, 8)); + Serial.print("\t\t||\t\t"); + if (_short == flash.readShort(1920, 8)) + Serial.print("True"); + else + Serial.print("False"); + + Serial.print(_uLong); + Serial.print("\t\t||\t\t"); + Serial.print(flash.readULong(1920, 10)); + Serial.print("\t\t||\t\t"); + if (_uLong == flash.readULong(1920, 10)) + Serial.print("True"); + else + Serial.print("False"); + + Serial.print(_long); + Serial.print("\t\t||\t\t"); + Serial.print(flash.readLong(1920, 14)); + Serial.print("\t\t||\t\t"); + if (_long == flash.readLong(1920, 14)) + Serial.print("True"); + else + Serial.print("False"); + + Serial.print(_float); + Serial.print("\t\t||\t\t"); + Serial.print(flash.readFloat(1920, 18)); + Serial.print("\t\t||\t\t"); + if (_float == flash.readFloat(1920, 18)) + Serial.print("True"); + else + Serial.print("False"); + + Serial.print("Saving struct at: "); + Serial.println(flash.writeAnything(2, 4, test)); + + Serial.println("Saved!"); + test.s1 = 0; + test.s2 = 0; + test.s3 = 0; + test.s4 = 0; + test.s5 = 0; + Serial.println(); + Serial.println("Local values set to 0"); + Serial.println(); + Serial.print("Reading struct back from: "); + Serial.println(flash.readAnything(2, 4, test)); + flash.eraseSector(2); + + Serial.println("After reading"); + Serial.println(test.s1); + Serial.println(test.s2); + Serial.println(test.s3); + Serial.println(test.s4); + Serial.println(test.s5); + + for (int i = 0; i < 256; ++i) { + pageBuffer[i] = i; + } + uint16_t page = 836; + uint8_t hex = 1, dec = 2; + flash.writePage(page, pageBuffer); + clearprintBuffer(); + sprintf(printBuffer, "Values from 0 to 255 have been written to the page %d", page); + Serial.println(printBuffer); + clearprintBuffer(); + sprintf(printBuffer, "These values have been read back from page %d", page); + Serial.println(printBuffer); + flash.printPage(page, dec); +} + +void clearprintBuffer() +{ + for (uint8_t i = 0; i < 128; i++) { + printBuffer[i] = 0; + } +} diff --git a/examples/TestFlash/TestFlash.ino b/examples/TestFlash/TestFlash.ino index d4daca0..653f461 100644 --- a/examples/TestFlash/TestFlash.ino +++ b/examples/TestFlash/TestFlash.ino @@ -1,10 +1,10 @@ /* *----------------------------------------------------------------------------------------------------------------------------------* - | W25Q80BV - Winbond 64 Mbit (1MB) Flash | - | SPIFlash library test v1.2.0 | + | Winbond Flash | + | SPIFlash library test v1.3.0 | |----------------------------------------------------------------------------------------------------------------------------------| | Prajwal Bhattaram | - | 20.06.2015 | + | 30.08.2015 | |----------------------------------------------------------------------------------------------------------------------------------| | (Please make sure your Serial monitor is set to 'No Line Ending') | | ***************************************************************** | @@ -21,32 +21,39 @@ | | | 3. Read Byte [page] [offset] | | '3' followed by '100' and then by '20' returns the byte from page 100 position 20 | + | | + | 4. Write Word [page] [offset] | + | '4' followed by '55' and then by '35' and then by '633' writes the int 633 to page 5 position 35 | + | | + | 5. readWord [page] [offset]")); | + | '5' followed by '200' and then by '30' returns the int from page 200 position 30 | | | - | 4. Write Page [page] | - | '4' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33 | + | 6. Write Page [page] | + | '6' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33 | | | - | 5. Read Page [page] | - | '5' followed by 33 reads page 33 | + | 7. Print Page [page] | + | '7' followed by 33 reads & prints page 33. To just read a page to a data buffer, refer | + | to 'ReadMe.md' in the library folder. | | | - | 6. Read All Pages | - | '6' reads all 4096 pages and outputs them to the serial console | + | 8. Print All Pages | + | '8' reads all 4096 pages and outputs them to the serial console | | This function is to extract data from a flash chip onto a computer as a text file. | | Refer to 'Read me.md' in the library for details. | | | - | 7. Erase sector | - | '7' followed by 2 erases a 4KB sector containing the page to be erased | + | 9. Erase 4KB sector | + | '9' followed by 2 erases a 4KB sector containing the page to be erased | | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | | | - | 8. Erase sector | - | '8' followed by 2 erases a 32KB block containing the page to be erased | + | 10. Erase 32KB block | + | '10' followed by 2 erases a 32KB block containing the page to be erased | | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | | | - | 9. Erase sector | - | '9' followed by 2 erases a 64KB block containing the page to be erased | + | 11. Erase 64KB block | + | '11' followed by 2 erases a 64KB block containing the page to be erased | | Page 0-15 --> Sector 0; Page 16-31 --> Sector 1;......Page 4080-4095 --> Sector 255 | | | - | 10. Erase Chip | - | '10' erases the entire chip | + | 12. Erase Chip | + | '12' erases the entire chip | | | ^----------------------------------------------------------------------------------------------------------------------------------^ */ @@ -61,17 +68,26 @@ String serialCommand; char printBuffer[128]; uint16_t page; uint8_t offset, dataByte; +uint16_t dataInt; + SPIFlash flash(cs); void setup() { - Serial.begin(9600); - Serial.println(F("Initialising Flash memory")); + Serial.begin(115200); + Serial.print(F("Initialising Flash memory")); for (int i = 0; i < 10; ++i) { Serial.print(F(".")); } Serial.println(); + flash.begin();/* + clearprintBuffer(); + sprintf(printBuffer, "Flash initiation code: %x", flashCode); + Serial.println(printBuffer); + Serial.println(F("If flashCode !=0 please redownload the latest version of the library.")); + Serial.println(F("If flashcode still !=0 after downloading the latest version, please raise an issue at https://github.com/Marzogh/SPIFlash/issues."));*/ + Serial.println(); Serial.println(); commandList(); } @@ -85,9 +101,21 @@ void loop() { else if (commandNo == 1) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F(" Function 1 : Get JEDEC ID ")); - Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - flash.getID(); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + uint8_t b1, b2; + uint16_t b3; + uint32_t JEDEC = flash.getJEDECID(); + uint16_t ManID = flash.getManID(); + b1 = (ManID >> 8); + b2 = (ManID >> 0); + b3 = (JEDEC >> 0); + clearprintBuffer(); + sprintf(printBuffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3); + Serial.println(printBuffer); + clearprintBuffer(); + sprintf(printBuffer, "JEDEC ID: %04lxh", JEDEC); + Serial.println(printBuffer); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } @@ -111,10 +139,12 @@ void loop() { } dataByte = Serial.parseInt(); Serial.println(dataByte); - flash.writeByte(page, offset, dataByte); - clearprintBuffer(); - sprintf(printBuffer, "%d has been written to position %d on page %d", dataByte, offset, page); - Serial.println(printBuffer); + Serial.println(flash.writeByte(page, offset, dataByte)); + /*else { + clearprintBuffer(); + sprintf(printBuffer, "%d has been written to position %d on page %d", dataByte, offset, page); + Serial.println(printBuffer); + }*/ Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } @@ -142,7 +172,56 @@ void loop() { } else if (commandNo == 4) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" Function 4 : Write Page ")); + Serial.println(F(" Function 4 : Write Word ")); + Serial.println(F(" SPIFlash library test ")); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.print(F("Please enter the number of the page (0-4095) you wish to modify: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position on the page (0-255) you wish to modify: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + Serial.print(F("Please enter the value of the word (>255) you wish to save: ")); + while (!Serial.available()) { + } + dataInt = Serial.parseInt(); + Serial.println(dataInt); + flash.writeWord(page, offset, dataInt); + clearprintBuffer(); + sprintf(printBuffer, "%d has been written to position %d on page %d", dataInt, offset, page); + Serial.println(printBuffer); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F("Please type the next command. Type 0 to get the list of commands")); + } + else if (commandNo == 5) { + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Function 5 : Read Word ")); + Serial.println(F(" SPIFlash library test ")); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.print(F("Please enter the number of the page (0-4095) the byte you wish to read is on: ")); + while (!Serial.available()) { + } + page = Serial.parseInt(); + Serial.println(page); + Serial.print(F("Please enter the position of the word on the page (0-255) you wish to read: ")); + while (!Serial.available()) { + } + offset = Serial.parseInt(); + Serial.println(offset); + clearprintBuffer(); + sprintf(printBuffer, "The unsigned int at position %d on page %d is: ", offset, page); + Serial.print(printBuffer); + Serial.println(flash.readWord(page, offset)); + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F("Please type the next command. Type 0 to get the list of commands")); + } + else if (commandNo == 6) { + Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); + Serial.println(F(" Function 6 : Write Page ")); Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("This function will write a sequence of bytes (0-255) to the page selected.")); @@ -174,9 +253,9 @@ void loop() { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } - else if (commandNo == 5) { + else if (commandNo == 7) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" Function 5 : Read Page ")); + Serial.println(F(" Function 7 : Read Page ")); Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("This function will read the entire page selected.")); @@ -194,9 +273,9 @@ void loop() { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } - else if (commandNo == 6) { + else if (commandNo == 8) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" Function 6 : Read All Pages ")); + Serial.println(F(" Function 8 : Read All Pages ")); Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("This function will read the entire flash memory.")); @@ -216,9 +295,9 @@ void loop() { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } - else if (commandNo == 7) { + else if (commandNo == 9) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" Function 7 : Erase sector ")); + Serial.println(F(" Function 9 : Erase sector ")); Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("This function will erase a 4KB sector.")); @@ -247,9 +326,9 @@ void loop() { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } - else if (commandNo == 8) { + else if (commandNo == 10) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" Function 8 : Erase 32KB Block ")); + Serial.println(F(" Function 10 : Erase 32KB Block ")); Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("This function will erase a 32KB block.")); @@ -278,9 +357,9 @@ void loop() { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } - else if (commandNo == 9) { + else if (commandNo == 11) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" Function 9 : Erase 64KB Block ")); + Serial.println(F(" Function 11 : Erase 64KB Block ")); Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("This function will erase a 64KB block.")); @@ -309,9 +388,9 @@ void loop() { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); } - else if (commandNo == 10) { + else if (commandNo == 12) { Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" Function 8 : Erase Chip ")); + Serial.println(F(" Function 12 : Erase Chip ")); Serial.println(F(" SPIFlash library test ")); Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("This function will erase the entire flash memory.")); @@ -321,8 +400,10 @@ void loop() { } c = (char)Serial.read(); if (c == 'Y' || c == 'y') { - flash.eraseChip(); - Serial.println(F("Chip erased")); + if (flash.eraseChip()) + Serial.println(F("Chip erased")); + else + Serial.println(F("Error erasing chip")); } Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F("Please type the next command. Type 0 to get the list of commands")); diff --git a/examples/TestFlash/command_list.ino b/examples/TestFlash/command_list.ino index 57b74b2..8f175e7 100644 --- a/examples/TestFlash/command_list.ino +++ b/examples/TestFlash/command_list.ino @@ -1,10 +1,10 @@ void commandList() { Serial.println(F("-----------------------------------------------------------------------------------------------------------------------------------")); - Serial.println(F(" W25Q80BV - Winbond 64 Mbit (1MB) Flash ")); - Serial.println(F(" SPIFlash library test v1.2.0 ")); + Serial.println(F(" Winbond Flash ")); + Serial.println(F(" SPIFlash library test v1.3.0 ")); Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F(" Prajwal Bhattaram ")); - Serial.println(F(" 20.06.2015 ")); + Serial.println(F(" 29.08.2015 ")); Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); Serial.println(F(" (Please make sure your Serial monitor is set to 'No Line Ending') ")); Serial.println(F(" ***************************************************************** ")); @@ -22,30 +22,36 @@ void commandList() { Serial.println(F(" 3. readByte [page] [offset]")); Serial.print(F("\t\t")); Serial.println(F("'3' followed by '100' and then by '20' returns the byte from page 100 position 20")); - Serial.println(F(" 4. writePage [page]")); + Serial.println(F(" 4. writeWord [page] [offset]")); Serial.print(F("\t\t")); - Serial.println(F("'4' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33")); - Serial.println(F(" 5. readPage [page]")); + Serial.println(F("'4' followed by '55' and then by '35' and then by '633' writes the int 633 to page 5 position 35")); + Serial.println(F(" 5. readWord [page] [offset]")); Serial.print(F("\t\t")); - Serial.println(F("'5' followed by 33 reads page 33")); - Serial.println(F(" 6. readAllPages")); + Serial.println(F("'5' followed by '200' and then by '30' returns the int from page 200 position 30")); + Serial.println(F(" 6. writePage [page]")); Serial.print(F("\t\t")); - Serial.println(F("'6' reads all 4096 pages and outputs them to the serial console")); + Serial.println(F("'6' followed by '33' writes bytes from 0 to 255 sequentially to fill page 33")); + Serial.println(F(" 7. readPage [page]")); + Serial.print(F("\t\t")); + Serial.println(F("'7' followed by 33 reads page 33")); + Serial.println(F(" 8. readAllPages")); + Serial.print(F("\t\t")); + Serial.println(F("'8' reads all 4096 pages and outputs them to the serial console")); Serial.print(F("\t\t")); Serial.println(F("This function is to extract data from a flash chip onto a computer as a text file")); Serial.print(F("\t\t")); Serial.println(F("Refer to 'Read me.md' in the library for details")); - Serial.println(F(" 7. eraseSector")); + Serial.println(F(" 9. eraseSector")); Serial.print(F("\t\t")); - Serial.println(F("'7' followed by '3' erases a 4KB sector (Sector 0) containing the page 3")); - Serial.println(F(" 8. eraseBlock32K")); + Serial.println(F("'9' followed by '3' erases a 4KB sector (Sector 0) containing the page 3")); + Serial.println(F(" 10. eraseBlock32K")); Serial.print(F("\t\t")); - Serial.println(F("'8' followed by '132' erases a 32KB sector (Sector 1) containing the page 132")); - Serial.println(F(" 9. eraseBlock64K")); + Serial.println(F("'10' followed by '132' erases a 32KB sector (Sector 1) containing the page 132")); + Serial.println(F(" 11. eraseBlock64K")); Serial.print(F("\t\t")); - Serial.println(F("'9' followed by '543' erases a 64KB sector (Sector 2) containing the page 543")); - Serial.println(F(" 10. eraseChip")); + Serial.println(F("'11' followed by '543' erases a 64KB sector (Sector 2) containing the page 543")); + Serial.println(F(" 12. eraseChip")); Serial.print(F("\t\t")); - Serial.println(F("'10' erases the entire chip")); + Serial.println(F("'12' erases the entire chip")); Serial.println(F(" ----------------------------------------------------------------------------------------------------------------------------------")); } diff --git a/extras/Winbond Flash Instructions - Comparison.xlsx b/extras/Winbond Flash Instructions - Comparison.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..b8a4b3357d2da1d4c05c7607d05cfc2840871f2f GIT binary patch literal 41353 zcmeFX1yo$i)+c@%ceg;G2~Hrm1b5d2f(4i054a`M+2L6}rQkD7-}N z8E}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tN$>ZysoQ)=pJMHQA6FHG8Y&A0z<#eRoJpHHj` zc)rm=bw}T=9J`vp2y|&x^u{Z0?o`n(>uUYex3)DfxR;W@)0@WDQu13UjU;6}b``3coul@To z`!9caf%CIMz*Ha|5C6e0*!$ajIPCn#3L;+|&rkss3;F`o8S7H(;DA#X{7xSWx$x~M(7)>ckYDJN z9`N}mpex3Ir~wA+CaB@t*9Qmq`Go}kOOJm0=eK9;FZ+{t<(&I1Fap=Xp#1TUEYkX| z!jJ&JAU|+sB6$6+mOuBYS1Y-<91KX43JRtEhZen9{`WqGgrD{M%g!u)c=B<*1~?HU z2plu_hoXhxRMbCq=J#&=xdDGZO!fDQvcS=epqA7B!O^OJujoHMF!J|`7H;|vkB|Iw zYyRj=|6T -sentence=Winbond W25Q80BV SPI flash library for Arduino. -paragraph=This library enables reading and writing bytes from and to various locations, reading and writing pages, sector, block and chip erase, powering down for low power operation and continuous read functions. Refer to change log for further information about this release. -category=Data Storage -url=https://github.com/Marzogh/SPIFlash -architectures=* +name=SPIFlash +version=1.3.0 +author=Marzogh +maintainer=Marzogh +sentence=Winbond SPI flash library for Arduino. +paragraph=This library enables read, write, erase and power functions on the following Winbond NOR Flash chips - W25X05CL, W25X10BV, W25X20BV, W25X40BV, W25Q80BV, W25Q16BV, W25Q32BV, W25Q64BV & W25Q128BV. Refer to change log for further information about this release. +category=Data Storage +url=https://github.com/Marzogh/SPIFlash +architectures=* \ No newline at end of file