Browse Source

esp32: enable input on both UART and USB

Enable data read on both UART and USB -- will be used to enable FPGA
firmware upload.
H. Peter Anvin 2 years ago
parent
commit
15629011c5
4 changed files with 40 additions and 5 deletions
  1. 40 5
      esp32/max80/max80.ino
  2. BIN
      esp32/output/max80.ino.bin
  3. BIN
      fpga/output/v1.fw
  4. BIN
      fpga/output/v2.fw

+ 40 - 5
esp32/max80/max80.ino

@@ -14,6 +14,24 @@
 #include <esp_task_wdt.h>
 #include <esp_mac.h>
 #include <USB.h>
+#include <HardwareSerial.h>
+
+static void Read_Echo(Stream &from)
+{
+    int byte;
+
+    while ((byte = from.read()) >= 0)
+	from.write(byte);
+}
+
+static void onrx_usb(void *foo, const char *bar, int baz, void *quux)
+{
+    Read_Echo(Serial);
+}
+static void onrx_uart(void)
+{
+    Read_Echo(Serial0);
+}
 
 #define PIN_USB_PWR_EN		7
 #define PIN_USB_PWR_SINK	8
@@ -48,6 +66,9 @@ uint8_t max80_board_version;
 
 static void init_hw()
 {
+    Serial0.begin(115200);
+    Serial0.onReceive(onrx_uart, false);
+
     // Start out with disabled shared I/O pins
     for (int i = 1; i <= 18; i++)
 	pinMode(i, INPUT);
@@ -76,6 +97,9 @@ static void init_hw()
 
     pinMode(PIN_USB_PWR_EN, OUTPUT);
     digitalWrite(PIN_USB_PWR_EN, 0);
+    delayMicroseconds(50);
+
+    Serial.onEvent(ARDUINO_USB_CDC_RX_EVENT, onrx_usb);
 
     // Configure LEDs
     led_init();
@@ -92,15 +116,21 @@ void setup() {
     const char *fwdate = __DATE__ " " __TIME__;
     printf("[START] MAX80 firmware compiled on %s\n", fwdate);
     init_hw();
+    Serial.println("MAX80 start");
     fpga_service_init();
+    Serial.println("0.2");
     init_config();
+    Serial.println("0.3");
     setenv_cond("status.max80.fw.date", fwdate);
     fpga_service_enable(true);
+    Serial.println("0.4");
     SetupWiFi();
+    Serial.println("0.5");
     printf("[RDY]\n");
     dump_config();
     led_set(LED_BLUE, LED_ON);	// Software ready
 
+    Serial.println("0.5");
     printf("Total heap:  %d\n"
 	   "Free heap:   %d\n"
 	   "Total PSRAM: %d\n"
@@ -145,12 +175,17 @@ static void dump_tasks(void)
 }
 
 void loop() {
-    printf("loop task: %s\n", pcTaskGetName(xTaskGetCurrentTaskHandle()));
-    printf("idle task: %s\n", pcTaskGetName(xTaskGetIdleTaskHandle()));
+    static int x = 0;
+
+    if (0) {
+	printf("loop task: %s\n", pcTaskGetName(xTaskGetCurrentTaskHandle()));
+	printf("idle task: %s\n", pcTaskGetName(xTaskGetIdleTaskHandle()));
 
-    dump_tasks();
+	dump_tasks();
 
-    putchar('\n');
+	putchar('\n');
+    }
 
-    vTaskDelay(120 * configTICK_RATE_HZ);
+    Serial.println(++x);
+    vTaskDelay(2 * configTICK_RATE_HZ);
 }

BIN
esp32/output/max80.ino.bin


BIN
fpga/output/v1.fw


BIN
fpga/output/v2.fw