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">
<doc>
<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
</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"/>
<define name="TELEMETRY_DISABLE_RX" value="FALSE|TRUE" description="disable incoming message parsing"/>
</doc>
+6 -17
View File
@@ -3,29 +3,18 @@
<module name="telemetry_transparent_usb" dir="datalink" task="datalink">
<doc>
<description>
DEPRECATED: Use telemetry_transparent with configure MODEM_PORT=usb_serial instead.
Telemetry using PPRZ protocol over serial USB (e.g. /dev/ttyACM0)
</description>
</doc>
<dep>
<depends>datalink_common</depends>
<provides>datalink,telemetry</provides>
<depends>telemetry_transparent</depends>
</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">
<define name="USE_USB_SERIAL"/>
<define name="DOWNLINK_DEVICE" value="usb_serial"/>
<define name="PPRZ_UART" value="usb_serial"/>
<define name="DOWNLINK_TRANSPORT" value="pprz_tp"/>
<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="."/>
<configure name="MODEM_PORT" value="usb_serial"/>
<raw>
$(warning Warning: telemetry_transparent_usb is deprecated. Use telemetry_transparent with configure MODEM_PORT=usb_serial instead.)
</raw>
</makefile>
</module>
+3 -2
View File
@@ -9,7 +9,9 @@
To be used with Lisa M/MX 2.1
</description>
</doc>
<dep>
<depends>uart</depends>
</dep>
<header>
<file name="usb_serial_stm32.h"/>
</header>
@@ -18,7 +20,6 @@
<event fun="event_usb_serial()"/>
<makefile target="!nps|sim">
<file_arch name="usb_ser_hw.c" dir=""/>
<define name="USE_USB_SERIAL"/>
<file name="usb_serial_stm32_example1.c"/>
</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 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
SUBSYSTEM=="tty", ATTRS{interface}=="TTL232R-3V3", SYMLINK+="ftdi-serial"
+2 -2
View File
@@ -173,7 +173,7 @@
* @brief Enables the SERIAL over USB subsystem.
*/
#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
#else
#define HAL_USE_SERIAL_USB FALSE
@@ -216,7 +216,7 @@
* @brief Enables the USB subsystem.
*/
#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define HAL_USE_USB TRUE
#else
#define HAL_USE_USB FALSE
+1
View File
@@ -32,6 +32,7 @@
#define CHIBIOS_MCU_ARCH_H
#include "std.h"
#include <hal.h>
extern void mcu_arch_init(void);
File diff suppressed because it is too large Load Diff
@@ -262,7 +262,7 @@
/*
* USB driver system settings.
*/
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define STM32_USB_USE_OTG1 TRUE
#else
#define STM32_USB_USE_OTG1 FALSE
@@ -427,7 +427,7 @@
/*
* USB driver system settings.
*/
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define STM32_USB_USE_OTG1 TRUE
#else
#define STM32_USB_USE_OTG1 FALSE
@@ -427,7 +427,7 @@
/*
* USB driver system settings.
*/
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define STM32_USB_USE_OTG1 TRUE
#else
#define STM32_USB_USE_OTG1 FALSE
+4 -3
View File
@@ -54,7 +54,8 @@
#if USE_ADC
#include "mcu_periph/adc.h"
#endif
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#define USING_USB_SERIAL 1
#include "mcu_periph/usb_serial.h"
#endif
#ifdef USE_UDP
@@ -197,7 +198,7 @@ void mcu_init(void)
#if USE_ADC
adc_init();
#endif
#if USE_USB_SERIAL
#if USING_USB_SERIAL
VCOM_init();
#endif
@@ -272,7 +273,7 @@ void mcu_event(void)
softi2c_event();
#endif
#if USE_USB_SERIAL
#if USING_USB_SERIAL
VCOM_event();
#endif
}
+14
View File
@@ -32,11 +32,22 @@
#include "std.h"
#include "pprzlink/pprzlink_device.h"
#include "mcu_periph/uart.h"
#include "mcu_arch.h"
#ifndef USB_RX_BUFFER_SIZE
#define USB_RX_BUFFER_SIZE UART_RX_BUFFER_SIZE
#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 {
/** Receive buffer */
uint8_t rx_buf[USB_RX_BUFFER_SIZE];
@@ -49,6 +60,9 @@ struct usb_serial_periph {
};
extern struct usb_serial_periph usb_serial;
#if USBD_NUMBER >= 2
extern struct usb_serial_periph usb_serial_debug;
#endif
void VCOM_init(void);
int VCOM_putchar(int c);
+1 -1
View File
@@ -34,7 +34,7 @@
#include "mcu_periph/udp.h"
#endif
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h"
#endif
+1 -1
View File
@@ -32,7 +32,7 @@
#include "pprz_mutex.h"
#include "mcu_periph/uart.h"
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h"
#endif
#if USE_UDP
+1 -1
View File
@@ -35,7 +35,7 @@
#if USE_UDP
#include "mcu_periph/udp.h"
#endif
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h"
#endif
#include "mcu_periph/uart.h"
+1 -1
View File
@@ -29,7 +29,7 @@
#include "pprzlink/pprz_transport.h"
#include "mcu_periph/uart.h"
#if USE_USB_SERIAL
#if USE_USB_SERIAL || USE_USB_SERIAL_DEBUG
#include "mcu_periph/usb_serial.h"
#endif
#if USE_FRSKY_X_SERIAL
@@ -165,8 +165,13 @@ bool usbStorageIsItRunning(void)
return isRunning;
}
/*
* Enable USB storage only if USB is plugged.
*/
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);
} else {
usb_storage_status = 0;
}
}
@@ -1125,6 +1125,9 @@ void deinit_msd_driver(void)
void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
{
usbStop(&USBD);
usbDisconnectBus(&USBD);
msdInit(&UMSD);
/* start the USB mass storage service */
msdStart(&UMSD, msdConfig);
@@ -1134,7 +1137,6 @@ void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
/* start the USB driver */
usbDisconnectBus(&USBD);
chThdSleepMilliseconds(1000);
usbStop(&USBD);
usbStart(&USBD, &usbConfig);
usbConnectBus(&USBD);
}