diff --git a/boards.txt b/boards.txt index db3e21b57f..b186f1ff99 100644 --- a/boards.txt +++ b/boards.txt @@ -346,26 +346,18 @@ Disco.menu.Other_serial.enable_Serial2=Serial2 (if available) Disco.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2 # USB connectivity -Nucleo_144.menu.USB_interface.enable_USB=None -Nucleo_144.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available) -Nucleo_144.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE -#Nucleo_144.menu.USB_interface.enable_CDC=CDC (if available) -#Nucleo_144.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS +Nucleo_144.menu.USB_interface.enable_usb=None +Nucleo_144.menu.USB_interface.enable_usb_periph=Enable USB (if available) +Nucleo_144.menu.USB_interface.enable_usb_periph.build.enable_usb={build.usb_flags} Nucleo_64.menu.USB_interface.enable_USB=None -Nucleo_64.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available) -Nucleo_64.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE -#Nucleo_64.menu.USB_interface.enable_CDC=CDC (if available) -#Nucleo_64.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS +Nucleo_64.menu.USB_interface.enable_usb_periph=Enable USB (if available) +Nucleo_64.menu.USB_interface.enable_usb_periph.build.enable_usb={build.usb_flags} Nucleo_32.menu.USB_interface.enable_USB=None -Nucleo_32.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available) -Nucleo_32.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE -#Nucleo_32.menu.USB_interface.enable_CDC=CDC (if available) -#Nucleo_32.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS +Nucleo_32.menu.USB_interface.enable_usb_periph=Enable USB (if available) +Nucleo_32.menu.USB_interface.enable_usb_periph.build.enable_usb={build.usb_flags} Disco.menu.USB_interface.enable_USB=None -Disco.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available) -Disco.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE -#Disco.menu.USB_interface.enable_CDC=CDC (if available) -#Disco.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS +Disco.menu.USB_interface.enable_usb_periph=Enable USB (if available) +Disco.menu.USB_interface.enable_usb_periph.build.enable_usb={build.usb_flags} diff --git a/cores/arduino/chip.h b/cores/arduino/chip.h index d4bcdc90a0..e5192c38d0 100644 --- a/cores/arduino/chip.h +++ b/cores/arduino/chip.h @@ -34,9 +34,6 @@ #include "timer.h" #include "twi.h" #include "stm32_eeprom.h" -#ifdef USBCON -#include "usb_interface.h" -#endif //USBCON #include "ethernet.h" diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 5e992f25dc..4cc4ffe89b 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -39,10 +39,6 @@ int main( void ) { initVariant(); -#if defined(USBCON) - usbd_interface_init(); -#endif - setup(); for (;;) diff --git a/cores/arduino/stm32/timer.c b/cores/arduino/stm32/timer.c index c0ce982886..9af6d4ab4f 100644 --- a/cores/arduino/stm32/timer.c +++ b/cores/arduino/stm32/timer.c @@ -563,8 +563,8 @@ uint32_t getTimerIrq(TIM_TypeDef* tim) */ void TimerHandleDeinit(stimer_t *obj) { - HAL_TIM_Base_DeInit(&(obj->handle)); HAL_TIM_Base_Stop_IT(&(obj->handle)); + HAL_TIM_Base_DeInit(&(obj->handle)); } /** @@ -1024,6 +1024,17 @@ void attachIntHandle(stimer_t *obj, void (*irqHandle)(stimer_t *)) obj->irqHandle = irqHandle; } +/** + * @brief Attached an interrupt handler + * @param htim : TIM handle + * @param irqHandle : interrupt handler + * @retval none + */ +void timer_attach_interrupt_handle(TIM_HandleTypeDef *htim, void (*irqHandle)(stimer_t *)) +{ + stimer_t *obj = get_timer_obj(htim); + obj->irqHandle = irqHandle; +} /******************************************************************************/ /* TIMx IRQ HANDLER */ diff --git a/cores/arduino/stm32/timer.h b/cores/arduino/stm32/timer.h index a73ea80383..40e9219121 100644 --- a/cores/arduino/stm32/timer.h +++ b/cores/arduino/stm32/timer.h @@ -157,6 +157,7 @@ struct timer_s{ void timer_enable_clock(TIM_HandleTypeDef *htim); void timer_disable_clock(TIM_HandleTypeDef *htim); +void timer_attach_interrupt_handle(TIM_HandleTypeDef *htim, void (*irqHandle)(stimer_t *)); void TimerHandleInit(stimer_t *obj, uint16_t period, uint16_t prescaler); void TimerHandleDeinit(stimer_t *obj); diff --git a/cores/arduino/stm32/usb_interface.c b/cores/arduino/stm32/usb_interface.c deleted file mode 100644 index af4fd9c999..0000000000 --- a/cores/arduino/stm32/usb_interface.c +++ /dev/null @@ -1,173 +0,0 @@ -/** - ****************************************************************************** - * @file usb_interface.c - * @author WI6LABS - * @version V1.0.0 - * @date 27-October-2016 - * @brief provide the usb interface - * - ****************************************************************************** - * @attention - * - *

