From 50560a23ac1ab3b52ebf8182e86004de868bca0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Piln=C3=BD?= <34927466+PilnyTomas@users.noreply.github.com> Date: Thu, 11 May 2023 12:18:16 +0200 Subject: [PATCH 1/4] Functional interrupt fix (#8175) * Added link to external examples to the doc * Fixed FunctionalInterrupt.ino + added introduction comment and few outputs --- .../FunctionalInterrupt.ino | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino b/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino index 844a14dabd1..d028f4ea036 100644 --- a/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino +++ b/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino @@ -1,26 +1,45 @@ +/* + * This example demonstrates usage of interrupt by detecting a button press. + * + * Setup: Connect first button between pin defined in BUTTON1 and GND + * Similarly connect second button between pin defined in BUTTON2 and GND. + * If you do not have a button simply connect a wire to those buttons + * - touching GND pin with other end of the wire will behave same as pressing the connected button. + * Wen using the bare wire be careful not to touch any other pin by accident. + * + * Note: There is no de-bounce implemented and the physical connection will normally + * trigger many more button presses than actually happened. + * This is completely normal and is not to be considered a fault. + */ + + #include #include #define BUTTON1 16 #define BUTTON2 17 -class Button -{ +class Button{ public: Button(uint8_t reqPin) : PIN(reqPin){ pinMode(PIN, INPUT_PULLUP); - attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING); }; - ~Button() { + + void begin(){ + attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING); + Serial.printf("Started button interrupt on pin %d\n", PIN); + } + + ~Button(){ detachInterrupt(PIN); } - void ARDUINO_ISR_ATTR isr() { + void ARDUINO_ISR_ATTR isr(){ numberKeyPresses += 1; pressed = true; } - void checkPressed() { + void checkPressed(){ if (pressed) { Serial.printf("Button on pin %u has been pressed %u times\n", PIN, numberKeyPresses); pressed = false; @@ -28,7 +47,7 @@ public: } private: - const uint8_t PIN; + const uint8_t PIN; volatile uint32_t numberKeyPresses; volatile bool pressed; }; @@ -36,9 +55,13 @@ private: Button button1(BUTTON1); Button button2(BUTTON2); - void setup() { Serial.begin(115200); + while(!Serial) delay(10); + Serial.println("Starting Functional Interrupt example."); + button1.begin(); + button2.begin(); + Serial.println("Setup done."); } void loop() { From 60751514c30528ae0c7aa5d8fa7028d6e55181e5 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Thu, 11 May 2023 18:43:23 +0800 Subject: [PATCH 2/4] Create M5CoreS3 pins_arduino.h and board (#8161) * Add M5CoreS3 boards.txt and pins definition * Fix some pins definition --- boards.txt | 192 +++++++++++++++++++++++++ variants/m5stack_cores3/pins_arduino.h | 72 ++++++++++ 2 files changed, 264 insertions(+) create mode 100644 variants/m5stack_cores3/pins_arduino.h diff --git a/boards.txt b/boards.txt index f3ea5e1cc5b..3c4bed617b9 100644 --- a/boards.txt +++ b/boards.txt @@ -12265,6 +12265,198 @@ m5stack-core2.menu.EraseFlash.all.upload.erase_cmd=-e ############################################################## +m5stack-cores3.name=M5Stack-CoreS3 +m5stack-cores3.vid.0=0x303a +m5stack-cores3.pid.0=0x1001 + +m5stack-cores3.bootloader.tool=esptool_py +m5stack-cores3.bootloader.tool.default=esptool_py + +m5stack-cores3.upload.tool=esptool_py +m5stack-cores3.upload.tool.default=esptool_py +m5stack-cores3.upload.tool.network=esp_ota + +m5stack-cores3.upload.maximum_size=1310720 +m5stack-cores3.upload.maximum_data_size=327680 +m5stack-cores3.upload.flags= +m5stack-cores3.upload.extra_flags= +m5stack-cores3.upload.use_1200bps_touch=false +m5stack-cores3.upload.wait_for_upload_port=false + +m5stack-cores3.serial.disableDTR=false +m5stack-cores3.serial.disableRTS=false + +m5stack-cores3.build.tarch=xtensa +m5stack-cores3.build.bootloader_addr=0x0 +m5stack-cores3.build.target=esp32s3 +m5stack-cores3.build.mcu=esp32s3 +m5stack-cores3.build.core=esp32 +m5stack-cores3.build.variant=m5stack_cores3 +m5stack-cores3.build.board=M5STACK_CORES3 + +m5stack-cores3.build.usb_mode=1 +m5stack-cores3.build.cdc_on_boot=0 +m5stack-cores3.build.msc_on_boot=0 +m5stack-cores3.build.dfu_on_boot=0 +m5stack-cores3.build.f_cpu=240000000L +m5stack-cores3.build.flash_size=4MB +m5stack-cores3.build.flash_freq=80m +m5stack-cores3.build.flash_mode=dio +m5stack-cores3.build.boot=qio +m5stack-cores3.build.boot_freq=80m +m5stack-cores3.build.partitions=default +m5stack-cores3.build.defines= +m5stack-cores3.build.loop_core= +m5stack-cores3.build.event_core= +m5stack-cores3.build.psram_type=qspi +m5stack-cores3.build.memory_type={build.boot}_{build.psram_type} + +m5stack-cores3.menu.JTAGAdapter.default=Disabled +m5stack-cores3.menu.JTAGAdapter.default.build.copy_jtag_files=0 +m5stack-cores3.menu.JTAGAdapter.builtin=Integrated USB JTAG +m5stack-cores3.menu.JTAGAdapter.builtin.build.openocdscript=esp32s3-builtin.cfg +m5stack-cores3.menu.JTAGAdapter.builtin.build.copy_jtag_files=1 +m5stack-cores3.menu.JTAGAdapter.external=FTDI Adapter +m5stack-cores3.menu.JTAGAdapter.external.build.openocdscript=esp32s3-ftdi.cfg +m5stack-cores3.menu.JTAGAdapter.external.build.copy_jtag_files=1 +m5stack-cores3.menu.JTAGAdapter.bridge=ESP USB Bridge +m5stack-cores3.menu.JTAGAdapter.bridge.build.openocdscript=esp32s3-bridge.cfg +m5stack-cores3.menu.JTAGAdapter.bridge.build.copy_jtag_files=1 + +m5stack-cores3.menu.PSRAM.disabled=Disabled +m5stack-cores3.menu.PSRAM.disabled.build.defines= +m5stack-cores3.menu.PSRAM.disabled.build.psram_type=qspi +m5stack-cores3.menu.PSRAM.enabled=QSPI PSRAM +m5stack-cores3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM +m5stack-cores3.menu.PSRAM.enabled.build.psram_type=qspi +m5stack-cores3.menu.PSRAM.opi=OPI PSRAM +m5stack-cores3.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM +m5stack-cores3.menu.PSRAM.opi.build.psram_type=opi + +m5stack-cores3.menu.FlashMode.qio=QIO 80MHz +m5stack-cores3.menu.FlashMode.qio.build.flash_mode=dio +m5stack-cores3.menu.FlashMode.qio.build.boot=qio +m5stack-cores3.menu.FlashMode.qio.build.boot_freq=80m +m5stack-cores3.menu.FlashMode.qio.build.flash_freq=80m +m5stack-cores3.menu.FlashMode.qio120=QIO 120MHz +m5stack-cores3.menu.FlashMode.qio120.build.flash_mode=dio +m5stack-cores3.menu.FlashMode.qio120.build.boot=qio +m5stack-cores3.menu.FlashMode.qio120.build.boot_freq=120m +m5stack-cores3.menu.FlashMode.qio120.build.flash_freq=80m +m5stack-cores3.menu.FlashMode.dio=DIO 80MHz +m5stack-cores3.menu.FlashMode.dio.build.flash_mode=dio +m5stack-cores3.menu.FlashMode.dio.build.boot=dio +m5stack-cores3.menu.FlashMode.dio.build.boot_freq=80m +m5stack-cores3.menu.FlashMode.dio.build.flash_freq=80m +m5stack-cores3.menu.FlashMode.opi=OPI 80MHz +m5stack-cores3.menu.FlashMode.opi.build.flash_mode=dout +m5stack-cores3.menu.FlashMode.opi.build.boot=opi +m5stack-cores3.menu.FlashMode.opi.build.boot_freq=80m +m5stack-cores3.menu.FlashMode.opi.build.flash_freq=80m + +m5stack-cores3.menu.FlashSize.4M=4MB (32Mb) +m5stack-cores3.menu.FlashSize.4M.build.flash_size=4MB +m5stack-cores3.menu.FlashSize.8M=8MB (64Mb) +m5stack-cores3.menu.FlashSize.8M.build.flash_size=8MB +m5stack-cores3.menu.FlashSize.8M.build.partitions=default_8MB +m5stack-cores3.menu.FlashSize.16M=16MB (128Mb) +m5stack-cores3.menu.FlashSize.16M.build.flash_size=16MB +#m5stack-cores3.menu.FlashSize.32M=32MB (256Mb) +#m5stack-cores3.menu.FlashSize.32M.build.flash_size=32MB + +m5stack-cores3.menu.LoopCore.1=Core 1 +m5stack-cores3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1 +m5stack-cores3.menu.LoopCore.0=Core 0 +m5stack-cores3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0 + +m5stack-cores3.menu.EventsCore.1=Core 1 +m5stack-cores3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1 +m5stack-cores3.menu.EventsCore.0=Core 0 +m5stack-cores3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0 + +m5stack-cores3.menu.USBMode.hwcdc=Hardware CDC and JTAG +m5stack-cores3.menu.USBMode.hwcdc.build.usb_mode=1 +m5stack-cores3.menu.USBMode.default=USB-OTG (TinyUSB) +m5stack-cores3.menu.USBMode.default.build.usb_mode=0 + +m5stack-cores3.menu.CDCOnBoot.default=Disabled +m5stack-cores3.menu.CDCOnBoot.default.build.cdc_on_boot=0 +m5stack-cores3.menu.CDCOnBoot.cdc=Enabled +m5stack-cores3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1 + +m5stack-cores3.menu.MSCOnBoot.default=Disabled +m5stack-cores3.menu.MSCOnBoot.default.build.msc_on_boot=0 +m5stack-cores3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode) +m5stack-cores3.menu.MSCOnBoot.msc.build.msc_on_boot=1 + +m5stack-cores3.menu.DFUOnBoot.default=Disabled +m5stack-cores3.menu.DFUOnBoot.default.build.dfu_on_boot=0 +m5stack-cores3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode) +m5stack-cores3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1 + +m5stack-cores3.menu.UploadMode.default=UART0 / Hardware CDC +m5stack-cores3.menu.UploadMode.default.upload.use_1200bps_touch=false +m5stack-cores3.menu.UploadMode.default.upload.wait_for_upload_port=false +m5stack-cores3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB) +m5stack-cores3.menu.UploadMode.cdc.upload.use_1200bps_touch=true +m5stack-cores3.menu.UploadMode.cdc.upload.wait_for_upload_port=true + +m5stack-cores3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS) +m5stack-cores3.menu.PartitionScheme.default.build.partitions=default +m5stack-cores3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS) +m5stack-cores3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat +m5stack-cores3.menu.PartitionScheme.default_8MB=8M with spiffs (3MB APP/1.5MB SPIFFS) +m5stack-cores3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB +m5stack-cores3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336 + +m5stack-cores3.menu.CPUFreq.240=240MHz (WiFi) +m5stack-cores3.menu.CPUFreq.240.build.f_cpu=240000000L +m5stack-cores3.menu.CPUFreq.160=160MHz (WiFi) +m5stack-cores3.menu.CPUFreq.160.build.f_cpu=160000000L +m5stack-cores3.menu.CPUFreq.80=80MHz (WiFi) +m5stack-cores3.menu.CPUFreq.80.build.f_cpu=80000000L +m5stack-cores3.menu.CPUFreq.40=40MHz +m5stack-cores3.menu.CPUFreq.40.build.f_cpu=40000000L +m5stack-cores3.menu.CPUFreq.20=20MHz +m5stack-cores3.menu.CPUFreq.20.build.f_cpu=20000000L +m5stack-cores3.menu.CPUFreq.10=10MHz +m5stack-cores3.menu.CPUFreq.10.build.f_cpu=10000000L + +m5stack-cores3.menu.UploadSpeed.921600=921600 +m5stack-cores3.menu.UploadSpeed.921600.upload.speed=921600 +m5stack-cores3.menu.UploadSpeed.115200=115200 +m5stack-cores3.menu.UploadSpeed.115200.upload.speed=115200 +m5stack-cores3.menu.UploadSpeed.256000.windows=256000 +m5stack-cores3.menu.UploadSpeed.256000.upload.speed=256000 +m5stack-cores3.menu.UploadSpeed.230400.windows.upload.speed=256000 +m5stack-cores3.menu.UploadSpeed.230400=230400 +m5stack-cores3.menu.UploadSpeed.230400.upload.speed=230400 +m5stack-cores3.menu.UploadSpeed.460800.linux=460800 +m5stack-cores3.menu.UploadSpeed.460800.macosx=460800 +m5stack-cores3.menu.UploadSpeed.460800.upload.speed=460800 +m5stack-cores3.menu.UploadSpeed.512000.windows=512000 +m5stack-cores3.menu.UploadSpeed.512000.upload.speed=512000 + +m5stack-cores3.menu.DebugLevel.none=None +m5stack-cores3.menu.DebugLevel.none.build.code_debug=0 +m5stack-cores3.menu.DebugLevel.error=Error +m5stack-cores3.menu.DebugLevel.error.build.code_debug=1 +m5stack-cores3.menu.DebugLevel.warn=Warn +m5stack-cores3.menu.DebugLevel.warn.build.code_debug=2 +m5stack-cores3.menu.DebugLevel.info=Info +m5stack-cores3.menu.DebugLevel.info.build.code_debug=3 +m5stack-cores3.menu.DebugLevel.debug=Debug +m5stack-cores3.menu.DebugLevel.debug.build.code_debug=4 +m5stack-cores3.menu.DebugLevel.verbose=Verbose +m5stack-cores3.menu.DebugLevel.verbose.build.code_debug=5 + +m5stack-cores3.menu.EraseFlash.none=Disabled +m5stack-cores3.menu.EraseFlash.none.upload.erase_cmd= +m5stack-cores3.menu.EraseFlash.all=Enabled +m5stack-cores3.menu.EraseFlash.all.upload.erase_cmd=-e + +############################################################## + m5stack-timer-cam.name=M5Stack-Timer-CAM m5stack-timer-cam.bootloader.tool=esptool_py diff --git a/variants/m5stack_cores3/pins_arduino.h b/variants/m5stack_cores3/pins_arduino.h new file mode 100644 index 00000000000..c8c979abe69 --- /dev/null +++ b/variants/m5stack_cores3/pins_arduino.h @@ -0,0 +1,72 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 48 +#define NUM_ANALOG_INPUTS 20 + +// Some boards have too low voltage on this pin (board design bug) +// Use different pin with 3V and connect with 48 +// and change this setup for the chosen pin (for example 38) +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 + +#define analogInputToDigitalPin(p) \ + (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) +#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1) +#define digitalPinHasPWM(p) (p < 46) + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t TXD2 = 17; +static const uint8_t RXD2 = 18; + +static const uint8_t SDA = 12; +static const uint8_t SCL = 11; + +static const uint8_t SS = 15; +static const uint8_t MOSI = 37; +static const uint8_t MISO = 35; +static const uint8_t SCK = 36; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; +static const uint8_t G11 = 11; +static const uint8_t G12 = 12; +static const uint8_t G13 = 13; +static const uint8_t G14 = 14; +static const uint8_t G17 = 17; +static const uint8_t G18 = 18; +static const uint8_t G19 = 19; +static const uint8_t G20 = 20; +static const uint8_t G21 = 21; +static const uint8_t G33 = 33; +static const uint8_t G34 = 34; +static const uint8_t G35 = 35; +static const uint8_t G36 = 36; +static const uint8_t G37 = 37; +static const uint8_t G38 = 38; +static const uint8_t G45 = 45; +static const uint8_t G46 = 46; + +static const uint8_t ADC = 10; + +#endif /* Pins_Arduino_h */ From a2c892073b24c327b77981aa7cec9cc8e5e512fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Piln=C3=BD?= <34927466+PilnyTomas@users.noreply.github.com> Date: Thu, 11 May 2023 12:49:30 +0200 Subject: [PATCH 3/4] Updated preferences and FAQ documentation (added SPIFFS) (#8150) * Updated preferences.rst * Added into FAQ info about SPIFFS failed mount --- docs/source/faq.rst | 17 ++++++++++ docs/source/tutorials/preferences.rst | 49 +++++++++++++++++---------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/docs/source/faq.rst b/docs/source/faq.rst index 97520b35673..6af19fc804f 100644 --- a/docs/source/faq.rst +++ b/docs/source/faq.rst @@ -15,3 +15,20 @@ How to compile libs with different debug level? ----------------------------------------------- The short answer is ``esp32-arduino-lib-builder/configs/defconfig.common:44``. A guide explaining the process can be found here + +SPIFFS mount failed +------------------- +When you come across and error like this: + +.. code-block:: shell + + E (588) SPIFFS: mount failed, -10025 + [E][SPIFFS.cpp:47] begin(): Mounting SPIFFS failed! Error: -1 + +Try enforcing format on fail in your code by adding ``true`` in the ``begin`` method such as this: + +.. code-block:: c++ + + SPIFFS.begin(true); + +See the method prototype for reference: ``bool begin(bool formatOnFail=false, const char * basePath="/spiffs", uint8_t maxOpenFiles=10, const char * partitionLabel=NULL);`` \ No newline at end of file diff --git a/docs/source/tutorials/preferences.rst b/docs/source/tutorials/preferences.rst index eb0397af543..3cb54f1928c 100644 --- a/docs/source/tutorials/preferences.rst +++ b/docs/source/tutorials/preferences.rst @@ -233,9 +233,9 @@ Like so: .. code-block:: arduino - String myString = myPreferences.getString("myStringKey"); + float myFloat = myPreferences.getFloat("pi"); -This will retrieve the String value from the namespace key ``"myStringKey"`` and assign it to the String type variable ``myString``. +This will retrieve the float value from the namespace key ``"pi"`` and assign it to the float type variable ``myFloat``. Summary @@ -277,9 +277,10 @@ When started, the system has no way of knowing which of the above conditions is // not the complete setup(), but in setup(), include this... stcPrefs.begin("STCPrefs", RO_MODE); // Open our namespace (or create it - // if it doesn't exist) in in RO mode. + // if it doesn't exist) in RO mode. - bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence of the "already initialized" key. + bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence + // of the "already initialized" key. if (tpInit == false) { // If tpInit is 'false', the key "nvsInit" does not yet exist therefore this @@ -289,13 +290,15 @@ When started, the system has no way of knowing which of the above conditions is // The .begin() method created the "STCPrefs" namespace and since this is our - // first-time run we will create our keys and store the initial "factory default" values. + // first-time run we will create + // our keys and store the initial "factory default" values. stcPrefs.putUChar("curBright", 10); stcPrefs.putString("talChan", "one"); stcPrefs.putLong("talMax", -220226); stcPrefs.putBool("ctMde", true); - stcPrefs.putBool("nvsInit", true); // Create the "already initialized" key and store a value. + stcPrefs.putBool("nvsInit", true); // Create the "already initialized" + // key and store a value. // The "factory defaults" are created and stored so... stcPrefs.end(); // Close the namespace in RW mode and... @@ -456,10 +459,12 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s Serial.begin(115200); delay(250); - mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace "myPrefs" in RW mode + mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace + // "myPrefs" in RW mode mySketchPrefs.clear(); // delete any previous keys in this namespace - // Create an array of test values. We're using hex numbers throughout to better show how the bytes move around. + // Create an array of test values. We're using hex numbers + // throughout to better show how the bytes move around. int16_t myArray[] = { 0x1112, 0x2122, 0x3132, 0x4142, 0x5152, 0x6162, 0x7172 }; Serial.println("Printing myArray..."); @@ -468,22 +473,28 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s } Serial.println("\r\n"); - // In the next statement, the second sizeof() needs to match the data type of the elements of myArray - Serial.print("The number of elements in myArray is: "); Serial.println( sizeof(myArray) / sizeof(int16_t) ); - Serial.print("But the size of myArray in bytes is: "); Serial.println( sizeof(myArray) ); + // In the next statement, the second sizeof() needs + // to match the data type of the elements of myArray + Serial.print("The number of elements in myArray is: "); + Serial.println( sizeof(myArray) / sizeof(int16_t) ); + Serial.print("But the size of myArray in bytes is: "); + Serial.println( sizeof(myArray) ); Serial.println(""); - Serial.println("Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\"."); + Serial.println( + "Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\"."); // Note: in the next statement, to store the entire array, we must use the // size of the arrray in bytes, not the number of elements in the array. mySketchPrefs.putBytes( "myPrefsBytes", myArray, sizeof(myArray) ); - Serial.print("The size of \"myPrefsBytes\" is (in bytes): "); Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") ); + Serial.print("The size of \"myPrefsBytes\" is (in bytes): "); + Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") ); Serial.println(""); - int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough. + int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough. Serial.println("Retrieving the value of myPrefsBytes into myIntBuffer."); Serial.println(" - Note the data type of myIntBuffer matches that of myArray"); - mySketchPrefs.getBytes( "myPrefsBytes", myIntBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") ); + mySketchPrefs.getBytes("myPrefsBytes", myIntBuffer, + mySketchPrefs.getBytesLength("myPrefsBytes")); Serial.println("Printing myIntBuffer..."); // In the next statement, sizeof() needs to match the data type of the elements of myArray @@ -492,9 +503,11 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s } Serial.println("\r\n"); - Serial.println("We can see how the data from myArray is actually stored in the namespace as follows."); - uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough. - mySketchPrefs.getBytes( "myPrefsBytes", myByteBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") ); + Serial.println( + "We can see how the data from myArray is actually stored in the namespace as follows."); + uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough. + mySketchPrefs.getBytes("myPrefsBytes", myByteBuffer, + mySketchPrefs.getBytesLength("myPrefsBytes")); Serial.println("Printing myByteBuffer..."); for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes"); i++) { From 3ec5f4efa1de4342aaab742008dc630091e5e035 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Thu, 11 May 2023 15:13:36 +0200 Subject: [PATCH 4/4] HardwareSerial: fix begin() lock issue on error path (#8182) * HardwareSerial: fix begin() lock issue on error path If the user supplied a wrong UART number, the begin() method would return without releasing the lock. Add missing unlock call. * removing unsed Case test --------- Co-authored-by: Rodrigo Garcia --- cores/esp32/HardwareSerial.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index e60588f931e..e2b12bda3f4 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -365,9 +365,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in } break; #endif - default: - log_e("Bad UART Number"); - return; } }