├── .gitattributes ├── .github └── workflows │ ├── test-build-lnx.yml │ ├── test-build-osx.yml │ └── test-build-win.yml ├── .gitignore ├── Doxyfile ├── LICENSE ├── Makefile ├── demo ├── cdc_loop.c ├── cdc_startup.c ├── sections.ld ├── stm32f042x6.ld ├── stm32f070xb.ld ├── stm32f103x6.ld ├── stm32f105xb.ld ├── stm32f303xc.ld ├── stm32f303xe.ld ├── stm32f373xc.ld ├── stm32f401xc.ld ├── stm32f401xe.ld ├── stm32f405xg.ld ├── stm32f429xi.ld ├── stm32f446xc.ld ├── stm32f745xe.ld ├── stm32g431xb.ld ├── stm32h743xx.ld ├── stm32l052x8.ld ├── stm32l100xc.ld ├── stm32l433xc.ld ├── stm32l476xg.ld └── stm32wb55xg.ld ├── hardware.md ├── inc ├── hid_usage_button.h ├── hid_usage_consumer.h ├── hid_usage_desktop.h ├── hid_usage_device.h ├── hid_usage_game.h ├── hid_usage_keyboard.h ├── hid_usage_led.h ├── hid_usage_ordinal.h ├── hid_usage_power.h ├── hid_usage_simulation.h ├── hid_usage_sport.h ├── hid_usage_telephony.h ├── hid_usage_vr.h ├── stm32_compat.h ├── usb.h ├── usb_cdc.h ├── usb_cdca.h ├── usb_cdce.h ├── usb_cdci.h ├── usb_cdcp.h ├── usb_cdcw.h ├── usb_dfu.h ├── usb_hid.h ├── usb_std.h ├── usb_tmc.h └── usbd_core.h ├── library.json ├── readme.md └── src ├── memmap.inc ├── usbd_core.c ├── usbd_stm32f103_devfs.c ├── usbd_stm32f103_devfs_asm.S ├── usbd_stm32f105_otgfs.c ├── usbd_stm32f429_otgfs.c ├── usbd_stm32f429_otghs.c ├── usbd_stm32f446_otgfs.c ├── usbd_stm32f446_otghs.c ├── usbd_stm32h743_otgfs.c ├── usbd_stm32l052_devfs.c ├── usbd_stm32l052_devfs_asm.S ├── usbd_stm32l100_devfs.c ├── usbd_stm32l100_devfs_asm.S ├── usbd_stm32l433_devfs.c ├── usbd_stm32l476_otgfs.c └── usbd_stm32wb55_devfs.c /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/workflows/test-build-lnx.yml: -------------------------------------------------------------------------------- 1 | name: LNX build 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | paths-ignore: 7 | - '**.md' 8 | push: 9 | branches: 10 | - master 11 | paths-ignore: 12 | - '**.md' 13 | 14 | jobs: 15 | build: 16 | name: Linux 17 | env: 18 | CMSIS: CMSIS_5 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: ARM GCC setup 22 | uses: fiam/arm-none-eabi-gcc@v1 23 | with: 24 | release: 8-2019-q3 25 | - name: Checkout 26 | uses: actions/checkout@v2 27 | - name: Resolve prerequisites 28 | run: make cmsis 29 | - name: testbuild F103 30 | run: make stm32f103x6 31 | - name: testbuild F303 32 | run: make stm32f303xe 33 | - name: testbuild F105 34 | run: make stm32f105xb 35 | - name: testbuild L052 36 | run: make stm32l052x8 37 | - name: testbuild L100 38 | run: make stm32l100xc 39 | - name: testbuild L476 40 | run: make stm32l476xg 41 | - name: testbuild F429 42 | run: make stm32f429xi 43 | - name: testbuild L433 44 | run: make stm32l433cc 45 | - name: testbuild F070 46 | run: make stm32f070xb 47 | - name: testbuild G431 48 | run: make stm32g431xb 49 | - name: testbuild F446 50 | run: make stm32f446xc 51 | - name: testbuild F373 52 | run: make stm32f373xc 53 | - name: testbuild F745 54 | run: make stm32f745xe 55 | -------------------------------------------------------------------------------- /.github/workflows/test-build-osx.yml: -------------------------------------------------------------------------------- 1 | name: OSX build 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | paths-ignore: 7 | - '**.md' 8 | push: 9 | branches: 10 | - master 11 | paths-ignore: 12 | - '**.md' 13 | 14 | jobs: 15 | build: 16 | name: OSX 17 | env: 18 | CMSIS: CMSIS_5 19 | runs-on: macos-latest 20 | steps: 21 | - name: ARM GCC setup 22 | uses: fiam/arm-none-eabi-gcc@v1 23 | with: 24 | release: 8-2019-q3 25 | - name: Checkout 26 | uses: actions/checkout@v2 27 | - name: Update make 28 | run: brew install make 29 | - name: Resolve prerequisites 30 | run: gmake cmsis 31 | - name: testbuild F103 32 | run: gmake stm32f103x6 33 | - name: testbuild F303 34 | run: gmake stm32f303xe 35 | - name: testbuild F105 36 | run: gmake stm32f105xb 37 | - name: testbuild L052 38 | run: gmake stm32l052x8 39 | - name: testbuild L100 40 | run: gmake stm32l100xc 41 | - name: testbuild L476 42 | run: gmake stm32l476xg 43 | - name: testbuild F429 44 | run: gmake stm32f429xi 45 | - name: testbuild L433 46 | run: gmake stm32l433cc 47 | - name: testbuild F070 48 | run: gmake stm32f070xb 49 | - name: testbuild G431 50 | run: gmake stm32g431xb 51 | - name: testbuild F446 52 | run: gmake stm32f446xc 53 | - name: testbuild F373 54 | run: gmake stm32f373xc 55 | - name: testbuild F745 56 | run: gmake stm32f745xe 57 | -------------------------------------------------------------------------------- /.github/workflows/test-build-win.yml: -------------------------------------------------------------------------------- 1 | name: WIN build 2 | on: 3 | pull_request: 4 | branches: 5 | - master 6 | paths-ignore: 7 | - '**.md' 8 | push: 9 | branches: 10 | - master 11 | paths-ignore: 12 | - '**.md' 13 | 14 | jobs: 15 | build: 16 | name: Windows 17 | env: 18 | CMSIS: CMSIS_5 19 | runs-on: windows-2019 20 | steps: 21 | - name: ARM GCC setup 22 | uses: fiam/arm-none-eabi-gcc@v1 23 | with: 24 | release: 8-2019-q3 25 | - name: Checkout 26 | uses: actions/checkout@v2 27 | - name: Resolve prerequisites 28 | run: make cmsis SHELL=cmd 29 | - name: testbuild F103 30 | run: make stm32f103x6 SHELL=cmd 31 | - name: testbuild F303 32 | run: make stm32f303xe SHELL=cmd 33 | - name: testbuild F105 34 | run: make stm32f105xb SHELL=cmd 35 | - name: testbuild L052 36 | run: make stm32l052x8 SHELL=cmd 37 | - name: testbuild L100 38 | run: make stm32l100xc SHELL=cmd 39 | - name: testbuild L476 40 | run: make stm32l476xg SHELL=cmd 41 | - name: testbuild F429 42 | run: make stm32f429xi SHELL=cmd 43 | - name: testbuild L433 44 | run: make stm32l433cc SHELL=cmd 45 | - name: testbuild F070 46 | run: make stm32f070xb SHELL=cmd 47 | - name: testbuild G431 48 | run: make stm32g431xb SHELL=cmd 49 | - name: testbuild F446 50 | run: make stm32f446xc SHELL=cmd 51 | - name: testbuild F373 52 | run: make stm32f373xc SHELL=cmd 53 | - name: testbuild F745 54 | run: make stm32f745xe SHELL=cmd 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #compile artefacts 2 | obj/* 3 | html/* 4 | *.hex 5 | *.elf 6 | *.map 7 | *.a 8 | *.bin 9 | 10 | #ide/editor files 11 | *.depend 12 | *.ebp 13 | *.elay 14 | *.sublime-project 15 | *.sublime-workspace 16 | .vscode 17 | 18 | #debug 19 | svd/* 20 | openocd.cfg 21 | 22 | #doxydoc artefacts 23 | html/* 24 | 25 | #other junk 26 | .DS_Store 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CMSIS ?= CMSIS 2 | CMSISDEV ?= $(CMSIS)/Device 3 | CMSISCORE ?= $(CMSIS)/CMSIS/Include $(CMSIS)/CMSIS/Core/Include 4 | FLASH ?= st-flash 5 | TOOLSET ?= arm-none-eabi- 6 | CC = $(TOOLSET)gcc 7 | LD = $(TOOLSET)gcc 8 | AR = $(TOOLSET)gcc-ar 9 | OBJCOPY = $(TOOLSET)objcopy 10 | DFU_UTIL ?= dfu-util 11 | STPROG_CLI ?= ~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI 12 | OPTFLAGS ?= -Os 13 | 14 | ifeq ($(OS),Windows_NT) 15 | RM = del /Q 16 | fixpath = $(strip $(subst /,\, $1)) 17 | else 18 | RM = rm -f 19 | fixpath = $(strip $1) 20 | endif 21 | 22 | MODULE ?= libusb.a 23 | CFLAGS ?= -mcpu=cortex-m3 24 | DEFINES ?= STM32F1 STM32F103x6 25 | 26 | ARFLAGS = -cvq 27 | LDFLAGS = --specs=nano.specs -nostartfiles -Wl,--gc-sections -L demo 28 | INCLUDES = $(CMSISDEV)/ST $(CMSISCORE) inc 29 | CFLAGS2 ?= $(CFLAGS) -mthumb -std=gnu99 $(OPTFLAGS) 30 | 31 | OBJDIR = obj 32 | SOURCES = $(wildcard src/*.c) $(wildcard src/*.S) 33 | OBJECTS = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES))))) 34 | DSRC = $(wildcard demo/*.c) $(wildcard demo/*.S) $(STARTUP) 35 | DOBJ = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(DSRC))))) 36 | DOUT = cdc_loop 37 | 38 | SRCPATH = $(sort $(dir $(SOURCES) $(DSRC))) 39 | vpath %.c $(SRCPATH) 40 | vpath %.S $(SRCPATH) 41 | vpath %.s $(SRCPATH) 42 | 43 | help all: 44 | @echo 'Usage: make target [program]' 45 | @echo 'Available targets are:' 46 | @echo ' bluepill' 47 | @echo ' stm32f103x6 CDC loopback demo for STM32F103 based boards' 48 | @echo ' 32l100c-disco' 49 | @echo ' stm32l100xc CDC loopback demo for STM32L100xC based boards' 50 | @echo ' 32l476rg-nucleo' 51 | @echo ' stm32l476rg CDC loopback demo for STM32L476xG based boards' 52 | @echo ' stm32l052x8 CDC loopback demo for STM32L052x8 based boards' 53 | @echo ' 32f429zi-nucleo' 54 | @echo ' stm32f429xi CDC loopback demo for STM32F429xI based boards' 55 | @echo ' stm32f401xc CDC loopback demo for STM32F401xC based boards' 56 | @echo ' stm32f401xe CDC loopback demo for STM32F401xE based boards' 57 | @echo ' cmsis Download CMSIS 5 and stm32.h into a $$(CMSIS) directory' 58 | @echo ' doc DOXYGEN documentation' 59 | @echo ' module static library module using following envars (defaults)' 60 | @echo ' MODULE module name ($(MODULE))' 61 | @echo ' CFLAGS mcu specified compiler flags ($(CFLAGS))' 62 | @echo ' DEFINES mcu and module specified defines ($(DEFINES))' 63 | @echo ' see USB Device HW driver and core API section for the' 64 | @echo ' compile-time control macros' 65 | @echo ' ' 66 | @echo 'Environmental variables (defaults):' 67 | @echo ' CMSIS Path to the CMSIS V4 or CMSIS V5 root folder ($(CMSIS))' 68 | @echo ' CMSISCORE Path to the CMSIS Core include folder(s) ($(CMSISCORE))' 69 | @echo ' CMSISDEV Path to the CMSIS Device folder ($(CMSISDEV))' 70 | @echo ' FLASH st-link flash utility ($(FLASH))' 71 | @echo ' ' 72 | @echo 'Examples:' 73 | @echo ' make bluepill program' 74 | @echo ' make module MODULE="usbd.a" CFLAGS="-mcpu=cortex-m4" DEFINES="STM32L4 STM32L476xx USBD_VBUS_DETECT"' 75 | 76 | cmsis: $(CMSISDEV)/ST 77 | 78 | $(CMSISDEV)/ST: $(CMSIS) 79 | @git clone --recurse-submodules --depth 1 https://github.com/dmitrystu/stm32h.git $@ 80 | 81 | $(CMSIS): 82 | @git clone --depth 1 https://github.com/ARM-software/CMSIS_5.git $@ 83 | 84 | $(OBJDIR): 85 | @mkdir $@ 86 | 87 | program: $(DOUT).hex 88 | $(FLASH) --reset --format ihex write $(DOUT).hex 89 | 90 | program_dfu: $(DOUT).bin 91 | $(DFU_UTIL) -d 0483:DF11 -a 0 -D $(DOUT).bin -s 0x08000000 92 | 93 | program_stcube: $(DOUT).hex 94 | $(STPROG_CLI) -c port=SWD reset=HWrst -d $(DOUT).hex -hardRst 95 | 96 | demo: $(DOUT).hex $(DOUT).bin 97 | 98 | $(DOUT).bin : $(DOUT).elf 99 | @echo building $@ 100 | @$(OBJCOPY) -O binary $< $@ 101 | 102 | $(DOUT).hex : $(DOUT).elf 103 | @echo building $@ 104 | @$(OBJCOPY) -O ihex $< $@ 105 | 106 | $(DOUT).elf : $(OBJDIR) $(DOBJ) $(OBJECTS) 107 | @echo building $@ 108 | @$(LD) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) $(OBJECTS) -o $@ 109 | 110 | clean: $(OBJDIR) 111 | $(MAKE) --version 112 | @$(RM) $(DOUT).* 113 | @$(RM) $(call fixpath, $(OBJDIR)/*.*) 114 | 115 | doc: 116 | doxygen 117 | 118 | module: clean 119 | $(MAKE) $(MODULE) 120 | 121 | $(MODULE): $(OBJDIR) $(OBJECTS) 122 | @$(AR) $(ARFLAGS) $(MODULE) $(OBJECTS) 123 | 124 | $(OBJDIR)/%.o: %.c 125 | @echo compiling $< 126 | @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@ 127 | 128 | $(OBJDIR)/%.o: %.S 129 | @echo assembling $< 130 | @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@ 131 | 132 | $(OBJDIR)/%.o: %.s 133 | @echo assembling $< 134 | @$(CC) $(CFLAGS2) $(addprefix -D, $(DEFINES)) $(addprefix -I, $(INCLUDES)) -c $< -o $@ 135 | 136 | .PHONY: module doc demo clean program help all program_stcube cmsis 137 | 138 | stm32f103x6 bluepill: clean 139 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103x6.s' \ 140 | LDSCRIPT='demo/stm32f103x6.ld' \ 141 | DEFINES='STM32F1 STM32F103x6 USBD_SOF_DISABLED' \ 142 | CFLAGS='-mcpu=cortex-m3' 143 | 144 | stm32f303xe 32f303re-nucleo: clean 145 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xe.s' \ 146 | LDSCRIPT='demo/stm32f303xe.ld' \ 147 | DEFINES='STM32F3 STM32F303xE USBD_SOF_DISABLED' \ 148 | CFLAGS='-mcpu=cortex-m4' 149 | 150 | stm32f303xc: clean 151 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xc.s' \ 152 | LDSCRIPT='demo/stm32f303xc.ld' \ 153 | DEFINES='STM32F3 STM32F303xC USBD_SOF_DISABLED' \ 154 | CFLAGS='-mcpu=cortex-m4' 155 | 156 | stm32f105xb: clean 157 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f105xc.s' \ 158 | LDSCRIPT='demo/stm32f105xb.ld' \ 159 | DEFINES='STM32F1 STM32F105xC USBD_VBUS_DETECT USBD_SOF_DISABLED' \ 160 | CFLAGS='-mcpu=cortex-m3 -Wp,-w' 161 | 162 | stm32f107xb: clean 163 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f107xc.s' \ 164 | LDSCRIPT='demo/stm32f105xb.ld' \ 165 | DEFINES='STM32F1 STM32F107xC HSE_25MHZ USBD_VBUS_DETECT USBD_SOF_DISABLED' \ 166 | CFLAGS='-mcpu=cortex-m3 -Wp,-w' 167 | 168 | stm32l052x8: clean 169 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s' \ 170 | LDSCRIPT='demo/stm32l052x8.ld' \ 171 | DEFINES='STM32L0 STM32L052xx USBD_SOF_DISABLED' \ 172 | CFLAGS='-mcpu=cortex-m0plus' 173 | 174 | stm32l100xc 32l100c-disco: clean 175 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L1xx/Source/Templates/gcc/startup_stm32l100xc.s' \ 176 | LDSCRIPT='demo/stm32l100xc.ld' \ 177 | DEFINES='STM32L1 STM32L100xC USBD_SOF_DISABLED' \ 178 | CFLAGS='-mcpu=cortex-m3' 179 | 180 | stm32l476xg 32l476rg-nucleo: clean 181 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l476xx.s' \ 182 | LDSCRIPT='demo/stm32l476xg.ld' \ 183 | DEFINES='STM32L4 STM32L476xx USBD_SOF_DISABLED' \ 184 | CFLAGS='-mcpu=cortex-m4' 185 | 186 | stm32f429xi 32f429zi-nucleo: clean 187 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \ 188 | LDSCRIPT='demo/stm32f429xi.ld' \ 189 | DEFINES='STM32F4 STM32F429xx USBD_SOF_DISABLED' \ 190 | CFLAGS='-mcpu=cortex-m4' 191 | 192 | stm32f429xi_hs 32f429zi-nucleo_hs: clean 193 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f429xx.s' \ 194 | LDSCRIPT='demo/stm32f429xi.ld' \ 195 | DEFINES='STM32F4 STM32F429xx USBD_PRIMARY_OTGHS USBD_SOF_DISABLED' \ 196 | CFLAGS='-mcpu=cortex-m4' 197 | 198 | stm32l433cc: clean 199 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l433xx.s' \ 200 | LDSCRIPT='demo/stm32l433xc.ld' \ 201 | DEFINES='STM32L4 STM32L433xx USBD_SOF_DISABLED' \ 202 | CFLAGS='-mcpu=cortex-m4' 203 | 204 | 205 | stm32f070xb: clean 206 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f070xb.s' \ 207 | LDSCRIPT='demo/stm32f070xb.ld' \ 208 | DEFINES='STM32F0 STM32F070xB USBD_SOF_DISABLED' \ 209 | CFLAGS='-mcpu=cortex-m0' 210 | 211 | stm32g431xb 32g431rb-nucleo: clean 212 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32G4xx/Source/Templates/gcc/startup_stm32g431xx.s' \ 213 | LDSCRIPT='demo/stm32g431xb.ld' \ 214 | DEFINES='STM32G4 STM32G431xx USBD_SOF_DISABLED' \ 215 | CFLAGS='-mcpu=cortex-m4' 216 | 217 | stm32f446xc 32f446re-nucleo: clean 218 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f446xx.s' \ 219 | LDSCRIPT='demo/stm32f446xc.ld' \ 220 | DEFINES='STM32F4 STM32F446xx USBD_SOF_DISABLED' \ 221 | CFLAGS='-mcpu=cortex-m4' 222 | 223 | stm32f446xc_hs 32f446re-nucleo_hs: clean 224 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f446xx.s' \ 225 | LDSCRIPT='demo/stm32f446xc.ld' \ 226 | DEFINES='STM32F4 STM32F446xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \ 227 | CFLAGS='-mcpu=cortex-m4' 228 | 229 | stm32f373xc: clean 230 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f373xc.s' \ 231 | LDSCRIPT='demo/stm32f373xc.ld' \ 232 | DEFINES='STM32F3 STM32F373xC USBD_SOF_DISABLED' \ 233 | CFLAGS='-mcpu=cortex-m4' 234 | 235 | stm32l053x8 32l053r8-nucleo: clean 236 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l053xx.s' \ 237 | LDSCRIPT='demo/stm32l052x8.ld' \ 238 | DEFINES='STM32L0 STM32L053xx USBD_SOF_DISABLED' \ 239 | CFLAGS='-mcpu=cortex-m0plus' 240 | 241 | stm32f405xg: clean 242 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f405xx.s' \ 243 | LDSCRIPT='demo/stm32f405xg.ld' \ 244 | DEFINES='STM32F4 STM32F405xx USBD_SOF_DISABLED' \ 245 | CFLAGS='-mcpu=cortex-m4' 246 | 247 | stm32f405xg_hs: clean 248 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f405xx.s' \ 249 | LDSCRIPT='demo/stm32f405xg.ld' \ 250 | DEFINES='STM32F4 STM32F405xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \ 251 | CFLAGS='-mcpu=cortex-m4' 252 | 253 | stm32f401xc: clean 254 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f401xc.s' \ 255 | LDSCRIPT='demo/stm32f401xc.ld' \ 256 | DEFINES='STM32F4 STM32F401xC USBD_SOF_DISABLED' \ 257 | CFLAGS='-mcpu=cortex-m4' 258 | 259 | stm32f401xe: clean 260 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f401xe.s' \ 261 | LDSCRIPT='demo/stm32f401xe.ld' \ 262 | DEFINES='STM32F4 STM32F401xE USBD_SOF_DISABLED' \ 263 | CFLAGS='-mcpu=cortex-m4' 264 | 265 | stm32f745xe: clean 266 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f745xx.s' \ 267 | LDSCRIPT='demo/stm32f745xe.ld' \ 268 | DEFINES='STM32F7 STM32F745xx USBD_SOF_DISABLED' \ 269 | CFLAGS='-mcpu=cortex-m7' 270 | 271 | stm32f745xe_hs: clean 272 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f745xx.s' \ 273 | LDSCRIPT='demo/stm32f745xe.ld' \ 274 | DEFINES='STM32F7 STM32F745xx USBD_SOF_DISABLED USBD_PRIMARY_OTGHS' \ 275 | CFLAGS='-mcpu=cortex-m7' 276 | 277 | stm32f042f6: clean 278 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f042x6.s' \ 279 | LDSCRIPT='demo/stm32f042x6.ld' \ 280 | DEFINES='STM32F0 STM32F042x6 USBD_SOF_DISABLED' \ 281 | CFLAGS='-mcpu=cortex-m0 -DUSBD_PINS_REMAP' 282 | 283 | stm32wb55xg: clean 284 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32WBxx/Source/Templates/gcc/startup_stm32wb55xx_cm4.s' \ 285 | LDSCRIPT='demo/stm32wb55xg.ld' \ 286 | DEFINES='STM32WB STM32WB55xx USBD_SOF_DISABLED' \ 287 | CFLAGS='-mcpu=cortex-m4' 288 | 289 | stm32h743xx: clean 290 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h743xx.s' \ 291 | LDSCRIPT='demo/stm32h743xx.ld' \ 292 | DEFINES='STM32H7 STM32H743xx USBD_VBUS_DETECT USBD_SOF_DISABLED' \ 293 | CFLAGS='-mcpu=cortex-m7' 294 | 295 | stm32f411xe stm32f411e-disco: clean 296 | @$(MAKE) demo STARTUP='$(CMSISDEV)/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f411xe.s' \ 297 | LDSCRIPT='demo/stm32f401xe.ld' \ 298 | DEFINES='STM32F4 STM32F411xE USBD_SOF_DISABLED' \ 299 | CFLAGS='-mcpu=cortex-m4' 300 | -------------------------------------------------------------------------------- /demo/cdc_startup.c: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "stm32_compat.h" 17 | 18 | static void cdc_init_rcc (void) { 19 | #if defined(STM32L0) 20 | _BST(RCC->APB1ENR, RCC_APB1ENR_PWREN); 21 | _BMD(PWR->CR, PWR_CR_VOS, PWR_CR_VOS_0); 22 | _WBC(PWR->CSR, PWR_CSR_VOSF); 23 | /* set FLASH latency to 1 */ 24 | _BST(FLASH->ACR, FLASH_ACR_LATENCY); 25 | /* set clock at 32MHz PLL 6/3 HSI */ 26 | _BMD(RCC->CFGR, RCC_CFGR_PLLDIV | RCC_CFGR_PLLMUL | RCC_CFGR_PLLSRC, RCC_CFGR_PLLDIV3 | RCC_CFGR_PLLMUL6); 27 | _BST(RCC->CR, RCC_CR_HSION); 28 | _WBS(RCC->CR, RCC_CR_HSIRDY); 29 | _BST(RCC->CR, RCC_CR_PLLON); 30 | _WBS(RCC->CR, RCC_CR_PLLRDY); 31 | /* switch clock to PLL */ 32 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 33 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 34 | 35 | #elif defined(STM32L1) 36 | _BST(RCC->APB1ENR, RCC_APB1ENR_PWREN); 37 | _BMD(PWR->CR, PWR_CR_VOS, PWR_CR_VOS_0); 38 | _WBC(PWR->CSR, PWR_CSR_VOSF); 39 | /* set FLASH latency to 1 */ 40 | _BST(FLASH->ACR, FLASH_ACR_ACC64); 41 | _BST(FLASH->ACR, FLASH_ACR_LATENCY); 42 | /* set clock at 32 MHz PLL 6/3 HSI */ 43 | _BMD(RCC->CFGR, RCC_CFGR_PLLDIV | RCC_CFGR_PLLMUL | RCC_CFGR_PLLSRC, RCC_CFGR_PLLDIV3 | RCC_CFGR_PLLMUL6); 44 | _BST(RCC->CR, RCC_CR_HSION); 45 | _WBS(RCC->CR, RCC_CR_HSIRDY); 46 | _BST(RCC->CR, RCC_CR_PLLON); 47 | _WBS(RCC->CR, RCC_CR_PLLRDY); 48 | /* switch clock to PLL */ 49 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 50 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 51 | 52 | #elif defined(STM32L476xx) 53 | _BST(RCC->APB1ENR1, RCC_APB1ENR1_PWREN); 54 | /* Set power Range 1 */ 55 | _BMD(PWR->CR1, PWR_CR1_VOS, PWR_CR1_VOS_0); 56 | _WBC(PWR->SR2, PWR_SR2_VOSF); 57 | /* Adjust Flash latency */ 58 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_2WS); 59 | /* set clock 48Mhz MSI */ 60 | _BMD(RCC->CR, RCC_CR_MSIRANGE, RCC_CR_MSIRANGE_11 | RCC_CR_MSIRGSEL); 61 | /* set MSI as 48MHz USB */ 62 | _BMD(RCC->CCIPR, RCC_CCIPR_CLK48SEL, RCC_CCIPR_CLK48SEL_0 | RCC_CCIPR_CLK48SEL_1); 63 | /* enable GPIOA clock */ 64 | _BST(RCC->AHB2ENR, RCC_AHB2ENR_GPIOAEN); 65 | /* set GP11 and GP12 as USB data pins AF10 */ 66 | _BST(GPIOA->AFR[1], (0x0A << 12) | (0x0A << 16)); 67 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); 68 | 69 | #elif defined(STM32F103x6) 70 | /* set flash latency 1WS */ 71 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_1); 72 | /* use PLL 48MHz clock from 8Mhz HSI */ 73 | _BMD(RCC->CFGR, 74 | RCC_CFGR_PLLMULL | RCC_CFGR_PLLSRC | RCC_CFGR_USBPRE, 75 | RCC_CFGR_PLLMULL12 | RCC_CFGR_USBPRE); 76 | _BST(RCC->CR, RCC_CR_PLLON); 77 | _WBS(RCC->CR, RCC_CR_PLLRDY); 78 | /* switch to PLL */ 79 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 80 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 81 | 82 | #elif defined(STM32F303xE) 83 | /* set flash latency 1WS */ 84 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_1); 85 | /* use PLL 48MHz clock from 8Mhz HSI */ 86 | _BMD(RCC->CFGR, 87 | RCC_CFGR_PLLMUL | RCC_CFGR_PLLSRC | RCC_CFGR_USBPRE, 88 | RCC_CFGR_PLLMUL12 | RCC_CFGR_USBPRE); 89 | _BST(RCC->CR, RCC_CR_PLLON); 90 | _WBS(RCC->CR, RCC_CR_PLLRDY); 91 | /* switch to PLL */ 92 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 93 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 94 | 95 | #elif defined(STM32F303xC) 96 | /* set flash latency 1WS */ 97 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_1); 98 | /* use PLL 48MHz clock from 8Mhz HSI */ 99 | _BMD(RCC->CFGR, 100 | RCC_CFGR_PLLMUL | RCC_CFGR_PLLSRC | RCC_CFGR_USBPRE, 101 | RCC_CFGR_PLLMUL12 | RCC_CFGR_USBPRE); 102 | _BST(RCC->CR, RCC_CR_PLLON); 103 | _WBS(RCC->CR, RCC_CR_PLLRDY); 104 | /* switch to PLL */ 105 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 106 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 107 | 108 | _BST(RCC->AHBENR, RCC_AHBENR_GPIOAEN); 109 | _BST(GPIOA->AFR[1], (0x0E << 12) | (0x0E << 16)); 110 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); 111 | 112 | #elif defined(STM32F373xC) 113 | /* set flash latency 1WS */ 114 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_1); 115 | _BMD(RCC->CFGR, 116 | RCC_CFGR_PLLMUL | RCC_CFGR_PLLSRC | RCC_CFGR_USBPRE | RCC_CFGR_PPRE1, 117 | RCC_CFGR_PLLMUL12 | RCC_CFGR_USBPRE | RCC_CFGR_PPRE1_DIV2); 118 | _BST(RCC->CR, RCC_CR_PLLON); 119 | _WBS(RCC->CR, RCC_CR_PLLRDY); 120 | /* switch to PLL */ 121 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 122 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 123 | 124 | /* Enabling USB PA11 PA12 AF 0x0E. 125 | * This is still undocumented in the 7th!! revision of the datasheet. 126 | * Thank you, mo***rs from ST for extra 5 hrs of debugging. 127 | */ 128 | _BST(RCC->AHBENR, RCC_AHBENR_GPIOAEN); 129 | _BST(GPIOA->AFR[1], (0x0E << 12) | (0x0E << 16)); 130 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); // MCO 131 | 132 | 133 | #elif defined(STM32F429xx) || defined(STM32F405xx) \ 134 | || defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) 135 | /* set flash latency 2WS */ 136 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_2WS); 137 | /* setting up PLL 16MHz HSI, VCO=144MHz, PLLP = 72MHz PLLQ = 48MHz */ 138 | _BMD(RCC->PLLCFGR, 139 | RCC_PLLCFGR_PLLM | RCC_PLLCFGR_PLLN | RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLQ | RCC_PLLCFGR_PLLP, 140 | _VAL2FLD(RCC_PLLCFGR_PLLM, 8) | _VAL2FLD(RCC_PLLCFGR_PLLN, 72) | _VAL2FLD(RCC_PLLCFGR_PLLQ, 3)); 141 | /* enabling PLL */ 142 | _BST(RCC->CR, RCC_CR_PLLON); 143 | _WBS(RCC->CR, RCC_CR_PLLRDY); 144 | /* Setup CFGR to PLL*/ 145 | /* APB1 | APB2 */ 146 | /* STM32F411 <50Mhz | <100MHz */ 147 | /* STM32F429 <45MHz | <90MHz */ 148 | /* STM32F405, STM32F401 <42MHz | <84MHz */ 149 | _BMD(RCC->CFGR, RCC_CFGR_SW | RCC_CFGR_PPRE1, RCC_CFGR_SW_PLL | RCC_CFGR_PPRE1_DIV2); 150 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 151 | #if defined(USBD_PRIMARY_OTGHS) 152 | /* enabling GPIOB and setting PB13, PB14 and PB15 to AF11 (USB_OTG2FS) */ 153 | _BST(RCC->AHB1ENR, RCC_AHB1ENR_GPIOBEN); 154 | #if defined(USBD_VBUS_DETECT) 155 | _BST(GPIOB->AFR[1], (0x0C << 24) | (0x0C << 28) | (0x0C << 20)); 156 | _BMD(GPIOB->MODER, (0x03 << 28) | (0x03 << 30) | (0x03 << 26), (0x02 << 28) | (0x02 << 30) | (0x02 << 26)); 157 | #else //defined(USBD_VBUS_DETECT) 158 | _BST(GPIOB->AFR[1], (0x0C << 24) | (0x0C << 28)); 159 | _BMD(GPIOB->MODER, (0x03 << 28) | (0x03 << 30), (0x02 << 28) | (0x02 << 30)); 160 | #endif //defined(USBD_VBUS_DETECT) 161 | #else //defined(USBD_PRIMARY_OTGHS) 162 | /* enabling GPIOA and setting PA11 and PA12 to AF10 (USB_FS) */ 163 | _BST(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN); 164 | _BST(GPIOA->AFR[1], (0x0A << 12) | (0x0A << 16)); 165 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); 166 | #endif //defined(USBD_PRIMARY_OTGHS) 167 | 168 | #elif defined(STM32F446xx) || defined(STM32F745xx) 169 | /* set flash latency 2WS */ 170 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_2WS); 171 | /* setting up PLL 16MHz HSI, VCO=144MHz, PLLP = 72MHz PLLQ = 48MHz */ 172 | _BMD(RCC->PLLCFGR, 173 | RCC_PLLCFGR_PLLM | RCC_PLLCFGR_PLLN | RCC_PLLCFGR_PLLP | RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLQ, 174 | _VAL2FLD(RCC_PLLCFGR_PLLM, 8) | _VAL2FLD(RCC_PLLCFGR_PLLN, 72) | _VAL2FLD(RCC_PLLCFGR_PLLQ, 3)); 175 | /* enabling PLL */ 176 | _BST(RCC->CR, RCC_CR_PLLON); 177 | _WBS(RCC->CR, RCC_CR_PLLRDY); 178 | /* switching to PLL */ 179 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 180 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 181 | /* enabling GPIOA and setting PA11 and PA12 to AF10 (USB_FS) */ 182 | #if defined(USBD_PRIMARY_OTGHS) 183 | _BST(RCC->AHB1ENR, RCC_AHB1ENR_GPIOBEN); 184 | _BST(GPIOB->AFR[1], (0x0C << 24) | (0x0C << 28)); 185 | _BMD(GPIOB->MODER, (0x03 << 28) | (0x03 << 30), (0x02 << 28) | (0x02 << 30)); 186 | #else 187 | _BST(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN); 188 | _BST(GPIOA->AFR[1], (0x0A << 12) | (0x0A << 16)); 189 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); 190 | #endif 191 | 192 | #elif defined(STM32F105xC) || defined(STM32F107xC) 193 | _BST(RCC->CR, RCC_CR_HSION); 194 | _WBS(RCC->CR, RCC_CR_HSIRDY); 195 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_HSI); 196 | _BMD(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_HSI); 197 | /* set flash latency 1WS */ 198 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_1); 199 | 200 | _BST(RCC->CR, RCC_CR_HSEON); 201 | _WBS(RCC->CR, RCC_CR_HSERDY); 202 | 203 | /* switch to HSE */ 204 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_HSE); 205 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_HSE); 206 | 207 | #if defined(HSE_25MHZ) 208 | RCC->CFGR = RCC_CFGR_PLLMULL9 | RCC_CFGR_PLLSRC | \ 209 | RCC_CFGR_ADCPRE_DIV8 | RCC_CFGR_PPRE2_DIV1 | \ 210 | RCC_CFGR_PPRE1_DIV2 | RCC_CFGR_HPRE_DIV1 | \ 211 | RCC_CFGR_OTGFSPRE*0; 212 | /* PREDIV1SRC= PLL2, PLL2MUL = 8, PREDIV1 = 5, PREDIV2=5 */ 213 | RCC->CFGR2 = RCC_CFGR2_PREDIV1SRC | RCC_CFGR2_PLL2MUL8 | \ 214 | RCC_CFGR2_PREDIV1_DIV5 | RCC_CFGR2_PREDIV2_DIV5; 215 | 216 | _BST(RCC->CR, RCC_CR_PLL2ON); 217 | _WBS(RCC->CR, RCC_CR_PLL2RDY); 218 | 219 | _BST(RCC->CR, RCC_CR_PLLON); 220 | _WBS(RCC->CR, RCC_CR_PLLRDY); 221 | #else 222 | RCC->CFGR = RCC_CFGR_PLLMULL9 | RCC_CFGR_PLLSRC | RCC_CFGR_ADCPRE_DIV8 | \ 223 | RCC_CFGR_PPRE2_DIV1 | RCC_CFGR_PPRE1_DIV2 | RCC_CFGR_HPRE_DIV1; 224 | _BMD(RCC->CFGR2, RCC_CFGR2_PREDIV1, RCC_CFGR2_PREDIV1_DIV1); 225 | _BCL(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC); 226 | _BST(RCC->CR, RCC_CR_PLLON); 227 | _WBS(RCC->CR, RCC_CR_PLLRDY); 228 | #endif 229 | 230 | RCC->CFGR |= RCC_CFGR_MCO_PLLCLK_DIV2; 231 | 232 | /* set flash latency 2WS */ 233 | _BMD(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_2); 234 | /* switch to PLL */ 235 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 236 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 237 | #elif defined(STM32L433xx) 238 | /* using HSI16 as AHB/CPU clock, HSI48 as USB PHY clock */ 239 | _BST(RCC->CR, RCC_CR_HSION); 240 | _WBS(RCC->CR, RCC_CR_HSIRDY); 241 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_HSI); 242 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_HSI); 243 | _BST(RCC->CRRCR, RCC_CRRCR_HSI48ON); 244 | _WBS(RCC->CRRCR, RCC_CRRCR_HSI48RDY); 245 | _BMD(RCC->CCIPR, RCC_CCIPR_CLK48SEL, 0); 246 | /* setup PA11 PA12 to AF10 (USB FS) */ 247 | _BST(RCC->AHB2ENR, RCC_AHB2ENR_GPIOAEN); 248 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); 249 | _BST(GPIOA->AFR[1], (0x0A << 12) | (0x0A << 16)); 250 | /* Disabling USB Vddusb power isolation. Vusb connected to Vdd */ 251 | _BST(RCC->APB1ENR1, RCC_APB1ENR1_PWREN); 252 | _BST(PWR->CR2, PWR_CR2_USV); 253 | #elif defined(STM32F070xB) 254 | /* set flash latency 1WS */ 255 | _BST(FLASH->ACR, FLASH_ACR_LATENCY); 256 | /* use PLL 48MHz clock from 8Mhz HSI */ 257 | _BMD(RCC->CFGR, 258 | RCC_CFGR_PLLMUL | RCC_CFGR_PLLSRC | RCC_CFGR_USBPRE, 259 | RCC_CFGR_PLLMUL12 | RCC_CFGR_USBPRE); 260 | _BST(RCC->CR, RCC_CR_PLLON); 261 | _WBS(RCC->CR, RCC_CR_PLLRDY); 262 | /* switch to PLL */ 263 | _BMD(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); 264 | _WVL(RCC->CFGR, RCC_CFGR_SWS, RCC_CFGR_SWS_PLL); 265 | _BST(RCC->CFGR3, RCC_CFGR3_USBSW_PLLCLK); 266 | #elif defined(STM32F042x6) 267 | /* set flash latency 1WS */ 268 | _BST(FLASH->ACR, FLASH_ACR_LATENCY); 269 | /* use HSI48 as clock incl. USB PHY clock, no PLL */ 270 | _BST(RCC->CR2, RCC_CR2_HSI48ON); 271 | _WBS(RCC->CR2, RCC_CR2_HSI48RDY); 272 | #elif defined(STM32G4) 273 | /* using HSI16 as AHB/CPU clock, HSI48 as USB PHY clock */ 274 | _BST(RCC->CRRCR, RCC_CRRCR_HSI48ON); 275 | _WBS(RCC->CRRCR, RCC_CRRCR_HSI48RDY); 276 | #elif defined(STM32WB55xx) 277 | /* using HSI16 as AHB/CPU clock, HSI48 as USB PHY clock */ 278 | _BST(RCC->CR, RCC_CR_HSION); 279 | _WBS(RCC->CR, RCC_CR_HSIRDY); 280 | _BMD(RCC->CFGR, RCC_CFGR_SW, (0x01UL << RCC_CFGR_SW_Pos)); // HSI16 281 | _WVL(RCC->CFGR, RCC_CFGR_SWS, (0x01UL << RCC_CFGR_SWS_Pos)); 282 | _BST(RCC->CRRCR, RCC_CRRCR_HSI48ON); 283 | _WBS(RCC->CRRCR, RCC_CRRCR_HSI48RDY); 284 | _BMD(RCC->CCIPR, RCC_CCIPR_CLK48SEL, 0); 285 | /* setup PA11 PA12 to AF10 (USB FS) */ 286 | _BST(RCC->AHB2ENR, RCC_AHB2ENR_GPIOAEN); 287 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); 288 | _BST(GPIOA->AFR[1], (0x0A << 12) | (0x0A << 16)); 289 | /* Disabling USB Vddusb power isolation. Vusb connected to Vdd */ 290 | _BST(PWR->CR2, PWR_CR2_USV); 291 | #elif defined(STM32H743xx) 292 | /* Enable USB supply */ 293 | _BST(PWR->CR3, PWR_CR3_SCUEN | PWR_CR3_LDOEN | PWR_CR3_USB33DEN); 294 | 295 | /* Enable HSI48 and use as USB PHY clock */ 296 | _BST(RCC->CR, RCC_CR_HSI48ON); 297 | _WBS(RCC->CR, RCC_CR_HSI48RDY); 298 | _BMD(RCC->D2CCIP2R, RCC_D2CCIP2R_USBSEL, 3 << RCC_D2CCIP2R_USBSEL_Pos); 299 | 300 | /* enabling GPIOA and setting PA11 and PA12 to AF10 (USB_FS) */ 301 | _BST(RCC->AHB4ENR, RCC_AHB4ENR_GPIOAEN); 302 | _BMD(GPIOA->MODER, (0x03 << 22) | (0x03 << 24), (0x02 << 22) | (0x02 << 24)); 303 | _BST(GPIOA->AFR[1], (0x0A << 12) | (0x0A << 16)); 304 | #else 305 | #error Not supported 306 | #endif 307 | } 308 | 309 | void __libc_init_array(void) { 310 | 311 | } 312 | 313 | void SystemInit(void) { 314 | cdc_init_rcc(); 315 | } 316 | -------------------------------------------------------------------------------- /demo/sections.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : 4 | { 5 | KEEP(*(.isr_vector)) 6 | *(.text*) 7 | KEEP(*(.init)) KEEP(*(.fini)) 8 | *crtbegin.o(.ctors) 9 | *crtbegin?.o(.ctors) 10 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) 11 | *(SORT(.ctors.*)) 12 | *(.ctors) 13 | *crtbegin.o(.dtors) 14 | *crtbegin?.o(.dtors) 15 | *(EXCLUDE_FILE(*crtend?.o *crtend.o).dtors) 16 | *(SORT(.dtors.*)) 17 | *(.dtors) 18 | *(.rodata*) 19 | KEEP(*(.eh_frame*)) 20 | } > ROM 21 | .ARM.extab : 22 | { 23 | *(.ARM.extab* .gnu.linkonce.armextab.*) 24 | } > ROM 25 | __exidx_start = .; 26 | .ARM.exidx : 27 | { 28 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 29 | } > ROM 30 | __exidx_end = .; 31 | __etext = .; 32 | .data : AT (__etext) 33 | { 34 | __data_start__ = .; 35 | *(vtable) 36 | *(.data*) 37 | . = ALIGN(4); 38 | PROVIDE_HIDDEN (__preinit_array_start = .); 39 | KEEP(*(.preinit_array)) 40 | PROVIDE_HIDDEN (__preinit_array_end = .); 41 | . = ALIGN(4); 42 | PROVIDE_HIDDEN (__init_array_start = .); 43 | KEEP(*(SORT(.init_array.*))) 44 | KEEP(*(.init_array)) 45 | PROVIDE_HIDDEN (__init_array_end = .); 46 | . = ALIGN(4); 47 | PROVIDE_HIDDEN (__fini_array_start = .); 48 | KEEP(*(SORT(.fini_array.*))) 49 | KEEP(*(.fini_array)) 50 | PROVIDE_HIDDEN (__fini_array_end = .); 51 | . = ALIGN(4); 52 | __data_end__ = .; 53 | } > RAM 54 | .bss (NOLOAD) : 55 | { 56 | __bss_start__ = .; 57 | *(.bss*) 58 | *(COMMON) 59 | __bss_end__ = .; 60 | } > RAM 61 | .heap (NOLOAD) : 62 | { 63 | __end__ = .; 64 | *(.heap*) 65 | __HeapLimit = .; 66 | } > RAM 67 | .stack_dummy (NOLOAD) : 68 | { 69 | *(.stack) 70 | } > RAM 71 | __StackTop = ORIGIN(RAM) + LENGTH(RAM); 72 | __StackLimit = __StackTop - SIZEOF(.stack_dummy); 73 | PROVIDE(__stack = __StackTop); 74 | ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") 75 | PROVIDE(_estack = __stack); 76 | PROVIDE(_sidata = __etext); 77 | PROVIDE(_sdata = __data_start__); 78 | PROVIDE(_edata = __data_end__); 79 | PROVIDE(_sbss = __bss_start__); 80 | PROVIDE(_ebss = __bss_end__); 81 | } 82 | -------------------------------------------------------------------------------- /demo/stm32f042x6.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 32K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 6K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f070xb.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 128K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 16K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f103x6.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 32K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 10K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f105xb.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 128K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 64K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f303xc.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 256K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 40K 6 | CCMRAM (rwx): ORIGIN = 0x10000000, LENGTH = 8K 7 | } 8 | 9 | INCLUDE sections.ld 10 | -------------------------------------------------------------------------------- /demo/stm32f303xe.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 512K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 64K 6 | CCMRAM (rwx): ORIGIN = 0x10000000, LENGTH = 16K 7 | } 8 | 9 | INCLUDE sections.ld 10 | -------------------------------------------------------------------------------- /demo/stm32f373xc.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 256K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 32K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f401xc.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 256K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 64K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f401xe.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 512K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 96K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f405xg.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 1024K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 128K 6 | RAM2 (rwx): ORIGIN = 0x10000000, LENGTH = 64K 7 | } 8 | 9 | INCLUDE sections.ld 10 | -------------------------------------------------------------------------------- /demo/stm32f429xi.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 2048K 5 | BANK0 (rx): ORIGIN = 0x08000000, LENGTH = 1024K 6 | BANK1 (rx): ORIGIN = 0x08100000, LENGTH = 1024K 7 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 192K 8 | SRAM1 (rwx): ORIGIN = 0x20000000, LENGTH = 112K 9 | SRAM2 (rwx): ORIGIN = 0x2001C000, LENGTH = 16K 10 | SRAM3 (rwx): ORIGIN = 0x20020000, LENGTH = 64K 11 | CMRAM (rwx): ORIGIN = 0x10000000, LENGTH = 64K 12 | } 13 | 14 | INCLUDE sections.ld 15 | -------------------------------------------------------------------------------- /demo/stm32f446xc.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 256K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 128K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32f745xe.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 512K 5 | ITCM (rwx): ORIGIN = 0x00000000, LENGTH = 16K 6 | DTCM (rw): ORIGIN = 0x20000000, LENGTH = 64K 7 | RAM (rwx): ORIGIN = 0x20010000, LENGTH = 240K 8 | RAM2 (rwx): ORIGIN = 0x2004C000, LENGTH = 16K 9 | } 10 | 11 | INCLUDE sections.ld 12 | -------------------------------------------------------------------------------- /demo/stm32g431xb.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 128K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 22K 6 | SRAM (rwx): ORIGIN = 0x10000000, LENGTH = 10K 7 | } 8 | 9 | INCLUDE sections.ld 10 | -------------------------------------------------------------------------------- /demo/stm32h743xx.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 1024K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 128K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32l052x8.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 64K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 8K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32l100xc.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 192K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 20K 6 | } 7 | 8 | INCLUDE sections.ld 9 | -------------------------------------------------------------------------------- /demo/stm32l433xc.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 256K 5 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 48K 6 | SRAM (rwx): ORIGIN = 0x10000000, LENGTH = 16K 7 | } 8 | 9 | INCLUDE sections.ld 10 | -------------------------------------------------------------------------------- /demo/stm32l476xg.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 1024K 5 | BANK0 (rx): ORIGIN = 0x08000000, LENGTH = 512K 6 | BANK1 (rx): ORIGIN = 0x08080000, LENGTH = 512K 7 | RAM (rwx): ORIGIN = 0x20000000, LENGTH = 96K 8 | RAM2 (rwx): ORIGIN = 0x10000000, LENGTH = 32K 9 | } 10 | 11 | INCLUDE sections.ld 12 | -------------------------------------------------------------------------------- /demo/stm32wb55xg.ld: -------------------------------------------------------------------------------- 1 | ENTRY(Reset_Handler) 2 | MEMORY 3 | { 4 | ROM (rx): ORIGIN = 0x08000000, LENGTH = 1024K 5 | RAM (rwx): ORIGIN = 0x20000008, LENGTH = 0x2fff8 6 | RAM_SHARED (xrw) : ORIGIN = 0x20030000, LENGTH = 10K 7 | } 8 | 9 | SECTIONS 10 | { 11 | MAPPING_TABLE (NOLOAD) : { *(MAPPING_TABLE) } >RAM_SHARED 12 | MB_MEM1 (NOLOAD) : { *(MB_MEM1) } >RAM_SHARED 13 | MB_MEM2 (NOLOAD) : { _sMB_MEM2 = . ; *(MB_MEM2) ; _eMB_MEM2 = . ; } >RAM_SHARED 14 | } 15 | 16 | INCLUDE sections.ld 17 | -------------------------------------------------------------------------------- /hardware.md: -------------------------------------------------------------------------------- 1 | ## HARDWARE 2 | 3 | | Target | Board | Notes | 4 | |----------------|----------------------------|---------------------------------------------| 5 | | stm32f103x6 | bluepill | | 6 | | stm32f103x6 | bluepill with GD32F103C8T6 | | 7 | | stm32f303xe | NUCLEO-F303RE + NUCLEO2USB | | 8 | | stm32f105xb | NUCLEO-F105RB + NUCLEO2USB | based on NUCLEO-F103RE, direct replacement | 9 | | stm32l052x8 | DIY board | | 10 | | stm32l100xc | STM32L100C-DISCO | | 11 | | stm32l476xg | NUCLEO-L476RG + NUCLEO2USB | | 12 | | stm32f429xi | NUCLEO-F429ZI | | 13 | | stm32f429xi_hs | NUCLEO-F429ZI | | 14 | | stm32l433cc | bluepill with STM32L433CC | direct replacement, R10 removed | 15 | | stm32f070xb | bluepill with STM32F070CB | direct replacement, R10 removed | 16 | | stm32g431xb | NUCLEO-G431RB + NUCLEO2USB | | 17 | | stm32f446xc | NUCLEO-F446RE + NUCLEO2USB | | 18 | | stm32f446xc_hs | NUCLEO-F446RE + NUCLEO2USB | | 19 | | stm32f373xc | bluepill with STM32F373CC | 2 cuts + 1 jumper wire | 20 | | stm32l053x8 | NUCLEO-L053R8 + NUCLEO2USB | | 21 | | stm32f405xg | NUCLEO-F405RG + NUCLEO2USB | based on NUCLEO-F103RE, 0.1uF at SB33, SB38 | 22 | | stm32f405xg_hs | NUCLEO-F405RG + NUCLEO2USB | based on NUCLEO-F103RE, 0.1uF at SB33, SB38 | 23 | | stm32f745xe | NUCO-V-F745VE + NUCLEO2USB | | 24 | | stm32f401xe | WeAct STM32F401CEU6 | | 25 | | stm32h743vt | Boring Tech STM32H743 | USB 5v connected to A9 | 26 | 27 | [NUCLEO2USB SHIELD](https://github.com/dmitrystu/Nucleo2USB) 28 | [NUCO-V](https://github.com/dmitrystu/nuco-v) 29 | -------------------------------------------------------------------------------- /inc/hid_usage_button.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_BUTTON_H_ 17 | #define _USB_HID_USAGE_BUTTON_H_ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | 23 | /**\ingroup USB_HID 24 | * \addtogroup USB_HID_USAGES_BUTTON HID Usage Tables for Button 25 | * \brief Contains USB HID Usages definitions for Button Page 26 | * \details This module based on 27 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 28 | * @{ */ 29 | 30 | #define HID_PAGE_BUTTON 0x09 /**<\brief HID usage page for Buttons */ 31 | 32 | #define HID_BUTTON_NO_PRESSED 0x00 /**<\brief No button pressed */ 33 | #define HID_BUTTON_1 0x01 /**<\brief Button 1 pressed */ 34 | #define HID_BUTTON_2 0x02 /**<\brief Button 2 pressed */ 35 | #define HID_BUTTON_3 0x03 /**<\brief Button 3 pressed */ 36 | #define HID_BUTTON_4 0x04 /**<\brief Button 4 pressed */ 37 | #define HID_BUTTON_5 0x05 /**<\brief Button 5 pressed */ 38 | 39 | /** @} */ 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /inc/hid_usage_desktop.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_DESKTOP_H_ 17 | #define _USB_HID_USAGE_DESKTOP_H_ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | 23 | /**\ingroup USB_HID 24 | * \addtogroup USB_HID_USAGES_DESKTOP HID Usage Tables for Desktop 25 | * \brief Contains USB HID Usages definitions for Generic Desktop Page 26 | * \details This module based on 27 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 28 | * @{ */ 29 | 30 | #define HID_PAGE_DESKTOP 0x01 /**<\brief Desktop usage page.*/ 31 | 32 | /**\name Application Usages 33 | * @{ */ 34 | #define HID_DESKTOP_POINTER 0x01 /**<\brief CP Pointer control.*/ 35 | #define HID_DESKTOP_MOUSE 0x02 /**<\brief CA Mouse.*/ 36 | #define HID_DESKTOP_JOYSTICK 0x04 /**<\brief CA Joystick.*/ 37 | #define HID_DESKTOP_GAMEPAD 0x05 /**<\brief CA Gamepad.*/ 38 | #define HID_DESKTOP_KEYBOARD 0x06 /**<\brief CA Keybiard.*/ 39 | #define HID_DESKTOP_KEYPAD 0x07 /**<\brief CA Keypad.*/ 40 | #define HID_DESKTOP_MULTIAXIS 0x08 /**<\brief CA 3D input device.*/ 41 | #define HID_DESKTOP_TABLET 0x09 /**<\brief CA System controls on Tablet PCs.*/ 42 | /** @} */ 43 | 44 | /**\name Axis Usages 45 | * @{ */ 46 | #define HID_DESKTOP_X 0x30 /**<\brief DV Linear translation in the X direction.*/ 47 | #define HID_DESKTOP_Y 0x31 /**<\brief DV Linear translation in the Y direction.*/ 48 | #define HID_DESKTOP_Z 0x32 /**<\brief DV Linear translation in the Z direction.*/ 49 | #define HID_DESKTOP_RX 0x33 /**<\brief DV Rotation about X axis.*/ 50 | #define HID_DESKTOP_RY 0x34 /**<\brief DV Rotation about Y axis.*/ 51 | #define HID_DESKTOP_RZ 0x35 /**<\brief DV Rotation about Z axis.*/ 52 | /** @} */ 53 | 54 | /**\name Miscellaneous Controls 55 | * @{ */ 56 | #define HID_DESKTOP_SLIDER 0x36 /**<\brief DV Linear control for a variable value.*/ 57 | #define HID_DESKTOP_DIAL 0x37 /**<\brief DV Rotary control for a variable value.*/ 58 | #define HID_DESKTOP_WHEEL 0x38 /**<\brief DV Rotary control for a variable value.*/ 59 | #define HID_DESKTOP_HAT_SWITCH 0x39 /**<\brief DV A specialized mechanical configuration of 60 | * switches generating a variable value with a null state.*/ 61 | #define HID_DESKTOP_MOTION_WAKEUP 0x3C /**<\brief DF Enables the generation of a USB remote 62 | * wakeup when the device detects motion.*/ 63 | #define HID_DESKTOP_START 0x3D /**<\brief OOC Session start button.*/ 64 | #define HID_DESKTOP_SELECT 0x3E /**<\brief OOC Application option select button.*/ 65 | #define HID_DESKTOP_RESOLUTION_MULT 0x48 /**<\brief DV Resolution Multiplier for a Control.*/ 66 | /** @} */ 67 | 68 | /**\name Vector Usages 69 | * @{ */ 70 | #define HID_DESKTOP_VX 0x40 /**<\brief DV Vector in the X direction.*/ 71 | #define HID_DESKTOP_VY 0x41 /**<\brief DV Vector in the Y direction.*/ 72 | #define HID_DESKTOP_VZ 0x42 /**<\brief DV Vector in the Z direction.*/ 73 | #define HID_DESKTOP_VBRX 0x43 /**<\brief DV Relative Vector in the X direction.*/ 74 | #define HID_DESKTOP_VBRY 0x44 /**<\brief DV Relative vector in the Y direction.*/ 75 | #define HID_DESKTOP_VBRZ 0x45 /**<\brief DV Relative vector in the Z direction.*/ 76 | #define HID_DESKTOP_VNO 0x46 /**<\brief DV A non oriented vector or value.*/ 77 | /** @} */ 78 | 79 | /**\name System Controls 80 | * @{ */ 81 | #define HID_DESKTOP_SYS_CONTROL 0x80 /**<\brief CA Application-level collection.*/ 82 | #define HID_DESKTOP_SYS_CONTEXT_MNU 0x84 /**<\brief OSC Evokes a context-sensitive menu.*/ 83 | #define HID_DESKTOP_SYS_MAIN_MNU 0x85 /**<\brief OSC Evokes the OS main-level selection menu.*/ 84 | #define HID_DESKTOP_SYS_APP_MNU 0x86 /**<\brief OSC Displays an application-specific menu.*/ 85 | #define HID_DESKTOP_SYS_MENU_HELP 0x87 /**<\brief OSC Displays the help menu.*/ 86 | #define HID_DESKTOP_SYS_MENU_EXIT 0x88 /**<\brief OSC Exits a menu.*/ 87 | #define HID_DESKTOP_SYS_MENU_SELECT 0x89 /**<\brief OSC Selects a menu item.*/ 88 | #define HID_DESKTOP_SYS_MENU_RIGHT 0x8A /**<\brief RTC Menu select right.*/ 89 | #define HID_DESKTOP_SYS_MENU_LEFT 0x8B /**<\brief RTC Menu select left.*/ 90 | #define HID_DESKTOP_SYS_MENU_UP 0x8C /**<\brief RTC Menu select up.*/ 91 | #define HID_DESKTOP_SYS_MENU_DOWN 0x8D /**<\brief RTC Menu select down.*/ 92 | /** @} */ 93 | 94 | /**\name Power Controls 95 | * @{ */ 96 | #define HID_DESKTOP_SYS_PWR_DOWN 0x81 /**<\brief OSC Power down control.*/ 97 | #define HID_DESKTOP_SYS_SLEEP 0x82 /**<\brief OSC Sleep control.*/ 98 | #define HID_DESKTOP_SYS_WAKEUP 0x83 /**<\brief OSC Wakeup control.*/ 99 | #define HID_DESKTOP_SYS_RST_COLD 0x8E /**<\brief OSC Cold restart control.*/ 100 | #define HID_DESKTOP_SYS_RST_WARM 0x8F /**<\brief OSC Warm restart control.*/ 101 | #define HID_DESKTOP_SYS_DOCK 0xA0 /**<\brief OSC Prepare for docking.*/ 102 | #define HID_DESKTOP_SYS_UNDOCK 0xA1 /**<\brief OSC Prepare for undocking. */ 103 | #define HID_DESKTOP_SYS_SETUP 0xA2 /**<\brief OSC Enter to BIOS-level setup.*/ 104 | #define HID_DESKTOP_SYS_SPKR_MUTE 0xA7 /**<\brief OSC Mute system speakers.*/ 105 | #define HID_DESKTOP_SYS_HIBERNATE 0xA8 /**<\brief OSC System hibernate control.*/ 106 | /** @} */ 107 | 108 | /**\name Buffered Bytes 109 | * @{ */ 110 | #define HID_DESKTOP_COUNTEDBUF 0x3A /**<\brief CL Used with buffered byte data to indicate 111 | * the number of valid bytes in the buffered-byte field.*/ 112 | #define HID_DESKTOP_BYTECOUNT 0x3B /**<\brief DV Defines a report field that indicates the 113 | * number of meaningful data bytes in an associated 114 | * buffered-byte field.*/ 115 | /** @} */ 116 | 117 | /**\name Direction Pads 118 | * @{ */ 119 | #define HID_DESKTOP_DPAD_UP 0x90 /**<\brief OOC Top of a Direction Pad is pressed.*/ 120 | #define HID_DESKTOP_DPAD_DOWN 0x91 /**<\brief OOC Bottom of a Direction Pad is pressed.*/ 121 | #define HID_DESKTOP_DPAD_RIGHT 0x92 /**<\brief OOC Right side of a Direction Pad is pressed.*/ 122 | #define HID_DESKTOP_DPAD_LEFT 0x93 /**<\brief OOC Left side of a Direction Pad is pressed.*/ 123 | /** @} */ 124 | 125 | /**\name Feature Notifications 126 | * @{ */ 127 | #define HID_DESKTOP_FEATURE_NOTIFY 0x47 /**<\brief DV This usage is declared in an Input report 128 | * and is used as a notification to the host that the 129 | * contents of a specific Feature report has changed.*/ 130 | /** @} */ 131 | 132 | /**\name Software Flow Control 133 | * @{ */ 134 | #define HID_DESKTOP_SYS_BREAK 0xA3 /**<\brief OSC System break control.*/ 135 | #define HID_DESKTOP_SYS_DBG_BREAK 0xA4 /**<\brief OSC System debugger break control.*/ 136 | #define HID_DESKTOP_APP_BREAK 0xA5 /**<\brief OSC Application break control.*/ 137 | #define HID_DESKTOP_APP_DBG_BREAK 0xA6 /**<\brief OSC Application debugger break control.*/ 138 | /** @} */ 139 | 140 | /**\name System Display Control 141 | * @{ */ 142 | #define HID_DESKTOP_SYS_DISP_INVERT 0xB0 /**<\brief OSC Set display to render in inverted colors.*/ 143 | #define HID_DESKTOP_SYS_DISP_INT 0xB1 /**<\brief OSC Set the captive display as the primary display.*/ 144 | #define HID_DESKTOP_SYS_DISP_EXT 0xB2 /**<\brief OSC Set the external display as the primary display.*/ 145 | #define HID_DESKTOP_SYS_DISP_BOTH 0xB3 /**<\brief OSC Use both internal and external displays 146 | * as primary diaplay.*/ 147 | #define HID_DESKTOP_SYS_DISP_DUAL 0xB4 /**<\brief OSC Use both internal and external displays 148 | * as primary and secondary diaplays.*/ 149 | #define HID_DESKTOP_SYS_DISP_TGL 0xB5 /**<\brief OSC Toggles internal/external/both displays.*/ 150 | #define HID_DESKTOP_SYS_DISP_SWAP 0xB6 /**<\brief OSC Swap primary/secondary displays.*/ 151 | #define HID_DESKTOP_SYS_DISP_AUTO 0xB7 /**<\brief OCS Toggles LCD autoscale.*/ 152 | 153 | /** @} */ 154 | /** @} */ 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | 160 | #endif 161 | 162 | -------------------------------------------------------------------------------- /inc/hid_usage_device.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_DEVICE_H_ 17 | #define _USB_HID_USAGE_DEVICE_H_ 18 | 19 | /**\ingroup USB_HID 20 | * \addtogroup USB_HID_USAGES_DEVICE HID Usages for Device 21 | * \brief Contains USB HID Usages definitions for Generic Device Control Page 22 | * \details This module based on 23 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 24 | * @{ */ 25 | #define HID_PAGE_DEVICE 0x06 /**<\brief Generic device control usage page.*/ 26 | #define HID_DEVICE_BATTERY_STRENGHT 0x20 /**<\brief DV Current battery status.*/ 27 | #define HID_DEVICE_WIRELESS_CHANNEL 0x21 /**<\brief DV Logical wireless channel.*/ 28 | #define HID_DEVICE_WIRELESS_ID 0x22 /**<\brief DV Unique wireless device ID.*/ 29 | #define HID_DEVICE_DISCO_WIRELESS_CTL 0x23 /**<\brief OSC Wirleless discover control.*/ 30 | #define HID_DEVICE_SECURITY_CHAR_ENT 0x24 /**<\brief OSC Code character entered.*/ 31 | #define HID_DEVICE_SECURITY_CHAR_ERA 0x25 /**<\brief OSC Code character erased.*/ 32 | #define HID_DEVICE_SCURITY_CODE_CLR 0x26 /**<\brief OSC Security code cleared.*/ 33 | /** @} */ 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /inc/hid_usage_game.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the LUS32 project 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_H_ 17 | #define _USB_HID_USAGE_H_ 18 | 19 | /**\ingroup USB_HID 20 | * \addtogroup USB_HID_USAGES_GAME HID Usage Tables for Game 21 | * \brief Contains USB HID Usages definitions for Game Controls Page 22 | * \details This module based on 23 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 24 | * @{ */ 25 | 26 | #define HID_PAGE_GAME 0x05 27 | 28 | #define HID_GAME_3D_GAME_CONTROLLER 0x01 29 | #define HID_GAME_PINBALL_DEVICE 0x02 30 | #define HID_GAME_GUN_DEVICE 0x03 31 | #define HID_GAME_POINT_OF_VIEW 0x20 32 | #define HID_GAME_TURN_LEFT_RIGHT 0x21 33 | #define HID_GAME_PITCH_FWD_BACK 0x22 34 | #define HID_GAME_ROLL_LEFT_RIGHT 0x23 35 | #define HID_GAME_MOVE_LEFT_RIGHT 0x24 36 | #define HID_GAME_MOVE_FWD_BACK 0x25 37 | #define HID_GAME_MOVE_UP_DOWN 0x26 38 | #define HID_GAME_LEAN_LEFT_RIGHT 0x27 39 | #define HID_GAME_LEAN_FWD_BACK 0x28 40 | #define HID_GAME_HEIGHT_OF_POV 0x29 41 | #define HID_GAME_FLIPPER 0x2A 42 | #define HID_GAME_SECONDARY_FLIPPER 0x2B 43 | #define HID_GAME_BUMP 0x2C 44 | #define HID_GAME_NEW_GAME 0x2D 45 | #define HID_GAME_SHOOT_BALL 0x2E 46 | #define HID_GAME_PLAYER 0x2F 47 | #define HID_GAME_GUN_BOLT 0x30 48 | #define HID_GAME_GUN_CLIP 0x31 49 | #define HID_GAME_GUN_SELECTOR 0x32 50 | #define HID_GAME_GUN_SINGLE_SHOT 0x33 51 | #define HID_GAME_GUN_BURST 0x34 52 | #define HID_GAME_GUN_AUTOMATIC 0x35 53 | #define HID_GAME_GUN_SAFETY 0x36 54 | #define HID_GAME_GANEPAD_FIRE_JUMP 0x37 55 | #define HID_GAME_GAMEPAD_TRIGGER 0x38 56 | /** @} */ 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /inc/hid_usage_keyboard.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_KEYBOARD_H_ 17 | #define _USB_HID_USAGE_KEYBOARD_H_ 18 | 19 | /**\ingroup USB_HID 20 | * \addtogroup USB_HID_USAGES_KEYBOARD HID Usages for Keyboard 21 | * \brief Contains USB HID Usages definitions for Keyboard/Keypad Page 22 | * \details This module based on 23 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 24 | * @{ */ 25 | 26 | #define HID_PAGE_KEYBOARD 0x07 27 | 28 | #define HID_KEYBOARD_ERR_ROLL_OVER 0x01 29 | #define HID_KEYBOARD_POST_FAIL 0x02 30 | #define HID_KEYBOARD_ERR_UNDEFINED 0x03 31 | #define HID_KEYBOARD_A 0x04 32 | #define HID_KEYBOARD_B 0x05 33 | #define HID_KEYBOARD_C 0x06 34 | #define HID_KEYBOARD_D 0x07 35 | #define HID_KEYBOARD_E 0x08 36 | #define HID_KEYBOARD_F 0x09 37 | #define HID_KEYBOARD_G 0x0A 38 | #define HID_KEYBOARD_H 0x0B 39 | #define HID_KEYBOARD_I 0x0C 40 | #define HID_KEYBOARD_J 0x0D 41 | #define HID_KEYBOARD_K 0x0E 42 | #define HID_KEYBOARD_L 0x0F 43 | #define HID_KEYBOARD_M 0x10 44 | #define HID_KEYBOARD_N 0x11 45 | #define HID_KEYBOARD_O 0x12 46 | #define HID_KEYBOARD_P 0x13 47 | #define HID_KEYBOARD_Q 0x14 48 | #define HID_KEYBOARD_R 0x15 49 | #define HID_KEYBOARD_S 0x16 50 | #define HID_KEYBOARD_T 0x17 51 | #define HID_KEYBOARD_U 0x18 52 | #define HID_KEYBOARD_V 0x19 53 | #define HID_KEYBOARD_W 0x1A 54 | #define HID_KEYBOARD_X 0x1B 55 | #define HID_KEYBOARD_Y 0x1C 56 | #define HID_KEYBOARD_Z 0x1D 57 | #define HID_KEYBOARD_1 0x1E 58 | #define HID_KEYBOARD_2 0x1F 59 | #define HID_KEYBOARD_3 0x20 60 | #define HID_KEYBOARD_4 0x21 61 | #define HID_KEYBOARD_5 0x22 62 | #define HID_KEYBOARD_6 0x23 63 | #define HID_KEYBOARD_7 0x24 64 | #define HID_KEYBOARD_8 0x25 65 | #define HID_KEYBOARD_9 0x26 66 | #define HID_KEYBOARD_0 0x27 67 | #define HID_KEYBOARD_RETURN 0x28 68 | #define HID_KEYBOARD_ESCAPE 0x29 69 | #define HID_KEYBOARD_DELETE 0x2A 70 | #define HID_KEYBOARD_TAB 0x2B 71 | #define HID_KEYBOARD_SPACEBAR 0x2C 72 | #define HID_KEYBOARD_MINUS 0x2D 73 | #define HID_KEYBOARD_EQUAL_SIGN 0x2E 74 | #define HID_KEYBOARD_OPEN_BRACKET 0x2F 75 | #define HID_KEYBOARD_CLOSE_BRACKET 0x30 76 | #define HID_KEYBOARD_BACKSLASH 0x31 77 | #define HID_KEYBOARD_NONUS_HASH 0x32 78 | #define HID_KEYBOARD_SEMICOLON 0x33 79 | #define HID_KEYBOARD_APOSTROPHE 0x34 80 | #define HID_KEYBOARD_GRAVE_ACCENT 0x35 81 | #define HID_KEYBOARD_COMMA 0x36 82 | #define HID_KEYBOARD_DOT 0x37 83 | #define HID_KEYBOARD_SLASH 0x38 84 | #define HID_KEYBOARD_CAPS_LOCK 0x39 85 | #define HID_KEYBOARD_F1 0x3A 86 | #define HID_KEYBOARD_F2 0x3B 87 | #define HID_KEYBOARD_F3 0x3C 88 | #define HID_KEYBOARD_F4 0x3D 89 | #define HID_KEYBOARD_F5 0x3E 90 | #define HID_KEYBOARD_F6 0x3F 91 | #define HID_KEYBOARD_F7 0x40 92 | #define HID_KEYBOARD_F8 0x41 93 | #define HID_KEYBOARD_F9 0x42 94 | #define HID_KEYBOARD_F10 0x43 95 | #define HID_KEYBOARD_F11 0x44 96 | #define HID_KEYBOARD_F12 0x45 97 | #define HID_KEYBOARD_PRINT_SCREEN 0x46 98 | #define HID_KEYBOARD_SCROLL_LOCK 0x47 99 | #define HID_KEYBOARD_PAUSE 0x48 100 | #define HID_KEYBOARD_INSERT 0x49 101 | #define HID_KEYBOARD_HOME 0x4A 102 | #define HID_KEYBOARD_PAGE_UP 0x4B 103 | #define HID_KEYBOARD_DELETE_FORWARD 0x4C 104 | #define HID_KEYBOARD_END 0x4D 105 | #define HID_KEYBOARD_PAGE_DOWN 0x4E 106 | #define HID_KEYBOARD_RIGHT_ARROW 0x4F 107 | #define HID_KEYBOARD_LEFT_ARROW 0x50 108 | #define HID_KEYBOARD_DOWN_ARROW 0x51 109 | #define HID_KEYBOARD_UP_ARROW 0x52 110 | #define HID_KEYPAD_NUMLOCK 0x53 111 | #define HID_KEYPAD_SLASH 0x54 112 | #define HID_KEYPAD_ASTERISK 0x55 113 | #define HID_KEYPAD_MINUS 0x56 114 | #define HID_KEYPAD_PLUS 0x57 115 | #define HID_KEYPAD_ENTER 0x58 116 | #define HID_KEYPAD_1 0x59 117 | #define HID_KEYPAD_2 0x5A 118 | #define HID_KEYPAD_3 0x5B 119 | #define HID_KEYPAD_4 0x5C 120 | #define HID_KEYPAD_5 0x5D 121 | #define HID_KEYPAD_6 0x5E 122 | #define HID_KEYPAD_7 0x5F 123 | #define HID_KEYPAD_8 0x60 124 | #define HID_KEYPAD_9 0x61 125 | #define HID_KEYPAD_0 0x62 126 | #define HID_KEYPAD_DOT 0x63 127 | #define HID_KEYBOARD_NONUS_BACKSLASH 0x64 128 | #define HID_KEYBOARD_APPLICATION 0x65 129 | #define HID_KEYBOARD_POWER 0x66 130 | #define HID_KEYPAD_EQUAL 0x67 131 | #define HID_KEYBOARD_F13 0x68 132 | #define HID_KEYBOARD_F14 0x69 133 | #define HID_KEYBOARD_F15 0x6A 134 | #define HID_KEYBOARD_F16 0x6B 135 | #define HID_KEYBOARD_F17 0x6C 136 | #define HID_KEYBOARD_F18 0x6D 137 | #define HID_KEYBOARD_F19 0x6E 138 | #define HID_KEYBOARD_F20 0x6F 139 | #define HID_KEYBOARD_F21 0x70 140 | #define HID_KEYBOARD_F22 0x71 141 | #define HID_KEYBOARD_F23 0x72 142 | #define HID_KEYBOARD_F24 0x73 143 | #define HID_KEYBOARD_EXECUTE 0x74 144 | #define HID_KEYBOARD_HELP 0x75 145 | #define HID_KEYBOARD_MENU 0x76 146 | #define HID_KEYBOARD_SELECT 0x77 147 | #define HID_KEYBOARD_STOP 0x78 148 | #define HID_KEYBOARD_AGAIN 0x79 149 | #define HID_KEYBOARD_UNDO 0x7A 150 | #define HID_KEYBOARD_CUT 0x7B 151 | #define HID_KEYBOARD_COPY 0x7C 152 | #define HID_KEYBOARD_PASTE 0x7D 153 | #define HID_KEYBOARD_FIND 0x7E 154 | #define HID_KEYBOARD_MUTE 0x7F 155 | #define HID_KEYBOARD_VOLUME_UP 0x80 156 | #define HID_KEYBOARD_VOLUME_DOWN 0x81 157 | #define HID_KEYBOARD_LOCK_CAPS_LOCK 0x82 158 | #define HID_KEYBOARD_LOCK_NUM_LOCK 0x83 159 | #define HID_KEYBOARD_LOCK_SCROLL_LOCK 0x84 160 | #define HID_KEYPAD_COMMA 0x85 161 | #define HID_KEYPAD_EQUAL_SIGN 0x86 162 | #define HID_KEYBOARD_INTERNATIONAL_1 0x87 163 | #define HID_KEYBOARD_INTERNATIONAL_2 0x88 164 | #define HID_KEYBOARD_INTERNATIONAL_3 0x89 165 | #define HID_KEYBOARD_INTERNATIONAL_4 0x8A 166 | #define HID_KEYBOARD_INTERNATIONAL_5 0x8B 167 | #define HID_KEYBOARD_INTERNATIONAL_6 0x8C 168 | #define HID_KEYBOARD_INTERNATIONAL_7 0x8D 169 | #define HID_KEYBOARD_INTERNATIONAL_8 0x8E 170 | #define HID_KEYBOARD_INTERNATIONAL_9 0x8F 171 | #define HID_KEYBOARD_LANG_1 0x90 172 | #define HID_KEYBOARD_LANG_2 0x91 173 | #define HID_KEYBOARD_LANG_3 0x92 174 | #define HID_KEYBOARD_LANG_4 0x93 175 | #define HID_KEYBOARD_LANG_5 0x94 176 | #define HID_KEYBOARD_LANG_6 0x95 177 | #define HID_KEYBOARD_LANG_7 0x96 178 | #define HID_KEYBOARD_LANG_8 0x97 179 | #define HID_KEYBOARD_LANG_9 0x98 180 | #define HID_KEYBOARD_ALTERNATE_ERASE 0x99 181 | #define HID_KEYBOARD_SYSREQ 0x9A 182 | #define HID_KEYBOARD_CANCEL 0x9B 183 | #define HID_KEYBOARD_CLEAR 0x9C 184 | #define HID_KEYBOARD_PRIOR 0x9D 185 | #define HID_KEYBOARD_RETURN_1 0x9E 186 | #define HID_KEYBOARD_SEPARATOR 0x9F 187 | #define HID_KEYBOARD_OUT 0xA0 188 | #define HID_KEYBOARD_OPER 0xA1 189 | #define HID_KEYBOARD_CLEAR_AGAIN 0xA2 190 | #define HID_KEYBOARD_CRSEL_PROPS 0xA3 191 | #define HID_KEYBOARD_EXSEL 0xA4 192 | #define HID_KEYPAD_00 0xB0 193 | #define HID_KEYPAD_000 0xB1 194 | #define HID_KEYPAD_OPEN_PARENTHESIS 0xB6 195 | #define HID_KEYPAD_CLOSE_PARENTHESIS 0xB7 196 | #define HID_KEYPAD_OPEN_BRACE 0xB8 197 | #define HID_KEYPAD_CLOSE_BRACE 0xB9 198 | #define HID_KEYPAD_TAB 0xBA 199 | #define HID_KEYPAD_BACKSPACE 0xBB 200 | #define HID_KEYPAD_A 0xBC 201 | #define HID_KEYPAD_B 0xBD 202 | #define HID_KEYPAD_C 0xBE 203 | #define HID_KEYPAD_D 0xBF 204 | #define HID_KEYPAD_E 0xC0 205 | #define HID_KEYPAD_F 0xC1 206 | #define HID_KEYPAD_XOR 0xC2 207 | #define HID_KEYPAD_CARET 0xC3 208 | #define HID_KEYPAD_PERCENT 0xC4 209 | #define HID_KEYPAD_LESS_THEN 0xC5 210 | #define HID_KEYPAD_GREATER_THEN 0xC6 211 | #define HID_KEYPAD_AMPERSAND 0xC7 212 | #define HID_KEYPAD_DOUBLE_AMPERSAND 0xC8 213 | #define HID_KEYPAD_PIPE 0xC9 214 | #define HID_KEYPAD_DOUBLE_PIPE 0xCA 215 | #define HID_KEYPAD_COLON 0xCB 216 | #define HID_KEYPAD_HASH 0xCC 217 | #define HID_KEYPAD_SPACE 0xCD 218 | #define HID_KEYPAD_AT 0xCE 219 | #define HID_KEYPAD_BANG 0xCF 220 | #define HID_KEYPAD_MEM_STORE 0xD0 221 | #define HID_KEYPAD_MEM_RECALL 0xD1 222 | #define HID_KEYPAD_MEM_CLEAR 0xD2 223 | #define HID_KEYPAD_MEM_ADD 0xD3 224 | #define HID_KEYPAD_MEM_SUBTRACT 0xD4 225 | #define HID_KEYPAD_MEM_MULTIPLY 0xD5 226 | #define HID_KEYPAD_MEM_DIVIDE 0xD6 227 | #define HID_KEYPAD_PLUS_MINUS 0xD7 228 | #define HID_KEYPAD_CLEAR 0xD8 229 | #define HID_KEYPAD_CLEAR_ENTRY 0xD9 230 | #define HID_KEYPAD_BINARY 0xDA 231 | #define HID_KEYPAD_OCTAL 0xDB 232 | #define HID_KEYPAD_DECIMAL 0xDC 233 | #define HID_KEYPAD_HEXADECIMAL 0xDD 234 | #define HID_KEYBOARD_L_CTRL 0xE0 235 | #define HID_KEYBOARD_L_SHIFT 0xE1 236 | #define HID_KEYBOARD_L_ALT 0xE2 237 | #define HID_KEYBOARD_L_GUI 0xE3 238 | #define HID_KEYBOARD_R_CTRL 0xE4 239 | #define HID_KEYBOARD_R_SHIFT 0xE5 240 | #define HID_KEYBOARD_R_ALT 0xE6 241 | #define HID_KEYBOARD_R_GUI 0xE7 242 | 243 | /** @} */ 244 | 245 | #endif 246 | 247 | -------------------------------------------------------------------------------- /inc/hid_usage_led.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the LUS32 project 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_LED_H_ 17 | #define _USB_HID_USAGE_LED_H_ 18 | 19 | /**\ingroup USB_HID 20 | * \addtogroup USB_HID_USAGES_LED HID Usages for LED's 21 | * \brief Contains USB HID Usages definitions for LED's Control Page 22 | * \details This module based on 23 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 24 | * @{ */ 25 | 26 | #define HID_PAGE_LED 0x08 27 | 28 | #define HID_LED_NUM_LOCK 0x01 29 | #define HID_LED_CAPS_LOCK 0x02 30 | #define HID_LED_SCROLL_LOCK 0x03 31 | #define HID_LED_COMPOSE 0x04 32 | #define HID_LED_KANA 0x05 33 | #define HID_LED_POWER 0x06 34 | #define HID_LED_SHIFT 0x07 35 | #define HID_LED_DO_NOT_DISTURB 0x08 36 | #define HID_LED_MUTE 0x09 37 | #define HID_LED_TONE_ENABLE 0x0A 38 | #define HID_LED_HIGH_CUT_FILTER 0x0B 39 | #define HID_LED_LOW_CUT_FILTER 0x0C 40 | #define HID_LED_EQUALIZER_ENABLE 0x0D 41 | #define HID_LED_SOUND_FIELD_ON 0x0E 42 | #define HID_LED_SURROUND_ON 0x0F 43 | #define HID_LED_REPEAT 0x10 44 | #define HID_LED_STEREO 0x11 45 | #define HID_LED_SAMPLING_RATE_DETECT 0x12 46 | #define HID_LED_SPINNING 0x13 47 | #define HID_LED_CAV 0x14 48 | #define HID_LED_CLV 0x15 49 | #define HID_LED_REC_FORMAT_DETECT 0x16 50 | #define HID_LED_OFF_HOOK 0x17 51 | #define HID_LED_RING 0x18 52 | #define HID_LED_MESSAGE_WAITING 0x19 53 | #define HID_LED_DATA_MODE 0x1A 54 | #define HID_LED_BATTERY_OPERATION 0x1B 55 | #define HID_LED_BATTERY_OK 0x1C 56 | #define HID_LED_BATTERY_LOW 0x1D 57 | #define HID_LED_SPEAKER 0x1E 58 | #define HID_LED_HEADSET 0x1F 59 | #define HID_LED_HOLD 0x20 60 | #define HID_LED_MICROPHONE 0x21 61 | #define HID_LED_COVERAGE 0x22 62 | #define HID_LED_NIGHT_MODE 0x23 63 | #define HID_LED_SEND_CALLS 0x24 64 | #define HID_LED_CALL_PICKUP 0x25 65 | #define HID_LED_CONFERENCE 0x26 66 | #define HID_LED_STANDBY 0x27 67 | #define HID_LED_CAMERA_ON 0x28 68 | #define HID_LED_CAMERA_OFF 0x29 69 | #define HID_LED_ONLINE 0x2A 70 | #define HID_LED_OFFLINE 0x2B 71 | #define HID_LED_BUSY 0x2C 72 | #define HID_LED_READY 0x2D 73 | #define HID_LED_PAPER_OUT 0x2E 74 | #define HID_LED_PAPER_JAM 0x2F 75 | #define HID_LED_REMOTE 0x30 76 | #define HID_LED_FORWARD 0x31 77 | #define HID_LED_REVERSE 0x32 78 | #define HID_LED_STOP 0x33 79 | #define HID_LED_REWIND 0x34 80 | #define HID_LED_FAST_FORWARD 0x35 81 | #define HID_LED_PLAY 0x36 82 | #define HID_LED_PAUSE 0x37 83 | #define HID_LED_RECORD 0x38 84 | #define HID_LED_ERROR 0x39 85 | #define HID_LED_USAGE_SELECTED_IND 0x3A 86 | #define HID_LED_USAGE_INUSE_IND 0x3B 87 | #define HID_LED_USAGE_MULTIMODE_IND 0x3C 88 | #define HID_LED_INDICATOR_ON 0x3D 89 | #define HID_LED_INDICATOR_FLASH 0x3E 90 | #define HID_LED_INDICATOR_SLOW_BLINK 0x3F 91 | #define HID_LED_INDICATOR_FAST_BLINK 0x40 92 | #define HID_LED_INDICATOR_OFF 0x41 93 | #define HID_LED_FLASH_ON_TIME 0x42 94 | #define HID_LED_SLOW_BLINK_ON_TIME 0x43 95 | #define HID_LED_SLOW_BLINK_OFF_TIME 0x44 96 | #define HID_LED_FAST_BLINK_ON_TIME 0x45 97 | #define HID_LED_FAST_BLINK_OFF_TIME 0x46 98 | #define HID_LED_USAGE_INDICATOR_COLOR 0x47 99 | #define HID_LED_INDICATOR_RED 0x48 100 | #define HID_LED_INDICATOR_GREEN 0x49 101 | #define HID_LED_INDICATOR_AMBER 0x4A 102 | #define HID_LED_GENERIC_INDICATOR 0x4B 103 | #define HID_LED_SYSTEM_SUSPEND 0x4C 104 | #define HID_LED_EXT_POWER_CONNECTED 0x4D 105 | /** @} */ 106 | #endif 107 | 108 | -------------------------------------------------------------------------------- /inc/hid_usage_ordinal.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the LUS32 project 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_ORDINAL_H_ 17 | #define _USB_HID_USAGE_ORDINAL_H_ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | 23 | /**\ingroup USB_HID 24 | * \addtogroup USB_HID_USAGES_ORDINAL HID Usage Tables for Ordinal 25 | * \brief Contains USB HID Usages definitions for Ordinal Page 26 | * \details This module based on 27 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 28 | * @{ */ 29 | 30 | #define HID_PAGE_ORDINAL 0x0A 31 | 32 | #define HID_ORDINAL_INSTANCE_1 0x01 33 | #define HID_ORDINAL_INSTANCE_2 0x02 34 | #define HID_ORDINAL_INSTANCE_3 0x03 35 | #define HID_ORDINAL_INSTANCE_4 0x04 36 | #define HID_ORDINAL_INSTANCE_5 0x05 37 | 38 | /** @} */ 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /inc/hid_usage_simulation.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_SIMUL_H_ 17 | #define _USB_HID_USAGE_SIMUL_H_ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | 23 | /**\ingroup USB_HID 24 | * \addtogroup USB_HID_USAGES_SIMUL HID Usage Tables for Simulation 25 | * \brief Contains USB HID Usages definitions for Simulation Controls Page 26 | * \details This module based on 27 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 28 | * @{ */ 29 | 30 | #define HID_PAGE_SIMULATION 0x02 /**<\brief Sumulation usage page.*/ 31 | #define HID_SIMUL_SPORTS 0x08 /**<\brief CA Genetic sports simulation device.*/ 32 | 33 | /**\name Flight Simulation Devices 34 | * @{ */ 35 | #define HID_SIMUL_FLIGHT 0x01 /**<\brief CA Airplane simulation device.*/ 36 | #define HID_SIMUL_SPACESHIP 0x04 /**<\brief CA Spaceship simulation device.*/ 37 | #define HID_SIMUL_AIRPLANE 0x09 /**<\brief CA Airplane simulation device.*/ 38 | #define HID_SIMUL_HELICOPTER 0x0A /**<\brief CA Helicopter simulation device.*/ 39 | #define HID_SIMUL_ALIERON 0xB0 /**<\brief DV Aileron control.*/ 40 | #define HID_SIMUL_ALIERIN_TRIM 0xB1 /**<\brief DV Aileron fine adjustment.*/ 41 | #define HID_SIMUL_ANTI_TORQUE 0xB2 /**<\brief DV Rudder pedals.*/ 42 | #define HID_SIMUL_AUTOPILOT_ENABLE 0xB3 /**<\brief OOC Autopilot switch.*/ 43 | #define HID_SIMUL_CHAFF_RELEASE 0xB4 /**<\brief OCS Chaff Release control.*/ 44 | #define HID_SIMUL_COLLECTIVE_CONTROL 0xB5 /**<\brief DV Vertical acceleration lift confrol.*/ 45 | #define HID_SIMUL_CYCLIC_CONTROL 0x22 /**<\brief CP Helicopter cyclic control.*/ 46 | #define HID_SIMUL_CYCLIC_TRIM 0x23 /**<\brief CP Cyclic fine adjustments.*/ 47 | #define HID_SIMUL_DRIVE_BRAKE 0xB6 /**<\brief DV Air brake control.*/ 48 | #define HID_SIMUL_ELECTR_COUNTERMEAS 0xB7 /**<\brief OOC Enables electronic countermeasures.*/ 49 | #define HID_SIMUL_ELEVATOR 0xB8 /**<\brief DV Elevator control.*/ 50 | #define HID_SIMUL_ELEVATOR_TRIM 0xB9 /**<\brief DV Elevator fine adjustment.*/ 51 | #define HID_SIMUL_FLIGHT_COMM 0xBC /**<\brief OOC Flight Communications switch.*/ 52 | #define HID_SIMUL_FLARE_RELEASE 0xBD /**<\brief OCS Flare release button.*/ 53 | #define HID_SIMUL_FLIGHT_CONTROL_STICK 0x20 /**<\brief CA Pitch and Roll control.*/ 54 | #define HID_SIMUL_FLIGHT_STICK 0x21 /**<\brief CA Pitch and Roll control for games.*/ 55 | #define HID_SIMUL_LANDING_GEAR 0xBE /**<\brief OOC Landing gear control.*/ 56 | #define HID_SIMUL_RUDDER 0xBA /**<\brief DV Rudder control.*/ 57 | #define HID_SIMUL_TOE_BRAKE 0xBF /**<\brief DV Toe Brake control.*/ 58 | #define HID_SIMUL_THROTTLE 0xBB /**<\brief DV Trottle control.*/ 59 | #define HID_SIMUL_TRIGGER 0xC0 /**<\brief MC Firearm trigger control.*/ 60 | #define HID_SIMUL_WEAPONS_ARM 0xC1 /**<\brief OOC Enables weapons system.*/ 61 | #define HID_SIMUL_WEAPONS_SELECT 0xC2 /**<\brief OSC Select weapon.*/ 62 | #define HID_SIMUL_WING_FLAPS 0xC3 /**<\brief DV wing flap control.*/ 63 | #define HID_SIMUL_FLIGHT_YOKE 0x24 /**<\brief CA A Flight Yoke controls.*/ 64 | /** @} */ 65 | 66 | /**\name Automobile Simulation Devices 67 | * @{ */ 68 | #define HID_SIMUL_AUTOMOBILE 0x02 /**<\brief CA Automobile or truck simulation device.*/ 69 | #define HID_SIMUL_ACCELERATOR 0xC4 /**<\brief DV Accelerator control.*/ 70 | #define HID_SIMUL_BRAKE 0xC5 /**<\brief DV Brake control.*/ 71 | #define HID_SIMUL_CLUTCH 0xC6 /**<\brief DV Clutch control.*/ 72 | #define HID_SIMUL_SHIFTER 0xC7 /**<\brief DV Shifting gears control.*/ 73 | #define HID_SIMUL_STEERING 0xC8 /**<\brief DV Steering wheel control.*/ 74 | /** @} */ 75 | 76 | /**\name Tank Simulation Devices 77 | * @{ */ 78 | #define HID_SIMUL_TANK 0x03 /**<\brief CA Treaded vehicle simulation device.*/ 79 | #define HID_SIMUL_TRACK_CONTROL 0x25 /**<\brief CP Direction and velocity controls.*/ 80 | #define HID_SIMUL_TURRET_DIRECTION 0xC9 /**<\brief DV Turret control right-left.*/ 81 | #define HID_SIMUL_BARREL_ELEVATION 0xCA /**<\brief DV Gun elevation control.*/ 82 | /** @} */ 83 | 84 | /**\name Maritime Simulation Devices 85 | * @{ */ 86 | #define HID_SIMUL_SUBMARINE 0x05 /**<\brief CA Submarine control.*/ 87 | #define HID_SIMUL_SAILING 0x06 /**<\brief CA Sailing simulatiion control.*/ 88 | #define HID_SIMUL_DIVE_PLANE 0xCB /**<\brief DV Dive plane control*/ 89 | #define HID_SIMUL_BALLAST 0xCC /**<\brief DV Ballast control.*/ 90 | /** @} */ 91 | 92 | /**\name Two-wheeled Simulation Devices 93 | * @{ */ 94 | #define HID_SIMUL_MOTOCYCLE 0x07 /**<\brief CA Motocycle simulation device.*/ 95 | #define HID_SIMUL_BICYCLE 0x0C /**<\brief CA Bycicle simulation device*/ 96 | #define HID_SIMUL_BICYCLE_CRANK 0xCD /**<\brief DV Bycicle crank control.*/ 97 | #define HID_SIMUL_HANDLE_BARS 0xCE /**<\brief DV Steering control.*/ 98 | #define HID_SIMUL_FRONT_BRAKE 0xCF /**<\brief DV Front brake control.*/ 99 | #define HID_SIMUL_REAR_BRAKE 0xD0 /**<\brief DV Rear brake control.*/ 100 | /** @} */ 101 | 102 | /**\name Miscellaneous Simulation Devices 103 | * @{ */ 104 | #define HID_SIMUL_MAGIC_CARPET 0x0B /**<\brief CA Magic carpet simulation device.*/ 105 | /** @} */ 106 | /** @} */ 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif 113 | 114 | -------------------------------------------------------------------------------- /inc/hid_usage_sport.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_SPORT_H_ 17 | #define _USB_HID_USAGE_SPORT_H_ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | 23 | /**\ingroup USB_HID 24 | * \addtogroup USB_HID_USAGES_SPORT HID Usage Tables for Sport 25 | * \brief Contains USB HID Usages definitions for Sport Controls Page 26 | * \details This module based on 27 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 28 | * @{ */ 29 | 30 | #define HID_PAGE_SPORT 0x04 31 | 32 | #define HID_SPORT_BASEBALL_BAT 0x01 33 | #define HID_SPORT_GOLF_CLUB 0x02 34 | #define HID_SPORT_ROWING_MACHINE 0x03 35 | #define HID_SPORT_TREADMILL 0x04 36 | #define HID_SPORT_OAR 0x30 37 | #define HID_SPORT_SLOPE 0x31 38 | #define HID_SPORT_RATE 0x32 39 | #define HID_SPORT_STICK_SPEED 0x33 40 | #define HID_SPORT_STICK_FACE_ANGLE 0x34 41 | #define HID_SPORT_STICK_HEEL_TOE 0x35 42 | #define HID_SPORT_STICK_FOLLOW_THROUGH 0x36 43 | #define HID_SPORT_STICK_TEMPO 0x37 44 | #define HID_SPORT_STICK_TYPE 0x38 45 | #define HID_SPORT_STICK_HEIGHT 0x39 46 | #define HID_SPORT_PUTTER 0x50 47 | #define HID_SPORT_1_IRON 0x51 48 | #define HID_SPORT_2_IRON 0x52 49 | #define HID_SPORT_3_IRON 0x53 50 | #define HID_SPORT_4_IRON 0x54 51 | #define HID_SPORT_5_IRON 0x55 52 | #define HID_SPORT_6_IRON 0x56 53 | #define HID_SPORT_7_IRON 0x57 54 | #define HID_SPORT_8_IRON 0x58 55 | #define HID_SPORT_9_IRON 0x59 56 | #define HID_SPORT_10_IRON 0x5A 57 | #define HID_SPORT_11_IRON 0x5B 58 | #define HID_SPORT_SAND_WEDGE 0x5C 59 | #define HID_SPORT_LOFT_WEDGE 0x5D 60 | #define HID_SPORT_POWER_WEDGE 0x5E 61 | #define HID_SPORT_1_WOOD 0x5F 62 | #define HID_SPORT_3_WOOD 0x60 63 | #define HID_SPORT_5_WOOD 0x61 64 | #define HID_SPORT_7_WOOD 0x62 65 | #define HID_SPORT_9_WOOD 0x63 66 | 67 | /** @} */ 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /inc/hid_usage_telephony.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_TELEPHONY_H_ 17 | #define _USB_HID_USAGE_TELEPHONY_H_ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | 23 | /**\ingroup USB_HID 24 | * \addtogroup USB_HID_USAGES_TELEPHONY HID Usage Tables for Telephony 25 | * \brief Contains USB HID Usages definitions for Telephony Page 26 | * \details This module based on 27 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 28 | * @{ */ 29 | 30 | #define HID_PAGE_TELEPHONY 0x0B 31 | 32 | #define HID_PHONE_PHONE 0x01 33 | #define HID_PHONE_ANSWERING_MACHINE 0x02 34 | #define HID_PHONE_MESSAGE_CONTROLS 0x03 35 | #define HID_PHONE_HANDSET 0x04 36 | #define HID_PHONE_HEADSET 0x05 37 | #define HID_PHONE_TELEPHONY_KEYPAD 0x06 38 | #define HID_PHONE_PROGRAMMABLE_BUTTON 0x07 39 | #define HID_PHONE_HOOK_SWITCH 0x20 40 | #define HID_PHONE_FLASH 0x21 41 | #define HID_PHONE_FEATURE 0x22 42 | #define HID_PHONE_HOLD 0x23 43 | #define HID_PHONE_REDIAL 0x24 44 | #define HID_PHONE_TRANSFER 0x25 45 | #define HID_PHONE_DROP 0x26 46 | #define HID_PHONE_PARK 0x27 47 | #define HID_PHONE_FORWARD_CALLS 0x28 48 | #define HID_PHONE_ALTERNATE_FUNCTION 0x29 49 | #define HID_PHONE_LINE 0x2A 50 | #define HID_PHONE_SPEAKERPHONE 0x2B 51 | #define HID_PHONE_CONFERENCE 0x2C 52 | #define HID_PHONE_RING_ENABLE 0x2D 53 | #define HID_PHONE_RING_SELECT 0x2E 54 | #define HID_PHONE_PHONE_MUTE 0x2F 55 | #define HID_PHONE_CALLER_ID 0x30 56 | #define HID_PHONE_SEND 0x31 57 | #define HID_PHONE_SPEED_DIAL 0x50 58 | #define HID_PHONE_STORE_NUMBER 0x51 59 | #define HID_PHONE_RECALL_NUMBER 0x52 60 | #define HID_PHONE_PHONE_DIRECTORY 0x53 61 | #define HID_PHONE_VOICE_MAIL 0x70 62 | #define HID_PHONE_SCREEN_CALLS 0x71 63 | #define HID_PHONE_DO_NOT_DISTURB 0x72 64 | #define HID_PHONE_MESSAGE 0x73 65 | #define HID_PHONE_ANSWER_ON_OFF 0x74 66 | #define HID_PHONE_INSIDE_DIAL_TONE 0x90 67 | #define HID_PHONE_OUTSIDE_DIAL_TONE 0x91 68 | #define HID_PHONE_INSIDE_RING_TONE 0x92 69 | #define HID_PHONE_OUTSIDE_RING_TONE 0x93 70 | #define HID_PHONE_PRIORITY_RING_TONE 0x94 71 | #define HID_PHONE_INSIDE_RINGBACK 0x95 72 | #define HID_PHONE_PRIORITY_RINGBACK 0x96 73 | #define HID_PHONE_LINE_BUSY_TONE 0x97 74 | #define HID_PHONE_REORDER_TONE 0x98 75 | #define HID_PHONE_CALL_WAITING_TONE 0x99 76 | #define HID_PHONE_CONFIRMATION_TONE_1 0x9A 77 | #define HID_PHONE_CONFIRMATION_TONE_2 0x9B 78 | #define HID_PHONE_TONES_OFF 0x9C 79 | #define HID_PHONE_OUTSIDE_RINGBACK 0x9D 80 | #define HID_PHONE_RINGER 0x9E 81 | #define HID_PHONE_KEY_0 0xB0 82 | #define HID_PHONE_KEY_1 0xB1 83 | #define HID_PHONE_KEY_2 0xB2 84 | #define HID_PHONE_KEY_3 0xB3 85 | #define HID_PHONE_KEY_4 0xB4 86 | #define HID_PHONE_KEY_5 0xB5 87 | #define HID_PHONE_KEY_6 0xB6 88 | #define HID_PHONE_KEY_7 0xB7 89 | #define HID_PHONE_KEY_8 0xB8 90 | #define HID_PHONE_KEY_9 0xB9 91 | #define HID_PHONE_KEY_STAR 0xBA 92 | #define HID_PHONE_KEY_POUND 0xBB 93 | #define HID_PHONE_KEY_A 0xBC 94 | #define HID_PHONE_KEY_B 0xBD 95 | #define HID_PHONE_KEY_C 0xBE 96 | #define HID_PHONE_KEY_D 0xBF 97 | 98 | /** @} */ 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif 105 | 106 | -------------------------------------------------------------------------------- /inc/hid_usage_vr.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_HID_USAGE_VR_H_ 17 | #define _USB_HID_USAGE_VR_H_ 18 | 19 | /**\ingroup USB_HID 20 | * \addtogroup USB_HID_USAGES_VR HID Usage Tables for VR 21 | * \brief Contains USB HID Usages definitions for VR Control Page 22 | * \details This module based on 23 | * + [HID Usage Tables Version 1.12](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf) 24 | * @{ */ 25 | 26 | #define HID_PAGE_VR 0x03 /**<\brief VR controls usage page.*/ 27 | #define HID_VR_BELT 0x01 /**<\brief CA Belt device.*/ 28 | #define HID_VR_BODY_SUIT 0x02 /**<\brief CA Body suit device.*/ 29 | #define HID_VR_FLEXTOR 0x03 /**<\brief CA Flextor device.*/ 30 | #define HID_VR_GLOVE 0x04 /**<\brief CA Clove device.*/ 31 | #define HID_VR_HEAD_TRACKER 0x05 /**<\brief CA Head tracker device.*/ 32 | #define HID_VR_HEAD_MOUNTED_DISPLAY 0x06 /**<\brief CA Head mounted display device.*/ 33 | #define HID_VR_HAND_TRACKER 0x07 /**<\brief CA Hand tracker device.*/ 34 | #define HID_VR_OCULOMETER 0x08 /**<\brief CA Oculometer device.*/ 35 | #define HID_VR_VEST 0x09 /**<\brief CA Vest device.*/ 36 | #define HID_VR_ANIMATRONIC_DEVICE 0x0A /**<\brief CA Animatronic device.*/ 37 | #define HID_VR_STEREO_ENABLE 0x20 /**<\brief OOC Stereo enable switch.*/ 38 | #define HID_VR_DISPLAY_ENABLE 0x21 /**<\brief OOC Display enable switch.*/ 39 | 40 | /** @} */ 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /inc/stm32_compat.h: -------------------------------------------------------------------------------- 1 | #ifndef _STM32_COMPAT_H_ 2 | #define _STM32_COMPAT_H_ 3 | 4 | #ifndef PLATFORMIO 5 | 6 | #include 7 | 8 | #else // PLATFORMIO 9 | /* modify bitfield */ 10 | #define _BMD(reg, msk, val) (reg) = (((reg) & ~(msk)) | (val)) 11 | /* set bitfield */ 12 | #define _BST(reg, bits) (reg) = ((reg) | (bits)) 13 | /* clear bitfield */ 14 | #define _BCL(reg, bits) (reg) = ((reg) & ~(bits)) 15 | /* wait until bitfield set */ 16 | #define _WBS(reg, bits) while(((reg) & (bits)) == 0) 17 | /* wait until bitfield clear */ 18 | #define _WBC(reg, bits) while(((reg) & (bits)) != 0) 19 | /* wait for bitfield value */ 20 | #define _WVL(reg, msk, val) while(((reg) & (msk)) != (val)) 21 | /* bit value */ 22 | #define _BV(bit) (0x01 << (bit)) 23 | 24 | #if defined(STM32F0xx) 25 | #include 26 | #elif defined(STM32F1xx) 27 | #include 28 | #elif defined(STM32F2xx) 29 | #include 30 | #elif defined(STM32F3xx) 31 | #include 32 | #elif defined(STM32F4xx) 33 | #include 34 | #elif defined(STM32F7xx) 35 | #include 36 | #elif defined(STM32H7xx) 37 | #include 38 | #elif defined(STM32L0xx) 39 | #include 40 | #elif defined(STM32L1xx) 41 | #include 42 | #elif defined(STM32L4xx) 43 | #include 44 | #elif defined(STM32L5xx) 45 | #include 46 | #elif defined(STM32G0xx) 47 | #include 48 | #elif defined(STM32G4xx) 49 | #include 50 | #elif defined(STM32WBxx) 51 | #include 52 | #else 53 | #error "STM32 family not defined" 54 | #endif 55 | 56 | #endif // PLATFORMIO 57 | 58 | 59 | #endif // _STM32_COMPAT_H_ -------------------------------------------------------------------------------- /inc/usb.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_H_ 17 | #define _USB_H_ 18 | #if defined(__cplusplus) 19 | extern "C" { 20 | #endif 21 | 22 | #include "usbd_core.h" 23 | #if !defined(__ASSEMBLER__) 24 | #include "usb_std.h" 25 | #endif 26 | 27 | #if defined(STM32L052xx) || defined(STM32L053xx) || \ 28 | defined(STM32L062xx) || defined(STM32L063xx) || \ 29 | defined(STM32L072xx) || defined(STM32L073xx) || \ 30 | defined(STM32L082xx) || defined(STM32L083xx) || \ 31 | defined(STM32F042x6) || defined(STM32F048xx) || \ 32 | defined(STM32F070x6) || defined(STM32F070xB) || \ 33 | defined(STM32F072xB) || defined(STM32F078xx) 34 | 35 | #define USBD_STM32L052 36 | 37 | #if !defined(__ASSEMBLER__) 38 | extern const struct usbd_driver usbd_devfs; 39 | extern const struct usbd_driver usbd_devfs_asm; 40 | #if defined(USBD_ASM_DRIVER) 41 | #define usbd_hw usbd_devfs_asm 42 | #else 43 | #define usbd_hw usbd_devfs 44 | #endif 45 | #endif 46 | 47 | #elif defined(STM32L432xx) || defined(STM32L433xx) || \ 48 | defined(STM32L442xx) || defined(STM32L443xx) || \ 49 | defined(STM32L452xx) || defined(STM32L462xx) || \ 50 | defined(STM32G4) 51 | 52 | #define USBD_STM32L433 53 | 54 | #if !defined(__ASSEMBLER__) 55 | extern const struct usbd_driver usbd_devfs; 56 | extern const struct usbd_driver usbd_devfs_asm; 57 | #if defined(USBD_ASM_DRIVER) 58 | #define usbd_hw usbd_devfs_asm 59 | #else 60 | #define usbd_hw usbd_devfs 61 | #endif 62 | #endif 63 | 64 | #elif defined(STM32L1) 65 | 66 | #define USBD_STM32L100 67 | 68 | #if !defined(__ASSEMBLER__) 69 | extern const struct usbd_driver usbd_devfs; 70 | extern const struct usbd_driver usbd_devfs_asm; 71 | #if defined(USBD_ASM_DRIVER) 72 | #define usbd_hw usbd_devfs_asm 73 | #else 74 | #define usbd_hw usbd_devfs 75 | #endif 76 | #endif 77 | 78 | #elif defined(STM32L475xx) || defined(STM32L476xx) 79 | 80 | #define USBD_STM32L476 81 | 82 | #if !defined(__ASSEMBLER__) 83 | extern const struct usbd_driver usbd_otgfs; 84 | #define usbd_hw usbd_otgfs 85 | #endif 86 | 87 | #elif defined(STM32F405xx) || defined(STM32F415xx) || \ 88 | defined(STM32F407xx) || defined(STM32F417xx) || \ 89 | defined(STM32F427xx) || defined(STM32F437xx) || \ 90 | defined(STM32F429xx) || defined(STM32F439xx) 91 | 92 | #define USBD_STM32F429FS 93 | #define USBD_STM32F429HS 94 | 95 | #if !defined(__ASSEMBLER__) 96 | extern const struct usbd_driver usbd_otgfs; 97 | extern const struct usbd_driver usbd_otghs; 98 | #if defined(USBD_PRIMARY_OTGHS) 99 | #define usbd_hw usbd_otghs 100 | #else 101 | #define usbd_hw usbd_otgfs 102 | #endif 103 | #endif //__ASSEMBLER__ 104 | 105 | #elif defined(STM32F411xE) || defined(STM32F401xC) || defined(STM32F401xE) 106 | 107 | #define USBD_STM32F429FS 108 | #if !defined(__ASSEMBLER__) 109 | extern const struct usbd_driver usbd_otgfs; 110 | #endif 111 | #define usbd_hw usbd_otgfs 112 | 113 | #elif defined(STM32F446xx) || defined(STM32F722xx) || defined (STM32F745xx) 114 | #define USBD_STM32F446FS 115 | #define USBD_STM32F446HS 116 | 117 | #if !defined(__ASSEMBLER__) 118 | extern const struct usbd_driver usbd_otgfs; 119 | extern const struct usbd_driver usbd_otghs; 120 | #if defined(USBD_PRIMARY_OTGHS) 121 | #define usbd_hw usbd_otghs 122 | #else 123 | #define usbd_hw usbd_otgfs 124 | #endif 125 | #endif //__ASSEMBLER__ 126 | 127 | #elif defined(STM32F102x6) || defined(STM32F102xB) || \ 128 | defined(STM32F103x6) || defined(STM32F103xB) || \ 129 | defined(STM32F103xE) || defined(STM32F103xG) || \ 130 | defined(STM32F302x8) || defined(STM32F302xC) || defined(STM32F302xE) || \ 131 | defined(STM32F303xC) || defined(STM32F303xE) || \ 132 | defined(STM32F373xC) 133 | 134 | #define USBD_STM32F103 135 | 136 | #if !defined(__ASSEMBLER__) 137 | extern const struct usbd_driver usbd_devfs; 138 | extern const struct usbd_driver usbd_devfs_asm; 139 | #if defined(USBD_ASM_DRIVER) 140 | #define usbd_hw usbd_devfs_asm 141 | #else 142 | #define usbd_hw usbd_devfs 143 | #endif 144 | #endif 145 | 146 | #elif defined(STM32F105xC) || defined(STM32F107xC) 147 | #define USBD_STM32F105 148 | 149 | #if !defined(__ASSEMBLER__) 150 | extern const struct usbd_driver usbd_otgfs; 151 | #define usbd_hw usbd_otgfs 152 | #endif 153 | 154 | #elif defined(STM32WB55xx) 155 | #define USBD_STM32WB55 156 | 157 | #if !defined(__ASSEMBLER__) 158 | extern const struct usbd_driver usbd_devfs; 159 | #define usbd_hw usbd_devfs 160 | #endif 161 | 162 | #elif defined(STM32H743xx) 163 | #define USBD_STM32H743FS 164 | 165 | #if !defined(__ASSEMBLER__) 166 | extern const struct usbd_driver usbd_otgfs; 167 | #define usbd_hw usbd_otgfs 168 | #endif //__ASSEMBLER__ 169 | 170 | #else 171 | #error Unsupported STM32 family 172 | #endif 173 | 174 | #if defined (__cplusplus) 175 | } 176 | #endif 177 | #endif //_USB_H_ 178 | -------------------------------------------------------------------------------- /inc/usb_cdc.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_CDC_H_ 17 | #define _USB_CDC_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /**\addtogroup USB_CDC USB CDC class 24 | * \brief Generic USB CDC class definitions 25 | * \details This module based on 26 | * + Universal Serial Bus Class Definitions for Communications Devices Revision 1.2 (Errata 1) 27 | * @{ */ 28 | 29 | /**\name USB CDC Class codes 30 | * @{ */ 31 | #define USB_CLASS_CDC 0x02 /**<\brief Communicational Device class */ 32 | #define USB_CLASS_CDC_DATA 0x0A /**<\brief Data Interface class */ 33 | /** @} */ 34 | 35 | /**\name USB CDC subclass codes 36 | * @{ */ 37 | #define USB_CDC_SUBCLASS_ACM 0x02 /**<\brief Abstract Control Model */ 38 | /** @} */ 39 | 40 | /**\name Communications Class Protocol Codes 41 | * @{ */ 42 | #define USB_CDC_PROTO_NONE 0x00 /**<\brief No class specific protocol required */ 43 | #define USB_CDC_PROTO_V25TER 0x01 /**<\brief AT Commands: V.250 etc.*/ 44 | /** @} */ 45 | 46 | 47 | /** \name Data Interface Class Protocol Codes 48 | * @{ */ 49 | #define USB_CDC_PROTO_NTB 0x01 /**<\brief Network Transfer Block.*/ 50 | #define USB_CDC_PROTO_HOST 0xFD /**<\brief Host based driver. 51 | * \details This protocol code should only be used 52 | * in messages between host and device to identify 53 | * the host driver portion of a protocol stack.*/ 54 | #define USB_CDC_PROTO_CDCSPEC 0xFE /**<\brief CDC specified. 55 | * \details The protocol(s) are described using a 56 | * Protocol Unit Functional Descriptors on 57 | *Communication Class Interface.*/ 58 | /** @} */ 59 | 60 | /**\name USB CDC class-specified functional descriptors 61 | * @{ */ 62 | #define USB_DTYPE_CDC_HEADER 0x00 /**<\brief Header Functional Descriptor.*/ 63 | #define USB_DTYPE_CDC_CALL_MANAGEMENT 0x01 /**<\brief Call Management Functional Descriptor.*/ 64 | #define USB_DTYPE_CDC_ACM 0x02 /**<\brief Abstract Control Management Functional 65 | * Descriptor.*/ 66 | #define USB_DTYPE_CDC_UNION 0x06 /**<\brief Union Functional Descriptor.*/ 67 | #define USB_DTYPE_CDC_COUNTRY 0x07 /**<\brief Country Selection Functional Descriptor.*/ 68 | /** @} */ 69 | 70 | 71 | 72 | /** \name USB CDC class-specific requests 73 | * @{ */ 74 | #define USB_CDC_SEND_ENCAPSULATED_CMD 0x00 /**<\brief Used to issue a command in the format of 75 | * the supported control protocol of the Communication 76 | * Class interface.*/ 77 | #define USB_CDC_GET_ENCAPSULATED_RESP 0x01 /**<\brief Used to request a response in the format 78 | * of the supported control protocol of the 79 | * Communication Class interface.*/ 80 | #define USB_CDC_SET_COMM_FEATURE 0x02 /**<\brief Controls the settings for a particular 81 | * communication feature of a particular target.*/ 82 | #define USB_CDC_GET_COMM_FEATURE 0x03 /**<\brief Returns the current settings for the 83 | * communication feature as selected.*/ 84 | #define USB_CDC_CLEAR_COMM_FEATURE 0x04 /**<\brief Controls the settings for a particular 85 | * communication feature of a particular target, 86 | * setting the selected feature to its default state.*/ 87 | #define USB_CDC_SET_LINE_CODING 0x20 /**<\brief Allows the host to specify typical 88 | * asynchronous line-character formatting properties.*/ 89 | #define USB_CDC_GET_LINE_CODING 0x21 /**<\brief Allows the host to find out the currently 90 | * configured line coding.*/ 91 | #define USB_CDC_SET_CONTROL_LINE_STATE 0x22 /**<\brief Generates RS-232/V.24 style control signals.*/ 92 | #define USB_CDC_SEND_BREAK 0x23 /**<\brief Sends special carrier modulation that 93 | * generates an RS-232 style break.*/ 94 | /** @} */ 95 | 96 | /**\name Generic CDC specific notifications 97 | * @{ */ 98 | #define USB_CDC_NTF_NETWORK_CONNECTION 0x00 /**<\brief Allows the device to notify the host about 99 | * network connection status.*/ 100 | #define USB_CDC_NTF_RESPONSE_AVAILABLE 0x01 /**<\brief Allows the device to notify the host that 101 | * a response is available.*/ 102 | #define USB_CDC_NTF_SERIAL_STATE 0x20 /**<\brief Sends asynchronous notification of UART status.*/ 103 | #define USB_CDC_NTF_SPEED_CHANGE 0x2A /**<\brief Allows the device to inform the host-networking 104 | * driver that a change in either the uplink or the 105 | * downlink bit rate of the connection has occurred.*/ 106 | /** @} */ 107 | 108 | 109 | /**\anchor USB_CDC_ACMGMNTCAP 110 | * \name USB CDC Abstract Control Management capabilities 111 | * @{ */ 112 | #define USB_CDC_COMM_FEATURE 0x01 /**<\brief Supports the request combination of 113 | * Set_Comm_Feature, Clear_Comm_Feature, Get_Comm_Feature.*/ 114 | #define USB_CDC_CAP_LINE 0x02 /**<\brief Supports the request combination of 115 | * Set_Line_Coding, Set_Control_Line_State, 116 | * Get_Line_Coding, and the notification Serial_State.*/ 117 | #define USB_CDC_CAP_BRK 0x04 /**<\brief Supports the request Send_Break.*/ 118 | #define USB_CDC_CAP_NOTIFY 0x08 /**<\brief Supports notification Network_Connection.*/ 119 | /** @} */ 120 | 121 | /**\anchor USB_CDC_CALLMGMTCAP 122 | * \name USB CDC Call Management capabilities 123 | * @{ */ 124 | #define USB_CDC_CALL_MGMT_CAP_CALL_MGMT 0x01 /**<\brief Device handles call management itself.*/ 125 | #define USB_CDC_CALL_MGMT_CAP_DATA_INTF 0x02 /**<\brief Device can send/receive call management 126 | * information over a Data Class interface.*/ 127 | /** @} */ 128 | 129 | /**\anchor USB_CDC_LINECODE 130 | * \name Line coding structire bit fields 131 | * @{ */ 132 | #define USB_CDC_1_STOP_BITS 0x00 /**<\brief 1 stop bit.*/ 133 | #define USB_CDC_1_5_STOP_BITS 0x01 /**<\brief 1.5 stop bits.*/ 134 | #define USB_CDC_2_STOP_BITS 0x02 /**<\brief 2 stop bits.*/ 135 | #define USB_CDC_NO_PARITY 0x00 /**<\brief NO parity bit.*/ 136 | #define USB_CDC_ODD_PARITY 0x01 /**<\brief ODD parity bit.*/ 137 | #define USB_CDC_EVEN_PARITY 0x02 /**<\brief EVEN parity bit.*/ 138 | #define USB_CDC_MARK_PARITY 0x03 /**<\brief patity is MARK.*/ 139 | #define USB_CDC_SPACE_PARITY 0x04 /**<\brief patity is SPACE.*/ 140 | /** @} */ 141 | 142 | /**\name SERIAL_STATE notification data values 143 | * @{ */ 144 | #define USB_CDC_STATE_RX_CARRIER 0x0001 /**<\brief State of receiver carrier detection mechanism. 145 | * \details This signal corresponds to V.24 signal 109 146 | * and RS-232 DCD.*/ 147 | #define USB_CDC_STATE_TX_CARRIER 0x0002 /**<\brief State of transmission carrier. 148 | * \details This signal corresponds to V.24 signal 106 149 | * and RS-232 DSR.*/ 150 | #define USB_CDC_STATE_BREAK 0x0004 /**<\brief State of break detection mechanism of the device.*/ 151 | #define USB_CDC_STATE_RING 0x0008 /**<\brief State of ring signal detection of the device.*/ 152 | #define USB_CDC_STATE_FRAMING 0x0010 /**<\brief A framing error has occurred.*/ 153 | #define USB_CDC_STATE_PARITY 0x0020 /**<\brief A parity error has occurred.*/ 154 | #define USB_CDC_STATE_OVERRUN 0x0040 /**<\brief Received data has been discarded due to 155 | * overrun in the device.*/ 156 | /** @} */ 157 | 158 | /**\brief Header Functional Descriptor 159 | * \details Header Functional Descriptor marks the beginning of the concatenated set of functional 160 | * descriptors for the interface. */ 161 | struct usb_cdc_header_desc { 162 | uint8_t bFunctionLength; /**<\brief Size of this descriptor in bytes.*/ 163 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 164 | uint8_t bDescriptorSubType; /**<\brief Header functional descriptor subtype.*/ 165 | uint16_t bcdCDC; /**<\brief USB CDC Specification release number in BCD.*/ 166 | } __attribute__ ((packed)); 167 | 168 | /**\brief Union Functional Descriptor 169 | * \details The Union functional descriptor describes the relationship between a group of interfaces 170 | * that can be considered to form a functional unit. It can only occur within the class-specific 171 | * portion of an Interface descriptor. One of the interfaces in the group is designated as a master 172 | * or controlling interface for the group, and certain class-specific messages can be sent to this 173 | * interface to act upon the group as a whole.*/ 174 | struct usb_cdc_union_desc { 175 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 176 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 177 | uint8_t bDescriptorSubType; /**<\brief Union Functional Descriptor.*/ 178 | uint8_t bMasterInterface0; /**<\brief The interface number of the CDC interface designated 179 | * as the master or controlling interface for the union.*/ 180 | uint8_t bSlaveInterface0; /**<\brief Interface number of first slave or associated interface 181 | * in the union.*/ 182 | /* ... and there could be other slave interfaces */ 183 | } __attribute__ ((packed)); 184 | 185 | /**\brief Country Selection Functional Descriptor 186 | * \details The Country Selection functional descriptor identifies the countries in which the 187 | * communication device is qualified to operate. The parameters of the network connection often vary 188 | * from one country to another, especially in Europe. Also legal requirements impose certain 189 | * restrictions on devices because of different regulations by the governing body of the network to 190 | * which the device must adhere. This descriptor can only occur within the class-specific portion of 191 | * an Interface descriptor and should only be provided to a master Communication Class interface of 192 | * a union. The country codes used in the Country Selection Functional Descriptor are not the same 193 | * as the country codes used in dialing international telephone calls. Implementers should refer to 194 | * the ISO 3166 specification for more information.*/ 195 | struct usb_cdc_country_desc { 196 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 197 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 198 | uint8_t bDescriptorSubType; /**<\brief Country Selection Functional Descriptor.*/ 199 | uint8_t iCountryCodeRelDate; /**<\brief Index of a string giving the release date for the 200 | * implemented ISO 3166 Country Codes. */ 201 | uint8_t wCountyCode0; /**<\brief Country code in hexadecimal format. 202 | * \details As defined in ISO 3166, release date as specified 203 | * in iCountryCodeRelDate for the first supported country. */ 204 | /* ... and there can be a lot of country codes */ 205 | } __attribute__ ((packed)); 206 | 207 | /**\brief Call Management Functional Descriptor. 208 | * \details The Call Management functional descriptor describes the processing of calls for the 209 | * Communication Class interface. It can only occur within the class-specific portion of an Interface 210 | * descriptor.*/ 211 | struct usb_cdc_call_mgmt_desc { 212 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 213 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 214 | uint8_t bDescriptorSubType; /**<\brief Call Management functional descriptor subtype.*/ 215 | uint8_t bmCapabilities; /**<\brief The call management capabilities that this 216 | * configuration supports.*/ 217 | uint8_t bDataInterface; /**<\brief Interface number of Data Class interface optionally 218 | * used for call management.*/ 219 | } __attribute__ ((packed)); 220 | 221 | /**\brief Abstract Control Management Functional Descriptor 222 | * \details The Abstract Control Management functional descriptor describes the commands supported 223 | * by the Communication Class interface, as defined in Section 3.6.2, with the SubClass code of 224 | * Abstract Control Model. It can only occur within the class-specific portion of an Interface 225 | * descriptor.*/ 226 | struct usb_cdc_acm_desc { 227 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 228 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 229 | uint8_t bDescriptorSubType; /**<\brief Abstract Control Management functional descriptor subtype.*/ 230 | uint8_t bmCapabilities; /**<\brief The capabilities that this configuration supports.*/ 231 | } __attribute__ ((packed)); 232 | 233 | /**\brief Notification structure from CDC */ 234 | struct usb_cdc_notification { 235 | uint8_t bmRequestType; /**<\brief This bitmapped field identifies the characteristics 236 | * of the specific request.*/ 237 | uint8_t bNotificationType; /**<\brief Notification type.*/ 238 | uint16_t wValue; /**<\brief Notification value.*/ 239 | uint16_t wIndex; /**<\brief Interface.*/ 240 | uint16_t wLength; /**<\brief Data payload length in bytes.*/ 241 | uint8_t Data[]; /**<\brief Data payload.*/ 242 | } __attribute__ ((packed)); 243 | 244 | /**\brief Line Coding Structure */ 245 | struct usb_cdc_line_coding { 246 | uint32_t dwDTERate; /**<\brief Data terminal rate, in bits per second.*/ 247 | uint8_t bCharFormat; /**<\brief Stop bits.*/ 248 | uint8_t bParityType; /**<\brief Parity.*/ 249 | uint8_t bDataBits; /**<\brief Data bits (5,6,7,8 or 16).*/ 250 | } __attribute__ ((packed)); 251 | 252 | /** @} */ 253 | 254 | #ifdef __cplusplus 255 | } 256 | #endif 257 | 258 | #endif /* _USB_CDC_H_ */ 259 | -------------------------------------------------------------------------------- /inc/usb_cdca.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /**\ingroup USB_CDC 17 | * \addtogroup USB_CDC_ATM USB CDC ATM subclass 18 | * \brief USB CDC ATM subclass definitions 19 | * \details This module based on "Universal Serial Bus Communications Class Subclass Specification 20 | * for Asynchronous Transfer Mode Devices" Revision 1.2 21 | * @{ */ 22 | 23 | #ifndef _USB_CDC_ATM_H_ 24 | #define _USB_CDC_ATM_H_ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | /**\name Communications Class Subclass Codes 32 | * @{ */ 33 | #define USB_CDC_SUBCLASS_ATM 0x07 /**<\brief ATM Networking Control Model */ 34 | /* @} */ 35 | 36 | 37 | /**\name CDC ATM subclass specific Functional Descriptors codes 38 | * @{ */ 39 | #define USB_DTYPE_CDC_ATM 0x10 /**<\brief ATM Networking Functional Descriptor */ 40 | /** @} */ 41 | 42 | /**\name CDC ATM subclass specific requests 43 | * @{ */ 44 | #define USB_CDC_SET_ATM_DATA_FORMAT 0x50 /**<\brief Chooses which ATM data format will be 45 | * exchanged between the host and the ATM Networking 46 | * device.*/ 47 | #define USB_CDC_GET_ATM_DEVICE_STATISTICS 0x51 /**<\brief Retrieves global statistics from the ATM 48 | * Networking device.*/ 49 | #define USB_CDC_SET_ATM_DEFAULT_VC 0x52 /**<\brief Pre-selects the VPI/VCI value for subsequent 50 | * GET_ATM_DEVICE_STATISTICS requests.*/ 51 | #define USB_CDC_GET_ATM_VC_STATISTICS 0x53 /**<\brief Retrieves statistics from the ATM Networking 52 | * device for a particular VPI/VCI.*/ 53 | /** @} */ 54 | 55 | /**\name ATM Device Statistics Feature Selector Codes 56 | * @{ */ 57 | #define ATM_STAT_US_CELLS_SENT 0x01 /**<\brief The number of cells that have been sent 58 | * upstream to the WAN link by the ATM layer. */ 59 | #define ATM_STAT_DS_CELLS_RECEIVED 0x02 /**<\brief The number of cells that have been received 60 | * downstream from the WAN link by the ATM layer */ 61 | #define ATM_STAT_DS_CELLS_USB_CONGESTION 0x03 /**<\brief The number of cells that have been received 62 | * downstream from the WAN link by the ATM layer and 63 | * discarded due to congestion on the USB link.*/ 64 | #define ATM_STAT_DS_CELLS_AAL5_CRC_ERROR 0x04 /**<\brief The number of cells that have been received 65 | * downstream from the WAN link by the ATM layer and 66 | * discarded due to AAL5 CRC errors.*/ 67 | #define ATM_STAT_DS_CELLS_HEC_ERROR 0x05 /**<\brief The number of cells that have been received 68 | * downstream from the WAN link and discarded due to 69 | * HEC errors in the cell header.*/ 70 | #define ATM_STAT_DS_CELLS_HEC_ERROR_CORRT 0x06 /**<\brief The number of cells that have been received 71 | * downstream from the WAN link and have been detected 72 | * with HEC errors in the cell header and successfully 73 | * corrected. */ 74 | /** @} */ 75 | 76 | /**\brief ATM Networking Functional Descriptor */ 77 | struct usb_cdc_atm_desc { 78 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 79 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 80 | uint8_t bDescriptorSubType; /**<\brief ATM Networking Functional Descriptor subtype.*/ 81 | uint8_t iEndSystemIdentifier; /**<\brief The string descriptor holds the End System Identifier. */ 82 | uint8_t bmDataCapabilities; /**<\brief The ATM data types the device supports.*/ 83 | uint8_t bmATMDeviceStatistics; /**<\brief Indicates which optional statistics functions the 84 | * device collects. */ 85 | uint16_t wType2MaxSegmentSize; /**<\brief The maximum segment size that the Type 2 device 86 | * is capable of supporting */ 87 | uint16_t wType3MaxSegmentSize; /**<\brief The maximum segment size that the Type 3 device 88 | * is capable of supporting */ 89 | uint16_t wMaxVC; /**<\brief The maximum number of simultaneous virtual circuits 90 | * the device is capable of supporting (Type 3 only) */ 91 | } __attribute__((packed)); 92 | 93 | /** @} */ 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* _USB_CDC_ATM_H_ */ -------------------------------------------------------------------------------- /inc/usb_cdce.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /**\ingroup USB_CDC 17 | * \addtogroup USB_CDC_ECM USB CDC ECM subclass 18 | * \brief USB CDC ECM subclass definitions 19 | * \details This module based on "Universal Serial Bus Communications Class Subclass Specification for 20 | * Ethernet Control Model Devices Revision 1.2" 21 | * @{ */ 22 | 23 | #ifndef _USB_CDC_ECM_H_ 24 | #define _USB_CDC_ECM_H_ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /**\name Communications Class Subclass Codes 31 | * @{ */ 32 | #define USB_CDC_SUBCLASS_ETH 0x06 /**<\brief Ethernet Networking Control Model */ 33 | /* @} */ 34 | 35 | /**\name CDC ECM subclass specific Functional Descriptors codes 36 | * @{ */ 37 | #define USB_DTYPE_CDC_ETHERNET 0x0F /**<\brief Ethernet Networking Functional Descriptor*/ 38 | /** @} */ 39 | 40 | /**\name CDC ECM subclass specific requests 41 | * @{ */ 42 | #define USB_CDC_SET_ETH_MULTICAST_FILTERS 0x40 /**<\brief */ 43 | #define USB_CDC_SET_ETH_PM_PATTERN_FILTER 0x41 /**<\brief */ 44 | #define USB_CDC_GET_ETH_PM_PATTERN_FILTER 0x42 /**<\brief */ 45 | #define USB_CDC_SET_ETH_PACKET_FILTER 0x43 /**<\brief Sets device filter for running a network 46 | * analyzer application on the host machine.*/ 47 | #define USB_CDC_GET_ETH_STATISTIC 0x44 /**<\brief Retrieves Ethernet device statistics such 48 | * as frames transmitted, frames received, and bad 49 | * frames received.*/ 50 | /** @} */ 51 | 52 | /**\name Ethernet Statistics Capabilities 53 | * @{ */ 54 | #define USB_ETH_XMIT_OK (1<<0) /**<\brief Frames transmitted without errors.*/ 55 | #define USB_ETH_RCV_OK (1<<1) /**<\brief Frames received without errors.*/ 56 | #define USB_ETH_XMIT_ERROR (1<<2) /**<\brief Frames not transmitted, or transmitted 57 | * with errors.*/ 58 | #define USB_ETH_RCV_ERROR (1<<3) /**<\brief Frames received with errors that are 59 | * not delivered to the USB host. */ 60 | #define USB_ETH_RCV_NO_BUFFER (1<<4) /**<\brief Frame missed, no buffers */ 61 | #define USB_ETH_DIRECTED_BYTES_XMIT (1<<5) /**<\brief Directed bytes transmitted without errors */ 62 | #define USB_ETH_DIRECTED_FRAMES_XMIT (1<<6) /**<\brief Directed frames transmitted without errors */ 63 | #define USB_ETH_MULTICAST_BYTES_XMIT (1<<7) /**<\brief Multicast bytes transmitted without errors */ 64 | #define USB_ETH_MULTICAST_FRAMES_XMIT (1<<8) /**<\brief Multicast frames transmitted without errors */ 65 | #define USB_ETH_BROADCAST_BYTES_XMIT (1<<9) /**<\brief Broadcast bytes transmitted without errors */ 66 | #define USB_ETH_BROADCAST_FRAMES_XMIT (1<<10) /**<\brief Broadcast frames transmitted without errors */ 67 | #define USB_ETH_DIRECTED_BYTES_RCV (1<<11) /**<\brief Directed bytes received without errors */ 68 | #define USB_ETH_DIRECTED_FRAMES_RCV (1<<12) /**<\brief Directed frames received without errors */ 69 | #define USB_ETH_MULTICAST_BYTES_RCV (1<<13) /**<\brief Multicast bytes received without errors */ 70 | #define USB_ETH_MULTICAST_FRAMES_RCV (1<<14) /**<\brief Multicast frames received without errors */ 71 | #define USB_ETH_BROADCAST_BYTES_RCV (1<<15) /**<\brief Broadcast bytes received without errors */ 72 | #define USB_ETH_BROADCAST_FRAMES_RCV (1<<16) /**<\brief Broadcast frames received without errors */ 73 | #define USB_ETH_RCV_CRC_ERROR (1<<17) /**<\brief Frames received with circular redundancy check 74 | * (CRC) or frame check sequence (FCS) error */ 75 | #define USB_ETH_TRANSMIT_QUEUE_LENGTH (1<<18) /**<\brief Length of transmit queue */ 76 | #define USB_ETH_RCV_ERROR_ALIGNMENT (1<<19) /**<\brief Frames received with alignment error */ 77 | #define USB_ETH_XMIT_ONE_COLLISION (1<<20) /**<\brief Frames transmitted with one collision */ 78 | #define USB_ETH_XMIT_MORE_COLLISIONS (1<<21) /**<\brief Frames transmitted with more than one collision */ 79 | #define USB_ETH_XMIT_DEFERRED (1<<22) /**<\brief Frames transmitted after deferral */ 80 | #define USB_ETH_XMIT_MAX_COLLISIONS (1<<23) /**<\brief Frames not transmitted due to collisions */ 81 | #define USB_ETH_RCV_OVERRUN (1<<24) /**<\brief Frames not received due to overrun */ 82 | #define USB_ETH_XMIT_UNDERRUN (1<<25) /**<\brief Frames not transmitted due to underrun */ 83 | #define USB_ETH_XMIT_HEARTBEAT_FAILURE (1<<26) /**<\brief Frames transmitted with heartbeat failure */ 84 | #define USB_ETH_XMIT_TIMES_CRS_LOST (1<<27) /**<\brief Times carrier sense signal lost during transmission */ 85 | #define USB_ETH_XMIT_LATE_COLLISIONS (1<<28) /**<\brief Late collisions detected */ 86 | /** @} */ 87 | 88 | 89 | /**\brief Ethernet Networking Functional Descriptor 90 | * \details describes the operational modes supported by the 91 | * Communications Class interface, as defined in Section 3.4, with the SubClass code of Ethernet 92 | * Networking Control. It can only occur within the class-specific portion of an Interface descriptor. 93 | */ 94 | struct usb_cdc_ether_desc { 95 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 96 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 97 | uint8_t bDescriptorSubType; /**<\brief Ethernet Networking Functional Descriptor.*/ 98 | uint8_t iMACAddress; /**<\brief Index of string descriptor that holds the 99 | * 48bit Ethernet MAC.*/ 100 | uint32_t bmEthernetStatistics; /**<\brief Indicates which Ethernet statistics functions 101 | * the device collects. */ 102 | uint16_t wMaxSegmentSize; /**<\brief The maximum segment size that the Ethernet 103 | * device is capable of supporting. */ 104 | uint16_t wNumberMCFilters; /**<\brief Contains the number of multicast filters that 105 | * can be configured by the host. */ 106 | uint8_t bNumberPowerFilters; /**<\brief Contains the number of pattern filters that 107 | * are available for causing wake-up of the host. */ 108 | } __attribute__ ((packed)); 109 | 110 | /** @} */ 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif /* _USB_CDC_ECM_H_ */ -------------------------------------------------------------------------------- /inc/usb_cdci.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /** \ingroup USB_CDC 17 | * \addtogroup USB_CDC_ISDN USB CDC ISDN subclass 18 | * \brief USB CDC ISDN subclass definitions 19 | * \details This module based on "Universal Serial Bus Communications Class Subclass Specification 20 | * for ISDN Devices" Revision 1.2 21 | * \details This module cotains definitions for 22 | * + Multiple Line Control Model 23 | * + CAPI Control Model 24 | * @{ */ 25 | 26 | #ifndef _USB_CDC_ISDN_H_ 27 | #define _USB_CDC_ISDN_H_ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | 34 | /**\name Communications Class Subclass Codes 35 | * @{ */ 36 | #define USB_CDC_SUBCLASS_MCNL 0x04 /**<\brief Multi-Channel Control Model */ 37 | #define USB_CDC_SUBCLASS_CAPI 0x05 /**<\brief CAPI Control Model */ 38 | /* @} */ 39 | 40 | /** \name CDC ISDN Data Interface Class Protocol Codes 41 | * @{ */ 42 | #define USB_CDC_PROTO_I340 0x30 /**<\brief Physical interface protocol for ISDN BRI */ 43 | #define USB_CDC_PROTO_HDLC 0x31 /**<\brief HDLC */ 44 | #define USB_CDC_PROTO_TRANSPARENT 0x32 /**<\brief Transparent */ 45 | #define USB_CDC_PROTO_Q921M 0x50 /**<\brief Management protocol for Q.921 data link protocol */ 46 | #define USB_CDC_PROTO_Q921 0x51 /**<\brief Data link protocol for Q.931 */ 47 | #define USB_CDC_PROTO_Q921TM 0x52 /**<\brief TEI-multiplexor for Q.921 data link protocol */ 48 | #define USB_CDC_PROTO_V42BIS 0x90 /**<\brief Data compression procedures */ 49 | #define USB_CDC_PROTO_Q931 0x91 /**<\brief Euro-ISDN protocol control */ 50 | #define USB_CDC_PROTO_V120 0x92 /**<\brief V.24 rate adaptation to ISDN */ 51 | #define USB_CDC_PROTO_CAPI20 0x93 /**<\brief CAPI Commands */ 52 | /** @} */ 53 | 54 | /**\name CDC ISDN subclass specific Functional Descriptors codes 55 | * @{ */ 56 | #define USB_DTYPE_CDC_TERMINAL 0x09 /**<\brief USB Terminal Functional Descriptor */ 57 | #define USB_DTYPE_CDC_NETWORK_TERMINAL 0x0A /**<\brief Network Channel Terminal Descriptor */ 58 | #define USB_DTYPE_CDC_PROTOCOL_UNIT 0x0B /**<\brief Protocol Unit Functional Descriptor */ 59 | #define USB_DTYPE_CDC_EXTENSION_UNIT 0x0C /**<\brief Extension Unit Functional Descriptor */ 60 | #define USB_DTYPE_CDC_MCNL_MANAGEMENT 0x0D /**<\brief Multi-Channel Management Functional Descriptor */ 61 | #define USB_DTYPE_CDC_CAPI_CONTROL 0x0E /**<\brief CAPI Control Management Functional Descriptor */ 62 | /** @} */ 63 | 64 | /**\name CDC ISDN subclass specific requests 65 | * @{ */ 66 | #define USB_CDC_SET_UNIT_PARAMETER 0x37 /**<\brief Used to set a Unit specific parameter. */ 67 | #define USB_CDC_GET_UNIT_PARAMETER 0x38 /**<\brief Used to retrieve a Unit specific parameter */ 68 | #define USB_CDC_CLEAR_UNIT_PARAMETER 0x39 /**<\brief Used to set a Unit specific parameter to 69 | * its default state. */ 70 | #define USB_CDC_GET_PROFILE 0x3A /**<\brief Returns the implemented capabilities of 71 | * the device */ 72 | /** @} */ 73 | 74 | /**\anchor USB_DFU_MCNHCAP 75 | * \name Multi-Channel Management Functional Descriptor capabilities 76 | * @{ */ 77 | #define USB_CDC_MCHN_UNIT_NVRAM 0x01 /**<\brief Device stores Unit parameters in 78 | * non-volatile memory. */ 79 | #define USB_CDC_MCHN_UNIT_CLR 0x02 /**<\brief Device supports the request Clear_Unit_Parameter. */ 80 | #define USB_CDC_MCHN_UNIR_SET 0x04 /**<\brief Device supports the request Set_Unit_Parameter.*/ 81 | /** @} */ 82 | 83 | /**\anchor USB_DFU_CAPICAP 84 | * \name CAPI Control Management Functional Descriptor capabilities 85 | * @{ */ 86 | #define USB_CDC_CAPI_SIMPLE 0x00 /**<\brief Device is a Simple CAPI device. */ 87 | #define USB_CDC_CAPI_INTELLIGENT 0x01 /**<\brief Device is an Intelligent CAPI device. */ 88 | /** @} */ 89 | 90 | /** \brief USB Terminal Functional Descriptor 91 | * \details The USB Terminal Functional Descriptor provides a means to indicate a relationship 92 | * between a Unit and an USB Interface. It also defines parameters specific to the interface between 93 | * the device and the host. It can only occur within the class-specific portion of an Interface 94 | * descriptor.*/ 95 | struct usb_cdc_terminal_desc { 96 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 97 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 98 | uint8_t bDescriptorSubType; /**<\brief USB Terminal Functional Descriptor */ 99 | uint8_t bEntityId; /**<\brief Constant uniquely identifying the Terminal */ 100 | uint8_t bInInterfaceNo; /**<\brief The input interface number of the associated USB interface. */ 101 | uint8_t bOutInterfaceNo; /**<\brief The output interface number of the associated USB interface. */ 102 | uint8_t bmOptions; /**<\brief D0: Protocol wrapper usage */ 103 | uint8_t bChildId0; /**<\brief First ID of lower Terminal or Unit to which this 104 | * Terminal is connected. */ 105 | /* ... and there can be a lot of Terminals or Units */ 106 | } __attribute__ ((packed)); 107 | 108 | /** \brief Network Channel Terminal Functional Descriptor 109 | * \details The Network Channel Terminal Functional descriptor provides a means to indicate a 110 | * relationship between a Unit and a Network Channel. It can only occur within the class-specific 111 | * portion of an Interface descriptor.*/ 112 | struct usb_cdc_network_terminal_desc { 113 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 114 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 115 | uint8_t bDescriptorSubType; /**<\brief Network Channel Terminal Functional Descriptor */ 116 | uint8_t bEntityId; /**<\brief Constant uniquely identifying the Terminal */ 117 | uint8_t iName; /**<\brief Index of string descriptor, describing the name of 118 | * the Network Channel Terminal. */ 119 | uint8_t bChannelIndex; /**<\brief The channel index of the associated network channel 120 | * according to indexing rules below. */ 121 | uint8_t bPhysicalInterface; /**<\brief Type of physical interface. 122 | * + 0 none 123 | * + 1 ISDN 124 | * + 2-200 RESERVED 125 | * + 201 -255 Vendor specific */ 126 | } __attribute__ ((packed)); 127 | 128 | /** \brief Protocol Unit Functional Descriptor 129 | * \details A communication protocol stack is a combination of communication functions (protocols) 130 | * into a layered structure. Each layer in the stack presents some abstract function for the layer 131 | * above according to some layer-interface-standard, making it possible to replace a function with 132 | * another as long as it conforms to the standard. Each layer may have a set of protocol parameters, 133 | * defined in Appendix E, to configure it for proper operation in the actual environment and the 134 | * parameters may be retrieved and/or modified. The Unit state is initially reset. See Section 6.2.23 135 | * “SetUnitParameter”, Section 6.2.24 “GetUnitParameter”, and 6.2.25 “ClearUnitParameter” for details. 136 | * A Protocol Unit Functional Descriptor identifies with bEntityId a specific protocol instance of 137 | * bProtocol in a stack. It can only occur within the class-specific portion of an Interface descriptor. 138 | */ 139 | struct usb_cdc_proto_unit_desc { 140 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 141 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 142 | uint8_t bDescriptorSubType; /**<\brief Network Channel Terminal Functional Descriptor */ 143 | uint8_t bEntityId; /**<\brief Constant uniquely identifying the Unit */ 144 | uint8_t bProtocol; /**<\brief Protocol code */ 145 | 146 | } __attribute__ ((packed)); 147 | 148 | /** \brief Extension Unit Functional Descriptor 149 | * \details The Extension Unit Functional Descriptor provides minimal information about the Extension 150 | * Unit for a generic driver at least to notice the presence of vendor-specific components within 151 | * the protocol stack. */ 152 | struct usb_cdc_ext_unit_desc { 153 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 154 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 155 | uint8_t bDescriptorSubType; /**<\brief Network Channel Terminal Functional Descriptor */ 156 | uint8_t bEntityId; /**<\brief Constant uniquely identifying the Unit */ 157 | uint8_t bExtensionCode; /**<\brief Vendor specific code identifying the Extension Unit. */ 158 | uint8_t iName; /**<\brief Index of string descriptor, describing the name of 159 | * the Extension Unit. */ 160 | uint8_t bChildId0; /**<\brief First ID of lower Terminal or Unit to which this 161 | * Terminal is connected. */ 162 | /* ... and there can be a lot of Terminals or Units */ 163 | } __attribute__ ((packed)); 164 | 165 | /**\brief Multi-Channel Management Functional Descriptor 166 | * \details The Multi-Channel Management functional descriptor describes the commands supported by 167 | * the Communications Class interface, as defined in CDC , with the SubClass code of Multi-Channel.*/ 168 | struct usb_cdc_mcnl_managemnt_desc { 169 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 170 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 171 | uint8_t bDescriptorSubType; /**<\brief Multi-Channel Management Functional Descriptor */ 172 | uint8_t bmCapabilities; /**<\brief The capabilities that this configuration supports. */ 173 | } __attribute__ ((packed)); 174 | 175 | /**\brief CAPI Control Management Functional Descriptor 176 | * \details The CAPI control management functional descriptor describes the commands supported by 177 | * the CAPI Control Model over the Data Class interface with the protocol code of CAPI control. */ 178 | struct usb_cdc_capi_ctl_desc { 179 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 180 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 181 | uint8_t bDescriptorSubType; /**<\brief CAPI Control Management Functional Descriptor */ 182 | uint8_t bmCapabilities; /**<\brief The capabilities that this configuration supports. */ 183 | } __attribute__ ((packed)); 184 | 185 | /** @} */ 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif 190 | 191 | #endif /* _USB_CDC_ISDN_H_ */ -------------------------------------------------------------------------------- /inc/usb_cdcp.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /** \ingroup USB_CDC 17 | * \addtogroup USB_CDC_PSTN USB CDC PSTN subclass 18 | * \brief USB CDC PSTN subclass definitions 19 | * \details This module based on "Universal Serial Bus Communications Class Subclass Specification 20 | * for PSTN Devices" Revision 1.2 21 | * \details This module contains definitions for 22 | * + Direct Line Control Model 23 | * + Telephony Control Model 24 | * @{ */ 25 | 26 | #ifndef _USB_CDC_PSTN_H_ 27 | #define _USB_CDC_PSTN_H_ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | 34 | /**\name Communications Class Subclass Codes 35 | * @{ */ 36 | #define USB_CDC_SUBCLASS_DLC 0x01 /**<\brief Direct Line Control Model */ 37 | #define USB_CDC_SUBCLASS_TEL 0x03 /**<\brief Telephone Control Model */ 38 | /* @} */ 39 | 40 | /**\name CDC PSTN subclass specific Functional Descriptors codes 41 | * @{ */ 42 | #define USB_DTYPE_CDC_LINE_MANAGEMENT 0x03 /**<\brief Direct Line Management Functional Descriptor.*/ 43 | #define USB_DTYPE_CDC_TEL_RING 0x04 /**<\brief Telephone Ringer Functional Descriptor. */ 44 | #define USB_DTYPE_CDC_TEL_CALL 0x05 /**<\brief Telephone Call and Line State Reporting 45 | * Capabilities Functional Descriptor.*/ 46 | #define USB_DTYPE_CDC_TEL_OPMODE 0x08 /**<\brief Telephone Operational Modes Functional Descriptor */ 47 | /** @} */ 48 | 49 | /**\name CDC PSTN subclass specific requests 50 | * @{ */ 51 | #define USB_CDC_SET_AUX_LINE_STATE 0x10 /**<\brief Used to connect or disconnect a secondary 52 | *jack to POTS circuit or CODEC, depending on hook state.*/ 53 | #define USB_CDC_SET_HOOK_STATE 0x11 /**<\brief Used to set the necessary POTS line relay code 54 | * for on-hook, off-hook, and caller ID states.*/ 55 | #define USB_CDC_PULSE_SETU 0x12 /**<\brief Used to prepare for a pulse-dialing cycle.*/ 56 | #define USB_CDC_SEND_PULSE 0x13 /**<\brief Used to generate a specified number of 57 | * make/break pulse cycles.*/ 58 | #define USB_CDC_SET_PULSE_TIME 0x14 /**<\brief Sets the timing of the make and break periods 59 | * for pulse dialing.*/ 60 | #define USB_CDC_RING_AUX_JACK 0x15 /**<\brief Used to generate a ring signal on a secondary 61 | * phone jack.*/ 62 | #define USB_CDC_SET_RINGER_PARMS 0x30 /**<\brief Configures the ringer for the communication 63 | * device.*/ 64 | #define USB_CDC_GET_RINGER_PARMS 0x31 /**<\brief Returns the ringer capabilities of the device 65 | * and the current status of the device’s ringer.*/ 66 | #define USB_CDC_SET_OPERATION_PARMS 0x32 /**<\brief Sets the operational mode for the device, 67 | * between a simple mode, standalone mode and a host 68 | * centric mode. */ 69 | #define USB_CDC_GET_OPERATION_PARMS 0x33 /**<\brief Gets the current operational mode for the device.*/ 70 | #define USB_CDC_SET_LINE_PARMS 0x34 /**<\brief Used to change the state of the line.*/ 71 | #define USB_CDC_GET_LINE_PARMS 0x35 /**<\brief Used to report the state of the line.*/ 72 | #define USB_CDC_DIAL_DIGITS 0x36 /**<\brief Dials the DTMF digits over the specified line.*/ 73 | /** @} */ 74 | 75 | /**\name CDC PSTN subclass specific notifications 76 | * @{ */ 77 | #define USB_CDC_NTF_AUX_JACK_HOOK_STATE 0x08 /**<\brief Indicates the loop has changed on the 78 | * auxiliary phone interface. */ 79 | #define USB_CDC_NTF_RING_DETECT 0x09 /**<\brief Indicates ring voltage on the POTS line 80 | * interface.*/ 81 | #define USB_CDC_NTF_CALL_STATE_CHANGE 0x28 /**<\brief Identifies that a change has occurred to the 82 | * state of a call on the line corresponding to the 83 | * interface or union for the line.*/ 84 | #define USB_CDC_NTF_LINE_STATE_CHANGE 0x29 /**<\brief identifies that a change has occurred to the 85 | * state of the line corresponding to theinterface or 86 | * master interface of a union.*/ 87 | /** @} */ 88 | 89 | 90 | /**\anchor USB_CDC_DLMGMNTCAP 91 | * \name USB CDC Direct Line Management capabilities 92 | * @{ */ 93 | #define USB_CDC_DLM_PULSE 0x01 /**<\brief Supports the request combination of Pulse_Setup, 94 | * Send_Pulse, and Set_Pulse_Time. */ 95 | #define USB_CDC_DLM_AUX 0x02 /**<\brief Supports the request combination of Set_Aux_Line_State, 96 | * Ring_Aux_Jack, and notification Aux_Jack_Hook_State. */ 97 | #define USB_CDC_DLM_XTRAPULSE 0x04 /**<\brief Device requires extra Pulse_Setup request during 98 | * pulse dialing sequence to disengage holding circuit.*/ 99 | /** @} */ 100 | 101 | /**\anchor USB_CDC_TOMCAP 102 | * \name USB CDC Telephone Operational Modes capabilities 103 | * @{ */ 104 | #define USB_CDC_TOM_SIMPLE 0x01 /**<\brief Supports Simple mode. */ 105 | #define USB_CDC_TOM_STANDALONE 0x02 /**<\brief Supports Standalone mode. */ 106 | #define USB_CDC_TOM_CENTRIC 0x04 /**<\brief Supports Computer Centric mode. */ 107 | /** @} */ 108 | 109 | /**\anchor USB_CDC_TCSCAP 110 | * \name USB CDC Telephone Call State Reporting capabilities 111 | * @{ */ 112 | #define USB_CDC_TCS_DIALTONE 0x01 /**<\brief Reports interrupted dialtone in addition to 113 | * normal dialtone.*/ 114 | #define USB_CDC_TCS_STATE 0x02 /**<\brief Reports ringback, busy, and fast busy states.*/ 115 | #define USB_CDC_TCS_CALLERID 0x04 /**<\brief Reports caller ID information. */ 116 | #define USB_CDC_TCS_RINGING 0x08 /**<\brief Reports incoming distinctive ringing patterns.*/ 117 | #define USB_CDC_TCS_DTMF 0x10 /**<\brief Can report DTMF digits input remotely over 118 | * the telephone line.*/ 119 | #define USB_CDC_TCS_NOTIFY 0x20 /**<\brief Does support line state change notification.*/ 120 | /** @} */ 121 | 122 | 123 | /** \brief Direct Line Management Functional Descriptor 124 | * \details The Direct Line Management functional descriptor describes the commands supported by the 125 | * Communication Class interface, as defined in Section 3.6.1, with the SubClass code of Direct Line 126 | * Control Model. It can only occur within the class-specific portion of an Interface descriptor.*/ 127 | struct usb_cdc_dlm_desc { 128 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 129 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 130 | uint8_t bDescriptorSubType; /**<\brief Direct Line Management Functional Descriptor. */ 131 | uint8_t bmCapabilities; /**<\brief The line management capabilities that this 132 | * configuration supports */ 133 | } __attribute__ ((packed)); 134 | 135 | /** \brief Telephone Ringer Functional Descriptor 136 | * \details The Telephone Ringer functional descriptor describes the ringer capabilities supported 137 | * by the Communication Class interface, as defined in Section 3.6.3.1, with the SubClass code of 138 | * Telephone Control. It can only occur within the class-specific portion of an Interface descriptor.*/ 139 | struct usb_cdc_tring_desc { 140 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 141 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 142 | uint8_t bDescriptorSubType; /**<\brief Direct Line Management Functional Descriptor.*/ 143 | uint8_t bRingerVolSteps; /**<\brief Number of discrete steps in volume supported by the ringer.*/ 144 | uint8_t bNumRingerPatterns; /**<\brief Number of ringer patterns supported.*/ 145 | } __attribute__ ((packed)); 146 | 147 | /** \brief Telephone Operational Modes Functional Descriptor 148 | * \details The Telephone Operational Modes functional descriptor describes the operational modes 149 | * supported by the Communication Class interface, as defined in Section 3.6.3.1, with the SubClass 150 | * code of Telephone Control. It can only occur within the class-specific portion of an Interface 151 | * descriptor. The modes supported are Simple, Standalone, and Computer Centric. See Section 6.2.18, 152 | * “SetOperationParms” for a definition of the various operational modes and Table 53 for the 153 | * definition of the operational mode values.*/ 154 | struct usb_cdc_tom_desc { 155 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 156 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 157 | uint8_t bDescriptorSubType; /**<\brief Direct Line Management Functional Descriptor. */ 158 | uint8_t bmCapabilities; /**<\brief The perational modes capabilities that this 159 | * configuration supports */ 160 | } __attribute__ ((packed)); 161 | 162 | /** \brief Telephone Call State Reporting Capabilities Descriptor 163 | * \details The Telephone Call and Line State Reporting Capabilities functional descriptor describes 164 | * the abilities of a telephone device to report optional call and line states. 165 | */ 166 | struct usb_cdc_tcs_desc { 167 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes. */ 168 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type. */ 169 | uint8_t bDescriptorSubType; /**<\brief Direct Line Management Functional Descriptor. */ 170 | uint32_t bmCapabilities; /**<\brief The call state capabilities that this configuration 171 | * supports */ 172 | } __attribute__ ((packed)); 173 | 174 | /** @} */ 175 | 176 | #ifdef __cplusplus 177 | } 178 | #endif 179 | #endif /* _USB_CDC_PSTN_H_ */ -------------------------------------------------------------------------------- /inc/usb_cdcw.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /**\ingroup USB_CDC 17 | * \addtogroup USB_CDC_WCM USB CDC WCM subclass 18 | * \brief USB CDC WCM subclass definitions 19 | * \details Wireless Mobile Communications Devices subclass 20 | * \details based on Universal Serial Bus CDC Subclass Specification for Wireless Mobile Communications Devices 21 | * Revision 1.1 (Errata 1) 22 | * + Wireless Handset Control Model 23 | * + Device Management Model 24 | * + Mobile Direct Line Model 25 | * + OBEX Model 26 | * @{ */ 27 | 28 | #ifndef _USB_CDC_WCM_H_ 29 | #define _USB_CDC_WCM_H_ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /**\name Communications Class Subclass Codes 37 | * @{ */ 38 | #define USB_CDC_SUBCLASS_WHCM 0x08 /**<\brief Wireless Handset Control Model.*/ 39 | #define USB_CDC_SUBCLASS_DMM 0x09 /**<\brief Device Management Model.*/ 40 | #define USB_CDC_SUBCLASS_MDLM 0x0A /**<\brief Mobile Direct Line Model.*/ 41 | #define USB_CDC_SUBCLASS_OBEX 0x0B /**<\brief OBEX Model.*/ 42 | /* @} */ 43 | 44 | /**\name Communications Class Protocol Codes 45 | * @{ */ 46 | #define USB_CDC_PROTO_PCCA101 0x02 /**<\brief AT Commands defined by PCCA-101.*/ 47 | #define USB_CDC_PROTO_PCCA101O 0x03 /**<\brief AT Commands defined by PCCA-101 & Annex O.*/ 48 | #define USB_CDC_PROTO_GSM 0x04 /**<\brief AT Commands defined by GSM 07.07.*/ 49 | #define USB_CDC_PROTO_3G 0x05 /**<\brief AT Commands defined by 3GPP 27.007.*/ 50 | #define USB_CDC_PROTO_CDMA 0x06 /**<\brief AT Commands defined by TIA for CDMA.*/ 51 | /** @} */ 52 | 53 | /**\name CDC WCM subclass specific Functional Descriptors codes 54 | * @{ */ 55 | #define USB_DTYPE_CDC_WHCM 0x11 /**<\brief Wireless Handset Control Model Functional Descriptor.*/ 56 | #define USB_DTYPE_CDC_MDLM 0x12 /**<\brief Mobile Direct Line Model Functional Descriptor.*/ 57 | #define USB_DTYPE_CDC_MDLM_DETAIL 0x13 /**<\brief MDLM Detail Functional Descriptor.*/ 58 | #define USB_DTYPE_CDC_DMM 0x14 /**<\brief Device Management Model Functional Descriptor.*/ 59 | #define USB_DTYPE_CDC_OBEX 0x15 /**<\brief OBEX Functional Descriptor.*/ 60 | #define USB_DTYPE_CDC_CMDSET 0x16 /**<\brief Command Set Functional Descriptor.*/ 61 | #define USB_DTYPE_CDC_CMDSET_DETAIL 0x17 /**<\brief Command Set Detail Functional Descriptor.*/ 62 | #define USB_DTYPE_CDC_TEL_CONRTOL 0x18 /**<\brief Telephone Control Model Functional Descriptor.*/ 63 | #define USB_DTYPE_CDC_OBEX_SERVICE 0x19 /**<\brief OBEX Service Identifier Functional Descriptor.*/ 64 | /** @} */ 65 | 66 | /**\name CDC WCM subclass specific requests 67 | * @{ */ 68 | 69 | /** @} */ 70 | 71 | /**\brief Wireless Handset Control Model Functional Descriptor */ 72 | struct usb_cdc_whcm_desc { 73 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 74 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 75 | uint8_t bDescriptorSubType; /**<\brief Wireless Handset Control Model Functional Descriptor.*/ 76 | uint16_t bcdVersion; /**<\brief BCD version number for this subclass specification.*/ 77 | } __attribute__ ((packed)); 78 | 79 | /**\brief Mobile Direct Line Model Functional Descriptor 80 | * \details This descriptor is mandatory. It conveys the GUID that uniquely identifies the kind of 81 | * MDLM interface that is being provided. 82 | */ 83 | struct usb_cdc_mdlm_desc { 84 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 85 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 86 | uint8_t bDescriptorSubType; /**<\brief Mobile Direct Line Model Functional Descriptor.*/ 87 | uint16_t bcdVersion; /**<\brief Version number for this subclass specification.*/ 88 | uint8_t bGUID[16]; /**<\brief Uniquely identifies the detailed transport protocol 89 | * provided by this MDLM interface. */ 90 | } __attribute__ ((packed)); 91 | 92 | /**\brief Mobile Direct Line Model Detail Functional Descriptor 93 | * \details This descriptor is optional, and may be repeated as necessary. It conveys any additional 94 | * information required by the MDLM transport specification identified by the MDLM Functional 95 | * Descriptor.*/ 96 | struct usb_cdc_mdlm_detail_desc { 97 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 98 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 99 | uint8_t bDescriptorSubType; /**<\brief Mobile Direct Line Model Details Functional Descriptor.*/ 100 | uint8_t bGuidDescriptorType; /**<\brief Discriminator, interpreted according to the semantic 101 | * model specified by the GUID in the MDLM Functional Descriptor.*/ 102 | uint8_t bDetailData[0]; /**< Information associated with this GUID and discriminator, 103 | * according to the semantic model specified by the GUID in 104 | * the MDLM Functional Descriptor */ 105 | } __attribute__ ((packed)); 106 | 107 | /**\brief Device Management Functional Descriptor */ 108 | struct usb_cdc_dmm_desc { 109 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 110 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 111 | uint8_t bDescriptorSubType; /**<\brief Wireless Handset Control Model Functional Descriptor.*/ 112 | uint16_t bcdVersion; /**<\brief Version number for this subclass specification.*/ 113 | uint16_t wMaxCommand; /**<\brief The buffer size allocated in the device for data 114 | * sent from the host using SEND_ENCAPSULATED_CMD. */ 115 | } __attribute__ ((packed)); 116 | 117 | /**\brief OBEX Service Identification Functional Descriptor 118 | * \details This optional functional descriptor indicates the mode supported by this OBEX function. 119 | * This corresponds to an OBEX role (client or server), a particular OBEX service, and an OBEX 120 | * service version.*/ 121 | struct usb_cdc_obex_serv_desc { 122 | uint8_t bFunctionLength; /**<\brief Size of this functional descriptor, in bytes.*/ 123 | uint8_t bDescriptorType; /**<\brief CS_INTERFACE descriptor type.*/ 124 | uint8_t bDescriptorSubType; /**<\brief OBEX Service Identifier Functional Descriptor.*/ 125 | uint8_t bmOBEXRole; /**<\brief Represents the OBEX role to be played by the function.*/ 126 | uint8_t bOBEXServiceUUID[16]; /**<\brief A 16 byte UUID value used to indicate the particular 127 | * OBEX service associated with this function. */ 128 | uint16_t wOBEXServiceVersion; /**<\brief A 16 bit value indicating the version of the OBEX 129 | * service associated with this function. */ 130 | } __attribute__ ((packed)); 131 | 132 | /** @} */ 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | #endif /* _USB_CDC_WCM_H_ */ -------------------------------------------------------------------------------- /inc/usb_dfu.h: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _USB_DFU_H_ 17 | #define _USB_DFU_H_ 18 | 19 | #if defined(__cplusplus) 20 | extern "C" { 21 | #endif 22 | 23 | /**\addtogroup USB_MODULE_DFU USB DFU class 24 | * \brief This module contains USB Device Firmware Upgrade class definitions. 25 | * \details This module based on 26 | * + [USB Device Firmware Upgrade Specification, Revision 1.1] 27 | * (https://www.usb.org/sites/default/files/DFU_1.1.pdf) 28 | * @{ */ 29 | 30 | /**\name USB DFU class subclass and protocol definitions 31 | * @{ */ 32 | #define USB_CLASS_DFU 0xFE /**<\brief USB DFU class.*/ 33 | #define USB_DFU_SUBCLASS_DFU 0x01 /**<\brief USB DFU subclass code.*/ 34 | #define USB_DFU_PROTO_RUNTIME 0x01 /**<\brief USB DFU runtime-mode protocol.*/ 35 | #define USB_DFU_PROTO_DFU 0x02 /**<\brief USB DFU DFU-mode protocol.*/ 36 | /** @{ */ 37 | 38 | /**\name USB DFU descriptor types */ 39 | #define USB_DTYPE_DFU_FUNCTIONAL 0x21 /**<\brief USB DFU functional descriptor type.*/ 40 | 41 | /**\name USB DFU class-specific requests 42 | * @{ */ 43 | #define USB_DFU_DETACH 0x00 /**<\brief Initiates a detach-attach sequence on the 44 | * bus when it sees this request. */ 45 | #define USB_DFU_DNLOAD 0x01 /**<\brief Initiates firmware image downloading */ 46 | #define USB_DFU_UPLOAD 0x02 /**<\brief This request is employed by the host to 47 | * solicit firmware from the device.*/ 48 | #define USB_DFU_GETSTATUS 0x03 /**<\brief The host employs this request to facilitate 49 | * synchronization with the device.*/ 50 | #define USB_DFU_CLRSTATUS 0x04 /**<\brief This request resets DFU machine state to 51 | * DFU_IDLE.*/ 52 | #define USB_DFU_GETSTATE 0x05 /**<\brief This request solicits a report about the 53 | * state of the device.*/ 54 | #define USB_DFU_ABORT 0x06 /**<\brief This request enables the host to exit from 55 | * certain states and return to the DFU_IDLE state.*/ 56 | /** @} */ 57 | 58 | /**\anchor USB_DFU_CAPAB 59 | * \name USB DFU capabilities 60 | * @{ */ 61 | #define USB_DFU_ATTR_WILL_DETACH 0x08 /**<\brief Device will perform a bus detach-attach 62 | * sequence when it receives a DFU_DETACH request.*/ 63 | #define USB_DFU_ATTR_MANIF_TOL 0x04 /**<\brief Device is able to communicate via USB 64 | * after Manifestation phase.*/ 65 | #define USB_DFU_ATTR_CAN_UPLOAD 0x02 /**<\brief Upload capable.*/ 66 | #define USB_DFU_ATTR_CAN_DNLOAD 0x01 /**<\brief Download capable.*/ 67 | /** @} */ 68 | 69 | /**\name USB DFU status codes 70 | * @{ */ 71 | #define USB_DFU_STATUS_OK 0x00 /**<\brief No error condition is present.*/ 72 | #define USB_DFU_STATUS_ERR_TARGET 0x01 /**<\brief File is not targeted for use by this device.*/ 73 | #define USB_DFU_STATUS_ERR_FILE 0x02 /**<\brief File is for this device but fails some 74 | * vendor specific verification test.*/ 75 | #define USB_DFU_STATUS_ERR_WRITE 0x03 /**<\brief Device is unable to write memory.*/ 76 | #define USB_DFU_STATUS_ERR_ERASE 0x04 /**<\brief Memory erase function failed.*/ 77 | #define USB_DFU_STATUS_ERR_CHECK_ERASED 0x05 /**<\brief Memory erase check failed.*/ 78 | #define USB_DFU_STATUS_ERR_PROG 0x06 /**<\brief Program memory function failed.*/ 79 | #define USB_DFU_STATUS_ERR_VERIFY 0x07 /**<\brief Programmed memory failed verification.*/ 80 | #define USB_DFU_STATUS_ERR_ADDRESS 0x08 /**<\brief Cannot program memory due to received 81 | * address that is out of range. */ 82 | #define USB_DFU_STATUS_ERR_NOTDONE 0x09 /**<\brief Received DFU_DNLOAD with wLength = 0, but 83 | * device does not think it has all of the data yet.*/ 84 | #define USB_DFU_STATUS_ERR_FIRMWARE 0x0A /**<\brief Device's firmware is corrupt. It cannot 85 | * return to run-time (non-DFU) operations.*/ 86 | #define USB_DFU_STATUS_ERR_VENDOR 0x0B /**<\brief iString indicates a vendor-specific error.*/ 87 | #define USB_DFU_STATUS_ERR_USBR 0x0C /**<\brief Device detected unexpected USB reset signaling.*/ 88 | #define USB_DFU_STATUS_ERR_POR 0x0D /**<\brief Device detected unexpected power on reset. */ 89 | #define USB_DFU_STATUS_ERR_UNKNOWN 0x0E /**<\brief Something went wrong, but the device does 90 | * not know what it was.*/ 91 | #define USB_DFU_STATUS_ERR_STALLEDPKT 0x0F /**<\brief Device stalled an unexpected request.*/ 92 | /** @} */ 93 | 94 | /**\name USB DFU state codes 95 | * @{ */ 96 | #define USB_DFU_STATE_APP_IDLE 0x00 /**<\brief Device is running its normal application.*/ 97 | #define USB_DFU_STATE_APP_DETACH 0x01 /**<\brief Device is running its normal application, 98 | * has received the DFU_DETACH request, and is 99 | * waiting for a USB reset. */ 100 | #define USB_DFU_STATE_DFU_IDLE 0x02 /**<\brief Device is operating in the DFU mode and 101 | * is waiting for requests. */ 102 | #define USB_DFU_STATE_DFU_DNLOADSYNC 0x03 /**<\brief Device has received a block and is waiting 103 | * for the host to solicit the status via DFU_GETSTATUS. */ 104 | #define USB_DFU_STATE_DFU_DNBUSY 0x04 /**<\brief Device is programming a control-write block 105 | * into its nonvolatile memories. */ 106 | #define USB_DFU_STATE_DFU_DNLOADIDLE 0x05 /**<\brief Device is processing a download operation. 107 | * Expecting DFU_DNLOAD requests. */ 108 | #define USB_DFU_STATE_DFU_MANIFESTSYNC 0x06 /**<\brief Device has received the final block of 109 | * firmware from the host and is waiting for receipt 110 | * of DFU_GETSTATUS to begin the Manifestation phase; 111 | * or device has completed the Manifestation phase 112 | * and is waiting for receipt of DFU_GETSTATUS. 113 | * \note Devices that can enter this state after the 114 | * Manifestation phase set bmAttributes bit 115 | * bitManifestationTolerant to 1. */ 116 | #define USB_DFU_STATE_DFU_MANIFEST 0x07 /**<\brief Device is in the Manifestation phase. 117 | * \note Not all devices will be able to respond to 118 | * DFU_GETSTATUS when in this state.*/ 119 | #define USB_DFU_STATE_DFU_MANIFESTWR 0x08 /**<\brief Device has programmed its memories and is 120 | * waiting for a USB reset or a power on reset. 121 | * \note Devices that must enter this state clear 122 | * bitManifestationTolerant to 0.*/ 123 | #define USB_DFU_STATE_DFU_UPLOADIDLE 0x09 /**<\brief The device is processing an upload operation.*/ 124 | #define USB_DFU_STATE_DFU_ERROR 0x0A /**<\brief An error has occurred. */ 125 | /** @} */ 126 | 127 | /**\brief USB DFU functional descriptor */ 128 | struct usb_dfu_func_desc { 129 | uint8_t bLength; /**<\brief Descriptor length in bytes.*/ 130 | uint8_t bDescriptorType; /**<\brief DFU functional descriptor type.*/ 131 | uint8_t bmAttributes; /**<\brief USB DFU capabilities \ref USB_DFU_CAPAB*/ 132 | uint16_t wDetachTimeout; /**<\brief USB DFU detach timeout in ms.*/ 133 | uint16_t wTransferSize; /**<\brief USB DFU maximum transfer block size in bytes.*/ 134 | uint16_t bcdDFUVersion; /**<\brief USB DFU version \ref VERSION_BCD utility macro.*/ 135 | }__attribute__((packed)); 136 | 137 | /**\brief Payload packet to response in DFU_GETSTATUS request */ 138 | struct usb_dfu_status { 139 | uint8_t bStatus; /**<\brief An indication of the status resulting from the 140 | * execution of the most recent request.*/ 141 | uint8_t bPollTimeout; /**<\brief Minimum time (LSB) in ms, that the host should wait 142 | * before sending a subsequent DFU_GETSTATUS request.*/ 143 | uint16_t wPollTimeout; /**<\brief Minimum time (MSB) in ms, that the host should wait 144 | * before sending a subsequent DFU_GETSTATUS request.*/ 145 | uint8_t bState; /**<\brief An indication of the state that the device is going 146 | * to enter immediately following transmission of this response.*/ 147 | uint8_t iString; /**<\brief Index of the status string descriptor.*/ 148 | }; 149 | 150 | /** @} */ 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | #endif /* _USB_DFU_H_ */ 156 | -------------------------------------------------------------------------------- /inc/usb_tmc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmitrystu/libusb_stm32/397c0517a30d9715d76006d8ae59c8ffa16eaec5/inc/usb_tmc.h -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "libusb_stm32", 3 | "description": "Lightweight USB Device Stack", 4 | "version": "0.1.0", 5 | "keywords": "stm32, usb", 6 | "authors": { 7 | "name": "Dmitry Filimonchuk", 8 | "email": "dmitrystu@gmail.com" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/dmitrystu/libusb_stm32.git" 13 | }, 14 | "platforms": [ "ststm32" ], 15 | "headers": ["stm32_compat.h", "usb.h"], 16 | "build": { "includeDir": "inc" } 17 | } 18 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ![LNX build](https://github.com/dmitrystu/libusb_stm32/workflows/LNX%20build/badge.svg) 2 | ![WIN build](https://github.com/dmitrystu/libusb_stm32/workflows/WIN%20build/badge.svg) 3 | ![OSX build](https://github.com/dmitrystu/libusb_stm32/workflows/OSX%20build/badge.svg) 4 | 5 | ### Lightweight USB Device Stack ### 6 | 7 | + Lightweight and fast 8 | + Event-driven process workflow 9 | + Completely separated USB hardware driver and usb core 10 | + Easy to use. 11 | 12 | ### Requirements ### 13 | 14 | + [CMSIS V4](https://github.com/ARM-software/CMSIS) or [CMSIS V5](https://github.com/ARM-software/CMSIS_5). 15 | + [stm32.h](https://github.com/dmitrystu/stm32h) STM32 universal header 16 | 17 | All requirements can be downloaded into a directory specified in environment variable `CMSIS` using 18 | `make cmsis` command. 19 | 20 | ### Supported hardware ### 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 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 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 |
MCU SeriesFeaturesDriverFile
STM32L0x2 STM32L0x3 STM32F070 STM32F0x2 STM32F0x8Doublebuffered[2]
8[1] endpoints
BC1.2
usbd_devfsusbd_stm32l052_devfs.c
usbd_devfs_asmusbd_stm32l052_devfs_asm.S
STM32L4x2 STM32L4x3 STM32G4 seriesDoublebuffered[2]
8[1] endpoints
BC1.2
usbd_devfsusbd_stm32l433_devfs.c
usbd_devfs_asmusbd_stm32l052_devfs_asm.S
STM32L1xxDoublebuffered[2]
8[1] endpoints
usbd_devfsusbd_stm32l100_devfs.c
usbd_devfs_asmusbd_stm32l100_devfs_asm.S
STM32F102 STM32F103 STM32F302 STM32F303 STM32F373Doublebuffered[2]
External DP pullup
8[1] endpoints
usbd_devfsusbd_stm32f103_devfs.c
usbd_devfs_asmusbd_stm32f103_devfs_asm.S
STM32WB55Doublebuffered[2]
External DP pullup
8[1] endpoints
usbd_devfsusbd_stm32wb55_devfs.c
STM32L4x5 STM32L4x6Doublebuffered
6 endpoints
BC1.2
VBUS detection
usbd_otgfsusbd_stm32l476_otgfs.c
STM32F401 STM32F411Doublebuffered
4 endpoints
VBUS detection
SOF output
usbd_otgfsusbd_stm32f429_otgfs.c
STM32F4x5 STM32F4x7 STM32F4x9Doublebuffered
4 endpoints
VBUS detection
SOF output
usbd_otgfsusbd_stm32f429_otgfs.c
Doublebuffered
6 endpoints
VBUS detection
SOF output
usbd_otghsusbd_stm32f429_otghs.c
STM32F105 STM32F107Doublebuffered
4 endpoints
VBUS detection
SOF output
usbd_otgfsusbd_stm32f105_otgfs.c
STM32F4x6 STM32F7Doublebuffered
6 endpoints
VBUS detection
SOF output
usbd_otgfsusbd_stm32f446_otgfs.c
Doublebuffered
9 endpoints
VBUS detection
SOF output
usbd_otghsusbd_stm32f446_otghs.c
STM32H743Doublebuffered
6 endpoints
VBUS detection
SOF output
usbd_otgfsusbd_stm32h743_otgfs.c
117 | 118 | 1. Single physical endpoint can be used to implement 119 | + one bi-directional/single-buffer logical endpoint (CONTROL) 120 | + one uni-directional/double-buffer logical endpoint (BULK OR ISOCHRONOUS) 121 | + two uni-directional/single-buffer logical endpoints (BULK OR INTERRUPT) 122 | 123 | 2. At this moment BULK IN endpoint can use both buffers, but it is not **real** doublebuffered. 124 | 125 | 3. Tested with STM32L052K8, STM32L100RC, STM32L476RG, STM32F072C8, STM32F103C8, STM32F103CB, 126 | STM32F303CC, STM32F303RE, STM32F429ZI, STM32F105RBT6, STM32F107VCT6, STM32L433CCT6, STM32F070CBT6, 127 | STM32G431RB, STM32F411CEUx, STM32F405RG, STM32F446RE, STM32F373CC, STM32L053R8, GD32F103C8T6, 128 | STM32F745VE, STM32F401CE, STM32H743. 129 | See [hardware.md](hardware.md) for details. 130 | 131 | ### Don't copy-paste the startup code from the demo without considering RCC and USB clock requirements. 132 | The HSI oscillator usually does not meet the timing requirements for USB and may cause performance loss 133 | and a high error rate. 134 | 135 | ### Implemented definitions for classes ### 136 | 1. USB HID based on [Device Class Definition for Human Interface Devices (HID) Version 1.11](https://www.usb.org/sites/default/files/documents/hid1_11.pdf) 137 | 2. USB DFU based on [USB Device Firmware Upgrade Specification, Revision 1.1](https://www.usb.org/sites/default/files/DFU_1.1.pdf) 138 | 3. USB CDC based on [Class definitions for Communication Devices 1.2](https://www.usb.org/sites/default/files/CDC1.2_WMC1.1_012011.zip) 139 | 4. USB TMC based on [USB Device Test and Measurement Class Specification, Revision 1.0](https://www.usb.org/sites/default/files/USBTMC_1_006a.zip) 140 | 141 | ### Using makefile ### 142 | + to build library module 143 | ``` 144 | make module MODULE=path/module.a DEFINES="mcu specified defines" CFLAGS="cpu specified compiler flags" 145 | ``` 146 | + to build demo 147 | ``` 148 | make bluepill program 149 | make stm32l052x8 150 | ``` 151 | + to get a help 152 | ``` 153 | make help 154 | ``` 155 | 156 | ### Default values: ### 157 | | Variable | Default Value | Means | 158 | |----------|-------------------------------------|-------------------------------| 159 | | CMSIS | ./CMSIS | path to CMSIS root folder | 160 | | CMSISDEV | $(CMSIS)/Device | path to CMSIS device folder | 161 | | CMSISCORE| $(CMSIS)/CMSIS/Include $(CMSIS)/CMSIS/Core/Include | path to CMSIS core headers | 162 | | MCU | stm32l100xc | MCU selection for demo project| 163 | | CFLAGS | -mcpu=cortex-m3 -mfloat-abi=soft | MCU specified compiler flags | 164 | | DEFINES | STM32L1 STM32L100xC | MCU specified defines | 165 | | STPROG_CLI | ~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI | Path to the ST Cube Programmer CLI | 166 | | OPTFLAGS | -Os | Code optimization flags | 167 | 168 | ### Useful Resources ### 169 | 1. [USB Implementers Forum official site](https://www.usb.org/) 170 | 2. [USB Made Simple](http://www.usbmadesimple.co.uk/) 171 | 3. [LUFA - the Lightweight USB Framework for AVRs.](https://github.com/abcminiuser/lufa) 172 | 4. [Open Source ARM cortex m microcontroller library](https://github.com/libopencm3/libopencm3) 173 | -------------------------------------------------------------------------------- /src/memmap.inc: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #if defined(STM32L052xx) || defined(STM32L053xx) || \ 17 | defined(STM32L062xx) || defined(STM32L063xx) || \ 18 | defined(STM32L072xx) || defined(STM32L073xx) || \ 19 | defined(STM32L082xx) || defined(STM32L083xx) || \ 20 | defined(STM32F042x6) || defined(STM32F048xx) || \ 21 | defined(STM32F070x6) || defined(STM32F070xB) || \ 22 | defined(STM32F072xB) || defined(STM32F078xx) 23 | 24 | #define USB_EPBASE 0x40005C00 25 | #define USB_REGBASE 0x40005C40 26 | #define USB_CNTR 0x00 27 | #define USB_ISTR 0x04 28 | #define USB_FNR 0x08 29 | #define USB_DADDR 0x0C 30 | #define USB_BTABLE 0x10 31 | #define USB_BCDR 0x18 32 | #define USB_PMABASE 0x40006000 33 | #define RCC_BASE 0x40021000 34 | #define RCC_USBEN 23 35 | #if defined(STM32F042x6) || defined(STM32F048xx) || \ 36 | defined(STM32F070x6) || defined(STM32F070xB) || \ 37 | defined(STM32F072xB) || defined(STM32F078xx) 38 | #define RCC_APB1RSTR 0x10 39 | #define RCC_APB1ENR 0x1C 40 | #define RCC_APB2ENR 0x18 41 | #define UID_BASE 0x1FFFF7AC 42 | #else 43 | #define RCC_APB1RSTR 0x28 44 | #define RCC_APB1ENR 0x38 45 | #define UID_BASE 0x1FF80050 46 | #endif 47 | 48 | #if defined(STM32F042x6) || defined(STM32F048xx) || \ 49 | defined(STM32F070x6) 50 | 51 | #define SYSCFG_BASE 0x40010000 52 | #define SYSCFG_USBREMAP 4 53 | #endif 54 | 55 | #elif defined(STM32L432xx) || defined(STM32L433xx) || \ 56 | defined(STM32L442xx) || defined(STM32L443xx) || \ 57 | defined(STM32L452xx) || defined(STM32L462xx) 58 | 59 | #define USB_EPBASE 0x40006800 60 | #define USB_REGBASE 0x40006840 61 | #define USB_CNTR 0x00 62 | #define USB_ISTR 0x04 63 | #define USB_FNR 0x08 64 | #define USB_DADDR 0x0C 65 | #define USB_BTABLE 0x10 66 | #define USB_BCDR 0x18 67 | #define USB_PMABASE 0x40006C00 68 | #define RCC_BASE 0x40021000 69 | #define RCC_APB1RSTR 0x38 70 | #define RCC_APB1ENR 0x58 71 | #define UID_BASE 0x1FFF7590 72 | #define RCC_USBEN 26 73 | 74 | #elif defined(STM32G4) 75 | 76 | #define USB_EPBASE 0x40005C00 77 | #define USB_REGBASE 0x40005C40 78 | #define USB_CNTR 0x00 79 | #define USB_ISTR 0x04 80 | #define USB_FNR 0x08 81 | #define USB_DADDR 0x0C 82 | #define USB_BTABLE 0x10 83 | #define USB_BCDR 0x18 84 | #define USB_PMABASE 0x40006000 85 | #define RCC_BASE 0x40021000 86 | #define RCC_APB1RSTR 0x38 87 | #define RCC_APB1ENR 0x58 88 | #define UID_BASE 0x1FFF7590 89 | #define RCC_USBEN 23 90 | 91 | #elif defined(STM32L1) 92 | /* common definitions for STM31L100xx STM32L151xx STM32L152xx STM32L162xx */ 93 | #define USB_EPBASE 0x40005C00 94 | #define USB_REGBASE 0x40005C40 95 | #define USB_CNTR 0x00 96 | #define USB_ISTR 0x04 97 | #define USB_FNR 0x08 98 | #define USB_DADDR 0x0C 99 | #define USB_BTABLE 0x10 100 | #define USB_PMABASE 0x40006000 101 | #define SYSCFG_BASE 0x40010000 102 | #define SYSCFG_PMC 0x04 103 | #define RCC_BASE 0x40023800 104 | #define RCC_APB1ENR 0x24 105 | #define RCC_APB1RSTR 0x18 106 | #define RCC_APB2ENR 0x20 107 | #if defined(STM32L100xB) || defined(STM32L100xBA) || \ 108 | defined(STM32L151xB) || defined(STM32L151xBA) 109 | /* Cat.1 and Cat.2 devices */ 110 | #define UID_BASE 0x1FF80050 111 | #else 112 | #define UID_BASE 0x1FF800D0 113 | #endif 114 | #elif defined(STM32F102x6) || defined(STM32F102xB) || \ 115 | defined(STM32F103x6) || defined(STM32F103xB) || \ 116 | defined(STM32F103xE) || defined(STM32F103xG) 117 | #define USB_EPBASE 0x40005C00 118 | #define USB_REGBASE 0x40005C40 119 | #define USB_CNTR 0x00 120 | #define USB_ISTR 0x04 121 | #define USB_FNR 0x08 122 | #define USB_DADDR 0x0C 123 | #define USB_BTABLE 0x10 124 | #define USB_PMABASE 0x40006000 125 | #define RCC_BASE 0x40021000 126 | #define RCC_APB1RSTR 0x10 127 | #define RCC_APB2ENR 0x18 128 | #define RCC_APB1ENR 0x1C 129 | #define RCC_GPIOAEN 0x02 130 | #define RCC_GPIOBEN 0x03 131 | #define RCC_GPIOCEN 0x04 132 | #define RCC_GPIODEN 0x05 133 | #define RCC_GPIOEEN 0x06 134 | #define RCC_GPIOFEN 0x07 135 | 136 | #define UID_BASE 0x1FFFF7E8 137 | #define GPIOA 0x40010800 138 | #define GPIOB 0x40010C00 139 | #define GPIOC 0x40011000 140 | #define GPIOD 0x40011400 141 | #define GPIOE 0x40011800 142 | #define GPIOF 0x40011C00 143 | #define GPIOG 0x40012000 144 | #define GPIO_CRL 0x00 145 | #define GPIO_CRH 0x04 146 | #define GPIO_IDR 0x08 147 | #define GPIO_BSRR 0x10 148 | 149 | 150 | #elif defined(STM32F303x8) || defined(STM32F303xC) || \ 151 | defined(STM32F303xE) || defined(STM32F373xC) 152 | 153 | #define USB_EPBASE 0x40005C00 154 | #define USB_REGBASE 0x40005C40 155 | #define USB_CNTR 0x00 156 | #define USB_ISTR 0x04 157 | #define USB_FNR 0x08 158 | #define USB_DADDR 0x0C 159 | #define USB_BTABLE 0x10 160 | #define USB_PMABASE 0x40006000 161 | 162 | #define RCC_BASE 0x40021000 163 | #define RCC_APB1ENR 0x1C 164 | #define RCC_APB1RSTR 0x10 165 | #define RCC_AHBENR 0x14 166 | #define RCC_GPIOAEN 0x11 167 | #define RCC_GPIOBEN 0x12 168 | #define RCC_GPIOCEN 0x13 169 | #define RCC_GPIODEN 0x14 170 | #define RCC_GPIOEEN 0x15 171 | #define RCC_GPIOFEN 0x16 172 | #define RCC_GPIOGEN 0x17 173 | #define RCC_GPIOHEN 0x10 174 | 175 | #define UID_BASE 0x1FFFF7AC 176 | 177 | #define GPIOA 0x48000000 178 | #define GPIOB 0x48000400 179 | #define GPIOC 0x48000800 180 | #define GPIOD 0x48000C00 181 | #define GPIOE 0x48001000 182 | #define GPIOF 0x48001400 183 | #define GPIO_MODER 0x00 184 | #define GPIO_BSRR 0x18 185 | 186 | #else 187 | #error Unsupported MCU 188 | #endif 189 | 190 | 191 | -------------------------------------------------------------------------------- /src/usbd_core.c: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include 17 | #include 18 | #include "usb.h" 19 | 20 | #define _MIN(a, b) ((a) < (b)) ? (a) : (b) 21 | 22 | static void usbd_process_ep0 (usbd_device *dev, uint8_t event, uint8_t ep); 23 | 24 | /** \brief Resets USB device state 25 | * \param dev pointer to usb device 26 | * \return none 27 | */ 28 | static void usbd_process_reset(usbd_device *dev) { 29 | dev->status.device_state = usbd_state_default; 30 | dev->status.control_state = usbd_ctl_idle; 31 | dev->status.device_cfg = 0; 32 | dev->driver->ep_config(0, USB_EPTYPE_CONTROL, dev->status.ep0size); 33 | dev->endpoint[0] = usbd_process_ep0; 34 | dev->driver->setaddr(0); 35 | } 36 | 37 | /** \brief Callback that sets USB device address 38 | * \param dev pointer to usb device 39 | * \param req pointer to usb control request data 40 | * \return none 41 | */ 42 | static void usbd_set_address (usbd_device *dev, usbd_ctlreq *req) { 43 | dev->driver->setaddr(req->wValue); 44 | dev->status.device_state = (req->wValue) ? usbd_state_addressed : usbd_state_default; 45 | } 46 | 47 | /** \brief Control transfer completion callback processing 48 | * \param dev pointer to the usb device 49 | * \return none 50 | */ 51 | static void usbd_process_callback (usbd_device *dev) { 52 | if (dev->complete_callback) { 53 | dev->complete_callback(dev, dev->status.data_buf); 54 | dev->complete_callback = 0; 55 | } 56 | } 57 | 58 | /** \brief SET_CONFIG request processing 59 | * \param dev usbd_device 60 | * \param config config number from request 61 | * \return usbd_ack if success 62 | */ 63 | static usbd_respond usbd_configure(usbd_device *dev, uint8_t config) { 64 | if (dev->config_callback) { 65 | if (dev->config_callback(dev, config) == usbd_ack) { 66 | dev->status.device_cfg = config; 67 | dev->status.device_state = (config) ? usbd_state_configured : usbd_state_addressed; 68 | return usbd_ack; 69 | } 70 | } 71 | return usbd_fail; 72 | } 73 | 74 | 75 | /** \brief Standard control request processing for device 76 | * \param dev pointer to usb device 77 | * \param req pointer to control request 78 | * \return TRUE if request is handled 79 | */ 80 | static usbd_respond usbd_process_devrq (usbd_device *dev, usbd_ctlreq *req) { 81 | switch (req->bRequest) { 82 | case USB_STD_CLEAR_FEATURE: 83 | /* not yet supported */ 84 | break; 85 | case USB_STD_GET_CONFIG: 86 | req->data[0] = dev->status.device_cfg; 87 | return usbd_ack; 88 | case USB_STD_GET_DESCRIPTOR: 89 | if (req->wValue == ((USB_DTYPE_STRING << 8) | INTSERIALNO_DESCRIPTOR )) { 90 | dev->status.data_count = dev->driver->get_serialno_desc(req->data); 91 | return usbd_ack; 92 | } else { 93 | if (dev->descriptor_callback) { 94 | return dev->descriptor_callback(req, &(dev->status.data_ptr), &(dev->status.data_count)); 95 | } 96 | } 97 | break; 98 | case USB_STD_GET_STATUS: 99 | req->data[0] = 0; 100 | req->data[1] = 0; 101 | return usbd_ack; 102 | case USB_STD_SET_ADDRESS: 103 | if (usbd_getinfo(dev) & USBD_HW_ADDRFST) { 104 | usbd_set_address(dev, req); 105 | } else { 106 | dev->complete_callback = usbd_set_address; 107 | } 108 | return usbd_ack; 109 | case USB_STD_SET_CONFIG: 110 | return usbd_configure(dev, req->wValue); 111 | case USB_STD_SET_DESCRIPTOR: 112 | /* should be externally handled */ 113 | break; 114 | case USB_STD_SET_FEATURE: 115 | /* not yet supported */ 116 | break; 117 | default: 118 | break; 119 | } 120 | return usbd_fail; 121 | } 122 | 123 | /** \brief Standard control request processing for interface 124 | * \param dev pointer to usb device 125 | * \param req pointer to control request 126 | * \return TRUE if request is handled 127 | */ 128 | static usbd_respond usbd_process_intrq(usbd_device *dev, usbd_ctlreq *req) { 129 | (void)dev; 130 | switch (req->bRequest) { 131 | case USB_STD_GET_STATUS: 132 | req->data[0] = 0; 133 | req->data[1] = 0; 134 | return usbd_ack; 135 | default: 136 | break; 137 | } 138 | return usbd_fail; 139 | } 140 | 141 | /** \brief Standard control request processing for endpoint 142 | * \param dev pointer to usb device 143 | * \param req pointer to control request 144 | * \return TRUE if request is handled 145 | */ 146 | static usbd_respond usbd_process_eptrq(usbd_device *dev, usbd_ctlreq *req) { 147 | switch (req->bRequest) { 148 | case USB_STD_SET_FEATURE: 149 | dev->driver->ep_setstall(req->wIndex, 1); 150 | return usbd_ack; 151 | case USB_STD_CLEAR_FEATURE: 152 | dev->driver->ep_setstall(req->wIndex, 0); 153 | return usbd_ack; 154 | case USB_STD_GET_STATUS: 155 | req->data[0] = dev->driver->ep_isstalled(req->wIndex) ? 1 : 0; 156 | req->data[1] = 0; 157 | return usbd_ack; 158 | default: 159 | break; 160 | } 161 | return usbd_fail; 162 | } 163 | 164 | /** \brief Processing control request 165 | * \param dev pointer to usb device 166 | * \param req pointer to usb control request 167 | * \return TRUE if request is handled 168 | */ 169 | static usbd_respond usbd_process_request(usbd_device *dev, usbd_ctlreq *req) { 170 | /* processing control request by callback */ 171 | if (dev->control_callback) { 172 | usbd_respond r = dev->control_callback(dev, req, &(dev->complete_callback)); 173 | if (r != usbd_fail) return r; 174 | } 175 | /* continuing standard USB requests */ 176 | switch (req->bmRequestType & (USB_REQ_TYPE | USB_REQ_RECIPIENT)) { 177 | case USB_REQ_STANDARD | USB_REQ_DEVICE: 178 | return usbd_process_devrq(dev, req); 179 | case USB_REQ_STANDARD | USB_REQ_INTERFACE: 180 | return usbd_process_intrq(dev, req); 181 | case USB_REQ_STANDARD | USB_REQ_ENDPOINT: 182 | return usbd_process_eptrq(dev, req); 183 | default: 184 | break; 185 | } 186 | return usbd_fail; 187 | } 188 | 189 | 190 | /** \brief Control endpoint stall (STALL PID) 191 | * \param dev pointer to usb device 192 | * \param ep endpoint number 193 | */ 194 | static void usbd_stall_pid(usbd_device *dev, uint8_t ep) { 195 | dev->driver->ep_setstall(ep & 0x7F, 1); 196 | dev->driver->ep_setstall(ep | 0x80, 1); 197 | dev->status.control_state = usbd_ctl_idle; 198 | } 199 | 200 | 201 | /** \brief Control endpoint TX event processing 202 | * \param dev pointer to usb device 203 | * \param ep endpoint number 204 | */ 205 | static void usbd_process_eptx(usbd_device *dev, uint8_t ep) { 206 | int32_t _t; 207 | switch (dev->status.control_state) { 208 | case usbd_ctl_ztxdata: 209 | case usbd_ctl_txdata: 210 | _t = _MIN(dev->status.data_count, dev->status.ep0size); 211 | dev->driver->ep_write(ep, dev->status.data_ptr, _t); 212 | dev->status.data_ptr = (uint8_t*)dev->status.data_ptr + _t; 213 | dev->status.data_count -= _t; 214 | /* if all data is not sent */ 215 | if (0 != dev->status.data_count) break; 216 | /* if last packet has a EP0 size and host awaiting for the more data ZLP should be sent*/ 217 | /* if ZLP required, control state will be unchanged, therefore next TX event sends ZLP */ 218 | if ( usbd_ctl_txdata == dev->status.control_state || _t != dev->status.ep0size ) { 219 | dev->status.control_state = usbd_ctl_lastdata; /* no ZLP required */ 220 | } 221 | break; 222 | case usbd_ctl_lastdata: 223 | dev->status.control_state = usbd_ctl_statusout; 224 | break; 225 | case usbd_ctl_statusin: 226 | dev->status.control_state = usbd_ctl_idle; 227 | usbd_process_callback(dev); 228 | break; 229 | default: 230 | /* unexpected TX completion */ 231 | /* just skipping it */ 232 | break; 233 | } 234 | } 235 | 236 | /** \brief Control endpoint RX event processing 237 | * \param dev pointer to usb device 238 | * \param ep endpoint number 239 | */ 240 | static void usbd_process_eprx(usbd_device *dev, uint8_t ep) { 241 | uint16_t _t; 242 | usbd_ctlreq *const req = dev->status.data_buf; 243 | switch (dev->status.control_state) { 244 | case usbd_ctl_idle: 245 | /* read SETUP packet, send STALL_PID if incorrect packet length */ 246 | if (0x08 != dev->driver->ep_read(ep, req, dev->status.data_maxsize)) { 247 | usbd_stall_pid(dev, ep); 248 | return; 249 | } 250 | dev->status.data_ptr = req->data; 251 | dev->status.data_count = req->wLength; 252 | /* processing request with no payload data*/ 253 | if ((req->bmRequestType & USB_REQ_DEVTOHOST) || (0 == req->wLength)) break; 254 | /* checking available memory for DATA OUT stage */ 255 | if (req->wLength > dev->status.data_maxsize) { 256 | usbd_stall_pid(dev, ep); 257 | return; 258 | } 259 | /* continue DATA OUT stage */ 260 | dev->status.control_state = usbd_ctl_rxdata; 261 | return; 262 | case usbd_ctl_rxdata: 263 | /*receive DATA OUT packet(s) */ 264 | _t = dev->driver->ep_read(ep, dev->status.data_ptr, dev->status.data_count); 265 | if (dev->status.data_count < _t) { 266 | /* if received packet is large than expected */ 267 | /* Must be error. Let's drop this request */ 268 | usbd_stall_pid(dev, ep); 269 | return; 270 | } else if (dev->status.data_count != _t) { 271 | /* if all data payload was not received yet */ 272 | dev->status.data_count -= _t; 273 | dev->status.data_ptr = (uint8_t*)dev->status.data_ptr + _t; 274 | return; 275 | } 276 | break; 277 | case usbd_ctl_statusout: 278 | /* fake reading STATUS OUT */ 279 | dev->driver->ep_read(ep, 0, 0); 280 | dev->status.control_state = usbd_ctl_idle; 281 | usbd_process_callback(dev); 282 | return; 283 | default: 284 | /* unexpected RX packet */ 285 | usbd_stall_pid(dev, ep); 286 | return; 287 | } 288 | /* usb request received. let's handle it */ 289 | dev->status.data_ptr = req->data; 290 | dev->status.data_count = /*req->wLength;*/dev->status.data_maxsize; 291 | switch (usbd_process_request(dev, req)) { 292 | case usbd_ack: 293 | if (req->bmRequestType & USB_REQ_DEVTOHOST) { 294 | /* return data from function */ 295 | if (dev->status.data_count >= req->wLength) { 296 | dev->status.data_count = req->wLength; 297 | dev->status.control_state = usbd_ctl_txdata; 298 | } else { 299 | /* DATA IN packet smaller than requested */ 300 | /* ZLP maybe wanted */ 301 | dev->status.control_state = usbd_ctl_ztxdata; 302 | } 303 | usbd_process_eptx(dev, ep | 0x80); 304 | } else { 305 | /* confirming by ZLP in STATUS_IN stage */ 306 | dev->driver->ep_write(ep | 0x80, 0, 0); 307 | dev->status.control_state = usbd_ctl_statusin; 308 | } 309 | break; 310 | case usbd_nak: 311 | dev->status.control_state = usbd_ctl_statusin; 312 | break; 313 | default: 314 | usbd_stall_pid(dev, ep); 315 | break; 316 | } 317 | } 318 | 319 | /** \brief Control endpoint 0 event processing callback 320 | * \param dev usb device 321 | * \param event endpoint event 322 | */ 323 | static void usbd_process_ep0 (usbd_device *dev, uint8_t event, uint8_t ep) { 324 | switch (event) { 325 | case usbd_evt_epsetup: 326 | /* force switch to setup state */ 327 | dev->status.control_state = usbd_ctl_idle; 328 | dev->complete_callback = 0; 329 | /* fall through */ 330 | case usbd_evt_eprx: 331 | usbd_process_eprx(dev, ep); 332 | break; 333 | case usbd_evt_eptx: 334 | usbd_process_eptx(dev, ep); 335 | break; 336 | default: 337 | break; 338 | } 339 | } 340 | 341 | 342 | /** \brief General event processing callback 343 | * \param dev usb device 344 | * \param evt usb event 345 | * \param ep active endpoint 346 | */ 347 | static void usbd_process_evt(usbd_device *dev, uint8_t evt, uint8_t ep) { 348 | switch (evt) { 349 | case usbd_evt_reset: 350 | usbd_process_reset(dev); 351 | break; 352 | case usbd_evt_eprx: 353 | case usbd_evt_eptx: 354 | case usbd_evt_epsetup: 355 | if (dev->endpoint[ep & 0x07]) dev->endpoint[ep & 0x07](dev, evt, ep); 356 | break; 357 | default: 358 | break; 359 | } 360 | if (dev->events[evt]) dev->events[evt](dev, evt, ep); 361 | } 362 | 363 | __attribute__((externally_visible)) void usbd_poll(usbd_device *dev) { 364 | dev->driver->poll(dev, usbd_process_evt); 365 | } 366 | -------------------------------------------------------------------------------- /src/usbd_stm32l100_devfs.c: -------------------------------------------------------------------------------- 1 | /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers 2 | * 3 | * Copyright ©2016 Dmitry Filimonchuk 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include 17 | #include 18 | #include "stm32_compat.h" 19 | #include "usb.h" 20 | 21 | #if defined(USBD_STM32L100) 22 | 23 | #ifndef USB_PMASIZE 24 | #pragma message "PMA memory size is not defined. Use 512 bytes by default" 25 | #define USB_PMASIZE 0x200 26 | #endif 27 | 28 | #define USB_EP_SWBUF_TX USB_EP_DTOG_RX 29 | #define USB_EP_SWBUF_RX USB_EP_DTOG_TX 30 | 31 | #define EP_TOGGLE_SET(epr, bits, mask) *(epr) = (*(epr) ^ (bits)) & (USB_EPREG_MASK | (mask)) 32 | 33 | #define EP_TX_STALL(epr) EP_TOGGLE_SET((epr), USB_EP_TX_STALL, USB_EPTX_STAT) 34 | #define EP_RX_STALL(epr) EP_TOGGLE_SET((epr), USB_EP_RX_STALL, USB_EPRX_STAT) 35 | #define EP_TX_UNSTALL(epr) EP_TOGGLE_SET((epr), USB_EP_TX_NAK, USB_EPTX_STAT | USB_EP_DTOG_TX) 36 | #define EP_RX_UNSTALL(epr) EP_TOGGLE_SET((epr), USB_EP_RX_VALID, USB_EPRX_STAT | USB_EP_DTOG_RX) 37 | #define EP_DTX_UNSTALL(epr) EP_TOGGLE_SET((epr), USB_EP_TX_VALID, USB_EPTX_STAT | USB_EP_DTOG_TX | USB_EP_SWBUF_TX) 38 | #define EP_DRX_UNSTALL(epr) EP_TOGGLE_SET((epr), USB_EP_RX_VALID | USB_EP_SWBUF_RX, USB_EPRX_STAT | USB_EP_DTOG_RX | USB_EP_SWBUF_RX) 39 | #define EP_TX_VALID(epr) EP_TOGGLE_SET((epr), USB_EP_TX_VALID, USB_EPTX_STAT) 40 | #define EP_RX_VALID(epr) EP_TOGGLE_SET((epr), USB_EP_RX_VALID, USB_EPRX_STAT) 41 | 42 | #define STATUS_VAL(x) (x) 43 | 44 | typedef struct { 45 | uint16_t addr; 46 | uint16_t :16; 47 | uint16_t cnt; 48 | uint16_t :16; 49 | } pma_rec; 50 | 51 | typedef union pma_table { 52 | struct { 53 | pma_rec tx; 54 | pma_rec rx; 55 | }; 56 | struct { 57 | pma_rec tx0; 58 | pma_rec tx1; 59 | }; 60 | struct { 61 | pma_rec rx0; 62 | pma_rec rx1; 63 | }; 64 | } pma_table; 65 | 66 | 67 | /** \brief Helper function. Returns pointer to the buffer descriptor table. 68 | */ 69 | inline static pma_table *EPT(uint8_t ep) { 70 | return (pma_table*)((ep & 0x07) * 16 + USB_PMAADDR); 71 | } 72 | 73 | /** \brief Helper function. Returns pointer to the endpoint control register. 74 | */ 75 | inline static volatile uint16_t *EPR(uint8_t ep) { 76 | return (uint16_t*)((ep & 0x07) * 4 + USB_BASE); 77 | } 78 | 79 | 80 | /** \brief Helper function. Returns next available PMA buffer. 81 | * 82 | * \param sz uint16_t Requested buffer size. 83 | * \return uint16_t Buffer address for PMA table. 84 | * \note PMA buffers grown from top to bottom like stack. 85 | */ 86 | static uint16_t get_next_pma(uint16_t sz) { 87 | unsigned _result = USB_PMASIZE; 88 | for (int i = 0; i < 8; i++) { 89 | pma_table *tbl = EPT(i); 90 | if ((tbl->tx.addr) && (tbl->tx.addr < _result)) _result = tbl->tx.addr; 91 | if ((tbl->rx.addr) && (tbl->rx.addr < _result)) _result = tbl->rx.addr; 92 | } 93 | return (_result < (0x020U + sz)) ? 0 : (_result - sz); 94 | } 95 | 96 | static uint32_t getinfo(void) { 97 | if (!(RCC->APB1ENR & RCC_APB1ENR_USBEN)) return STATUS_VAL(0); 98 | if (SYSCFG->PMC & SYSCFG_PMC_USB_PU) return STATUS_VAL(USBD_HW_ENABLED | USBD_HW_SPEED_FS); 99 | return STATUS_VAL(USBD_HW_ENABLED); 100 | } 101 | 102 | static void ep_setstall(uint8_t ep, bool stall) { 103 | volatile uint16_t *reg = EPR(ep); 104 | /* ISOCHRONOUS endpoint can't be stalled or unstalled */ 105 | if (USB_EP_ISOCHRONOUS == (*reg & USB_EP_T_FIELD)) return; 106 | /* If it's an IN endpoint */ 107 | if (ep & 0x80) { 108 | /* DISABLED endpoint can't be stalled or unstalled */ 109 | if (USB_EP_TX_DIS == (*reg & USB_EPTX_STAT)) return; 110 | if (stall) { 111 | EP_TX_STALL(reg); 112 | } else { 113 | /* if it's a doublebuffered endpoint */ 114 | if ((USB_EP_KIND | USB_EP_BULK) == (*reg & (USB_EP_T_FIELD | USB_EP_KIND))) { 115 | /* set endpoint to VALID and clear DTOG_TX & SWBUF_TX */ 116 | EP_DTX_UNSTALL(reg); 117 | } else { 118 | /* set endpoint to NAKED and clear DTOG_TX */ 119 | EP_TX_UNSTALL(reg); 120 | } 121 | } 122 | } else { 123 | if (USB_EP_RX_DIS == (*reg & USB_EPRX_STAT)) return; 124 | if (stall) { 125 | EP_RX_STALL(reg); 126 | } else { 127 | /* if it's a doublebuffered endpoint */ 128 | if ((USB_EP_KIND | USB_EP_BULK) == (*reg & (USB_EP_T_FIELD | USB_EP_KIND))) { 129 | /* set endpoint to VALID, clear DTOG_RX, set SWBUF_RX */ 130 | EP_DRX_UNSTALL(reg); 131 | } else { 132 | /* set endpoint to VALID and clear DTOG_RX */ 133 | EP_RX_UNSTALL(reg); 134 | } 135 | } 136 | } 137 | } 138 | 139 | static bool ep_isstalled(uint8_t ep) { 140 | if (ep & 0x80) { 141 | return (USB_EP_TX_STALL == (USB_EPTX_STAT & *EPR(ep))); 142 | } else { 143 | return (USB_EP_RX_STALL == (USB_EPRX_STAT & *EPR(ep))); 144 | } 145 | } 146 | 147 | static void enable(bool enable) { 148 | if (enable) { 149 | RCC->APB1ENR |= RCC_APB1ENR_USBEN; 150 | RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; 151 | RCC->APB1RSTR |= RCC_APB1RSTR_USBRST; 152 | RCC->APB1RSTR &= ~RCC_APB1RSTR_USBRST; 153 | USB->CNTR = USB_CNTR_CTRM | USB_CNTR_RESETM | USB_CNTR_ERRM | 154 | #if !defined(USBD_SOF_DISABLED) 155 | USB_CNTR_SOFM | 156 | #endif 157 | USB_CNTR_SUSPM | USB_CNTR_WKUPM; 158 | } else if (RCC->APB1ENR & RCC_APB1ENR_USBEN) { 159 | SYSCFG->PMC &= ~SYSCFG_PMC_USB_PU; 160 | RCC->APB1RSTR |= RCC_APB1RSTR_USBRST; 161 | RCC->APB1ENR &= ~RCC_APB1ENR_USBEN; 162 | } 163 | } 164 | 165 | static uint8_t connect(bool connect) { 166 | if (connect) { 167 | SYSCFG->PMC |= SYSCFG_PMC_USB_PU; 168 | } else { 169 | SYSCFG->PMC &= ~SYSCFG_PMC_USB_PU; 170 | } 171 | return usbd_lane_unk; 172 | } 173 | 174 | static void setaddr (uint8_t addr) { 175 | USB->DADDR = USB_DADDR_EF | addr; 176 | } 177 | 178 | 179 | static bool ep_config(uint8_t ep, uint8_t eptype, uint16_t epsize) { 180 | volatile uint16_t *reg = EPR(ep); 181 | pma_table *tbl = EPT(ep); 182 | /* epsize must be 2-byte aligned */ 183 | epsize = (~0x01U) & (epsize + 1); 184 | 185 | switch (eptype) { 186 | case USB_EPTYPE_CONTROL: 187 | *reg = USB_EP_CONTROL | (ep & 0x07); 188 | break; 189 | case USB_EPTYPE_ISOCHRONUS: 190 | *reg = USB_EP_ISOCHRONOUS | (ep & 0x07); 191 | break; 192 | case USB_EPTYPE_BULK: 193 | *reg = USB_EP_BULK | (ep & 0x07); 194 | break; 195 | case USB_EPTYPE_BULK | USB_EPTYPE_DBLBUF: 196 | *reg = USB_EP_BULK | USB_EP_KIND | (ep & 0x07); 197 | break; 198 | default: 199 | *reg = USB_EP_INTERRUPT | (ep & 0x07); 200 | break; 201 | } 202 | /* if it TX or CONTROL endpoint */ 203 | if ((ep & 0x80) || (eptype == USB_EPTYPE_CONTROL)) { 204 | uint16_t _pma; 205 | _pma = get_next_pma(epsize); 206 | if (_pma == 0) return false; 207 | tbl->tx.addr = _pma; 208 | tbl->tx.cnt = 0; 209 | if ((eptype == USB_EPTYPE_ISOCHRONUS) || 210 | (eptype == (USB_EPTYPE_BULK | USB_EPTYPE_DBLBUF))) { 211 | _pma = get_next_pma(epsize); 212 | if (_pma == 0) return false; 213 | tbl->tx1.addr = _pma; 214 | tbl->tx1.cnt = 0; 215 | EP_DTX_UNSTALL(reg); 216 | } else { 217 | EP_TX_UNSTALL(reg); 218 | } 219 | } 220 | if (!(ep & 0x80)) { 221 | uint16_t _rxcnt; 222 | uint16_t _pma; 223 | if (epsize > 62) { 224 | /* using 32-byte blocks. epsize must be 32-byte aligned */ 225 | epsize = (~0x1FU) & (epsize + 0x1FU); 226 | _rxcnt = 0x8000 - 0x400 + (epsize << 5); 227 | } else { 228 | _rxcnt = epsize << 9; 229 | } 230 | _pma = get_next_pma(epsize); 231 | if (_pma == 0) return false; 232 | tbl->rx.addr = _pma; 233 | tbl->rx.cnt = _rxcnt; 234 | if ((eptype == USB_EPTYPE_ISOCHRONUS) || 235 | (eptype == (USB_EPTYPE_BULK | USB_EPTYPE_DBLBUF))) { 236 | _pma = get_next_pma(epsize); 237 | if (_pma == 0) return false; 238 | tbl->rx0.addr = _pma; 239 | tbl->rx0.cnt = _rxcnt; 240 | EP_DRX_UNSTALL(reg); 241 | } else { 242 | EP_RX_UNSTALL(reg); 243 | } 244 | } 245 | return true; 246 | } 247 | 248 | static void ep_deconfig(uint8_t ep) { 249 | pma_table *ept = EPT(ep); 250 | *EPR(ep) &= ~USB_EPREG_MASK; 251 | ept->rx.addr = 0; 252 | ept->rx.cnt = 0; 253 | ept->tx.addr = 0; 254 | ept->tx.cnt = 0; 255 | } 256 | 257 | static uint16_t pma_read (uint8_t *buf, uint16_t blen, pma_rec *rx) { 258 | uint16_t tmp = 0; 259 | uint16_t *pma = (void*)(USB_PMAADDR + 2 * rx->addr); 260 | uint16_t rxcnt = rx->cnt & 0x03FF; 261 | rx->cnt &= ~0x3FF; 262 | for(int idx = 0; idx < rxcnt; idx++) { 263 | if ((idx & 0x01) == 0) { 264 | tmp = *pma; 265 | pma += 2; 266 | } 267 | if (idx < blen) { 268 | buf[idx] = tmp & 0xFF; 269 | tmp >>= 8; 270 | } else { 271 | return blen; 272 | } 273 | } 274 | return rxcnt; 275 | } 276 | 277 | static int32_t ep_read(uint8_t ep, void *buf, uint16_t blen) { 278 | pma_table *tbl = EPT(ep); 279 | volatile uint16_t *reg = EPR(ep); 280 | switch (*reg & (USB_EPRX_STAT | USB_EP_T_FIELD | USB_EP_KIND)) { 281 | /* doublebuffered bulk endpoint */ 282 | case (USB_EP_RX_VALID | USB_EP_BULK | USB_EP_KIND): 283 | /* switching SWBUF if EP is NAKED */ 284 | switch (*reg & (USB_EP_DTOG_RX | USB_EP_SWBUF_RX)) { 285 | case 0: 286 | case (USB_EP_DTOG_RX | USB_EP_SWBUF_RX): 287 | *reg = (*reg & USB_EPREG_MASK) | USB_EP_SWBUF_RX; 288 | break; 289 | default: 290 | break; 291 | } 292 | if (*reg & USB_EP_SWBUF_RX) { 293 | return pma_read(buf, blen, &(tbl->rx1)); 294 | } else { 295 | return pma_read(buf, blen, &(tbl->rx0)); 296 | } 297 | /* isochronous endpoint */ 298 | case (USB_EP_RX_VALID | USB_EP_ISOCHRONOUS): 299 | if (*reg & USB_EP_DTOG_RX) { 300 | return pma_read(buf, blen, &(tbl->rx1)); 301 | } else { 302 | return pma_read(buf, blen, &(tbl->rx0)); 303 | } 304 | /* regular endpoint */ 305 | case (USB_EP_RX_NAK | USB_EP_BULK): 306 | case (USB_EP_RX_NAK | USB_EP_CONTROL): 307 | case (USB_EP_RX_NAK | USB_EP_INTERRUPT): 308 | { 309 | int32_t res = pma_read(buf, blen, &(tbl->rx)); 310 | /* setting endpoint to VALID state */ 311 | EP_RX_VALID(reg); 312 | return res; 313 | } 314 | /* invalid or not ready */ 315 | default: 316 | return -1; 317 | } 318 | } 319 | 320 | static void pma_write(const uint8_t *buf, uint16_t blen, pma_rec *tx) { 321 | uint16_t *pma = (void*)(USB_PMAADDR + 2 * (tx->addr)); 322 | uint16_t tmp = 0; 323 | tx->cnt = blen; 324 | for (int idx=0; idx < blen; idx++) { 325 | tmp |= buf[idx] << ((idx & 0x01) ? 8 : 0); 326 | if ((idx & 0x01) || (idx + 1) == blen) { 327 | *pma = tmp; 328 | pma += 2; 329 | tmp = 0; 330 | } 331 | } 332 | } 333 | 334 | static int32_t ep_write(uint8_t ep, const void *buf, uint16_t blen) { 335 | pma_table *tbl = EPT(ep); 336 | volatile uint16_t *reg = EPR(ep); 337 | switch (*reg & (USB_EPTX_STAT | USB_EP_T_FIELD | USB_EP_KIND)) { 338 | /* doublebuffered bulk endpoint */ 339 | case (USB_EP_TX_NAK | USB_EP_BULK | USB_EP_KIND): 340 | if (*reg & USB_EP_SWBUF_TX) { 341 | pma_write(buf, blen, &(tbl->tx1)); 342 | } else { 343 | pma_write(buf, blen, &(tbl->tx0)); 344 | } 345 | *reg = (*reg & USB_EPREG_MASK) | USB_EP_SWBUF_TX; 346 | break; 347 | /* isochronous endpoint */ 348 | case (USB_EP_TX_VALID | USB_EP_ISOCHRONOUS): 349 | if (!(*reg & USB_EP_DTOG_TX)) { 350 | pma_write(buf, blen, &(tbl->tx1)); 351 | } else { 352 | pma_write(buf, blen, &(tbl->tx0)); 353 | } 354 | break; 355 | /* regular endpoint */ 356 | case (USB_EP_TX_NAK | USB_EP_BULK): 357 | case (USB_EP_TX_NAK | USB_EP_CONTROL): 358 | case (USB_EP_TX_NAK | USB_EP_INTERRUPT): 359 | pma_write(buf, blen, &(tbl->tx)); 360 | EP_TX_VALID(reg); 361 | break; 362 | /* invalid or not ready */ 363 | default: 364 | return -1; 365 | } 366 | return blen; 367 | } 368 | 369 | static uint16_t get_frame (void) { 370 | return USB->FNR & USB_FNR_FN; 371 | } 372 | 373 | static void evt_poll(usbd_device *dev, usbd_evt_callback callback) { 374 | uint8_t _ev, _ep; 375 | uint16_t _istr = USB->ISTR; 376 | _ep = _istr & USB_ISTR_EP_ID; 377 | 378 | if (_istr & USB_ISTR_CTR) { 379 | volatile uint16_t *reg = EPR(_ep); 380 | if (*reg & USB_EP_CTR_TX) { 381 | *reg &= (USB_EPREG_MASK ^ USB_EP_CTR_TX); 382 | _ep |= 0x80; 383 | _ev = usbd_evt_eptx; 384 | } else { 385 | *reg &= (USB_EPREG_MASK ^ USB_EP_CTR_RX); 386 | _ev = (*reg & USB_EP_SETUP) ? usbd_evt_epsetup : usbd_evt_eprx; 387 | } 388 | } else if (_istr & USB_ISTR_RESET) { 389 | USB->ISTR &= ~USB_ISTR_RESET; 390 | USB->BTABLE = 0; 391 | for (int i = 0; i < 8; i++) { 392 | ep_deconfig(i); 393 | } 394 | _ev = usbd_evt_reset; 395 | #if !defined(USBD_SOF_DISABLED) 396 | } else if (_istr & USB_ISTR_SOF) { 397 | _ev = usbd_evt_sof; 398 | USB->ISTR &= ~USB_ISTR_SOF; 399 | #endif 400 | } else if (_istr & USB_ISTR_WKUP) { 401 | _ev = usbd_evt_wkup; 402 | USB->CNTR &= ~USB_CNTR_FSUSP; 403 | USB->ISTR &= ~USB_ISTR_WKUP; 404 | } else if (_istr & USB_ISTR_SUSP) { 405 | _ev = usbd_evt_susp; 406 | USB->CNTR |= USB_CNTR_FSUSP; 407 | USB->ISTR &= ~USB_ISTR_SUSP; 408 | } else if (_istr & USB_ISTR_ERR) { 409 | USB->ISTR &= ~USB_ISTR_ERR; 410 | _ev = usbd_evt_error; 411 | } else { 412 | return; 413 | } 414 | callback(dev, _ev, _ep); 415 | } 416 | 417 | static uint32_t fnv1a32_turn (uint32_t fnv, uint32_t data ) { 418 | for (int i = 0; i < 4 ; i++) { 419 | fnv ^= (data & 0xFF); 420 | fnv *= 16777619; 421 | data >>= 8; 422 | } 423 | return fnv; 424 | } 425 | 426 | static uint16_t get_serialno_desc(void *buffer) { 427 | struct usb_string_descriptor *dsc = buffer; 428 | uint16_t *str = dsc->wString; 429 | uint32_t fnv = 2166136261; 430 | fnv = fnv1a32_turn(fnv, *(uint32_t*)(UID_BASE + 0x00)); 431 | fnv = fnv1a32_turn(fnv, *(uint32_t*)(UID_BASE + 0x04)); 432 | fnv = fnv1a32_turn(fnv, *(uint32_t*)(UID_BASE + 0x14)); 433 | for (int i = 28; i >= 0; i -= 4 ) { 434 | uint16_t c = (fnv >> i) & 0x0F; 435 | c += (c < 10) ? '0' : ('A' - 10); 436 | *str++ = c; 437 | } 438 | dsc->bDescriptorType = USB_DTYPE_STRING; 439 | dsc->bLength = 18; 440 | return 18; 441 | } 442 | 443 | __attribute__((externally_visible)) const struct usbd_driver usbd_devfs = { 444 | getinfo, 445 | enable, 446 | connect, 447 | setaddr, 448 | ep_config, 449 | ep_deconfig, 450 | ep_read, 451 | ep_write, 452 | ep_setstall, 453 | ep_isstalled, 454 | evt_poll, 455 | get_frame, 456 | get_serialno_desc, 457 | }; 458 | 459 | #endif //USBD_STM32L100 460 | --------------------------------------------------------------------------------