© COPYRIGHT(c) 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/** @addtogroup CMSIS - * @{ - */ - -/** @addtogroup stm32f4xx_system - * @{ - */ - -/** @addtogroup STM32F4xx_System_Private_Includes - * @{ - */ -#include "usb_interface.h" - -/** - * @} - */ - -#ifdef __cplusplus - extern "C" { -#endif -#ifdef USBCON -/** @addtogroup STM32F4xx_System_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Defines - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Variables - * @{ - */ -/* USB Device Core handle declaration */ -#ifdef USBD_USE_HID_COMPOSITE -static USBD_HandleTypeDef hUSBD_Device_HID; -#endif //USBD_USE_HID_COMPOSITE -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Functions - * @{ - */ - -/** - * @brief initialize the USB HID interface - * @param HID_Desc : usb HID descriptor callbacks - * @retval none - */ -void usbd_interface_init(void) -{ -#ifdef USBD_USE_HID_COMPOSITE - /* Init Device Library */ - USBD_Init(&hUSBD_Device_HID, &HID_Desc, 0); - - /* Add Supported Class */ - USBD_RegisterClass(&hUSBD_Device_HID, USBD_COMPOSITE_HID_CLASS); - - /* Start Device Process */ - USBD_Start(&hUSBD_Device_HID); -#endif // USBD_USE_HID_COMPOSITE -} - -/** - * @brief initialize the USB HID interface - * @param HID_Desc : usb HID descriptor callbacks - * @retval none - */ -void usbd_interface_mouse_sendReport(uint8_t *report, uint16_t len) -{ -#ifdef USBD_USE_HID_COMPOSITE - USBD_HID_MOUSE_SendReport(&hUSBD_Device_HID, report, len); -#endif // USBD_USE_HID_COMPOSITE -} - -/** - * @brief initialize the USB HID interface - * @param HID_Desc : usb HID descriptor callbacks - * @retval none - */ -void usbd_interface_keyboard_sendReport(uint8_t *report, uint16_t len) -{ -#ifdef USBD_USE_HID_COMPOSITE - USBD_HID_KEYBOARD_SendReport(&hUSBD_Device_HID, report, len); -#endif // USBD_USE_HID_COMPOSITE -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -#endif // USBCON -#ifdef __cplusplus -} -#endif - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h index 094efb41d6..3f7435d217 100644 --- a/cores/arduino/wiring.h +++ b/cores/arduino/wiring.h @@ -20,6 +20,8 @@ #ifndef _WIRING_ #define _WIRING_ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/libraries/Keyboard/src/Keyboard.cpp b/libraries/Keyboard/src/Keyboard.cpp index 5b2988ffcf..ab0b170bec 100644 --- a/libraries/Keyboard/src/Keyboard.cpp +++ b/libraries/Keyboard/src/Keyboard.cpp @@ -20,7 +20,7 @@ */ #include "Keyboard.h" -#include "usbd_hid_composite.h" +#include "USBHIDComposite.h" #if defined(USBCON) @@ -34,10 +34,12 @@ Keyboard_::Keyboard_(void) void Keyboard_::begin(void) { + HID.begin(); } void Keyboard_::end(void) { + HID.end(); } void Keyboard_::sendReport(KeyReport* keys) @@ -45,7 +47,7 @@ void Keyboard_::sendReport(KeyReport* keys) uint8_t buf[8] = {keys->modifiers, keys->reserved, keys->keys[0], keys->keys[1], keys->keys[2], keys->keys[3], keys->keys[4], keys->keys[5]}; - usbd_interface_keyboard_sendReport(buf, 8); + HID.keyboardSend(buf, 8); //delay required to prevent persistent key when call print delay(20); diff --git a/libraries/Keyboard/src/Keyboard.h b/libraries/Keyboard/src/Keyboard.h index 640346e633..7e5bebcbbb 100644 --- a/libraries/Keyboard/src/Keyboard.h +++ b/libraries/Keyboard/src/Keyboard.h @@ -24,9 +24,9 @@ #include -#if !defined(USBCON) || !defined(USBD_USE_HID_COMPOSITE) +#if !defined(USBCON) -#error "USB HID not enabled! Select 'HID' in the 'Tools->USB interface' menu." +#error "USB not enabled! Select 'USB Enable' in the 'Tools->USB interface' menu." #else diff --git a/libraries/Mouse/src/Mouse.cpp b/libraries/Mouse/src/Mouse.cpp index 30f7b732b0..42b2cd980f 100644 --- a/libraries/Mouse/src/Mouse.cpp +++ b/libraries/Mouse/src/Mouse.cpp @@ -20,7 +20,7 @@ */ #include "Mouse.h" -#include "usbd_hid_composite.h" +#include "USBHIDComposite.h" #if defined(USBCON) @@ -34,10 +34,12 @@ Mouse_::Mouse_(void) : _buttons(0) void Mouse_::begin(void) { + HID.begin(); } void Mouse_::end(void) { + HID.end(); } void Mouse_::click(uint8_t b) @@ -56,7 +58,7 @@ void Mouse_::move(signed char x, signed char y, signed char wheel) m[2] = y; m[3] = wheel; - usbd_interface_mouse_sendReport(m, 4); + HID.mouseSend(m, 4); } void Mouse_::buttons(uint8_t b) diff --git a/libraries/Mouse/src/Mouse.h b/libraries/Mouse/src/Mouse.h index 0a28ffc250..9c24fcf12e 100644 --- a/libraries/Mouse/src/Mouse.h +++ b/libraries/Mouse/src/Mouse.h @@ -24,9 +24,9 @@ #include -#if !defined(USBCON) || !defined(USBD_USE_HID_COMPOSITE) +#if !defined(USBCON) -#error "USB HID not enabled! Select 'HID' in the 'Tools->USB interface' menu." +#error "USB not enabled! Select 'USB Enable' in the 'Tools->USB interface' menu." #else diff --git a/libraries/USBHIDComposite/README.md b/libraries/USBHIDComposite/README.md new file mode 100644 index 0000000000..ed5b943737 --- /dev/null +++ b/libraries/USBHIDComposite/README.md @@ -0,0 +1,14 @@ +# USBHIDComposite + +Arduino library to provide USB HID class with Mouse and Keyboard descriptors. + +This library functions allow to configure the USB peripheral and to send mouse +and keyboard report descriptors. + +* HID.begin() +* HID.end() +* HID.mouseSend() +* HID.keyboardSend() + +For more information about this library please visit us at +https://github.com/stm32duino/Arduino_Core_STM32 diff --git a/libraries/USBHIDComposite/keywords.txt b/libraries/USBHIDComposite/keywords.txt new file mode 100644 index 0000000000..e638853ff7 --- /dev/null +++ b/libraries/USBHIDComposite/keywords.txt @@ -0,0 +1,22 @@ +####################################### +# Syntax Coloring Map For HID +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +HID KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +end KEYWORD2 +mouseSend KEYWORD2 +keyboardSend KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/libraries/USBHIDComposite/library.properties b/libraries/USBHIDComposite/library.properties new file mode 100644 index 0000000000..35eea339f2 --- /dev/null +++ b/libraries/USBHIDComposite/library.properties @@ -0,0 +1,9 @@ +name=HID Composite +version=1.0.0 +author=Wi6Labs +maintainer=STMicroelectronics +sentence=Provides USB HID class for Mouse and Keyboard. +paragraph= +category=Device Control +url=https://github.com/stm32duino/Arduino_Core_STM32 +architectures=stm32 diff --git a/cores/arduino/stm32/usb_interface.h b/libraries/USBHIDComposite/src/USBHIDComposite.cpp similarity index 56% rename from cores/arduino/stm32/usb_interface.h rename to libraries/USBHIDComposite/src/USBHIDComposite.cpp index 070b7bc861..e8ebe641dd 100644 --- a/cores/arduino/stm32/usb_interface.h +++ b/libraries/USBHIDComposite/src/USBHIDComposite.cpp @@ -1,10 +1,11 @@ /** ****************************************************************************** - * @file usb_interface.h + * @file USBHIDComposite.cpp * @author WI6LABS * @version V1.0.0 - * @date 27-October-2016 - * @brief Header for usb interface + * @date 27-July-2016 + * @brief USB HID composite API for Arduino + * ****************************************************************************** * @attention * @@ -35,44 +36,46 @@ ****************************************************************************** */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_INTERFACE_H -#define __USB_INTERFACE_H #ifdef USBCON -/* Includes ------------------------------------------------------------------*/ -#if __has_include("usbd_desc.h") -#include "usbd_desc.h" -#else -#ifdef USBD_USE_HID_COMPOSITE -#error "This board does not support (yet?) USB HID! Select 'None' in the 'Tools->USB interface' menu" -#elif defined(USBD_USE_CDC) -#error "This board does not support (yet?) USB CDC! Select 'None' in the 'Tools->USB interface' menu" -#else -#error "This board does not support (yet?) USB! Select 'None' in the 'Tools->USB interface' menu" -#endif -#endif +#include "usbd_desc_hid_composite.h" #include "usbd_hid_composite.h" +#include "USBHIDComposite.h" + + +USBHIDComposite HID; + +USBHIDComposite::USBHIDComposite(void) +{ + +} -#ifdef __cplusplus - extern "C" { -#endif +void USBHIDComposite::begin(void) +{ + /* Init Device Library */ + USBD_Init(&hUSBD_Device, &HID_Desc, 0); -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported variables --------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -void usbd_interface_init(void); + /* Add Supported Class */ + USBD_RegisterClass(&hUSBD_Device, USBD_COMPOSITE_HID_CLASS); -void usbd_interface_mouse_sendReport(uint8_t *report, uint16_t len); -void usbd_interface_keyboard_sendReport(uint8_t *report, uint16_t len); + /* Start Device Process */ + USBD_Start(&hUSBD_Device); +} -#ifdef __cplusplus +void USBHIDComposite::end(void) +{ + /* Stop Device Process */ + USBD_Stop(&hUSBD_Device); } -#endif -#endif // USBCON -#endif /* __USB_INTERFACE_H */ +void USBHIDComposite::mouseSend(uint8_t *report, uint16_t len) +{ + USBD_HID_MOUSE_SendReport(&hUSBD_Device, report, len); +} + +void USBHIDComposite::keyboardSend(uint8_t *report, uint16_t len) +{ + USBD_HID_KEYBOARD_SendReport(&hUSBD_Device, report, len); +} -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +#endif //USBCON diff --git a/libraries/USBHIDComposite/src/USBHIDComposite.h b/libraries/USBHIDComposite/src/USBHIDComposite.h new file mode 100644 index 0000000000..adab79e8b8 --- /dev/null +++ b/libraries/USBHIDComposite/src/USBHIDComposite.h @@ -0,0 +1,66 @@ +/** + ****************************************************************************** + * @file USBHIDComposite.h + * @author WI6LABS + * @version V1.0.0 + * @date 27-July-2016 + * @brief Header for USB HID composite API + * + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ +#ifndef __USBHIDCOMPOSITE_H +#define __USBHIDCOMPOSITE_H + +#ifndef USBCON +#error "USB not enabled! Select 'USB Enable' in the 'Tools->USB interface' menu." +#else + +#include "usbd_def.h" + +class USBHIDComposite +{ +public: + USBHIDComposite(void); + + void begin(void); + void end(void); + + void mouseSend(uint8_t *report, uint16_t len); + void keyboardSend(uint8_t *report, uint16_t len); + +private: + USBD_HandleTypeDef hUSBD_Device; +}; + +extern USBHIDComposite HID; + +#endif //USBCON + +#endif //__USBHIDCOMPOSITE_H diff --git a/libraries/USBHIDComposite/src/usbd_desc_hid_composite.c b/libraries/USBHIDComposite/src/usbd_desc_hid_composite.c new file mode 100644 index 0000000000..8ca5f27893 --- /dev/null +++ b/libraries/USBHIDComposite/src/usbd_desc_hid_composite.c @@ -0,0 +1,148 @@ +/** + ****************************************************************************** + * @file USB_Device/HID_Standalone/Src/usbd_desc.c + * @author MCD Application Team + * @version V1.0.2 + * @date 06-May-2016 + * @brief This file provides the USBD descriptors and string formatting method. + ****************************************************************************** + * @attention + * + *

