From c3e699de004164bacfbb4881dd1037a01b6b589d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 1 Mar 2021 09:48:28 +0100 Subject: [PATCH 01/10] Fix gpios for Nano rp2040 connect --- main/CommandHandler.cpp | 12 +++++++++--- main/sketch.ino.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index 7d2c3f96..41497219 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -1578,9 +1578,15 @@ CommandHandlerClass::CommandHandlerClass() { } +#if defined(NANO_RP2040_CONNECT) +static const int GPIO_IRQ = 26; +#else +static const int GPIO_IRQ = 0; +#endif + void CommandHandlerClass::begin() { - pinMode(0, OUTPUT); + pinMode(GPIO_IRQ, OUTPUT); for (int i = 0; i < MAX_SOCKETS; i++) { socketTypes[i] = 255; @@ -1667,9 +1673,9 @@ void CommandHandlerClass::updateGpio0Pin() } if (available) { - digitalWrite(0, HIGH); + digitalWrite(GPIO_IRQ, HIGH); } else { - digitalWrite(0, LOW); + digitalWrite(GPIO_IRQ, LOW); } vTaskDelay(1); diff --git a/main/sketch.ino.cpp b/main/sketch.ino.cpp index b71de7c3..6660a2ba 100644 --- a/main/sketch.ino.cpp +++ b/main/sketch.ino.cpp @@ -111,7 +111,7 @@ void setupBluetooth() { periph_module_enable(PERIPH_UART1_MODULE); periph_module_enable(PERIPH_UHCI0_MODULE); -#ifdef UNO_WIFI_REV2 +#if defined(UNO_WIFI_REV2) || defined(NANO_RP2040_CONNECT) uart_set_pin(UART_NUM_1, 1, 3, 33, 0); // TX, RX, RTS, CTS #else uart_set_pin(UART_NUM_1, 23, 12, 18, 5); From 92b38f6b39d677113649d7261971e75237e45975 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 1 Mar 2021 09:54:16 +0100 Subject: [PATCH 02/10] Fix makefile --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index c8a54890..4c4fa19c 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,11 @@ CFLAGS += -DUNO_WIFI_REV2 CPPFLAGS += -DUNO_WIFI_REV2 endif +ifeq ($(NANO_RP2040_CONNECT),1) +CFLAGS += -DNANO_RP2040_CONNECT +CPPFLAGS += -DNANO_RP2040_CONNECT +endif + include $(IDF_PATH)/make/project.mk firmware: all From 6bb97b6a893d038cdd037542a88cb6c5b6c93812 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 1 Mar 2021 13:06:55 +0100 Subject: [PATCH 03/10] rp2040: give LEDs safe defaults --- main/sketch.ino.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main/sketch.ino.cpp b/main/sketch.ino.cpp index 6660a2ba..6fe4367b 100644 --- a/main/sketch.ino.cpp +++ b/main/sketch.ino.cpp @@ -97,6 +97,13 @@ void setup() { pinMode(15, INPUT); pinMode(21, INPUT); +#if defined(NANO_RP2040_CONNECT) + pinMode(26, OUTPUT); + pinMode(27, OUTPUT); + digitalWrite(26, HIGH); + digitalWrite(27, HIGH); +#endif + pinMode(5, INPUT); if (digitalRead(5) == LOW) { setupBluetooth(); @@ -121,7 +128,7 @@ void setupBluetooth() { esp_bt_controller_config_t btControllerConfig = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); btControllerConfig.hci_uart_no = UART_NUM_1; -#ifdef UNO_WIFI_REV2 +#if defined(UNO_WIFI_REV2) || defined(NANO_RP2040_CONNECT) btControllerConfig.hci_uart_baudrate = 115200; #else btControllerConfig.hci_uart_baudrate = 912600; From 0f9f8310863d79a8be516fc4c1e272de23b53d8a Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 12 Apr 2021 14:46:02 +0200 Subject: [PATCH 04/10] Implement digitalRead API which allows to read the status of a digital input pin from the host processor. --- main/CommandHandler.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index 41497219..f1a23bd6 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -1180,6 +1180,19 @@ int setAnalogWrite(const uint8_t command[], uint8_t response[]) return 6; } +int getDigitalRead(const uint8_t command[], uint8_t response[]) +{ + uint8_t pin = command[4]; + + int const pin_status = digitalRead(pin); + + response[2] = 1; // number of parameters + response[3] = 1; // parameter 1 length + response[4] = (uint8_t)pin_status; + + return 6; +} + int writeFile(const uint8_t command[], uint8_t response[]) { char filename[32 + 1]; size_t len; @@ -1566,7 +1579,7 @@ const CommandHandlerType commandHandlers[] = { setEnt, NULL, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 0x50 -> 0x5f - setPinMode, setDigitalWrite, setAnalogWrite, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + setPinMode, setDigitalWrite, setAnalogWrite, getDigitalRead, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 0x60 -> 0x6f writeFile, readFile, deleteFile, existsFile, downloadFile, applyOTA, renameFile, downloadOTA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, From a323261c557310388b1001d9cf45771859f75e7e Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 12 Apr 2021 15:23:41 +0200 Subject: [PATCH 05/10] Implement analogRead() API which allows to read the value provided at any of the analog pins of the ESP32. --- main/CommandHandler.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index f1a23bd6..6b87033a 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -1193,6 +1193,34 @@ int getDigitalRead(const uint8_t command[], uint8_t response[]) return 6; } +extern "C" { +#include +} + +int getAnalogRead(const uint8_t command[], uint8_t response[]) +{ + uint8_t pin = command[4]; + + /* Power up the ADC. */ + adc_power_on(); + /* Initialize the ADC. */ + adc_gpio_init(ADC_UNIT_1, (adc_channel_t)pin); + /* Set maximum analog bit-width = 12 bit. */ + adc1_config_width(ADC_WIDTH_BIT_12); + /* Configure channel attenuation. */ + adc1_config_channel_atten((adc1_channel_t)pin, ADC_ATTEN_DB_0); + /* Read the analog value from the pin. */ + uint16_t const adc_raw = adc1_get_raw((adc1_channel_t)pin); + /* Power down the ADC. */ + adc_power_off(); + + response[2] = 1; // number of parameters + response[3] = sizeof(adc_raw); // parameter 1 length = 2 bytes + memcpy(&response[4], &adc_raw, sizeof(adc_raw)); + + return 7; +} + int writeFile(const uint8_t command[], uint8_t response[]) { char filename[32 + 1]; size_t len; @@ -1579,7 +1607,7 @@ const CommandHandlerType commandHandlers[] = { setEnt, NULL, NULL, NULL, sendDataTcp, getDataBufTcp, insertDataBuf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 0x50 -> 0x5f - setPinMode, setDigitalWrite, setAnalogWrite, getDigitalRead, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + setPinMode, setDigitalWrite, setAnalogWrite, getDigitalRead, getAnalogRead, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 0x60 -> 0x6f writeFile, readFile, deleteFile, existsFile, downloadFile, applyOTA, renameFile, downloadOTA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, From ae9c8535b5b011fa5c3334c3d5e5ef5a72845063 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 13 Apr 2021 07:17:09 +0200 Subject: [PATCH 06/10] Add API for configuring a GPIO as INPUT_PULLUP. --- arduino/cores/esp32/wiring_digital.c | 5 +++++ arduino/cores/esp32/wiring_digital.h | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arduino/cores/esp32/wiring_digital.c b/arduino/cores/esp32/wiring_digital.c index 05435df4..2bfdbda1 100644 --- a/arduino/cores/esp32/wiring_digital.c +++ b/arduino/cores/esp32/wiring_digital.c @@ -33,6 +33,11 @@ void pinMode(uint32_t pin, uint32_t mode) gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT); gpio_set_pull_mode((gpio_num_t)pin, GPIO_FLOATING); break; + + case INPUT_PULLUP: + gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT); + gpio_set_pull_mode((gpio_num_t)pin, GPIO_PULLUP_ONLY); + break; } PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO); diff --git a/arduino/cores/esp32/wiring_digital.h b/arduino/cores/esp32/wiring_digital.h index 6788aeb0..ac3558f4 100644 --- a/arduino/cores/esp32/wiring_digital.h +++ b/arduino/cores/esp32/wiring_digital.h @@ -29,8 +29,9 @@ extern "C" { #define LOW 0x00 #define HIGH 0x01 -#define INPUT 0x00 -#define OUTPUT 0x01 +#define INPUT 0x00 +#define OUTPUT 0x01 +#define INPUT_PULLUP 0x02 extern void pinMode(uint32_t pin, uint32_t mode); From bed5b6268a75ad036d0446cccc7eb34d7fbdf8ad Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 13 Apr 2021 08:36:04 +0200 Subject: [PATCH 07/10] Fix: There is no need to manually power-up the ADC, as the ADC is powered-up within 'adc1_get_raw' --- main/CommandHandler.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index 6b87033a..a8352e1b 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -1199,20 +1199,16 @@ extern "C" { int getAnalogRead(const uint8_t command[], uint8_t response[]) { - uint8_t pin = command[4]; + uint8_t adc_channel = command[4]; - /* Power up the ADC. */ - adc_power_on(); /* Initialize the ADC. */ - adc_gpio_init(ADC_UNIT_1, (adc_channel_t)pin); + adc_gpio_init(ADC_UNIT_1, (adc_channel_t)adc_channel); /* Set maximum analog bit-width = 12 bit. */ adc1_config_width(ADC_WIDTH_BIT_12); /* Configure channel attenuation. */ - adc1_config_channel_atten((adc1_channel_t)pin, ADC_ATTEN_DB_0); + adc1_config_channel_atten((adc1_channel_t)adc_channel, ADC_ATTEN_DB_0); /* Read the analog value from the pin. */ - uint16_t const adc_raw = adc1_get_raw((adc1_channel_t)pin); - /* Power down the ADC. */ - adc_power_off(); + uint16_t const adc_raw = adc1_get_raw((adc1_channel_t)adc_channel); response[2] = 1; // number of parameters response[3] = sizeof(adc_raw); // parameter 1 length = 2 bytes From 054edb8798eac7d19083fa7dfcb6fe813eedac23 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 13 Apr 2021 09:12:33 +0200 Subject: [PATCH 08/10] Release v1.4.4. --- CHANGELOG | 12 ++++++++++++ main/CommandHandler.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 10e72533..3d76ca08 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,17 @@ Arduino NINA-W102 firmware ?.?.? - ????.??.?? +Arduino NINA-W102 firmware 1.4.4 - 2021.04.13 + +* Adding support for Arduino RP2040 Nano Connect (#64) + +Arduino NINA-W102 firmware 1.4.3 - 2021.01.29 + +* Do not immediately close connection after 1 failed write (#62) + +Arduino NINA-W102 firmware 1.4.2 - 2021.01.28 + +Port BearSSL + crypto integration to NINA (#57). This allows to offload BearSSL for Arduino IoT Cloud applications to the nina module, drastically saving on flash/RAM. + Arduino NINA-W102 firmware 1.4.1 - 2020.08.17 * Direct download of OTA binary to Nina storage and verifying both CRC and length (#53) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index a8352e1b..db6e43ba 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -36,7 +36,7 @@ #include "esp_log.h" -const char FIRMWARE_VERSION[6] = "1.4.3"; +const char FIRMWARE_VERSION[6] = "1.4.4"; /*IPAddress*/uint32_t resolvedHostname; From 3832dae91b330d953f98f1d534b4e52daf819f2b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Sat, 1 May 2021 14:32:29 +0200 Subject: [PATCH 09/10] rp2040_connect: change pinmux --- main/CommandHandler.cpp | 4 ---- main/sketch.ino.cpp | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index db6e43ba..19b56422 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -1615,11 +1615,7 @@ CommandHandlerClass::CommandHandlerClass() { } -#if defined(NANO_RP2040_CONNECT) -static const int GPIO_IRQ = 26; -#else static const int GPIO_IRQ = 0; -#endif void CommandHandlerClass::begin() { diff --git a/main/sketch.ino.cpp b/main/sketch.ino.cpp index 6fe4367b..e304c498 100644 --- a/main/sketch.ino.cpp +++ b/main/sketch.ino.cpp @@ -118,8 +118,10 @@ void setupBluetooth() { periph_module_enable(PERIPH_UART1_MODULE); periph_module_enable(PERIPH_UHCI0_MODULE); -#if defined(UNO_WIFI_REV2) || defined(NANO_RP2040_CONNECT) +#if defined(UNO_WIFI_REV2) uart_set_pin(UART_NUM_1, 1, 3, 33, 0); // TX, RX, RTS, CTS +#elif defined(NANO_RP2040_CONNECT) + uart_set_pin(UART_NUM_1, 1, 3, 33, 12); // TX, RX, RTS, CTS #else uart_set_pin(UART_NUM_1, 23, 12, 18, 5); #endif From 8713b0938d15fb7c1dc85671b52438e36ef55cc9 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Sat, 1 May 2021 14:33:06 +0200 Subject: [PATCH 10/10] Release 1.4.5 --- main/CommandHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/CommandHandler.cpp b/main/CommandHandler.cpp index cb1a225d..4fa3d656 100644 --- a/main/CommandHandler.cpp +++ b/main/CommandHandler.cpp @@ -36,7 +36,7 @@ #include "esp_log.h" -const char FIRMWARE_VERSION[6] = "1.4.4"; +const char FIRMWARE_VERSION[6] = "1.4.5"; /*IPAddress*/uint32_t resolvedHostname;