diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 86ac9d2..2aa2a40 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p Please ensure to specify the following: * Arduino IDE version (e.g. 1.8.19) or Platform.io version -* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.12, Adafruit SAMD core v1.7.7, Seeed Studio SAMD v1.8.2) +* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.13, Adafruit SAMD core v1.7.11, Seeed Studio SAMD v1.8.3) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce * Anything that might be relevant in your opinion, such as: @@ -27,12 +27,12 @@ Please ensure to specify the following: ``` Arduino IDE version: 1.8.19 -Arduino SAMD Core Version 1.8.12 +Arduino SAMD Core Version 1.8.13 OS: Ubuntu 20.04 LTS -Linux Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Context: -I encountered a crash while trying to use the Timer Interrupt. +I encountered a crash while using this library Steps to reproduce: 1. ... @@ -41,12 +41,33 @@ Steps to reproduce: 4. ... ``` +--- + ### Sending Feature Requests Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/FlashStorage_SAMD/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. +--- + ### Sending Pull Requests Pull Requests with changes and fixes are also welcome! + +Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) + +1. Change directory to the library GitHub + +``` +xy@xy-Inspiron-3593:~$ cd Arduino/xy/FlashStorage_SAMD_GitHub/ +xy@xy-Inspiron-3593:~/Arduino/xy/FlashStorage_SAMD_GitHub$ +``` + +2. Issue astyle command + +``` +xy@xy-Inspiron-3593:~/Arduino/xy/FlashStorage_SAMD_GitHub$ bash utils/restyle.sh +``` + + diff --git a/changelog.md b/changelog.md index a977c61..ee27d67 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,13 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/FlashStorage_SAMD.svg)](http://github.com/khoih-prog/FlashStorage_SAMD/issues) + +Donate to my libraries using BuyMeACoffee + + + + + --- --- diff --git a/examples/EEPROM_CRC/EEPROM_CRC.ino b/examples/EEPROM_CRC/EEPROM_CRC.ino index b982837..a2dbbb4 100644 --- a/examples/EEPROM_CRC/EEPROM_CRC.ino +++ b/examples/EEPROM_CRC/EEPROM_CRC.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ /*** @@ -39,7 +39,7 @@ // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include -unsigned long eeprom_crc() +unsigned long eeprom_crc() { const unsigned long crc_table[16] = { @@ -64,11 +64,13 @@ unsigned long eeprom_crc() void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_CRC on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_CRC on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); //Print length of data to run CRC on. @@ -81,7 +83,7 @@ void setup() Serial.print("Done!"); } -void loop() +void loop() { /* Empty loop */ } diff --git a/examples/EEPROM_Clear/EEPROM_Clear.ino b/examples/EEPROM_Clear/EEPROM_Clear.ino index b295a37..6461c06 100644 --- a/examples/EEPROM_Clear/EEPROM_Clear.ino +++ b/examples/EEPROM_Clear/EEPROM_Clear.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ @@ -31,25 +31,28 @@ // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include -void setup() +void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_Clear on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_Clear on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); - + // initialize the LED pin as an output. pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); - Serial.print("Emulated EEPROM length (bytes) = "); Serial.println(EEPROM.length()); + Serial.print("Emulated EEPROM length (bytes) = "); + Serial.println(EEPROM.length()); unsigned long startMillis = millis(); - - for (int i = 0 ; i < EEPROM.length() ; i++) + + for (int i = 0 ; i < EEPROM.length() ; i++) { EEPROM.write(i, 0); } @@ -58,13 +61,14 @@ void setup() // The time spent can be very short (5-25ms) if the EEPROM is not dirty. // For Seeed XIAO, the time is around 22 / 42 ms for 2048 / 4096 bytes of emulated-EEPROM - Serial.print("Done clearing emulated EEPROM. Time spent (ms) = "); Serial.println(millis() - startMillis); + Serial.print("Done clearing emulated EEPROM. Time spent (ms) = "); + Serial.println(millis() - startMillis); // turn the LED on when we're done digitalWrite(LED_BUILTIN, HIGH); } -void loop() +void loop() { /** Empty loop. **/ } diff --git a/examples/EEPROM_get/EEPROM_get.ino b/examples/EEPROM_get/EEPROM_get.ino index 44dd000..4ea2b26 100644 --- a/examples/EEPROM_get/EEPROM_get.ino +++ b/examples/EEPROM_get/EEPROM_get.ino @@ -58,15 +58,19 @@ struct MyObject void printMyObject(MyObject &customVar) { Serial.println("==============="); - Serial.print("Field1: "); Serial.println(customVar.field1, 5); - Serial.print("Field2: "); Serial.println(customVar.field2); - Serial.print("Name: "); Serial.println(customVar.name); + Serial.print("Field1: "); + Serial.println(customVar.field1, 5); + Serial.print("Field2: "); + Serial.println(customVar.field2); + Serial.print("Name: "); + Serial.println(customVar.name); Serial.println("==============="); } void secondTest() { - int eeAddress = START_ADDRESS + sizeof(WRITTEN_SIGNATURE) + sizeof(float); //Move address to the next byte after float 'f'. + int eeAddress = START_ADDRESS + sizeof(WRITTEN_SIGNATURE) + sizeof( + float); //Move address to the next byte after float 'f'. MyObject customVar; //Variable to store custom object read from EEPROM. EEPROM.get(eeAddress, customVar); @@ -78,11 +82,13 @@ void secondTest() void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_get on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_get on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); diff --git a/examples/EEPROM_iteration/EEPROM_iteration.ino b/examples/EEPROM_iteration/EEPROM_iteration.ino index a157a1b..ee41930 100644 --- a/examples/EEPROM_iteration/EEPROM_iteration.ino +++ b/examples/EEPROM_iteration/EEPROM_iteration.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ /*** @@ -44,11 +44,13 @@ void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_iteration on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_iteration on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); @@ -58,9 +60,9 @@ void setup() Iterate the EEPROM using a for loop. ***/ - for (int index = 0 ; index < EEPROM.length() ; index++) + for (int index = 0 ; index < EEPROM.length() ; index++) { - // Add one to each cell in the EEPROM + // Add one to each cell in the EEPROM EEPROM.write(index, EEPROM.read(index) + 1); } @@ -74,9 +76,9 @@ void setup() int index = 0; - while (index < EEPROM.length()) + while (index < EEPROM.length()) { - // Add one to each cell in the EEPROM + // Add one to each cell in the EEPROM EEPROM.write(index, EEPROM.read(index) + 1); index++; } @@ -101,7 +103,7 @@ void setup() EEPROM.commit(); Serial.println("Done do-while loop"); - + } //End of setup function. void loop() {} diff --git a/examples/EEPROM_put/EEPROM_put.ino b/examples/EEPROM_put/EEPROM_put.ino index d330252..1f5b1bb 100644 --- a/examples/EEPROM_put/EEPROM_put.ino +++ b/examples/EEPROM_put/EEPROM_put.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ /*** @@ -56,20 +56,25 @@ struct MyObject void printMyObject(MyObject &customVar) { Serial.println("==============="); - Serial.print("Field1: "); Serial.println(customVar.field1, 5); - Serial.print("Field2: "); Serial.println(customVar.field2); - Serial.print("Name: "); Serial.println(customVar.name); + Serial.print("Field1: "); + Serial.println(customVar.field1, 5); + Serial.print("Field2: "); + Serial.println(customVar.field2); + Serial.print("Name: "); + Serial.println(customVar.name); Serial.println("==============="); } void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_put on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_put on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); diff --git a/examples/EEPROM_read/EEPROM_read.ino b/examples/EEPROM_read/EEPROM_read.ino index fd25ae4..917cceb 100644 --- a/examples/EEPROM_read/EEPROM_read.ino +++ b/examples/EEPROM_read/EEPROM_read.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ /* @@ -44,18 +44,20 @@ byte value; void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_read on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_read on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); Serial.println(EEPROM.length()); } -void loop() +void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address); @@ -64,8 +66,8 @@ void loop() Serial.print("\t"); Serial.print(value, DEC); Serial.println(); - - if (++address == EEPROM.length()) + + if (++address == EEPROM.length()) { address = 0; } diff --git a/examples/EEPROM_update/EEPROM_update.ino b/examples/EEPROM_update/EEPROM_update.ino index 457deb3..ca841eb 100644 --- a/examples/EEPROM_update/EEPROM_update.ino +++ b/examples/EEPROM_update/EEPROM_update.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ /*** @@ -49,11 +49,13 @@ int address = 0; void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_read on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_read on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); @@ -63,12 +65,12 @@ void setup() void loop() { unsigned long startMillis = millis(); - - for (int i = 0 ; i < EEPROM.length() ; i++) + + for (int i = 0 ; i < EEPROM.length() ; i++) { /*** The function EEPROM.update(address, val) is equivalent to the following: - + if( EEPROM.read(address) != val ) { EEPROM.write(address, val); @@ -76,10 +78,11 @@ void loop() ***/ EEPROM.update(i, (uint8_t) analogRead(0)); } - + EEPROM.commit(); - Serial.print("Done updating emulated EEPROM. Time spent (ms) = "); Serial.println(millis() - startMillis); + Serial.print("Done updating emulated EEPROM. Time spent (ms) = "); + Serial.println(millis() - startMillis); delay(60000); } diff --git a/examples/EEPROM_write/EEPROM_write.ino b/examples/EEPROM_write/EEPROM_write.ino index a3cdac8..bdbf349 100644 --- a/examples/EEPROM_write/EEPROM_write.ino +++ b/examples/EEPROM_write/EEPROM_write.ino @@ -9,23 +9,23 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ /* EEPROM Write - Stores values read from analog input 0 into the EEPROM. These values will stay in the EEPROM + Stores values read from analog input 0 into the EEPROM. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch. */ @@ -43,11 +43,13 @@ int address = 0; void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EEPROM_write on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EEPROM_write on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); @@ -57,12 +59,12 @@ void setup() void loop() { unsigned long startMillis = millis(); - - for (int i = 0 ; i < EEPROM.length() ; i++) + + for (int i = 0 ; i < EEPROM.length() ; i++) { /*** The function EEPROM.update(address, val) is equivalent to the following: - + if( EEPROM.read(address) != val ) { EEPROM.write(address, val); @@ -70,10 +72,11 @@ void loop() ***/ EEPROM.write(i, (uint8_t) analogRead(0)); } - + EEPROM.commit(); - Serial.print("Done writing emulated EEPROM. Time spent (ms) = "); Serial.println(millis() - startMillis); + Serial.print("Done writing emulated EEPROM. Time spent (ms) = "); + Serial.println(millis() - startMillis); delay(60000); } diff --git a/examples/EmulateEEPROM/EmulateEEPROM.ino b/examples/EmulateEEPROM/EmulateEEPROM.ino index d1018f4..7f9170a 100644 --- a/examples/EmulateEEPROM/EmulateEEPROM.ino +++ b/examples/EmulateEEPROM/EmulateEEPROM.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ @@ -37,11 +37,13 @@ const int WRITTEN_SIGNATURE = 0xBEEFDEED; void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart EmulatedEEPROM on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart EmulatedEEPROM on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); @@ -82,7 +84,8 @@ void setup() { EEPROM.get(0, signature); - Serial.print("EEPROM has been written.Signature = 0x"); Serial.println(signature, HEX); + Serial.print("EEPROM has been written.Signature = 0x"); + Serial.println(signature, HEX); Serial.println("Here is the content of the next 16 bytes:"); @@ -103,7 +106,7 @@ void setup() Serial.println("CommitASAP not set. Need commit()"); EEPROM.commit(); } - + Serial.println("Done clearing signature in emulated EEPROM. You can reset now"); } } diff --git a/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino b/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino index 8464827..1616aee 100644 --- a/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino +++ b/examples/FlashStoreAndRetrieve/FlashStoreAndRetrieve.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ @@ -37,11 +37,13 @@ void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart FlashStoreAndRetrieve on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart FlashStoreAndRetrieve on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); @@ -54,7 +56,8 @@ void setup() EEPROM.get(address, number); // Print the current number on the serial monitor - Serial.print("Number = 0x"); Serial.println(number, HEX); + Serial.print("Number = 0x"); + Serial.println(number, HEX); // Save into emulated-EEPROM the number increased by 1 for the next run of the sketch EEPROM.put(address, (int) (number + 1)); diff --git a/examples/StoreNameAndSurname/StoreNameAndSurname.ino b/examples/StoreNameAndSurname/StoreNameAndSurname.ino index 5ae80c7..48c5e03 100644 --- a/examples/StoreNameAndSurname/StoreNameAndSurname.ino +++ b/examples/StoreNameAndSurname/StoreNameAndSurname.ino @@ -9,17 +9,17 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by A. Christian - + Copyright (c) 2015-2016 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) ******************************************************************************************************************************************/ @@ -46,11 +46,13 @@ typedef struct void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStart StoreNameAndSurname on ")); Serial.println(BOARD_NAME); + Serial.print(F("\nStart StoreNameAndSurname on ")); + Serial.println(BOARD_NAME); Serial.println(FLASH_STORAGE_SAMD_VERSION); Serial.print("EEPROM length: "); @@ -71,7 +73,10 @@ void setup() EEPROM.get(storedAddress + sizeof(signature), owner); // Say hello to the returning user! - Serial.print("Hi "); Serial.print(owner.name); Serial.print(" "); Serial.print(owner.surname); + Serial.print("Hi "); + Serial.print(owner.name); + Serial.print(" "); + Serial.print(owner.surname); Serial.println(", nice to see you again :-)"); Serial.println("Clearing WRITTEN_SIGNATURE for next try"); @@ -108,8 +113,10 @@ void setup() } // Print a confirmation of the data inserted. - Serial.print("<< Your name: "); Serial.print(owner.name); - Serial.print(". Your surname: "); Serial.print(owner.surname); + Serial.print("<< Your name: "); + Serial.print(owner.name); + Serial.print(". Your surname: "); + Serial.print(owner.surname); Serial.println(" >> have been saved. Thank you!"); Serial.println("You can reset to check emulated-EEPROM data retention."); } diff --git a/examples/multiFileProject/multiFileProject.cpp b/examples/multiFileProject/multiFileProject.cpp index 75687f7..2e9c34e 100644 --- a/examples/multiFileProject/multiFileProject.cpp +++ b/examples/multiFileProject/multiFileProject.cpp @@ -1,6 +1,6 @@ /**************************************************************************************************************************** multiFileProject.cpp - + For SAMD21/SAMD51 using Flash emulated-EEPROM The FlashStorage_SAMD library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory @@ -35,7 +35,10 @@ void testEEPROM() EEPROM.get(storedAddress + sizeof(signature), owner); // Say hello to the returning user! - Serial.print("Hi "); Serial.print(owner.name); Serial.print(" "); Serial.print(owner.surname); + Serial.print("Hi "); + Serial.print(owner.name); + Serial.print(" "); + Serial.print(owner.surname); Serial.println(", nice to see you again :-)"); Serial.println("Clearing WRITTEN_SIGNATURE for next try"); @@ -72,8 +75,10 @@ void testEEPROM() } // Print a confirmation of the data inserted. - Serial.print("<< Your name: "); Serial.print(owner.name); - Serial.print(". Your surname: "); Serial.print(owner.surname); + Serial.print("<< Your name: "); + Serial.print(owner.name); + Serial.print(". Your surname: "); + Serial.print(owner.surname); Serial.println(" >> have been saved. Thank you!"); Serial.println("You can reset to check emulated-EEPROM data retention."); } diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h index 7cc2df2..7f77762 100644 --- a/examples/multiFileProject/multiFileProject.h +++ b/examples/multiFileProject/multiFileProject.h @@ -1,6 +1,6 @@ /**************************************************************************************************************************** multiFileProject.h - + For SAMD21/SAMD51 using Flash emulated-EEPROM The FlashStorage_SAMD library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino index b2f8426..a7cad67 100644 --- a/examples/multiFileProject/multiFileProject.ino +++ b/examples/multiFileProject/multiFileProject.ino @@ -1,6 +1,6 @@ /**************************************************************************************************************************** multiFileProject.ino - + For SAMD21/SAMD51 using Flash emulated-EEPROM The FlashStorage_SAMD library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory @@ -21,7 +21,7 @@ || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) - #error This code is designed to run on SAMD21/SAMD51 platform! Please check your Tools->Board setting. +#error This code is designed to run on SAMD21/SAMD51 platform! Please check your Tools->Board setting. #endif #define FLASH_STORAGE_SAMD_VERSION_MIN_TARGET "FlashStorage_SAMD v1.3.2" @@ -32,26 +32,29 @@ // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "FlashStorage_SAMD.h" -void setup() +void setup() { Serial.begin(115200); + while (!Serial); - + Serial.println("\nStart multiFileProject"); Serial.println(FLASH_STORAGE_SAMD_VERSION); #if defined(FLASH_STORAGE_SAMD_VERSION_MIN) + if (FLASH_STORAGE_SAMD_VERSION_INT < FLASH_STORAGE_SAMD_VERSION_MIN) { Serial.print("Warning. Must use this example on Version equal or later than : "); Serial.println(FLASH_STORAGE_SAMD_VERSION_MIN_TARGET); } + #endif testEEPROM(); } -void loop() +void loop() { // put your main code here, to run repeatedly: } diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 49131d3..7e8cd4a 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -35,6 +35,8 @@ upload_speed = 921600 ; Checks for the compatibility with frameworks and dev/platforms lib_compat_mode = strict +lib_ldf_mode = chain+ +;lib_ldf_mode = deep+ lib_deps = diff --git a/src/FlashAsEEPROM_SAMD.h b/src/FlashAsEEPROM_SAMD.h index 7980a11..4476699 100644 --- a/src/FlashAsEEPROM_SAMD.h +++ b/src/FlashAsEEPROM_SAMD.h @@ -9,19 +9,19 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by Cristian Maglie - + Copyright (c) 2015 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) - + Version: 1.3.2 Version Modified By Date Comments diff --git a/src/FlashStorage_SAMD.h b/src/FlashStorage_SAMD.h index 4f09153..537272f 100644 --- a/src/FlashStorage_SAMD.h +++ b/src/FlashStorage_SAMD.h @@ -9,19 +9,19 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by Cristian Maglie - + Copyright (c) 2015 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) - + Version: 1.3.2 Version Modified By Date Comments diff --git a/src/FlashStorage_SAMD21.h b/src/FlashStorage_SAMD21.h index 001394e..f58582c 100644 --- a/src/FlashStorage_SAMD21.h +++ b/src/FlashStorage_SAMD21.h @@ -9,19 +9,19 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by Cristian Maglie - + Copyright (c) 2015 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) - + Version: 1.3.2 Version Modified By Date Comments @@ -34,7 +34,7 @@ 1.3.1 K Hoang 25/01/2022 Reduce number of library files 1.3.2 K Hoang 26/01/2022 Make compatible with old libraries and codes ******************************************************************************************************************************************/ - + // The .hpp contains only definitions, and can be included as many times as necessary, without `Multiple Definitions` Linker Error // The .h contains implementations, and can be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error @@ -65,14 +65,14 @@ FlashClass::FlashClass(const void *flash_addr, uint32_t size) : static inline uint32_t read_unaligned_uint32(const void *data) { - union + union { uint32_t u32; uint8_t u8[4]; } res; - + const uint8_t *d = (const uint8_t *)data; - + res.u8[0] = d[0]; res.u8[1] = d[1]; res.u8[2] = d[2]; @@ -86,7 +86,7 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data) { // Calculate data boundaries uint32_t size = (flash_size + 3) / 4; - + volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr; const uint8_t *src_addr = (uint8_t *)data; @@ -94,16 +94,17 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data) NVMCTRL->CTRLB.bit.MANW = 1; // Do writes in pages - while (size) + while (size) { // Execute "PBC" Page Buffer Clear NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_PBC; + while (NVMCTRL->INTFLAG.bit.READY == 0) { } // Fill page buffer uint32_t i; - - for (i=0; i<(PAGE_SIZE/4) && size; i++) + + for (i = 0; i < (PAGE_SIZE / 4) && size; i++) { *dst_addr = read_unaligned_uint32(src_addr); src_addr += 4; @@ -113,6 +114,7 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data) // Execute "WP" Write Page NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_WP; + while (NVMCTRL->INTFLAG.bit.READY == 0) { } } } @@ -123,11 +125,14 @@ void FlashClass::read(const volatile void *flash_ptr, void *data) { FLASH_LOGERROR3(F("MAX_FLASH (KB) = "), MAX_FLASH / 1024, F(", ROW_SIZE ="), ROW_SIZE); FLASH_LOGERROR1(F("FlashStorage size = "), flash_size); - FLASH_LOGERROR0(F("FlashStorage Start Address: 0x")); FLASH_HEXLOGERROR0((uint32_t ) flash_address); - - FLASH_LOGDEBUG0(F("Read: flash_ptr = 0x")); FLASH_HEXLOGDEBUG0((uint32_t ) flash_ptr); - FLASH_LOGDEBUG0(F("data = 0x")); FLASH_HEXLOGDEBUG0(* (uint32_t *) data); - + FLASH_LOGERROR0(F("FlashStorage Start Address: 0x")); + FLASH_HEXLOGERROR0((uint32_t ) flash_address); + + FLASH_LOGDEBUG0(F("Read: flash_ptr = 0x")); + FLASH_HEXLOGDEBUG0((uint32_t ) flash_ptr); + FLASH_LOGDEBUG0(F("data = 0x")); + FLASH_HEXLOGDEBUG0(* (uint32_t *) data); + memcpy(data, (const void *)flash_ptr, flash_size); } @@ -136,14 +141,14 @@ void FlashClass::read(const volatile void *flash_ptr, void *data) void FlashClass::erase(const volatile void *flash_ptr, uint32_t size) { const uint8_t *ptr = (const uint8_t *)flash_ptr; - - while (size > ROW_SIZE) + + while (size > ROW_SIZE) { erase(ptr); ptr += ROW_SIZE; size -= ROW_SIZE; } - + erase(ptr); } @@ -153,6 +158,7 @@ void FlashClass::erase(const volatile void *flash_ptr) { NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr) / 2; NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER; + while (!NVMCTRL->INTFLAG.bit.READY) { } } diff --git a/src/FlashStorage_SAMD51.h b/src/FlashStorage_SAMD51.h index 6bc32ba..49f964c 100644 --- a/src/FlashStorage_SAMD51.h +++ b/src/FlashStorage_SAMD51.h @@ -9,19 +9,19 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by Cristian Maglie - + Copyright (c) 2015 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) - + Version: 1.3.2 Version Modified By Date Comments @@ -66,7 +66,8 @@ FlashClass::FlashClass(const void *flash_addr, uint32_t size) : static inline uint32_t read_unaligned_uint32(const void *data) { - union { + union + { uint32_t u32; uint8_t u8[4]; } res; @@ -84,13 +85,13 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data) { // Calculate data boundaries uint32_t size = (flash_size + 3) / 4; - + volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr; const uint8_t *src_addr = (uint8_t *)data; // Disable automatic page write NVMCTRL->CTRLA.bit.WMODE = 0; - + ////KH /* 1. Configure manual write for the NVM using WMODE (NVMCTRL.CTRLA). @@ -104,28 +105,28 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data) 9. Clear the DONE Flag (NVMCTRL.INTFLAG). */ //KH - + // 2. Make sure the NVM is ready to accept a new command (NVMCTRL.STATUS). - while (NVMCTRL->STATUS.bit.READY != NVMCTRL_STATUS_READY ) { } - + while (NVMCTRL->STATUS.bit.READY != NVMCTRL_STATUS_READY ) { } + // Do writes in pages - while (size) + while (size) { // Execute "PBC" Page Buffer Clear // 3. Clear page buffer ( NVMCTRL.CTRLB). NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_PBC; - + // 4. Make sure the NVM is ready to accept a new command (NVMCTRL.STATUS). - //while (NVMCTRL->STATUS.bit.READY != NVMCTRL_STATUS_READY ) { } - + //while (NVMCTRL->STATUS.bit.READY != NVMCTRL_STATUS_READY ) { } + // 5. Clear the DONE Flag (NVMCTRL.INTFLAG) while (NVMCTRL->INTFLAG.bit.DONE == 0) { } // 6. Write data to page buffer with 32-bit accesses at the needed address. // Fill page buffer uint32_t i; - - for (i=0; i<(PAGE_SIZE/4) && size; i++) + + for (i = 0; i < (PAGE_SIZE / 4) && size; i++) { *dst_addr = read_unaligned_uint32(src_addr); src_addr += 4; @@ -136,10 +137,10 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data) //7. Perform page write (NVMCTRL.CTRLB). // Execute "WP" Write Page NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_WP; - + // 8. Make sure NVM is ready to accept a new command (NVMCTRL.STATUS). - //while (NVMCTRL->STATUS.bit.READY != NVMCTRL_STATUS_READY ) { } - + //while (NVMCTRL->STATUS.bit.READY != NVMCTRL_STATUS_READY ) { } + // 9. Clear the DONE Flag (NVMCTRL.INTFLAG) while (NVMCTRL->INTFLAG.bit.DONE == 0) { } } @@ -151,11 +152,14 @@ void FlashClass::read(const volatile void *flash_ptr, void *data) { FLASH_LOGERROR3(F("MAX_FLASH (KB) = "), MAX_FLASH / 1024, F(", ROW_SIZE ="), ROW_SIZE); FLASH_LOGERROR1(F("FlashStorage size = "), flash_size); - FLASH_LOGERROR0(F("FlashStorage Start Address: 0x")); FLASH_HEXLOGERROR0((uint32_t ) flash_address); - - FLASH_LOGDEBUG0(F("Read: flash_ptr = 0x")); FLASH_HEXLOGDEBUG0((uint32_t ) flash_ptr); - FLASH_LOGDEBUG0(F("data = 0x")); FLASH_HEXLOGDEBUG0(* (uint32_t *) data); - + FLASH_LOGERROR0(F("FlashStorage Start Address: 0x")); + FLASH_HEXLOGERROR0((uint32_t ) flash_address); + + FLASH_LOGDEBUG0(F("Read: flash_ptr = 0x")); + FLASH_HEXLOGDEBUG0((uint32_t ) flash_ptr); + FLASH_LOGDEBUG0(F("data = 0x")); + FLASH_HEXLOGDEBUG0(* (uint32_t *) data); + memcpy(data, (const void *)flash_ptr, flash_size); } @@ -164,14 +168,14 @@ void FlashClass::read(const volatile void *flash_ptr, void *data) void FlashClass::erase(const volatile void *flash_ptr, uint32_t size) { const uint8_t *ptr = (const uint8_t *)flash_ptr; - - while (size > ROW_SIZE) + + while (size > ROW_SIZE) { erase(ptr); ptr += ROW_SIZE; size -= ROW_SIZE; } - + erase(ptr); } @@ -180,10 +184,10 @@ void FlashClass::erase(const volatile void *flash_ptr, uint32_t size) void FlashClass::erase(const volatile void *flash_ptr) { NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr); - + // Check, now erase PAGE, instead of ROW !!! NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | NVMCTRL_CTRLB_CMD_EB; - + while (NVMCTRL->INTFLAG.bit.DONE == 0) { } } diff --git a/src/FlashStorage_SAMD_Impl.h b/src/FlashStorage_SAMD_Impl.h index 14d0aee..ffb050a 100644 --- a/src/FlashStorage_SAMD_Impl.h +++ b/src/FlashStorage_SAMD_Impl.h @@ -9,19 +9,19 @@ Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_SAMD Licensed under LGPLv3 license - + Orginally written by Cristian Maglie - + Copyright (c) 2015 Arduino LLC. All right reserved. Copyright (c) 2020 Khoi Hoang. - - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bythe 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library. + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see (https://www.gnu.org/licenses/) - + Version: 1.3.2 Version Modified By Date Comments @@ -44,7 +44,7 @@ #define FlashStorage_SAMD_Impl_h #if ( defined(__SAMD51__) || defined(__SAMD51J20A__) || defined(__SAMD51J19A__) || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) ) - #include "FlashStorage_SAMD51.h" +#include "FlashStorage_SAMD51.h" #elif ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) \ || defined(ARDUINO_SAMD_MKRWAN1310) || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) \ @@ -52,9 +52,9 @@ || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) - #include "FlashStorage_SAMD21.h" +#include "FlashStorage_SAMD21.h" #else - #error This code is intended to run only on the SAMD21 or SAMD51 boards ! Please check your Tools->Board setting. +#error This code is intended to run only on the SAMD21 or SAMD51 boards ! Please check your Tools->Board setting. #endif #endif //#ifndef FlashStorage_SAMD_Impl_h diff --git a/utils/astyle_library.conf b/utils/astyle_library.conf new file mode 100644 index 0000000..8a73bc2 --- /dev/null +++ b/utils/astyle_library.conf @@ -0,0 +1,70 @@ +# Code formatting rules for Arduino libraries, modified from for KH libraries: +# +# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf +# + +# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino + +--mode=c +--lineend=linux +--style=allman + +# -r or -R +#--recursive + +# -c => Converts tabs into spaces +convert-tabs + +# -s2 => 2 spaces indentation +--indent=spaces=2 + +# -t2 => tab =2 spaces +#--indent=tab=2 + +# -C +--indent-classes + +# -S +--indent-switches + +# -xW +--indent-preproc-block + +# -Y => indent classes, switches (and cases), comments starting at column 1 +--indent-col1-comments + +# -M120 => maximum of 120 spaces to indent a continuation line +--max-continuation-indent=120 + +# -xC120 => max‑code‑length will break a line if the code exceeds # characters +--max-code-length=120 + +# -f => +--break-blocks + +# -p => put a space around operators +--pad-oper + +# -xg => Insert space padding after commas +--pad-comma + +# -H => put a space after if/for/while +pad-header + +# -xb => Break one line headers (e.g. if/for/while) +--break-one-line-headers + +# -c => Converts tabs into spaces +#--convert-tabs + +# if you like one-liners, keep them +#keep-one-line-statements + +# -xV +--attach-closing-while + +#unpad-paren + +# -xp +remove-comment-prefix + diff --git a/utils/restyle.sh b/utils/restyle.sh new file mode 100644 index 0000000..bcd846f --- /dev/null +++ b/utils/restyle.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for dir in . ; do + find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \; +done +