© Copyright � 2016 STMicroelectronics International N.V. + * All rights reserved.

+ * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted, provided that the following conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific written permission. + * 4. This software, including modifications and/or derivative works of this + * software, must execute solely and exclusively on microcontroller or + * microprocessor devices manufactured by or for STMicroelectronics. + * 5. Redistribution and use of this software other than as permitted under + * this license is void and will automatically terminate your rights under + * this license. + * + * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY + * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT + * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ +/* Includes ------------------------------------------------------------------*/ +#ifdef USBCON +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_conf.h" +#include "utils.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +#define USBD_HID_PRODUCT_HS_STRING CONCATS(USB_PRODUCT, "HID in HS Mode") +#define USBD_HID_PRODUCT_FS_STRING CONCATS(USB_PRODUCT, "HID in FS Mode") +#define USBD_HID_CONFIGURATION_HS_STRING CONCATS(USB_PRODUCT, "HID Config") +#define USBD_HID_INTERFACE_HS_STRING CONCATS(USB_PRODUCT, "HID Interface") +#define USBD_HID_CONFIGURATION_FS_STRING CONCATS(USB_PRODUCT, "HID Config") +#define USBD_HID_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "HID Interface") + +/* Private macro -------------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static uint8_t *USBD_HID_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); +static uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +static uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +#ifdef USB_SUPPORT_USER_STRING_DESC +static uint8_t *USBD_HID_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); +#endif /* USB_SUPPORT_USER_STRING_DESC */ + +/* Private variables ---------------------------------------------------------*/ +USBD_DescriptorsTypeDef HID_Desc = { + USBD_DeviceDescriptor, + USBD_LangIDStrDescriptor, + USBD_ManufacturerStrDescriptor, + USBD_HID_ProductStrDescriptor, + USBD_SerialStrDescriptor, + USBD_HID_ConfigStrDescriptor, + USBD_HID_InterfaceStrDescriptor, +}; + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +__ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; + +/* Private functions ---------------------------------------------------------*/ +/** + * @brief Returns the product string descriptor. + * @param speed: Current device speed + * @param length: Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t *USBD_HID_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString((uint8_t *)USBD_HID_PRODUCT_HS_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Returns the configuration string descriptor. + * @param speed: Current device speed + * @param length: Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_HS_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Returns the interface string descriptor. + * @param speed: Current device speed + * @param length: Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString((uint8_t *)USBD_HID_INTERFACE_HS_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +#endif // USBCON +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libraries/USBHIDComposite/src/usbd_desc_hid_composite.h b/libraries/USBHIDComposite/src/usbd_desc_hid_composite.h new file mode 100644 index 0000000000..c9fd21a18d --- /dev/null +++ b/libraries/USBHIDComposite/src/usbd_desc_hid_composite.h @@ -0,0 +1,64 @@ +/** + ****************************************************************************** + * @file USB_Device/HID_Standalone/Inc/usbd_desc.h + * @author MCD Application Team + * @version V1.0.2 + * @date 06-May-2016 + * @brief Header for usbd_desc.c module + ****************************************************************************** + * @attention + * + *

© Copyright © 2016 STMicroelectronics International N.V. + * All rights reserved.

+ * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted, provided that the following conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific written permission. + * 4. This software, including modifications and/or derivative works of this + * software, must execute solely and exclusively on microcontroller or + * microprocessor devices manufactured by or for STMicroelectronics. + * 5. Redistribution and use of this software other than as permitted under + * this license is void and will automatically terminate your rights under + * this license. + * + * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY + * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT + * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_DESC_HID_COMPOSITE_H +#define __USBD_DESC_HID_COMPOSITE_H + +#ifdef USBCON +/* Includes ------------------------------------------------------------------*/ +#include "usbd_def.h" + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +extern USBD_DescriptorsTypeDef HID_Desc; + +#endif // USBCON +#endif /* __USBD_DESC_HID_COMPOSITE_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/usbd_hid_composite.c b/libraries/USBHIDComposite/src/usbd_hid_composite.c similarity index 96% rename from cores/arduino/stm32/usbd_hid_composite.c rename to libraries/USBHIDComposite/src/usbd_hid_composite.c index c9f28a540a..045f0b9026 100644 --- a/cores/arduino/stm32/usbd_hid_composite.c +++ b/libraries/USBHIDComposite/src/usbd_hid_composite.c @@ -47,7 +47,6 @@ */ #ifdef USBCON -#ifdef USBD_USE_HID_COMPOSITE /* Includes ------------------------------------------------------------------*/ #include "usbd_hid_composite.h" @@ -369,6 +368,7 @@ __ALIGN_BEGIN static uint8_t HID_KEYBOARD_ReportDesc[HID_KEYBOARD_REPORT_DESC_SI static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { + UNUSED(cfgidx); uint8_t ret = 0; /* Open EP IN */ @@ -407,6 +407,8 @@ static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { + UNUSED(cfgidx); + /* Close HID EPs */ USBD_LL_CloseEP(pdev, HID_MOUSE_EPIN_ADDR); @@ -585,7 +587,7 @@ static uint8_t USBD_HID_KEYBOARD_Setup (USBD_HandleTypeDef *pdev, } else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE) { - pbuf = USBD_MOUSE_HID_Desc; + pbuf = USBD_KEYBOARD_HID_Desc; len = MIN(USB_HID_DESC_SIZ , req->wLength); } @@ -741,6 +743,6 @@ static uint8_t *USBD_HID_GetDeviceQualifierDesc (uint16_t *length) *length = sizeof (USBD_HID_DeviceQualifierDesc); return USBD_HID_DeviceQualifierDesc; } -#endif // USBD_USE_HID_COMPOSITE + #endif // USBCON /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/cores/arduino/stm32/usbd_hid_composite.h b/libraries/USBHIDComposite/src/usbd_hid_composite.h similarity index 94% rename from cores/arduino/stm32/usbd_hid_composite.h rename to libraries/USBHIDComposite/src/usbd_hid_composite.h index 39d870f116..410a201fd0 100644 --- a/cores/arduino/stm32/usbd_hid_composite.h +++ b/libraries/USBHIDComposite/src/usbd_hid_composite.h @@ -30,7 +30,6 @@ #define __USB_HID_COMPOSITE_H #ifdef USBCON -#ifdef USBD_USE_HID_COMPOSITE #ifdef __cplusplus extern "C" { @@ -146,7 +145,6 @@ uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev); } #endif -#endif // USBD_USE_HID_COMPOSITE #endif // USBCON #endif /* __USB_HID_COMPOSITE_H */ /** diff --git a/libraries/USBSerial/examples/USBSerial/USBSerial.ino b/libraries/USBSerial/examples/USBSerial/USBSerial.ino new file mode 100644 index 0000000000..c7813635e8 --- /dev/null +++ b/libraries/USBSerial/examples/USBSerial/USBSerial.ino @@ -0,0 +1,16 @@ +#include + +void setup() { + // Default baudrate is set to 9600 + SerialUSB.begin(); +} + +void loop() { + SerialUSB.println("Hello world!"); + delay(1000); + + while(SerialUSB.available()) { + char c = SerialUSB.read(); + SerialUSB.print(c); + } +} diff --git a/libraries/USBSerial/library.properties b/libraries/USBSerial/library.properties new file mode 100644 index 0000000000..26b31a4254 --- /dev/null +++ b/libraries/USBSerial/library.properties @@ -0,0 +1,9 @@ +name=USB Serial +version=1.0.0 +author=Wi6Labs +maintainer=STMicroelectronics +sentence=Provides USB CDC class. +paragraph= +category=Device Control +url=https://github.com/stm32duino/Arduino_Core_STM32 +architectures=stm32 diff --git a/libraries/USBSerial/src/USBSerial.cpp b/libraries/USBSerial/src/USBSerial.cpp new file mode 100644 index 0000000000..fe55e4debf --- /dev/null +++ b/libraries/USBSerial/src/USBSerial.cpp @@ -0,0 +1,244 @@ +/****************************************************************************** + * The MIT License + * + * Copyright (c) 2010 Perry Hung. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + *****************************************************************************/ + +/** + * @brief USB virtual serial terminal + */ + + /* + * Arduino srl - www.arduino.org + * 2016 Jun 9: Edited Francesco Alessi (alfran) - francesco@arduino.org + */ + +#ifdef USBCON + +#include + +#include "wiring.h" +#include "USBSerial.h" +#include "usbd_desc.h" +#include "usbd_desc_cdc.h" +#include "usbd_cdc.h" +#include "usbd_cdc_if.h" + +#define USB_TIMEOUT 50 +/* USB Device Core handle declaration */ +USBD_HandleTypeDef hUSBD_Device_CDC; +extern __IO uint32_t device_connection_status; +extern __IO uint32_t lineState; +extern __IO uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; +extern __IO uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; +extern __IO uint32_t UserTxBufPtrIn; +extern __IO uint32_t UserTxBufPtrOut; +extern __IO uint32_t UserRxBufPtrIn; +extern __IO uint32_t UserRxBufPtrOut; +__IO uint32_t usbEnableBlockingTx; + +USBSerial SerialUSB; + + +USBSerial::USBSerial(void) { +} + +/* USBSerial is always available and instantiated in main.cpp */ +void USBSerial::begin(void) { + if (USBD_Init(&hUSBD_Device_CDC, &CDC_Desc, DEVICE_FS) == USBD_OK) { + + /* Add Supported Class */ + if (USBD_RegisterClass(&hUSBD_Device_CDC, USBD_CDC_CLASS) == USBD_OK) { + + /* Add CDC Interface Class */ + if (USBD_CDC_RegisterInterface(&hUSBD_Device_CDC, &USBD_Interface_fops_FS) == USBD_OK) { + + /* Start Device Process */ + USBD_Start(&hUSBD_Device_CDC); + } + } + } +} + +void USBSerial::begin(int) { + if (USBD_Init(&hUSBD_Device_CDC, &CDC_Desc, DEVICE_FS) == USBD_OK) { + + /* Add Supported Class */ + if (USBD_RegisterClass(&hUSBD_Device_CDC, USBD_CDC_CLASS) == USBD_OK) { + + /* Add CDC Interface Class */ + if (USBD_CDC_RegisterInterface(&hUSBD_Device_CDC, &USBD_Interface_fops_FS) == USBD_OK) { + + /* Start Device Process */ + USBD_Start(&hUSBD_Device_CDC); + } + } + } +} + +void USBSerial::end(void) { + + USBD_LL_DeInit(&hUSBD_Device_CDC); +} + +int USBSerial::availableForWrite(void) +{ + int ret_val; + + /* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */ + /* value that we read is correct, we need to disable TIM Interrupt. */ + CDC_disable_TIM_Interrupt(); + + if(UserTxBufPtrIn >= UserTxBufPtrOut) + { + ret_val = (APP_TX_DATA_SIZE - 1 - UserTxBufPtrIn + UserTxBufPtrOut); + } else + { + ret_val = (UserTxBufPtrOut - UserTxBufPtrIn - 1); + } + + CDC_enable_TIM_Interrupt(); + + return ret_val; +} + +size_t USBSerial::write(uint8_t ch) { + + /* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */ + /* value that we read is correct, we need to disable TIM Interrupt. */ + CDC_disable_TIM_Interrupt(); + + if(((UserTxBufPtrIn + 1) % APP_TX_DATA_SIZE) == UserTxBufPtrOut) + { + // Buffer full!!! Force a flush to not loose data and go on + CDC_flush(); + } + UserTxBufferFS[UserTxBufPtrIn] = ch; + UserTxBufPtrIn = ((UserTxBufPtrIn + 1) % APP_TX_DATA_SIZE); + + CDC_enable_TIM_Interrupt(); + + return 1; +} + +int USBSerial::available(void) { + int ret; + + CDC_disable_TIM_Interrupt(); + ret = ((APP_RX_DATA_SIZE + (UserRxBufPtrIn - UserRxBufPtrOut)) % APP_RX_DATA_SIZE); + CDC_enable_TIM_Interrupt(); + + return ret; +} + +int USBSerial::read(void) { + /* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */ + /* value that we read is correct, we need to disable TIM Interrupt. */ + CDC_disable_TIM_Interrupt(); + if(UserRxBufPtrOut == UserRxBufPtrIn) + { + CDC_enable_TIM_Interrupt(); + return -1; + } else + { + unsigned char c = UserRxBufferFS[UserRxBufPtrOut]; + UserRxBufPtrOut = ((UserRxBufPtrOut + 1) % APP_RX_DATA_SIZE); + CDC_enable_TIM_Interrupt(); + return c; + } +} + +int USBSerial::peek(void) +{ + /* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */ + /* value that we read is correct, we need to disable TIM Interrupt. */ + CDC_disable_TIM_Interrupt(); + if(UserRxBufPtrOut == UserRxBufPtrIn) + { + CDC_enable_TIM_Interrupt(); + return -1; + } else + { + unsigned char c = UserRxBufferFS[UserRxBufPtrOut]; + CDC_enable_TIM_Interrupt(); + return c; + } +} + +void USBSerial::flush(void) +{ + /* UserTxBufPtrOut can be modified by TIM ISR, so in order to be sure that the */ + /* value that we read is correct, we need to disable TIM Interrupt. */ + CDC_disable_TIM_Interrupt(); + CDC_flush(); + CDC_enable_TIM_Interrupt(); + +#if 0 + /* Flush EP1 for data IN */ + USBD_LL_FlushEP(&hUSBD_Device_CDC, CDC_IN_EP); + /* Flush EP1 for data OUT */ + USBD_LL_FlushEP(&hUSBD_Device_CDC, CDC_IN_EP); + /* Flush EP1 for CDC commands */ + USBD_LL_FlushEP(&hUSBD_Device_CDC, CDC_IN_EP); + + return; +#endif + +} + +uint8_t USBSerial::pending(void) { +// return usbGetPending(); // No equivalent in HAL + return 0; +} + +uint8_t USBSerial::isConnected(void) { + + if(device_connection_status == 1) + { + return 1; + } + else + { + return 0; + } +} + +uint8_t USBSerial::getDTR(void) { +// return usbGetDTR(); + return 0; +} + +uint8_t USBSerial::getRTS(void) { +// return usbGetRTS(); + return 0; +} + +USBSerial::operator bool() { + bool result = false; + if (lineState == 1) + result = true; + delay(10); + return result; +} + +#endif // USBCON diff --git a/libraries/USBSerial/src/USBSerial.h b/libraries/USBSerial/src/USBSerial.h new file mode 100644 index 0000000000..29f3500a9b --- /dev/null +++ b/libraries/USBSerial/src/USBSerial.h @@ -0,0 +1,80 @@ +/****************************************************************************** + * The MIT License + * + * Copyright (c) 2010 Perry Hung. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + *****************************************************************************/ + +/** + * @brief Wirish virtual serial port + */ + + /* + * Arduino srl - www.arduino.org + * 2016 Jun 9: Edited Francesco Alessi (alfran) - francesco@arduino.org + */ + +#ifndef _USB_SERIAL_H_ +#define _USB_SERIAL_H_ + +#if !defined (USBCON) +#warning "Using legacy CDC core (non pluggable)" +#else +#include "Stream.h" +#include "usbd_core.h" + +/** + * @brief Virtual serial terminal. + */ +class USBSerial : public Stream { +public: + USBSerial(void); + + void begin(void); + void begin(int); + void end(void); + + virtual int available(void); + virtual int peek(void); + virtual void flush(void); + virtual int read(void); + + int availableForWrite(void); + virtual size_t write(uint8_t); + inline size_t write(unsigned long n) { return write((uint8_t)n); } + inline size_t write(long n) { return write((uint8_t)n); } + inline size_t write(unsigned int n) { return write((uint8_t)n); } + inline size_t write(int n) { return write((uint8_t)n); } + using Print::write; + + uint8_t getRTS(); + uint8_t getDTR(); + uint8_t isConnected(); + uint8_t pending(); + + virtual operator bool(void); + +}; + +extern USBSerial SerialUSB; +#endif +#endif diff --git a/libraries/USBSerial/src/usb_device_cdc.c b/libraries/USBSerial/src/usb_device_cdc.c new file mode 100644 index 0000000000..9ce6bc71c3 --- /dev/null +++ b/libraries/USBSerial/src/usb_device_cdc.c @@ -0,0 +1,26 @@ +/* + * + * + * Copyright (C) 2017, STMicroelectronics - All Rights Reserved + * Author: YOUR NAME <> for STMicroelectronics. + * + * License type: GPLv2 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see + * . + */ +#ifdef USBCON + +#include "usbd_cdc.c" + +#endif //USBCON diff --git a/libraries/USBSerial/src/usbd_cdc_if.c b/libraries/USBSerial/src/usbd_cdc_if.c new file mode 100644 index 0000000000..29d62e5837 --- /dev/null +++ b/libraries/USBSerial/src/usbd_cdc_if.c @@ -0,0 +1,434 @@ +/** + ****************************************************************************** + * @file : usbd_cdc_if.c + * @brief : + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** +*/ +#ifdef USBCON + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc_if.h" +#include "stm32_def.h" + +#ifdef __cplusplus + extern "C" { +#endif + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_CDC + * @brief usbd core module + * @{ + */ + +/** @defgroup USBD_CDC_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Defines + * @{ + */ +/* Define size for the receive and transmit buffer over CDC */ +/* It's up to user to redefine and/or remove those define */ +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Variables + * @{ + */ +/* Create buffer for reception and transmission */ +/* It's up to user to redefine and/or remove those define */ +extern USBD_HandleTypeDef hUSBD_Device_CDC; +/* Received Data over USB are stored in this buffer */ +__IO uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; +__IO uint8_t StackRxBufferFS[APP_RX_DATA_SIZE]; + +/* Send Data over USB CDC are stored in this buffer */ +__IO uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; +__IO uint8_t StackTxBufferFS[APP_TX_DATA_SIZE]; + +__IO uint32_t UserTxBufPtrIn = 0; /* Increment this pointer or roll it back to + start address when data are received over write call */ +__IO uint32_t UserTxBufPtrOut = 0; /* Increment this pointer or roll it back to + start address when data are sent over USB */ + +__IO uint32_t UserRxBufPtrIn = 0; /* Increment this pointer or roll it back to + start address when data are received over USB */ +__IO uint32_t UserRxBufPtrOut = 0; /* Increment this pointer or roll it back to + start address when data are sent over read call */ + +__IO uint32_t SLP; +__IO uint32_t GetRxCount; +__IO uint32_t lineState = 0; +uint8_t cptlineState = 0; +volatile uint32_t USB_received = 0; +uint8_t USBBuffer[64]; +uint8_t USBPackSize; + +/* Default configuration: 115200, 8N1 */ +uint8_t lineSetup[] = {0x00, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x08}; + +#define CDC_POLLING_INTERVAL 2 /* in ms. The max is 65 and the min is 1 */ + +stimer_t TimHandle; + +static void TIM_Config(void); + +/* USB handler declaration */ +/* Handle for USB Full Speed IP */ +// USBD_HandleTypeDef *hUsbDevice_0; + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Variables + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_FunctionPrototypes + * @{ + */ +static int8_t CDC_Init_FS (void); +static int8_t CDC_DeInit_FS (void); +static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length); +static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len); + +/** + * @} + */ + +USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = +{ + CDC_Init_FS, + CDC_DeInit_FS, + CDC_Control_FS, + CDC_Receive_FS +}; + +/* Private functions ---------------------------------------------------------*/ +/** + * @brief CDC_Init_FS + * Initializes the CDC media low layer over the FS USB IP + * @param None + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Init_FS(void) +{ + /*##-3- Configure and start the TIM Base generation #################################*/ + TIM_Config(); + + /* Set Application Buffers */ + USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, (uint8_t *)UserTxBufferFS, 1); + USBD_CDC_SetRxBuffer(&hUSBD_Device_CDC, (uint8_t *)StackRxBufferFS); + + return (USBD_OK); +} + +/** + * @brief CDC_DeInit_FS + * DeInitializes the CDC media low layer + * @param None + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_DeInit_FS(void) +{ + return (USBD_OK); +} + +/** + * @brief CDC_Control_FS + * Manage the CDC class requests + * @param cmd: Command code + * @param pbuf: Buffer containing command data (request parameters) + * @param length: Number of data to be sent (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length) +{ + UNUSED(length); + switch (cmd) + { + case CDC_SEND_ENCAPSULATED_COMMAND: + + break; + + case CDC_GET_ENCAPSULATED_RESPONSE: + + break; + + case CDC_SET_COMM_FEATURE: + + break; + + case CDC_GET_COMM_FEATURE: + + break; + + case CDC_CLEAR_COMM_FEATURE: + + break; + + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ + /*******************************************************************************/ + case CDC_SET_LINE_CODING: + memcpy(lineSetup, pbuf, 7); + break; + + case CDC_GET_LINE_CODING: + memcpy(pbuf, lineSetup, 7); + break; + + case CDC_SET_CONTROL_LINE_STATE: + cptlineState++; + if(cptlineState == 2) + lineState = 1; + break; + + case CDC_SEND_BREAK: + + break; + + default: + break; + } + + return (USBD_OK); +} + +/** + * @brief CDC_Receive_FS + * Data received over USB OUT endpoint are sent over CDC interface + * through this function. + * + * @note + * This function will block any OUT packet reception on USB endpoint + * untill exiting this function. If you exit this function before transfer + * is complete on CDC interface (ie. using DMA controller) it will result + * in receiving more data while previous ones are still not sent. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ + +static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len) +{ + /* Initiate next USB packet transfer once a packet is received */ + USBPackSize = *Len; + memcpy(USBBuffer, Buf, USBPackSize); + + USB_received = 1; + return (USBD_OK); +} + +/** + * @brief CDC_Transmit_FS + * Data send over USB IN endpoint are sent over CDC interface + * through this function. + * @note + * + * + * @param Buf: Buffer of data to be send + * @param Len: Number of data to be send (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) +{ + UNUSED(Buf); + uint8_t result = USBD_OK; + UNUSED(Len); + USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, (uint8_t *)UserTxBufferFS, 1); + result = USBD_CDC_TransmitPacket(&hUSBD_Device_CDC); + return result; +} + +void CDC_flush(void) +{ + uint8_t status; + + if(UserTxBufPtrOut != UserTxBufPtrIn) + { + if(UserTxBufPtrOut > UserTxBufPtrIn) /* Roll-back */ + { + memcpy((uint8_t*)&StackTxBufferFS[0], (uint8_t*)&UserTxBufferFS[UserTxBufPtrOut], (APP_TX_DATA_SIZE - UserTxBufPtrOut)); + + memcpy((uint8_t*)&StackTxBufferFS[APP_TX_DATA_SIZE - UserTxBufPtrOut], (uint8_t*)&UserTxBufferFS[0], UserTxBufPtrIn); + + USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, (uint8_t*)&StackTxBufferFS[0], (APP_TX_DATA_SIZE - UserTxBufPtrOut + UserTxBufPtrIn)); + + do { + status = USBD_CDC_TransmitPacket(&hUSBD_Device_CDC); + } while(status == USBD_BUSY); + + if(status == USBD_OK) + { + UserTxBufPtrOut = UserTxBufPtrIn; + } + } + else + { + USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, (uint8_t*)&UserTxBufferFS[UserTxBufPtrOut], (UserTxBufPtrIn - UserTxBufPtrOut)); + + do { + status = USBD_CDC_TransmitPacket(&hUSBD_Device_CDC); + } while(status == USBD_BUSY); + + if(status == USBD_OK) + { + UserTxBufPtrOut = UserTxBufPtrIn; + } + } + } +} + +void CDC_disable_TIM_Interrupt(void) +{ + HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn); +} + +void CDC_enable_TIM_Interrupt(void) +{ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); +} + +static void TIM_Config(void) +{ + /* Set TIMx instance */ + TimHandle.timer = TIM6; + /* Initialize TIM6 peripheral as follow: + + Period = 10000 - 1 + + Prescaler = ((SystemCoreClock/2)/10000) - 1 + + ClockDivision = 0 + + Counter direction = Up + */ + TimerHandleInit(&TimHandle, (uint16_t)((CDC_POLLING_INTERVAL*1000) - 1), ((uint32_t)(getTimerClkFreq(TIM6) / (1000000)) - 1)); //CDC_POLLING_INTERVAL + + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 6, 0); + + timer_attach_interrupt_handle(&TimHandle.handle, TIM6_PeriodElapsedCallback); +} + +void TIM6_PeriodElapsedCallback(stimer_t *htim) +{ + UNUSED(htim); + uint8_t status; + + if(USB_received) { + USB_received = 0; + + if((USBPackSize > 0)) { + if(UserRxBufPtrIn + USBPackSize > APP_RX_DATA_SIZE) { + memcpy(((uint8_t *)UserRxBufferFS+UserRxBufPtrIn), &USBBuffer[0], (APP_RX_DATA_SIZE - UserRxBufPtrIn)); + memcpy((uint8_t *)UserRxBufferFS, &USBBuffer[(APP_RX_DATA_SIZE - UserRxBufPtrIn)], (USBPackSize - (APP_RX_DATA_SIZE - UserRxBufPtrIn))); + UserRxBufPtrIn = ((UserRxBufPtrIn + USBPackSize) % APP_RX_DATA_SIZE); + } else { + memcpy(((uint8_t *)UserRxBufferFS+UserRxBufPtrIn), USBBuffer, USBPackSize); + UserRxBufPtrIn = ((UserRxBufPtrIn + USBPackSize) % APP_RX_DATA_SIZE); + } + } + + USBD_CDC_ReceivePacket(&hUSBD_Device_CDC); + } + + if(UserTxBufPtrOut != UserTxBufPtrIn) { + if(UserTxBufPtrOut > UserTxBufPtrIn) { /* Roll-back */ + memcpy((uint8_t*)&StackTxBufferFS[0], (uint8_t*)&UserTxBufferFS[UserTxBufPtrOut], (APP_TX_DATA_SIZE - UserTxBufPtrOut)); + + memcpy((uint8_t*)&StackTxBufferFS[APP_TX_DATA_SIZE - UserTxBufPtrOut], (uint8_t*)&UserTxBufferFS[0], UserTxBufPtrIn); + + USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, (uint8_t*)&StackTxBufferFS[0], (APP_TX_DATA_SIZE - UserTxBufPtrOut + UserTxBufPtrIn)); + + do { + status = USBD_CDC_TransmitPacket(&hUSBD_Device_CDC); + } while(status == USBD_BUSY); + + if(status == USBD_OK) { + UserTxBufPtrOut = UserTxBufPtrIn; + } + } + else { + USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, (uint8_t*)&UserTxBufferFS[UserTxBufPtrOut], (UserTxBufPtrIn - UserTxBufPtrOut)); + + do { + status = USBD_CDC_TransmitPacket(&hUSBD_Device_CDC); + } while(status == USBD_BUSY); + + if(status == USBD_OK) { + UserTxBufPtrOut = UserTxBufPtrIn; + } + } + } +} + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif // USBCON +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libraries/USBSerial/src/usbd_cdc_if.h b/libraries/USBSerial/src/usbd_cdc_if.h new file mode 100644 index 0000000000..20a9e8bfc3 --- /dev/null +++ b/libraries/USBSerial/src/usbd_cdc_if.h @@ -0,0 +1,117 @@ +/** + ****************************************************************************** + * @file : usbd_cdc_if.h + * @brief : Header for usbd_cdc_if file. + ****************************************************************************** + * COPYRIGHT(c) 2016 STMicroelectronics + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** +*/ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CDC_IF_H +#define __USBD_CDC_IF_H + +#ifdef USBCON + +#ifdef __cplusplus + extern "C" { +#endif +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc.h" +#include "timer.h" + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_CDC_IF + * @brief header + * @{ + */ + +/** @defgroup USBD_CDC_IF_Exported_Defines + * @{ + */ +#define APP_RX_DATA_SIZE 256 +#define APP_TX_DATA_SIZE 256 + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Types + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Macros + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Variables + * @{ + */ +extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype + * @{ + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); + +void CDC_flush(void); +void CDC_disable_TIM_Interrupt(void); +void CDC_enable_TIM_Interrupt(void); +void TIM6_PeriodElapsedCallback(stimer_t *htim); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif +#endif // USBCON +#endif /* __USBD_CDC_IF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libraries/USBSerial/src/usbd_desc_cdc.c b/libraries/USBSerial/src/usbd_desc_cdc.c new file mode 100644 index 0000000000..9bc64aae14 --- /dev/null +++ b/libraries/USBSerial/src/usbd_desc_cdc.c @@ -0,0 +1,197 @@ +/** + ****************************************************************************** + * @file USB_Device/HID_Standalone/Src/usbd_desc.c + * @author MCD Application Team + * @version V1.0.2 + * @date 06-May-2016 + * @brief This file provides the USBD descriptors and string formatting method. + ****************************************************************************** + * @attention + * + *

