├── README.md └── src ├── pic16f1454 ├── .gitignore ├── HidSensorSpec.h ├── Makefile ├── README.md ├── include │ ├── usb.h │ ├── usb_cdc.h │ ├── usb_ch9.h │ ├── usb_hid.h │ └── usb_microsoft.h ├── main.c ├── usb.c ├── usb_config.h ├── usb_descriptors.c ├── usb_hal.h ├── usb_hid.c └── usb_winusb.h └── stm32f072 ├── .gitignore ├── HidSensorSpec.h ├── MCD-ST Liberty SW License Agreement V2.pdf ├── README.md ├── config.h ├── main.c ├── standardhidhelper.h ├── stm32f0xx_hal.c ├── stm32f0xx_hal.h ├── stm32f0xx_hal_conf.h ├── stm32f0xx_hal_cortex.c ├── stm32f0xx_hal_cortex.h ├── stm32f0xx_hal_def.h ├── stm32f0xx_hal_flash.h ├── stm32f0xx_hal_flash_ex.h ├── stm32f0xx_hal_gpio.c ├── stm32f0xx_hal_gpio.h ├── stm32f0xx_hal_gpio_ex.h ├── stm32f0xx_hal_pcd.c ├── stm32f0xx_hal_pcd.h ├── stm32f0xx_hal_pcd_ex.c ├── stm32f0xx_hal_pcd_ex.h ├── stm32f0xx_hal_pwr.h ├── stm32f0xx_hal_pwr_ex.h ├── stm32f0xx_hal_rcc.c ├── stm32f0xx_hal_rcc.h ├── stm32f0xx_hal_rcc_ex.c ├── stm32f0xx_hal_rcc_ex.h ├── stm32f0xx_it.c ├── stm32f0xx_it.h ├── stm32hidsensor.hzp ├── system_stm32f0xx.c ├── usbd_composite.c ├── usbd_composite.h ├── usbd_conf.c ├── usbd_conf.h ├── usbd_core.c ├── usbd_core.h ├── usbd_ctlreq.c ├── usbd_ctlreq.h ├── usbd_def.h ├── usbd_desc.c ├── usbd_desc.h ├── usbd_hid.c ├── usbd_hid.h ├── usbd_ioreq.c ├── usbd_ioreq.h └── usbhelper.h /README.md: -------------------------------------------------------------------------------- 1 | USB HID Sensor implementation for PIC16F1454 and STM32F072 2 | ========================================================== 3 | 4 | This project contains open-source firmware for an example USB HID Sensor implementation. Functionally equivalent source code is provided for two inexpensive USB microcontrollers: 5 | 6 | [Microchip PIC16F1454 / PIC16F1455 / PIC16F1459](http://www.microchip.com/wwwproducts/en/PIC16F1454) 7 | 8 | [ST Micro STM32F042 / STM32F072](http://www.st.com/en/microcontrollers/stm32f0x2.html) 9 | 10 | ## What It Is 11 | 12 | If you have arrived at this from a search engine, like me you probably encountered countless inapplicable search results of people doing Sensors that use the USB HID Protocol, rather than the desired search result of an implementation of the USB HID Sensor protocol [HUTRR39b](http://www.usb.org/developers/hidpage/HUTRR39b.pdf). 13 | 14 | This project provides example code to demonstrate an implementation of the HID Sensor protocol; you must modify the code yourself to add your particular sensor's functionality. 15 | 16 | ## Introduction to HID Sensor 17 | 18 | Ostensibly, the appeal of the HID Sensor protocol is it that provides a driver-less mechanism to connect sensors to a PC. There is a very rich descriptive metadata defined in the HID Sensor protocol that tells PC software what type of sensor it is, what values it outputs, what units these values are in, and how often it sends updates. 19 | 20 | This is also the Achilles Heel of the HID Sensor protocol; this descriptive metadata is so flexible that the OS driver writers may not have anticipated or tested the configuration of your particular sensor. 21 | 22 | To my knowledge, the HID Sensor protocol is presently only supported in Windows 8 and Windows 10. (There are some bleeding edge Linux drivers under development.) 23 | 24 | To make things more convoluted for the would-be developer, there are subtle differences in behavior between Windows 8 and Windows 10 with maddeningly cryptic or misleading error messages. For example, someone in Redmond crafted the misleading Windows 10 error message "Failed to get HID identification string from device". Only by trial and error did I discover this error happens when the HID Sensor device does not provide USB manufacturer and serial number strings. These strings are not mandated by the HID Sensor protocol nor by the USB specification documents. Furthermore, they have absolutely nothing to do with "HID", despite the "HID identification string" error message. Windows 8, in contrast to Windows 10, does not give this error message. 25 | 26 | Similarly frustrating is that some of the example HID report descriptors in the HID Sensor protocol document will not work in Windows 8. It just gives up with a Feature Report error; one would have hoped that, at a minimum, these examples at least would have been tested. Thankfully, Windows 10 seems more adept at decoding these. 27 | 28 | So, you must expect trial and error testing to see what will work. An implementation may be 100% compliant to the HID Sensor protocol but yet not work in Windows. 29 | 30 | A further frustration for the would-be developer is that Microsoft has seemingly abandoned its Sensor Diagnostic Tool, the slightly clunky but indispensable software provided by the Windows WDK and needed by HID Sensor developers to check the incoming sensor data. Windows 10 seems to have broken this software, and Microsoft is either unwilling or unable to fix it. Instead, their website indicates that the tool is now deprecated and to use the SensorInfo app. Alas, this new software is positively useless. 31 | 32 | ## Customizing 33 | 34 | Like the USB HID specification on which the HID Sensors are based, the HID Report Descriptor for HID Sensors describes what the Input, Output, and Feature Reports will be. Of primary interest are Input and Feature Reports. 35 | 36 | The Feature Report is retrieved from the USB device (via EP0) and provides much of the descriptive metadata (such as ranges, units, etc). 37 | 38 | The Input Report is sent from the USB device and each message provides the current sensor data. 39 | 40 | Read the HID Sensor protocol standard thoroughly to learn the specifics. The HID Report Descriptors in this firmware follow the conventions established in the standards document. 41 | 42 | The firmware for each of the USB microcontrollers has its own README.md file to describe the structure and operation of the firmware. 43 | 44 | Customize the HID Report Descriptor to suit your sensor, and then craft the Feature and Input Reports to *exactly* match, byte-for-byte, what has been described in the HID Report Descriptor. 45 | 46 | -------------------------------------------------------------------------------- /src/pic16f1454/.gitignore: -------------------------------------------------------------------------------- 1 | *.d 2 | *.p1 3 | *.pre 4 | *.cmf 5 | *.cof 6 | *.hxl 7 | *.lst 8 | *.obj 9 | *.rlf 10 | *.sdb 11 | *.sym 12 | funclist 13 | *.hex 14 | -------------------------------------------------------------------------------- /src/pic16f1454/HidSensorSpec.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majbthrd/HIDsensor/8ed0a6312c4c9daee7c0431c160af9fbb824d30a/src/pic16f1454/HidSensorSpec.h -------------------------------------------------------------------------------- /src/pic16f1454/Makefile: -------------------------------------------------------------------------------- 1 | # customize the following paths for your computer 2 | CC = xc8 3 | LIB_INC_PATH = "./include" 4 | 5 | CHIP = 16F1454 6 | 7 | CFLAGS = --chip=$(CHIP) -Q -G --double=24 --float=24 8 | CFLAGS += --rom=default,-0-1FF,-1F7F-1F7F 9 | CFLAGS += --codeoffset=0x200 10 | CFLAGS += --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore 11 | CFLAGS += --mode=pro -N64 -I. -I$(LIB_INC_PATH) --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 12 | CFLAGS += --runtime=default,-clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib 13 | 14 | HIDSENSOR_OBJS = usb.p1 usb_hid.p1 usb_descriptors.p1 main.p1 15 | 16 | HIDSENSOR_HDRS = usb_config.h 17 | 18 | all: hidsensor.hex 19 | 20 | hidsensor.hex: $(HIDSENSOR_OBJS) 21 | $(CC) $(CFLAGS) -o./$@ $(HIDSENSOR_OBJS) 22 | 23 | %.p1: %.c $(HIDSENSOR_HDRS) Makefile 24 | $(CC) --pass1 $(CFLAGS) -o./$@ $< 25 | 26 | clean: 27 | # rm -f hidsensor.hex 28 | rm -f *.p1 *.d *.pre *.sym *.cmf *.cof *.hxl *.lst *.obj *.rlf *.sdb 29 | rm -f funclist 30 | -------------------------------------------------------------------------------- /src/pic16f1454/README.md: -------------------------------------------------------------------------------- 1 | example HID Sensor using PIC16F1454 microcontroller 2 | =================================================== 3 | 4 | ## What It Does 5 | 6 | The firmware functions as a Temperature HID Sensor. It reports dummy values in progression from -50C to 125C, and then repeats. 7 | 8 | ## Requirements 9 | 10 | [XC8](http://www.microchip.com/mplab/compilers) and make tools are needed to compile this code. 11 | 12 | ## Sanity Checklist If Customizing 13 | 14 | The HID Interface numbers in the USB descriptor in usb\_descriptors.c must be continguous and start from zero. 15 | 16 | Customize the HID Report descriptor (in usbd\_descriptors.c) to suit your sensor. Refer to the protocol document [HUTRR39b](http://www.usb.org/developers/hidpage/HUTRR39b.pdf) for details. 17 | 18 | An understanding of USB descriptors is important when modifying usb\_descriptors.c. This data conveys the configuration of the device (including endpoint, etc.) to the host PC. 19 | 20 | Be *certain* that the Feature and Input Reports *exactly* match, byte-for-byte, what is described in the HID Report. 21 | 22 | The Makefile uses compiler options --rom and --codeoffset to work with this [open-source PIC16F1454 bootloader](https://github.com/majbthrd/PIC16F1-USB-DFU-Bootloader/). If, however, you are a masochist who wants the pain and suffering of using a Microchip PICkit3 to reprogram the chip each and every time you change your code, then alter these compiler options. 23 | 24 | -------------------------------------------------------------------------------- /src/pic16f1454/include/usb_ch9.h: -------------------------------------------------------------------------------- 1 | /* 2 | * M-Stack USB Chapter 9 Structures 3 | * Copyright (C) 2013 Alan Ott 4 | * Copyright (C) 2013 Signal 11 Software 5 | * 6 | * 2013-04-26 7 | * 8 | * M-Stack is free software: you can redistribute it and/or modify it under 9 | * the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, version 3; or the Apache License, version 2.0 11 | * as published by the Apache Software Foundation. If you have purchased a 12 | * commercial license for this software from Signal 11 Software, your 13 | * commerical license superceeds the information in this header. 14 | * 15 | * M-Stack is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this software. If not, see . 22 | * 23 | * You should have received a copy of the Apache License, verion 2.0 along 24 | * with this software. If not, see . 25 | */ 26 | 27 | #ifndef USB_CH9_H__ 28 | #define USB_CH9_H__ 29 | 30 | /** @file usb.h 31 | * @brief USB Chapter 9 Enumerations and Structures 32 | * @defgroup public_api Public API 33 | */ 34 | 35 | /** @addtogroup public_api 36 | * @{ 37 | */ 38 | 39 | #include 40 | 41 | #if defined(__XC16__) || defined(__XC32__) 42 | #pragma pack(push, 1) 43 | #elif __XC8 44 | #else 45 | #error "Compiler not supported" 46 | #endif 47 | 48 | /** @defgroup ch9_items USB Chapter 9 Enumerations and Descriptors 49 | * @brief Packet structs from Chapter 9 of the USB spec which deals with 50 | * device enumeration. 51 | * 52 | * For more information about these structures, see Chapter 9 of the USB 53 | * specification, available from http://www.usb.org . 54 | * @addtogroup ch9_items 55 | * @{ 56 | */ 57 | 58 | /** USB PIDs */ 59 | enum PID { 60 | PID_OUT = 0x01, 61 | PID_IN = 0x09, 62 | PID_SOF = 0x05, 63 | PID_SETUP = 0x0D, 64 | PID_DATA0 = 0x03, 65 | PID_DATA1 = 0x0B, 66 | PID_DATA2 = 0x07, 67 | PID_MDATA = 0x0F, 68 | PID_ACK = 0x02, 69 | PID_NAK = 0x0A, 70 | PID_STALL = 0x0E, 71 | PID_NYET = 0x06, 72 | PID_PRE = 0x0C, 73 | PID_ERR = 0x0C, 74 | PID_SPLIT = 0x08, 75 | PID_PING = 0x04, 76 | PID_RESERVED = 0x00, 77 | }; 78 | 79 | /** Destination type 80 | * 81 | * This is present in the SETUP packet's bmRequestType field as Direction. 82 | */ 83 | enum DestinationType { 84 | DEST_DEVICE = 0, 85 | DEST_INTERFACE = 1, 86 | DEST_ENDPOINT = 2, 87 | DEST_OTHER_ELEMENT = 3, 88 | }; 89 | 90 | /** Request type 91 | * 92 | * These are present in the SETUP packet's bmRequestType field as Type. 93 | */ 94 | enum RequestType { 95 | REQUEST_TYPE_STANDARD = 0, 96 | REQUEST_TYPE_CLASS = 1, 97 | REQUEST_TYPE_VENDOR = 2, 98 | REQUEST_TYPE_RESERVED = 3, 99 | }; 100 | 101 | /** Control Request 102 | * 103 | * These are requests sent in the SETUP packet's bRequest field. 104 | */ 105 | enum StandardControlRequest { 106 | GET_STATUS = 0x0, 107 | CLEAR_FEATURE = 0x1, 108 | SET_FEATURE = 0x3, 109 | SET_ADDRESS = 0x5, 110 | GET_DESCRIPTOR = 0x6, 111 | SET_DESCRIPTOR = 0x7, 112 | GET_CONFIGURATION = 0x8, 113 | SET_CONFIGURATION = 0x9, 114 | GET_INTERFACE = 0xA, 115 | SET_INTERFACE = 0xB, 116 | SYNCH_FRAME = 0xC, 117 | }; 118 | 119 | /** Standard Descriptor Types */ 120 | enum DescriptorTypes { 121 | DESC_DEVICE = 0x1, 122 | DESC_CONFIGURATION = 0x2, 123 | DESC_STRING = 0x3, 124 | DESC_INTERFACE = 0x4, 125 | DESC_ENDPOINT = 0x5, 126 | DESC_DEVICE_QUALIFIER = 0x6, 127 | DESC_OTHER_SPEED_CONFIGURATION = 0x7, 128 | DESC_INTERFACE_POWER = 0x8, 129 | DESC_OTG = 0x9, 130 | DESC_DEBUG = 0xA, 131 | DESC_INTERFACE_ASSOCIATION = 0xB, 132 | }; 133 | 134 | /** Device Classes 135 | * 136 | * Some Device class constants which don't correspond to actual 137 | * classes. 138 | * 139 | * Device class codes which correspond to actual device classes are 140 | * defined in that device class's header file (for M-Stack supported 141 | * device classes). 142 | */ 143 | enum DeviceClassCodes { 144 | DEVICE_CLASS_DEFINED_AT_INTERFACE_LEVEL = 0x0, 145 | DEVICE_CLASS_MISC = 0xef, 146 | DEVICE_CLASS_APPLICATION_SPECIFIC = 0xfe, 147 | DEVICE_CLASS_VENDOR_SPECIFIC = 0xff, 148 | }; 149 | 150 | /** Endpoint Attributes */ 151 | enum EndpointAttributes { 152 | EP_CONTROL = 0x0, 153 | EP_ISOCHRONOUS = 0x1, 154 | EP_BULK = 0x2, 155 | EP_INTERRUPT = 0x3, 156 | 157 | /* More bits here for ISO endpoints only. */ 158 | }; 159 | 160 | /** The SETUP packet, as defined by the USB specification. 161 | * 162 | * The contents of the packet sent from the host during the SETUP stage of 163 | * every control transfer 164 | */ 165 | struct setup_packet { 166 | union { 167 | struct { 168 | uint8_t destination : 5; /**< @see enum DestinationType */ 169 | uint8_t type : 2; /**< @see enum RequestType */ 170 | uint8_t direction : 1; /**< 0=out, 1=in */ 171 | }; 172 | uint8_t bmRequestType; 173 | } REQUEST; 174 | uint8_t bRequest; /**< Dependent on @p type. @see enum StandardControlRequest */ 175 | uint16_t wValue; 176 | uint16_t wIndex; 177 | uint16_t wLength; 178 | }; 179 | 180 | /** Device Descriptor */ 181 | struct device_descriptor { 182 | uint8_t bLength; 183 | uint8_t bDescriptorType; /**< set to DESC_DEVICE */ 184 | uint16_t bcdUSB; /**< Set to 0x0200 for USB 2.0 */ 185 | uint8_t bDeviceClass; 186 | uint8_t bDeviceSubclass; 187 | uint8_t bDeviceProtocol; 188 | uint8_t bMaxPacketSize0; /**< Max packet size for ep 0. Must be 8, 16, 32, or 64. */ 189 | uint16_t idVendor; 190 | uint16_t idProduct; 191 | uint16_t bcdDevice; 192 | uint8_t iManufacturer; /**< index of manufacturer string descriptor */ 193 | uint8_t iProduct; /**< index of product string descriptor */ 194 | uint8_t iSerialNumber; /**< index of serial number string descriptor */ 195 | uint8_t bNumConfigurations; 196 | }; 197 | 198 | /** Configuration Descriptor */ 199 | struct configuration_descriptor { 200 | uint8_t bLength; 201 | uint8_t bDescriptorType; /**< Set to DESC_CONFIGURATION */ 202 | uint16_t wTotalLength; 203 | uint8_t bNumInterfaces; 204 | uint8_t bConfigurationValue; 205 | uint8_t iConfiguration; /**< index of string descriptor */ 206 | uint8_t bmAttributes; 207 | uint8_t bMaxPower; /**< one-half the max power required by this device. */ 208 | }; 209 | 210 | /** Interface Descriptor */ 211 | struct interface_descriptor { 212 | uint8_t bLength; 213 | uint8_t bDescriptorType; /**< Set to DESC_INTERFACE */ 214 | uint8_t bInterfaceNumber; 215 | uint8_t bAlternateSetting; 216 | uint8_t bNumEndpoints; 217 | uint8_t bInterfaceClass; 218 | uint8_t bInterfaceSubclass; 219 | uint8_t bInterfaceProtocol; 220 | uint8_t iInterface; 221 | }; 222 | 223 | /** Endpoint Descriptor */ 224 | struct endpoint_descriptor { 225 | // ... 226 | uint8_t bLength; 227 | uint8_t bDescriptorType; /**< Set to DESC_ENDPOINT */ 228 | uint8_t bEndpointAddress; 229 | uint8_t bmAttributes; 230 | uint16_t wMaxPacketSize; 231 | uint8_t bInterval; 232 | }; 233 | 234 | /** String Descriptor */ 235 | struct string_descriptor { 236 | uint8_t bLength; 237 | uint8_t bDescriptorType; /**< Set to DESC_STRING */ 238 | uint16_t chars[]; 239 | }; 240 | 241 | /** Interface Association Descriptor 242 | * 243 | * See the Interface Association Descriptors Engineering Change Note (ECN) 244 | * available from www.usb.org . 245 | */ 246 | struct interface_association_descriptor { 247 | uint8_t bLength; /**< Set to 8 bytes */ 248 | uint8_t bDescriptorType; /**< Set to DESC_INTERFACE_ASSOCIATION = 0xB */ 249 | uint8_t bFirstInterface; 250 | uint8_t bInterfaceCount; 251 | uint8_t bFunctionClass; 252 | uint8_t bFunctionSubClass; 253 | uint8_t bFunctionProtocol; 254 | uint8_t iFunction; /**< String Descriptor Index */ 255 | }; 256 | 257 | /* Doxygen end-of-group for ch9_items */ 258 | /** @}*/ 259 | 260 | 261 | /** @cond INTERNAL */ 262 | 263 | /* So far this is the best place for these macros because they are used in 264 | * usb.c and also in the application's usb_descriptors.c. Most applications 265 | * will not need to include this file outside their usb_descriptors.c, so 266 | * there isn't much namespace pollution. 267 | */ 268 | #define USB_ARRAYLEN(X) (sizeof(X)/sizeof(*X)) 269 | #define STATIC_SIZE_CHECK_EQUAL(X,Y) typedef char USB_CONCAT(STATIC_SIZE_CHECK_LINE_,__LINE__) [(X==Y)?1:-1] 270 | #define USB_CONCAT(X,Y) USB_CONCAT_HIDDEN(X,Y) 271 | #define USB_CONCAT_HIDDEN(X,Y) X ## Y 272 | 273 | /** @endcond */ 274 | 275 | 276 | #if defined(__XC16__) || defined(__XC32__) 277 | #pragma pack(pop) 278 | #elif __XC8 279 | #else 280 | #error "Compiler not supported" 281 | #endif 282 | 283 | /* Doxygen end-of-group for public_api */ 284 | /** @}*/ 285 | 286 | #endif /* USB_CH9_H__ */ 287 | -------------------------------------------------------------------------------- /src/pic16f1454/include/usb_hid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * M-Stack USB Chapter 9 Structures 3 | * Copyright (C) 2013 Alan Ott 4 | * Copyright (C) 2013 Signal 11 Software 5 | * 6 | * 2013-08-13 7 | * 8 | * M-Stack is free software: you can redistribute it and/or modify it under 9 | * the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, version 3; or the Apache License, version 2.0 11 | * as published by the Apache Software Foundation. If you have purchased a 12 | * commercial license for this software from Signal 11 Software, your 13 | * commerical license superceeds the information in this header. 14 | * 15 | * M-Stack is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this software. If not, see . 22 | * 23 | * You should have received a copy of the Apache License, verion 2.0 along 24 | * with this software. If not, see . 25 | */ 26 | 27 | #ifndef USB_HID_H__ 28 | #define USB_HID_H__ 29 | 30 | /** @file usb_hid.h 31 | * @brief USB HID Class Enumerations and Structures 32 | * @defgroup public_api Public API 33 | */ 34 | 35 | /** @addtogroup public_api 36 | * @{ 37 | */ 38 | 39 | #include 40 | #include "usb_config.h" 41 | 42 | #if defined(__XC16__) || defined(__XC32__) 43 | #pragma pack(push, 1) 44 | #elif __XC8 45 | #else 46 | #error "Compiler not supported" 47 | #endif 48 | 49 | /** @defgroup hid_items USB HID Class Enumerations and Descriptors 50 | * @brief Packet structs from the Device Class Definition for Human 51 | * Interface Devices (commonly the USB HID Specification), version 1.11, 52 | * chapter 6. 53 | * 54 | * For more information about these structures, see the above referenced 55 | * document, available from http://www.usb.org . 56 | * @addtogroup hid_items 57 | * @{ 58 | */ 59 | 60 | #define HID_INTERFACE_CLASS 0x03 61 | 62 | /** HID Class Descriptor Tyes */ 63 | enum HIDDescriptorTypes { 64 | DESC_HID = 0x21, 65 | DESC_REPORT = 0x22, 66 | DESC_PHYSICAL = 0x23, 67 | }; 68 | 69 | /** HID Class Requests */ 70 | enum HIDRequests { 71 | HID_GET_REPORT = 0x1, 72 | HID_GET_IDLE = 0x2, 73 | HID_GET_PROTOCOL = 0x3, 74 | HID_SET_REPORT = 0x9, 75 | HID_SET_IDLE = 0xa, 76 | HID_SET_PROTOCOL = 0xb, 77 | }; 78 | 79 | /** HID Report Types */ 80 | enum HIDReportTypes { 81 | HID_INPUT = 0x1, 82 | HID_OUTPUT = 0x2, 83 | HID_FEATURE = 0x3, 84 | }; 85 | 86 | /** HID Protocols */ 87 | enum HIDProtocols { 88 | HID_PROTO_BOOT = 0, 89 | HID_PROTO_REPORT = 1, 90 | }; 91 | 92 | struct hid_descriptor { 93 | uint8_t bLength; /**< Size of this struct plus any optional descriptors */ 94 | uint8_t bDescriptorType; /**< Set to DESC_HID */ 95 | uint16_t bcdHID; /**< HID Version in BCD. (0x0100 is 1.00) */ 96 | uint8_t bCountryCode; 97 | uint8_t bNumDescriptors; /**< Number of class descriptors (always at least 1) */ 98 | uint8_t bDescriptorType2; /**< Set to DESC_REPORT */ 99 | uint16_t wDescriptorLength; /**< Set to size of report descriptor */ 100 | }; 101 | 102 | struct hid_optional_descriptor { 103 | uint8_t bDescriptorType; 104 | uint16_t wDescriptorLength; 105 | }; 106 | 107 | /** HID Descriptor Function 108 | * 109 | * The USB Stack will call this function to retrieve the HID descriptor for 110 | * each HID interface when requested by the host. This function is mandatory 111 | * for HID devices. 112 | * 113 | * @param interface The interface for which the descriptor is requested 114 | * @param ptr A Pointer to a pointer which should be set to the 115 | * requested HID descriptor by this function. 116 | * 117 | * @returns 118 | * Return the length of the HID descriptor in bytes or -1 if the descriptor 119 | * does not exist. 120 | */ 121 | extern int16_t USB_HID_DESCRIPTOR_FUNC(uint8_t interface, const void **ptr); 122 | 123 | /** HID Report Descriptor Function 124 | * 125 | * The USB Stack will call this function to retrieve the HID report 126 | * descriptor for each HID interface when requested by the host. This 127 | * function is mandatory for HID devices. 128 | * 129 | * @param interface The interface for which the descriptor is requested 130 | * @param ptr A Pointer to a pointer which should be set to the 131 | * requested HID report descriptor by this function. 132 | * 133 | * @returns 134 | * Return the length of the HID report descriptor in bytes or -1 if the 135 | * descriptor does not exist. 136 | */ 137 | extern int16_t USB_HID_REPORT_DESCRIPTOR_FUNC(uint8_t interface, const void **ptr); 138 | 139 | #ifdef USB_HID_PHYSICAL_DESCRIPTOR_FUNC 140 | /** HID Physical Descriptor Function 141 | * 142 | * The USB Stack will call this function to retrieve the physical 143 | * descriptor for each HID interface when requested by the host. This 144 | * function, and physical descriptors, are optional. 145 | * 146 | * @param interface The interface for which the descriptor is requested 147 | * @param index The physical descriptor set to return. Index zero 148 | * requests a special descriptor describing the number of 149 | * descriptor sets and their sizes. See the HID 150 | * specification, version 1.11, section 7.1.1. 151 | * @param ptr A Pointer to a pointer which should be set to the 152 | * requested physical descriptor by this function 153 | * 154 | * @returns 155 | * Return the length of the physical descriptor in bytes or -1 if the 156 | * descriptor does not exist. 157 | */ 158 | extern int16_t USB_HID_PHYSICAL_DESCRIPTOR_FUNC(uint8_t interface, uint8_t index, const void **ptr); 159 | #endif 160 | 161 | #ifdef HID_GET_REPORT_CALLBACK 162 | /** HID Get_Report request callback 163 | * 164 | * The USB Stack will call this function when a Get_Report request has been 165 | * received from the host. This function should set the @p report pointer 166 | * to a buffer containing the report data and return the length of the 167 | * report. Once the transfer has completed, @p callback will be called with 168 | * the @p context pointer provided. The buffer pointed to by @p report 169 | * should be considered to be owned by the USB stack until the @p callback 170 | * is called and should not be modified by the application until that time. 171 | * 172 | * 173 | * @param interface The interface for which the report is requested 174 | * @param report_type The type of report, either @p HID_INPUT, 175 | * @p HID_OUTPUT, or @p HID_FEATURE. 176 | * @param report_id The report index requested. This will be zero if the 177 | * device does not use numbered reports. 178 | * @param report A pointer to a pointer which should be set to the 179 | * report data. 180 | * @param callback A callback function to call when the transfer 181 | * completes. This parameter is mandatory. Once the 182 | * callback is called, the transfer is over, and the 183 | * buffer can be considered to be owned by the 184 | * application again. 185 | * @param context A pointer to be passed to the callback. The USB stack 186 | * does not dereference this pointer. 187 | * 188 | * @returns 189 | * Return 0 if the request can be handled or -1 if it cannot. Returning -1 190 | * will cause STALL to be returned to the host. 191 | */ 192 | extern int16_t HID_GET_REPORT_CALLBACK(uint8_t interface, uint8_t report_type, 193 | uint8_t report_id, const void **report, 194 | usb_ep0_data_stage_callback *callback, 195 | void **context); 196 | #endif 197 | 198 | 199 | #ifdef HID_SET_REPORT_CALLBACK 200 | /** HID Set_Report request callback 201 | * 202 | * The USB Stack will call this function when a Set_Report request has been 203 | * received from the host. There are two ways to handle this: 204 | * 205 | * 0. For unknown requests, return -1. This will send a STALL to the host. 206 | * 1. For known requests the callback should call 207 | * @p usb_start_receive_ep0_data_stage() with a buffer to be filled with 208 | * the report data and a callback which will get called when the data 209 | * stage is complete. The callback is required, and the data buffer 210 | * passed to @p usb_start_receive_ep0_data_stage() must remain valid 211 | * until the callback is called. 212 | * 213 | * It is worth noting that only one control transfer can be active at any 214 | * given time. Once HID_SET_REPORT_CALLBACK() has been called, it will not 215 | * be called again until the next transfer, meaning that if the 216 | * application-provided HID_SET_REPORT_CALLBACK() function performs option 1 217 | * above, the callback function passed to @p 218 | * usb_start_receive_ep0_data_stage() will be called before any other setup 219 | * transfer can happen again. Thus, it is safe to use the same buffer 220 | * for all control transfers if desired. 221 | * 222 | * 223 | * @param interface The interface for which the report is provided 224 | * @param report_type The type of report, either @p HID_INPUT, 225 | * @p HID_OUTPUT, or @p HID_FEATURE. 226 | * @param report_id The report index requested. This will be zero if the 227 | * device does not use numbered reports. 228 | * @returns 229 | * Return 0 if the request can be handled or -1 if it cannot. Returning -1 230 | * will cause STALL to be returned to the host. 231 | */ 232 | extern int8_t HID_SET_REPORT_CALLBACK(uint8_t interface, uint8_t report_type, 233 | uint8_t report_id); 234 | #endif 235 | 236 | #ifdef HID_GET_IDLE_CALLBACK 237 | /** HID Get_Idle request callback 238 | * 239 | * The USB Stack will call this function when a Get_Idle request has been 240 | * received from the host. The application should return the current idle 241 | * rate. 242 | * 243 | * @param interface The interface for which the report is provided 244 | * @param report_id The report index requested. 245 | * 246 | * @returns 247 | * Return the current idle rate. 248 | */ 249 | extern uint8_t HID_GET_IDLE_CALLBACK(uint8_t interface, uint8_t report_id); 250 | #endif 251 | 252 | #ifdef HID_SET_IDLE_CALLBACK 253 | /** HID Set_Idle request callback 254 | * 255 | * The USB Stack will call this function when a Set_Idle request has been 256 | * received from the host. The application should use the provided value 257 | * as the idle rate. 258 | * 259 | * @param interface The interface for which the report is provided 260 | * @param report_id The report index requested. Zero means all reports. 261 | * @param idle_rate The idle rate to set, in multiples of 4 milliseconds. 262 | * 263 | * @returns 264 | * Return 0 on success and -1 on failure. 265 | */ 266 | extern int8_t HID_SET_IDLE_CALLBACK(uint8_t interface, uint8_t report_id, 267 | uint8_t idle_rate); 268 | #endif 269 | 270 | #ifdef HID_GET_PROTOCOL_CALLBACK 271 | /** HID Get_Protocol request callback 272 | * 273 | * The USB Stack will call this function when a Get_Protocol request has 274 | * been received from the host. The application should return the current 275 | * protocol. 276 | * 277 | * @param interface The interface for which the report is provided 278 | * 279 | * @returns 280 | * Return the current protocol (@p HID_PROTO_BOOT, @p HID_PROTO_REPORT) or 281 | * -1 on failure. 282 | */ 283 | extern int8_t HID_GET_PROTOCOL_CALLBACK(uint8_t interface); 284 | #endif 285 | 286 | #ifdef HID_SET_PROTOCOL_CALLBACK 287 | /** HID Set_Protocol request callback 288 | * 289 | * The USB Stack will call this function when a Set_Protocol request has 290 | * been received from the host, and will provide the protocol to set as 291 | * either @p HID_PROTO_BOOT, or @p HID_PROTO_REPORT. 292 | * 293 | * @param interface The interface for which the report is provided 294 | * @param protocol The protocol to set. Either @p HID_PROTO_BOOT, or 295 | * @p HID_PROTO_REPORT. 296 | * 297 | * @returns 298 | * Return 0 on success or -1 on failure. 299 | */ 300 | extern int8_t HID_SET_PROTOCOL_CALLBACK(uint8_t interface, uint8_t protocol); 301 | #endif 302 | 303 | #ifdef MULTI_CLASS_DEVICE 304 | /** Set the list of HID interfaces on this device 305 | * 306 | * Provide a list to the HID class implementation of the interfaces on this 307 | * device which should be treated as HID devices. This is only necessary 308 | * for multi-class composite devices to make sure that requests are not 309 | * confused between interfaces. It should be called before usb_init(). 310 | * 311 | * @param interfaces An array of interfaces which are HID class. 312 | * @param num_interfaces The size of the @p interfaces array. 313 | */ 314 | void hid_set_interface_list(uint8_t *interfaces, uint8_t num_interfaces); 315 | #endif 316 | 317 | /** Process HID Setup Request 318 | * 319 | * Process a setup request which has been unhandled as if it is potentially 320 | * a HID setup request. This function will then call appropriate callbacks 321 | * into the appliction if the setup packet is one recognized by the HID 322 | * specification. 323 | * 324 | * @param setup A setup packet to handle 325 | * 326 | * @returns 327 | * Returns 0 if the setup packet could be processed or -1 if it could not. 328 | */ 329 | uint8_t process_hid_setup_request(const struct setup_packet *setup); 330 | 331 | 332 | /* Doxygen end-of-group for hid_items */ 333 | /** @}*/ 334 | 335 | 336 | #if defined(__XC16__) || defined(__XC32__) 337 | #pragma pack(pop) 338 | #elif __XC8 339 | #else 340 | #error "Compiler not supported" 341 | #endif 342 | 343 | /* Doxygen end-of-group for public_api */ 344 | /** @}*/ 345 | 346 | #endif /* USB_HID_H__ */ 347 | -------------------------------------------------------------------------------- /src/pic16f1454/include/usb_microsoft.h: -------------------------------------------------------------------------------- 1 | /* 2 | * M-Stack Microsoft-Specific OS Descriptors 3 | * Copyright (C) 2013 Alan Ott 4 | * Copyright (C) 2013 Signal 11 Software 5 | * 6 | * 2013-08-27 7 | * 8 | * M-Stack is free software: you can redistribute it and/or modify it under 9 | * the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, version 3; or the Apache License, version 2.0 11 | * as published by the Apache Software Foundation. If you have purchased a 12 | * commercial license for this software from Signal 11 Software, your 13 | * commerical license superceeds the information in this header. 14 | * 15 | * M-Stack is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this software. If not, see . 22 | * 23 | * You should have received a copy of the Apache License, verion 2.0 along 24 | * with this software. If not, see . 25 | */ 26 | 27 | #ifndef USB_MICROSOFT_H__ 28 | #define USB_MICROSOFT_H__ 29 | 30 | /** @file usb.h 31 | * @brief Microsoft-Specific OS Descriptors 32 | * @defgroup public_api Public API 33 | */ 34 | 35 | /** @addtogroup public_api 36 | * @{ 37 | */ 38 | 39 | #include 40 | 41 | #if defined(__XC16__) || defined(__XC32__) 42 | #pragma pack(push, 1) 43 | #elif __XC8 44 | #else 45 | #error "Compiler not supported" 46 | #endif 47 | 48 | /** @defgroup microsoft_items Microsoft-Specific Descriptors 49 | * @brief Packet structs from Microsoft's documentation which deal with 50 | * the Microsoft OS String Descriptor and the Extended Compat Descriptors. 51 | * 52 | * For more information about these structures, see the Microsoft 53 | * documentation at http://msdn.microsoft.com/library/windows/hardware/gg463182 54 | * or search for "Microsoft OS Descriptors" on http://msdn.microsoft.com . 55 | * Also see docs/winusb.txt in the M-Stack distribution. 56 | * 57 | * @addtogroup microsoft_items 58 | * @{ 59 | */ 60 | 61 | /** OS String Descriptor 62 | * 63 | * This is the first descriptor Windows will request, as string number 0xee. 64 | */ 65 | struct microsoft_os_descriptor { 66 | uint8_t bLength; /**< set to 0x12 */ 67 | uint8_t bDescriptorType; /**< set to 0x3 */ 68 | uint16_t qwSignature[7]; /**< set to "MSFT100" (Unicode) (no NULL) */ 69 | uint8_t bMS_VendorCode; /**< Set to the bRequest by which the host 70 | should ask for the Compat ID and 71 | Property descriptors. */ 72 | uint8_t bPad; /**< Set to 0x0 */ 73 | }; 74 | 75 | /** Extended Compat ID Header 76 | * 77 | * This is the header for the Extended Compat ID Descriptor 78 | */ 79 | struct microsoft_extended_compat_header { 80 | uint32_t dwLength; /**< Total length of descriptor (header + functions) */ 81 | uint16_t bcdVersion; /**< Descriptor version number, 0x0100. */ 82 | uint16_t wIndex; /**< This OS feature descriptor; set to 0x04. */ 83 | uint8_t bCount; /**< Number of custom property sections */ 84 | uint8_t reserved[7]; 85 | }; 86 | 87 | /** Extended Compat ID Function 88 | * 89 | * This is the function struct for the Extended Compat ID Descriptor 90 | */ 91 | struct microsoft_extended_compat_function { 92 | uint8_t bFirstInterfaceNumber; /**< The interface or function number */ 93 | uint8_t reserved; 94 | uint8_t compatibleID[8]; /**< Compatible String */ 95 | uint8_t subCompatibleID[8]; /**< Subcompatible String */ 96 | uint8_t reserved2[6]; 97 | }; 98 | 99 | /** Extended Properties Header 100 | * 101 | * This is the header for the Extended Properties Descriptor 102 | */ 103 | struct microsoft_extended_properties_header { 104 | uint32_t dwLength; /**< Total length of descriptor (header + functions) */ 105 | uint16_t bcdVersion; /**< Descriptor version number, 0x0100. */ 106 | uint16_t wIndex; /**< This OS feature descriptor; set to 0x04. */ 107 | uint16_t bCount; /**< Number of custom property sections */ 108 | }; 109 | 110 | /** Extended Property Section header 111 | * 112 | * This is the first part of the Extended Property Section, which is a 113 | * variable-length descriptor. The Variable-length types must be packed 114 | * manually after this section header. 115 | * 116 | */ 117 | struct microsoft_extended_property_section_header { 118 | uint32_t dwSize; /**< Size of this section (this struct + data) */ 119 | uint32_t dwPropertyDataType; /**< Property Data Format */ 120 | 121 | /* Variable-length fields and lengths: 122 | uint16_t wPropertyNameLength; 123 | uint16_t bPropertyName[]; 124 | uint32_t dwPropertyDataLength; 125 | uint8_t bPropertyData[]; 126 | */ 127 | }; 128 | 129 | #ifdef MICROSOFT_COMPAT_ID_DESCRIPTOR_FUNC 130 | /** @brief Callback for the GET_MS_DESCRIPTOR/CompatID request 131 | * 132 | * MICROSOFT_COMPAT_ID_DESCRIPTOR_FUNC() is called when a @p 133 | * GET_MS_DESCRIPTOR request is received from the host with a wIndex of 0x0004. 134 | * The value of MS_GET_DESCRIPTOR request is defined by 135 | * MICROSOFT_OS_DESC_VENDOR_CODE which is set in usb_config.h, and reported to 136 | * the host as part of the @p microsoft_os_descriptor. See the MSDN 137 | * documentation on "Microsoft OS Descriptors" for more information. 138 | * 139 | * @param interface The interface for which the descriptor is queried 140 | * @param descriptor a pointer to a pointer which should be set to the 141 | * descriptor data. 142 | * @returns 143 | * Return the length of the descriptor pointed to by @p *descriptor, or -1 144 | * if the descriptor does not exist. 145 | */ 146 | uint16_t MICROSOFT_COMPAT_ID_DESCRIPTOR_FUNC(uint8_t interface, 147 | const void **descriptor); 148 | #endif 149 | 150 | #ifdef MICROSOFT_CUSTOM_PROPERTY_DESCRIPTOR_FUNC 151 | /** @brief Callback for the GET_MS_DESCRIPTOR/Custom_Property request 152 | * 153 | * MICROSOFT_CUSTOM_PROPERTY_DESCRIPTOR_FUNC() is called when a @p 154 | * GET_MS_DESCRIPTOR request with a wIndex of 0x0005 is received from the host. 155 | * The value of the MS_GET_DESCRIPTOR request is defined by 156 | * MICROSOFT_OS_DESC_VENDOR_CODE which is set in usb_config.h, and reported to 157 | * the host as part of the @p microsoft_os_descriptor. See the MSDN 158 | * documentation on "Microsoft OS Descriptors" for more information. 159 | * 160 | * @param interface The interface for which the descriptor is queried 161 | * @param descriptor a pointer to a pointer which should be set to the 162 | * descriptor data. 163 | * @returns 164 | * Return the length of the descriptor pointed to by @p *descriptor, or -1 165 | * if the descriptor does not exist. 166 | */ 167 | uint16_t MICROSOFT_CUSTOM_PROPERTY_DESCRIPTOR_FUNC(uint8_t interface, 168 | const void **descriptor); 169 | #endif 170 | 171 | /* Doxygen end-of-group for microsoft_items */ 172 | /** @}*/ 173 | 174 | #if defined(__XC16__) || defined(__XC32__) 175 | #pragma pack(pop) 176 | #elif __XC8 177 | #else 178 | #error "Compiler not supported" 179 | #endif 180 | 181 | /* Doxygen end-of-group for public_api */ 182 | /** @}*/ 183 | 184 | #endif /* USB_MICROSOFT_H__ */ 185 | -------------------------------------------------------------------------------- /src/pic16f1454/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | example HID Sensor using PIC16F1454 microcontroller 3 | 4 | Copyright (C) 2016 Peter Lawrence 5 | 6 | based on top of M-Stack USB driver stack by Alan Ott, Signal 11 Software 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a 9 | copy of this software and associated documentation files (the "Software"), 10 | to deal in the Software without restriction, including without limitation 11 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | and/or sell copies of the Software, and to permit persons to whom the 13 | Software is furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | #include "usb.h" 28 | #include 29 | #include 30 | #include "usb_config.h" 31 | #include "usb_ch9.h" 32 | #include "usb_hid.h" 33 | #include "HidSensorSpec.h" 34 | 35 | /* 36 | since this is a downloaded app, configuration words (e.g. __CONFIG or #pragma config) are not relevant 37 | */ 38 | 39 | static uint8_t tick_counter; 40 | 41 | int main(void) 42 | { 43 | uint8_t *TxDataBuffer; 44 | int16_t temperature = -5000; 45 | 46 | usb_init(); 47 | 48 | TxDataBuffer = usb_get_in_buffer(1); 49 | 50 | for (;;) 51 | { 52 | usb_service(); 53 | 54 | /* if USB isn't configured, there is no point in proceeding further */ 55 | if (!usb_is_configured()) 56 | continue; 57 | 58 | /* proceed further only when the IN endpoint is ready */ 59 | if (usb_in_endpoint_halted(1) || usb_in_endpoint_busy(1)) 60 | continue; 61 | 62 | /* wait for prescribed interval (in ticks) before sending new sensor value */ 63 | if (tick_counter < 100) 64 | continue; 65 | 66 | TxDataBuffer[0] = 0x02; /* Ready */ 67 | TxDataBuffer[1] = 0x03; /* Data Updated */ 68 | TxDataBuffer[2] = (temperature >> 0); /* sensor value */ 69 | TxDataBuffer[3] = (temperature >> 8); 70 | 71 | /* send a reading to the PC */ 72 | usb_send_in_buffer(1, 4); 73 | 74 | /* pick next value; generate temperatures from -50.0C to 125.0C in increments of 1.0C */ 75 | if (temperature > 12500) 76 | temperature = -5000; 77 | else 78 | temperature += 100; 79 | 80 | /* reset counter */ 81 | tick_counter = 0; 82 | } 83 | } 84 | 85 | int8_t app_unknown_setup_request_callback(const struct setup_packet *setup) 86 | { 87 | return process_hid_setup_request(setup); 88 | } 89 | 90 | static const uint8_t temp_sensor_feature_report[] = 91 | { 92 | HID_SENSOR_VALUE_SIZE_32(100), /* report interval (ms) */ 93 | HID_SENSOR_VALUE_SIZE_16(150 * 100), /* maximum sensor value (150C) */ 94 | HID_SENSOR_VALUE_SIZE_16(-50 * 100), /* minimum sensor value (-50C) */ 95 | }; 96 | 97 | int16_t app_get_report_callback(uint8_t interface, uint8_t report_type, uint8_t report_id, const void **report, usb_ep0_data_stage_callback *callback, void **context) 98 | { 99 | *report = temp_sensor_feature_report; 100 | return sizeof(temp_sensor_feature_report); 101 | } 102 | 103 | void app_start_of_frame_callback(void) 104 | { 105 | tick_counter++; 106 | } 107 | 108 | int8_t app_set_report_callback(uint8_t interface, uint8_t report_type, uint8_t report_id) 109 | { 110 | usb_send_data_stage(NULL, 0, NULL, NULL); 111 | return 0; 112 | } 113 | 114 | int8_t app_set_idle_callback(uint8_t interface, uint8_t report_id, uint8_t idle_rate) 115 | { 116 | usb_send_data_stage(NULL, 0, NULL, NULL); 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /src/pic16f1454/usb_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | example HID Sensor using PIC16F1454 microcontroller 3 | 4 | Copyright (C) 2016 Peter Lawrence 5 | 6 | based on top of M-Stack USB driver stack by Alan Ott, Signal 11 Software 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a 9 | copy of this software and associated documentation files (the "Software"), 10 | to deal in the Software without restriction, including without limitation 11 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | and/or sell copies of the Software, and to permit persons to whom the 13 | Software is furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | #ifndef USB_CONFIG_H__ 28 | #define USB_CONFIG_H__ 29 | 30 | /* Number of endpoint numbers besides endpoint zero. It's worth noting that 31 | and endpoint NUMBER does not completely describe an endpoint, but the 32 | along with the DIRECTION does (eg: EP 1 IN). The #define below turns on 33 | BOTH IN and OUT endpoints for endpoint numbers (besides zero) up to the 34 | value specified. For example, setting NUM_ENDPOINT_NUMBERS to 2 will 35 | activate endpoints EP 1 IN, EP 1 OUT, EP 2 IN, EP 2 OUT. */ 36 | #define NUM_ENDPOINT_NUMBERS 1 37 | 38 | /* Only 8, 16, 32 and 64 are supported for endpoint zero length. */ 39 | #define EP_0_LEN 64 40 | 41 | #define EP_1_OUT_LEN 64 42 | #define EP_1_IN_LEN EP_1_OUT_LEN 43 | 44 | #define NUMBER_OF_CONFIGURATIONS 1 45 | 46 | /* Ping-pong buffering mode. Valid values are: 47 | PPB_NONE - Do not ping-pong any endpoints 48 | PPB_EPO_OUT_ONLY - Ping-pong only endpoint 0 OUT 49 | PPB_ALL - Ping-pong all endpoints 50 | PPB_EPN_ONLY - Ping-pong all endpoints except 0 51 | */ 52 | 53 | #define PPB_MODE PPB_NONE 54 | 55 | /* Objects from usb_descriptors.c */ 56 | #define USB_DEVICE_DESCRIPTOR this_device_descriptor 57 | #define USB_CONFIG_DESCRIPTOR_MAP usb_application_config_descs 58 | #define USB_STRING_DESCRIPTOR_FUNC usb_application_get_string 59 | 60 | /* Optional callbacks from usb.c. Leave them commented if you don't want to 61 | use them. For the prototypes and documentation for each one, see usb.h. */ 62 | 63 | //#define SET_CONFIGURATION_CALLBACK app_set_configuration_callback 64 | //#define GET_DEVICE_STATUS_CALLBACK app_get_device_status_callback 65 | //#define ENDPOINT_HALT_CALLBACK app_endpoint_halt_callback 66 | //#define SET_INTERFACE_CALLBACK app_set_interface_callback 67 | //#define GET_INTERFACE_CALLBACK app_get_interface_callback 68 | //#define OUT_TRANSACTION_CALLBACK app_out_transaction_callback 69 | //#define IN_TRANSACTION_COMPLETE_CALLBACK app_in_transaction_complete_callback 70 | #define UNKNOWN_SETUP_REQUEST_CALLBACK app_unknown_setup_request_callback 71 | //#define UNKNOWN_GET_DESCRIPTOR_CALLBACK app_unknown_get_descriptor_callback 72 | #define START_OF_FRAME_CALLBACK app_start_of_frame_callback 73 | //#define USB_RESET_CALLBACK app_usb_reset_callback 74 | 75 | /* HID Configuration functions. See usb_hid.h for documentation. */ 76 | #define USB_HID_DESCRIPTOR_FUNC usb_application_get_hid_descriptor 77 | #define USB_HID_REPORT_DESCRIPTOR_FUNC usb_application_get_hid_report_descriptor 78 | //#define USB_HID_PHYSICAL_DESCRIPTOR_FUNC usb_application_get_hid_physical_descriptor 79 | 80 | /* HID Callbacks. See usb_hid.h for documentation. */ 81 | #define HID_GET_REPORT_CALLBACK app_get_report_callback 82 | #define HID_SET_REPORT_CALLBACK app_set_report_callback 83 | //#define HID_GET_IDLE_CALLBACK app_get_idle_callback 84 | #define HID_SET_IDLE_CALLBACK app_set_idle_callback 85 | //#define HID_GET_PROTOCOL_CALLBACK app_get_protocol_callback 86 | //#define HID_SET_PROTOCOL_CALLBACK app_set_protocol_callback 87 | 88 | #endif /* USB_CONFIG_H__ */ 89 | -------------------------------------------------------------------------------- /src/pic16f1454/usb_descriptors.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majbthrd/HIDsensor/8ed0a6312c4c9daee7c0431c160af9fbb824d30a/src/pic16f1454/usb_descriptors.c -------------------------------------------------------------------------------- /src/pic16f1454/usb_hid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * M-Stack USB Device Stack Implementation 3 | * Copyright (C) 2013 Alan Ott 4 | * Copyright (C) 2013 Signal 11 Software 5 | * 6 | * Initial version for PIC18, 2008-02-24 7 | * PIC24 port, 2013-08-13 8 | * 9 | * M-Stack is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Lesser General Public License as published by the 11 | * Free Software Foundation, version 3; or the Apache License, version 2.0 12 | * as published by the Apache Software Foundation. If you have purchased a 13 | * commercial license for this software from Signal 11 Software, your 14 | * commerical license superceeds the information in this header. 15 | * 16 | * M-Stack is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public License 22 | * along with this software. If not, see . 23 | * 24 | * You should have received a copy of the Apache License, verion 2.0 along 25 | * with this software. If not, see . 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define MIN(x,y) (((x)<(y))?(x):(y)) 35 | 36 | STATIC_SIZE_CHECK_EQUAL(sizeof(struct hid_descriptor), 9); 37 | STATIC_SIZE_CHECK_EQUAL(sizeof(struct hid_optional_descriptor), 3); 38 | 39 | #ifdef MULTI_CLASS_DEVICE 40 | static uint8_t *hid_interfaces; 41 | static uint8_t num_hid_interfaces; 42 | 43 | void hid_set_interface_list(uint8_t *interfaces, uint8_t num_interfaces) 44 | { 45 | hid_interfaces = interfaces; 46 | num_hid_interfaces = num_interfaces; 47 | } 48 | #endif 49 | 50 | uint8_t process_hid_setup_request(const struct setup_packet *setup) 51 | { 52 | /* The following comes from the HID spec 1.11, section 7.1.1 */ 53 | 54 | uint8_t interface = setup->wIndex; 55 | 56 | #ifdef MULTI_CLASS_DEVICE 57 | /* Check the interface first to make sure the destination is a 58 | * HID interface. Composite devices will need to call 59 | * hid_set_interface_list() first. 60 | */ 61 | uint8_t i; 62 | for (i = 0; i < num_hid_interfaces; i++) { 63 | if (interface == hid_interfaces[i]) 64 | break; 65 | } 66 | 67 | /* Return if interface is not in the list of HID interfaces. */ 68 | if (i == num_hid_interfaces) 69 | return -1; 70 | #endif 71 | 72 | if (setup->bRequest == GET_DESCRIPTOR && 73 | setup->REQUEST.bmRequestType == 0x81) { 74 | uint8_t descriptor = ((setup->wValue >> 8) & 0x00ff); 75 | 76 | const void *desc; 77 | int16_t len = -1; 78 | 79 | if (descriptor == DESC_HID) { 80 | len = USB_HID_DESCRIPTOR_FUNC(interface, &desc); 81 | } 82 | else if (descriptor == DESC_REPORT) { 83 | len = USB_HID_REPORT_DESCRIPTOR_FUNC(interface, &desc); 84 | } 85 | #ifdef USB_HID_PHYSICAL_DESCRIPTOR_FUNC 86 | else if (descriptor == DESC_PHYSICAL) { 87 | uint8_t descriptor_index = setup->wValue & 0x00ff; 88 | len = USB_HID_PHYSICAL_DESCRIPTOR_FUNC(interface, descriptor_index, &desc); 89 | } 90 | #endif 91 | if (len < 0) 92 | return -1; 93 | 94 | usb_send_data_stage((void*) desc, min(len, setup->wLength), NULL, NULL); 95 | return 0; 96 | } 97 | 98 | /* No support for Set_Descriptor */ 99 | 100 | #ifdef HID_GET_REPORT_CALLBACK 101 | const void *desc; 102 | int16_t len = -1; 103 | usb_ep0_data_stage_callback callback; 104 | void *context; 105 | if (setup->bRequest == HID_GET_REPORT && 106 | setup->REQUEST.bmRequestType == 0xa1) { 107 | uint8_t report_type = (setup->wValue >> 8) & 0x00ff; 108 | uint8_t report_id = setup->wValue & 0x00ff; 109 | len = HID_GET_REPORT_CALLBACK(interface/*interface*/, 110 | report_type, report_id, 111 | &desc, &callback, &context); 112 | if (len < 0) 113 | return -1; 114 | 115 | usb_send_data_stage((void*)desc, min(len, setup->wLength), callback, context); 116 | return 0; 117 | } 118 | #endif 119 | 120 | #ifdef HID_SET_REPORT_CALLBACK 121 | if (setup->bRequest == HID_SET_REPORT && 122 | setup->REQUEST.bmRequestType == 0x21) { 123 | uint8_t report_type = (setup->wValue >> 8) & 0x00ff; 124 | uint8_t report_id = setup->wValue & 0x00ff; 125 | int8_t res = HID_SET_REPORT_CALLBACK(interface, 126 | report_type, report_id); 127 | return res; 128 | } 129 | #endif 130 | 131 | #ifdef HID_GET_IDLE_CALLBACK 132 | if (setup->bRequest == HID_GET_IDLE && 133 | setup->REQUEST.bmRequestType == 0xa1) { 134 | uint8_t report_id = setup->wValue & 0x00ff; 135 | uint8_t res = HID_GET_IDLE_CALLBACK(interface, report_id); 136 | 137 | usb_send_data_stage((char*)&res, 1, NULL, NULL); 138 | return 0; 139 | } 140 | #endif 141 | 142 | #ifdef HID_SET_IDLE_CALLBACK 143 | if (setup->bRequest == HID_SET_IDLE && 144 | setup->REQUEST.bmRequestType == 0x21) { 145 | uint8_t duration = (setup->wValue >> 8) & 0x00ff; 146 | uint8_t report_id = setup->wValue & 0x00ff; 147 | uint8_t res = HID_SET_IDLE_CALLBACK(interface, report_id, 148 | duration); 149 | 150 | return res; 151 | } 152 | #endif 153 | 154 | #ifdef HID_GET_PROTOCOL_CALLBACK 155 | if (setup->bRequest == HID_GET_PROTOCOL && 156 | setup->REQUEST.bmRequestType == 0xa1) { 157 | int8_t res = HID_GET_PROTOCOL_CALLBACK(interface); 158 | if (res < 0) 159 | return -1; 160 | 161 | usb_send_data_stage((char*)&res, 1, NULL, NULL); 162 | return 0; 163 | } 164 | #endif 165 | 166 | #ifdef HID_SET_PROTOCOL_CALLBACK 167 | if (setup->bRequest == HID_SET_PROTOCOL && 168 | setup->REQUEST.bmRequestType == 0x21) { 169 | int8_t res = HID_SET_PROTOCOL_CALLBACK(interface, 170 | setup->wValue); 171 | return res; 172 | } 173 | #endif 174 | 175 | return -1; 176 | } 177 | -------------------------------------------------------------------------------- /src/pic16f1454/usb_winusb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * M-Stack Automatic WinUSB Support 3 | * Copyright (C) 2013 Alan Ott 4 | * Copyright (C) 2013 Signal 11 Software 5 | * 6 | * 2013-10-12 7 | * 8 | * M-Stack is free software: you can redistribute it and/or modify it under 9 | * the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, version 3; or the Apache License, version 2.0 11 | * as published by the Apache Software Foundation. If you have purchased a 12 | * commercial license for this software from Signal 11 Software, your 13 | * commerical license superceeds the information in this header. 14 | * 15 | * M-Stack is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this software. If not, see . 22 | * 23 | * You should have received a copy of the Apache License, verion 2.0 along 24 | * with this software. If not, see . 25 | */ 26 | 27 | #ifndef USB_WINUSB_H__ 28 | #define USB_WINUSB_H__ 29 | 30 | #include 31 | 32 | /* Functions for automatic WinUSB support */ 33 | 34 | uint16_t m_stack_winusb_get_microsoft_compat(uint8_t interface, 35 | const void **descriptor); 36 | 37 | uint16_t m_stack_winusb_get_microsoft_property(uint8_t interface, 38 | const void **descriptor); 39 | 40 | #endif /* USB_WINUSB_H__ */ 41 | -------------------------------------------------------------------------------- /src/stm32f072/.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | stm32hidsensor THUMB Debug\* 3 | stm32hidsensor THUMB Release\* 4 | *.hzs 5 | -------------------------------------------------------------------------------- /src/stm32f072/HidSensorSpec.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majbthrd/HIDsensor/8ed0a6312c4c9daee7c0431c160af9fbb824d30a/src/stm32f072/HidSensorSpec.h -------------------------------------------------------------------------------- /src/stm32f072/MCD-ST Liberty SW License Agreement V2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majbthrd/HIDsensor/8ed0a6312c4c9daee7c0431c160af9fbb824d30a/src/stm32f072/MCD-ST Liberty SW License Agreement V2.pdf -------------------------------------------------------------------------------- /src/stm32f072/README.md: -------------------------------------------------------------------------------- 1 | example USB HID Sensor for STM32F072 microcontroller 2 | ==================================================== 3 | 4 | ## What It Does 5 | 6 | The firmware functions as a Temperature HID Sensor. It reports dummy values in progression from -50C to 125C, and then repeats. 7 | 8 | ## Requirements 9 | 10 | [Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) is needed to compile this code. The source code is gcc-friendly, but you must adapt the code yourself if you wish to adopt a different tool chain. 11 | 12 | ## Sanity Checklist If Customizing 13 | 14 | config.h has a NUM\_OF\_STANDARDHID value that is used throughout the code to control the number of HID interfaces. If contemplating multiple sensors, consider using multiple Input Report IDs for in lieu of multiple HID interfaces. 15 | 16 | The HID Interface numbers in the USB descriptor in usbd\_desc.c must be continguous and start from zero. 17 | 18 | One must manually ensure that the size of the HID Report descriptor (in usbd\_hid.c) equals the report size in the Configuration Descriptor in usbd\_desc.c. 19 | 20 | Customize the HID Report descriptor (in usbd\_hid.c) to suit your sensor. Refer to the protocol document [HUTRR39b](http://www.usb.org/developers/hidpage/HUTRR39b.pdf) for details. 21 | 22 | An understanding of USB descriptors is important when modifying usb\_desc.c. This data conveys the configuration of the device (including endpoint, etc.) to the host PC. 23 | 24 | Be *certain* that the Feature and Input Reports *exactly* match, byte-for-byte, what is described in the HID Report. 25 | 26 | USB transfers are handled via a distinct section of memory called "PMA". Read the ST documentation on this. At most, there is 1kBytes that must be shared across all endpoints. Consider the usage of this PMA memory when scaling up the number of interfaces and buffer sizes. 27 | 28 | -------------------------------------------------------------------------------- /src/stm32f072/config.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONFIG_H 2 | #define __CONFIG_H 3 | 4 | /* 5 | adjust these to suit the application 6 | */ 7 | #define NUM_OF_STANDARDHID 1 8 | 9 | #endif /* __CONFIG_H */ 10 | -------------------------------------------------------------------------------- /src/stm32f072/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | example USB HID Sensor for STM32F072 microcontroller 3 | 4 | Copyright (C) 2015,2016 Peter Lawrence 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include "usbd_desc.h" 26 | #include "usbd_composite.h" 27 | #include "usbd_hid.h" 28 | 29 | USBD_HandleTypeDef USBD_Device; 30 | 31 | static void SystemClock_Config(void); 32 | 33 | int main(void) 34 | { 35 | uint32_t last_tick, now_tick, delta; 36 | uint8_t HID_Buffer[4]; /* size chosen to match size of sensor's Input Report */ 37 | 38 | /* STM32F0xx HAL library initialization */ 39 | HAL_Init(); 40 | 41 | /* configure the system clock to get correspondent USB clock source */ 42 | SystemClock_Config(); 43 | 44 | /* Initialize Device Library */ 45 | USBD_Init(&USBD_Device, &USBD_Desc, 0); 46 | 47 | /* to work within ST's drivers, I've written a special USBD_Composite class that then invokes several classes */ 48 | USBD_RegisterClass(&USBD_Device, &USBD_Composite); 49 | 50 | /* Start Device Process */ 51 | USBD_Start(&USBD_Device); 52 | 53 | memset(HID_Buffer, 0, sizeof(HID_Buffer)); 54 | 55 | /* generate temperatures from -50.0C to 125.0C in increments of 1.0C */ 56 | int16_t temperature = -5000; 57 | for (;;) 58 | { 59 | HID_Buffer[0] = 0x02; /* Ready */ 60 | HID_Buffer[1] = 0x03; /* Data Updated */ 61 | HID_Buffer[2] = (temperature >> 0); /* sensor value */ 62 | HID_Buffer[3] = (temperature >> 8); 63 | 64 | /* send Input Report though IN endpoint */ 65 | USBD_HID_SendReport(&USBD_Device, 0, HID_Buffer, sizeof(HID_Buffer)); 66 | 67 | /* pick next value */ 68 | if (temperature > 12500) 69 | temperature = -5000; 70 | else 71 | temperature += 100; 72 | 73 | /* wait for prescribed interval (in ticks) before looping */ 74 | last_tick = HAL_GetTick(); 75 | do 76 | { 77 | __WFI(); 78 | now_tick = HAL_GetTick(); 79 | delta = now_tick - last_tick; 80 | } while (delta < 100); 81 | } 82 | } 83 | 84 | static void SystemClock_Config(void) 85 | { 86 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 87 | RCC_OscInitTypeDef RCC_OscInitStruct; 88 | RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; 89 | static RCC_CRSInitTypeDef RCC_CRSInitStruct; 90 | 91 | /* Enable HSI48 Oscillator to be used as system clock source */ 92 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; 93 | HAL_RCC_OscConfig(&RCC_OscInitStruct); 94 | 95 | /* Select HSI48 as USB clock source */ 96 | PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB; 97 | PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; 98 | HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); 99 | 100 | /* Select HSI48 as system clock source and configure the HCLK and PCLK1 clock dividers */ 101 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1); 102 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; 103 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 104 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 105 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); 106 | 107 | /*Configure the clock recovery system (CRS)**********************************/ 108 | 109 | /*Enable CRS Clock*/ 110 | __CRS_CLK_ENABLE(); 111 | 112 | /* Default Synchro Signal division factor (not divided) */ 113 | RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; 114 | 115 | /* Set the SYNCSRC[1:0] bits according to CRS_Source value */ 116 | RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; 117 | 118 | /* HSI48 is synchronized with USB SOF at 1KHz rate */ 119 | RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_CALCULATE_RELOADVALUE(48000000, 1000); 120 | RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT; 121 | 122 | /* Set the TRIM[5:0] to the default value*/ 123 | RCC_CRSInitStruct.HSI48CalibrationValue = 0x20; 124 | 125 | /* Start automatic synchronization */ 126 | HAL_RCCEx_CRSConfig (&RCC_CRSInitStruct); 127 | } 128 | -------------------------------------------------------------------------------- /src/stm32f072/standardhidhelper.h: -------------------------------------------------------------------------------- 1 | #ifndef __STANDARDHID_HELPER_H 2 | #define __STANDARDHID_HELPER_H 3 | 4 | #include 5 | #include "usbhelper.h" 6 | 7 | /* macro to help generate Standard HID (e.g. keyboard and mouse) USB descriptors */ 8 | 9 | #define STANDARDHID_DESCRIPTOR(HID_INTF, DATAIN_EP, HID_REPORT_DESC_SIZE, HID_PROTOCOL) \ 10 | { \ 11 | { \ 12 | /*Interface Descriptor */ \ 13 | sizeof(struct interface_descriptor), /* bLength: Interface Descriptor size */ \ 14 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ \ 15 | HID_INTF, /* bInterfaceNumber: Number of Interface */ \ 16 | 0x00, /* bAlternateSetting: Alternate setting */ \ 17 | 0x01, /* bNumEndpoints */ \ 18 | 0x03, /* bInterfaceClass: HID */ \ 19 | 0x00, /* bInterfaceSubClass: 1=BOOT, 0=no boot */ \ 20 | HID_PROTOCOL, /* bInterfaceProtocol: 0=none, 1=keyboard, 2=mouse */ \ 21 | 0x00, /* iInterface (string index) */ \ 22 | }, \ 23 | \ 24 | { \ 25 | sizeof(struct hid_functional_descriptor), /* bLength */ \ 26 | HID_DESCRIPTOR_TYPE, /* bDescriptorType */ \ 27 | USB_UINT16(0x0111), /* bcdHID */ \ 28 | 0x00, /* bCountryCode */ \ 29 | 0x01, /* bNumDescriptors */ \ 30 | HID_REPORT_DESC, /* bDescriptorType */ \ 31 | USB_UINT16(HID_REPORT_DESC_SIZE), /* wItemLength */ \ 32 | }, \ 33 | \ 34 | { \ 35 | sizeof(struct endpoint_descriptor), /* bLength: Endpoint Descriptor size */ \ 36 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ \ 37 | DATAIN_EP, /* bEndpointAddress */ \ 38 | 0x03, /* bmAttributes: Interrupt */ \ 39 | USB_UINT16(HID_EP_SIZE), /* wMaxPacketSize */ \ 40 | HID_POLLING_INTERVAL, /* bInterval */ \ 41 | }, \ 42 | }, 43 | 44 | struct standardhid_interface 45 | { 46 | struct interface_descriptor ctl_interface; 47 | struct hid_functional_descriptor hid_func; 48 | struct endpoint_descriptor ep_in; 49 | }; 50 | 51 | #define HIDMOUSE_DESCRIPTOR(HID_INTF, DATAIN_EP, HID_REPORT_DESC_SIZE) STANDARDHID_DESCRIPTOR(HID_INTF, DATAIN_EP, HID_REPORT_DESC_SIZE, 2) 52 | #define HIDKEYBOARD_DESCRIPTOR(HID_INTF, DATAIN_EP, HID_REPORT_DESC_SIZE) STANDARDHID_DESCRIPTOR(HID_INTF, DATAIN_EP, HID_REPORT_DESC_SIZE, 1) 53 | #define HIDNONE_DESCRIPTOR(HID_INTF, DATAIN_EP, HID_REPORT_DESC_SIZE) STANDARDHID_DESCRIPTOR(HID_INTF, DATAIN_EP, HID_REPORT_DESC_SIZE, 0) 54 | 55 | #endif /* __STANDARDHID_HELPER_H */ 56 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_hal_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_conf.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 18-June-2014 7 | * @brief HAL configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F0xx_HAL_CONF_H 40 | #define __STM32F0xx_HAL_CONF_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Exported types ------------------------------------------------------------*/ 47 | /* Exported constants --------------------------------------------------------*/ 48 | 49 | /* ########################## Module Selection ############################## */ 50 | /** 51 | * @brief This is the list of modules to be used in the HAL driver 52 | */ 53 | #define HAL_MODULE_ENABLED 54 | /* #define HAL_ADC_MODULE_ENABLED */ 55 | /* #define HAL_CAN_MODULE_ENABLED */ 56 | /*#define HAL_CEC_MODULE_ENABLED*/ 57 | /* #define HAL_COMP_MODULE_ENABLED */ 58 | #define HAL_CORTEX_MODULE_ENABLED 59 | /* #define HAL_CRC_MODULE_ENABLED */ 60 | /* #define HAL_DAC_MODULE_ENABLED */ 61 | /* #define HAL_DMA_MODULE_ENABLED */ 62 | #define HAL_FLASH_MODULE_ENABLED 63 | #define HAL_GPIO_MODULE_ENABLED 64 | /* #define HAL_I2C_MODULE_ENABLED */ 65 | /*#define HAL_I2S_MODULE_ENABLED*/ 66 | /* #define HAL_IRDA_MODULE_ENABLED */ 67 | /* #define HAL_IWDG_MODULE_ENABLED */ 68 | #define HAL_PCD_MODULE_ENABLED 69 | #define HAL_PWR_MODULE_ENABLED 70 | #define HAL_RCC_MODULE_ENABLED 71 | /* #define HAL_RTC_MODULE_ENABLED */ 72 | /* #define HAL_SMARTCARD_MODULE_ENABLED */ 73 | /* #define HAL_SMBUS_MODULE_ENABLED */ 74 | /* #define HAL_SPI_MODULE_ENABLED */ 75 | /* #define HAL_TIM_MODULE_ENABLED */ 76 | /* #define HAL_TSC_MODULE_ENABLED */ 77 | /* #define HAL_UART_MODULE_ENABLED */ 78 | /* #define HAL_USART_MODULE_ENABLED */ 79 | /* #define HAL_WWDG_MODULE_ENABLED */ 80 | 81 | /* ######################### Oscillator Values adaptation ################### */ 82 | /** 83 | * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. 84 | * This value is used by the RCC HAL module to compute the system frequency 85 | * (when HSE is used as system clock source, directly or through the PLL). 86 | */ 87 | #if !defined (HSE_VALUE) 88 | #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ 89 | #endif /* HSE_VALUE */ 90 | 91 | /** 92 | * @brief In the following line adjust the External High Speed oscillator (HSE) Startup 93 | * Timeout value 94 | */ 95 | #if !defined (HSE_STARTUP_TIMEOUT) 96 | #define HSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSE start up, in ms */ 97 | #endif /* HSE_STARTUP_TIMEOUT */ 98 | 99 | /** 100 | * @brief Internal High Speed oscillator (HSI) value. 101 | * This value is used by the RCC HAL module to compute the system frequency 102 | * (when HSI is used as system clock source, directly or through the PLL). 103 | */ 104 | #if !defined (HSI_VALUE) 105 | #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ 106 | #endif /* HSI_VALUE */ 107 | 108 | /** 109 | * @brief In the following line adjust the Internal High Speed oscillator (HSI) Startup 110 | * Timeout value 111 | */ 112 | #if !defined (HSI_STARTUP_TIMEOUT) 113 | #define HSI_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSI start up */ 114 | #endif /* HSI_STARTUP_TIMEOUT */ 115 | 116 | /** 117 | * @brief Internal High Speed oscillator for ADC (HSI14) value. 118 | */ 119 | #if !defined (HSI14_VALUE) 120 | #define HSI14_VALUE ((uint32_t)14000000) /*!< Value of the Internal High Speed oscillator for ADC in Hz. 121 | The real value may vary depending on the variations 122 | in voltage and temperature. */ 123 | #endif /* HSI14_VALUE */ 124 | 125 | /** 126 | * @brief Internal High Speed oscillator for USB (HSI48) value. 127 | */ 128 | #if !defined (HSI48_VALUE) 129 | #define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz. 130 | The real value may vary depending on the variations 131 | in voltage and temperature. */ 132 | #endif /* HSI48_VALUE */ 133 | 134 | /** 135 | * @brief Internal Low Speed oscillator (LSI) value. 136 | */ 137 | #if !defined (LSI_VALUE) 138 | #define LSI_VALUE ((uint32_t)40000) 139 | #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz 140 | The real value may vary depending on the variations 141 | in voltage and temperature. */ 142 | /** 143 | * @brief External Low Speed oscillator (LSE) value. 144 | */ 145 | #if !defined (LSE_VALUE) 146 | #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */ 147 | #endif /* LSE_VALUE */ 148 | 149 | 150 | /* Tip: To avoid modifying this file each time you need to use different HSE, 151 | === you can define the HSE value in your toolchain compiler preprocessor. */ 152 | 153 | /* ########################### System Configuration ######################### */ 154 | /** 155 | * @brief This is the HAL system configuration section 156 | */ 157 | #define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ 158 | #define TICK_INT_PRIORITY 0 /*!< tick interrupt priority (lowest by default) */ 159 | /* Warning: Must be set to higher priority for HAL_Delay() */ 160 | /* and HAL_GetTick() usage under interrupt context */ 161 | #define USE_RTOS 0 162 | #define PREFETCH_ENABLE 1 163 | #define INSTRUCTION_CACHE_ENABLE 0 164 | #define DATA_CACHE_ENABLE 0 165 | 166 | /* ########################## Assert Selection ############################## */ 167 | /** 168 | * @brief Uncomment the line below to expanse the "assert_param" macro in the 169 | * HAL drivers code 170 | */ 171 | /*#define USE_FULL_ASSERT 1*/ 172 | 173 | /* Includes ------------------------------------------------------------------*/ 174 | /** 175 | * @brief Include module's header file 176 | */ 177 | 178 | #ifdef HAL_RCC_MODULE_ENABLED 179 | #include "stm32f0xx_hal_rcc.h" 180 | #endif /* HAL_RCC_MODULE_ENABLED */ 181 | 182 | #ifdef HAL_GPIO_MODULE_ENABLED 183 | #include "stm32f0xx_hal_gpio.h" 184 | #endif /* HAL_GPIO_MODULE_ENABLED */ 185 | 186 | #ifdef HAL_DMA_MODULE_ENABLED 187 | #include "stm32f0xx_hal_dma.h" 188 | #endif /* HAL_DMA_MODULE_ENABLED */ 189 | 190 | #ifdef HAL_CORTEX_MODULE_ENABLED 191 | #include "stm32f0xx_hal_cortex.h" 192 | #endif /* HAL_CORTEX_MODULE_ENABLED */ 193 | 194 | #ifdef HAL_ADC_MODULE_ENABLED 195 | #include "stm32f0xx_hal_adc.h" 196 | #endif /* HAL_ADC_MODULE_ENABLED */ 197 | 198 | #ifdef HAL_CAN_MODULE_ENABLED 199 | #include "stm32f0xx_hal_can.h" 200 | #endif /* HAL_CAN_MODULE_ENABLED */ 201 | 202 | #ifdef HAL_CEC_MODULE_ENABLED 203 | #include "stm32f0xx_hal_cec.h" 204 | #endif /* HAL_CEC_MODULE_ENABLED */ 205 | 206 | #ifdef HAL_COMP_MODULE_ENABLED 207 | #include "stm32f0xx_hal_comp.h" 208 | #endif /* HAL_COMP_MODULE_ENABLED */ 209 | 210 | #ifdef HAL_CRC_MODULE_ENABLED 211 | #include "stm32f0xx_hal_crc.h" 212 | #endif /* HAL_CRC_MODULE_ENABLED */ 213 | 214 | #ifdef HAL_DAC_MODULE_ENABLED 215 | #include "stm32f0xx_hal_dac.h" 216 | #endif /* HAL_DAC_MODULE_ENABLED */ 217 | 218 | #ifdef HAL_FLASH_MODULE_ENABLED 219 | #include "stm32f0xx_hal_flash.h" 220 | #endif /* HAL_FLASH_MODULE_ENABLED */ 221 | 222 | #ifdef HAL_I2C_MODULE_ENABLED 223 | #include "stm32f0xx_hal_i2c.h" 224 | #endif /* HAL_I2C_MODULE_ENABLED */ 225 | 226 | #ifdef HAL_I2S_MODULE_ENABLED 227 | #include "stm32f0xx_hal_i2s.h" 228 | #endif /* HAL_I2S_MODULE_ENABLED */ 229 | 230 | #ifdef HAL_IRDA_MODULE_ENABLED 231 | #include "stm32f0xx_hal_irda.h" 232 | #endif /* HAL_IRDA_MODULE_ENABLED */ 233 | 234 | #ifdef HAL_IWDG_MODULE_ENABLED 235 | #include "stm32f0xx_hal_iwdg.h" 236 | #endif /* HAL_IWDG_MODULE_ENABLED */ 237 | 238 | #ifdef HAL_PCD_MODULE_ENABLED 239 | #include "stm32f0xx_hal_pcd.h" 240 | #endif /* HAL_PCD_MODULE_ENABLED */ 241 | 242 | #ifdef HAL_PWR_MODULE_ENABLED 243 | #include "stm32f0xx_hal_pwr.h" 244 | #endif /* HAL_PWR_MODULE_ENABLED */ 245 | 246 | #ifdef HAL_RTC_MODULE_ENABLED 247 | #include "stm32f0xx_hal_rtc.h" 248 | #endif /* HAL_RTC_MODULE_ENABLED */ 249 | 250 | #ifdef HAL_SMARTCARD_MODULE_ENABLED 251 | #include "stm32f0xx_hal_smartcard.h" 252 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ 253 | 254 | #ifdef HAL_SMBUS_MODULE_ENABLED 255 | #include "stm32f0xx_hal_smbus.h" 256 | #endif /* HAL_SMBUS_MODULE_ENABLED */ 257 | 258 | #ifdef HAL_SPI_MODULE_ENABLED 259 | #include "stm32f0xx_hal_spi.h" 260 | #endif /* HAL_SPI_MODULE_ENABLED */ 261 | 262 | #ifdef HAL_TIM_MODULE_ENABLED 263 | #include "stm32f0xx_hal_tim.h" 264 | #endif /* HAL_TIM_MODULE_ENABLED */ 265 | 266 | #ifdef HAL_TSC_MODULE_ENABLED 267 | #include "stm32f0xx_hal_tsc.h" 268 | #endif /* HAL_TSC_MODULE_ENABLED */ 269 | 270 | #ifdef HAL_UART_MODULE_ENABLED 271 | #include "stm32f0xx_hal_uart.h" 272 | #endif /* HAL_UART_MODULE_ENABLED */ 273 | 274 | #ifdef HAL_USART_MODULE_ENABLED 275 | #include "stm32f0xx_hal_usart.h" 276 | #endif /* HAL_USART_MODULE_ENABLED */ 277 | 278 | #ifdef HAL_WWDG_MODULE_ENABLED 279 | #include "stm32f0xx_hal_wwdg.h" 280 | #endif /* HAL_WWDG_MODULE_ENABLED */ 281 | 282 | /* Exported macro ------------------------------------------------------------*/ 283 | #ifdef USE_FULL_ASSERT 284 | /** 285 | * @brief The assert_param macro is used for function's parameters check. 286 | * @param expr: If expr is false, it calls assert_failed function 287 | * which reports the name of the source file and the source 288 | * line number of the call that failed. 289 | * If expr is true, it returns no value. 290 | * @retval None 291 | */ 292 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 293 | /* Exported functions ------------------------------------------------------- */ 294 | void assert_failed(uint8_t* file, uint32_t line); 295 | #else 296 | #define assert_param(expr) ((void)0) 297 | #endif /* USE_FULL_ASSERT */ 298 | 299 | #ifdef __cplusplus 300 | } 301 | #endif 302 | 303 | #endif /* __STM32F0xx_HAL_CONF_H */ 304 | 305 | 306 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 307 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_hal_cortex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_cortex.c 4 | * @author MCD Application Team 5 | * @version V1.2.1 6 | * @date 09-January-2015 7 | * @brief CORTEX HAL module driver. 8 | * This file provides firmware functions to manage the following 9 | * functionalities of the CORTEX: 10 | * + Initialization and de-initialization functions 11 | * + Peripheral Control functions 12 | * 13 | * @verbatim 14 | ============================================================================== 15 | ##### How to use this driver ##### 16 | ============================================================================== 17 | 18 | [..] 19 | *** How to configure Interrupts using CORTEX HAL driver *** 20 | =========================================================== 21 | [..] 22 | This section provides functions allowing to configure the NVIC interrupts (IRQ). 23 | The Cortex-M0 exceptions are managed by CMSIS functions. 24 | (#) Enable and Configure the priority of the selected IRQ Channels. 25 | The priority can be 0..3. 26 | 27 | -@- Lower priority values gives higher priority. 28 | -@- Priority Order: 29 | (#@) Lowest priority. 30 | (#@) Lowest hardware priority (IRQn position). 31 | 32 | (#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority() 33 | 34 | (#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ() 35 | 36 | 37 | [..] 38 | *** How to configure Systick using CORTEX HAL driver *** 39 | ======================================================== 40 | [..] 41 | Setup SysTick Timer for time base 42 | 43 | (+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which 44 | is a CMSIS function that: 45 | (++) Configures the SysTick Reload register with value passed as function parameter. 46 | (++) Configures the SysTick IRQ priority to the lowest value (0x03). 47 | (++) Resets the SysTick Counter register. 48 | (++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK). 49 | (++) Enables the SysTick Interrupt. 50 | (++) Starts the SysTick Counter. 51 | 52 | (+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro 53 | __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the 54 | HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined 55 | inside the stm32f0xx_hal_cortex.h file. 56 | 57 | (+) You can change the SysTick IRQ priority by calling the 58 | HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function 59 | call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function. 60 | 61 | (+) To adjust the SysTick time base, use the following formula: 62 | 63 | Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s) 64 | (++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function 65 | (++) Reload Value should not exceed 0xFFFFFF 66 | 67 | @endverbatim 68 | ****************************************************************************** 69 | * @attention 70 | * 71 | *

© COPYRIGHT(c) 2015 STMicroelectronics

72 | * 73 | * Redistribution and use in source and binary forms, with or without modification, 74 | * are permitted provided that the following conditions are met: 75 | * 1. Redistributions of source code must retain the above copyright notice, 76 | * this list of conditions and the following disclaimer. 77 | * 2. Redistributions in binary form must reproduce the above copyright notice, 78 | * this list of conditions and the following disclaimer in the documentation 79 | * and/or other materials provided with the distribution. 80 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 81 | * may be used to endorse or promote products derived from this software 82 | * without specific prior written permission. 83 | * 84 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 85 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 86 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 87 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 88 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 89 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 90 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 91 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 92 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 93 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 94 | * 95 | ****************************************************************************** 96 | */ 97 | 98 | /* Includes ------------------------------------------------------------------*/ 99 | #include "stm32f0xx_hal.h" 100 | 101 | /** @addtogroup STM32F0xx_HAL_Driver 102 | * @{ 103 | */ 104 | 105 | /** @defgroup CORTEX CORTEX HAL module driver 106 | * @brief CORTEX CORTEX HAL module driver 107 | * @{ 108 | */ 109 | 110 | #ifdef HAL_CORTEX_MODULE_ENABLED 111 | 112 | /* Private typedef -----------------------------------------------------------*/ 113 | /* Private define ------------------------------------------------------------*/ 114 | /* Private macro -------------------------------------------------------------*/ 115 | /* Private variables ---------------------------------------------------------*/ 116 | /* Private function prototypes -----------------------------------------------*/ 117 | /* Exported functions ---------------------------------------------------------*/ 118 | 119 | /** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions 120 | * @{ 121 | */ 122 | 123 | 124 | /** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions 125 | * @brief Initialization and Configuration functions 126 | * 127 | @verbatim 128 | ============================================================================== 129 | ##### Initialization and de-initialization functions ##### 130 | ============================================================================== 131 | [..] 132 | This section provides the CORTEX HAL driver functions allowing to configure Interrupts 133 | Systick functionalities 134 | 135 | @endverbatim 136 | * @{ 137 | */ 138 | 139 | /** 140 | * @brief Sets the priority of an interrupt. 141 | * @param IRQn: External interrupt number . 142 | * This parameter can be an enumerator of IRQn_Type enumeration 143 | * (For the complete STM32 Devices IRQ Channels list, please refer to stm32l0xx.h file) 144 | * @param PreemptPriority: The pre-emption priority for the IRQn channel. 145 | * This parameter can be a value between 0 and 3. 146 | * A lower priority value indicates a higher priority 147 | * @param SubPriority: The subpriority level for the IRQ channel. 148 | * with stm32f0xx devices, this parameter is a dummy value and it is ignored, because 149 | * no subpriority supported in Cortex M0 based products. 150 | * @retval None 151 | */ 152 | void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) 153 | { 154 | /* Check the parameters */ 155 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); 156 | NVIC_SetPriority(IRQn,PreemptPriority); 157 | } 158 | 159 | /** 160 | * @brief Enables a device specific interrupt in the NVIC interrupt controller. 161 | * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig() 162 | * function should be called before. 163 | * @param IRQn External interrupt number 164 | * This parameter can be an enumerator of IRQn_Type enumeration 165 | * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h)) 166 | * @retval None 167 | */ 168 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn) 169 | { 170 | /* Enable interrupt */ 171 | NVIC_EnableIRQ(IRQn); 172 | } 173 | 174 | /** 175 | * @brief Disables a device specific interrupt in the NVIC interrupt controller. 176 | * @param IRQn External interrupt number 177 | * This parameter can be an enumerator of IRQn_Type enumeration 178 | * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h)) 179 | * @retval None 180 | */ 181 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn) 182 | { 183 | /* Disable interrupt */ 184 | NVIC_DisableIRQ(IRQn); 185 | } 186 | 187 | /** 188 | * @brief Initiates a system reset request to reset the MCU. 189 | * @retval None 190 | */ 191 | void HAL_NVIC_SystemReset(void) 192 | { 193 | /* System Reset */ 194 | NVIC_SystemReset(); 195 | } 196 | 197 | /** 198 | * @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer. 199 | * Counter is in free running mode to generate periodic interrupts. 200 | * @param TicksNumb: Specifies the ticks Number of ticks between two interrupts. 201 | * @retval status: - 0 Function succeeded. 202 | * - 1 Function failed. 203 | */ 204 | uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb) 205 | { 206 | return SysTick_Config(TicksNumb); 207 | } 208 | /** 209 | * @} 210 | */ 211 | 212 | /** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions 213 | * @brief Cortex control functions 214 | * 215 | @verbatim 216 | ============================================================================== 217 | ##### Peripheral Control functions ##### 218 | ============================================================================== 219 | [..] 220 | This subsection provides a set of functions allowing to control the CORTEX 221 | (NVIC, SYSTICK) functionalities. 222 | 223 | 224 | @endverbatim 225 | * @{ 226 | */ 227 | 228 | 229 | /** 230 | * @brief Gets the priority of an interrupt. 231 | * @param IRQn: External interrupt number 232 | * This parameter can be an enumerator of IRQn_Type enumeration 233 | * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h)) 234 | * @retval None 235 | */ 236 | uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn) 237 | { 238 | /* Get priority for Cortex-M system or device specific interrupts */ 239 | return NVIC_GetPriority(IRQn); 240 | } 241 | 242 | /** 243 | * @brief Sets Pending bit of an external interrupt. 244 | * @param IRQn External interrupt number 245 | * This parameter can be an enumerator of IRQn_Type enumeration 246 | * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h)) 247 | * @retval None 248 | */ 249 | void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn) 250 | { 251 | /* Set interrupt pending */ 252 | NVIC_SetPendingIRQ(IRQn); 253 | } 254 | 255 | /** 256 | * @brief Gets Pending Interrupt (reads the pending register in the NVIC 257 | * and returns the pending bit for the specified interrupt). 258 | * @param IRQn External interrupt number 259 | * This parameter can be an enumerator of IRQn_Type enumeration 260 | * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h)) 261 | * @retval status: - 0 Interrupt status is not pending. 262 | * - 1 Interrupt status is pending. 263 | */ 264 | uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn) 265 | { 266 | /* Return 1 if pending else 0 */ 267 | return NVIC_GetPendingIRQ(IRQn); 268 | } 269 | 270 | /** 271 | * @brief Clears the pending bit of an external interrupt. 272 | * @param IRQn External interrupt number 273 | * This parameter can be an enumerator of IRQn_Type enumeration 274 | * (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f0xxxx.h)) 275 | * @retval None 276 | */ 277 | void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn) 278 | { 279 | /* Clear pending interrupt */ 280 | NVIC_ClearPendingIRQ(IRQn); 281 | } 282 | 283 | /** 284 | * @brief Configures the SysTick clock source. 285 | * @param CLKSource: specifies the SysTick clock source. 286 | * This parameter can be one of the following values: 287 | * @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source. 288 | * @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source. 289 | * @retval None 290 | */ 291 | void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource) 292 | { 293 | /* Check the parameters */ 294 | assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource)); 295 | if (CLKSource == SYSTICK_CLKSOURCE_HCLK) 296 | { 297 | SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK; 298 | } 299 | else 300 | { 301 | SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK; 302 | } 303 | } 304 | 305 | /** 306 | * @brief This function handles SYSTICK interrupt request. 307 | * @retval None 308 | */ 309 | void HAL_SYSTICK_IRQHandler(void) 310 | { 311 | HAL_SYSTICK_Callback(); 312 | } 313 | 314 | /** 315 | * @brief SYSTICK callback. 316 | * @retval None 317 | */ 318 | __weak void HAL_SYSTICK_Callback(void) 319 | { 320 | /* NOTE : This function Should not be modified, when the callback is needed, 321 | the HAL_SYSTICK_Callback could be implemented in the user file 322 | */ 323 | } 324 | 325 | /** 326 | * @} 327 | */ 328 | 329 | /** 330 | * @} 331 | */ 332 | 333 | #endif /* HAL_CORTEX_MODULE_ENABLED */ 334 | /** 335 | * @} 336 | */ 337 | 338 | /** 339 | * @} 340 | */ 341 | 342 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 343 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_hal_cortex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_cortex.h 4 | * @author MCD Application Team 5 | * @version V1.2.1 6 | * @date 09-January-2015 7 | * @brief Header file of CORTEX HAL module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2015 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F0xx_HAL_CORTEX_H 40 | #define __STM32F0xx_HAL_CORTEX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f0xx_hal_def.h" 48 | 49 | /** @addtogroup STM32F0xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup CORTEX CORTEX HAL module driver 54 | * @{ 55 | */ 56 | /* Exported types ------------------------------------------------------------*/ 57 | /* Exported constants --------------------------------------------------------*/ 58 | /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants 59 | * @{ 60 | */ 61 | 62 | /** @defgroup CORTEX_Priority CORTEX Priority 63 | * @{ 64 | */ 65 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x4) 66 | /** 67 | * @} 68 | */ 69 | 70 | /** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source 71 | * @{ 72 | */ 73 | #define SYSTICK_CLKSOURCE_HCLK_DIV8 ((uint32_t)0x00000000) 74 | #define SYSTICK_CLKSOURCE_HCLK ((uint32_t)0x00000004) 75 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \ 76 | ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8)) 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /* Exported Macros -----------------------------------------------------------*/ 86 | /** @defgroup CORTEX_Exported_Macro CORTEX Exported Macro 87 | * @{ 88 | */ 89 | 90 | /** @brief Configures the SysTick clock source. 91 | * @param __CLKSRC__: specifies the SysTick clock source. 92 | * This parameter can be one of the following values: 93 | * @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source. 94 | * @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source. 95 | * @retval None 96 | */ 97 | #define __HAL_CORTEX_SYSTICKCLK_CONFIG(__CLKSRC__) \ 98 | do { \ 99 | if ((__CLKSRC__) == SYSTICK_CLKSOURCE_HCLK) \ 100 | { \ 101 | SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK; \ 102 | } \ 103 | else \ 104 | SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK; \ 105 | } while(0) 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /* Exported functions --------------------------------------------------------*/ 112 | /** @addtogroup CORTEX_Exported_Functions CORTEX Exported Functions 113 | * @{ 114 | */ 115 | /** @addtogroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions 116 | * @brief Initialization and Configuration functions 117 | * @{ 118 | */ 119 | /* Initialization and de-initialization functions *******************************/ 120 | void HAL_NVIC_SetPriority(IRQn_Type IRQn,uint32_t PreemptPriority, uint32_t SubPriority); 121 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); 122 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); 123 | void HAL_NVIC_SystemReset(void); 124 | uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb); 125 | /** 126 | * @} 127 | */ 128 | 129 | /** @addtogroup CORTEX_Exported_Functions_Group2 Peripheral Control functions 130 | * @brief Cortex control functions 131 | * @{ 132 | */ 133 | 134 | /* Peripheral Control functions *************************************************/ 135 | uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn); 136 | uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn); 137 | void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn); 138 | void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn); 139 | void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource); 140 | void HAL_SYSTICK_IRQHandler(void); 141 | void HAL_SYSTICK_Callback(void); 142 | /** 143 | * @} 144 | */ 145 | 146 | /** 147 | * @} 148 | */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif 161 | 162 | #endif /* __STM32F0xx_HAL_CORTEX_H */ 163 | 164 | 165 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 166 | 167 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_def.h 4 | * @author MCD Application Team 5 | * @version V1.2.1 6 | * @date 09-January-2015 7 | * @brief This file contains HAL common defines, enumeration, macros and 8 | * structures definitions. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT(c) 2015 STMicroelectronics

13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __STM32F0xx_HAL_DEF 41 | #define __STM32F0xx_HAL_DEF 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "stm32f0xx.h" 49 | 50 | /* Exported types ------------------------------------------------------------*/ 51 | 52 | /** 53 | * @brief HAL Status structures definition 54 | */ 55 | typedef enum 56 | { 57 | HAL_OK = 0x00, 58 | HAL_ERROR = 0x01, 59 | HAL_BUSY = 0x02, 60 | HAL_TIMEOUT = 0x03 61 | } HAL_StatusTypeDef; 62 | 63 | /** 64 | * @brief HAL Lock structures definition 65 | */ 66 | typedef enum 67 | { 68 | HAL_UNLOCKED = 0x00, 69 | HAL_LOCKED = 0x01 70 | } HAL_LockTypeDef; 71 | 72 | /* Exported macro ------------------------------------------------------------*/ 73 | #ifndef NULL 74 | #define NULL 0 75 | #endif 76 | 77 | #define HAL_MAX_DELAY 0xFFFFFFFF 78 | 79 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != RESET) 80 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET) 81 | 82 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD_, __DMA_HANDLE_) \ 83 | do{ \ 84 | (__HANDLE__)->__PPP_DMA_FIELD_ = &(__DMA_HANDLE_); \ 85 | (__DMA_HANDLE_).Parent = (__HANDLE__); \ 86 | } while(0) 87 | 88 | #define UNUSED(x) ((void)(x)) 89 | 90 | /** @brief Reset the Handle's State field. 91 | * @param __HANDLE__: specifies the Peripheral Handle. 92 | * @note This macro can be used for the following purpose: 93 | * - When the Handle is declared as local variable; before passing it as parameter 94 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 95 | * to set to 0 the Handle's "State" field. 96 | * Otherwise, "State" field may have any random value and the first time the function 97 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 98 | * (i.e. HAL_PPP_MspInit() will not be executed). 99 | * - When there is a need to reconfigure the low level hardware: instead of calling 100 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 101 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 102 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 103 | * @retval None 104 | */ 105 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0) 106 | 107 | #if (USE_RTOS == 1) 108 | #error " USE_RTOS should be 0 in the current HAL release " 109 | #else 110 | #define __HAL_LOCK(__HANDLE__) \ 111 | do{ \ 112 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 113 | { \ 114 | return HAL_BUSY; \ 115 | } \ 116 | else \ 117 | { \ 118 | (__HANDLE__)->Lock = HAL_LOCKED; \ 119 | } \ 120 | }while (0) 121 | 122 | #define __HAL_UNLOCK(__HANDLE__) \ 123 | do{ \ 124 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 125 | }while (0) 126 | #endif /* USE_RTOS */ 127 | 128 | #if defined ( __GNUC__ ) 129 | #ifndef __weak 130 | #define __weak __attribute__((weak)) 131 | #endif /* __weak */ 132 | #ifndef __packed 133 | #define __packed __attribute__((__packed__)) 134 | #endif /* __packed */ 135 | #endif /* __GNUC__ */ 136 | 137 | 138 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 139 | #if defined (__GNUC__) /* GNU Compiler */ 140 | #ifndef __ALIGN_END 141 | #define __ALIGN_END __attribute__ ((aligned (4))) 142 | #endif /* __ALIGN_END */ 143 | #ifndef __ALIGN_BEGIN 144 | #define __ALIGN_BEGIN 145 | #endif /* __ALIGN_BEGIN */ 146 | #else 147 | #ifndef __ALIGN_END 148 | #define __ALIGN_END 149 | #endif /* __ALIGN_END */ 150 | #ifndef __ALIGN_BEGIN 151 | #if defined (__CC_ARM) /* ARM Compiler */ 152 | #define __ALIGN_BEGIN __align(4) 153 | #elif defined (__ICCARM__) /* IAR Compiler */ 154 | #define __ALIGN_BEGIN 155 | #endif /* __CC_ARM */ 156 | #endif /* __ALIGN_BEGIN */ 157 | #endif /* __GNUC__ */ 158 | 159 | /** 160 | * @brief __NOINLINE definition 161 | */ 162 | #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 163 | /* ARM & GNUCompiler 164 | ---------------- 165 | */ 166 | #define __NOINLINE __attribute__ ( (noinline) ) 167 | 168 | #elif defined ( __ICCARM__ ) 169 | /* ICCARM Compiler 170 | --------------- 171 | */ 172 | #define __NOINLINE _Pragma("optimize = no_inline") 173 | 174 | #endif 175 | 176 | #ifdef __cplusplus 177 | } 178 | #endif 179 | 180 | #endif /* ___STM32F0xx_HAL_DEF */ 181 | 182 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 183 | 184 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_hal_pcd_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pcd_ex.c 4 | * @author MCD Application Team 5 | * @version V1.2.1 6 | * @date 09-January-2015 7 | * @brief Extended PCD HAL module driver. 8 | * This file provides firmware functions to manage the following 9 | * functionalities of the USB Peripheral Controller: 10 | * + Configuration of the PMA for EP 11 | * 12 | ****************************************************************************** 13 | * @attention 14 | * 15 | *

© COPYRIGHT(c) 2015 STMicroelectronics

16 | * 17 | * Redistribution and use in source and binary forms, with or without modification, 18 | * are permitted provided that the following conditions are met: 19 | * 1. Redistributions of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 25 | * may be used to endorse or promote products derived from this software 26 | * without specific prior written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | ****************************************************************************** 40 | */ 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm32f0xx_hal.h" 44 | 45 | #ifdef HAL_PCD_MODULE_ENABLED 46 | 47 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)|| defined(STM32F070x6) 48 | 49 | /** @addtogroup STM32F0xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @defgroup PCDEx PCDEx Extended HAL module driver 54 | * @brief PCDEx PCDEx Extended HAL module driver 55 | * @{ 56 | */ 57 | /* Private typedef -----------------------------------------------------------*/ 58 | /* Private define ------------------------------------------------------------*/ 59 | /* Private macro -------------------------------------------------------------*/ 60 | /* Private variables ---------------------------------------------------------*/ 61 | /* Private function prototypes -----------------------------------------------*/ 62 | /* Exported functions ---------------------------------------------------------*/ 63 | 64 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions 65 | * @{ 66 | */ 67 | 68 | /** @defgroup PCDEx_Exported_Functions_Group2 Initialization and de-initialization functions 69 | * @brief Initialization and Configuration functions 70 | * 71 | @verbatim 72 | =============================================================================== 73 | ##### Peripheral extended features methods ##### 74 | =============================================================================== 75 | @endverbatim 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief Configure PMA for EP 81 | * @param hpcd: PCD handle 82 | * @param ep_addr: endpoint address 83 | * @param ep_kind: endpoint Kind 84 | * @arg USB_SNG_BUF: Single Buffer used 85 | * @arg USB_DBL_BUF: Double Buffer used 86 | * @param pmaadress: EP address in The PMA: In case of single buffer endpoint 87 | * this parameter is 16-bit value providing the address 88 | * in PMA allocated to endpoint. 89 | * In case of double buffer endpoint this parameter 90 | * is a 32-bit value providing the endpoint buffer 0 address 91 | * in the LSB part of 32-bit value and endpoint buffer 1 address 92 | * in the MSB part of 32-bit value. 93 | * @retval : status 94 | */ 95 | 96 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 97 | uint16_t ep_addr, 98 | uint16_t ep_kind, 99 | uint32_t pmaadress) 100 | 101 | { 102 | PCD_EPTypeDef *ep; 103 | 104 | /* initialize ep structure*/ 105 | if ((0x80 & ep_addr) == 0x80) 106 | { 107 | ep = &hpcd->IN_ep[ep_addr & 0x7F]; 108 | } 109 | else 110 | { 111 | ep = &hpcd->OUT_ep[ep_addr]; 112 | } 113 | 114 | /* Here we check if the endpoint is single or double Buffer*/ 115 | if (ep_kind == PCD_SNG_BUF) 116 | { 117 | /*Single Buffer*/ 118 | ep->doublebuffer = 0; 119 | /*Configure te PMA*/ 120 | ep->pmaadress = (uint16_t)pmaadress; 121 | } 122 | else /*USB_DBL_BUF*/ 123 | { 124 | /*Double Buffer Endpoint*/ 125 | ep->doublebuffer = 1; 126 | /*Configure the PMA*/ 127 | ep->pmaaddr0 = pmaadress & 0xFFFF; 128 | ep->pmaaddr1 = (pmaadress & 0xFFFF0000) >> 16; 129 | } 130 | 131 | return HAL_OK; 132 | } 133 | /** 134 | * @} 135 | */ 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /** 142 | * @} 143 | */ 144 | 145 | /** 146 | * @} 147 | */ 148 | 149 | #endif /* STM32F042x6 || STM32F072xB || STM32F078xx || STM32F070xB || STM32F070x6 */ 150 | 151 | #endif /* HAL_PCD_MODULE_ENABLED */ 152 | 153 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 154 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @version V1.2.1 6 | * @date 09-January-2015 7 | * @brief Header file of PCD HAL Extension module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2015 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32L0xx_HAL_PCD_EX_H 40 | #define __STM32L0xx_HAL_PCD_EX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx)|| defined(STM32F070xB)|| defined(STM32F070x6) 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "stm32f0xx_hal_def.h" 50 | 51 | /** @addtogroup STM32F0xx_HAL_Driver 52 | * @{ 53 | */ 54 | 55 | /** @addtogroup PCDEx 56 | * @{ 57 | */ 58 | 59 | /* Exported types ------------------------------------------------------------*/ 60 | /* Exported constants --------------------------------------------------------*/ 61 | /* Exported macros -----------------------------------------------------------*/ 62 | /* Internal macros -----------------------------------------------------------*/ 63 | /* Exported functions --------------------------------------------------------*/ 64 | 65 | /** @addtogroup PCDEx_Exported_Functions 66 | * @{ 67 | */ 68 | 69 | /** @addtogroup PCDEx_Exported_Functions_Group2 70 | * @{ 71 | */ 72 | 73 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 74 | uint16_t ep_addr, 75 | uint16_t ep_kind, 76 | uint32_t pmaadress); 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | #endif /* STM32F042x6 || STM32F072xB || STM32F078xx || STM32F070xB || STM32F070x6*/ 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | 100 | #endif /* __STM32F0xx_HAL_PCD_EX_H */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_hal_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pwr.h 4 | * @author MCD Application Team 5 | * @version V1.2.1 6 | * @date 09-January-2015 7 | * @brief Header file of PWR HAL module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2015 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F0xx_HAL_PWR_H 40 | #define __STM32F0xx_HAL_PWR_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f0xx_hal_def.h" 48 | 49 | /** @addtogroup STM32F0xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup PWR PWR HAL module Driver 54 | * @{ 55 | */ 56 | 57 | /* Exported types ------------------------------------------------------------*/ 58 | /* Exported constants --------------------------------------------------------*/ 59 | 60 | /** @defgroup PWR_Exported_Constants PWR Exported Constants 61 | * @{ 62 | */ 63 | 64 | /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in STOP mode 65 | * @{ 66 | */ 67 | #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) 68 | #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPDS 69 | 70 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ 71 | ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry 77 | * @{ 78 | */ 79 | #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) 80 | #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) 81 | #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry 87 | * @{ 88 | */ 89 | #define PWR_STOPENTRY_WFI ((uint8_t)0x01) 90 | #define PWR_STOPENTRY_WFE ((uint8_t)0x02) 91 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE)) 92 | /** 93 | * @} 94 | */ 95 | 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /* Exported macro ------------------------------------------------------------*/ 102 | /** @defgroup PWR_Exported_Macro PWR Exported Macro 103 | * @{ 104 | */ 105 | 106 | /** @brief Check PWR flag is set or not. 107 | * @param __FLAG__: specifies the flag to check. 108 | * This parameter can be one of the following values: 109 | * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event 110 | * was received from the WKUP pin or from the RTC alarm (Alarm A), 111 | * RTC Tamper event, RTC TimeStamp event or RTC Wakeup. 112 | * An additional wakeup event is detected if the WKUP pin is enabled 113 | * (by setting the EWUP bit) when the WKUP pin level is already high. 114 | * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was 115 | * resumed from StandBy mode. 116 | * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled 117 | * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode 118 | * For this reason, this bit is equal to 0 after Standby or reset 119 | * until the PVDE bit is set. 120 | * Warning: this Flag is not available on STM32F030x8 products 121 | * @arg PWR_FLAG_VREFINTRDY: This flag indicates that the internal reference 122 | * voltage VREFINT is ready. 123 | * Warning: this Flag is not available on STM32F030x8 products 124 | * @retval The new state of __FLAG__ (TRUE or FALSE). 125 | */ 126 | #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__)) 127 | 128 | /** @brief Clear the PWR's pending flags. 129 | * @param __FLAG__: specifies the flag to clear. 130 | * This parameter can be one of the following values: 131 | * @arg PWR_FLAG_WU: Wake Up flag 132 | * @arg PWR_FLAG_SB: StandBy flag 133 | */ 134 | #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR |= (__FLAG__) << 2) 135 | 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /* Include PWR HAL Extension module */ 142 | #include "stm32f0xx_hal_pwr_ex.h" 143 | 144 | /* Exported functions --------------------------------------------------------*/ 145 | 146 | /** @addtogroup PWR_Exported_Functions PWR Exported Functions 147 | * @{ 148 | */ 149 | 150 | /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 151 | * @{ 152 | */ 153 | 154 | /* Initialization and de-initialization functions *****************************/ 155 | void HAL_PWR_DeInit(void); 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 162 | * @{ 163 | */ 164 | 165 | /* Peripheral Control functions **********************************************/ 166 | void HAL_PWR_EnableBkUpAccess(void); 167 | void HAL_PWR_DisableBkUpAccess(void); 168 | 169 | /* WakeUp pins configuration functions ****************************************/ 170 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx); 171 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); 172 | 173 | /* Low Power modes configuration functions ************************************/ 174 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); 175 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); 176 | void HAL_PWR_EnterSTANDBYMode(void); 177 | 178 | void HAL_PWR_EnableSleepOnExit(void); 179 | void HAL_PWR_DisableSleepOnExit(void); 180 | void HAL_PWR_EnableSEVOnPend(void); 181 | void HAL_PWR_DisableSEVOnPend(void); 182 | 183 | /** 184 | * @} 185 | */ 186 | 187 | /** 188 | * @} 189 | */ 190 | 191 | /** 192 | * @} 193 | */ 194 | 195 | /** 196 | * @} 197 | */ 198 | 199 | #ifdef __cplusplus 200 | } 201 | #endif 202 | 203 | 204 | #endif /* __STM32F0xx_HAL_PWR_H */ 205 | 206 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 207 | 208 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file USB_Device/HID_Standalone/Src/stm32f0xx_it.c 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 18-June-2014 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and 9 | * peripherals interrupt service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© COPYRIGHT(c) 2014 STMicroelectronics

14 | * 15 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 16 | * You may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at: 18 | * 19 | * http://www.st.com/software_license_agreement_liberty_v2 20 | * 21 | * Unless required by applicable law or agreed to in writing, software 22 | * distributed under the License is distributed on an "AS IS" BASIS, 23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | * See the License for the specific language governing permissions and 25 | * limitations under the License. 26 | * 27 | ****************************************************************************** 28 | */ 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usbd_core.h" 32 | #include "stm32f0xx_it.h" 33 | 34 | /* Private typedef -----------------------------------------------------------*/ 35 | /* Private define ------------------------------------------------------------*/ 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | extern PCD_HandleTypeDef hpcd; 39 | extern USBD_HandleTypeDef USBD_Device; 40 | 41 | /* Private function prototypes -----------------------------------------------*/ 42 | /* Private functions ---------------------------------------------------------*/ 43 | 44 | /******************************************************************************/ 45 | /* Cortex-M0 Processor Exceptions Handlers */ 46 | /******************************************************************************/ 47 | 48 | /** 49 | * @brief This function handles NMI exception. 50 | * @param None 51 | * @retval None 52 | */ 53 | void NMI_Handler(void) 54 | { 55 | } 56 | 57 | /** 58 | * @brief This function handles Hard Fault exception. 59 | * @param None 60 | * @retval None 61 | */ 62 | void HardFault_Handler(void) 63 | { 64 | /* Go to infinite loop when Hard Fault exception occurs */ 65 | while (1) 66 | { 67 | } 68 | } 69 | 70 | 71 | /** 72 | * @brief This function handles SVCall exception. 73 | * @param None 74 | * @retval None 75 | */ 76 | void SVC_Handler(void) 77 | { 78 | } 79 | 80 | 81 | /** 82 | * @brief This function handles PendSVC exception. 83 | * @param None 84 | * @retval None 85 | */ 86 | void PendSV_Handler(void) 87 | { 88 | } 89 | 90 | /** 91 | * @brief This function handles SysTick Handler. 92 | * @param None 93 | * @retval None 94 | */ 95 | void SysTick_Handler(void) 96 | { 97 | HAL_IncTick(); 98 | } 99 | 100 | /******************************************************************************/ 101 | /* STM32F0xx Peripherals Interrupt Handlers */ 102 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 103 | /* available peripheral interrupt handler's name please refer to the startup */ 104 | /* file (startup_stm32f0xx.s). */ 105 | /******************************************************************************/ 106 | 107 | /** 108 | * @brief This function handles USB Handler. 109 | * @param None 110 | * @retval None 111 | */ 112 | void USB_IRQHandler(void) 113 | { 114 | HAL_PCD_IRQHandler(&hpcd); 115 | } 116 | 117 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 118 | -------------------------------------------------------------------------------- /src/stm32f072/stm32f0xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file USB_Device/HID_Standalone/Inc/stm32f0xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 18-June-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F0xx_IT_H 30 | #define __STM32F0xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* Exported macro ------------------------------------------------------------*/ 40 | /* Exported functions ------------------------------------------------------- */ 41 | 42 | void NMI_Handler(void); 43 | void HardFault_Handler(void); 44 | void SVC_Handler(void); 45 | void PendSV_Handler(void); 46 | void SysTick_Handler(void); 47 | void USB_IRQHandler(void); 48 | void EXTI4_15_IRQHandler(void); 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __STM32F0xx_IT_H */ 54 | 55 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 56 | -------------------------------------------------------------------------------- /src/stm32f072/stm32hidsensor.hzp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 38 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 97 | -------------------------------------------------------------------------------- /src/stm32f072/system_stm32f0xx.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.c 4 | * @author MCD Application Team 5 | * @version V1.2.0 6 | * @date 05-Dec-2014 7 | * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File. 8 | * 9 | * 1. This file provides two functions and one global variable to be called from 10 | * user application: 11 | * - SystemInit(): This function is called at startup just after reset and 12 | * before branch to main program. This call is made inside 13 | * the "startup_stm32f0xx.s" file. 14 | * 15 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used 16 | * by the user application to setup the SysTick 17 | * timer or configure other parameters. 18 | * 19 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must 20 | * be called whenever the core clock is changed 21 | * during program execution. 22 | * 23 | * 2. After each device reset the HSI (8 MHz) is used as system clock source. 24 | * Then SystemInit() function is called, in "startup_stm32f0xx.s" file, to 25 | * configure the system clock before to branch to main program. 26 | * 27 | * 3. This file configures the system clock as follows: 28 | *============================================================================= 29 | * Supported STM32F0xx device 30 | *----------------------------------------------------------------------------- 31 | * System Clock source | HSI 32 | *----------------------------------------------------------------------------- 33 | * SYSCLK(Hz) | 8000000 34 | *----------------------------------------------------------------------------- 35 | * HCLK(Hz) | 8000000 36 | *----------------------------------------------------------------------------- 37 | * AHB Prescaler | 1 38 | *----------------------------------------------------------------------------- 39 | * APB1 Prescaler | 1 40 | *----------------------------------------------------------------------------- 41 | *============================================================================= 42 | ****************************************************************************** 43 | * @attention 44 | * 45 | *

© COPYRIGHT(c) 2014 STMicroelectronics

46 | * 47 | * Redistribution and use in source and binary forms, with or without modification, 48 | * are permitted provided that the following conditions are met: 49 | * 1. Redistributions of source code must retain the above copyright notice, 50 | * this list of conditions and the following disclaimer. 51 | * 2. Redistributions in binary form must reproduce the above copyright notice, 52 | * this list of conditions and the following disclaimer in the documentation 53 | * and/or other materials provided with the distribution. 54 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 55 | * may be used to endorse or promote products derived from this software 56 | * without specific prior written permission. 57 | * 58 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 59 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 61 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 64 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 65 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 66 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 67 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 68 | * 69 | ****************************************************************************** 70 | */ 71 | 72 | /** @addtogroup CMSIS 73 | * @{ 74 | */ 75 | 76 | /** @addtogroup stm32f0xx_system 77 | * @{ 78 | */ 79 | 80 | /** @addtogroup STM32F0xx_System_Private_Includes 81 | * @{ 82 | */ 83 | 84 | #include "stm32f0xx.h" 85 | #include "stm32f0xx_hal.h" /* MODIFIED: added */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F0xx_System_Private_TypesDefinitions 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F0xx_System_Private_Defines 100 | * @{ 101 | */ 102 | #if !defined (HSE_VALUE) 103 | #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz. 104 | This value can be provided and adapted by the user application. */ 105 | #endif /* HSE_VALUE */ 106 | 107 | #if !defined (HSI_VALUE) 108 | #define HSI_VALUE ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz. 109 | This value can be provided and adapted by the user application. */ 110 | #endif /* HSI_VALUE */ 111 | /** 112 | * @} 113 | */ 114 | 115 | /** @addtogroup STM32F0xx_System_Private_Macros 116 | * @{ 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | /** @addtogroup STM32F0xx_System_Private_Variables 124 | * @{ 125 | */ 126 | /* This variable is updated in three ways: 127 | 1) by calling CMSIS function SystemCoreClockUpdate() 128 | 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 129 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 130 | Note: If you use this function to configure the system clock there is no need to 131 | call the 2 first functions listed above, since SystemCoreClock variable is 132 | updated automatically. 133 | */ 134 | uint32_t SystemCoreClock = 8000000; 135 | 136 | const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /** @addtogroup STM32F0xx_System_Private_FunctionPrototypes 143 | * @{ 144 | */ 145 | 146 | /** 147 | * @} 148 | */ 149 | 150 | /** @addtogroup STM32F0xx_System_Private_Functions 151 | * @{ 152 | */ 153 | 154 | /** 155 | * @brief Setup the microcontroller system. 156 | * Initialize the default HSI clock source, vector table location and the PLL configuration is reset. 157 | * @param None 158 | * @retval None 159 | */ 160 | void SystemInit(void) 161 | { 162 | /* Reset the RCC clock configuration to the default reset state ------------*/ 163 | /* Set HSION bit */ 164 | RCC->CR |= (uint32_t)0x00000001; 165 | 166 | #if defined (STM32F051x8) || defined (STM32F058x8) 167 | /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE and MCOSEL[2:0] bits */ 168 | RCC->CFGR &= (uint32_t)0xF8FFB80C; 169 | #else 170 | /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE, MCOSEL[2:0], MCOPRE[2:0] and PLLNODIV bits */ 171 | RCC->CFGR &= (uint32_t)0x08FFB80C; 172 | #endif /* STM32F051x8 or STM32F058x8 */ 173 | 174 | /* Reset HSEON, CSSON and PLLON bits */ 175 | RCC->CR &= (uint32_t)0xFEF6FFFF; 176 | 177 | /* Reset HSEBYP bit */ 178 | RCC->CR &= (uint32_t)0xFFFBFFFF; 179 | 180 | /* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */ 181 | RCC->CFGR &= (uint32_t)0xFFC0FFFF; 182 | 183 | /* Reset PREDIV[3:0] bits */ 184 | RCC->CFGR2 &= (uint32_t)0xFFFFFFF0; 185 | 186 | #if defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xB) 187 | /* Reset USART2SW[1:0] USART1SW[1:0], I2C1SW, CECSW, USBSW and ADCSW bits */ 188 | RCC->CFGR3 &= (uint32_t)0xFFFCFE2C; 189 | #elif defined (STM32F091xC) 190 | /* Reset USART3SW[1:0], USART2SW[1:0], USART1SW[1:0], I2C1SW, CECSW bits */ 191 | RCC->CFGR3 &= (uint32_t)0xFFF0FFAC; 192 | #else 193 | /* Reset USART1SW[1:0], I2C1SW, CECSW, USBSW and ADCSW bits */ 194 | RCC->CFGR3 &= (uint32_t)0xFFFFFE2C; 195 | #endif 196 | 197 | /* Reset HSI14 bit */ 198 | RCC->CR2 &= (uint32_t)0xFFFFFFFE; 199 | 200 | /* Disable all interrupts */ 201 | RCC->CIR = 0x00000000; 202 | 203 | } 204 | 205 | /** 206 | * @brief Update SystemCoreClock variable according to Clock Register Values. 207 | * The SystemCoreClock variable contains the core clock (HCLK), it can 208 | * be used by the user application to setup the SysTick timer or configure 209 | * other parameters. 210 | * 211 | * @note Each time the core clock (HCLK) changes, this function must be called 212 | * to update SystemCoreClock variable value. Otherwise, any configuration 213 | * based on this variable will be incorrect. 214 | * 215 | * @note - The system frequency computed by this function is not the real 216 | * frequency in the chip. It is calculated based on the predefined 217 | * constant and the selected clock source: 218 | * 219 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) 220 | * 221 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) 222 | * 223 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 224 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. 225 | * 226 | * (*) HSI_VALUE is a constant defined in stm32f0xx_hal.h file (default value 227 | * 8 MHz) but the real value may vary depending on the variations 228 | * in voltage and temperature. 229 | * 230 | * (**) HSE_VALUE is a constant defined in stm32f0xx_hal.h file (default value 231 | * 8 MHz), user has to ensure that HSE_VALUE is same as the real 232 | * frequency of the crystal used. Otherwise, this function may 233 | * have wrong result. 234 | * 235 | * - The result of this function could be not correct when using fractional 236 | * value for HSE crystal. 237 | * 238 | * @param None 239 | * @retval None 240 | */ 241 | void SystemCoreClockUpdate (void) 242 | { 243 | uint32_t tmp = 0, pllmull = 0, pllsource = 0, predivfactor = 0; 244 | 245 | /* Get SYSCLK source -------------------------------------------------------*/ 246 | tmp = RCC->CFGR & RCC_CFGR_SWS; 247 | 248 | switch (tmp) 249 | { 250 | case RCC_CFGR_SWS_HSI: /* HSI used as system clock */ 251 | SystemCoreClock = HSI_VALUE; 252 | break; 253 | case RCC_CFGR_SWS_HSE: /* HSE used as system clock */ 254 | SystemCoreClock = HSE_VALUE; 255 | break; 256 | case RCC_CFGR_SWS_PLL: /* PLL used as system clock */ 257 | /* Get PLL clock source and multiplication factor ----------------------*/ 258 | pllmull = RCC->CFGR & RCC_CFGR_PLLMUL; 259 | pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; 260 | pllmull = ( pllmull >> 18) + 2; 261 | predivfactor = (RCC->CFGR2 & RCC_CFGR2_PREDIV) + 1; 262 | 263 | if (pllsource == RCC_CFGR_PLLSRC_HSE_PREDIV) 264 | { 265 | /* HSE used as PLL clock source : SystemCoreClock = HSE/PREDIV * PLLMUL */ 266 | SystemCoreClock = (HSE_VALUE/predivfactor) * pllmull; 267 | } 268 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx) 269 | else if (pllsource == RCC_CFGR_PLLSRC_HSI48_PREDIV) 270 | { 271 | /* HSI48 used as PLL clock source : SystemCoreClock = HSI48/PREDIV * PLLMUL */ 272 | SystemCoreClock = (HSI48_VALUE/predivfactor) * pllmull; 273 | } 274 | #endif /* STM32F042x6 || STM32F048xx || STM32F072xB || STM32F078xx */ 275 | else 276 | { 277 | #if defined(STM32F042x6) || defined(STM32F048xx) || \ 278 | defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) 279 | /* HSI used as PLL clock source : SystemCoreClock = HSI/PREDIV * PLLMUL */ 280 | SystemCoreClock = (HSI_VALUE/predivfactor) * pllmull; 281 | #else 282 | /* HSI used as PLL clock source : SystemCoreClock = HSI/2 * PLLMUL */ 283 | SystemCoreClock = (HSI_VALUE >> 1) * pllmull; 284 | #endif /* STM32F042x6 || STM32F048xx || STM32F071xB || STM32F072xB || STM32F078xx */ 285 | } 286 | break; 287 | default: /* HSI used as system clock */ 288 | SystemCoreClock = HSI_VALUE; 289 | break; 290 | } 291 | /* Compute HCLK clock frequency ----------------*/ 292 | /* Get HCLK prescaler */ 293 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; 294 | /* HCLK clock frequency */ 295 | SystemCoreClock >>= tmp; 296 | } 297 | 298 | /** 299 | * @} 300 | */ 301 | 302 | /** 303 | * @} 304 | */ 305 | 306 | /** 307 | * @} 308 | */ 309 | 310 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 311 | 312 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_composite.c: -------------------------------------------------------------------------------- 1 | /* 2 | shim code to enable USB Composite devices within ST Micro's USB stack 3 | 4 | Copyright (C) 2015,2016 Peter Lawrence 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include "usbd_composite.h" 26 | #include "usbd_desc.h" /* for USBD_CfgFSDesc_len and USBD_CfgFSDesc_pnt */ 27 | #include "usbd_hid.h" 28 | 29 | /* USB handle declared in main.c */ 30 | extern USBD_HandleTypeDef USBD_Device; 31 | 32 | /* local function prototyping */ 33 | 34 | static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx); 35 | static uint8_t USBD_Composite_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx); 36 | static uint8_t USBD_Composite_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 37 | static uint8_t USBD_Composite_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); 38 | static uint8_t USBD_Composite_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); 39 | static uint8_t USBD_Composite_EP0_TxSent (USBD_HandleTypeDef *pdev); 40 | static uint8_t USBD_Composite_EP0_RxReady (USBD_HandleTypeDef *pdev); 41 | static const uint8_t *USBD_Composite_GetFSCfgDesc (uint16_t *length); 42 | static uint8_t USBD_Composite_SOF (struct _USBD_HandleTypeDef *pdev); 43 | 44 | /* interface class callbacks structure that is used by main.c */ 45 | const USBD_ClassTypeDef USBD_Composite = 46 | { 47 | .Init = USBD_Composite_Init, 48 | .DeInit = USBD_Composite_DeInit, 49 | .Setup = USBD_Composite_Setup, 50 | .EP0_TxSent = USBD_Composite_EP0_TxSent, 51 | .EP0_RxReady = USBD_Composite_EP0_RxReady, 52 | .DataIn = USBD_Composite_DataIn, 53 | .DataOut = USBD_Composite_DataOut, 54 | .SOF = USBD_Composite_SOF, 55 | .IsoINIncomplete = NULL, 56 | .IsoOUTIncomplete = NULL, 57 | .GetFSConfigDescriptor = USBD_Composite_GetFSCfgDesc, 58 | }; 59 | 60 | struct composite_list_struct 61 | { 62 | const USBD_CompClassTypeDef *pnt; 63 | }; 64 | 65 | /* 66 | A deficiency of the ST Micro code is that it makes no provision whatsoever to allow for USB Composite devices. 67 | To make it possible to implement Composite devices, but yet leverage ST Micro's USB drivers, this driver acts like 68 | one of ST Micro's legacy code's single class drivers, but then invokes all composite members added to this array 69 | */ 70 | 71 | static const struct composite_list_struct composite_list[] = 72 | { 73 | &USBD_HID, /* in this particular code, there is only HID */ 74 | }; 75 | 76 | static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) 77 | { 78 | unsigned index; 79 | 80 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 81 | { 82 | if (composite_list[index].pnt->Init) 83 | composite_list[index].pnt->Init(pdev, cfgidx); 84 | } 85 | 86 | return USBD_OK; 87 | } 88 | 89 | static uint8_t USBD_Composite_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) 90 | { 91 | unsigned index; 92 | 93 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 94 | { 95 | if (composite_list[index].pnt->DeInit) 96 | composite_list[index].pnt->DeInit(pdev, cfgidx); 97 | } 98 | 99 | return USBD_OK; 100 | } 101 | 102 | static uint8_t USBD_Composite_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) 103 | { 104 | unsigned index; 105 | 106 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 107 | { 108 | if (composite_list[index].pnt->Setup) 109 | composite_list[index].pnt->Setup(pdev, req); 110 | } 111 | 112 | return USBD_OK; 113 | } 114 | 115 | static uint8_t USBD_Composite_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) 116 | { 117 | unsigned index; 118 | 119 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 120 | { 121 | if (composite_list[index].pnt->DataIn) 122 | composite_list[index].pnt->DataIn(pdev, epnum); 123 | } 124 | 125 | return USBD_OK; 126 | } 127 | 128 | static uint8_t USBD_Composite_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) 129 | { 130 | unsigned index; 131 | 132 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 133 | { 134 | if (composite_list[index].pnt->DataOut) 135 | composite_list[index].pnt->DataOut(pdev, epnum); 136 | } 137 | 138 | return USBD_OK; 139 | } 140 | 141 | static uint8_t USBD_Composite_SOF (USBD_HandleTypeDef *pdev) 142 | { 143 | unsigned index; 144 | 145 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 146 | { 147 | if (composite_list[index].pnt->SOF) 148 | composite_list[index].pnt->SOF(pdev); 149 | } 150 | 151 | return USBD_OK; 152 | } 153 | 154 | static uint8_t USBD_Composite_EP0_TxSent (USBD_HandleTypeDef *pdev) 155 | { 156 | unsigned index; 157 | 158 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 159 | { 160 | if (composite_list[index].pnt->EP0_TxSent) 161 | composite_list[index].pnt->EP0_TxSent(pdev); 162 | } 163 | 164 | return USBD_OK; 165 | } 166 | 167 | static uint8_t USBD_Composite_EP0_RxReady (USBD_HandleTypeDef *pdev) 168 | { 169 | unsigned index; 170 | 171 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 172 | { 173 | if (composite_list[index].pnt->EP0_RxReady) 174 | composite_list[index].pnt->EP0_RxReady(pdev); 175 | } 176 | 177 | return USBD_OK; 178 | } 179 | 180 | static const uint8_t *USBD_Composite_GetFSCfgDesc (uint16_t *length) 181 | { 182 | *length = USBD_CfgFSDesc_len; 183 | return USBD_CfgFSDesc_pnt; 184 | } 185 | 186 | void USBD_Composite_PMAConfig(PCD_HandleTypeDef *hpcd, uint32_t *pma_address) 187 | { 188 | unsigned index; 189 | 190 | for (index = 0; index < (sizeof(composite_list) / sizeof(*composite_list)); index++) 191 | { 192 | if (composite_list[index].pnt->PMAConfig) 193 | composite_list[index].pnt->PMAConfig(hpcd, pma_address); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_composite.h: -------------------------------------------------------------------------------- 1 | #ifndef __USB_COMPOSITE_H_ 2 | #define __USB_COMPOSITE_H_ 3 | 4 | #include "usbd_def.h" 5 | #include "usbd_ioreq.h" 6 | 7 | typedef struct 8 | { 9 | uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); 10 | uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); 11 | /* Control Endpoints */ 12 | uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req); 13 | uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev ); 14 | uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev ); 15 | /* Class Specific Endpoints */ 16 | uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 17 | uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 18 | uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev); 19 | void (*PMAConfig) (PCD_HandleTypeDef *hpcd, uint32_t *pma_address); 20 | } USBD_CompClassTypeDef; 21 | 22 | /* array of callback functions invoked by USBD_RegisterClass() in main.c */ 23 | extern const USBD_ClassTypeDef USBD_Composite; 24 | 25 | void USBD_Composite_PMAConfig(PCD_HandleTypeDef *hpcd, uint32_t *pma_address); 26 | 27 | #endif // __USB_COMPOSITE_H_ 28 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file USB_Device/CDC_Standalone/Inc/usbd_conf.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 18-June-2014 7 | * @brief General low level driver configuration 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_CONF_H 30 | #define __USBD_CONF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm32f0xx_hal.h" 34 | #include 35 | #include 36 | #include 37 | #include "config.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Common Config */ 42 | #define USBD_MAX_NUM_INTERFACES ( 0 + NUM_OF_STANDARDHID ) 43 | #define USBD_MAX_NUM_CONFIGURATION 1 44 | #define USBD_MAX_STR_DESC_SIZ 0x100 45 | #define USBD_SUPPORT_USER_STRING 0 46 | #define USBD_SELF_POWERED 0 47 | #define USBD_DEBUG_LEVEL 0 48 | 49 | /* Exported macro ------------------------------------------------------------*/ 50 | /* Memory management macros */ 51 | 52 | /* DEBUG macros */ 53 | #if (USBD_DEBUG_LEVEL > 0) 54 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 55 | printf("\n"); 56 | #else 57 | #define USBD_UsrLog(...) 58 | #endif 59 | 60 | #if (USBD_DEBUG_LEVEL > 1) 61 | 62 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 63 | printf(__VA_ARGS__);\ 64 | printf("\n"); 65 | #else 66 | #define USBD_ErrLog(...) 67 | #endif 68 | 69 | #if (USBD_DEBUG_LEVEL > 2) 70 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 71 | printf(__VA_ARGS__);\ 72 | printf("\n"); 73 | #else 74 | #define USBD_DbgLog(...) 75 | #endif 76 | 77 | /* Exported functions ------------------------------------------------------- */ 78 | 79 | #endif /* __USBD_CONF_H */ 80 | 81 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 82 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_core.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 04-November-2014 7 | * @brief This file provides all the USBD core functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_core.h" 30 | 31 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | 36 | /** @defgroup USBD_CORE 37 | * @brief usbd core module 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_CORE_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_CORE_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_CORE_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | 67 | 68 | /** @defgroup USBD_CORE_Private_FunctionPrototypes 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_CORE_Private_Variables 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup USBD_CORE_Private_Functions 85 | * @{ 86 | */ 87 | 88 | /** 89 | * @brief USBD_Init 90 | * Initializes the device stack and load the class driver 91 | * @param pdev: device instance 92 | * @param pdesc: Descriptor structure address 93 | * @param id: Low level core index 94 | * @retval None 95 | */ 96 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, const USBD_DescriptorsTypeDef *pdesc, uint8_t id) 97 | { 98 | /* Check whether the USB Host handle is valid */ 99 | if(pdev == NULL) 100 | { 101 | USBD_ErrLog("Invalid Device handle"); 102 | return USBD_FAIL; 103 | } 104 | 105 | /* Unlink previous class*/ 106 | if(pdev->pClass != NULL) 107 | { 108 | pdev->pClass = NULL; 109 | } 110 | 111 | /* Assign USBD Descriptors */ 112 | if(pdesc != NULL) 113 | { 114 | pdev->pDesc = pdesc; 115 | } 116 | 117 | /* Set Device initial State */ 118 | pdev->dev_state = USBD_STATE_DEFAULT; 119 | pdev->id = id; 120 | /* Initialize low level driver */ 121 | USBD_LL_Init(pdev); 122 | 123 | return USBD_OK; 124 | } 125 | 126 | /** 127 | * @brief USBD_DeInit 128 | * Re-Initialize th device library 129 | * @param pdev: device instance 130 | * @retval status: status 131 | */ 132 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) 133 | { 134 | /* Set Default State */ 135 | pdev->dev_state = USBD_STATE_DEFAULT; 136 | 137 | /* Free Class Resources */ 138 | pdev->pClass->DeInit(pdev, pdev->dev_config); 139 | 140 | /* Stop the low level driver */ 141 | USBD_LL_Stop(pdev); 142 | 143 | /* Initialize low level driver */ 144 | USBD_LL_DeInit(pdev); 145 | 146 | return USBD_OK; 147 | } 148 | 149 | 150 | /** 151 | * @brief USBD_RegisterClass 152 | * Link class driver to Device Core. 153 | * @param pDevice : Device Handle 154 | * @param pclass: Class handle 155 | * @retval USBD Status 156 | */ 157 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, const USBD_ClassTypeDef *pclass) 158 | { 159 | USBD_StatusTypeDef status = USBD_OK; 160 | if(pclass != 0) 161 | { 162 | /* link the class to the USB Device handle */ 163 | pdev->pClass = pclass; 164 | status = USBD_OK; 165 | } 166 | else 167 | { 168 | USBD_ErrLog("Invalid Class handle"); 169 | status = USBD_FAIL; 170 | } 171 | 172 | return status; 173 | } 174 | 175 | /** 176 | * @brief USBD_Start 177 | * Start the USB Device Core. 178 | * @param pdev: Device Handle 179 | * @retval USBD Status 180 | */ 181 | USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev) 182 | { 183 | 184 | /* Start the low level driver */ 185 | USBD_LL_Start(pdev); 186 | 187 | return USBD_OK; 188 | } 189 | 190 | /** 191 | * @brief USBD_Stop 192 | * Stop the USB Device Core. 193 | * @param pdev: Device Handle 194 | * @retval USBD Status 195 | */ 196 | USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev) 197 | { 198 | /* Free Class Resources */ 199 | pdev->pClass->DeInit(pdev, pdev->dev_config); 200 | 201 | /* Stop the low level driver */ 202 | USBD_LL_Stop(pdev); 203 | 204 | return USBD_OK; 205 | } 206 | 207 | /** 208 | * @brief USBD_SetClassConfig 209 | * Configure device and start the interface 210 | * @param pdev: device instance 211 | * @param cfgidx: configuration index 212 | * @retval status 213 | */ 214 | 215 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) 216 | { 217 | USBD_StatusTypeDef ret = USBD_FAIL; 218 | 219 | if(pdev->pClass != NULL) 220 | { 221 | /* Set configuration and Start the Class*/ 222 | if(pdev->pClass->Init(pdev, cfgidx) == 0) 223 | { 224 | ret = USBD_OK; 225 | } 226 | } 227 | return ret; 228 | } 229 | 230 | /** 231 | * @brief USBD_ClrClassConfig 232 | * Clear current configuration 233 | * @param pdev: device instance 234 | * @param cfgidx: configuration index 235 | * @retval status: USBD_StatusTypeDef 236 | */ 237 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) 238 | { 239 | /* Clear configuration and De-initialize the Class process*/ 240 | pdev->pClass->DeInit(pdev, cfgidx); 241 | return USBD_OK; 242 | } 243 | 244 | 245 | /** 246 | * @brief USBD_SetupStage 247 | * Handle the setup stage 248 | * @param pdev: device instance 249 | * @retval status 250 | */ 251 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) 252 | { 253 | 254 | USBD_ParseSetupRequest(&pdev->request, psetup); 255 | 256 | pdev->ep0_state = USBD_EP0_SETUP; 257 | pdev->ep0_data_len = pdev->request.wLength; 258 | 259 | switch (pdev->request.bmRequest & 0x1F) 260 | { 261 | case USB_REQ_RECIPIENT_DEVICE: 262 | USBD_StdDevReq (pdev, &pdev->request); 263 | break; 264 | 265 | case USB_REQ_RECIPIENT_INTERFACE: 266 | USBD_StdItfReq(pdev, &pdev->request); 267 | break; 268 | 269 | case USB_REQ_RECIPIENT_ENDPOINT: 270 | USBD_StdEPReq(pdev, &pdev->request); 271 | break; 272 | 273 | default: 274 | USBD_LL_StallEP(pdev , pdev->request.bmRequest & 0x80); 275 | break; 276 | } 277 | return USBD_OK; 278 | } 279 | 280 | /** 281 | * @brief USBD_DataOutStage 282 | * Handle data OUT stage 283 | * @param pdev: device instance 284 | * @param epnum: endpoint index 285 | * @retval status 286 | */ 287 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata) 288 | { 289 | USBD_EndpointTypeDef *pep; 290 | 291 | if(epnum == 0) 292 | { 293 | pep = &pdev->ep_out[0]; 294 | 295 | if ( pdev->ep0_state == USBD_EP0_DATA_OUT) 296 | { 297 | if(pep->rem_length > pep->maxpacket) 298 | { 299 | pep->rem_length -= pep->maxpacket; 300 | 301 | USBD_CtlContinueRx (pdev, 302 | pdata, 303 | MIN(pep->rem_length ,pep->maxpacket)); 304 | } 305 | else 306 | { 307 | if((pdev->pClass->EP0_RxReady != NULL)&& 308 | (pdev->dev_state == USBD_STATE_CONFIGURED)) 309 | { 310 | pdev->pClass->EP0_RxReady(pdev); 311 | } 312 | USBD_CtlSendStatus(pdev); 313 | } 314 | } 315 | } 316 | else if((pdev->pClass->DataOut != NULL)&& 317 | (pdev->dev_state == USBD_STATE_CONFIGURED)) 318 | { 319 | pdev->pClass->DataOut(pdev, epnum); 320 | } 321 | return USBD_OK; 322 | } 323 | 324 | /** 325 | * @brief USBD_DataInStage 326 | * Handle data in stage 327 | * @param pdev: device instance 328 | * @param epnum: endpoint index 329 | * @retval status 330 | */ 331 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev ,uint8_t epnum, uint8_t *pdata) 332 | { 333 | USBD_EndpointTypeDef *pep; 334 | 335 | if(epnum == 0) 336 | { 337 | pep = &pdev->ep_in[0]; 338 | 339 | if ( pdev->ep0_state == USBD_EP0_DATA_IN) 340 | { 341 | if(pep->rem_length > pep->maxpacket) 342 | { 343 | pep->rem_length -= pep->maxpacket; 344 | 345 | USBD_CtlContinueSendData (pdev, 346 | pdata, 347 | pep->rem_length); 348 | } 349 | else 350 | { /* last packet is MPS multiple, so send ZLP packet */ 351 | if((pep->total_length % pep->maxpacket == 0) && 352 | (pep->total_length >= pep->maxpacket) && 353 | (pep->total_length < pdev->ep0_data_len )) 354 | { 355 | 356 | USBD_CtlContinueSendData(pdev , NULL, 0); 357 | pdev->ep0_data_len = 0; 358 | } 359 | else 360 | { 361 | if((pdev->pClass->EP0_TxSent != NULL)&& 362 | (pdev->dev_state == USBD_STATE_CONFIGURED)) 363 | { 364 | pdev->pClass->EP0_TxSent(pdev); 365 | } 366 | USBD_CtlReceiveStatus(pdev); 367 | } 368 | } 369 | } 370 | } 371 | else if((pdev->pClass->DataIn != NULL)&& 372 | (pdev->dev_state == USBD_STATE_CONFIGURED)) 373 | { 374 | pdev->pClass->DataIn(pdev, epnum); 375 | } 376 | return USBD_OK; 377 | } 378 | 379 | /** 380 | * @brief USBD_LL_Reset 381 | * Handle Reset event 382 | * @param pdev: device instance 383 | * @retval status 384 | */ 385 | 386 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) 387 | { 388 | /* Open EP0 OUT */ 389 | USBD_LL_OpenEP(pdev, 390 | 0x00, 391 | USBD_EP_TYPE_CTRL, 392 | USB_MAX_EP0_SIZE); 393 | 394 | pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; 395 | 396 | /* Open EP0 IN */ 397 | USBD_LL_OpenEP(pdev, 398 | 0x80, 399 | USBD_EP_TYPE_CTRL, 400 | USB_MAX_EP0_SIZE); 401 | 402 | pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; 403 | /* Upon Reset call user call back */ 404 | pdev->dev_state = USBD_STATE_DEFAULT; 405 | 406 | pdev->pClass->DeInit(pdev, pdev->dev_config); 407 | 408 | return USBD_OK; 409 | } 410 | 411 | 412 | 413 | 414 | /** 415 | * @brief USBD_LL_Reset 416 | * Handle Reset event 417 | * @param pdev: device instance 418 | * @retval status 419 | */ 420 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed) 421 | { 422 | pdev->dev_speed = speed; 423 | return USBD_OK; 424 | } 425 | 426 | /** 427 | * @brief USBD_Suspend 428 | * Handle Suspend event 429 | * @param pdev: device instance 430 | * @retval status 431 | */ 432 | 433 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev) 434 | { 435 | pdev->dev_old_state = pdev->dev_state; 436 | pdev->dev_state = USBD_STATE_SUSPENDED; 437 | return USBD_OK; 438 | } 439 | 440 | /** 441 | * @brief USBD_Resume 442 | * Handle Resume event 443 | * @param pdev: device instance 444 | * @retval status 445 | */ 446 | 447 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) 448 | { 449 | pdev->dev_state = pdev->dev_old_state; 450 | return USBD_OK; 451 | } 452 | 453 | /** 454 | * @brief USBD_SOF 455 | * Handle SOF event 456 | * @param pdev: device instance 457 | * @retval status 458 | */ 459 | 460 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) 461 | { 462 | if(pdev->dev_state == USBD_STATE_CONFIGURED) 463 | { 464 | if(pdev->pClass->SOF != NULL) 465 | { 466 | pdev->pClass->SOF(pdev); 467 | } 468 | } 469 | return USBD_OK; 470 | } 471 | 472 | /** 473 | * @brief USBD_IsoINIncomplete 474 | * Handle iso in incomplete event 475 | * @param pdev: device instance 476 | * @retval status 477 | */ 478 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) 479 | { 480 | return USBD_OK; 481 | } 482 | 483 | /** 484 | * @brief USBD_IsoOUTIncomplete 485 | * Handle iso out incomplete event 486 | * @param pdev: device instance 487 | * @retval status 488 | */ 489 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) 490 | { 491 | return USBD_OK; 492 | } 493 | 494 | /** 495 | * @brief USBD_DevConnected 496 | * Handle device connection event 497 | * @param pdev: device instance 498 | * @retval status 499 | */ 500 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev) 501 | { 502 | return USBD_OK; 503 | } 504 | 505 | /** 506 | * @brief USBD_DevDisconnected 507 | * Handle device disconnection event 508 | * @param pdev: device instance 509 | * @retval status 510 | */ 511 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev) 512 | { 513 | /* Free Class Resources */ 514 | pdev->dev_state = USBD_STATE_DEFAULT; 515 | pdev->pClass->DeInit(pdev, pdev->dev_config); 516 | 517 | return USBD_OK; 518 | } 519 | /** 520 | * @} 521 | */ 522 | 523 | 524 | /** 525 | * @} 526 | */ 527 | 528 | 529 | /** 530 | * @} 531 | */ 532 | 533 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 534 | 535 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 04-November-2014 7 | * @brief Header file for usbd_core.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_CORE_H 30 | #define __USBD_CORE_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_conf.h" 38 | #include "usbd_def.h" 39 | #include "usbd_ioreq.h" 40 | #include "usbd_ctlreq.h" 41 | 42 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 43 | * @{ 44 | */ 45 | 46 | /** @defgroup USBD_CORE 47 | * @brief This file is the Header file for usbd_core.c file 48 | * @{ 49 | */ 50 | 51 | 52 | /** @defgroup USBD_CORE_Exported_Defines 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | 61 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 62 | * @{ 63 | */ 64 | 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | 71 | 72 | /** @defgroup USBD_CORE_Exported_Macros 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_CORE_Exported_Variables 81 | * @{ 82 | */ 83 | #define USBD_SOF USBD_LL_SOF 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 89 | * @{ 90 | */ 91 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, const USBD_DescriptorsTypeDef *pdesc, uint8_t id); 92 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 93 | USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev); 94 | USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev); 95 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, const USBD_ClassTypeDef *pclass); 96 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 97 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 98 | 99 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 100 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); 101 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); 102 | 103 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 104 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 105 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 106 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 107 | 108 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 109 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 110 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 111 | 112 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 113 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 114 | 115 | /* USBD Low Level Driver */ 116 | USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev); 117 | USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev); 118 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 119 | USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev); 120 | USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, 121 | uint8_t ep_addr, 122 | uint8_t ep_type, 123 | uint16_t ep_mps); 124 | 125 | USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 126 | USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 127 | USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 128 | USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 129 | uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 130 | USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr); 131 | USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, 132 | uint8_t ep_addr, 133 | uint8_t *pbuf, 134 | uint16_t size); 135 | 136 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 137 | uint8_t ep_addr, 138 | uint8_t *pbuf, 139 | uint16_t size); 140 | 141 | uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 142 | void USBD_LL_Delay (uint32_t Delay); 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | #ifdef __cplusplus 149 | } 150 | #endif 151 | 152 | #endif /* __USBD_CORE_H */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 04-November-2014 7 | * @brief Header file for the usbd_req.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_REQUEST_H 30 | #define __USB_REQUEST_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_REQ 45 | * @brief header file for the usbd_req.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_REQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_REQ_Exported_Types 58 | * @{ 59 | */ 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_REQ_Exported_Macros 67 | * @{ 68 | */ 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_REQ_Exported_Variables 74 | * @{ 75 | */ 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 81 | * @{ 82 | */ 83 | 84 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 85 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 86 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 87 | 88 | 89 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 90 | 91 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); 92 | 93 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USB_REQUEST_H */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | 113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 114 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_def.h 4 | * @author MCD Application Team 5 | * @version V2.2.0 6 | * @date 13-June-2014 7 | * @brief general defines for the usb device library 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | 30 | #ifndef __USBD_DEF_H 31 | #define __USBD_DEF_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "usbd_conf.h" 35 | 36 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USB_DEF 41 | * @brief general defines for the usb device library file 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USB_DEF_Exported_Defines 46 | * @{ 47 | */ 48 | 49 | #ifndef NULL 50 | #define NULL ((void *)0) 51 | #endif 52 | 53 | 54 | #define USB_LEN_DEV_QUALIFIER_DESC 0x0A 55 | #define USB_LEN_DEV_DESC 0x12 56 | #define USB_LEN_CFG_DESC 0x09 57 | #define USB_LEN_IF_DESC 0x09 58 | #define USB_LEN_EP_DESC 0x07 59 | #define USB_LEN_OTG_DESC 0x03 60 | #define USB_LEN_LANGID_STR_DESC 0x04 61 | #define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09 62 | 63 | #define USBD_IDX_LANGID_STR 0x00 64 | #define USBD_IDX_MFC_STR 0x01 65 | #define USBD_IDX_PRODUCT_STR 0x02 66 | #define USBD_IDX_SERIAL_STR 0x03 67 | 68 | #define USB_REQ_TYPE_STANDARD 0x00 69 | #define USB_REQ_TYPE_CLASS 0x20 70 | #define USB_REQ_TYPE_VENDOR 0x40 71 | #define USB_REQ_TYPE_MASK 0x60 72 | 73 | #define USB_REQ_RECIPIENT_DEVICE 0x00 74 | #define USB_REQ_RECIPIENT_INTERFACE 0x01 75 | #define USB_REQ_RECIPIENT_ENDPOINT 0x02 76 | #define USB_REQ_RECIPIENT_MASK 0x03 77 | 78 | #define USB_REQ_GET_STATUS 0x00 79 | #define USB_REQ_CLEAR_FEATURE 0x01 80 | #define USB_REQ_SET_FEATURE 0x03 81 | #define USB_REQ_SET_ADDRESS 0x05 82 | #define USB_REQ_GET_DESCRIPTOR 0x06 83 | #define USB_REQ_SET_DESCRIPTOR 0x07 84 | #define USB_REQ_GET_CONFIGURATION 0x08 85 | #define USB_REQ_SET_CONFIGURATION 0x09 86 | #define USB_REQ_GET_INTERFACE 0x0A 87 | #define USB_REQ_SET_INTERFACE 0x0B 88 | #define USB_REQ_SYNCH_FRAME 0x0C 89 | 90 | #define USB_DESC_TYPE_DEVICE 1 91 | #define USB_DESC_TYPE_CONFIGURATION 2 92 | #define USB_DESC_TYPE_STRING 3 93 | #define USB_DESC_TYPE_INTERFACE 4 94 | #define USB_DESC_TYPE_ENDPOINT 5 95 | #define USB_DESC_TYPE_DEVICE_QUALIFIER 6 96 | #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 97 | #define USB_DESC_TYPE_INTERFACE_ASSOCIATION 11 98 | 99 | 100 | #define USB_CONFIG_REMOTE_WAKEUP 2 101 | #define USB_CONFIG_SELF_POWERED 1 102 | 103 | #define USB_FEATURE_EP_HALT 0 104 | #define USB_FEATURE_REMOTE_WAKEUP 1 105 | #define USB_FEATURE_TEST_MODE 2 106 | 107 | 108 | #define USB_HS_MAX_PACKET_SIZE 512 109 | #define USB_FS_MAX_PACKET_SIZE 64 110 | #define USB_MAX_EP0_SIZE 64 111 | 112 | /* Device Status */ 113 | #define USBD_STATE_DEFAULT 1 114 | #define USBD_STATE_ADDRESSED 2 115 | #define USBD_STATE_CONFIGURED 3 116 | #define USBD_STATE_SUSPENDED 4 117 | 118 | 119 | /* EP0 State */ 120 | #define USBD_EP0_IDLE 0 121 | #define USBD_EP0_SETUP 1 122 | #define USBD_EP0_DATA_IN 2 123 | #define USBD_EP0_DATA_OUT 3 124 | #define USBD_EP0_STATUS_IN 4 125 | #define USBD_EP0_STATUS_OUT 5 126 | #define USBD_EP0_STALL 6 127 | 128 | #define USBD_EP_TYPE_CTRL 0 129 | #define USBD_EP_TYPE_ISOC 1 130 | #define USBD_EP_TYPE_BULK 2 131 | #define USBD_EP_TYPE_INTR 3 132 | 133 | 134 | /** 135 | * @} 136 | */ 137 | 138 | 139 | /** @defgroup USBD_DEF_Exported_TypesDefinitions 140 | * @{ 141 | */ 142 | 143 | typedef struct usb_setup_req 144 | { 145 | uint8_t bmRequest; 146 | uint8_t bRequest; 147 | uint16_t wValue; 148 | uint16_t wIndex; 149 | uint16_t wLength; 150 | } USBD_SetupReqTypedef; 151 | 152 | struct _USBD_HandleTypeDef; 153 | 154 | typedef struct _Device_cb 155 | { 156 | uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); 157 | uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); 158 | /* Control Endpoints*/ 159 | uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req); 160 | uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev ); 161 | uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev ); 162 | /* Class Specific Endpoints*/ 163 | uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 164 | uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 165 | uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev); 166 | uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 167 | uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 168 | 169 | const uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); 170 | #if (USBD_SUPPORT_USER_STRING == 1) 171 | uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length); 172 | #endif 173 | 174 | } USBD_ClassTypeDef; 175 | 176 | /* Following USB Device Speed */ 177 | typedef enum 178 | { 179 | USBD_SPEED_HIGH = 0, 180 | USBD_SPEED_FULL = 1, 181 | USBD_SPEED_LOW = 2, 182 | }USBD_SpeedTypeDef; 183 | 184 | /* Following USB Device status */ 185 | typedef enum { 186 | USBD_OK = 0, 187 | USBD_BUSY, 188 | USBD_FAIL, 189 | }USBD_StatusTypeDef; 190 | 191 | /* USB Device descriptors structure */ 192 | typedef struct 193 | { 194 | uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 195 | uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 196 | uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 197 | uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 198 | uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 199 | } USBD_DescriptorsTypeDef; 200 | 201 | /* USB Device handle structure */ 202 | typedef struct 203 | { 204 | uint32_t status; 205 | uint32_t total_length; 206 | uint32_t rem_length; 207 | uint32_t maxpacket; 208 | } USBD_EndpointTypeDef; 209 | 210 | /* USB Device handle structure */ 211 | typedef struct _USBD_HandleTypeDef 212 | { 213 | uint8_t id; 214 | uint32_t dev_config; 215 | uint32_t dev_default_config; 216 | uint32_t dev_config_status; 217 | USBD_SpeedTypeDef dev_speed; 218 | USBD_EndpointTypeDef ep_in[15]; 219 | USBD_EndpointTypeDef ep_out[15]; 220 | uint32_t ep0_state; 221 | uint32_t ep0_data_len; 222 | uint8_t dev_state; 223 | uint8_t dev_old_state; 224 | uint8_t dev_address; 225 | uint8_t dev_connection_status; 226 | uint32_t dev_remote_wakeup; 227 | 228 | USBD_SetupReqTypedef request; 229 | const USBD_DescriptorsTypeDef *pDesc; 230 | const USBD_ClassTypeDef *pClass; 231 | void *pData; 232 | } USBD_HandleTypeDef; 233 | 234 | /** 235 | * @} 236 | */ 237 | 238 | 239 | 240 | /** @defgroup USBD_DEF_Exported_Macros 241 | * @{ 242 | */ 243 | #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ 244 | (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) 245 | 246 | #define LOBYTE(x) ((uint8_t)(x & 0x00FF)) 247 | #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) 248 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 249 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 250 | 251 | 252 | #if defined ( __GNUC__ ) 253 | #ifndef __weak 254 | #define __weak __attribute__((weak)) 255 | #endif /* __weak */ 256 | #ifndef __packed 257 | #define __packed __attribute__((__packed__)) 258 | #endif /* __packed */ 259 | #endif /* __GNUC__ */ 260 | 261 | 262 | /* In HS mode and when the DMA is used, all variables and data structures dealing 263 | with the DMA during the transaction process should be 4-bytes aligned */ 264 | 265 | #if defined (__GNUC__) /* GNU Compiler */ 266 | #define __ALIGN_END __attribute__ ((aligned (4))) 267 | #define __ALIGN_BEGIN 268 | #else 269 | #define __ALIGN_END 270 | #if defined (__CC_ARM) /* ARM Compiler */ 271 | #define __ALIGN_BEGIN __align(4) 272 | #elif defined (__ICCARM__) /* IAR Compiler */ 273 | #define __ALIGN_BEGIN 274 | #elif defined (__TASKING__) /* TASKING Compiler */ 275 | #define __ALIGN_BEGIN __align(4) 276 | #endif /* __CC_ARM */ 277 | #endif /* __GNUC__ */ 278 | 279 | 280 | /** 281 | * @} 282 | */ 283 | 284 | /** @defgroup USBD_DEF_Exported_Variables 285 | * @{ 286 | */ 287 | 288 | /** 289 | * @} 290 | */ 291 | 292 | /** @defgroup USBD_DEF_Exported_FunctionsPrototype 293 | * @{ 294 | */ 295 | 296 | /** 297 | * @} 298 | */ 299 | 300 | #endif /* __USBD_DEF_H */ 301 | 302 | /** 303 | * @} 304 | */ 305 | 306 | /** 307 | * @} 308 | */ 309 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 310 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_desc.c: -------------------------------------------------------------------------------- 1 | /* 2 | example USB HID Sensor for STM32F072 microcontroller 3 | 4 | Copyright (C) 2015,2016 Peter Lawrence 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include "usbd_core.h" 26 | #include "usbd_desc.h" 27 | #include "usbd_conf.h" 28 | #include "usbhelper.h" 29 | #include "usbd_hid.h" 30 | #include "standardhidhelper.h" 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* Private define ------------------------------------------------------------*/ 34 | #define USBD_VID 0x1209 35 | #define USBD_PID 0x0001 36 | #define USBD_LANGID_STRING 0x409 37 | #define USBD_MANUFACTURER_STRING "Acme" 38 | #define USBD_PRODUCT_FS_STRING "Sensor" 39 | 40 | /* Private macro -------------------------------------------------------------*/ 41 | /* Private function prototypes -----------------------------------------------*/ 42 | static uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 43 | static uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 44 | static uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 45 | static uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 46 | static uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 47 | static uint8_t *USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 48 | static uint8_t *USBD_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 49 | static void IntToUnicode (uint32_t value, uint8_t *pbuf, uint8_t len); 50 | 51 | /* Private variables ---------------------------------------------------------*/ 52 | const USBD_DescriptorsTypeDef USBD_Desc = 53 | { 54 | USBD_DeviceDescriptor, 55 | USBD_LangIDStrDescriptor, 56 | USBD_ManufacturerStrDescriptor, 57 | USBD_ProductStrDescriptor, 58 | USBD_SerialStrDescriptor, 59 | }; 60 | 61 | /* USB Standard Device Descriptor */ 62 | static const struct device_descriptor hUSBDDeviceDesc = 63 | { 64 | sizeof(hUSBDDeviceDesc), /* bLength */ 65 | USB_DESC_TYPE_DEVICE, /* bDescriptorType */ 66 | USB_UINT16(0x0200), /* bcdUSB */ 67 | 0x00, /* bDeviceClass */ 68 | 0x00, /* bDeviceSubClass */ 69 | 0x00, /* bDeviceProtocol */ 70 | USB_MAX_EP0_SIZE, /* bMaxPacketSize */ 71 | USB_UINT16(USBD_VID), /* idVendor */ 72 | USB_UINT16(USBD_PID), /* idProduct */ 73 | USB_UINT16(0x0200), /* bcdDevice */ 74 | USBD_IDX_MFC_STR, /* Index of manufacturer string */ 75 | USBD_IDX_PRODUCT_STR, /* Index of product string */ 76 | USBD_IDX_SERIAL_STR, /* Index of serial number string */ 77 | USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */ 78 | }; 79 | 80 | /* bespoke struct for this device; struct members are added and removed as needed */ 81 | struct configuration_1 82 | { 83 | struct configuration_descriptor config; 84 | struct standardhid_interface vhid[NUM_OF_STANDARDHID]; 85 | }; 86 | 87 | /* fully initialize the bespoke struct as a const */ 88 | __ALIGN_BEGIN static const struct configuration_1 USBD_Composite_CfgFSDesc __ALIGN_END = 89 | { 90 | { 91 | /*Configuration Descriptor*/ 92 | sizeof(struct configuration_descriptor), /* bLength */ 93 | USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType */ 94 | USB_UINT16(sizeof(USBD_Composite_CfgFSDesc)), /* wTotalLength */ 95 | USBD_MAX_NUM_INTERFACES, /* bNumInterfaces */ 96 | 0x01, /* bConfigurationValue */ 97 | 0x00, /* iConfiguration */ 98 | 0x80, /* bmAttributes */ 99 | 50, /* MaxPower */ 100 | }, 101 | 102 | { 103 | #if (NUM_OF_STANDARDHID > 0) 104 | HIDNONE_DESCRIPTOR(/* ITF */ 0, /* DataIn EP */ 0x81, /* HID report size */ 184) 105 | #endif 106 | }, 107 | }; 108 | 109 | /* pointer and length of configuration descriptor for main USB driver */ 110 | const uint8_t *const USBD_CfgFSDesc_pnt = (const uint8_t *)&USBD_Composite_CfgFSDesc; 111 | const uint16_t USBD_CfgFSDesc_len = sizeof(USBD_Composite_CfgFSDesc); 112 | 113 | /* 114 | A peculiarity of the HID protocol is that the driver needs to be able to provide its report descriptor on request. 115 | Given this, we must manually create some data structures to point to the report descriptor within the above data. 116 | */ 117 | 118 | const struct USBD_CfgFSHIDDesc_struct USBD_CfgFSHIDDesc_array[NUM_OF_STANDARDHID] = 119 | { 120 | #if (NUM_OF_STANDARDHID > 0) 121 | { (const uint8_t *)&USBD_Composite_CfgFSDesc.vhid[0].hid_func, sizeof(USBD_Composite_CfgFSDesc.vhid[0].hid_func) }, 122 | #endif 123 | }; 124 | 125 | const struct USBD_CfgFSHIDDesc_struct *USBD_CfgFSHIDDesc = USBD_CfgFSHIDDesc_array; 126 | /* USB Standard Device Descriptor */ 127 | static const uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC]= 128 | { 129 | USB_LEN_LANGID_STR_DESC, 130 | USB_DESC_TYPE_STRING, 131 | LOBYTE(USBD_LANGID_STRING), 132 | HIBYTE(USBD_LANGID_STRING), 133 | }; 134 | 135 | static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ]; 136 | 137 | /** * @brief Returns the device descriptor. 138 | * @param speed: Current device speed 139 | * @param length: Pointer to data length variable 140 | * @retval Pointer to descriptor buffer 141 | */ 142 | static uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 143 | { 144 | *length = sizeof(hUSBDDeviceDesc); 145 | return (uint8_t*)&hUSBDDeviceDesc; 146 | } 147 | 148 | /** 149 | * @brief Returns the LangID string descriptor. 150 | * @param speed: Current device speed 151 | * @param length: Pointer to data length variable 152 | * @retval Pointer to descriptor buffer 153 | */ 154 | static uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 155 | { 156 | *length = sizeof(USBD_LangIDDesc); 157 | return (uint8_t*)USBD_LangIDDesc; 158 | } 159 | 160 | /** 161 | * @brief Returns the product string descriptor. 162 | * @param speed: Current device speed 163 | * @param length: Pointer to data length variable 164 | * @retval Pointer to descriptor buffer 165 | */ 166 | static uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 167 | { 168 | USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); 169 | return USBD_StrDesc; 170 | } 171 | 172 | /** 173 | * @brief Returns the manufacturer string descriptor. 174 | * @param speed: Current device speed 175 | * @param length: Pointer to data length variable 176 | * @retval Pointer to descriptor buffer 177 | */ 178 | static uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 179 | { 180 | USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); 181 | return USBD_StrDesc; 182 | } 183 | 184 | /** 185 | * @brief Returns the serial number string descriptor. 186 | * @param speed: Current device speed 187 | * @param length: Pointer to data length variable 188 | * @retval Pointer to descriptor buffer 189 | */ 190 | static uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 191 | { 192 | uint32_t deviceserial0, deviceserial1, deviceserial2; 193 | 194 | /* 195 | for some peculiar reason, ST doesn't define the unique ID registers in the HAL include files 196 | these registers are documented in Chapter 33 of the RM0091 Reference Manual 197 | */ 198 | deviceserial0 = *(uint32_t*)(0x1FFFF7AC); /*DEVICE_ID1*/ 199 | deviceserial1 = *(uint32_t*)(0x1FFFF7B0); /*DEVICE_ID2*/ 200 | deviceserial2 = *(uint32_t*)(0x1FFFF7B4); /*DEVICE_ID3*/ 201 | 202 | deviceserial0 += deviceserial2; 203 | 204 | USBD_StrDesc[0] = *length = 0x1A; 205 | USBD_StrDesc[1] = USB_DESC_TYPE_STRING; 206 | IntToUnicode (deviceserial0, &USBD_StrDesc[2] ,8); 207 | IntToUnicode (deviceserial1, &USBD_StrDesc[18] ,4); 208 | return USBD_StrDesc; 209 | } 210 | 211 | /** 212 | * @brief Convert Hex 32Bits value into char 213 | * @param value: value to convert 214 | * @param pbuf: pointer to the buffer 215 | * @param len: buffer length 216 | * @retval None 217 | */ 218 | static void IntToUnicode (uint32_t value, uint8_t *pbuf, uint8_t len) 219 | { 220 | uint8_t idx = 0; 221 | 222 | for( idx = 0 ; idx < len ; idx ++) 223 | { 224 | if( ((value >> 28)) < 0xA ) 225 | { 226 | pbuf[ 2* idx] = (value >> 28) + '0'; 227 | } 228 | else 229 | { 230 | pbuf[2* idx] = (value >> 28) + 'A' - 10; 231 | } 232 | 233 | value = value << 4; 234 | 235 | pbuf[ 2* idx + 1] = 0; 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_desc.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBD_DESC_H 2 | #define __USBD_DESC_H 3 | 4 | /* Includes ------------------------------------------------------------------*/ 5 | #include "usbd_def.h" 6 | 7 | /* Exported types ------------------------------------------------------------*/ 8 | /* Exported constants --------------------------------------------------------*/ 9 | /* Exported macro ------------------------------------------------------------*/ 10 | /* Exported functions ------------------------------------------------------- */ 11 | extern const USBD_DescriptorsTypeDef USBD_Desc; 12 | extern const uint8_t *const USBD_CfgFSDesc_pnt; 13 | extern const uint16_t USBD_CfgFSDesc_len; 14 | 15 | struct USBD_CfgFSHIDDesc_struct 16 | { 17 | const uint8_t *pnt; 18 | const uint16_t len; 19 | }; 20 | 21 | extern const struct USBD_CfgFSHIDDesc_struct *USBD_CfgFSHIDDesc; 22 | 23 | #endif /* __USBD_DESC_H */ 24 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_hid.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majbthrd/HIDsensor/8ed0a6312c4c9daee7c0431c160af9fbb824d30a/src/stm32f072/usbd_hid.c -------------------------------------------------------------------------------- /src/stm32f072/usbd_hid.h: -------------------------------------------------------------------------------- 1 | #ifndef __USB_HID_H 2 | #define __USB_HID_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* Includes ------------------------------------------------------------------*/ 9 | #include "usbd_ioreq.h" 10 | #include "usbd_composite.h" 11 | #include "config.h" 12 | 13 | #define HID_EP_SIZE 0x40 14 | 15 | #define HID_DESCRIPTOR_TYPE 0x21 16 | #define HID_REPORT_DESC 0x22 17 | #define HID_POLLING_INTERVAL 0x01 18 | 19 | #define HID_REQ_SET_PROTOCOL 0x0B 20 | #define HID_REQ_GET_PROTOCOL 0x03 21 | 22 | #define HID_REQ_SET_IDLE 0x0A 23 | #define HID_REQ_GET_IDLE 0x02 24 | 25 | #define HID_REQ_SET_REPORT 0x09 26 | #define HID_REQ_GET_REPORT 0x01 27 | 28 | typedef enum 29 | { 30 | HID_IDLE = 0, 31 | HID_BUSY, 32 | } 33 | HID_StateTypeDef; 34 | 35 | typedef struct 36 | { 37 | uint32_t Protocol; 38 | uint32_t IdleState; 39 | uint32_t AltSetting; 40 | uint8_t buffer[HID_EP_SIZE]; 41 | HID_StateTypeDef state; 42 | } 43 | USBD_HID_HandleTypeDef; 44 | 45 | extern const USBD_CompClassTypeDef USBD_HID; 46 | 47 | uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, unsigned index, uint8_t *report, uint16_t len); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __USB_HID_H */ 54 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 04-November-2014 7 | * @brief This file provides the IO requests APIs for control endpoints. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief control I/O requests module 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup USBD_IOREQ_Private_Variables 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 76 | * @{ 77 | */ 78 | /** 79 | * @} 80 | */ 81 | 82 | 83 | /** @defgroup USBD_IOREQ_Private_Functions 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @brief USBD_CtlSendData 89 | * send data on the ctl pipe 90 | * @param pdev: device instance 91 | * @param buff: pointer to data buffer 92 | * @param len: length of data to be sent 93 | * @retval status 94 | */ 95 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 96 | uint8_t *pbuf, 97 | uint16_t len) 98 | { 99 | /* Set EP0 State */ 100 | pdev->ep0_state = USBD_EP0_DATA_IN; 101 | pdev->ep_in[0].total_length = len; 102 | pdev->ep_in[0].rem_length = len; 103 | /* Start the transfer */ 104 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 105 | 106 | return USBD_OK; 107 | } 108 | 109 | /** 110 | * @brief USBD_CtlContinueSendData 111 | * continue sending data on the ctl pipe 112 | * @param pdev: device instance 113 | * @param buff: pointer to data buffer 114 | * @param len: length of data to be sent 115 | * @retval status 116 | */ 117 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 118 | uint8_t *pbuf, 119 | uint16_t len) 120 | { 121 | /* Start the next transfer */ 122 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 123 | 124 | return USBD_OK; 125 | } 126 | 127 | /** 128 | * @brief USBD_CtlPrepareRx 129 | * receive data on the ctl pipe 130 | * @param pdev: device instance 131 | * @param buff: pointer to data buffer 132 | * @param len: length of data to be received 133 | * @retval status 134 | */ 135 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 136 | uint8_t *pbuf, 137 | uint16_t len) 138 | { 139 | /* Set EP0 State */ 140 | pdev->ep0_state = USBD_EP0_DATA_OUT; 141 | pdev->ep_out[0].total_length = len; 142 | pdev->ep_out[0].rem_length = len; 143 | /* Start the transfer */ 144 | USBD_LL_PrepareReceive (pdev, 145 | 0, 146 | pbuf, 147 | len); 148 | 149 | return USBD_OK; 150 | } 151 | 152 | /** 153 | * @brief USBD_CtlContinueRx 154 | * continue receive data on the ctl pipe 155 | * @param pdev: device instance 156 | * @param buff: pointer to data buffer 157 | * @param len: length of data to be received 158 | * @retval status 159 | */ 160 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 161 | uint8_t *pbuf, 162 | uint16_t len) 163 | { 164 | 165 | USBD_LL_PrepareReceive (pdev, 166 | 0, 167 | pbuf, 168 | len); 169 | return USBD_OK; 170 | } 171 | /** 172 | * @brief USBD_CtlSendStatus 173 | * send zero lzngth packet on the ctl pipe 174 | * @param pdev: device instance 175 | * @retval status 176 | */ 177 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) 178 | { 179 | 180 | /* Set EP0 State */ 181 | pdev->ep0_state = USBD_EP0_STATUS_IN; 182 | 183 | /* Start the transfer */ 184 | USBD_LL_Transmit (pdev, 0x00, NULL, 0); 185 | 186 | return USBD_OK; 187 | } 188 | 189 | /** 190 | * @brief USBD_CtlReceiveStatus 191 | * receive zero lzngth packet on the ctl pipe 192 | * @param pdev: device instance 193 | * @retval status 194 | */ 195 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) 196 | { 197 | /* Set EP0 State */ 198 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 199 | 200 | /* Start the transfer */ 201 | USBD_LL_PrepareReceive ( pdev, 202 | 0, 203 | NULL, 204 | 0); 205 | 206 | return USBD_OK; 207 | } 208 | 209 | 210 | /** 211 | * @brief USBD_GetRxCount 212 | * returns the received data length 213 | * @param pdev: device instance 214 | * @param ep_addr: endpoint address 215 | * @retval Rx Data blength 216 | */ 217 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , uint8_t ep_addr) 218 | { 219 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 220 | } 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | 227 | /** 228 | * @} 229 | */ 230 | 231 | 232 | /** 233 | * @} 234 | */ 235 | 236 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 237 | -------------------------------------------------------------------------------- /src/stm32f072/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 04-November-2014 7 | * @brief Header file for the usbd_ioreq.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_IOREQ_H 30 | #define __USBD_IOREQ_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | #include "usbd_core.h" 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_IOREQ 45 | * @brief header file for the usbd_ioreq.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_IOREQ_Exported_Types 58 | * @{ 59 | */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Macros 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_Variables 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 85 | * @{ 86 | */ 87 | 88 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 89 | uint8_t *buf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 97 | uint8_t *pbuf, 98 | uint16_t len); 99 | 100 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 101 | uint8_t *pbuf, 102 | uint16_t len); 103 | 104 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); 105 | 106 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); 107 | 108 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , 109 | uint8_t epnum); 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* __USBD_IOREQ_H */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 129 | -------------------------------------------------------------------------------- /src/stm32f072/usbhelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | USB descriptor structs 3 | 4 | Copyright (C) 2015,2016 Peter Lawrence 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef __USB_MAGIC_H 26 | #define __USB_MAGIC_H 27 | 28 | #include 29 | 30 | /* 31 | IMPORTANT note to self: 32 | all of these helper structs must *solely* use uint8_t-derived members 33 | GCC doesn't seem to support packed structs any more, so to only way to avoid padding is to be uint8_t-only 34 | */ 35 | 36 | struct usb_uint16 37 | { 38 | uint8_t lo; 39 | uint8_t hi; 40 | }; 41 | 42 | #define USB_UINT16(x) { .lo = LOBYTE(x), .hi = HIBYTE(x) } 43 | 44 | struct device_descriptor 45 | { 46 | uint8_t bLength; 47 | uint8_t bDescriptorType; 48 | struct usb_uint16 bcdUSB; 49 | uint8_t bDeviceClass; 50 | uint8_t bDeviceSubclass; 51 | uint8_t bDeviceProtocol; 52 | uint8_t bMaxPacketSize0; 53 | struct usb_uint16 idVendor; 54 | struct usb_uint16 idProduct; 55 | struct usb_uint16 bcdDevice; 56 | uint8_t iManufacturer; 57 | uint8_t iProduct; 58 | uint8_t iSerialNumber; 59 | uint8_t bNumConfigurations; 60 | }; 61 | 62 | struct configuration_descriptor 63 | { 64 | uint8_t bLength; 65 | uint8_t bDescriptorType; 66 | struct usb_uint16 wTotalLength; 67 | uint8_t bNumInterfaces; 68 | uint8_t bConfigurationValue; 69 | uint8_t iConfiguration; 70 | uint8_t bmAttributes; 71 | uint8_t bMaxPower; 72 | }; 73 | 74 | struct interface_descriptor 75 | { 76 | uint8_t bLength; 77 | uint8_t bDescriptorType; 78 | uint8_t bInterfaceNumber; 79 | uint8_t bAlternateSetting; 80 | uint8_t bNumEndpoints; 81 | uint8_t bInterfaceClass; 82 | uint8_t bInterfaceSubclass; 83 | uint8_t bInterfaceProtocol; 84 | uint8_t iInterface; 85 | }; 86 | 87 | struct endpoint_descriptor 88 | { 89 | uint8_t bLength; 90 | uint8_t bDescriptorType; 91 | uint8_t bEndpointAddress; 92 | uint8_t bmAttributes; 93 | struct usb_uint16 wMaxPacketSize; 94 | uint8_t bInterval; 95 | }; 96 | 97 | struct cdc_functional_descriptor_header 98 | { 99 | uint8_t bFunctionLength; 100 | uint8_t bDescriptorType; 101 | uint8_t bDescriptorSubtype; 102 | struct usb_uint16 bcdCDC; 103 | }; 104 | 105 | struct cdc_acm_functional_descriptor 106 | { 107 | uint8_t bFunctionLength; 108 | uint8_t bDescriptorType; 109 | uint8_t bDescriptorSubtype; 110 | uint8_t bmCapabilities; 111 | }; 112 | 113 | struct cdc_cm_functional_descriptor 114 | { 115 | uint8_t bFunctionLength; 116 | uint8_t bDescriptorType; 117 | uint8_t bDescriptorSubtype; 118 | uint8_t bmCapabilities; 119 | uint8_t bDataInterface; 120 | }; 121 | 122 | struct cdc_union_functional_descriptor 123 | { 124 | uint8_t bFunctionLength; 125 | uint8_t bDescriptorType; 126 | uint8_t bDescriptorSubtype; 127 | uint8_t bMasterInterface; 128 | uint8_t bSlaveInterface0; 129 | }; 130 | 131 | struct hid_functional_descriptor 132 | { 133 | uint8_t bFunctionLength; 134 | uint8_t bDescriptorType; 135 | struct usb_uint16 bcdHID; 136 | uint8_t bCountryCode; 137 | uint8_t bNumDescriptors; 138 | /* FIXME: a shortcut taken below is to assume bNumDescriptors = 1 */ 139 | uint8_t bDescriptorType2; 140 | struct usb_uint16 wItemLength; 141 | }; 142 | 143 | struct interface_association_descriptor 144 | { 145 | uint8_t bLength; 146 | uint8_t bDescriptorType; 147 | uint8_t bFirstInterface; 148 | uint8_t bInterfaceCount; 149 | uint8_t bFunctionClass; 150 | uint8_t bFunctionSubClass; 151 | uint8_t bFunctionProtocol; 152 | uint8_t iFunction; 153 | }; 154 | 155 | #endif /* __USB_MAGIC_H */ 156 | --------------------------------------------------------------------------------