From f0e1fadfd1c039e95a331b2058b882fc89bd0d20 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Tue, 27 May 2025 18:35:05 -0600 Subject: [PATCH] Removed Serial USB HAL library --- cfg/halconf.h | 2 +- main.c | 108 ++---------------------------------------------- source/usbcfg.c | 42 ++----------------- source/usbcfg.h | 2 - 4 files changed, 9 insertions(+), 145 deletions(-) diff --git a/cfg/halconf.h b/cfg/halconf.h index 5404a2f..b035b4b 100644 --- a/cfg/halconf.h +++ b/cfg/halconf.h @@ -149,7 +149,7 @@ * @brief Enables the SERIAL over USB subsystem. */ #if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL_USB TRUE +#define HAL_USE_SERIAL_USB FALSE #endif /** diff --git a/main.c b/main.c index 5f45458..19b4cf5 100644 --- a/main.c +++ b/main.c @@ -25,85 +25,10 @@ #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. */ /*===========================================================================*/ -/* - * 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. */ @@ -119,42 +44,17 @@ int main(void) { halInit(); 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+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ - usbDisconnectBus(serusbcfg.usbp); + usbDisconnectBus(&USBD1); chThdSleepMilliseconds(1500); - usbStart(serusbcfg.usbp, &usbcfg); - usbConnectBus(serusbcfg.usbp); + usbStart(&USBD1, &usbcfg); + usbConnectBus(&USBD1); - /* - * 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. */ - } + while(true) { chThdSleepMilliseconds(1000); } } diff --git a/source/usbcfg.c b/source/usbcfg.c index 237dab0..a99ae3c 100644 --- a/source/usbcfg.c +++ b/source/usbcfg.c @@ -16,9 +16,6 @@ #include "hal.h" -/* Virtual serial port over USB.*/ -SerialUSBDriver SDU1; - /* * Endpoints to be used for USBD1. */ @@ -229,8 +226,8 @@ static USBOutEndpointState ep1outstate; static const USBEndpointConfig ep1config = { USB_EP_MODE_TYPE_BULK, NULL, - sduDataTransmitted, - sduDataReceived, + NULL, + NULL, 0x0040, 0x0040, &ep1instate, @@ -250,7 +247,7 @@ static USBInEndpointState ep2instate; static const USBEndpointConfig ep2config = { USB_EP_MODE_TYPE_INTR, NULL, - sduInterruptTransmitted, + NULL, NULL, 0x0010, 0x0000, @@ -264,8 +261,6 @@ static const USBEndpointConfig ep2config = { * Handles the USB driver global events. */ static void usb_event(USBDriver *usbp, usbevent_t event) { - extern SerialUSBDriver SDU1; - switch (event) { case USB_EVENT_ADDRESS: return; @@ -278,9 +273,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { usbInitEndpointI(usbp, USB1_DATA_REQUEST_EP, &ep1config); usbInitEndpointI(usbp, USB1_INTERRUPT_REQUEST_EP, &ep2config); - /* Resetting the state of the CDC subsystem.*/ - sduConfigureHookI(&SDU1); - chSysUnlockFromISR(); return; case USB_EVENT_RESET: @@ -288,20 +280,8 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { case USB_EVENT_UNCONFIGURED: /* Falls into.*/ case USB_EVENT_SUSPEND: - chSysLockFromISR(); - - /* Disconnection event on suspend.*/ - sduSuspendHookI(&SDU1); - - chSysUnlockFromISR(); return; case USB_EVENT_WAKEUP: - chSysLockFromISR(); - - /* Connection event on wakeup.*/ - sduWakeupHookI(&SDU1); - - chSysUnlockFromISR(); return; case USB_EVENT_STALLED: return; @@ -315,10 +295,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { static void sof_handler(USBDriver *usbp) { (void)usbp; - - osalSysLockFromISR(); - sduSOFHookI(&SDU1); - osalSysUnlockFromISR(); } /* @@ -327,16 +303,6 @@ static void sof_handler(USBDriver *usbp) { const USBConfig usbcfg = { usb_event, get_descriptor, - sduRequestsHook, + NULL, sof_handler }; - -/* - * Serial over USB driver configuration. - */ -const SerialUSBConfig serusbcfg = { - &USBD1, - USB1_DATA_REQUEST_EP, - USB1_DATA_AVAILABLE_EP, - USB1_INTERRUPT_REQUEST_EP -}; diff --git a/source/usbcfg.h b/source/usbcfg.h index 7f2e941..aee5679 100644 --- a/source/usbcfg.h +++ b/source/usbcfg.h @@ -18,8 +18,6 @@ #define USBCFG_H extern const USBConfig usbcfg; -extern SerialUSBConfig serusbcfg; -extern SerialUSBDriver SDU1; #endif /* USBCFG_H */