From 34310e401f78e1849e73e1e74efea661be967e61 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 20 Aug 2012 15:31:48 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4594 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/usb_cdc.h | 16 ++++----- testhal/STM32F1xx/USB_CDC/readme.txt | 26 ++++++++++++++ testhal/STM32F4xx/USB_CDC/Makefile | 2 +- testhal/STM32F4xx/USB_CDC/main.c | 51 ++++++++++------------------ testhal/STM32F4xx/USB_CDC/mcuconf.h | 2 +- testhal/STM32F4xx/USB_CDC/readme.txt | 26 ++++++++++++++ 6 files changed, 79 insertions(+), 44 deletions(-) create mode 100644 testhal/STM32F1xx/USB_CDC/readme.txt create mode 100644 testhal/STM32F4xx/USB_CDC/readme.txt diff --git a/os/hal/include/usb_cdc.h b/os/hal/include/usb_cdc.h index 2f7247fee..84005604a 100644 --- a/os/hal/include/usb_cdc.h +++ b/os/hal/include/usb_cdc.h @@ -88,6 +88,14 @@ #define USB_CDC_DATA_REQUEST_EP 1 #endif +/** + * @brief Endpoint number for bulk OUT. + */ +#if !defined(USB_CDC_DATA_AVAILABLE_EP) || defined(__DOXYGEN__) +#define USB_CDC_DATA_AVAILABLE_EP 1 +#endif +/** @} */ + /** * @brief Endpoint number for interrupt IN. */ @@ -95,14 +103,6 @@ #define USB_CDC_INTERRUPT_REQUEST_EP 2 #endif -/** - * @brief Endpoint number for bulk OUT. - */ -#if !defined(USB_CDC_DATA_AVAILABLE_EP) || defined(__DOXYGEN__) -#define USB_CDC_DATA_AVAILABLE_EP 3 -#endif -/** @} */ - /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ diff --git a/testhal/STM32F1xx/USB_CDC/readme.txt b/testhal/STM32F1xx/USB_CDC/readme.txt new file mode 100644 index 000000000..2d71df64f --- /dev/null +++ b/testhal/STM32F1xx/USB_CDC/readme.txt @@ -0,0 +1,26 @@ +***************************************************************************** +** ChibiOS/RT HAL - USB-CDC driver demo for STM32. ** +***************************************************************************** + +** TARGET ** + +The demo runs on an Olimex STM32-P103 board. + +** The Demo ** + +The application demonstrates the use of the STM32 USB driver. + +** Build Procedure ** + +The demo has been tested using the free Codesourcery GCC-based toolchain +and YAGARTO. +Just modify the TRGT line in the makefile in order to use different GCC ports. + +** Notes ** + +Some files used by the demo are not part of ChibiOS/RT but are copyright of +ST Microelectronics and are licensed under a different license. +Also note that not all the files present in the ST library are distributed +with ChibiOS/RT, you can find the whole library on the ST web site: + + http://www.st.com diff --git a/testhal/STM32F4xx/USB_CDC/Makefile b/testhal/STM32F4xx/USB_CDC/Makefile index 1a6ac2d74..8c329e2d7 100644 --- a/testhal/STM32F4xx/USB_CDC/Makefile +++ b/testhal/STM32F4xx/USB_CDC/Makefile @@ -65,7 +65,7 @@ PROJECT = ch # Imported source files and paths CHIBIOS = ../../.. -include $(CHIBIOS)/boards/ST_STM32F4_DISCOVERY/board.mk +include $(CHIBIOS)/boards/OLIMEX_STM32_E407/board.mk include $(CHIBIOS)/os/hal/platforms/STM32F4xx/platform.mk include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F4xx/port.mk diff --git a/testhal/STM32F4xx/USB_CDC/main.c b/testhal/STM32F4xx/USB_CDC/main.c index 34bdf55eb..f2f00ebce 100644 --- a/testhal/STM32F4xx/USB_CDC/main.c +++ b/testhal/STM32F4xx/USB_CDC/main.c @@ -231,17 +231,22 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp, static USBInEndpointState ep1instate; /** - * @brief EP1 initialization structure (IN only). + * @brief OUT EP1 state. + */ +static USBOutEndpointState ep1outstate; + +/** + * @brief EP1 initialization structure (both IN and OUT). */ static const USBEndpointConfig ep1config = { USB_EP_MODE_TYPE_BULK, NULL, sduDataTransmitted, - NULL, + sduDataReceived, + 0x0040, 0x0040, - 0x0000, &ep1instate, - NULL, + &ep1outstate, 2, NULL }; @@ -249,7 +254,7 @@ static const USBEndpointConfig ep1config = { /** * @brief IN EP2 state. */ -USBInEndpointState ep2instate; +static USBInEndpointState ep2instate; /** * @brief EP2 initialization structure (IN only). @@ -267,27 +272,6 @@ static const USBEndpointConfig ep2config = { NULL }; -/** - * @brief OUT EP2 state. - */ -USBOutEndpointState ep3outstate; - -/** - * @brief EP3 initialization structure (OUT only). - */ -static const USBEndpointConfig ep3config = { - USB_EP_MODE_TYPE_BULK, - NULL, - NULL, - sduDataReceived, - 0x0000, - 0x0040, - NULL, - &ep3outstate, - 0, - NULL -}; - /* * Handles the USB driver global events. */ @@ -306,7 +290,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { must be used.*/ usbInitEndpointI(usbp, USB_CDC_DATA_REQUEST_EP, &ep1config); usbInitEndpointI(usbp, USB_CDC_INTERRUPT_REQUEST_EP, &ep2config); - usbInitEndpointI(usbp, USB_CDC_DATA_AVAILABLE_EP, &ep3config); /* Resetting the state of the CDC subsystem.*/ sduConfigureHookI(usbp); @@ -337,7 +320,7 @@ static const USBConfig usbcfg = { * Serial over USB driver configuration. */ static const SerialUSBConfig serusbcfg = { - &USBD1 + &USBD2 }; /*===========================================================================*/ @@ -425,9 +408,9 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) { chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1); - palTogglePad(GPIOD, GPIOD_LED4); +// palTogglePad(GPIOD, GPIOD_LED4); } - palClearPad(GPIOD, GPIOD_LED4); +// palClearPad(GPIOD, GPIOD_LED4); chprintf(chp, "\r\n\nstopped\r\n"); } @@ -459,10 +442,10 @@ static msg_t Thread1(void *arg) { while (TRUE) { systime_t time; - time = USBD1.state == USB_ACTIVE ? 250 : 500; - palClearPad(GPIOD, GPIOD_LED6); + time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; + palClearPad(GPIOC, GPIOC_LED); chThdSleepMilliseconds(time); - palSetPad(GPIOD, GPIOD_LED6); + palSetPad(GPIOC, GPIOC_LED); chThdSleepMilliseconds(time); } } @@ -496,7 +479,7 @@ int main(void) { */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); - usbStart(&USBD1, &usbcfg); + usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* diff --git a/testhal/STM32F4xx/USB_CDC/mcuconf.h b/testhal/STM32F4xx/USB_CDC/mcuconf.h index e7f082583..a441dda57 100644 --- a/testhal/STM32F4xx/USB_CDC/mcuconf.h +++ b/testhal/STM32F4xx/USB_CDC/mcuconf.h @@ -43,7 +43,7 @@ #define STM32_CLOCK48_REQUIRED TRUE #define STM32_SW STM32_SW_PLL #define STM32_PLLSRC STM32_PLLSRC_HSE -#define STM32_PLLM_VALUE 8 +#define STM32_PLLM_VALUE 12 #define STM32_PLLN_VALUE 336 #define STM32_PLLP_VALUE 2 #define STM32_PLLQ_VALUE 7 diff --git a/testhal/STM32F4xx/USB_CDC/readme.txt b/testhal/STM32F4xx/USB_CDC/readme.txt new file mode 100644 index 000000000..38599111d --- /dev/null +++ b/testhal/STM32F4xx/USB_CDC/readme.txt @@ -0,0 +1,26 @@ +***************************************************************************** +** ChibiOS/RT HAL - USB-CDC driver demo for STM32. ** +***************************************************************************** + +** TARGET ** + +The demo runs on an Olimex STM32-E407 board. + +** The Demo ** + +The application demonstrates the use of the STM32 USB driver. + +** Build Procedure ** + +The demo has been tested using the free Codesourcery GCC-based toolchain +and YAGARTO. +Just modify the TRGT line in the makefile in order to use different GCC ports. + +** Notes ** + +Some files used by the demo are not part of ChibiOS/RT but are copyright of +ST Microelectronics and are licensed under a different license. +Also note that not all the files present in the ST library are distributed +with ChibiOS/RT, you can find the whole library on the ST web site: + + http://www.st.com