Преглед изворни кода

Output log over serial USB

Added logging over serial USB to the DaynaPORT target.
Removed the DISABLE_USB macros.
Morio пре 2 година
родитељ
комит
573dc60ca9

+ 33 - 17
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp

@@ -41,9 +41,12 @@
 #  include <platform/mbed_error.h>
 #endif // __MBED__
 
-#ifndef DISABLE_USB
-#  include <USB/PluggableUSBSerial.h>
-#endif // DISABLE_USB
+#ifndef __MBED__
+# include <SerialUSB.h>
+# include <class/cdc/cdc_device.h>
+#else
+# include <USB/PluggableUSBSerial.h>
+#endif // __MBED__
 
 #ifndef ZULUSCSI_NETWORK
 #  include <multicore.h>
@@ -361,6 +364,10 @@ void platform_late_init()
         gpio_conf(SCSI_IN_ATN,    GPIO_FUNC_SIO, true, false, false, true, false);
         gpio_conf(SCSI_IN_RST,    GPIO_FUNC_SIO, true, false, false, true, false);
 
+#ifndef __MBED__
+    Serial.begin();
+#endif // __MBED__
+
 #ifdef ENABLE_AUDIO_OUTPUT
         // one-time control setup for DMA channels and second core
         audio_setup();
@@ -490,11 +497,27 @@ void mbed_error_hook(const mbed_error_ctx * error_context)
 // also starts calling this after 2 seconds.
 // This ensures that log messages get passed even if code hangs,
 // but does not unnecessarily delay normal execution.
-#ifndef DISABLE_USB
 static void usb_log_poll()
 {
     static uint32_t logpos = 0;
-
+#ifndef __MBED__
+    if (Serial.availableForWrite())
+    {
+        // Retrieve pointer to log start and determine number of bytes available.
+        uint32_t available = 0;
+        const char *data = log_get_buffer(&logpos, &available);
+                // Limit to CDC packet size
+        uint32_t len = available;
+        if (len == 0) return;
+        if (len > CFG_TUD_CDC_EP_BUFSIZE) len = CFG_TUD_CDC_EP_BUFSIZE;
+        
+        // Update log position by the actual number of bytes sent
+        // If USB CDC buffer is full, this may be 0
+        uint32_t actual = 0;
+        actual = Serial.write(data, len);
+        logpos -= available - actual;
+    }
+#else
     if (_SerialUSB.ready())
     {
         // Retrieve pointer to log start and determine number of bytes available.
@@ -512,8 +535,9 @@ static void usb_log_poll()
         _SerialUSB.send_nb((uint8_t*)data, len, &actual);
         logpos -= available - actual;
     }
+#endif // __MBED__
 }
-#endif // DISABLE_USB
+
 
 // Use ADC to implement supply voltage monitoring for the +3.0V rail.
 // This works by sampling the temperature sensor channel, which has
@@ -587,13 +611,11 @@ static void watchdog_callback(unsigned alarm_num)
 {
     g_watchdog_timeout -= 1000;
 
-#ifndef DISABLE_USB
     if (g_watchdog_timeout < WATCHDOG_CRASH_TIMEOUT - 1000)
     {
         // Been stuck for at least a second, start dumping USB log
         usb_log_poll();
     }
-#endif  // DISABLE_USB
 
     if (g_watchdog_timeout <= WATCHDOG_CRASH_TIMEOUT - WATCHDOG_BUS_RESET_TIMEOUT)
     {
@@ -640,9 +662,7 @@ static void watchdog_callback(unsigned alarm_num)
                 p += 4;
             }
 
-#ifndef DISABLE_USB
             usb_log_poll();
-#endif // DISABLE_USB
 
             platform_emergency_log_save();
 
@@ -684,19 +704,14 @@ void platform_reset_watchdog()
 
     // USB log is polled here also to make sure any log messages in fault states
     // get passed to USB.
-#ifndef DISABLE_USB
     usb_log_poll();
-#endif // DISABLE_USB
 }
 
 // Poll function that is called every few milliseconds.
 // Can be left empty or used for platform-specific processing.
 void platform_poll()
 {
-#ifndef DISABLE_USB
     usb_log_poll();
-#endif // DISABLE_USB
-
     adc_poll();
     
 #ifdef ENABLE_AUDIO_OUTPUT
@@ -756,14 +771,15 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
         }
     }
 
-#ifndef DISABLE_USB
+
+#ifdef __MBED__
     if (NVIC_GetEnableIRQ(USBCTRL_IRQn))
     {
         logmsg("Disabling USB during firmware flashing");
         NVIC_DisableIRQ(USBCTRL_IRQn);
         usb_hw->main_ctrl = 0;
     }
-#endif // DISABLE_USB
+#endif // __MBED__
 
     dbgmsg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
     assert(offset % PLATFORM_FLASH_PAGE_SIZE == 0);

+ 2 - 3
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.h

@@ -56,9 +56,6 @@ extern const char *g_platform_name;
 # define PLATFORM_REVISION "2.0"
 # define PLATFORM_HAS_INITIATOR_MODE 1
 # define DISABLE_SWO
-# ifdef ZULUSCSI_NETWORK
-#   define DISABLE_USB
-# endif
 #elif defined(ZULUSCSI_BS2)
 # define PLATFORM_NAME "ZuluSCSI BS2"
 # define PLATFORM_REVISION "1.0"
@@ -182,6 +179,8 @@ int platform_network_wifi_channel();
 #ifdef __cplusplus
 }
 
+
+
 // SD card driver for SdFat
 
 #ifdef SD_USE_SDIO

+ 13 - 0
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform_network.cpp

@@ -125,10 +125,23 @@ bool platform_network_wifi_join(char *ssid, char *password)
 		logmsg_f("Connecting to Wi-Fi SSID \"%s\" with WPA/WPA2 PSK", ssid);
 		ret = cyw43_arch_wifi_connect_async(ssid, password, CYW43_AUTH_WPA2_MIXED_PSK);
 	}
+
 	if (ret != 0)
 	{
 		logmsg_f("Wi-Fi connection failed: %d", ret);
 	}
+	else
+	{
+		// Blink 2 times at start of connection sequence
+		LED_OFF();
+		for (uint8_t i = 0; i < 2; i++)
+		{
+			delay(75);
+			LED_ON();
+			delay(75);
+			LED_OFF();
+		}
+	}
 	
 	return (ret == 0);
 }

+ 0 - 1
platformio.ini

@@ -145,7 +145,6 @@ build_flags =
     -DENABLE_DEDICATED_SPI=1
     -DHAS_SDIO_CLASS
     -DUSE_ARDUINO=1
-    -DNO_USB=1
     -DZULUSCSI_PICO
     -DZULUSCSI_NETWORK
     -DZULUSCSI_DAYNAPORT

+ 2 - 2
src/ZuluSCSI_config.h

@@ -28,8 +28,8 @@
 #include <ZuluSCSI_platform.h>
 
 // Use variables for version number
-#define FW_VER_NUM      "23.09.21"
-#define FW_VER_SUFFIX   "devel"
+#define FW_VER_NUM      "23.09.25"
+#define FW_VER_SUFFIX   "wifi-dev"
 #define ZULU_FW_VERSION FW_VER_NUM "-" FW_VER_SUFFIX
 
 // Configuration and log file paths