Unverified Commit a9b24827 authored by Pontus Oldberg's avatar Pontus Oldberg Committed by GitHub

Updated PID for WiFi/BLE board and other changes (#595)

parent fc55e1e7
...@@ -7449,8 +7449,8 @@ challenger_2040_ltepicodebug.menu.usbstack.nousb.build.usbstack_flags="-DNO_USB ...@@ -7449,8 +7449,8 @@ challenger_2040_ltepicodebug.menu.usbstack.nousb.build.usbstack_flags="-DNO_USB
# ----------------------------------- # -----------------------------------
challenger_2040_wifi_ble.name=iLabs Challenger 2040 WiFi/BLE challenger_2040_wifi_ble.name=iLabs Challenger 2040 WiFi/BLE
challenger_2040_wifi_ble.vid.0=0x2e8a challenger_2040_wifi_ble.vid.0=0x2e8a
challenger_2040_wifi_ble.pid.0=0x1101 challenger_2040_wifi_ble.pid.0=0x102C
challenger_2040_wifi_ble.build.usbpid=-DSERIALUSB_PID=0x1101 challenger_2040_wifi_ble.build.usbpid=-DSERIALUSB_PID=0x102C
challenger_2040_wifi_ble.build.usbpwr=-DUSBD_MAX_POWER_MA=500 challenger_2040_wifi_ble.build.usbpwr=-DUSBD_MAX_POWER_MA=500
challenger_2040_wifi_ble.build.board=CHALLENGER_2040_WIFI_BLE_RP2040 challenger_2040_wifi_ble.build.board=CHALLENGER_2040_WIFI_BLE_RP2040
challenger_2040_wifi_ble.build.mcu=cortex-m0plus challenger_2040_wifi_ble.build.mcu=cortex-m0plus
...@@ -7469,7 +7469,7 @@ challenger_2040_wifi_ble.build.ldscript=memmap_default.ld ...@@ -7469,7 +7469,7 @@ challenger_2040_wifi_ble.build.ldscript=memmap_default.ld
challenger_2040_wifi_ble.build.ram_length=256k challenger_2040_wifi_ble.build.ram_length=256k
challenger_2040_wifi_ble.build.boot2=boot2_w25q080_2_padded_checksum challenger_2040_wifi_ble.build.boot2=boot2_w25q080_2_padded_checksum
challenger_2040_wifi_ble.build.vid=0x2e8a challenger_2040_wifi_ble.build.vid=0x2e8a
challenger_2040_wifi_ble.build.pid=0x1101 challenger_2040_wifi_ble.build.pid=0x102C
challenger_2040_wifi_ble.build.usb_manufacturer="iLabs" challenger_2040_wifi_ble.build.usb_manufacturer="iLabs"
challenger_2040_wifi_ble.build.usb_product="Challenger 2040 WiFi/BLE" challenger_2040_wifi_ble.build.usb_product="Challenger 2040 WiFi/BLE"
challenger_2040_wifi_ble.menu.flash.8388608_0=8MB (no FS) challenger_2040_wifi_ble.menu.flash.8388608_0=8MB (no FS)
...@@ -7613,7 +7613,7 @@ challenger_2040_wifi_ble.menu.usbstack.tinyusb.build.usbstack_flags=-DUSE_TINYUS ...@@ -7613,7 +7613,7 @@ challenger_2040_wifi_ble.menu.usbstack.tinyusb.build.usbstack_flags=-DUSE_TINYUS
challenger_2040_wifi_blepicoprobe.name=iLabs Challenger 2040 WiFi/BLE (Picoprobe) challenger_2040_wifi_blepicoprobe.name=iLabs Challenger 2040 WiFi/BLE (Picoprobe)
challenger_2040_wifi_blepicoprobe.vid.0=0x2e8a challenger_2040_wifi_blepicoprobe.vid.0=0x2e8a
challenger_2040_wifi_blepicoprobe.pid.0=0x0004 challenger_2040_wifi_blepicoprobe.pid.0=0x0004
challenger_2040_wifi_blepicoprobe.build.usbpid=-DSERIALUSB_PID=0x1101 challenger_2040_wifi_blepicoprobe.build.usbpid=-DSERIALUSB_PID=0x102C
challenger_2040_wifi_blepicoprobe.build.usbpwr=-DUSBD_MAX_POWER_MA=500 challenger_2040_wifi_blepicoprobe.build.usbpwr=-DUSBD_MAX_POWER_MA=500
challenger_2040_wifi_blepicoprobe.build.board=CHALLENGER_2040_WIFI_BLE_RP2040 challenger_2040_wifi_blepicoprobe.build.board=CHALLENGER_2040_WIFI_BLE_RP2040
challenger_2040_wifi_blepicoprobe.build.mcu=cortex-m0plus challenger_2040_wifi_blepicoprobe.build.mcu=cortex-m0plus
...@@ -7632,7 +7632,7 @@ challenger_2040_wifi_blepicoprobe.build.ldscript=memmap_default.ld ...@@ -7632,7 +7632,7 @@ challenger_2040_wifi_blepicoprobe.build.ldscript=memmap_default.ld
challenger_2040_wifi_blepicoprobe.build.ram_length=256k challenger_2040_wifi_blepicoprobe.build.ram_length=256k
challenger_2040_wifi_blepicoprobe.build.boot2=boot2_w25q080_2_padded_checksum challenger_2040_wifi_blepicoprobe.build.boot2=boot2_w25q080_2_padded_checksum
challenger_2040_wifi_blepicoprobe.build.vid=0x2e8a challenger_2040_wifi_blepicoprobe.build.vid=0x2e8a
challenger_2040_wifi_blepicoprobe.build.pid=0x1101 challenger_2040_wifi_blepicoprobe.build.pid=0x102C
challenger_2040_wifi_blepicoprobe.build.usb_manufacturer="iLabs" challenger_2040_wifi_blepicoprobe.build.usb_manufacturer="iLabs"
challenger_2040_wifi_blepicoprobe.build.usb_product="Challenger 2040 WiFi/BLE (Picoprobe)" challenger_2040_wifi_blepicoprobe.build.usb_product="Challenger 2040 WiFi/BLE (Picoprobe)"
challenger_2040_wifi_blepicoprobe.menu.flash.8388608_0=8MB (no FS) challenger_2040_wifi_blepicoprobe.menu.flash.8388608_0=8MB (no FS)
...@@ -7776,7 +7776,7 @@ challenger_2040_wifi_blepicoprobe.menu.usbstack.tinyusb.build.usbstack_flags=-DU ...@@ -7776,7 +7776,7 @@ challenger_2040_wifi_blepicoprobe.menu.usbstack.tinyusb.build.usbstack_flags=-DU
challenger_2040_wifi_blepicodebug.name=iLabs Challenger 2040 WiFi/BLE (pico-debug) challenger_2040_wifi_blepicodebug.name=iLabs Challenger 2040 WiFi/BLE (pico-debug)
challenger_2040_wifi_blepicodebug.vid.0=0x1209 challenger_2040_wifi_blepicodebug.vid.0=0x1209
challenger_2040_wifi_blepicodebug.pid.0=0x2488 challenger_2040_wifi_blepicodebug.pid.0=0x2488
challenger_2040_wifi_blepicodebug.build.usbpid=-DSERIALUSB_PID=0x1101 challenger_2040_wifi_blepicodebug.build.usbpid=-DSERIALUSB_PID=0x102C
challenger_2040_wifi_blepicodebug.build.usbpwr=-DUSBD_MAX_POWER_MA=500 challenger_2040_wifi_blepicodebug.build.usbpwr=-DUSBD_MAX_POWER_MA=500
challenger_2040_wifi_blepicodebug.build.board=CHALLENGER_2040_WIFI_BLE_RP2040 challenger_2040_wifi_blepicodebug.build.board=CHALLENGER_2040_WIFI_BLE_RP2040
challenger_2040_wifi_blepicodebug.build.mcu=cortex-m0plus challenger_2040_wifi_blepicodebug.build.mcu=cortex-m0plus
...@@ -7795,7 +7795,7 @@ challenger_2040_wifi_blepicodebug.build.ldscript=memmap_default.ld ...@@ -7795,7 +7795,7 @@ challenger_2040_wifi_blepicodebug.build.ldscript=memmap_default.ld
challenger_2040_wifi_blepicodebug.build.ram_length=240k challenger_2040_wifi_blepicodebug.build.ram_length=240k
challenger_2040_wifi_blepicodebug.build.boot2=boot2_w25q080_2_padded_checksum challenger_2040_wifi_blepicodebug.build.boot2=boot2_w25q080_2_padded_checksum
challenger_2040_wifi_blepicodebug.build.vid=0x2e8a challenger_2040_wifi_blepicodebug.build.vid=0x2e8a
challenger_2040_wifi_blepicodebug.build.pid=0x1101 challenger_2040_wifi_blepicodebug.build.pid=0x102C
challenger_2040_wifi_blepicodebug.build.usb_manufacturer="iLabs" challenger_2040_wifi_blepicodebug.build.usb_manufacturer="iLabs"
challenger_2040_wifi_blepicodebug.build.usb_product="Challenger 2040 WiFi/BLE (pico-debug)" challenger_2040_wifi_blepicodebug.build.usb_product="Challenger 2040 WiFi/BLE (pico-debug)"
challenger_2040_wifi_blepicodebug.menu.flash.8388608_0=8MB (no FS) challenger_2040_wifi_blepicodebug.menu.flash.8388608_0=8MB (no FS)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"variant": "challenger_2040_wifi_ble", "variant": "challenger_2040_wifi_ble",
"boot2_source": "boot2_w25q080_2_padded_checksum.S", "boot2_source": "boot2_w25q080_2_padded_checksum.S",
"usb_vid": "0x2e8a", "usb_vid": "0x2e8a",
"usb_pid": "0x1101", "usb_pid": "0x102C",
"usb_manufacturer": "iLabs", "usb_manufacturer": "iLabs",
"usb_product": "Challenger 2040 WiFi/BLE" "usb_product": "Challenger 2040 WiFi/BLE"
} }
......
...@@ -251,7 +251,7 @@ MakeBoard("dfrobot_beetle_rp2040", "DFRobot", "Beetle RP2040", "0x3343", "0x4253 ...@@ -251,7 +251,7 @@ MakeBoard("dfrobot_beetle_rp2040", "DFRobot", "Beetle RP2040", "0x3343", "0x4253
MakeBoard("challenger_2040_lora", "iLabs", "Challenger 2040 LoRa", "0x2e8a", "0x1023", 250, "CHALLENGER_2040_LORA_RP2040", 8, "boot2_w25q080_2_padded_checksum") MakeBoard("challenger_2040_lora", "iLabs", "Challenger 2040 LoRa", "0x2e8a", "0x1023", 250, "CHALLENGER_2040_LORA_RP2040", 8, "boot2_w25q080_2_padded_checksum")
MakeBoard("challenger_2040_wifi", "iLabs", "Challenger 2040 WiFi", "0x2e8a", "0x1006", 250, "CHALLENGER_2040_WIFI_RP2040", 8, "boot2_w25q080_2_padded_checksum") MakeBoard("challenger_2040_wifi", "iLabs", "Challenger 2040 WiFi", "0x2e8a", "0x1006", 250, "CHALLENGER_2040_WIFI_RP2040", 8, "boot2_w25q080_2_padded_checksum")
MakeBoard("challenger_2040_lte", "iLabs", "Challenger 2040 LTE", "0x2e8a", "0x100b", 500, "CHALLENGER_2040_LTE_RP2040", 8, "boot2_w25q080_2_padded_checksum") MakeBoard("challenger_2040_lte", "iLabs", "Challenger 2040 LTE", "0x2e8a", "0x100b", 500, "CHALLENGER_2040_LTE_RP2040", 8, "boot2_w25q080_2_padded_checksum")
MakeBoard("challenger_2040_wifi_ble", "iLabs", "Challenger 2040 WiFi/BLE", "0x2e8a", "0x1101", 500, "CHALLENGER_2040_WIFI_BLE_RP2040", 8, "boot2_w25q080_2_padded_checksum") MakeBoard("challenger_2040_wifi_ble", "iLabs", "Challenger 2040 WiFi/BLE", "0x2e8a", "0x102C", 500, "CHALLENGER_2040_WIFI_BLE_RP2040", 8, "boot2_w25q080_2_padded_checksum")
MakeBoard("challenger_nb_2040_wifi", "iLabs", "Challenger NB 2040 WiFi", "0x2e8a", "0x100b", 500, "CHALLENGER_NB_2040_WIFI_RP2040", 8, "boot2_w25q080_2_padded_checksum") MakeBoard("challenger_nb_2040_wifi", "iLabs", "Challenger NB 2040 WiFi", "0x2e8a", "0x100b", 500, "CHALLENGER_NB_2040_WIFI_RP2040", 8, "boot2_w25q080_2_padded_checksum")
MakeBoard("ilabs_rpico32", "iLabs", "RPICO32", "0x2e8a", "0x1010", 250, "ILABS_2040_RPICO32_RP2040", 8, "boot2_w25q080_2_padded_checksum") MakeBoard("ilabs_rpico32", "iLabs", "RPICO32", "0x2e8a", "0x1010", 250, "ILABS_2040_RPICO32_RP2040", 8, "boot2_w25q080_2_padded_checksum")
......
/* /*
ESP8285 helper class for the Challenger RP2040 WiFi boards ESP8285/ESP32C3 helper class for the Challenger RP2040 WiFi enabled boards
Copyright (c) 2021 P. Oldberg <pontus@ilabs.se> Copyright (c) 2021,2022 P. Oldberg <pontus@ilabs.se>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
...@@ -21,31 +21,33 @@ ...@@ -21,31 +21,33 @@
#include <Arduino.h> #include <Arduino.h>
#include <ChallengerWiFi.h> #include <ChallengerWiFi.h>
Challenger2040WiFiClass::Challenger2040WiFiClass() { Challenger2040WiFiClass::Challenger2040WiFiClass(HardwareSerial* serial) {
pinMode(PIN_ESP8285_RST, OUTPUT); _serial = serial;
digitalWrite(PIN_ESP8285_RST, LOW); // Hold ESP8285 in reset
pinMode(PIN_ESP8285_MODE, OUTPUT); pinMode(PIN_ESP_RST, OUTPUT);
digitalWrite(PIN_ESP8285_MODE, HIGH); // Prepare for normal start digitalWrite(PIN_ESP_RST, LOW); // Hold ESP in reset
pinMode(PIN_ESP_MODE, OUTPUT);
digitalWrite(PIN_ESP_MODE, HIGH); // Prepare for normal start
} }
// Do a HW reset by applying a low pulse to the reset line for 1mSec // Do a HW reset by applying a low pulse to the reset line for 1mSec
void Challenger2040WiFiClass::doHWReset() { void Challenger2040WiFiClass::doHWReset() {
digitalWrite(PIN_ESP8285_RST, LOW); // Hold ESP8285 in reset digitalWrite(PIN_ESP_RST, LOW); // Hold ESP in reset
delay(1); delay(1);
digitalWrite(PIN_ESP8285_RST, HIGH); // Release ESP8285 reset digitalWrite(PIN_ESP_RST, HIGH); // Release ESP reset
} }
// Set the mode flag high to indicate normal run operation and do a HW // Set the mode flag high to indicate normal run operation and do a HW
// reset. // reset.
void Challenger2040WiFiClass::runReset() { // Prepare ESP8285 for normal op void Challenger2040WiFiClass::runReset() { // Prepare ESP for normal op
digitalWrite(PIN_ESP8285_MODE, HIGH); // Prepare for normal start digitalWrite(PIN_ESP_MODE, HIGH); // Prepare for normal start
doHWReset(); doHWReset();
} }
// Set the mode flag low to indicate flash operation and do a HW // Set the mode flag low to indicate flash operation and do a HW
// reset. // reset.
void Challenger2040WiFiClass::flashReset() { // Prepare ESP8285 for flashing void Challenger2040WiFiClass::flashReset() { // Prepare ESP for flashing
digitalWrite(PIN_ESP8285_MODE, LOW); // Prepare for normal start digitalWrite(PIN_ESP_MODE, LOW); // Prepare for normal start
doHWReset(); doHWReset();
} }
...@@ -55,53 +57,82 @@ void Challenger2040WiFiClass::flashReset() { // Prepare ESP8285 for flashing ...@@ -55,53 +57,82 @@ void Challenger2040WiFiClass::flashReset() { // Prepare ESP8285 for flashing
bool Challenger2040WiFiClass::waitForReady() { bool Challenger2040WiFiClass::waitForReady() {
int timeout = 20; // Aprox max 2 sec int timeout = 20; // Aprox max 2 sec
Serial2.begin(DEFAULT_ESP8285_BAUDRATE); _serial->setTimeout(100);
Serial2.setTimeout(100); String rdy = _serial->readStringUntil('\n');
String rdy = Serial2.readStringUntil('\n');
while(!rdy.startsWith("ready") && timeout--) { while(!rdy.startsWith("ready") && timeout--) {
rdy = Serial2.readStringUntil('\n'); rdy = _serial->readStringUntil('\n');
} }
Serial2.setTimeout(1000); // Reset default timeout to 1000 _serial->setTimeout(1000); // Reset default timeout to 1000
if (timeout) if (timeout)
return true; return true;
return false; return false;
} }
// Reset the ESP8285 and wait for the "ready" prompt to be returned. // Reset the ESP and wait for the "ready" prompt to be returned.
bool Challenger2040WiFiClass::reset() { bool Challenger2040WiFiClass::reset() {
runReset(); runReset();
_serial->begin(DEFAULT_ESP_BAUDRATE);
return waitForReady(); return waitForReady();
} }
// Checks to see if the modem responds to the "AT" poll command. // Checks to see if the modem responds to the "AT" poll command.
bool Challenger2040WiFiClass::isAlive() { bool Challenger2040WiFiClass::isAlive() {
int timeout = 5; int timeout = 100;
Serial2.setTimeout(250); _serial->setTimeout(250);
Serial2.println(F("AT")); _serial->println(F("AT"));
String rdy = Serial2.readStringUntil('\n'); String rdy = _serial->readStringUntil('\n');
while(!rdy.startsWith(F("OK")) && timeout--) { while(!rdy.startsWith(F("OK")) && timeout--) {
rdy = Serial2.readStringUntil('\n'); _serial->println(F("AT"));
rdy = _serial->readStringUntil('\n');
} }
Serial2.setTimeout(1000); _serial->setTimeout(1000);
if (timeout) if (timeout)
return true; return true;
return false; return false;
} }
// Change the baud rate of the ESP8285 as well as the local UART. // Change the baud rate of the ESP device as well as the local UART.
// No checking is done on the input baud rate so the user must know what // No checking is done on the input baud rate so the user must know what
// baud rates are valid. The function ends by checking if the ESP8285 is // baud rates are valid. The function ends by checking if the ESP is
// reachable by doing an "AT" poll. // reachable by doing an "AT" poll.
bool Challenger2040WiFiClass::changeBaudRate(int baud) { bool Challenger2040WiFiClass::changeBaudRate(int baud) {
Serial2.print(F("AT+UART_CUR=")); _serial->print(F("AT+UART_CUR="));
Serial2.print(baud); _serial->print(baud);
Serial2.println(F(",8,1,0,0")); _serial->println(F(",8,1,0,0"));
delay(100); delay(100);
Serial2.end(); _serial->end();
Serial2.begin(baud); _serial->begin(baud);
return isAlive(); return isAlive();
} }
// This method should be called id the builtin object isn't needed any more
// It basically just releases the UART pins for other use.
void Challenger2040WiFiClass::release() {
_serial->end();
}
// We can assign a new hardware serial port to accommodate the ESP device here.
// The function will release the previously used serial port and assign the
// new port. The ESP will be left in a reset state ready to start normal
// operation when exiting the function.
// This function is useful for when using the PIO serial ports to communicate
// with the ESP instead of the built in hardware serial port.
void Challenger2040WiFiClass::setSerial(HardwareSerial* serial) {
release();
_serial = serial;
pinMode(PIN_ESP_RST, OUTPUT);
digitalWrite(PIN_ESP_RST, LOW); // Hold ESP in reset
pinMode(PIN_ESP_MODE, OUTPUT);
digitalWrite(PIN_ESP_MODE, HIGH); // Prepare for normal start
}
// Return the current serial object
HardwareSerial* Challenger2040WiFiClass::getSerial() {
return _serial;
}
Challenger2040WiFiClass Challenger2040WiFi; Challenger2040WiFiClass Challenger2040WiFi;
/* /*
ESP8285 helper class for the Challenger RP2040 WiFi boards ESP8285/ESP32C3 helper class for the Challenger RP2040 WiFi enabled boards
Copyright (c) 2021 P. Oldberg <pontus@ilabs.se> Copyright (c) 2021,2022 P. Oldberg <pontus@ilabs.se>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
...@@ -17,20 +17,27 @@ ...@@ -17,20 +17,27 @@
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#pragma once #pragma once
#define DEFAULT_ESP8285_BAUDRATE 115200 #define DEFAULT_ESP32_BAUDRATE 115200
#define DEFAULT_ESP_BAUDRATE DEFAULT_ESP32_BAUDRATE
class Challenger2040WiFiClass { class Challenger2040WiFiClass {
public: public:
Challenger2040WiFiClass(); Challenger2040WiFiClass(HardwareSerial* = &ESP_SERIAL_PORT);
void doHWReset(); void doHWReset();
void runReset(); void runReset();
void flashReset(); void flashReset();
bool waitForReady(); bool waitForReady();
bool reset(); bool reset();
bool isAlive(); bool isAlive();
bool changeBaudRate(int baud); bool changeBaudRate(int);
void release();
void setSerial(HardwareSerial*);
HardwareSerial* getSerial();
private:
HardwareSerial* _serial;
}; };
extern Challenger2040WiFiClass Challenger2040WiFi; extern Challenger2040WiFiClass Challenger2040WiFi;
...@@ -18,6 +18,13 @@ ...@@ -18,6 +18,13 @@
#define PIN_SERIAL2_RX (5u) #define PIN_SERIAL2_RX (5u)
#define PIN_ESP8285_RST (19u) #define PIN_ESP8285_RST (19u)
#define PIN_ESP8285_MODE (13u) #define PIN_ESP8285_MODE (13u)
#define ESP8285_SERIAL Serial2
// Uart define esp serial abstraction pins
#define PIN_ESP_TX PIN_SERIAL2_TX
#define PIN_ESP_RX PIN_SERIAL2_RX
#define PIN_ESP_RST PIN_ESP8285_RST
#define PIN_ESP_MODE PIN_ESP8285_MODE
#define ESP_SERIAL_PORT ESP8285_SERIAL
// SPI // SPI
#define PIN_SPI0_MISO (24u) #define PIN_SPI0_MISO (24u)
......
/* /*
ESP32 helper class for the Challenger RP2040 WiFi boards ESP8285/ESP32C3 helper class for the Challenger RP2040 WiFi enabled boards
Copyright (c) 2021 P. Oldberg <pontus@ilabs.se> Copyright (c) 2021,2022 P. Oldberg <pontus@ilabs.se>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
...@@ -21,31 +21,33 @@ ...@@ -21,31 +21,33 @@
#include <Arduino.h> #include <Arduino.h>
#include <ChallengerWiFi.h> #include <ChallengerWiFi.h>
Challenger2040WiFiClass::Challenger2040WiFiClass() { Challenger2040WiFiClass::Challenger2040WiFiClass(HardwareSerial* serial) {
pinMode(PIN_ESP32_RST, OUTPUT); _serial = serial;
digitalWrite(PIN_ESP32_RST, LOW); // Hold ESP32 in reset
pinMode(PIN_ESP32_MODE, OUTPUT); pinMode(PIN_ESP_RST, OUTPUT);
digitalWrite(PIN_ESP32_MODE, HIGH); // Prepare for normal start digitalWrite(PIN_ESP_RST, LOW); // Hold ESP in reset
pinMode(PIN_ESP_MODE, OUTPUT);
digitalWrite(PIN_ESP_MODE, HIGH); // Prepare for normal start
} }
// Do a HW reset by applying a low pulse to the reset line for 1mSec // Do a HW reset by applying a low pulse to the reset line for 1mSec
void Challenger2040WiFiClass::doHWReset() { void Challenger2040WiFiClass::doHWReset() {
digitalWrite(PIN_ESP32_RST, LOW); // Hold ESP32 in reset digitalWrite(PIN_ESP_RST, LOW); // Hold ESP in reset
delay(1); delay(1);
digitalWrite(PIN_ESP32_RST, HIGH); // Release ESP32 reset digitalWrite(PIN_ESP_RST, HIGH); // Release ESP reset
} }
// Set the mode flag high to indicate normal run operation and do a HW // Set the mode flag high to indicate normal run operation and do a HW
// reset. // reset.
void Challenger2040WiFiClass::runReset() { // Prepare ESP32 for normal op void Challenger2040WiFiClass::runReset() { // Prepare ESP for normal op
digitalWrite(PIN_ESP32_MODE, HIGH); // Prepare for normal start digitalWrite(PIN_ESP_MODE, HIGH); // Prepare for normal start
doHWReset(); doHWReset();
} }
// Set the mode flag low to indicate flash operation and do a HW // Set the mode flag low to indicate flash operation and do a HW
// reset. // reset.
void Challenger2040WiFiClass::flashReset() { // Prepare ESP32 for flashing void Challenger2040WiFiClass::flashReset() { // Prepare ESP for flashing
digitalWrite(PIN_ESP32_MODE, LOW); // Prepare for normal start digitalWrite(PIN_ESP_MODE, LOW); // Prepare for normal start
doHWReset(); doHWReset();
} }
...@@ -55,53 +57,82 @@ void Challenger2040WiFiClass::flashReset() { // Prepare ESP32 for flashing ...@@ -55,53 +57,82 @@ void Challenger2040WiFiClass::flashReset() { // Prepare ESP32 for flashing
bool Challenger2040WiFiClass::waitForReady() { bool Challenger2040WiFiClass::waitForReady() {
int timeout = 20; // Aprox max 2 sec int timeout = 20; // Aprox max 2 sec
Serial2.begin(DEFAULT_ESP32_BAUDRATE); _serial->setTimeout(100);
Serial2.setTimeout(100); String rdy = _serial->readStringUntil('\n');
String rdy = Serial2.readStringUntil('\n');
while(!rdy.startsWith("ready") && timeout--) { while(!rdy.startsWith("ready") && timeout--) {
rdy = Serial2.readStringUntil('\n'); rdy = _serial->readStringUntil('\n');
} }
Serial2.setTimeout(1000); // Reset default timeout to 1000 _serial->setTimeout(1000); // Reset default timeout to 1000
if (timeout) if (timeout)
return true; return true;
return false; return false;
} }
// Reset the ESP32 and wait for the "ready" prompt to be returned. // Reset the ESP and wait for the "ready" prompt to be returned.
bool Challenger2040WiFiClass::reset() { bool Challenger2040WiFiClass::reset() {
runReset(); runReset();
_serial->begin(DEFAULT_ESP_BAUDRATE);
return waitForReady(); return waitForReady();
} }
// Checks to see if the modem responds to the "AT" poll command. // Checks to see if the modem responds to the "AT" poll command.
bool Challenger2040WiFiClass::isAlive() { bool Challenger2040WiFiClass::isAlive() {
int timeout = 5; int timeout = 100;
Serial2.setTimeout(250); _serial->setTimeout(250);
Serial2.println(F("AT")); _serial->println(F("AT"));
String rdy = Serial2.readStringUntil('\n'); String rdy = _serial->readStringUntil('\n');
while(!rdy.startsWith(F("OK")) && timeout--) { while(!rdy.startsWith(F("OK")) && timeout--) {
rdy = Serial2.readStringUntil('\n'); _serial->println(F("AT"));
rdy = _serial->readStringUntil('\n');
} }
Serial2.setTimeout(1000); _serial->setTimeout(1000);
if (timeout) if (timeout)
return true; return true;
return false; return false;
} }
// Change the baud rate of the ESP32 as well as the local UART. // Change the baud rate of the ESP device as well as the local UART.
// No checking is done on the input baud rate so the user must know what // No checking is done on the input baud rate so the user must know what
// baud rates are valid. The function ends by checking if the ESP32 is // baud rates are valid. The function ends by checking if the ESP is
// reachable by doing an "AT" poll. // reachable by doing an "AT" poll.
bool Challenger2040WiFiClass::changeBaudRate(int baud) { bool Challenger2040WiFiClass::changeBaudRate(int baud) {
Serial2.print(F("AT+UART_CUR=")); _serial->print(F("AT+UART_CUR="));
Serial2.print(baud); _serial->print(baud);
Serial2.println(F(",8,1,0,0")); _serial->println(F(",8,1,0,0"));
delay(100); delay(100);
Serial2.end(); _serial->end();
Serial2.begin(baud); _serial->begin(baud);
return isAlive(); return isAlive();
} }
// This method should be called id the builtin object isn't needed any more
// It basically just releases the UART pins for other use.
void Challenger2040WiFiClass::release() {
_serial->end();
}
// We can assign a new hardware serial port to accommodate the ESP device here.
// The function will release the previously used serial port and assign the
// new port. The ESP will be left in a reset state ready to start normal
// operation when exiting the function.
// This function is useful for when using the PIO serial ports to communicate
// with the ESP instead of the built in hardware serial port.
void Challenger2040WiFiClass::setSerial(HardwareSerial* serial) {
release();
_serial = serial;
pinMode(PIN_ESP_RST, OUTPUT);
digitalWrite(PIN_ESP_RST, LOW); // Hold ESP in reset
pinMode(PIN_ESP_MODE, OUTPUT);
digitalWrite(PIN_ESP_MODE, HIGH); // Prepare for normal start
}
// Return the current serial object
HardwareSerial* Challenger2040WiFiClass::getSerial() {
return _serial;
}
Challenger2040WiFiClass Challenger2040WiFi; Challenger2040WiFiClass Challenger2040WiFi;
/* /*
ESP8285 helper class for the Challenger RP2040 WiFi boards ESP8285/ESP32C3 helper class for the Challenger RP2040 WiFi enabled boards
Copyright (c) 2021 P. Oldberg <pontus@ilabs.se> Copyright (c) 2021,2022 P. Oldberg <pontus@ilabs.se>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
...@@ -17,20 +17,27 @@ ...@@ -17,20 +17,27 @@
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#pragma once #pragma once
#define DEFAULT_ESP32_BAUDRATE 115200 #define DEFAULT_ESP32_BAUDRATE 115200
#define DEFAULT_ESP_BAUDRATE DEFAULT_ESP32_BAUDRATE
class Challenger2040WiFiClass { class Challenger2040WiFiClass {
public: public:
Challenger2040WiFiClass(); Challenger2040WiFiClass(HardwareSerial* = &ESP_SERIAL_PORT);
void doHWReset(); void doHWReset();
void runReset(); void runReset();
void flashReset(); void flashReset();
bool waitForReady(); bool waitForReady();
bool reset(); bool reset();
bool isAlive(); bool isAlive();
bool changeBaudRate(int baud); bool changeBaudRate(int);
void release();
void setSerial(HardwareSerial*);
HardwareSerial* getSerial();
private:
HardwareSerial* _serial;
}; };
extern Challenger2040WiFiClass Challenger2040WiFi; extern Challenger2040WiFiClass Challenger2040WiFi;
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
#define PIN_SERIAL2_RX (5u) #define PIN_SERIAL2_RX (5u)
#define PIN_ESP32_RST (19u) #define PIN_ESP32_RST (19u)
#define PIN_ESP32_MODE (24u) #define PIN_ESP32_MODE (24u)
#define ESP32_SERIAL 1 #define ESP32_SERIAL Serial2
// Uart define esp serial abstraction pins
#define PIN_ESP_TX PIN_SERIAL2_TX
#define PIN_ESP_RX PIN_SERIAL2_RX
#define PIN_ESP_RST PIN_ESP32_RST
#define PIN_ESP_MODE PIN_ESP32_MODE
#define ESP_SERIAL_PORT ESP32_SERIAL
// SPI // SPI
#define PIN_SPI0_MISO (24u) #define PIN_SPI0_MISO (24u)
...@@ -33,7 +39,7 @@ ...@@ -33,7 +39,7 @@
#define PIN_SPI1_SS (13u) #define PIN_SPI1_SS (13u)
// Handshake signal from ESP32C3 // Handshake signal from ESP32C3
#define ESP32_HS (18u) #define ESP32_HS (18u)
#define ESP32_SPI 1 #define ESP32_SPI SPI1
// Wire // Wire
#define PIN_WIRE0_SDA (0u) #define PIN_WIRE0_SDA (0u)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment