rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
usbconsole.cpp
Go to the documentation of this file.
1/**
2 * @file usbconsole.cpp
3 * @brief USB-over-serial configuration
4 *
5 * @date Oct 14, 2013
6 * @author Andrey Belomutskiy, (c) 2012-2020
7 */
8
9#include "pch.h"
10
11
12#if EFI_USB_SERIAL
13
14#include "usbconsole.h"
15#include "usbcfg.h"
16#include "mpu_util.h"
17
18static bool isUsbSerialInitialized = false;
19
20/**
21 * start USB serial using hard-coded communications pins (see comments inside the code)
22 */
24#ifndef BOARD_SERIAL
25 // populate serial number based on chip unique number
26 usbPopulateSerialNumber(MCU_SERIAL_NUMBER_LOCATION, MCU_SERIAL_NUMBER_BYTES);
27#endif
28
29 efiSetPadMode("USB DM", EFI_USB_SERIAL_DM, PAL_MODE_ALTERNATE(EFI_USB_AF));
30 efiSetPadMode("USB DP", EFI_USB_SERIAL_DP, PAL_MODE_ALTERNATE(EFI_USB_AF));
31
32 /*
33 * Initializes a serial-over-USB CDC driver.
34 */
35 sduObjectInit(&SDU1);
36 sduStart(&SDU1, &serusbcfg);
37
38 /*
39 * Activates the USB driver and then the USB bus pull-up on D+.
40 * Note, a delay is inserted in order to not have to disconnect the cable
41 * after a reset.
42 */
43// See also https://github.com/rusefi/rusefi/issues/705
44#ifndef EFI_SKIP_USB_DISCONNECT
45 usbDisconnectBus(serusbcfg.usbp);
46 chThdSleepMilliseconds(250);
47#endif/* EFI_SKIP_USB_DISCONNECT */
48 usbStart(serusbcfg.usbp, &usbcfg);
49 usbConnectBus(serusbcfg.usbp);
50
52}
53
55 return isUsbSerialInitialized && SDU1.config->usbp->state == USB_ACTIVE;
56}
57
58#else
60 return false;
61}
62
63#endif /* EFI_USB_SERIAL */
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
BaseChannel SDU1
static bool isUsbSerialInitialized
bool is_usb_serial_ready()
void usb_serial_start(void)
Main function of PDL.
const USBConfig usbcfg
Definition usbcfg.cpp:470
const SerialUSBConfig serusbcfg
Definition usbcfg.cpp:480
void usbPopulateSerialNumber(const uint8_t *serialNumber, size_t bytes)
Definition usbcfg.cpp:280