Removed Serial USB HAL library

main
noah metz 2025-05-27 18:35:05 -06:00
parent bb7442a812
commit f0e1fadfd1
4 changed files with 9 additions and 145 deletions

@ -149,7 +149,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__)
#define HAL_USE_SERIAL_USB TRUE #define HAL_USE_SERIAL_USB FALSE
#endif #endif
/** /**

108
main.c

@ -25,85 +25,10 @@
#include "usbcfg.h" #include "usbcfg.h"
/*===========================================================================*/
/* Command line related. */
/*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
/* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
static uint8_t buf[] =
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: write\r\n");
return;
}
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
#if 1
/* Writing in channel mode.*/
chnWrite(&SDU1, buf, sizeof buf - 1);
#else
/* Writing in buffer mode.*/
(void) obqGetEmptyBufferTimeout(&SDU1.obqueue, TIME_INFINITE);
memcpy(SDU1.obqueue.ptr, buf, SERIAL_USB_BUFFERS_SIZE);
obqPostFullBuffer(&SDU1.obqueue, SERIAL_USB_BUFFERS_SIZE);
#endif
}
chprintf(chp, "\r\n\nstopped\r\n");
}
static const ShellCommand commands[] = {
{"write", cmd_write},
{NULL, NULL}
};
static const ShellConfig shell_cfg1 = {
(BaseSequentialStream *)&SDU1,
commands
};
/*===========================================================================*/ /*===========================================================================*/
/* Generic code. */ /* Generic code. */
/*===========================================================================*/ /*===========================================================================*/
/*
* LED blinker thread, times are in milliseconds.
*/
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("blinker");
while (true) {
systime_t time;
time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500;
palClearLine(LINE_LED_RED);
chThdSleepMilliseconds(time);
palSetLine(LINE_LED_RED);
chThdSleepMilliseconds(time);
}
}
/* /*
* Application entry point. * Application entry point.
*/ */
@ -119,42 +44,17 @@ int main(void) {
halInit(); halInit();
chSysInit(); chSysInit();
/*
* Initializes a serial-over-USB CDC driver.
*/
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
/* /*
* Activates the USB driver and then the USB bus pull-up on D+. * Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable * Note, a delay is inserted in order to not have to disconnect the cable
* after a reset. * after a reset.
*/ */
usbDisconnectBus(serusbcfg.usbp); usbDisconnectBus(&USBD1);
chThdSleepMilliseconds(1500); chThdSleepMilliseconds(1500);
usbStart(serusbcfg.usbp, &usbcfg); usbStart(&USBD1, &usbcfg);
usbConnectBus(serusbcfg.usbp); usbConnectBus(&USBD1);
/* while(true) {
* Shell manager initialization.
*/
shellInit();
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, spawning shells.
*/
while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
"shell", NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
} }

@ -16,9 +16,6 @@
#include "hal.h" #include "hal.h"
/* Virtual serial port over USB.*/
SerialUSBDriver SDU1;
/* /*
* Endpoints to be used for USBD1. * Endpoints to be used for USBD1.
*/ */
@ -229,8 +226,8 @@ static USBOutEndpointState ep1outstate;
static const USBEndpointConfig ep1config = { static const USBEndpointConfig ep1config = {
USB_EP_MODE_TYPE_BULK, USB_EP_MODE_TYPE_BULK,
NULL, NULL,
sduDataTransmitted, NULL,
sduDataReceived, NULL,
0x0040, 0x0040,
0x0040, 0x0040,
&ep1instate, &ep1instate,
@ -250,7 +247,7 @@ static USBInEndpointState ep2instate;
static const USBEndpointConfig ep2config = { static const USBEndpointConfig ep2config = {
USB_EP_MODE_TYPE_INTR, USB_EP_MODE_TYPE_INTR,
NULL, NULL,
sduInterruptTransmitted, NULL,
NULL, NULL,
0x0010, 0x0010,
0x0000, 0x0000,
@ -264,8 +261,6 @@ static const USBEndpointConfig ep2config = {
* Handles the USB driver global events. * Handles the USB driver global events.
*/ */
static void usb_event(USBDriver *usbp, usbevent_t event) { static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) { switch (event) {
case USB_EVENT_ADDRESS: case USB_EVENT_ADDRESS:
return; return;
@ -278,9 +273,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
usbInitEndpointI(usbp, USB1_DATA_REQUEST_EP, &ep1config); usbInitEndpointI(usbp, USB1_DATA_REQUEST_EP, &ep1config);
usbInitEndpointI(usbp, USB1_INTERRUPT_REQUEST_EP, &ep2config); usbInitEndpointI(usbp, USB1_INTERRUPT_REQUEST_EP, &ep2config);
/* Resetting the state of the CDC subsystem.*/
sduConfigureHookI(&SDU1);
chSysUnlockFromISR(); chSysUnlockFromISR();
return; return;
case USB_EVENT_RESET: case USB_EVENT_RESET:
@ -288,20 +280,8 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
case USB_EVENT_UNCONFIGURED: case USB_EVENT_UNCONFIGURED:
/* Falls into.*/ /* Falls into.*/
case USB_EVENT_SUSPEND: case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return; return;
case USB_EVENT_WAKEUP: case USB_EVENT_WAKEUP:
chSysLockFromISR();
/* Connection event on wakeup.*/
sduWakeupHookI(&SDU1);
chSysUnlockFromISR();
return; return;
case USB_EVENT_STALLED: case USB_EVENT_STALLED:
return; return;
@ -315,10 +295,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
static void sof_handler(USBDriver *usbp) { static void sof_handler(USBDriver *usbp) {
(void)usbp; (void)usbp;
osalSysLockFromISR();
sduSOFHookI(&SDU1);
osalSysUnlockFromISR();
} }
/* /*
@ -327,16 +303,6 @@ static void sof_handler(USBDriver *usbp) {
const USBConfig usbcfg = { const USBConfig usbcfg = {
usb_event, usb_event,
get_descriptor, get_descriptor,
sduRequestsHook, NULL,
sof_handler sof_handler
}; };
/*
* Serial over USB driver configuration.
*/
const SerialUSBConfig serusbcfg = {
&USBD1,
USB1_DATA_REQUEST_EP,
USB1_DATA_AVAILABLE_EP,
USB1_INTERRUPT_REQUEST_EP
};

@ -18,8 +18,6 @@
#define USBCFG_H #define USBCFG_H
extern const USBConfig usbcfg; extern const USBConfig usbcfg;
extern SerialUSBConfig serusbcfg;
extern SerialUSBDriver SDU1;
#endif /* USBCFG_H */ #endif /* USBCFG_H */