© Copyright � 2016 STMicroelectronics International N.V. + * All rights reserved.

+ * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted, provided that the following conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific written permission. + * 4. This software, including modifications and/or derivative works of this + * software, must execute solely and exclusively on microcontroller or + * microprocessor devices manufactured by or for STMicroelectronics. + * 5. Redistribution and use of this software other than as permitted under + * this license is void and will automatically terminate your rights under + * this license. + * + * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY + * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT + * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ +/* Includes ------------------------------------------------------------------*/ +#ifdef USBCON +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_conf.h" +#include "utils.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +#define USBD_CDC_PRODUCT_HS_STRING CONCATS(USB_PRODUCT, "CDC in HS Mode") +#define USBD_CDC_PRODUCT_FS_STRING CONCATS(USB_PRODUCT, "CDC in FS Mode") +#define USBD_CDC_CONFIGURATION_HS_STRING CONCATS(USB_PRODUCT, "CDC Config") +#define USBD_CDC_INTERFACE_HS_STRING CONCATS(USB_PRODUCT, "CDC Interface") +#define USBD_CDC_CONFIGURATION_FS_STRING CONCATS(USB_PRODUCT, "CDC Config") +#define USBD_CDC_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "CDC Interface") +#define USBD_CDC_SERIALNUMBER_HS_STRING "00000000001A" +#define USBD_CDC_SERIALNUMBER_FS_STRING "00000000001A" +#define USB_SIZ_BOS_DESC 0x0C + +/* Private macro -------------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static uint8_t *USBD_CDC_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); +static uint8_t *USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +static uint8_t *USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +#ifdef USB_SUPPORT_USER_STRING_DESC +static uint8_t *USBD_CDC_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); +#endif /* USB_SUPPORT_USER_STRING_DESC */ + +#if (USBD_LPM_ENABLED == 1) +uint8_t *USBD_CDC_USR_BOSDescriptor(USBD_SpeedTypeDef speed , uint16_t *length); +#endif + +/* Private variables ---------------------------------------------------------*/ +USBD_DescriptorsTypeDef CDC_Desc = +{ + USBD_DeviceDescriptor, + USBD_LangIDStrDescriptor, + USBD_ManufacturerStrDescriptor, + USBD_CDC_ProductStrDescriptor, + USBD_SerialStrDescriptor, + USBD_CDC_ConfigStrDescriptor, + USBD_CDC_InterfaceStrDescriptor, +#if (USBD_LPM_ENABLED == 1) + USBD_CDC_USR_BOSDescriptor, +#endif +}; + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +__ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; + +/* BOS descriptor */ +#if (USBD_LPM_ENABLED == 1) +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +__ALIGN_BEGIN uint8_t USBD_CDC_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = { + 0x5, + USB_DESC_TYPE_BOS, + 0xC, + 0x0, + 0x1, /* 1 device capability */ + /* device capability*/ + 0x7, + USB_DEVICE_CAPABITY_TYPE, + 0x2, + 0x2, /*LPM capability bit set */ + 0x0, + 0x0, + 0x0 +}; +#endif + +/* Private functions ---------------------------------------------------------*/ +/** + * @brief Returns the product string descriptor. + * @param speed: Current device speed + * @param length: Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t *USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString((uint8_t *)USBD_CDC_PRODUCT_HS_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_CDC_PRODUCT_FS_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Returns the configuration string descriptor. + * @param speed: Current device speed + * @param length: Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t *USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString((uint8_t *)USBD_CDC_CONFIGURATION_HS_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_CDC_CONFIGURATION_FS_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Returns the interface string descriptor. + * @param speed: Current device speed + * @param length: Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t *USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString((uint8_t *)USBD_CDC_INTERFACE_HS_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_CDC_INTERFACE_FS_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +#if (USBD_LPM_ENABLED == 1) +/** + * @brief USBD_CDC_USR_BOSDescriptor + * return the BOS descriptor + * @param speed : current device speed + * @param length : pointer to data length variable + * @retval pointer to descriptor buffer + */ +uint8_t *USBD_CDC_USR_BOSDescriptor(USBD_SpeedTypeDef speed , uint16_t *length) +{ + UNUSED(speed); + *length = sizeof(USBD_CDC_BOSDesc); + return (uint8_t*)USBD_CDC_BOSDesc; + } +#endif + +#endif // USBCON +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libraries/USBSerial/src/usbd_desc_cdc.h b/libraries/USBSerial/src/usbd_desc_cdc.h new file mode 100644 index 0000000000..4389f576f6 --- /dev/null +++ b/libraries/USBSerial/src/usbd_desc_cdc.h @@ -0,0 +1,64 @@ +/** + ****************************************************************************** + * @file USB_Device/HID_Standalone/Inc/usbd_desc.h + * @author MCD Application Team + * @version V1.0.2 + * @date 06-May-2016 + * @brief Header for usbd_desc.c module + ****************************************************************************** + * @attention + * + *

