Usb add serial (#2966)

* [USB Serial] Cleanup serial USB configuration.
* [USB Serial] Add 2nd serial.
* [USB Serial] Add udev symlinks.
* [ChibiOS Mass storage] Change USB stop sequence. (Seems to works better this way)
* [USB Serial] Fix thread blocked when port is not opened.
* [USB Serial] Adapt number of CDC to the number of endpoints.
      STM32F7: 2 serial
      STM32F4: 1 serial
* Mark telemetry_transparent_usb as deprecated.
This commit is contained in:
Fabien-B
2023-02-15 22:04:53 +01:00
committed by GitHub
parent a75f011050
commit 5e2c9e488a
18 changed files with 398 additions and 151 deletions
+4 -2
View File
@@ -3,11 +3,13 @@
<module name="telemetry_transparent" dir="datalink" task="datalink"> <module name="telemetry_transparent" dir="datalink" task="datalink">
<doc> <doc>
<description> <description>
Telemetry using PPRZ protocol over UART Telemetry using PPRZ protocol over UART or USB serial.
Can be used with a UART (uart1, uart2 ...), or a serial over USB: usb_serial, usb_serial_debug.
usb_serial_debug is available only for some MCUs (STM32F7, STM32H7)
Currently used as a makefile wrapper over the telemetry_transparent modules Currently used as a makefile wrapper over the telemetry_transparent modules
</description> </description>
<configure name="MODEM_PORT" value="UARTx" description="UART where the modem is connected to (UART1, UART2, etc)"/> <configure name="MODEM_PORT" value="UARTx" description="UART where the modem is connected to (UART1, UART2, usb_serial, etc)"/>
<configure name="MODEM_BAUD" value="B57600" description="UART baud rate"/> <configure name="MODEM_BAUD" value="B57600" description="UART baud rate"/>
<define name="TELEMETRY_DISABLE_RX" value="FALSE|TRUE" description="disable incoming message parsing"/> <define name="TELEMETRY_DISABLE_RX" value="FALSE|TRUE" description="disable incoming message parsing"/>
</doc> </doc>
+6 -17
View File
@@ -3,29 +3,18 @@
<module name="telemetry_transparent_usb" dir="datalink" task="datalink"> <module name="telemetry_transparent_usb" dir="datalink" task="datalink">
<doc> <doc>
<description> <description>
DEPRECATED: Use telemetry_transparent with configure MODEM_PORT=usb_serial instead.
Telemetry using PPRZ protocol over serial USB (e.g. /dev/ttyACM0) Telemetry using PPRZ protocol over serial USB (e.g. /dev/ttyACM0)
</description> </description>
</doc> </doc>
<dep> <dep>
<depends>datalink_common</depends> <depends>telemetry_transparent</depends>
<provides>datalink,telemetry</provides>
</dep> </dep>
<autoload name="telemetry" type="nps"/>
<autoload name="telemetry" type="sim"/>
<header>
<file name="pprz_dl.h"/>
</header>
<init fun="pprz_dl_init()"/>
<event fun="pprz_dl_event()"/>
<makefile target="!sim|nps|hitl"> <makefile target="!sim|nps|hitl">
<define name="USE_USB_SERIAL"/> <configure name="MODEM_PORT" value="usb_serial"/>
<define name="DOWNLINK_DEVICE" value="usb_serial"/> <raw>
<define name="PPRZ_UART" value="usb_serial"/> $(warning Warning: telemetry_transparent_usb is deprecated. Use telemetry_transparent with configure MODEM_PORT=usb_serial instead.)
<define name="DOWNLINK_TRANSPORT" value="pprz_tp"/> </raw>
<define name="DATALINK" value="PPRZ"/>
<file name="pprz_dl.c"/>
<file name="pprz_transport.c" dir="pprzlink/src"/>
<file_arch name="usb_ser_hw.c" dir="."/>
</makefile> </makefile>
</module> </module>
+3 -2
View File
@@ -9,7 +9,9 @@
To be used with Lisa M/MX 2.1 To be used with Lisa M/MX 2.1
</description> </description>
</doc> </doc>
<dep>
<depends>uart</depends>
</dep>
<header> <header>
<file name="usb_serial_stm32.h"/> <file name="usb_serial_stm32.h"/>
</header> </header>
@@ -18,7 +20,6 @@
<event fun="event_usb_serial()"/> <event fun="event_usb_serial()"/>
<makefile target="!nps|sim"> <makefile target="!nps|sim">
<file_arch name="usb_ser_hw.c" dir=""/>
<define name="USE_USB_SERIAL"/> <define name="USE_USB_SERIAL"/>
<file name="usb_serial_stm32_example1.c"/> <file name="usb_serial_stm32_example1.c"/>
</makefile> </makefile>
@@ -11,6 +11,9 @@ SUBSYSTEM=="tty", ATTRS{interface}=="FLOSS-JTAG", ATTRS{bInterfaceNumber}=="01",
SUBSYSTEM=="tty", ATTRS{interface}=="Black Magic GDB Server", SYMLINK+="bmp-gdb" SUBSYSTEM=="tty", ATTRS{interface}=="Black Magic GDB Server", SYMLINK+="bmp-gdb"
SUBSYSTEM=="tty", ATTRS{interface}=="Black Magic UART Port", SYMLINK+="bmp-serial" SUBSYSTEM=="tty", ATTRS{interface}=="Black Magic UART Port", SYMLINK+="bmp-serial"
SUBSYSTEM=="tty", ATTRS{interface}=="Paparazzi UAV debug Port", SYMLINK+="pprz-dbg"
SUBSYSTEM=="tty", ATTRS{interface}=="Paparazzi UAV telemetry Port", SYMLINK+="pprz-tlm"
# FTDI 3.3V serial cable # FTDI 3.3V serial cable
SUBSYSTEM=="tty", ATTRS{interface}=="TTL232R-3V3", SYMLINK+="ftdi-serial" SUBSYSTEM=="tty", ATTRS{interface}=="TTL232R-3V3", SYMLINK+="ftdi-serial"
+2 -2
View File
@@ -173,7 +173,7 @@
* @brief Enables the SERIAL over USB subsystem. * @brief Enables the SERIAL over USB subsystem.
*/ */
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) #if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define HAL_USE_SERIAL_USB TRUE #define HAL_USE_SERIAL_USB TRUE
#else #else
#define HAL_USE_SERIAL_USB FALSE #define HAL_USE_SERIAL_USB FALSE
@@ -216,7 +216,7 @@
* @brief Enables the USB subsystem. * @brief Enables the USB subsystem.
*/ */
#if !defined(HAL_USE_USB) || defined(__DOXYGEN__) #if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define HAL_USE_USB TRUE #define HAL_USE_USB TRUE
#else #else
#define HAL_USE_USB FALSE #define HAL_USE_USB FALSE
+1
View File
@@ -32,6 +32,7 @@
#define CHIBIOS_MCU_ARCH_H #define CHIBIOS_MCU_ARCH_H
#include "std.h" #include "std.h"
#include <hal.h>
extern void mcu_arch_init(void); extern void mcu_arch_init(void);
File diff suppressed because it is too large Load Diff
@@ -262,7 +262,7 @@
/* /*
* USB driver system settings. * USB driver system settings.
*/ */
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define STM32_USB_USE_OTG1 TRUE #define STM32_USB_USE_OTG1 TRUE
#else #else
#define STM32_USB_USE_OTG1 FALSE #define STM32_USB_USE_OTG1 FALSE
@@ -427,7 +427,7 @@
/* /*
* USB driver system settings. * USB driver system settings.
*/ */
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define STM32_USB_USE_OTG1 TRUE #define STM32_USB_USE_OTG1 TRUE
#else #else
#define STM32_USB_USE_OTG1 FALSE #define STM32_USB_USE_OTG1 FALSE
@@ -427,7 +427,7 @@
/* /*
* USB driver system settings. * USB driver system settings.
*/ */
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define STM32_USB_USE_OTG1 TRUE #define STM32_USB_USE_OTG1 TRUE
#else #else
#define STM32_USB_USE_OTG1 FALSE #define STM32_USB_USE_OTG1 FALSE
+4 -3
View File
@@ -54,7 +54,8 @@
#if USE_ADC #if USE_ADC
#include "mcu_periph/adc.h" #include "mcu_periph/adc.h"
#endif #endif
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define USING_USB_SERIAL 1
#include "mcu_periph/usb_serial.h" #include "mcu_periph/usb_serial.h"
#endif #endif
#ifdef USE_UDP #ifdef USE_UDP
@@ -197,7 +198,7 @@ void mcu_init(void)
#if USE_ADC #if USE_ADC
adc_init(); adc_init();
#endif #endif
#if USE_USB_SERIAL #if USING_USB_SERIAL
VCOM_init(); VCOM_init();
#endif #endif
@@ -272,7 +273,7 @@ void mcu_event(void)
softi2c_event(); softi2c_event();
#endif #endif
#if USE_USB_SERIAL #if USING_USB_SERIAL
VCOM_event(); VCOM_event();
#endif #endif
} }
+14
View File
@@ -32,11 +32,22 @@
#include "std.h" #include "std.h"
#include "pprzlink/pprzlink_device.h" #include "pprzlink/pprzlink_device.h"
#include "mcu_periph/uart.h" #include "mcu_periph/uart.h"
#include "mcu_arch.h"
#ifndef USB_RX_BUFFER_SIZE #ifndef USB_RX_BUFFER_SIZE
#define USB_RX_BUFFER_SIZE UART_RX_BUFFER_SIZE #define USB_RX_BUFFER_SIZE UART_RX_BUFFER_SIZE
#endif #endif
#ifdef USB_MAX_ENDPOINTS
#if USB_MAX_ENDPOINTS < 4
#define USBD_NUMBER 1
#else
#define USBD_NUMBER 2
#endif
#else
#define USBD_NUMBER 1
#endif
struct usb_serial_periph { struct usb_serial_periph {
/** Receive buffer */ /** Receive buffer */
uint8_t rx_buf[USB_RX_BUFFER_SIZE]; uint8_t rx_buf[USB_RX_BUFFER_SIZE];
@@ -49,6 +60,9 @@ struct usb_serial_periph {
}; };
extern struct usb_serial_periph usb_serial; extern struct usb_serial_periph usb_serial;
#if USBD_NUMBER >= 2
extern struct usb_serial_periph usb_serial_debug;
#endif
void VCOM_init(void); void VCOM_init(void);
int VCOM_putchar(int c); int VCOM_putchar(int c);
+1 -1
View File
@@ -34,7 +34,7 @@
#include "mcu_periph/udp.h" #include "mcu_periph/udp.h"
#endif #endif
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h" #include "mcu_periph/usb_serial.h"
#endif #endif
+1 -1
View File
@@ -32,7 +32,7 @@
#include "pprz_mutex.h" #include "pprz_mutex.h"
#include "mcu_periph/uart.h" #include "mcu_periph/uart.h"
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h" #include "mcu_periph/usb_serial.h"
#endif #endif
#if USE_UDP #if USE_UDP
+1 -1
View File
@@ -35,7 +35,7 @@
#if USE_UDP #if USE_UDP
#include "mcu_periph/udp.h" #include "mcu_periph/udp.h"
#endif #endif
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h" #include "mcu_periph/usb_serial.h"
#endif #endif
#include "mcu_periph/uart.h" #include "mcu_periph/uart.h"
+1 -1
View File
@@ -29,7 +29,7 @@
#include "pprzlink/pprz_transport.h" #include "pprzlink/pprz_transport.h"
#include "mcu_periph/uart.h" #include "mcu_periph/uart.h"
#if USE_USB_SERIAL #if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h" #include "mcu_periph/usb_serial.h"
#endif #endif
#if USE_FRSKY_X_SERIAL #if USE_FRSKY_X_SERIAL
@@ -165,8 +165,13 @@ bool usbStorageIsItRunning(void)
return isRunning; return isRunning;
} }
/*
* Enable USB storage only if USB is plugged.
*/
void usbStorage_enable_usb_storage(float e) { void usbStorage_enable_usb_storage(float e) {
if(e > 0.5) { if(e > 0.5 && palReadPad(SDLOG_USB_VBUS_PORT, SDLOG_USB_VBUS_PIN) == PAL_HIGH) {
chBSemSignal(&bs_start_msd); chBSemSignal(&bs_start_msd);
} else {
usb_storage_status = 0;
} }
} }
@@ -1125,6 +1125,9 @@ void deinit_msd_driver(void)
void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig) void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
{ {
usbStop(&USBD);
usbDisconnectBus(&USBD);
msdInit(&UMSD); msdInit(&UMSD);
/* start the USB mass storage service */ /* start the USB mass storage service */
msdStart(&UMSD, msdConfig); msdStart(&UMSD, msdConfig);
@@ -1134,7 +1137,6 @@ void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
/* start the USB driver */ /* start the USB driver */
usbDisconnectBus(&USBD); usbDisconnectBus(&USBD);
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
usbStop(&USBD);
usbStart(&USBD, &usbConfig); usbStart(&USBD, &usbConfig);
usbConnectBus(&USBD); usbConnectBus(&USBD);
} }