From 7a93b667ffccb17b1e6ff90cc20c0283975a7e48 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Thu, 24 Nov 2022 23:09:35 -0500 Subject: [PATCH] Update `README.md` and use `allman` astyle --- CONTRIBUTING.md | 28 +- README.md | 288 ++-- changelog.md | 8 +- examples/checkWaitingMRD/checkWaitingMRD.ino | 24 +- examples/minimal/minimal.ino | 12 +- platformio/platformio.ini | 2 + src/MultiResetDetector_Generic.h | 1249 +++++++++--------- src/mbed_portenta/FlashIAPLimits.h | 24 +- utils/astyle_library.conf | 70 + utils/restyle.sh | 6 + 10 files changed, 958 insertions(+), 753 deletions(-) create mode 100644 utils/astyle_library.conf create mode 100644 utils/restyle.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5a0c2e5..1efc134 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.13, Adafruit SAMD core v1.7.9, 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: @@ -29,10 +29,10 @@ Please ensure to specify the following: Arduino IDE version: 1.8.19 Arduino SAMD Core Version 1.8.13 OS: Ubuntu 20.04 LTS -Linux kh-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 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 an endless loop while trying to connect to Local WiFi. +I encountered a crash while using this library Steps to reproduce: 1. ... @@ -41,12 +41,34 @@ 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/MultiResetDetector_Generic/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/MultiResetDetector_Generic_GitHub/ +xy@xy-Inspiron-3593:~/Arduino/xy/MultiResetDetector_Generic_GitHub$ +``` + +2. Issue astyle command + +``` +xy@xy-Inspiron-3593:~/Arduino/xy/MultiResetDetector_Generic_GitHub$ bash utils/restyle.sh +``` + + + diff --git a/README.md b/README.md index 9b1250f..1bb011a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,16 @@ -## MultiResetDetector_Generic +## MultiResetDetector_Generic Library [![arduino-library-badge](https://www.ardu-badge.com/badge/MultiResetDetector_Generic.svg?)](https://www.ardu-badge.com/MultiResetDetector_Generic) [![GitHub release](https://img.shields.io/github/release/khoih-prog/MultiResetDetector_Generic.svg)](https://github.com/khoih-prog/MultiResetDetector_Generic/releases) -[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/MultiResetDetector_Generic/blob/master/LICENSE) +[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/MultiResetDetector_Generic/blob/main/LICENSE) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/MultiResetDetector_Generic.svg)](http://github.com/khoih-prog/MultiResetDetector_Generic/issues) + Donate to my libraries using BuyMeACoffee + + --- --- @@ -40,6 +43,10 @@ * [8.1. To use BOARD_NAME](#81-to-use-board_name) * [8.2. To avoid compile error relating to microsecondsToClockCycles](#82-to-avoid-compile-error-relating-to-microsecondstoclockcycles) * [9. For Portenta_H7 boards using Arduino IDE in Linux](#9-for-portenta_h7-boards-using-arduino-ide-in-linux) + * [10. For RTL8720DN boards using AmebaD core](#10-for-rtl8720dn-boards-using-amebad-core) + * [11. For SAMD21 and SAMD51 boards using ArduinoCore-fab-sam core](#11-For-SAMD21-and-SAMD51-boards-using-ArduinoCore-fab-sam-core) + * [12. For Seeeduino RP2040 boards](#12-For-Seeeduino-RP2040-boards) + * [13. For Seeeduino nRF52840 boards](#13-For-Seeeduino-nRF52840-boards) * [Purpose](#purpose) * [How It Works](#how-it-works) * [Examples](#examples) @@ -227,18 +234,18 @@ This [**MultiResetDetector_Generic** library](https://github.com/khoih-prog/Mult ## Prerequisites 1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest) - 2. [`Arduino Core for STM32 v2.2.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32 boards. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) - 3. [`Teensy core 1.56+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0, LC) boards + 2. [`Arduino Core for STM32 v2.3.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32 boards. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) + 3. [`Teensy core 1.57+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0, LC) boards 4. [`Arduino SAM DUE core 1.6.12+`](https://github.com/arduino/ArduinoCore-sam) for SAM DUE ARM Cortex-M3 boards 5. [`Arduino SAMD core 1.8.13+`](https://www.arduino.cc/en/Guide/ArduinoM0) for SAMD ARM Cortex-M0+ boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-samd.svg)](https://github.com/arduino/ArduinoCore-samd/releases/latest) - 6. [`Adafruit SAMD core 1.7.9+`](https://www.adafruit.com/) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). [![GitHub release](https://img.shields.io/github/release/adafruit/ArduinoCore-samd.svg)](https://github.com/adafruit/ArduinoCore-samd/releases/latest) - 7. [`Seeeduino SAMD core 1.8.2+`](https://github.com/Seeed-Studio/ArduinoCore-samd) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). [![Latest release](https://img.shields.io/github/release/Seeed-Studio/ArduinoCore-samd.svg)](https://github.com/Seeed-Studio/ArduinoCore-samd/releases/latest/) + 6. [`Adafruit SAMD core 1.7.11+`](https://www.adafruit.com/) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). [![GitHub release](https://img.shields.io/github/release/adafruit/ArduinoCore-samd.svg)](https://github.com/adafruit/ArduinoCore-samd/releases/latest) + 7. [`Seeeduino SAMD core 1.8.3+`](https://github.com/Seeed-Studio/ArduinoCore-samd) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). [![Latest release](https://img.shields.io/github/release/Seeed-Studio/ArduinoCore-samd.svg)](https://github.com/Seeed-Studio/ArduinoCore-samd/releases/latest/) 8. [`Adafruit nRF52 v1.3.0+`](https://www.adafruit.com) for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, **NINA_B302_ublox**, etc. [![GitHub release](https://img.shields.io/github/release/adafruit/Adafruit_nRF52_Arduino.svg)](https://github.com/adafruit/Adafruit_nRF52_Arduino/releases/latest) - 9. [`Earle Philhower's arduino-pico core v1.12.0+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) -10. [`Arduino mbed_rp2040 core 2.7.2+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) -11. [`Arduino mbed_nano core 2.7.2+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) MBED nRF52840-based boards such as **Nano_33_BLE, Nano_33_BLE_Sense**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) -12. [`ArduinoCore-mbed mbed_portenta core 2.7.2+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino **Portenta_H7**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) -13. [`Arduino AmebaD core 3.1.2+`](https://github.com/ambiot/ambd_arduino) for Realtek RTL8720DN, RTL8722DM and RTL8722CSM, etc. boards. [![GitHub release](https://img.shields.io/github/release/ambiot/ambd_arduino.svg)](https://github.com/ambiot/ambd_arduino/releases/latest) + 9. [`Earle Philhower's arduino-pico core v2.6.3+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) +10. [`Arduino mbed_rp2040 core 3.4.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) +11. [`Arduino mbed_nano core 3.4.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) MBED nRF52840-based boards such as **Nano_33_BLE, Nano_33_BLE_Sense**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) +12. [`ArduinoCore-mbed mbed_portenta core 3.4.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino **Portenta_H7**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) +13. [`Arduino AmebaD core 3.1.4+`](https://github.com/ambiot/ambd_arduino) for Realtek RTL8720DN, RTL8722DM and RTL8722CSM, etc. boards. [![GitHub release](https://img.shields.io/github/release/ambiot/ambd_arduino.svg)](https://github.com/ambiot/ambd_arduino/releases/latest) 14. [`FlashStorage_SAMD library v1.3.2+`](https://github.com/khoih-prog/FlashStorage_SAMD) for SAMD21 and SAMD51 boards (ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit Itsy-Bitsy M4, etc.). [![GitHub release](https://img.shields.io/github/release/khoih-prog/FlashStorage_SAMD.svg)](https://github.com/khoih-prog/FlashStorage_SAMD/releases/latest) 15. [`FlashStorage_STM32F1 library v1.1.0+`](https://github.com/khoih-prog/FlashStorage_STM32F1) for STM32F1/F3 boards. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/FlashStorage_STM32F1.svg?)](https://www.ardu-badge.com/FlashStorage_STM32F1) @@ -262,9 +269,9 @@ You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/ Another way to install is to: 1. Navigate to [MultiResetDetector_Generic](https://github.com/khoih-prog/MultiResetDetector_Generic) page. -2. Download the latest release `MultiResetDetector_Generic-master.zip`. -3. Extract the zip file to `MultiResetDetector_Generic-master` directory -4. Copy whole `MultiResetDetector_Generic-master` folder to Arduino libraries' directory such as `~/Arduino/libraries/`. +2. Download the latest release `MultiResetDetector_Generic-main.zip`. +3. Extract the zip file to `MultiResetDetector_Generic-main` directory +4. Copy whole `MultiResetDetector_Generic-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`. ### VS Code & PlatformIO: @@ -381,16 +388,16 @@ Whenever the above-mentioned compiler error issue is fixed with the new Arduino #### 5. For Adafruit SAMD boards - ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.9) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.9). + ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.11) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.11). -Supposing the Adafruit SAMD core version is 1.7.9. This file must be copied into the directory: +Supposing the Adafruit SAMD core version is 1.7.11. These files must be copied into the directory: -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/platform.txt` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/cores/arduino/Print.h` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/cores/arduino/Print.cpp` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.11/platform.txt` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.h` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.cpp` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz -This file must be copied into the directory: +These files must be copied into the directory: - `~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/platform.txt` - `~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/cores/arduino/Print.h` @@ -398,17 +405,17 @@ This file must be copied into the directory: #### 6. For Seeeduino SAMD boards - ***To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the whole [Seeeduino SAMD Packages_Patches](Packages_Patches/Seeeduino/hardware/samd/1.8.2) directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2). + ***To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the whole [Seeeduino SAMD Packages_Patches](Packages_Patches/Seeeduino/hardware/samd/1.8.3) directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3). -Supposing the Seeeduino SAMD core version is 1.8.2. This file must be copied into the directory: +Supposing the Seeeduino SAMD core version is 1.8.3. These files must be copied into the directory: -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/platform.txt` -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Arduino.h` -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Print.h` -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Print.cpp` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/platform.txt` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Arduino.h` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.h` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.cpp` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz -This file must be copied into the directory: +These files must be copied into the directory: - `~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/platform.txt` - `~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Arduino.h` @@ -419,18 +426,22 @@ This file must be copied into the directory: #### 7.1 For STM32 boards to use LAN8720 +For `Generic STM32F4 series` boards, such as `STM32F407VE`, using `LAN8720`, please use STM32 core `v2.2.0` as breaking core `v2.3.0` creates the compile error. + +--- + To use LAN8720 on some STM32 boards - **Nucleo-144 (F429ZI, NUCLEO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG)** - **Discovery (DISCO_F746NG)** - **STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)** -you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system) to overwrite the old files. +you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.3.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.3.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system) to overwrite the old files. -Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory: +Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory: @@ -441,12 +452,12 @@ these files must be copied into the corresponding directory: #### 7.2 For STM32 boards to use Serial1 -**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.2.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0). You have to modify the files corresponding to your boards, this is just an illustration how to do. +**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.3.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0). You have to modify the files corresponding to your boards, this is just an illustration how to do. -Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory: +Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory: @@ -489,12 +500,12 @@ With core after v1.5.0, this step is not necessary anymore thanks to the PR [Add #### 9. For Portenta_H7 boards using Arduino IDE in Linux - **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/2.7.2/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/2.7.2/portenta_post_install.sh). + **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh). Then run the following command using `sudo` ``` -$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.7.2 +$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1 $ chmod 755 portenta_post_install.sh $ sudo ./portenta_post_install.sh ``` @@ -507,9 +518,9 @@ This will create the file `/etc/udev/rules.d/49-portenta_h7.rules` as follows: SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666" ``` -Supposing the ArduinoCore-mbed core version is 2.7.2. Now only one file must be copied into the directory: +Supposing the ArduinoCore-mbed core version is 3.4.1. Now only one file must be copied into the directory: -- `~/.arduino15/packages/arduino/hardware/mbed_portenta/2.7.2/portenta_post_install.sh` +- `~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh` Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz @@ -517,16 +528,84 @@ This file must be copied into the directory: - `~/.arduino15/packages/arduino/hardware/mbed_portenta/x.yy.zz/portenta_post_install.sh` + +#### 10. For RTL8720DN boards using AmebaD core + + To avoid compile error relating to PROGMEM, you have to copy the file [Realtek AmebaD core pgmspace.h](Packages_Patches/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h) into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h). + +Supposing the Realtek AmebaD core version is 3.1.4. This file must be copied into the directory: + +- `~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h` + +Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz +This file must be copied into the directory: + +- `~/.arduino15/packages/realtek/hardware/AmebaD/x.yy.zz/cores/ambd/avr/pgmspace.h` + + +#### 11. For SAMD21 and SAMD51 boards using ArduinoCore-fab-sam core + + To avoid compile error relating to SAMD21/SAMD51, you have to copy the file [ArduinoCore-fab-sam core pgmspace.h](Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt) into `ArduinoCore-fab-sam` samd directory (~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt). + +Supposing the `ArduinoCore-fab-sam` samd core version is 1.9.0. This file must be copied into the directory: + +- `~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt` + +Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz +This file must be copied into the directory: + +- `~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/x.yy.zz/boards.txt` + + +#### 12. For Seeeduino RP2040 boards + + ***To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino RP2040 (XIAO RP2040, Wio RP2040 Mini) boards***, you have to copy the whole [Seeeduino RP2040 Packages_Patches](Packages_Patches/Seeeduino/hardware/rp2040/2.7.2) directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/rp2040/2.7.2). + +Supposing the Seeeduino RP2040 core version is 2.7.2. These files must be copied into the directory: + +- `~/.arduino15/packages/Seeeduino/hardware/rp2040/2.7.2/boards.txt` +- `~/.arduino15/packages/Seeeduino/hardware/rp2040/2.7.2/variants/Seeed_XIAO_RP2040/pins_arduino.h` + +Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz +These files must be copied into the directory: + +- `~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/boards.txt` +- `~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/variants/Seeed_XIAO_RP2040/pins_arduino.h` + + +--- + +#### 13. For Seeeduino nRF52840 boards + +**To be able to compile and run on Xiao nRF52840 boards**, you have to copy the whole [nRF52 1.0.0](Packages_Patches/Seeeduino/hardware/nrf52/1.0.0) directory into Seeeduino nRF52 directory (~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0). + +Supposing the Seeeduino nRF52 version is 1.0.0. These files must be copied into the directory: + +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/platform.txt`** +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Print.h`** +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Print.cpp`** +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Udp.h`** + +Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z +These files must be copied into the directory: + +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/platform.txt`** +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Print.h`** +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Print.cpp`** +- **`~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h`** + + + --- --- ### Purpose -Detects a multi reset so that an alternative start-up mode can be used. One example use is to allow re-configuration of a device's WiFi or Blynk Credentials or to count the number of resets within a pre-determined timed. +Detects a `multi-reset` so that an alternative start-up mode can be used. One example use is to allow re-configuration of a device's WiFi or Blynk Credentials or to count the number of resets within a pre-determined timed. ### How It Works - When the device starts up it checks the EEPROM, (Due)FlashStorage or LittleFS file `/mrd.dat` for a flag to see if it has been recently reset within the configurable timeout seconds + When the device starts up it checks the `EEPROM`, `(Due)FlashStorage` or `LittleFS` file `/mrd.dat` for a flag to see if it has been recently reset within the configurable timeout seconds --- @@ -570,7 +649,7 @@ This is terminal debug output when running [minimal](examples/minimal) on ***Ada #### 1.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -592,7 +671,7 @@ ClearFlag write = 0xfffe0001 #### 1.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -609,7 +688,7 @@ No Multi Reset Detected #### 1.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -626,7 +705,7 @@ No Multi Reset Detected #### 1.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -643,7 +722,7 @@ No Multi Reset Detected #### 1.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -660,7 +739,7 @@ No Multi Reset Detected #### 1.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -684,7 +763,7 @@ This is terminal debug output when running [minimal](examples/minimal) on ***Tee #### 2.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -702,7 +781,7 @@ No Multi Reset Detected #### 2.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -717,7 +796,7 @@ No Multi Reset Detected #### 2.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -732,7 +811,7 @@ No Multi Reset Detected #### 2.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -747,7 +826,7 @@ No Multi Reset Detected #### 2.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -762,7 +841,7 @@ No Multi Reset Detected #### 2.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -784,7 +863,7 @@ This is terminal debug output when running [minimal](examples/minimal) on ***SAM #### 3.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -799,7 +878,7 @@ ClearFlag write = 0xfffe0001 #### 3.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -812,7 +891,7 @@ No Multi Reset Detected #### 3.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -825,7 +904,7 @@ No Multi Reset Detected #### 3.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -838,7 +917,7 @@ No Multi Reset Detected #### 3.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -851,7 +930,7 @@ No Multi Reset Detected #### 3.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -871,7 +950,7 @@ This is terminal debug output when running [minimal](examples/minimal) on ***Ard #### 4.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -887,7 +966,7 @@ No Multi Reset Detected #### 4.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -900,7 +979,7 @@ No Multi Reset Detected #### 4.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -913,7 +992,7 @@ No Multi Reset Detected #### 4.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -926,7 +1005,7 @@ No Multi Reset Detected #### 4.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -939,7 +1018,7 @@ No Multi Reset Detected #### 4.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -959,7 +1038,7 @@ This is terminal debug output when running [minimal](examples/minimal) on **STM3 #### 5.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program on NUCLEO_F767ZI MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -977,7 +1056,7 @@ No Multi Reset Detected #### 5.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program on NUCLEO_F767ZI MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -992,7 +1071,7 @@ No Multi Reset Detected #### 5.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program on NUCLEO_F767ZI MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1007,7 +1086,7 @@ No Multi Reset Detected #### 5.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program on NUCLEO_F767ZI MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1022,7 +1101,7 @@ No Multi Reset Detected #### 5.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program on NUCLEO_F767ZI MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1037,7 +1116,7 @@ No Multi Reset Detected #### 5.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program on NUCLEO_F767ZI MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1059,7 +1138,7 @@ This is terminal debug output when running [minimal](examples/minimal) on **RASP #### 6.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program on RASPBERRY_PI_PICO MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1083,7 +1162,7 @@ No Multi Reset Detected #### 6.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program on RASPBERRY_PI_PICO MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1100,7 +1179,7 @@ No Multi Reset Detected #### 6.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1117,7 +1196,7 @@ No Multi Reset Detected #### 6.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program on RASPBERRY_PI_PICO MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1134,7 +1213,7 @@ No Multi Reset Detected #### 6.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program on RASPBERRY_PI_PICO MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1151,7 +1230,7 @@ No Multi Reset Detected #### 6.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program on RASPBERRY_PI_PICO MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1175,7 +1254,7 @@ This is terminal debug output when running [minimal](examples/minimal) on **Nano #### 7.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program on Nano RP2040 Connect MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1200,7 +1279,7 @@ No Multi Reset Detected #### 7.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program on Nano RP2040 Connect MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1219,7 +1298,7 @@ No Multi Reset Detected #### 7.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program on Nano RP2040 Connect MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1238,7 +1317,7 @@ No Multi Reset Detected #### 7.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program on Nano RP2040 Connect MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1257,7 +1336,7 @@ No Multi Reset Detected #### 7.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program on Nano RP2040 Connect MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1276,7 +1355,7 @@ No Multi Reset Detected #### 7.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program on Nano RP2040 Connect MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1302,7 +1381,7 @@ This is terminal debug output when running [minimal](examples/minimal) on **MBED #### 8.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program on RaspberryPi Pico MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1327,7 +1406,7 @@ No Multi Reset Detected #### 8.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program on RaspberryPi Pico MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1346,7 +1425,7 @@ No Multi Reset Detected #### 8.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program on RaspberryPi Pico MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1365,7 +1444,7 @@ No Multi Reset Detected #### 8.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program on RaspberryPi Pico MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1384,7 +1463,7 @@ No Multi Reset Detected #### 8.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program on RaspberryPi Pico MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1403,7 +1482,7 @@ No Multi Reset Detected #### 8.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program on RaspberryPi Pico MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1429,7 +1508,7 @@ This is terminal debug output when running [minimal](examples/minimal) on **MBED #### 9.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program on Nano 33 BLE MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1459,7 +1538,7 @@ ClearFlag write = 0xfffe0001 #### 9.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program on Nano 33 BLE MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1478,7 +1557,7 @@ No Multi Reset Detected #### 9.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program on Nano 33 BLE MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1502,7 +1581,7 @@ ClearFlag write = 0xfffe0001 #### 9.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program on Nano 33 BLE MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1521,7 +1600,7 @@ No Multi Reset Detected #### 9.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program on Nano 33 BLE MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1540,7 +1619,7 @@ No Multi Reset Detected #### 9.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program on Nano 33 BLE MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1568,7 +1647,7 @@ This is terminal debug output when running [minimal](examples/minimal) on **MBED #### 10.1 Data Corrupted => reset to 0 -``` +```cpp MultiResetDetector minimal Example Program on PORTENTA_H7_M7 MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1600,7 +1679,7 @@ ClearFlag write = 0xfffe0001 #### 10.2 Reset Detected => Reporting 1 -``` +```cpp MultiResetDetector minimal Example Program on PORTENTA_H7_M7 MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1621,7 +1700,7 @@ No Multi Reset Detected #### 10.3 Reset Detected => Reporting 2 -``` +```cpp MultiResetDetector minimal Example Program on PORTENTA_H7_M7 MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1642,7 +1721,7 @@ No Multi Reset Detected #### 10.4 Reset Detected => Reporting 3 -``` +```cpp MultiResetDetector minimal Example Program on PORTENTA_H7_M7 MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1663,7 +1742,7 @@ No Multi Reset Detected #### 10.5 Reset Detected => Reporting 4 -``` +```cpp MultiResetDetector minimal Example Program on PORTENTA_H7_M7 MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1684,7 +1763,7 @@ No Multi Reset Detected #### 10.6 Reset Detected => Reporting 5. Multi Reset Detected -``` +```cpp MultiResetDetector minimal Example Program on PORTENTA_H7_M7 MultiResetDetector_Generic v1.8.1 ----------------------------------- @@ -1818,10 +1897,13 @@ If you want to contribute to this project: ### License -- The library is licensed under [MIT](https://github.com/khoih-prog/MultiResetDetector_Generic/blob/master/LICENSE) +- The library is licensed under [MIT](https://github.com/khoih-prog/MultiResetDetector_Generic/blob/main/LICENSE) --- ### Copyright -Copyright 2020- Khoi Hoang +Copyright (c) 2020- Khoi Hoang + + + diff --git a/changelog.md b/changelog.md index 42f8b3d..4d8c079 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -## MultiResetDetector_Generic +## MultiResetDetector_Generic Library [![arduino-library-badge](https://www.ardu-badge.com/badge/MultiResetDetector_Generic.svg?)](https://www.ardu-badge.com/MultiResetDetector_Generic) [![GitHub release](https://img.shields.io/github/release/khoih-prog/MultiResetDetector_Generic.svg)](https://github.com/khoih-prog/MultiResetDetector_Generic/releases) @@ -6,6 +6,12 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/MultiResetDetector_Generic.svg)](http://github.com/khoih-prog/MultiResetDetector_Generic/issues) + +Donate to my libraries using BuyMeACoffee + + + + --- --- diff --git a/examples/checkWaitingMRD/checkWaitingMRD.ino b/examples/checkWaitingMRD/checkWaitingMRD.ino index bd6081d..721431d 100644 --- a/examples/checkWaitingMRD/checkWaitingMRD.ino +++ b/examples/checkWaitingMRD/checkWaitingMRD.ino @@ -48,7 +48,7 @@ To support ESP32, use ESP_DoubleResetDetector library from https://github.com/khoih-prog/ESP_DoubleResetDetector To support AVR, Teensy, SAM DUE, SAMD and STM32, etc., use this MultiResetDetector_Generic from //https://github.com/khoih-prog/MultiResetDetector_Generic *****************************************************************************************************************************/ - + // These definitions must be placed before #include to be used // Otherwise, default values (MRD_TIMES = 3, MRD_TIMEOUT = 10 seconds and MRD_ADDRESS = 0) will be used // Number of subsequent resets during MRD_TIMEOUT to activate @@ -67,7 +67,7 @@ // Number of subsequent resets during MRD_TIMEOUT to activate #define MRD_TIMES 3 -// Number of seconds after reset during which a +// Number of seconds after reset during which a // subsequent reset will be considered a multi reset. #define MRD_TIMEOUT 10 @@ -109,13 +109,13 @@ void check_status() { digitalWrite(LED_BUILTIN, LEDState); - LEDState = !LEDState; + LEDState = !LEDState; } else { digitalWrite(LED_BUILTIN, LED_OFF); } - + checkstatus_timeout = current_millis + MRD_CHECK_INTERVAL; } } @@ -123,30 +123,32 @@ void check_status() void setup() { pinMode(LED_BUILTIN, OUTPUT); - + Serial.begin(115200); + while (!Serial); delay(200); #if defined(BOARD_NAME) - Serial.print(F("\nStarting checkWaitingMRD on")); Serial.println(BOARD_NAME); + Serial.print(F("\nStarting checkWaitingMRD on")); + Serial.println(BOARD_NAME); #else Serial.print(F("\nStarting checkWaitingMRD")); -#endif +#endif Serial.println(MULTIRESETDETECTOR_GENERIC_VERSION); Serial.println("-----------------------------------"); - + mrd = new MultiResetDetector_Generic(MRD_TIMEOUT, MRD_ADDRESS); - if (mrd->detectMultiReset()) + if (mrd->detectMultiReset()) { Serial.println("Multi Reset Detected"); digitalWrite(LED_BUILTIN, LED_ON); MRD_Detected = true; - } - else + } + else { Serial.println("No Multi Reset Detected"); digitalWrite(LED_BUILTIN, LED_OFF); diff --git a/examples/minimal/minimal.ino b/examples/minimal/minimal.ino index 8692297..00bd55c 100644 --- a/examples/minimal/minimal.ino +++ b/examples/minimal/minimal.ino @@ -55,7 +55,7 @@ // Number of subsequent resets during MRD_TIMEOUT to activate #define MRD_TIMES 5 -// Number of seconds after reset during which a +// Number of seconds after reset during which a // subsequent reset will be considered a multi reset. #define MRD_TIMEOUT 10 @@ -75,12 +75,14 @@ void setup() pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); + while (!Serial); Serial.println(); #if defined(BOARD_NAME) - Serial.print(F("MultiResetDetector minimal Example Program on ")); Serial.println(BOARD_NAME); + Serial.print(F("MultiResetDetector minimal Example Program on ")); + Serial.println(BOARD_NAME); #else Serial.println(F("MultiResetDetector minimal Example Program")); #endif @@ -90,12 +92,12 @@ void setup() mrd = new MultiResetDetector_Generic(MRD_TIMEOUT, MRD_ADDRESS); - if (mrd->detectMultiReset()) + if (mrd->detectMultiReset()) { Serial.println(F("Multi Reset Detected")); digitalWrite(LED_BUILTIN, LOW); - } - else + } + else { Serial.println(F("No Multi Reset Detected")); digitalWrite(LED_BUILTIN, HIGH); diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 2c275e1..a4a8c6e 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -37,6 +37,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 = ; PlatformIO 4.x diff --git a/src/MultiResetDetector_Generic.h b/src/MultiResetDetector_Generic.h index 3eaf24d..59e58ec 100644 --- a/src/MultiResetDetector_Generic.h +++ b/src/MultiResetDetector_Generic.h @@ -12,7 +12,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/MultiResetDetector_Generic Licensed under MIT license - + Version: 1.8.1 Version Modified By Date Comments @@ -48,7 +48,7 @@ #define MULTIRESETDETECTOR_GENERIC_VERSION_MINOR 8 #define MULTIRESETDETECTOR_GENERIC_VERSION_PATCH 1 -#define MULTIRESETDETECTOR_GENERIC_VERSION_INT 1008001 + #define MULTIRESETDETECTOR_GENERIC_VERSION_INT 1008001 #endif @@ -70,7 +70,7 @@ #define MRD_GENERIC_USE_EEPROM true -///////////////////////////// +///////////////////////////// #define MRD_GENERIC_USE_SAM_DUE false #define MRD_GENERIC_USE_SAMD false @@ -84,20 +84,20 @@ ///////////////////////////// #if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) - #if defined(MRD_GENERIC_USE_SAM_DUE) - #undef MRD_GENERIC_USE_SAM_DUE - #endif - #define MRD_GENERIC_USE_SAM_DUE true - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM - #endif - #define MRD_GENERIC_USE_EEPROM false - - #if (MRD_GENERIC_DEBUG) - #warning Use SAM-DUE and DueFlashStorage - #endif - -///////////////////////////// +#if defined(MRD_GENERIC_USE_SAM_DUE) + #undef MRD_GENERIC_USE_SAM_DUE +#endif +#define MRD_GENERIC_USE_SAM_DUE true +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use SAM-DUE and DueFlashStorage +#endif + +///////////////////////////// #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) || defined(ARDUINO_SAMD_MKRVIDOR4000) \ @@ -106,242 +106,242 @@ || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) - #if defined(MRD_GENERIC_USE_SAMD) - #undef MRD_GENERIC_USE_SAMD - #endif - #define MRD_GENERIC_USE_SAMD true - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM - #endif - #define MRD_GENERIC_USE_EEPROM false - - #if (MRD_GENERIC_DEBUG) - #warning Use SAMD and FlashStorage - #endif -///////////////////////////// +#if defined(MRD_GENERIC_USE_SAMD) + #undef MRD_GENERIC_USE_SAMD +#endif +#define MRD_GENERIC_USE_SAMD true +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use SAMD and FlashStorage +#endif +///////////////////////////// #elif ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) | defined(NINA_B302_ublox) ) && \ ! ( defined(ARDUINO_ARCH_MBED) ) - #if defined(MRD_GENERIC_USE_NRF52) - #undef MRD_GENERIC_USE_NRF52 - #endif - #define MRD_GENERIC_USE_NRF52 true - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM - #endif - #define MRD_GENERIC_USE_EEPROM false - - #if (MRD_GENERIC_DEBUG) - #warning Use NRF52 and LittleFS / InternalFS - #endif +#if defined(MRD_GENERIC_USE_NRF52) + #undef MRD_GENERIC_USE_NRF52 +#endif +#define MRD_GENERIC_USE_NRF52 true +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use NRF52 and LittleFS / InternalFS +#endif ///////////////////////////// #elif ( defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) ) - #if defined(MRD_GENERIC_USE_RP2040) - #undef MRD_GENERIC_USE_RP2040 - #endif - #define MRD_GENERIC_USE_RP2040 true - - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM - #endif - #define MRD_GENERIC_USE_EEPROM false - - #if (MRD_GENERIC_DEBUG) - #warning Use RP2040 (such as RASPBERRY_PI_PICO) and LittleFS - #endif +#if defined(MRD_GENERIC_USE_RP2040) + #undef MRD_GENERIC_USE_RP2040 +#endif +#define MRD_GENERIC_USE_RP2040 true + +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use RP2040 (such as RASPBERRY_PI_PICO) and LittleFS +#endif ///////////////////////////// #elif ( defined(ARDUINO_ARCH_RP2040) && defined(ARDUINO_ARCH_MBED) ) - // For Arduino' arduino-mbed core - // To check and determine if we need to init LittleFS here - #if MBED_RP2040_INITIALIZED - #define MRD_MBED_LITTLEFS_NEED_INIT false - - #if (MRD_GENERIC_DEBUG) - #warning MBED_RP2040_INITIALIZED in another place - #endif +// For Arduino' arduino-mbed core +// To check and determine if we need to init LittleFS here +#if MBED_RP2040_INITIALIZED + #define MRD_MBED_LITTLEFS_NEED_INIT false - #else - // Better to delay until init done - #if defined(MBED_RP2040_INITIALIZED) - #undef MBED_RP2040_INITIALIZED - #endif - #define MBED_RP2040_INITIALIZED true - - #define MRD_MBED_LITTLEFS_NEED_INIT true - #endif - - #if defined(MRD_GENERIC_USE_MBED_RP2040) - #undef MRD_GENERIC_USE_MBED_RP2040 - #endif - #define MRD_GENERIC_USE_MBED_RP2040 true - - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM - #endif - #define MRD_GENERIC_USE_EEPROM false - #if (MRD_GENERIC_DEBUG) - #warning Use MBED RP2040 (such as NANO_RP2040_CONNECT, RASPBERRY_PI_PICO) and LittleFS + #warning MBED_RP2040_INITIALIZED in another place #endif -///////////////////////////// -#elif ( ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) && defined(ARDUINO_ARCH_MBED) ) - - #if defined(BOARD_NAME) - #undef BOARD_NAME +#else + // Better to delay until init done + #if defined(MBED_RP2040_INITIALIZED) + #undef MBED_RP2040_INITIALIZED #endif + #define MBED_RP2040_INITIALIZED true - #if defined(CORE_CM7) - #if (MRD_GENERIC_DEBUG) - #warning Using Portenta H7 M7 core - #endif + #define MRD_MBED_LITTLEFS_NEED_INIT true +#endif - #define BOARD_NAME "PORTENTA_H7_M7" - #else - #if (MRD_GENERIC_DEBUG) - #warning Using Portenta H7 M4 core - #endif +#if defined(MRD_GENERIC_USE_MBED_RP2040) + #undef MRD_GENERIC_USE_MBED_RP2040 +#endif +#define MRD_GENERIC_USE_MBED_RP2040 true - #define BOARD_NAME "PORTENTA_H7_M4" - #endif - - // For Arduino' arduino-mbed core - // To check and determine if we need to init LittleFS here - #if MBED_PORTENTA_H7_INITIALIZED - #define MRD_MBED_LITTLEFS_NEED_INIT false - - #if (MRD_GENERIC_DEBUG) - #warning MBED_PORTENTA_H7_INITIALIZED in another place - #endif +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false - #else - // Better to delay until init done - #if defined(MBED_PORTENTA_H7_INITIALIZED) - #undef MBED_PORTENTA_H7_INITIALIZED - #endif - #define MBED_PORTENTA_H7_INITIALIZED true - - #define MRD_PORTENTA_LITTLEFS_NEED_INIT true - #endif - - #if defined(MRD_GENERIC_USE_MBED_PORTENTA) - #undef MRD_GENERIC_USE_MBED_PORTENTA - #endif - #define MRD_GENERIC_USE_MBED_PORTENTA true - - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM +#if (MRD_GENERIC_DEBUG) + #warning Use MBED RP2040 (such as NANO_RP2040_CONNECT, RASPBERRY_PI_PICO) and LittleFS +#endif + +///////////////////////////// +#elif ( ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) && defined(ARDUINO_ARCH_MBED) ) + +#if defined(BOARD_NAME) + #undef BOARD_NAME +#endif + +#if defined(CORE_CM7) + #if (MRD_GENERIC_DEBUG) + #warning Using Portenta H7 M7 core #endif - #define MRD_GENERIC_USE_EEPROM false - + + #define BOARD_NAME "PORTENTA_H7_M7" +#else #if (MRD_GENERIC_DEBUG) - #warning Use MBED PORTENTA_H7 and LittleFS + #warning Using Portenta H7 M4 core #endif - -///////////////////////////// -#elif ( defined(ARDUINO_ARCH_NRF52840) && defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARDUINO_NANO33BLE) ) - // For Arduino' arduino-mbed core - // To check and determine if we need to init LittleFS here - #if NANO33BLE_INITIALIZED - #define MRD_NANO33BLE_NEED_INIT false - - #if (MRD_GENERIC_DEBUG) - #warning NANO33BLE_INITIALIZED in another place - #endif + #define BOARD_NAME "PORTENTA_H7_M4" +#endif - #else - // Better to delay until init done - #if defined(NANO33BLE_INITIALIZED) - #undef NANO33BLE_INITIALIZED - #endif - #define NANO33BLE_INITIALIZED true - - #define MRD_NANO33BLE_NEED_INIT true - #endif - - #if defined(MRD_GENERIC_USE_NANO33BLE) - #undef MRD_GENERIC_USE_NANO33BLE +// For Arduino' arduino-mbed core +// To check and determine if we need to init LittleFS here +#if MBED_PORTENTA_H7_INITIALIZED + #define MRD_MBED_LITTLEFS_NEED_INIT false + + #if (MRD_GENERIC_DEBUG) + #warning MBED_PORTENTA_H7_INITIALIZED in another place #endif - #define MRD_GENERIC_USE_NANO33BLE true - - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM + +#else + // Better to delay until init done + #if defined(MBED_PORTENTA_H7_INITIALIZED) + #undef MBED_PORTENTA_H7_INITIALIZED #endif - #define MRD_GENERIC_USE_EEPROM false - + #define MBED_PORTENTA_H7_INITIALIZED true + + #define MRD_PORTENTA_LITTLEFS_NEED_INIT true +#endif + +#if defined(MRD_GENERIC_USE_MBED_PORTENTA) + #undef MRD_GENERIC_USE_MBED_PORTENTA +#endif +#define MRD_GENERIC_USE_MBED_PORTENTA true + +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use MBED PORTENTA_H7 and LittleFS +#endif + +///////////////////////////// +#elif ( defined(ARDUINO_ARCH_NRF52840) && defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARDUINO_NANO33BLE) ) + +// For Arduino' arduino-mbed core +// To check and determine if we need to init LittleFS here +#if NANO33BLE_INITIALIZED + #define MRD_NANO33BLE_NEED_INIT false + #if (MRD_GENERIC_DEBUG) - #warning Use MBED nRF52840 (such as Nano_33_BLE, Nano_33_BLE_Sense) and LittleFS + #warning NANO33BLE_INITIALIZED in another place + #endif + +#else + // Better to delay until init done + #if defined(NANO33BLE_INITIALIZED) + #undef NANO33BLE_INITIALIZED #endif - + #define NANO33BLE_INITIALIZED true + + #define MRD_NANO33BLE_NEED_INIT true +#endif + +#if defined(MRD_GENERIC_USE_NANO33BLE) + #undef MRD_GENERIC_USE_NANO33BLE +#endif +#define MRD_GENERIC_USE_NANO33BLE true + +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use MBED nRF52840 (such as Nano_33_BLE, Nano_33_BLE_Sense) and LittleFS +#endif + ///////////////////////////// #elif defined(CONFIG_PLATFORM_8721D) - #if defined(MRD_GENERIC_USE_RTL8720) - #undef MRD_GENERIC_USE_RTL8720 - #endif - #define MRD_GENERIC_USE_RTL8720 true - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM - #endif - #define MRD_GENERIC_USE_EEPROM false - - #if (MRD_GENERIC_DEBUG) - #warning Use RTL8720 and FlashStorage_RTL8720 - #endif - -///////////////////////////// +#if defined(MRD_GENERIC_USE_RTL8720) + #undef MRD_GENERIC_USE_RTL8720 +#endif +#define MRD_GENERIC_USE_RTL8720 true +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use RTL8720 and FlashStorage_RTL8720 +#endif + +///////////////////////////// #elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ defined(STM32WB) || defined(STM32MP1) || defined(STM32L5) ) - #if defined(MRD_GENERIC_USE_STM32) - #undef MRD_GENERIC_USE_STM32 - #endif - #define MRD_GENERIC_USE_STM32 true - #if defined(MRD_GENERIC_USE_EEPROM) - #undef MRD_GENERIC_USE_EEPROM - #endif - #define MRD_GENERIC_USE_EEPROM false - - #if (MRD_GENERIC_DEBUG) - #warning Use STM32 and FlashStorage_STM32 - #endif +#if defined(MRD_GENERIC_USE_STM32) + #undef MRD_GENERIC_USE_STM32 +#endif +#define MRD_GENERIC_USE_STM32 true +#if defined(MRD_GENERIC_USE_EEPROM) + #undef MRD_GENERIC_USE_EEPROM +#endif +#define MRD_GENERIC_USE_EEPROM false + +#if (MRD_GENERIC_DEBUG) + #warning Use STM32 and FlashStorage_STM32 +#endif -///////////////////////////// +///////////////////////////// #else - #if defined(CORE_TEENSY) - #if (MRD_GENERIC_DEBUG) - #warning Use TEENSY and EEPROM - #endif +#if defined(CORE_TEENSY) +#if (MRD_GENERIC_DEBUG) + #warning Use TEENSY and EEPROM +#endif - #elif ( defined(ARDUINO_AVR_ADK) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_DUEMILANOVE) || defined(ARDUINO_AVR_ESPLORA) \ +#elif ( defined(ARDUINO_AVR_ADK) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_DUEMILANOVE) || defined(ARDUINO_AVR_ESPLORA) \ || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_LEONARDO) \ || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) \ || defined(ARDUINO_AVR_MICRO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_NG) \ || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || defined(ARDUINO_AVR_UNO) \ || defined(ARDUINO_AVR_YUN) ) - - #if (MRD_GENERIC_DEBUG) - #warning Use AVR and EEPROM - #endif - #else - - #if (MRD_GENERIC_DEBUG) - #warning Use Unknown board and EEPROM - #endif +#if (MRD_GENERIC_DEBUG) + #warning Use AVR and EEPROM +#endif + +#else + +#if (MRD_GENERIC_DEBUG) + #warning Use Unknown board and EEPROM +#endif - #endif +#endif #endif ///////////////////////////// - + //default to use EEPROM, otherwise, use DueFlashStorage or FlashStorage_SAMD ///////////////////////////// #if MRD_GENERIC_USE_EEPROM @@ -354,27 +354,27 @@ #define MRD_EEPROM_SIZE (E2END + 1) #endif -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_SAMD // Include EEPROM-like API for FlashStorage #include //https://github.com/khoih-prog/FlashStorage_SAMD -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_SAM_DUE //Use DueFlashStorage to simulate EEPROM #include //https://github.com/sebnil/DueFlashStorage DueFlashStorage dueFlashStorage; -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_NRF52 // Include LittleFS similar to SPIFFS #include #include using namespace Adafruit_LittleFS_Namespace; - + File MRD_file(InternalFS); -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_RP2040 //Use LittleFS for RPI Pico @@ -383,8 +383,8 @@ FS* filesystem = &LittleFS; #define FileFS LittleFS - -///////////////////////////// + + ///////////////////////////// #elif (MRD_GENERIC_USE_MBED_RP2040 && MRD_MBED_LITTLEFS_NEED_INIT) //Use LittleFS for MBED RPI Pico @@ -424,17 +424,17 @@ FlashIAPBlockDevice bd(XIP_BASE + RP2040_FS_START, (RP2040_FS_SIZE_KB * 1024)); mbed::LittleFileSystem fs("fs"); - + #if defined(MRD_FILENAME) #undef MRD_FILENAME #endif - #define MRD_FILENAME "/fs/mrd.dat" - + #define MRD_FILENAME "/fs/mrd.dat" + #if (MRD_GENERIC_DEBUG) #warning MRD_MBED_LITTLEFS INITIALIZED locally in MultiResetDetector_Generic #endif -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_MBED_PORTENTA && MRD_PORTENTA_LITTLEFS_NEED_INIT) //Use LittleFS for MBED Portenta @@ -447,7 +447,7 @@ #include #include "BlockDevice.h" - + #include "mbed_portenta/FlashIAPLimits.h" #if !defined(FORCE_REFORMAT) @@ -459,19 +459,19 @@ static FlashIAPBlockDevice* blockDevicePtr; mbed::LittleFileSystem fs("littlefs"); - + struct FlashIAPLimits _flashIAPLimits; - + #if defined(MRD_FILENAME) #undef MRD_FILENAME #endif #define MRD_FILENAME "/littlefs/mrd.dat" - + #if (MRD_GENERIC_DEBUG) #warning MRD_PORTENTA_LITTLEFS INITIALIZED locally in MultiResetDetector_Generic #endif - -///////////////////////////// + + ///////////////////////////// #elif (MRD_GENERIC_USE_NANO33BLE && MRD_NANO33BLE_NEED_INIT) //Use LittleFS for MBED Nano33BLE @@ -516,65 +516,65 @@ FlashIAPBlockDevice wholeBD(FLASH_BASE, 0x80000); FlashIAPBlockDevice bd(FLASH_BASE, (NANO33BLE_FS_SIZE_KB * 1024)); - + mbed::LittleFileSystem fs("littlefs"); - + #if defined(MRD_FILENAME) #undef MRD_FILENAME #endif #define MRD_FILENAME "/littlefs/mrd.dat" - + #if (MRD_GENERIC_DEBUG) #warning MRD_NANO33BLE_LITTLEFS INITIALIZED locally in MultiResetDetector_Generic #endif - -///////////////////////////// + + ///////////////////////////// #elif MRD_GENERIC_USE_STM32 -///////////////////////////////////////////// - + ///////////////////////////////////////////// + #if defined(DATA_EEPROM_BASE) - // For STM32 devices having integrated EEPROM. - #include - + // For STM32 devices having integrated EEPROM. + #include + + #if (MRD_GENERIC_DEBUG) + #warning STM32 devices have integrated EEPROM. Not using buffered API. + #endif + + #else + /** + Most STM32 devices don't have an integrated EEPROM. To emulate a EEPROM, the STM32 Arduino core emulated + the operation of an EEPROM with the help of the embedded flash. + Writing to a flash is very expensive operation, since a whole flash page needs to be written, even if you only + want to access the flash byte-wise. + The STM32 Arduino core provides a buffered access API to the emulated EEPROM. The library has allocated the + buffer even if you don't use the buffered API, so it's strongly suggested to use the buffered API anyhow. + */ + #if ( defined(STM32F1xx) || defined(STM32F3xx) ) + #include // https://github.com/khoih-prog/FlashStorage_STM32 + #if (MRD_GENERIC_DEBUG) - #warning STM32 devices have integrated EEPROM. Not using buffered API. + #warning STM32F1/F3 devices have no integrated EEPROM. Using buffered API with FlashStorage_STM32F1 library #endif - - #else - /** - Most STM32 devices don't have an integrated EEPROM. To emulate a EEPROM, the STM32 Arduino core emulated - the operation of an EEPROM with the help of the embedded flash. - Writing to a flash is very expensive operation, since a whole flash page needs to be written, even if you only - want to access the flash byte-wise. - The STM32 Arduino core provides a buffered access API to the emulated EEPROM. The library has allocated the - buffer even if you don't use the buffered API, so it's strongly suggested to use the buffered API anyhow. - */ - #if ( defined(STM32F1xx) || defined(STM32F3xx) ) - #include // https://github.com/khoih-prog/FlashStorage_STM32 - - #if (MRD_GENERIC_DEBUG) - #warning STM32F1/F3 devices have no integrated EEPROM. Using buffered API with FlashStorage_STM32F1 library - #endif - - #else - #include // https://github.com/khoih-prog/FlashStorage_STM32 - - #if (MRD_GENERIC_DEBUG) - #warning STM32 devices have no integrated EEPROM. Using buffered API with FlashStorage_STM32 library - #endif + #else + #include // https://github.com/khoih-prog/FlashStorage_STM32 + + #if (MRD_GENERIC_DEBUG) + #warning STM32 devices have no integrated EEPROM. Using buffered API with FlashStorage_STM32 library #endif + + #endif #endif // #if defined(DATA_EEPROM_BASE) ////////////////////////////////////////////// - + #elif MRD_GENERIC_USE_RTL8720 // Include FlashStorage API for FlashStorage_RTL8720 #include //https://github.com/khoih-prog/FlashStorage_RTL8720 -///////////////////////////// - + ///////////////////////////// + #endif //#if MRD_GENERIC_USE_EEPROM /////////////////// @@ -596,7 +596,7 @@ // Flag clear to 0xFFFE0001 if no MRD within MRD_TIMEOUT. Flag will increase 1 for each reset within MRD_TIMEOUT // So MULTIRESETDETECTOR_FLAG_SET is not necessary. -// Will use upper 2 bytes to verify if corrupted data. +// Will use upper 2 bytes to verify if corrupted data. #define USING_INVERTED true @@ -613,71 +613,73 @@ class MultiResetDetector_Generic { public: - + ///////////////////////////////////////////// - + MultiResetDetector_Generic(unsigned long timeout, int address) { mrd_times = MRD_TIMES; - + this->timeout = timeout * 1000; this->MRD_EEPROM_START = address; multiResetDetected = false; waitingForMultiReset = false; -///////////////////////////// + ///////////////////////////// #if MRD_GENERIC_USE_EEPROM EEPROM.begin(); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print(F("\nEEPROM size = ")); Serial.print(MRD_EEPROM_SIZE); Serial.print(F(", start = ")); Serial.println(MRD_EEPROM_START); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_STM32) - #if defined(DATA_EEPROM_BASE) +#if defined(DATA_EEPROM_BASE) EEPROM.begin(); - #endif - - #if (MRD_GENERIC_DEBUG) +#endif + +#if (MRD_GENERIC_DEBUG) Serial.print("\n(Emulated-)EEPROM size = "); Serial.print(EEPROM.length()); Serial.print(", start = "); Serial.println(MRD_EEPROM_START); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_SAMD // Do something to init FlashStorage - -///////////////////////////// + + ///////////////////////////// #elif MRD_GENERIC_USE_SAM_DUE // Do something to init DueFlashStorage -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_NRF52 // Do something to init LittleFS / InternalFS // Initialize Internal File System InternalFS.begin(); - -///////////////////////////// + + ///////////////////////////// #elif MRD_GENERIC_USE_RP2040 bool beginOK = FileFS.begin(); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) + if (!beginOK) { Serial.println("\nLittleFS error"); } - #endif - -///////////////////////////// + +#endif + + ///////////////////////////// #elif (MRD_GENERIC_USE_MBED_RP2040 && MRD_MBED_LITTLEFS_NEED_INIT) Serial.print("LittleFS size (KB) = "); @@ -686,130 +688,139 @@ class MultiResetDetector_Generic #if FORCE_REFORMAT fs.reformat(&bd); #endif - + int err = fs.mount(&bd); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.println(err ? "LittleFS Mount Fail" : "LittleFS Mount OK"); - #endif - +#endif + if (err) { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) // Reformat if we can't mount the filesystem Serial.println("Formatting... "); Serial.flush(); - #endif - +#endif + err = fs.reformat(&bd); } - + bool beginOK = (err == 0); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) + if (!beginOK) { Serial.println("\nLittleFS error"); } - #endif +#endif -///////////////////////////// + + ///////////////////////////// #elif (MRD_GENERIC_USE_MBED_PORTENTA && MRD_PORTENTA_LITTLEFS_NEED_INIT) // Get limits of the the internal flash of the microcontroller _flashIAPLimits = getFlashIAPLimits(); - - Serial.print("Flash Size: (KB) = "); Serial.println(_flashIAPLimits.flash_size / 1024.0); - Serial.print("FlashIAP Start Address: = 0x"); Serial.println(_flashIAPLimits.start_address, HEX); - Serial.print("LittleFS size (KB) = "); Serial.println(_flashIAPLimits.available_size / 1024.0); - + + Serial.print("Flash Size: (KB) = "); + Serial.println(_flashIAPLimits.flash_size / 1024.0); + Serial.print("FlashIAP Start Address: = 0x"); + Serial.println(_flashIAPLimits.start_address, HEX); + Serial.print("LittleFS size (KB) = "); + Serial.println(_flashIAPLimits.available_size / 1024.0); + blockDevicePtr = new FlashIAPBlockDevice(_flashIAPLimits.start_address, _flashIAPLimits.available_size); - + if (!blockDevicePtr) { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Error init FlashIAPBlockDevice"); - #endif +#endif return; } - - #if FORCE_REFORMAT + +#if FORCE_REFORMAT fs.reformat(blockDevicePtr); - #endif +#endif int err = fs.mount(blockDevicePtr); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.println(err ? "LittleFS Mount Fail" : "LittleFS Mount OK"); - #endif - +#endif + if (err) { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) // Reformat if we can't mount the filesystem Serial.println("Formatting... "); - #endif - +#endif + err = fs.reformat(blockDevicePtr); } - + bool beginOK = (err == 0); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) + if (!beginOK) { Serial.println("\nLittleFS error"); } - #endif - -///////////////////////////// +#endif + + + ///////////////////////////// #elif (MRD_GENERIC_USE_NANO33BLE && MRD_NANO33BLE_NEED_INIT) Serial.print("LittleFS size (KB) = "); Serial.println(NANO33BLE_FS_SIZE_KB); - + #if FORCE_REFORMAT mbed::LittleFileSystem::format(&bd); -#endif - +#endif + int err = fs.mount(&bd); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.println(err ? "LittleFS Mount Fail" : "LittleFS Mount OK"); - #endif - +#endif + if (err) { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) // Reformat if we can't mount the filesystem Serial.println("Formatting... "); - #endif - +#endif + err = mbed::LittleFileSystem::format(&bd); } - + bool beginOK = (err == 0); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) + if (!beginOK) { Serial.println("\nLittleFS error"); } - #endif - -///////////////////////////// +#endif + + + ///////////////////////////// #elif MRD_GENERIC_USE_RTL8720 // Do something to init FlashStorage_RTL8720 - -///////////////////////////// + + ///////////////////////////// #else - #error Un-identifiable board selected. Please check your Tools->Board setting. +#error Un-identifiable board selected. Please check your Tools->Board setting. #endif }; - + ///////////////////////////////////////////// bool detectMultiReset() @@ -839,14 +850,14 @@ class MultiResetDetector_Generic return multiResetDetected; }; - + ///////////////////////////////////////////// - + bool waitingForMRD() { return waitingForMultiReset; } - + ///////////////////////////////////////////// void loop() @@ -860,7 +871,7 @@ class MultiResetDetector_Generic stop(); } }; - + ///////////////////////////////////////////// void stop() @@ -868,122 +879,122 @@ class MultiResetDetector_Generic clearRecentlyResetFlag(); waitingForMultiReset = false; }; - + ///////////////////////////////////////////// bool multiResetDetected; - + ///////////////////////////////////////////// private: uint32_t MULTIRESETDETECTOR_FLAG; - + unsigned long mrd_times; - + unsigned long timeout; int MRD_EEPROM_START; bool waitingForMultiReset; - + uint32_t multiResetDetectorFlag; ///////////////////////////////////////////////////////////////////// - -#if (MRD_GENERIC_USE_SAMD) + +#if (MRD_GENERIC_USE_SAMD) ///////////////////////////////////////////// - + uint32_t readFlagSAMD(void) - { - uint16_t offset = MRD_EEPROM_START; + { + uint16_t offset = MRD_EEPROM_START; uint8_t* _pointer = (uint8_t *) &MULTIRESETDETECTOR_FLAG; - + for (unsigned int i = 0; i < sizeof(MULTIRESETDETECTOR_FLAG); i++, _pointer++, offset++) - { + { *_pointer = EEPROM.read(offset); } - + return MULTIRESETDETECTOR_FLAG; } - + ///////////////////////////////////////////// - + #elif (MRD_GENERIC_USE_SAM_DUE) ///////////////////////////////////////////// - + uint32_t readFlagSAM_DUE(void) - { + { byte* dataPointer = (byte* ) dueFlashStorage.readAddress(MRD_EEPROM_START); - - memcpy(&MULTIRESETDETECTOR_FLAG, dataPointer, sizeof(MULTIRESETDETECTOR_FLAG)); - + + memcpy(&MULTIRESETDETECTOR_FLAG, dataPointer, sizeof(MULTIRESETDETECTOR_FLAG)); + return MULTIRESETDETECTOR_FLAG; } - + ///////////////////////////////////////////// - + #elif MRD_GENERIC_USE_NRF52 ///////////////////////////////////////////// uint32_t readFlagNRF52(void) - { + { MRD_file.open(MRD_FILENAME, FILE_O_READ); - + if (MRD_file) { MRD_file.seek(MRD_FLAG_OFFSET); MRD_file.read((char *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.print(F("LittleFS Flag read = 0x")); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif - MRD_file.close(); + MRD_file.close(); } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println(F("Loading MRD file failed")); - #endif +#endif } - + return MULTIRESETDETECTOR_FLAG; } - + ///////////////////////////////////////////// - + #elif MRD_GENERIC_USE_RP2040 ///////////////////////////////////////////// uint32_t readFlagRP2040() - { + { File file = FileFS.open(MRD_FILENAME, "r"); - + if (file) { file.seek(MRD_FLAG_OFFSET); file.read((uint8_t *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("LittleFS Flag read = 0x" + String(MULTIRESETDETECTOR_FLAG, HEX) ); - #endif +#endif - file.close(); + file.close(); } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Loading MRD file failed"); - #endif +#endif } - + return MULTIRESETDETECTOR_FLAG; } - + ///////////////////////////////////////////// #elif MRD_GENERIC_USE_MBED_RP2040 @@ -991,63 +1002,63 @@ class MultiResetDetector_Generic ///////////////////////////////////////////// uint32_t readFlagMbedRP2040() - { + { FILE *file = fopen(MRD_FILENAME, "r"); - + if (file) { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fread((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("LittleFS Flag read = 0x" + String(MULTIRESETDETECTOR_FLAG, HEX) ); - #endif +#endif fclose(file); } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Loading MRD file failed"); - #endif +#endif } - + return MULTIRESETDETECTOR_FLAG; } ///////////////////////////////////////////// - + #elif (MRD_GENERIC_USE_MBED_PORTENTA) ///////////////////////////////////////////// - + uint32_t readFlagMbedPortenta() - { + { FILE *file = fopen(MRD_FILENAME, "r"); - + if (file) { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fread((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("LittleFS Flag read = 0x" + String(MULTIRESETDETECTOR_FLAG, HEX) ); - #endif +#endif fclose(file); } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Loading MRD file failed"); - #endif +#endif } - + return MULTIRESETDETECTOR_FLAG; - } - - + } + + ///////////////////////////////////////////// #elif MRD_GENERIC_USE_NANO33BLE @@ -1055,30 +1066,30 @@ class MultiResetDetector_Generic ///////////////////////////////////////////// uint32_t readFlagNano33BLE() - { + { FILE *file = fopen(MRD_FILENAME, "r"); - + if (file) { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fread((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("LittleFS Flag read = 0x" + String(MULTIRESETDETECTOR_FLAG, HEX) ); - #endif +#endif fclose(file); } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Loading MRD file failed"); - #endif +#endif } - + return MULTIRESETDETECTOR_FLAG; - } - + } + ///////////////////////////////////////////// #elif (MRD_GENERIC_USE_RTL8720) @@ -1086,96 +1097,96 @@ class MultiResetDetector_Generic ///////////////////////////////////////////// uint32_t readFlagRTL8720() - { + { // Using name MRD_EEPROM_START, but actually FlashStorage not EEPROM FlashStorage.get(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); - + return MULTIRESETDETECTOR_FLAG; } - + ///////////////////////////////////////////// #endif ///////////////////////////////////////////// - + bool readRecentlyResetFlag() { - -///////////////////////////// + + ///////////////////////////// #if (MRD_GENERIC_USE_EEPROM || MRD_GENERIC_USE_STM32) EEPROM.get(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); multiResetDetectorFlag = MULTIRESETDETECTOR_FLAG; -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_SAMD) - // SAMD code + // SAMD code multiResetDetectorFlag = readFlagSAMD(); -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_SAM_DUE) - // SAM DUE code + // SAM DUE code multiResetDetectorFlag = readFlagSAM_DUE(); -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_NRF52 - // nRF52 code - multiResetDetectorFlag = readFlagNRF52(); + // nRF52 code + multiResetDetectorFlag = readFlagNRF52(); -///////////////////////////// -#elif MRD_GENERIC_USE_RP2040 - // RP2040 code - multiResetDetectorFlag = readFlagRP2040(); + ///////////////////////////// +#elif MRD_GENERIC_USE_RP2040 + // RP2040 code + multiResetDetectorFlag = readFlagRP2040(); -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_MBED_RP2040 - // MBED RP2040 code + // MBED RP2040 code multiResetDetectorFlag = readFlagMbedRP2040(); -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_MBED_PORTENTA) - // MBED Portenta code + // MBED Portenta code multiResetDetectorFlag = readFlagMbedPortenta(); - -///////////////////////////// + + ///////////////////////////// #elif MRD_GENERIC_USE_NANO33BLE - // MBED Nano_33_BLE code + // MBED Nano_33_BLE code multiResetDetectorFlag = readFlagNano33BLE(); - -///////////////////////////// + + ///////////////////////////// #elif (MRD_GENERIC_USE_RTL8720) - // RTL8720 code + // RTL8720 code multiResetDetectorFlag = readFlagRTL8720(); - + #endif //(MRD_GENERIC_USE_EEPROM || MRD_GENERIC_USE_STM32) return true; } - + ///////////////////////////////////////////////////////////////////// - + bool detectRecentlyResetFlag() { if (!readRecentlyResetFlag()) return false; - + ///////////////////////////////////////// //multiResetDetected = (multiResetDetectorFlag == MULTIRESETDETECTOR_FLAG_SET); // Check lower 2 bytes is > 0 and upper 2 bytes agrees - -#if USING_INVERTED + +#if USING_INVERTED uint16_t upperBytes = ~(multiResetDetectorFlag >> 16); #else uint16_t upperBytes = multiResetDetectorFlag >> 16; #endif - + uint16_t lowerBytes = multiResetDetectorFlag & 0x0000FFFF; - + #if (MRD_GENERIC_DEBUG) Serial.print(F("multiResetDetectorFlag = 0x")); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); @@ -1185,15 +1196,15 @@ class MultiResetDetector_Generic Serial.println(String(upperBytes, HEX)); #endif - if ( ( lowerBytes >= MRD_TIMES ) && ( lowerBytes == upperBytes ) ) + if ( ( lowerBytes >= MRD_TIMES ) && ( lowerBytes == upperBytes ) ) { multiResetDetected = true; } else { multiResetDetected = false; - - if (lowerBytes != upperBytes) + + if (lowerBytes != upperBytes) { #if (MRD_GENERIC_DEBUG) Serial.print(F("lowerBytes = 0x")); @@ -1202,232 +1213,232 @@ class MultiResetDetector_Generic Serial.println(String(upperBytes, HEX)); Serial.println(F("detectRecentlyResetFlag: Data corrupted. Reset to 0")); #endif - // To reset flag to MULTIRESETDETECTOR_GENERIC_FLAG_CLEAR if data corrupted + // To reset flag to MULTIRESETDETECTOR_GENERIC_FLAG_CLEAR if data corrupted clearRecentlyResetFlag(MULTIRESETDETECTOR_GENERIC_FLAG_CLEAR); } } - ///////////////////////////////////////// - - + ///////////////////////////////////////// + + return multiResetDetected; }; ///////////////////////////////////////////////////////////////////// - + void setRecentlyResetFlag() { // Add 1 every time detecting a reset // To read first, increase and update 2 checking bytes readRecentlyResetFlag(); - + MULTIRESETDETECTOR_FLAG = multiResetDetectorFlag; - + #if USING_INVERTED // 2 lower bytes MULTIRESETDETECTOR_FLAG = (MULTIRESETDETECTOR_FLAG & 0x0000FFFF) + 1; - + // 2 upper bytes //uint16_t upperBytes = ~MULTIRESETDETECTOR_FLAG; uint32_t upperBytes = ~MULTIRESETDETECTOR_FLAG; MULTIRESETDETECTOR_FLAG = (upperBytes << 16) | MULTIRESETDETECTOR_FLAG; -#else +#else // 2 lower bytes MULTIRESETDETECTOR_FLAG = (MULTIRESETDETECTOR_FLAG & 0x0000FFFF) + 1; - + // 2 upper bytes MULTIRESETDETECTOR_FLAG = (MULTIRESETDETECTOR_FLAG << 16) | MULTIRESETDETECTOR_FLAG; #endif multiResetDetectorFlag = MULTIRESETDETECTOR_FLAG; -///////////////////////////// + ///////////////////////////// #if (MRD_GENERIC_USE_EEPROM || MRD_GENERIC_USE_STM32) EEPROM.put(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) delay(1000); EEPROM.get(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_SAMD) - // SAMD code - uint16_t offset = MRD_EEPROM_START; + // SAMD code + uint16_t offset = MRD_EEPROM_START; uint8_t* _pointer = (uint8_t *) &MULTIRESETDETECTOR_FLAG; - + for (unsigned int i = 0; i < sizeof(MULTIRESETDETECTOR_FLAG); i++, _pointer++, offset++) - { + { EEPROM.write(offset, *_pointer); } - + EEPROM.commit(); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) delay(1000); readFlagSAMD(); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_SAM_DUE) - // SAM DUE code + // SAM DUE code dueFlashStorage.write(MRD_EEPROM_START, (byte *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) delay(1000); readFlagSAM_DUE(); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_NRF52 // nRF52 code MRD_file.open(MRD_FILENAME, FILE_O_WRITE); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print(F("Saving MULTIRESETDETECTOR_FLAG to MRD file : 0x")); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (MRD_file) { MRD_file.seek(MRD_FLAG_OFFSET); MRD_file.write((uint8_t *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); MRD_file.close(); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println(F("Saving MRD file OK")); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println(F("Saving MRD file failed")); - #endif +#endif } - -///////////////////////////// + + ///////////////////////////// #elif MRD_GENERIC_USE_RP2040 // RP2040 code - File file = FileFS.open(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + File file = FileFS.open(MRD_FILENAME, "w"); + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving MULTIRESETDETECTOR_FLAG to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) { file.seek(MRD_FLAG_OFFSET); file.write((uint8_t *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); file.close(); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif +#endif } -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_MBED_RP2040 // Mbed RP2040 code FILE *file = fopen(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving MULTIRESETDETECTOR_FLAG to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fwrite((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - + fclose(file); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif +#endif } -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_MBED_PORTENTA) // Mbed Portenta code FILE *file = fopen(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving MULTIRESETDETECTOR_FLAG to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fwrite((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - + fclose(file); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif +#endif } - - -///////////////////////////// + + + ///////////////////////////// #elif MRD_GENERIC_USE_NANO33BLE // Mbed Nano_33_BLE code FILE *file = fopen(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving MULTIRESETDETECTOR_FLAG to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fwrite((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - + fclose(file); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif +#endif } - -///////////////////////////// + + ///////////////////////////// #elif (MRD_GENERIC_USE_RTL8720) - // RTL8720 code + // RTL8720 code FlashStorage.put(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) delay(1000); readFlagRTL8720(); - #endif - -///////////////////////////// +#endif + + ///////////////////////////// #endif //(MRD_GENERIC_USE_EEPROM || MRD_GENERIC_USE_STM32) #if (MRD_GENERIC_DEBUG) @@ -1437,223 +1448,223 @@ class MultiResetDetector_Generic }; ///////////////////////////////////////////////////////////////////// - + void clearRecentlyResetFlag(uint32_t flagValue = MULTIRESETDETECTOR_GENERIC_FLAG_BEGIN) - { + { multiResetDetectorFlag = flagValue; MULTIRESETDETECTOR_FLAG = flagValue; -///////////////////////////// + ///////////////////////////// #if (MRD_GENERIC_USE_EEPROM || MRD_GENERIC_USE_STM32) EEPROM.put(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) delay(1000); EEPROM.get(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_SAMD) - // SAMD code - uint16_t offset = MRD_EEPROM_START; + // SAMD code + uint16_t offset = MRD_EEPROM_START; uint8_t* _pointer = (uint8_t *) &MULTIRESETDETECTOR_FLAG; - + for (unsigned int i = 0; i < sizeof(MULTIRESETDETECTOR_FLAG); i++, _pointer++, offset++) - { + { EEPROM.write(offset, *_pointer); } - + EEPROM.commit(); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) delay(1000); readFlagSAMD(); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_SAM_DUE) - // SAM DUE code + // SAM DUE code dueFlashStorage.write(MRD_EEPROM_START, (byte *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) delay(1000); readFlagSAM_DUE(); - #endif +#endif -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_NRF52 // nRF52 code MRD_file.open(MRD_FILENAME, FILE_O_WRITE); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.print(F("Saving to MRD file : 0x")); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (MRD_file) { MRD_file.seek(MRD_FLAG_OFFSET); - MRD_file.write((uint8_t *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); - + MRD_file.write((uint8_t *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); + MRD_file.close(); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println(F("Saving MRD file OK")); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println(F("Saving MRD file failed")); - #endif - } - +#endif + } + delay(1000); readFlagNRF52(); -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_RP2040 // RP2040 code File file = FileFS.open(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) { file.seek(MRD_FLAG_OFFSET); - file.write((uint8_t *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); - + file.write((uint8_t *) &MULTIRESETDETECTOR_FLAG, sizeof(MULTIRESETDETECTOR_FLAG)); + file.close(); - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif - } - +#endif + } + delay(1000); readFlagRP2040(); -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_MBED_RP2040 // Mbed RP2040 code FILE *file = fopen(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) - { + { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fwrite((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - + fclose(file); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif - } - +#endif + } + delay(1000); readFlagMbedRP2040(); -///////////////////////////// + ///////////////////////////// #elif (MRD_GENERIC_USE_MBED_PORTENTA) // Mbed Portenta code FILE *file = fopen(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) - { + { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fwrite((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - + fclose(file); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif - } - +#endif + } + delay(1000); readFlagMbedPortenta(); -///////////////////////////// + ///////////////////////////// #elif MRD_GENERIC_USE_NANO33BLE // Mbed Nano_33_BLE code FILE *file = fopen(MRD_FILENAME, "w"); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.print("Saving to MRD file : 0x"); Serial.println(String(MULTIRESETDETECTOR_FLAG, HEX)); - #endif +#endif if (file) - { + { fseek(file, MRD_FLAG_OFFSET, SEEK_SET); fwrite((uint8_t *) &MULTIRESETDETECTOR_FLAG, 1, sizeof(MULTIRESETDETECTOR_FLAG), file); - + fclose(file); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file OK"); - #endif +#endif } else { - #if (MRD_GENERIC_DEBUG) +#if (MRD_GENERIC_DEBUG) Serial.println("Saving MRD file failed"); - #endif - } - +#endif + } + delay(1000); readFlagNano33BLE(); - -///////////////////////////// + + ///////////////////////////// #elif (MRD_GENERIC_USE_RTL8720) - - // RTL8720 code + + // RTL8720 code FlashStorage.put(MRD_EEPROM_START, MULTIRESETDETECTOR_FLAG); - - #if (MRD_GENERIC_DEBUG) + +#if (MRD_GENERIC_DEBUG) delay(1000); readFlagRTL8720(); - #endif - -///////////////////////////// - +#endif + + ///////////////////////////// + #endif //(MRD_GENERIC_USE_EEPROM || MRD_GENERIC_USE_STM32) #if (MRD_GENERIC_DEBUG) diff --git a/src/mbed_portenta/FlashIAPLimits.h b/src/mbed_portenta/FlashIAPLimits.h index f394dfd..f15215e 100644 --- a/src/mbed_portenta/FlashIAPLimits.h +++ b/src/mbed_portenta/FlashIAPLimits.h @@ -1,6 +1,6 @@ /**************************************************************************************************************************** FlashIAPLimits.h - Filesystem wrapper for LittleFS on the Mbed Portenta_H7 - + Arduino AVR, Teensy, SAM-DUE, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, nRF52, RASPBERRY_PI_PICO, etc. boards MultiResetDetector_Generic is a library for the Arduino AVR, Teensy, SAM-DUE, SAMD, STM32, nRF52, RASPBERRY_PI_PICO, etc. boards @@ -13,7 +13,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/MultiResetDetector_Generic Licensed under MIT license - + Version: 1.8.1 Version Modified By Date Comments @@ -45,7 +45,7 @@ using namespace mbed; // A helper struct for FlashIAP limits -struct FlashIAPLimits +struct FlashIAPLimits { size_t flash_size; uint32_t start_address; @@ -57,24 +57,24 @@ struct FlashIAPLimits static FlashIAPLimits getFlashIAPLimits() { // Alignment lambdas - auto align_down = [](uint64_t val, uint64_t size) + auto align_down = [](uint64_t val, uint64_t size) { return (((val) / size)) * size; }; - - auto align_up = [](uint32_t val, uint32_t size) + + auto align_up = [](uint32_t val, uint32_t size) { return (((val - 1) / size) + 1) * size; }; FlashIAPLimits flashIAPLimits; - + uint32_t flash_start_address; - + FlashIAP flash; auto result = flash.init(); - + if (result != 0) return { }; @@ -82,14 +82,16 @@ static FlashIAPLimits getFlashIAPLimits() int sector_size = flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR); flash_start_address = flash.get_flash_start(); + flashIAPLimits.start_address = align_up(FLASHIAP_APP_ROM_END_ADDR, sector_size); + flashIAPLimits.flash_size = flash.get_flash_size(); result = flash.deinit(); flashIAPLimits.available_size = flash_start_address + flashIAPLimits.flash_size - flashIAPLimits.start_address; - - if (flashIAPLimits.available_size % (sector_size * 2)) + + if (flashIAPLimits.available_size % (sector_size * 2)) { flashIAPLimits.available_size = align_down(flashIAPLimits.available_size, sector_size * 2); } 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 +