© Copyright © 2016 STMicroelectronics International N.V. + * All rights reserved.

+ * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted, provided that the following conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of other + * contributors to this software may be used to endorse or promote products + * derived from this software without specific written permission. + * 4. This software, including modifications and/or derivative works of this + * software, must execute solely and exclusively on microcontroller or + * microprocessor devices manufactured by or for STMicroelectronics. + * 5. Redistribution and use of this software other than as permitted under + * this license is void and will automatically terminate your rights under + * this license. + * + * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY + * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT + * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_DESC_CDC_H +#define __USBD_DESC_CDC_H + +#ifdef USBCON +/* Includes ------------------------------------------------------------------*/ +#include "usbd_def.h" + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +extern USBD_DescriptorsTypeDef CDC_Desc; + +#endif // USBCON +#endif /* __USBD_DESC_CDC_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/platform.txt b/platform.txt index c510765c19..0336970d84 100644 --- a/platform.txt +++ b/platform.txt @@ -10,9 +10,7 @@ version=1.0.0 # STM compile variables # ---------------------- -compiler.stm.extra_include="-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.variant.path}/Ethernet" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" - -# "-I{build.system.path}/Drivers/BSP/Components" "-I{build.system.path}/Middlewares/Third_Party/FatFs/src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc" +compiler.stm.extra_include="-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.variant.path}/Ethernet" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" compiler.warning_flags=-w compiler.warning_flags.none=-w diff --git a/variants/DISCO_F407VG/usb/usbd_conf.c b/variants/DISCO_F407VG/usb/usbd_conf.c index aaf87de770..5fc74a9931 100644 --- a/variants/DISCO_F407VG/usb/usbd_conf.c +++ b/variants/DISCO_F407VG/usb/usbd_conf.c @@ -129,6 +129,8 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) */ void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) { + UNUSED(hpcd); + /* Disable USB FS Clock */ __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); __HAL_RCC_SYSCFG_CLK_DISABLE(); diff --git a/variants/DISCO_F407VG/usb/usbd_conf.h b/variants/DISCO_F407VG/usb/usbd_conf.h index cda1a9588e..7dc197a6a3 100644 --- a/variants/DISCO_F407VG/usb/usbd_conf.h +++ b/variants/DISCO_F407VG/usb/usbd_conf.h @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file USB_Device/HID_Standalone/Inc/usbd_conf.h + * @file usbd_conf.h * @author MCD Application Team * @version V1.0.2 * @date 06-May-2016 @@ -45,9 +45,11 @@ ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CONF_H -#define __USBD_CONF_H - +#ifndef __USBD_CONF__H__ +#define __USBD_CONF__H__ +#ifdef __cplusplus + extern "C" { +#endif /* Includes ------------------------------------------------------------------*/ #include "stm32_def.h" #include @@ -57,23 +59,31 @@ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ -#define USBD_LPM_ENABLED 0 +#define USBD_LPM_ENABLED 0 /* Common Config */ #define USBD_MAX_NUM_INTERFACES 1 #define USBD_MAX_NUM_CONFIGURATION 1 -#define USBD_MAX_STR_DESC_SIZ 0x100 +#define USBD_MAX_STR_DESC_SIZ 512 #define USBD_SUPPORT_USER_STRING 0 #define USBD_SELF_POWERED 1 -#define USBD_DEBUG_LEVEL 3 +#define USBD_DEBUG_LEVEL 0 +#define USBD_CDC_INTERVAL 1000 + /* Exported macro ------------------------------------------------------------*/ +/****************************************/ +/* #define for FS and HS identification */ +#define DEVICE_FS 0 +#define DEVICE_HS 1 /* Memory management macros */ #define USBD_malloc malloc #define USBD_free free #define USBD_memset memset #define USBD_memcpy memcpy +#define USBD_Delay HAL_Delay + /* DEBUG macros */ #if (USBD_DEBUG_LEVEL > 0) #define USBD_UsrLog(...) printf(__VA_ARGS__);\ @@ -101,7 +111,11 @@ /* Exported functions ------------------------------------------------------- */ +#ifdef __cplusplus +} +#endif + #endif // USBCON -#endif /* __USBD_CONF_H */ +#endif //__USBD_CONF__H__ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/DISCO_F407VG/usb/usbd_desc.c b/variants/DISCO_F407VG/usb/usbd_desc.c index 57da7a4f77..1a3b3e543f 100644 --- a/variants/DISCO_F407VG/usb/usbd_desc.c +++ b/variants/DISCO_F407VG/usb/usbd_desc.c @@ -44,8 +44,8 @@ * ****************************************************************************** */ -#ifdef USBCON /* Includes ------------------------------------------------------------------*/ +#ifdef USBCON #include "usbd_core.h" #include "usbd_desc.h" #include "usbd_conf.h" @@ -68,39 +68,10 @@ #else #define USBD_MANUFACTURER_STRING USB_MANUFACTURER #endif -#ifdef USBD_USE_HID_COMPOSITE -#define USBD_HID_PRODUCT_HS_STRING CONCATS(USB_PRODUCT, "HID in HS Mode") -#define USBD_HID_PRODUCT_FS_STRING CONCATS(USB_PRODUCT, "HID in FS Mode") -#define USBD_HID_CONFIGURATION_HS_STRING CONCATS(USB_PRODUCT, "HID Config") -#define USBD_HID_INTERFACE_HS_STRING CONCATS(USB_PRODUCT, "HID Interface") -#define USBD_HID_CONFIGURATION_FS_STRING CONCATS(USB_PRODUCT, "HID Config") -#define USBD_HID_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "HID Interface") /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ -static uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -#ifdef USB_SUPPORT_USER_STRING_DESC -static uint8_t *USBD_HID_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); -#endif /* USB_SUPPORT_USER_STRING_DESC */ - /* Private variables ---------------------------------------------------------*/ -USBD_DescriptorsTypeDef HID_Desc = { - USBD_HID_DeviceDescriptor, - USBD_HID_LangIDStrDescriptor, - USBD_HID_ManufacturerStrDescriptor, - USBD_HID_ProductStrDescriptor, - USBD_HID_SerialStrDescriptor, - USBD_HID_ConfigStrDescriptor, - USBD_HID_InterfaceStrDescriptor, -}; -#endif //USBD_USE_HID_COMPOSITE - /* USB Standard Device Descriptor */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 @@ -152,15 +123,16 @@ __ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len); static void Get_SerialNum(void); -#ifdef USBD_USE_HID_COMPOSITE /** * @brief Returns the device descriptor. * @param speed: Current device speed * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + *length = sizeof(USBD_DeviceDesc); return (uint8_t*)USBD_DeviceDesc; } @@ -171,39 +143,24 @@ uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + *length = sizeof(USBD_LangIDDesc); return (uint8_t*)USBD_LangIDDesc; } -/** - * @brief Returns the product string descriptor. - * @param speed: Current device speed - * @param length: Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t *USBD_HID_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_HID_PRODUCT_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - /** * @brief Returns the manufacturer string descriptor. * @param speed: Current device speed * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); return USBD_StrDesc; } @@ -214,8 +171,10 @@ uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + *length = USB_SIZ_STRING_SERIAL; /* Update the serial number string descriptor with the data from the unique ID*/ @@ -224,44 +183,6 @@ uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) return (uint8_t*)USBD_StringSerial; } -/** - * @brief Returns the configuration string descriptor. - * @param speed: Current device speed - * @param length: Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Returns the interface string descriptor. - * @param speed: Current device speed - * @param length: Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_HID_INTERFACE_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} -#endif //USBD_USE_HID_COMPOSITE /** * @brief Create the serial number string descriptor * @param None diff --git a/variants/DISCO_F407VG/usb/usbd_desc.h b/variants/DISCO_F407VG/usb/usbd_desc.h index 455fcf1a4d..88ffd993cd 100644 --- a/variants/DISCO_F407VG/usb/usbd_desc.h +++ b/variants/DISCO_F407VG/usb/usbd_desc.h @@ -60,7 +60,11 @@ #define USB_SIZ_STRING_SERIAL 0x1A /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ -extern USBD_DescriptorsTypeDef HID_Desc; +uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); + #endif // USBCON #endif /* __USBD_DESC_H */ diff --git a/variants/NUCLEO_F429ZI/usb/usbd_conf.c b/variants/NUCLEO_F429ZI/usb/usbd_conf.c index 30a3c9203c..a7a4009005 100644 --- a/variants/NUCLEO_F429ZI/usb/usbd_conf.c +++ b/variants/NUCLEO_F429ZI/usb/usbd_conf.c @@ -130,6 +130,8 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) */ void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) { + UNUSED(hpcd); + /* Disable USB FS Clock */ __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); __HAL_RCC_SYSCFG_CLK_DISABLE(); diff --git a/variants/NUCLEO_F429ZI/usb/usbd_conf.h b/variants/NUCLEO_F429ZI/usb/usbd_conf.h index cda1a9588e..7dc197a6a3 100644 --- a/variants/NUCLEO_F429ZI/usb/usbd_conf.h +++ b/variants/NUCLEO_F429ZI/usb/usbd_conf.h @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file USB_Device/HID_Standalone/Inc/usbd_conf.h + * @file usbd_conf.h * @author MCD Application Team * @version V1.0.2 * @date 06-May-2016 @@ -45,9 +45,11 @@ ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CONF_H -#define __USBD_CONF_H - +#ifndef __USBD_CONF__H__ +#define __USBD_CONF__H__ +#ifdef __cplusplus + extern "C" { +#endif /* Includes ------------------------------------------------------------------*/ #include "stm32_def.h" #include @@ -57,23 +59,31 @@ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ -#define USBD_LPM_ENABLED 0 +#define USBD_LPM_ENABLED 0 /* Common Config */ #define USBD_MAX_NUM_INTERFACES 1 #define USBD_MAX_NUM_CONFIGURATION 1 -#define USBD_MAX_STR_DESC_SIZ 0x100 +#define USBD_MAX_STR_DESC_SIZ 512 #define USBD_SUPPORT_USER_STRING 0 #define USBD_SELF_POWERED 1 -#define USBD_DEBUG_LEVEL 3 +#define USBD_DEBUG_LEVEL 0 +#define USBD_CDC_INTERVAL 1000 + /* Exported macro ------------------------------------------------------------*/ +/****************************************/ +/* #define for FS and HS identification */ +#define DEVICE_FS 0 +#define DEVICE_HS 1 /* Memory management macros */ #define USBD_malloc malloc #define USBD_free free #define USBD_memset memset #define USBD_memcpy memcpy +#define USBD_Delay HAL_Delay + /* DEBUG macros */ #if (USBD_DEBUG_LEVEL > 0) #define USBD_UsrLog(...) printf(__VA_ARGS__);\ @@ -101,7 +111,11 @@ /* Exported functions ------------------------------------------------------- */ +#ifdef __cplusplus +} +#endif + #endif // USBCON -#endif /* __USBD_CONF_H */ +#endif //__USBD_CONF__H__ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/variants/NUCLEO_F429ZI/usb/usbd_desc.c b/variants/NUCLEO_F429ZI/usb/usbd_desc.c index 27f8df5e35..1a3b3e543f 100644 --- a/variants/NUCLEO_F429ZI/usb/usbd_desc.c +++ b/variants/NUCLEO_F429ZI/usb/usbd_desc.c @@ -68,39 +68,10 @@ #else #define USBD_MANUFACTURER_STRING USB_MANUFACTURER #endif -#ifdef USBD_USE_HID_COMPOSITE -#define USBD_HID_PRODUCT_HS_STRING CONCATS(USB_PRODUCT, "HID in HS Mode") -#define USBD_HID_PRODUCT_FS_STRING CONCATS(USB_PRODUCT, "HID in FS Mode") -#define USBD_HID_CONFIGURATION_HS_STRING CONCATS(USB_PRODUCT, "HID Config") -#define USBD_HID_INTERFACE_HS_STRING CONCATS(USB_PRODUCT, "HID Interface") -#define USBD_HID_CONFIGURATION_FS_STRING CONCATS(USB_PRODUCT, "HID Config") -#define USBD_HID_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "HID Interface") /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ -static uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -static uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -#ifdef USB_SUPPORT_USER_STRING_DESC -static uint8_t *USBD_HID_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); -#endif /* USB_SUPPORT_USER_STRING_DESC */ - /* Private variables ---------------------------------------------------------*/ -USBD_DescriptorsTypeDef HID_Desc = { - USBD_HID_DeviceDescriptor, - USBD_HID_LangIDStrDescriptor, - USBD_HID_ManufacturerStrDescriptor, - USBD_HID_ProductStrDescriptor, - USBD_HID_SerialStrDescriptor, - USBD_HID_ConfigStrDescriptor, - USBD_HID_InterfaceStrDescriptor, -}; -#endif //USBD_USE_HID_COMPOSITE - /* USB Standard Device Descriptor */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 @@ -152,15 +123,16 @@ __ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len); static void Get_SerialNum(void); -#ifdef USBD_USE_HID_COMPOSITE /** * @brief Returns the device descriptor. * @param speed: Current device speed * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + *length = sizeof(USBD_DeviceDesc); return (uint8_t*)USBD_DeviceDesc; } @@ -171,39 +143,24 @@ uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + *length = sizeof(USBD_LangIDDesc); return (uint8_t*)USBD_LangIDDesc; } -/** - * @brief Returns the product string descriptor. - * @param speed: Current device speed - * @param length: Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t *USBD_HID_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_HID_PRODUCT_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - /** * @brief Returns the manufacturer string descriptor. * @param speed: Current device speed * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); return USBD_StrDesc; } @@ -214,8 +171,10 @@ uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { + UNUSED(speed); + *length = USB_SIZ_STRING_SERIAL; /* Update the serial number string descriptor with the data from the unique ID*/ @@ -224,44 +183,6 @@ uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) return (uint8_t*)USBD_StringSerial; } -/** - * @brief Returns the configuration string descriptor. - * @param speed: Current device speed - * @param length: Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Returns the interface string descriptor. - * @param speed: Current device speed - * @param length: Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_HID_INTERFACE_HS_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} -#endif //USBD_USE_HID_COMPOSITE /** * @brief Create the serial number string descriptor * @param None diff --git a/variants/NUCLEO_F429ZI/usb/usbd_desc.h b/variants/NUCLEO_F429ZI/usb/usbd_desc.h index 455fcf1a4d..88ffd993cd 100644 --- a/variants/NUCLEO_F429ZI/usb/usbd_desc.h +++ b/variants/NUCLEO_F429ZI/usb/usbd_desc.h @@ -60,7 +60,11 @@ #define USB_SIZ_STRING_SERIAL 0x1A /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ -extern USBD_DescriptorsTypeDef HID_Desc; +uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); + #endif // USBCON #endif /* __USBD_DESC_H */ diff --git a/variants/NUCLEO_F429ZI/variant.h b/variants/NUCLEO_F429ZI/variant.h index a85c817198..50a98233d0 100644 --- a/variants/NUCLEO_F429ZI/variant.h +++ b/variants/NUCLEO_F429ZI/variant.h @@ -188,7 +188,7 @@ enum { //Timer Definitions //Do not use timer used by PWM pins when possible. See PinMap_PWM. -#define TIMER_TONE TIM6 +#define TIMER_TONE TIM2 #define TIMER_UART_EMULATED TIM7 //Do not use basic timer: OC is required