├── .gitignore ├── LICENSE ├── README.md ├── interface ├── Common │ ├── inc │ │ ├── DAP.h │ │ └── uart.h │ └── src │ │ ├── DAP.c │ │ ├── JTAG_DP.c │ │ ├── SW_DP.c │ │ ├── main.c │ │ ├── usb_config.c │ │ ├── usb_config_hs.c │ │ ├── usbd_user_cdc_acm.c │ │ └── usbd_user_hid.c ├── interface │ └── hal │ │ ├── TARGET_Freescale │ │ └── TARGET_MK20DX │ │ │ ├── DAP_config.h │ │ │ ├── uart.c │ │ │ └── usbd_MK20D5.c │ │ └── TARGET_NXP │ │ ├── TARGET_LPC11U35 │ │ ├── DAP_config.h │ │ ├── uart.c │ │ └── usbd_LPC11Uxx.c │ │ └── TARGET_LPC4320 │ │ ├── DAP_config.h │ │ └── usbd_LPC43xx_USB0.c └── mdk │ ├── k20dx128 │ ├── Abstract.txt │ └── k20dx128.uvproj │ ├── lpc11u35 │ ├── Abstract.txt │ └── lpc11u35.uvproj │ └── lpc4320 │ ├── Abstract.txt │ └── lpc4320.uvproj └── shared ├── USBStack ├── INC │ ├── rl_usb.h │ ├── usb.h │ ├── usb_cdc.h │ ├── usb_def.h │ ├── usb_for_lib.h │ ├── usb_hid.h │ ├── usb_lib.c │ ├── usb_lib.h │ ├── usb_msc.h │ ├── usbd_cdc.h │ ├── usbd_cdc_acm.h │ ├── usbd_core.h │ ├── usbd_core_cdc.h │ ├── usbd_core_hid.h │ ├── usbd_core_msc.h │ ├── usbd_desc.h │ ├── usbd_event.h │ ├── usbd_hid.h │ ├── usbd_hw.h │ ├── usbd_lib_cdc.h │ ├── usbd_lib_hid.h │ ├── usbd_lib_msc.h │ └── usbd_msc.h └── SRC │ ├── usbd_cdc_acm.c │ ├── usbd_core.c │ ├── usbd_core_cdc.c │ ├── usbd_core_hid.c │ ├── usbd_core_msc.c │ ├── usbd_hid.c │ └── usbd_msc.c └── cmsis ├── TARGET_Freescale └── TARGET_MK20DX │ ├── MK20D5.h │ ├── TOOLCHAIN_ARM_STD │ ├── MK20D5.sct │ └── startup_MK20D5.s │ ├── system_MK20D5.c │ └── system_MK20D5.h ├── TARGET_NXP ├── TARGET_LPC11UXX │ ├── LPC11Uxx.h │ ├── TOOLCHAIN_ARM_STD │ │ ├── LPC11U35.sct │ │ └── startup_LPC11Uxx.s │ └── system_LPC11Uxx.c └── TARGET_LPC43XX │ ├── TOOLCHAIN_ARM_STD │ ├── LPC4320_SPIFI.sct │ └── startup_LPC43xx.s │ └── system_LPC43xx.c ├── core_cm0.h ├── core_cm0plus.h ├── core_cm3.h ├── core_cm4.h ├── core_cm4_simd.h ├── core_cmFunc.h └── core_cmInstr.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Private settings 2 | private_settings.py 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | tmp/ 9 | 10 | # Compiled Dynamic libraries 11 | *.so 12 | *.dylib 13 | 14 | # Compiled Static libraries 15 | *.lai 16 | *.la 17 | *.a 18 | 19 | # Python 20 | *.py[cod] 21 | 22 | # Eclipse Project Files 23 | .cproject 24 | .project 25 | .pydevproject 26 | 27 | # uVision generated files 28 | *.uvopt 29 | *.uvgui.* 30 | 31 | *.plg 32 | *.map 33 | *.lst 34 | *.lnp 35 | *.htm 36 | *.dep 37 | *.d 38 | *.crf 39 | *.bak 40 | 41 | *.axf 42 | *.S19 43 | *.bin 44 | *.dep 45 | *.FLM 46 | 47 | # JLink files 48 | JLink*.* 49 | 50 | # Output directories 51 | Output 52 | Lst 53 | Obj 54 | 55 | # cscope 56 | cscope.* 57 | 58 | # ctags 59 | tags 60 | -------------------------------------------------------------------------------- /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, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "[]" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright [yyyy] [name of copyright owner] 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Simple-DAP 2 | ========== 3 | A subset of the mbed CMSIS-DAP project that implements USB DAP and CDC interfaces on ARM Cortex-M microcontrollers for debugging ARM targets. 4 | 5 | This project is a simpler implementation that does not include the USB MSD flash filesystem, target flash algorithms, USB bootloader and Keil RTX RTOS. It can be useful for testing your DAP abd CDC logic before implementing a new mbed CMSIS-DAP interface or for developing a standalone DAP debugger. 6 | 7 | The mbed code is licensed under the permissive Apache 2.0 licence, so you can use it in both commercial and personal projects with confidence. This license also applies to the USB device stack. 8 | 9 | Supported Interface MCUs 10 | ------------------------ 11 | NXP: 12 | 13 | * [LPC11U35] (http://www.nxp.com/products/microcontrollers/cortex_m0_m0/lpc1100/series/LPC11U00.html) (Cortex-M0) 14 | * [LPC4320/LPC4330/LPC4370] (http://www.nxp.com/products/microcontrollers/cortex_m4/series/LPC4300.html) (Cortex-M4) 15 | 16 | Freescale: 17 | 18 | * [K20DX128] (http://www.freescale.com/webapp/sps/site/taxonomy.jsp?code=K20_USB_MCU) (Cortex-M4) (untested) 19 | 20 | Documentation 21 | ------------- 22 | * [Porting CMSIS-DAP to new boards](http://mbed.org/handbook/cmsis-dap-interface-firmware) 23 | 24 | This mbed-DAP project does not include the bootloader or flash algorithms. References to those or to the Python tools from the mbed CMSIS-DAP project are not applicable. 25 | 26 | References 27 | ---------- 28 | * [mbed CMSIS-DAP Project] (https://github.com/mbedmicro/CMSIS-DAP) 29 | * [ARM CMSIS-DAP Reference Implementation Beta 0.01](http://silver.arm.com/browse/CMSISDAP) (Free registration required) 30 | * [NXP AN11321 - Porting the CMSIS-DAP debugger to the Cortex-M0 platform](http://www.nxp.com/documents/application_note/AN11321.zip) 31 | -------------------------------------------------------------------------------- /interface/Common/inc/DAP.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __DAP_H__ 18 | #define __DAP_H__ 19 | 20 | 21 | // DAP Command IDs 22 | #define ID_DAP_Info 0x00 23 | #define ID_DAP_LED 0x01 24 | #define ID_DAP_Connect 0x02 25 | #define ID_DAP_Disconnect 0x03 26 | #define ID_DAP_TransferConfigure 0x04 27 | #define ID_DAP_Transfer 0x05 28 | #define ID_DAP_TransferBlock 0x06 29 | #define ID_DAP_TransferAbort 0x07 30 | #define ID_DAP_WriteABORT 0x08 31 | #define ID_DAP_Delay 0x09 32 | #define ID_DAP_ResetTarget 0x0A 33 | #define ID_DAP_SWJ_Pins 0x10 34 | #define ID_DAP_SWJ_Clock 0x11 35 | #define ID_DAP_SWJ_Sequence 0x12 36 | #define ID_DAP_SWD_Configure 0x13 37 | #define ID_DAP_JTAG_Sequence 0x14 38 | #define ID_DAP_JTAG_Configure 0x15 39 | #define ID_DAP_JTAG_IDCODE 0x16 40 | 41 | // DAP Vendor Command IDs 42 | #define ID_DAP_Vendor0 0x80 43 | #define ID_DAP_Vendor1 0x81 44 | #define ID_DAP_Vendor2 0x82 45 | #define ID_DAP_Vendor3 0x83 46 | #define ID_DAP_Vendor4 0x84 47 | #define ID_DAP_Vendor5 0x85 48 | #define ID_DAP_Vendor6 0x86 49 | #define ID_DAP_Vendor7 0x87 50 | #define ID_DAP_Vendor8 0x88 51 | #define ID_DAP_Vendor9 0x89 52 | #define ID_DAP_Vendor10 0x8A 53 | #define ID_DAP_Vendor11 0x8B 54 | #define ID_DAP_Vendor12 0x8C 55 | #define ID_DAP_Vendor13 0x8D 56 | #define ID_DAP_Vendor14 0x8E 57 | #define ID_DAP_Vendor15 0x8F 58 | #define ID_DAP_Vendor16 0x90 59 | #define ID_DAP_Vendor17 0x91 60 | #define ID_DAP_Vendor18 0x92 61 | #define ID_DAP_Vendor19 0x93 62 | #define ID_DAP_Vendor20 0x94 63 | #define ID_DAP_Vendor21 0x95 64 | #define ID_DAP_Vendor22 0x96 65 | #define ID_DAP_Vendor23 0x97 66 | #define ID_DAP_Vendor24 0x98 67 | #define ID_DAP_Vendor25 0x99 68 | #define ID_DAP_Vendor26 0x9A 69 | #define ID_DAP_Vendor27 0x9B 70 | #define ID_DAP_Vendor28 0x9C 71 | #define ID_DAP_Vendor29 0x9D 72 | #define ID_DAP_Vendor30 0x9E 73 | #define ID_DAP_Vendor31 0x9F 74 | 75 | #define ID_DAP_Invalid 0xFF 76 | 77 | // DAP Status Code 78 | #define DAP_OK 0 79 | #define DAP_ERROR 0xFF 80 | 81 | // DAP ID 82 | #define DAP_ID_VENDOR 1 83 | #define DAP_ID_PRODUCT 2 84 | #define DAP_ID_SER_NUM 3 85 | #define DAP_ID_FW_VER 4 86 | #define DAP_ID_DEVICE_VENDOR 5 87 | #define DAP_ID_DEVICE_NAME 6 88 | #define DAP_ID_CAPABILITIES 0xF0 89 | #define DAP_ID_PACKET_COUNT 0xFE 90 | #define DAP_ID_PACKET_SIZE 0xFF 91 | 92 | // DAP LEDs 93 | #define DAP_LED_DEBUGGER_CONNECTED 0 94 | #define DAP_LED_TARGET_RUNNING 1 95 | 96 | // DAP Port 97 | #define DAP_PORT_AUTODETECT 0 // Autodetect Port 98 | #define DAP_PORT_DISABLED 0 // Port Disabled (I/O pins in High-Z) 99 | #define DAP_PORT_SWD 1 // SWD Port (SWCLK, SWDIO) + nRESET 100 | #define DAP_PORT_JTAG 2 // JTAG Port (TCK, TMS, TDI, TDO, nTRST) + nRESET 101 | 102 | // DAP SWJ Pins 103 | #define DAP_SWJ_SWCLK_TCK 0 // SWCLK/TCK 104 | #define DAP_SWJ_SWDIO_TMS 1 // SWDIO/TMS 105 | #define DAP_SWJ_TDI 2 // TDI 106 | #define DAP_SWJ_TDO 3 // TDO 107 | #define DAP_SWJ_nTRST 5 // nTRST 108 | #define DAP_SWJ_nRESET 7 // nRESET 109 | 110 | // DAP Transfer Request 111 | #define DAP_TRANSFER_APnDP (1<<0) 112 | #define DAP_TRANSFER_RnW (1<<1) 113 | #define DAP_TRANSFER_A2 (1<<2) 114 | #define DAP_TRANSFER_A3 (1<<3) 115 | #define DAP_TRANSFER_MATCH_VALUE (1<<4) 116 | #define DAP_TRANSFER_MATCH_MASK (1<<5) 117 | 118 | // DAP Transfer Response 119 | #define DAP_TRANSFER_OK (1<<0) 120 | #define DAP_TRANSFER_WAIT (1<<1) 121 | #define DAP_TRANSFER_FAULT (1<<2) 122 | #define DAP_TRANSFER_ERROR (1<<3) 123 | #define DAP_TRANSFER_MISMATCH (1<<4) 124 | 125 | 126 | // Debug Port Register Addresses 127 | #define DP_IDCODE 0x00 // IDCODE Register (SW Read only) 128 | #define DP_ABORT 0x00 // Abort Register (SW Write only) 129 | #define DP_CTRL_STAT 0x04 // Control & Status 130 | #define DP_WCR 0x04 // Wire Control Register (SW Only) 131 | #define DP_SELECT 0x08 // Select Register (JTAG R/W & SW W) 132 | #define DP_RESEND 0x08 // Resend (SW Read Only) 133 | #define DP_RDBUFF 0x0C // Read Buffer (Read Only) 134 | 135 | // JTAG IR Codes 136 | #define JTAG_ABORT 0x08 137 | #define JTAG_DPACC 0x0A 138 | #define JTAG_APACC 0x0B 139 | #define JTAG_IDCODE 0x0E 140 | #define JTAG_BYPASS 0x0F 141 | 142 | // JTAG Sequence Info 143 | #define JTAG_SEQUENCE_TCK 0x3F // TCK count 144 | #define JTAG_SEQUENCE_TMS 0x40 // TMS value 145 | #define JTAG_SEQUENCE_TDO 0x80 // TDO capture 146 | 147 | 148 | #include 149 | #include 150 | 151 | // DAP Data structure 152 | typedef struct { 153 | uint8_t debug_port; // Debug Port 154 | uint8_t fast_clock; // Fast Clock Flag 155 | uint32_t clock_delay; // Clock Delay 156 | struct { // Transfer Configuration 157 | uint8_t idle_cycles; // Idle cycles after transfer 158 | uint16_t retry_count; // Number of retries after WAIT response 159 | uint16_t match_retry; // Number of retries if read value does not match 160 | uint32_t match_mask; // Match Mask 161 | } transfer; 162 | #if (DAP_SWD != 0) 163 | struct { // SWD Configuration 164 | uint8_t turnaround; // Turnaround period 165 | uint8_t data_phase; // Always generate Data Phase 166 | } swd_conf; 167 | #endif 168 | #if (DAP_JTAG != 0) 169 | struct { // JTAG Device Chain 170 | uint8_t count; // Number of devices 171 | uint8_t index; // Device index (device at TDO has index 0) 172 | #if (DAP_JTAG_DEV_CNT != 0) 173 | uint8_t ir_length[DAP_JTAG_DEV_CNT]; // IR Length in bits 174 | uint16_t ir_before[DAP_JTAG_DEV_CNT]; // Bits before IR 175 | uint16_t ir_after [DAP_JTAG_DEV_CNT]; // Bits after IR 176 | #endif 177 | } jtag_dev; 178 | #endif 179 | } DAP_Data_t; 180 | 181 | extern DAP_Data_t DAP_Data; // DAP Data 182 | extern volatile uint8_t DAP_TransferAbort; // Transfer Abort Flag 183 | 184 | 185 | // Functions 186 | extern void SWJ_Sequence (uint32_t count, uint8_t *data); 187 | extern void JTAG_Sequence (uint32_t info, uint8_t *tdi, uint8_t *tdo); 188 | extern void JTAG_IR (uint32_t ir); 189 | extern uint32_t JTAG_ReadIDCode (void); 190 | extern void JTAG_WriteAbort (uint32_t data); 191 | extern uint8_t JTAG_Transfer (uint32_t request, uint32_t *data); 192 | extern uint8_t SWD_Transfer (uint32_t request, uint32_t *data); 193 | 194 | extern void Delayms (uint32_t delay); 195 | 196 | extern uint32_t DAP_ProcessVendorCommand (uint8_t *request, uint8_t *response); 197 | 198 | extern uint32_t DAP_ProcessCommand (uint8_t *request, uint8_t *response); 199 | extern void DAP_Setup (void); 200 | 201 | // Configurable delay for clock generation 202 | #define DELAY_SLOW_CYCLES 3 // Number of cycles for one iteration 203 | static __forceinline void PIN_DELAY_SLOW (uint32_t delay) { 204 | volatile int32_t count; 205 | 206 | count = delay; 207 | while (--count); 208 | } 209 | 210 | // Fixed delay for fast clock generation 211 | #define DELAY_FAST_CYCLES 0 // Number of cycles 212 | static __forceinline void PIN_DELAY_FAST (void) { 213 | //__nop(); 214 | } 215 | 216 | 217 | #endif /* __DAP_H__ */ 218 | -------------------------------------------------------------------------------- /interface/Common/inc/uart.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef UART_H 17 | #define UART_H 18 | 19 | #include 20 | 21 | /* Parity enumerator */ 22 | typedef enum { 23 | UART_PARITY_NONE = 0, 24 | UART_PARITY_ODD = 1, 25 | UART_PARITY_EVEN = 2, 26 | UART_PARITY_MARK = 3, 27 | UART_PARITY_SPACE = 4 28 | } UART_Parity; 29 | 30 | /* Stop Bits enumerator */ 31 | typedef enum { 32 | UART_STOP_BITS_1 = 0, 33 | UART_STOP_BITS_1_5 = 1, 34 | UART_STOP_BITS_2 = 2 35 | } UART_StopBits; 36 | 37 | /* Data Bits enumerator */ 38 | typedef enum { 39 | UART_DATA_BITS_5 = 5, 40 | UART_DATA_BITS_6 = 6, 41 | UART_DATA_BITS_7 = 7, 42 | UART_DATA_BITS_8 = 8, 43 | UART_DATA_BITS_16 = 16 44 | } UART_DataBits; 45 | 46 | /* Flow control enumerator */ 47 | typedef enum { 48 | UART_FLOW_CONTROL_NONE = 0, 49 | UART_FLOW_CONTROL_RTS_CTS = 1, 50 | UART_FLOW_CONTROL_XON_XOFF = 2 51 | } UART_FlowControl; 52 | 53 | /* UART Port Properties structure */ 54 | typedef struct { 55 | uint32_t Baudrate; 56 | UART_DataBits DataBits; 57 | UART_Parity Parity; 58 | UART_StopBits StopBits; 59 | UART_FlowControl FlowControl; 60 | } UART_Configuration; 61 | 62 | /*----------------------------------------------------------------------------- 63 | * FUNCTION PROTOTYPES 64 | *----------------------------------------------------------------------------*/ 65 | 66 | /* UART driver function prototypes */ 67 | extern int32_t uart_initialize (void); 68 | extern int32_t uart_uninitialize (void); 69 | extern int32_t uart_reset (void); 70 | extern int32_t uart_set_configuration (UART_Configuration *config); 71 | extern int32_t uart_get_configuration (UART_Configuration *config); 72 | extern int32_t uart_write_free (void); 73 | extern int32_t uart_write_data (uint8_t *data, uint16_t size); 74 | extern int32_t uart_read_data (uint8_t *data, uint16_t size); 75 | 76 | #endif /* __UART_H */ 77 | -------------------------------------------------------------------------------- /interface/Common/src/SW_DP.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "DAP_config.h" 18 | #include "DAP.h" 19 | 20 | 21 | // SW Macros 22 | 23 | #define PIN_SWCLK_SET PIN_SWCLK_TCK_SET 24 | #define PIN_SWCLK_CLR PIN_SWCLK_TCK_CLR 25 | 26 | #define SW_CLOCK_CYCLE() \ 27 | PIN_SWCLK_CLR(); \ 28 | PIN_DELAY(); \ 29 | PIN_SWCLK_SET(); \ 30 | PIN_DELAY() 31 | 32 | #define SW_WRITE_BIT(bit) \ 33 | PIN_SWDIO_OUT(bit); \ 34 | PIN_SWCLK_CLR(); \ 35 | PIN_DELAY(); \ 36 | PIN_SWCLK_SET(); \ 37 | PIN_DELAY() 38 | 39 | #define SW_READ_BIT(bit) \ 40 | PIN_SWCLK_CLR(); \ 41 | PIN_DELAY(); \ 42 | bit = PIN_SWDIO_IN(); \ 43 | PIN_SWCLK_SET(); \ 44 | PIN_DELAY() 45 | 46 | #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) 47 | 48 | 49 | // Generate SWJ Sequence 50 | // count: sequence bit count 51 | // data: pointer to sequence bit data 52 | // return: none 53 | #if ((DAP_SWD != 0) || (DAP_JTAG != 0)) 54 | void SWJ_Sequence (uint32_t count, uint8_t *data) { 55 | uint32_t val; 56 | uint32_t n; 57 | 58 | val = 0; 59 | n = 0; 60 | while (count--) { 61 | if (n == 0) { 62 | val = *data++; 63 | n = 8; 64 | } 65 | if (val & 1) { 66 | PIN_SWDIO_TMS_SET(); 67 | } else { 68 | PIN_SWDIO_TMS_CLR(); 69 | } 70 | SW_CLOCK_CYCLE(); 71 | val >>= 1; 72 | n--; 73 | } 74 | } 75 | #endif 76 | 77 | 78 | #if (DAP_SWD != 0) 79 | 80 | 81 | // SWD Transfer I/O 82 | // request: A[3:2] RnW APnDP 83 | // data: DATA[31:0] 84 | // return: ACK[2:0] 85 | #define SWD_TransferFunction(speed) /**/ \ 86 | uint8_t SWD_Transfer##speed (uint32_t request, uint32_t *data) { \ 87 | uint32_t ack; \ 88 | uint32_t bit; \ 89 | uint32_t val; \ 90 | uint32_t parity; \ 91 | \ 92 | uint32_t n; \ 93 | \ 94 | /* Packet Request */ \ 95 | parity = 0; \ 96 | SW_WRITE_BIT(1); /* Start Bit */ \ 97 | bit = request >> 0; \ 98 | SW_WRITE_BIT(bit); /* APnDP Bit */ \ 99 | parity += bit; \ 100 | bit = request >> 1; \ 101 | SW_WRITE_BIT(bit); /* RnW Bit */ \ 102 | parity += bit; \ 103 | bit = request >> 2; \ 104 | SW_WRITE_BIT(bit); /* A2 Bit */ \ 105 | parity += bit; \ 106 | bit = request >> 3; \ 107 | SW_WRITE_BIT(bit); /* A3 Bit */ \ 108 | parity += bit; \ 109 | SW_WRITE_BIT(parity); /* Parity Bit */ \ 110 | SW_WRITE_BIT(0); /* Stop Bit */ \ 111 | SW_WRITE_BIT(1); /* Park Bit */ \ 112 | \ 113 | /* Turnaround */ \ 114 | PIN_SWDIO_OUT_DISABLE(); \ 115 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ 116 | SW_CLOCK_CYCLE(); \ 117 | } \ 118 | \ 119 | /* Acknowledge response */ \ 120 | SW_READ_BIT(bit); \ 121 | ack = bit << 0; \ 122 | SW_READ_BIT(bit); \ 123 | ack |= bit << 1; \ 124 | SW_READ_BIT(bit); \ 125 | ack |= bit << 2; \ 126 | \ 127 | if (ack == DAP_TRANSFER_OK) { /* OK response */ \ 128 | /* Data transfer */ \ 129 | if (request & DAP_TRANSFER_RnW) { \ 130 | /* Read data */ \ 131 | val = 0; \ 132 | parity = 0; \ 133 | for (n = 32; n; n--) { \ 134 | SW_READ_BIT(bit); /* Read RDATA[0:31] */ \ 135 | parity += bit; \ 136 | val >>= 1; \ 137 | val |= bit << 31; \ 138 | } \ 139 | SW_READ_BIT(bit); /* Read Parity */ \ 140 | if ((parity ^ bit) & 1) { \ 141 | ack = DAP_TRANSFER_ERROR; \ 142 | } \ 143 | if (data) *data = val; \ 144 | /* Turnaround */ \ 145 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ 146 | SW_CLOCK_CYCLE(); \ 147 | } \ 148 | PIN_SWDIO_OUT_ENABLE(); \ 149 | } else { \ 150 | /* Turnaround */ \ 151 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ 152 | SW_CLOCK_CYCLE(); \ 153 | } \ 154 | PIN_SWDIO_OUT_ENABLE(); \ 155 | /* Write data */ \ 156 | val = *data; \ 157 | parity = 0; \ 158 | for (n = 32; n; n--) { \ 159 | SW_WRITE_BIT(val); /* Write WDATA[0:31] */ \ 160 | parity += val; \ 161 | val >>= 1; \ 162 | } \ 163 | SW_WRITE_BIT(parity); /* Write Parity Bit */ \ 164 | } \ 165 | /* Idle cycles */ \ 166 | n = DAP_Data.transfer.idle_cycles; \ 167 | if (n) { \ 168 | PIN_SWDIO_OUT(0); \ 169 | for (; n; n--) { \ 170 | SW_CLOCK_CYCLE(); \ 171 | } \ 172 | } \ 173 | PIN_SWDIO_OUT(1); \ 174 | return (ack); \ 175 | } \ 176 | \ 177 | if ((ack == DAP_TRANSFER_WAIT) || (ack == DAP_TRANSFER_FAULT)) { \ 178 | /* WAIT or FAULT response */ \ 179 | if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) != 0)) { \ 180 | for (n = 32+1; n; n--) { \ 181 | SW_CLOCK_CYCLE(); /* Dummy Read RDATA[0:31] + Parity */ \ 182 | } \ 183 | } \ 184 | /* Turnaround */ \ 185 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ 186 | SW_CLOCK_CYCLE(); \ 187 | } \ 188 | PIN_SWDIO_OUT_ENABLE(); \ 189 | if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) == 0)) { \ 190 | PIN_SWDIO_OUT(0); \ 191 | for (n = 32+1; n; n--) { \ 192 | SW_CLOCK_CYCLE(); /* Dummy Write WDATA[0:31] + Parity */ \ 193 | } \ 194 | } \ 195 | PIN_SWDIO_OUT(1); \ 196 | return (ack); \ 197 | } \ 198 | \ 199 | /* Protocol error */ \ 200 | for (n = DAP_Data.swd_conf.turnaround + 32 + 1; n; n--) { \ 201 | SW_CLOCK_CYCLE(); /* Back off data phase */ \ 202 | } \ 203 | PIN_SWDIO_OUT(1); \ 204 | return (ack); \ 205 | } 206 | 207 | 208 | #undef PIN_DELAY 209 | #define PIN_DELAY() PIN_DELAY_FAST() 210 | SWD_TransferFunction(Fast); 211 | 212 | #undef PIN_DELAY 213 | #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) 214 | SWD_TransferFunction(Slow); 215 | 216 | 217 | // SWD Transfer I/O 218 | // request: A[3:2] RnW APnDP 219 | // data: DATA[31:0] 220 | // return: ACK[2:0] 221 | uint8_t SWD_Transfer(uint32_t request, uint32_t *data) { 222 | if (DAP_Data.fast_clock) { 223 | return SWD_TransferFast(request, data); 224 | } else { 225 | return SWD_TransferSlow(request, data); 226 | } 227 | } 228 | 229 | 230 | #endif /* (DAP_SWD != 0) */ 231 | -------------------------------------------------------------------------------- /interface/Common/src/main.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #if !defined(CONF_DAP) && !defined(CONF_CDC) 21 | #error "Configure at least one device by defining CONF_DAP or CONF_CDC" 22 | #endif 23 | 24 | #if defined(CONF_DAP) 25 | #include "DAP_config.h" 26 | #include "DAP.h" 27 | 28 | extern void usbd_hid_process (void); 29 | #endif 30 | 31 | #if defined(CONF_CDC) 32 | #include "UART.h" 33 | #include 34 | 35 | #define SIZE_DATA (64) 36 | 37 | void serial_process() { 38 | uint8_t data[SIZE_DATA]; 39 | int32_t len_data = 0; 40 | 41 | while (1) { 42 | 43 | len_data = USBD_CDC_ACM_DataFree(); 44 | if (len_data > SIZE_DATA) 45 | len_data = SIZE_DATA; 46 | if (len_data) 47 | len_data = uart_read_data(data, len_data); 48 | if (len_data) { 49 | USBD_CDC_ACM_DataSend(data , len_data); 50 | } 51 | 52 | len_data = uart_write_free(); 53 | if (len_data > SIZE_DATA) 54 | len_data = SIZE_DATA; 55 | if (len_data) 56 | len_data = USBD_CDC_ACM_DataRead(data, len_data); 57 | if (len_data) { 58 | uart_write_data(data, len_data); 59 | } 60 | } 61 | } 62 | #endif 63 | 64 | // Main program 65 | int main (void) { 66 | #if defined(CONF_DAP) 67 | DAP_Setup(); // DAP Setup 68 | #endif 69 | 70 | usbd_init(); // USB Device Initialization 71 | usbd_connect(0); // USB Device Disconnect 72 | usbd_connect(1); // USB Device Connect 73 | 74 | while (!usbd_configured()); // Wait for USB Device to configure 75 | 76 | #if defined(CONF_DAP) 77 | LED_CONNECTED_OUT(1); // Turn on Debugger Connected LED 78 | LED_RUNNING_OUT(1); // Turn on Target Running LED 79 | Delayms(500); // Wait for 500ms 80 | LED_RUNNING_OUT(0); // Turn off Target Running LED 81 | LED_CONNECTED_OUT(0); // Turn off Debugger Connected LED 82 | #endif 83 | 84 | while (1) { // Endless Loop 85 | #if defined(CONF_DAP) 86 | usbd_hid_process(); // Process USB HID Data 87 | #endif 88 | #if defined(CONF_CDC) 89 | serial_process(); // Process USB CDC Data 90 | #endif 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /interface/Common/src/usbd_user_cdc_acm.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include "rl_usb.h" 18 | 19 | #include "uart.h" 20 | 21 | 22 | UART_Configuration UART_Config; 23 | 24 | 25 | /** \brief Vitual COM Port initialization 26 | 27 | The function inititalizes the hardware resources of the port used as 28 | the Virtual COM Port. 29 | 30 | \return 0 Function failed. 31 | \return 1 Function succeeded. 32 | */ 33 | int32_t USBD_CDC_ACM_PortInitialize (void) { 34 | return (uart_initialize ()); 35 | } 36 | 37 | 38 | /** \brief Vitual COM Port uninitialization 39 | 40 | The function uninititalizes/releases the hardware resources of the port used 41 | as the Virtual COM Port. 42 | 43 | \return 0 Function failed. 44 | \return 1 Function succeeded. 45 | */ 46 | int32_t USBD_CDC_ACM_PortUninitialize (void) { 47 | return (uart_uninitialize ()); 48 | } 49 | 50 | 51 | /** \brief Vitual COM Port reset 52 | 53 | The function resets the internal states of the port used 54 | as the Virtual COM Port. 55 | 56 | \return 0 Function failed. 57 | \return 1 Function succeeded. 58 | */ 59 | int32_t USBD_CDC_ACM_PortReset (void) { 60 | return (uart_reset ()); 61 | } 62 | 63 | 64 | /** \brief Virtual COM Port change communication settings 65 | 66 | The function changes communication settings of the port used as the 67 | Virtual COM Port. 68 | 69 | \param [in] line_coding Pointer to the loaded CDC_LINE_CODING structure. 70 | \return 0 Function failed. 71 | \return 1 Function succeeded. 72 | */ 73 | int32_t USBD_CDC_ACM_PortSetLineCoding (CDC_LINE_CODING *line_coding) { 74 | UART_Config.Baudrate = line_coding->dwDTERate; 75 | UART_Config.DataBits = (UART_DataBits) line_coding->bDataBits; 76 | UART_Config.Parity = (UART_Parity) line_coding->bParityType; 77 | UART_Config.StopBits = (UART_StopBits) line_coding->bCharFormat; 78 | UART_Config.FlowControl = UART_FLOW_CONTROL_NONE; 79 | 80 | return (uart_set_configuration (&UART_Config)); 81 | } 82 | 83 | 84 | /** \brief Vitual COM Port retrieve communication settings 85 | 86 | The function retrieves communication settings of the port used as the 87 | Virtual COM Port. 88 | 89 | \param [in] line_coding Pointer to the CDC_LINE_CODING structure. 90 | \return 0 Function failed. 91 | \return 1 Function succeeded. 92 | */ 93 | int32_t USBD_CDC_ACM_PortGetLineCoding (CDC_LINE_CODING *line_coding) { 94 | if (uart_get_configuration (&UART_Config)) { 95 | line_coding->dwDTERate = UART_Config.Baudrate; 96 | line_coding->bDataBits = UART_Config.DataBits; 97 | line_coding->bParityType = UART_Config.Parity; 98 | line_coding->bCharFormat = UART_Config.StopBits; 99 | return (1); 100 | } 101 | 102 | return (0); 103 | } 104 | 105 | 106 | /** \brief Virtual COM Port set control line state 107 | 108 | The function sets control line state on the port used as the 109 | Virtual COM Port. 110 | 111 | \param [in] ctrl_bmp Control line settings bitmap ( 112 | 0. bit - DTR state, 113 | 1. bit - RTS state). 114 | \return 0 Function failed. 115 | \return 1 Function succeeded. 116 | */ 117 | int32_t USBD_CDC_ACM_PortSetControlLineState (uint16_t ctrl_bmp) { 118 | return (1); 119 | } 120 | -------------------------------------------------------------------------------- /interface/Common/src/usbd_user_hid.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #define __NO_USB_LIB_C 21 | #ifdef TARGET_LPC4320 22 | #include "usb_config_hs.c" 23 | #else 24 | #include "usb_config.c" 25 | #endif 26 | #include "DAP_config.h" 27 | #include "DAP.h" 28 | 29 | 30 | #if (USBD_HID_OUTREPORT_MAX_SZ != DAP_PACKET_SIZE) 31 | #error "USB HID Output Report Size must match DAP Packet Size" 32 | #endif 33 | #if (USBD_HID_INREPORT_MAX_SZ != DAP_PACKET_SIZE) 34 | #error "USB HID Input Report Size must match DAP Packet Size" 35 | #endif 36 | 37 | static volatile uint8_t USB_RequestFlag; // Request Buffer Usage Flag 38 | static volatile uint32_t USB_RequestIn; // Request Buffer In Index 39 | static volatile uint32_t USB_RequestOut; // Request Buffer Out Index 40 | 41 | static volatile uint8_t USB_ResponseIdle; // Response Buffer Idle Flag 42 | static volatile uint8_t USB_ResponseFlag; // Response Buffer Usage Flag 43 | static volatile uint32_t USB_ResponseIn; // Response Buffer In Index 44 | static volatile uint32_t USB_ResponseOut; // Response Buffer Out Index 45 | 46 | static uint8_t USB_Request [DAP_PACKET_COUNT][DAP_PACKET_SIZE]; // Request Buffer 47 | static uint8_t USB_Response[DAP_PACKET_COUNT][DAP_PACKET_SIZE]; // Response Buffer 48 | 49 | 50 | // USB HID Callback: when system initializes 51 | void usbd_hid_init (void) { 52 | USB_RequestFlag = 0; 53 | USB_RequestIn = 0; 54 | USB_RequestOut = 0; 55 | USB_ResponseIdle = 1; 56 | USB_ResponseFlag = 0; 57 | USB_ResponseIn = 0; 58 | USB_ResponseOut = 0; 59 | } 60 | 61 | // USB HID Callback: when data needs to be prepared for the host 62 | int usbd_hid_get_report (U8 rtype, U8 rid, U8 *buf, U8 req) { 63 | switch (rtype) { 64 | case HID_REPORT_INPUT: 65 | switch (req) { 66 | case USBD_HID_REQ_EP_CTRL: 67 | case USBD_HID_REQ_PERIOD_UPDATE: 68 | break; 69 | case USBD_HID_REQ_EP_INT: 70 | if ((USB_ResponseOut != USB_ResponseIn) || USB_ResponseFlag) { 71 | memcpy(buf, USB_Response[USB_ResponseOut], DAP_PACKET_SIZE); 72 | USB_ResponseOut++; 73 | if (USB_ResponseOut == DAP_PACKET_COUNT) { 74 | USB_ResponseOut = 0; 75 | } 76 | if (USB_ResponseOut == USB_ResponseIn) { 77 | USB_ResponseFlag = 0; 78 | } 79 | return (DAP_PACKET_SIZE); 80 | } else { 81 | USB_ResponseIdle = 1; 82 | } 83 | break; 84 | } 85 | break; 86 | case HID_REPORT_FEATURE: 87 | break; 88 | } 89 | return (0); 90 | } 91 | 92 | // USB HID Callback: when data is received from the host 93 | void usbd_hid_set_report (U8 rtype, U8 rid, U8 *buf, int len, U8 req) { 94 | switch (rtype) { 95 | case HID_REPORT_OUTPUT: 96 | if (len == 0) break; 97 | if (buf[0] == ID_DAP_TransferAbort) { 98 | DAP_TransferAbort = 1; 99 | break; 100 | } 101 | if (USB_RequestFlag && (USB_RequestIn == USB_RequestOut)) { 102 | break; // Discard packet when buffer is full 103 | } 104 | // Store data into request packet buffer 105 | memcpy(USB_Request[USB_RequestIn], buf, len); 106 | USB_RequestIn++; 107 | if (USB_RequestIn == DAP_PACKET_COUNT) { 108 | USB_RequestIn = 0; 109 | } 110 | if (USB_RequestIn == USB_RequestOut) { 111 | USB_RequestFlag = 1; 112 | } 113 | break; 114 | case HID_REPORT_FEATURE: 115 | break; 116 | } 117 | } 118 | 119 | 120 | // Process USB HID Data 121 | void usbd_hid_process (void) { 122 | uint32_t n; 123 | 124 | // Process pending requests 125 | if ((USB_RequestOut != USB_RequestIn) || USB_RequestFlag) { 126 | // Process DAP Command and prepare response 127 | DAP_ProcessCommand(USB_Request[USB_RequestOut], USB_Response[USB_ResponseIn]); 128 | 129 | // Update request index and flag 130 | n = USB_RequestOut + 1; 131 | if (n == DAP_PACKET_COUNT) { 132 | n = 0; 133 | } 134 | USB_RequestOut = n; 135 | if (USB_RequestOut == USB_RequestIn) { 136 | USB_RequestFlag = 0; 137 | } 138 | 139 | if (USB_ResponseIdle) { 140 | // Request that data is send back to host 141 | USB_ResponseIdle = 0; 142 | usbd_hid_get_report_trigger(0, USB_Response[USB_ResponseIn], DAP_PACKET_SIZE); 143 | } else { 144 | // Update response index and flag 145 | n = USB_ResponseIn + 1; 146 | if (n == DAP_PACKET_COUNT) { 147 | n = 0; 148 | } 149 | USB_ResponseIn = n; 150 | if (USB_ResponseIn == USB_ResponseOut) { 151 | USB_ResponseFlag = 1; 152 | } 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /interface/interface/hal/TARGET_Freescale/TARGET_MK20DX/uart.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include "uart.h" 18 | #include 19 | 20 | extern uint32_t SystemCoreClock; 21 | 22 | static void clear_buffers(void); 23 | 24 | // Size must be 2^n for using quick wrap around 25 | #define BUFFER_SIZE (512) 26 | 27 | struct { 28 | uint8_t data[BUFFER_SIZE]; 29 | volatile uint32_t idx_in; 30 | volatile uint32_t idx_out; 31 | volatile uint32_t cnt_in; 32 | volatile uint32_t cnt_out; 33 | } write_buffer, read_buffer; 34 | 35 | uint32_t tx_in_progress = 0; 36 | 37 | void clear_buffers(void) 38 | { 39 | memset((void*)&read_buffer, 0xBB, sizeof(read_buffer.data)); 40 | read_buffer.idx_in = 0; 41 | read_buffer.idx_out = 0; 42 | read_buffer.cnt_in = 0; 43 | read_buffer.cnt_out = 0; 44 | memset((void*)&write_buffer, 0xBB, sizeof(read_buffer.data)); 45 | write_buffer.idx_in = 0; 46 | write_buffer.idx_out = 0; 47 | write_buffer.cnt_in = 0; 48 | write_buffer.cnt_out = 0; 49 | } 50 | 51 | int32_t uart_initialize (void) { 52 | 53 | NVIC_DisableIRQ(UART1_RX_TX_IRQn); 54 | 55 | clear_buffers(); 56 | 57 | // enable clk PORTC 58 | SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK; 59 | 60 | // enable clk uart 61 | SIM->SCGC4 |= SIM_SCGC4_UART1_MASK; 62 | 63 | // disable interrupt 64 | NVIC_DisableIRQ (UART1_RX_TX_IRQn); 65 | 66 | // Enable receiver and transmitter 67 | UART1->C2 |= UART_C2_RE_MASK | UART_C2_TE_MASK; 68 | 69 | // alternate 3: UART1 70 | PORTC->PCR[3] = (3 << 8); 71 | PORTC->PCR[4] = (3 << 8); 72 | 73 | // Enable receive interrupt 74 | UART1->C2 |= UART_C2_RIE_MASK; 75 | 76 | NVIC_ClearPendingIRQ(UART1_RX_TX_IRQn); 77 | 78 | NVIC_EnableIRQ(UART1_RX_TX_IRQn); 79 | 80 | return 1; 81 | } 82 | 83 | int32_t uart_uninitialize (void) { 84 | 85 | // transmitter and receiver disabled 86 | UART1->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK); 87 | 88 | // disable interrupt 89 | UART1->C2 &= ~(UART_C2_RIE_MASK | UART_C2_TIE_MASK); 90 | 91 | clear_buffers(); 92 | 93 | return 1; 94 | } 95 | 96 | int32_t uart_reset (void) { 97 | 98 | // disable interrupt 99 | NVIC_DisableIRQ (UART1_RX_TX_IRQn); 100 | 101 | clear_buffers(); 102 | 103 | // disable TIE interrupt 104 | UART1->C2 &= ~(UART_C2_TIE_MASK); 105 | 106 | tx_in_progress = 0; 107 | 108 | // enable interrupt 109 | NVIC_EnableIRQ (UART1_RX_TX_IRQn); 110 | 111 | return 1; 112 | } 113 | 114 | int32_t uart_set_configuration (UART_Configuration *config) { 115 | 116 | uint8_t data_bits = 8; 117 | uint8_t parity_enable = 0; 118 | uint8_t parity_type = 0; 119 | uint32_t dll; 120 | 121 | // disable interrupt 122 | NVIC_DisableIRQ (UART1_RX_TX_IRQn); 123 | 124 | // Disable receiver and transmitter while updating 125 | UART1->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK); 126 | 127 | clear_buffers(); 128 | 129 | // set data bits, stop bits, parity 130 | if ((config->DataBits < 8) || (config->DataBits > 9)) { 131 | data_bits = 8; 132 | } 133 | data_bits -= 8; 134 | 135 | if (config->Parity == 1) { 136 | parity_enable = 1; 137 | parity_type = 1; 138 | data_bits++; 139 | } else if (config->Parity == 2) { 140 | parity_enable = 1; 141 | parity_type = 0; 142 | data_bits++; 143 | } 144 | 145 | // does not support 10 bit data comm 146 | if (data_bits == 2) { 147 | data_bits = 0; 148 | parity_enable = 0; 149 | parity_type = 0; 150 | } 151 | 152 | // data bits, parity and parity mode 153 | UART1->C1 = data_bits << UART_C1_M_SHIFT 154 | | parity_enable << UART_C1_PE_SHIFT 155 | | parity_type << UART_C1_PT_SHIFT; 156 | 157 | dll = SystemCoreClock / (16 * config->Baudrate); 158 | 159 | // set baudrate 160 | UART1->BDH = (UART1->BDH & ~(UART_BDH_SBR_MASK)) | ((dll >> 8) & UART_BDH_SBR_MASK); 161 | UART1->BDL = (UART1->BDL & ~(UART_BDL_SBR_MASK)) | (dll & UART_BDL_SBR_MASK); 162 | 163 | // Enable transmitter and receiver 164 | UART1->C2 |= UART_C2_RE_MASK | UART_C2_TE_MASK; 165 | 166 | // Enable UART interrupt 167 | NVIC_ClearPendingIRQ (UART1_RX_TX_IRQn); 168 | NVIC_EnableIRQ (UART1_RX_TX_IRQn); 169 | 170 | return 1; 171 | } 172 | 173 | int32_t uart_get_configuration (UART_Configuration *config) { 174 | 175 | return 1; 176 | } 177 | 178 | int32_t uart_write_free(void) { 179 | 180 | return BUFFER_SIZE - (write_buffer.cnt_in - write_buffer.cnt_out); 181 | } 182 | 183 | int32_t uart_write_data (uint8_t *data, uint16_t size) { 184 | uint32_t cnt; 185 | int16_t len_in_buf; 186 | 187 | if (size == 0) { 188 | return 0; 189 | } 190 | 191 | cnt = 0; 192 | 193 | while (size--) { 194 | len_in_buf = write_buffer.cnt_in - write_buffer.cnt_out; 195 | if (len_in_buf < BUFFER_SIZE) { 196 | write_buffer.data[write_buffer.idx_in++] = *data++; 197 | write_buffer.idx_in &= (BUFFER_SIZE - 1); 198 | write_buffer.cnt_in++; 199 | cnt++; 200 | } 201 | } 202 | 203 | if (!tx_in_progress) 204 | { 205 | // Wait for D register to be free 206 | while(!(UART1->S1 & UART_S1_TDRE_MASK)) { } 207 | 208 | tx_in_progress = 1; 209 | 210 | // Write the first byte into D 211 | UART1->D = write_buffer.data[write_buffer.idx_out++]; 212 | write_buffer.idx_out &= (BUFFER_SIZE - 1); 213 | write_buffer.cnt_out++; 214 | 215 | // enable TX interrupt 216 | UART1->C2 |= UART_C2_TIE_MASK; 217 | } 218 | 219 | return cnt; 220 | } 221 | 222 | int32_t uart_read_data (uint8_t *data, uint16_t size) { 223 | uint32_t cnt; 224 | 225 | if (size == 0) { 226 | return 0; 227 | } 228 | 229 | cnt = 0; 230 | 231 | while (size--) { 232 | if (read_buffer.cnt_in != read_buffer.cnt_out) { 233 | *data++ = read_buffer.data[read_buffer.idx_out++]; 234 | read_buffer.idx_out &= (BUFFER_SIZE - 1); 235 | read_buffer.cnt_out++; 236 | cnt++; 237 | } 238 | else 239 | { 240 | break; 241 | } 242 | } 243 | 244 | return cnt; 245 | } 246 | 247 | void UART1_RX_TX_IRQHandler (void) { 248 | uint32_t s1; 249 | volatile uint8_t errorData; 250 | 251 | // read interrupt status 252 | s1 = UART1->S1; 253 | 254 | // handle character to transmit 255 | if (write_buffer.cnt_in != write_buffer.cnt_out) { 256 | // if TDRE is empty 257 | if (s1 & UART_S1_TDRE_MASK) { 258 | UART1->D = write_buffer.data[write_buffer.idx_out++]; 259 | write_buffer.idx_out &= (BUFFER_SIZE - 1); 260 | write_buffer.cnt_out++; 261 | tx_in_progress = 1; 262 | } 263 | } 264 | else { 265 | // disable TIE interrupt 266 | UART1->C2 &= ~(UART_C2_TIE_MASK); 267 | tx_in_progress = 0; 268 | } 269 | 270 | // handle received character 271 | if (s1 & UART_S1_RDRF_MASK) { 272 | if ((s1 & UART_S1_NF_MASK) || (s1 & UART_S1_FE_MASK)) 273 | { 274 | errorData = UART1->D; 275 | } 276 | else 277 | { 278 | read_buffer.data[read_buffer.idx_in++] = UART1->D; 279 | read_buffer.idx_in &= (BUFFER_SIZE - 1); 280 | read_buffer.cnt_in++; 281 | } 282 | } 283 | } 284 | 285 | /*------------------------------------------------------------------------------ 286 | * End of file 287 | *----------------------------------------------------------------------------*/ 288 | 289 | -------------------------------------------------------------------------------- /interface/interface/hal/TARGET_NXP/TARGET_LPC11U35/uart.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include "uart.h" 18 | 19 | static uint32_t baudrate; 20 | static uint32_t dll; 21 | static uint32_t tx_in_progress; 22 | 23 | extern uint32_t SystemCoreClock; 24 | 25 | // Size must be 2^n 26 | #define BUFFER_SIZE (64) 27 | 28 | 29 | static struct { 30 | uint8_t data[BUFFER_SIZE]; 31 | volatile uint16_t idx_in; 32 | volatile uint16_t idx_out; 33 | volatile int16_t cnt_in; 34 | volatile int16_t cnt_out; 35 | } write_buffer, read_buffer; 36 | 37 | 38 | int32_t uart_initialize (void) { 39 | NVIC_DisableIRQ(UART_IRQn); 40 | 41 | LPC_SYSCON->SYSAHBCLKCTRL |= ((1UL << 6) | // enable clock for GPIO 42 | (1UL << 16) ); // enable clock for IOCON 43 | 44 | // enable clk for usart 45 | LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 12); 46 | 47 | // usart clk divider = 1 48 | LPC_SYSCON->UARTCLKDIV = (1UL << 0); 49 | 50 | // alternate function USART and PullNone 51 | LPC_IOCON->PIO0_18 |= 0x01; 52 | LPC_IOCON->PIO0_19 |= 0x01; 53 | 54 | // enable FIFOs (trigger level 1) and clear them 55 | LPC_USART->FCR = 0x87; 56 | 57 | // Transmit Enable 58 | LPC_USART->TER = 0x80; 59 | 60 | // reset uart 61 | uart_reset(); 62 | 63 | // enable rx and tx interrupt 64 | LPC_USART->IER |= (1 << 0) | (1 << 1); 65 | 66 | NVIC_EnableIRQ(UART_IRQn); 67 | 68 | return 1; 69 | } 70 | 71 | 72 | int32_t uart_uninitialize (void) { 73 | // disable interrupt 74 | LPC_USART->IER &= ~(0x7); 75 | NVIC_DisableIRQ(UART_IRQn); 76 | 77 | // reset uart 78 | uart_reset(); 79 | 80 | return 1; 81 | } 82 | 83 | 84 | int32_t uart_reset (void) { 85 | 86 | uint8_t *ptr; 87 | int32_t i; 88 | 89 | // disable interrupt 90 | NVIC_DisableIRQ (UART_IRQn); 91 | 92 | // Reset FIFOs 93 | LPC_USART->FCR = 0x06; 94 | 95 | baudrate = 0; 96 | dll = 0; 97 | tx_in_progress = 0; 98 | 99 | ptr = (uint8_t *)&write_buffer; 100 | for (i = 0; i < sizeof(write_buffer); i++) { 101 | *ptr++ = 0; 102 | } 103 | 104 | ptr = (uint8_t *)&read_buffer; 105 | for (i = 0; i < sizeof(read_buffer); i++) { 106 | *ptr++ = 0; 107 | } 108 | 109 | // Ensure a clean start, no data in either TX or RX FIFO 110 | while (( LPC_USART->LSR & ( (1 << 5) | (1 << 6) ) ) != ( (1 << 5) | (1 << 6) ) ); 111 | while ( LPC_USART->LSR & 0x01 ) { 112 | LPC_USART->RBR; // Dump data from RX FIFO 113 | } 114 | 115 | // enable interrupt 116 | NVIC_EnableIRQ (UART_IRQn); 117 | 118 | return 1; 119 | } 120 | 121 | 122 | int32_t uart_set_configuration (UART_Configuration *config) { 123 | 124 | uint8_t DivAddVal = 0; 125 | uint8_t MulVal = 1; 126 | uint16_t dlv; 127 | uint8_t mv, dav, hit = 0, data_bits = 8, parity, stop_bits = 0; 128 | float ratio, err, calcbaud; 129 | 130 | // disable interrupt 131 | NVIC_DisableIRQ (UART_IRQn); 132 | 133 | // reset uart 134 | uart_reset(); 135 | 136 | dll = SystemCoreClock / (16 * config->Baudrate); 137 | baudrate = config->Baudrate; 138 | 139 | // First we check to see if the basic divide with no DivAddVal/MulVal 140 | // ratio gives us an integer result. If it does, we set DivAddVal = 0, 141 | // MulVal = 1. Otherwise, we search the valid ratio value range to find 142 | // the closest match. This could be more elegant, using search methods 143 | // and/or lookup tables, but the brute force method is not that much 144 | // slower, and is more maintainable. 145 | if ((SystemCoreClock % (16 * config->Baudrate)) != 0) { // Checking for zero remainder 146 | float err_best = (float) config->Baudrate; 147 | unsigned short dlmax = dll; 148 | for (dlv = dlmax/2; (dlv <= dlmax) && !hit; dlv++) { 149 | for ( mv = 1; mv <= 15; mv++) { 150 | for ( dav = 1; dav < mv; dav++) { 151 | ratio = 1.0 + ((float) dav / (float) mv); 152 | calcbaud = (float)SystemCoreClock / (16.0 * (float) dlv * ratio); 153 | err = ((config->Baudrate - calcbaud) > 0) ? (config->Baudrate - calcbaud) : -(config->Baudrate - calcbaud); 154 | if (err < err_best) { 155 | dll = dlv; 156 | DivAddVal = dav; 157 | MulVal = mv; 158 | err_best = err; 159 | if (err < 10) { 160 | hit = 1; 161 | } 162 | } 163 | } 164 | } 165 | } 166 | } 167 | 168 | 169 | // set LCR[DLAB] to enable writing to divider registers 170 | LPC_USART->LCR |= (1 << 7); 171 | 172 | // set divider values 173 | LPC_USART->DLM = (dll >> 8) & 0xFF; 174 | LPC_USART->DLL = (dll >> 0) & 0xFF; 175 | LPC_USART->FDR = (uint32_t) DivAddVal << 0 176 | | (uint32_t) MulVal << 4; 177 | 178 | // clear LCR[DLAB] 179 | LPC_USART->LCR &= ~(1 << 7); 180 | 181 | // set data bits, stop bits, parity 182 | if ((config->DataBits < 5) || (config->DataBits > 8)) { 183 | data_bits = 8; 184 | } 185 | data_bits -= 5; 186 | 187 | if (config->StopBits != 1 && config->StopBits != 2) { 188 | stop_bits = 1; 189 | } 190 | stop_bits -= 1; 191 | 192 | switch (config->Parity) { 193 | case UART_PARITY_ODD: parity = 0x01; break; // Parity Odd 194 | case UART_PARITY_EVEN: parity = 0x03; break; // Parity Even 195 | case UART_PARITY_MARK: parity = 0x05; break; // Parity Mark 196 | case UART_PARITY_SPACE: parity = 0x07; break; // Parity Space 197 | 198 | case UART_PARITY_NONE: // Parity None 199 | default: 200 | parity = 0x00; 201 | break; 202 | } 203 | 204 | LPC_USART->LCR = (data_bits << 0) 205 | | (stop_bits << 2) 206 | | (parity << 3); 207 | 208 | // Enable UART interrupt 209 | NVIC_EnableIRQ (UART_IRQn); 210 | 211 | 212 | return 1; 213 | } 214 | 215 | 216 | int32_t uart_get_configuration (UART_Configuration *config) { 217 | float br; 218 | uint32_t lcr; 219 | 220 | // line control parameter 221 | lcr = LPC_USART->LCR; 222 | 223 | // baudrate 224 | br = SystemCoreClock / (dll * 16); 225 | 226 | // If inside +/- 2% tolerance 227 | if (((br * 100) <= (baudrate * 102)) && ((br * 100) >= (baudrate * 98))) { 228 | config->Baudrate = baudrate; 229 | } else { 230 | config->Baudrate = br; 231 | } 232 | 233 | // get data bits 234 | switch ((lcr >> 0) & 3) { 235 | case 0: 236 | config->DataBits = UART_DATA_BITS_5; 237 | break; 238 | case 1: 239 | config->DataBits = UART_DATA_BITS_6; 240 | break; 241 | case 2: 242 | config->DataBits = UART_DATA_BITS_7; 243 | break; 244 | case 3: 245 | config->DataBits = UART_DATA_BITS_8; 246 | break; 247 | default: 248 | return 0; 249 | } 250 | 251 | // get parity 252 | switch ((lcr >> 3) & 7) { 253 | case 0: 254 | case 2: 255 | case 4: 256 | case 6: 257 | config->Parity = UART_PARITY_NONE; 258 | break; 259 | case 1: 260 | config->Parity = UART_PARITY_ODD; 261 | break; 262 | case 3: 263 | config->Parity = UART_PARITY_MARK; 264 | break; 265 | case 5: 266 | config->Parity = UART_PARITY_EVEN; 267 | break; 268 | case 7: 269 | config->Parity = UART_PARITY_SPACE; 270 | break; 271 | default: 272 | return 0; 273 | } 274 | 275 | // get stop bits 276 | switch ((lcr >> 2) & 1) { 277 | case 0: 278 | config->StopBits = UART_STOP_BITS_1; 279 | break; 280 | case 1: 281 | config->StopBits = UART_STOP_BITS_2; 282 | break; 283 | default: 284 | return 0; 285 | } 286 | 287 | // get flow control 288 | config->FlowControl = UART_FLOW_CONTROL_NONE; 289 | 290 | return 1; 291 | } 292 | 293 | int32_t uart_write_free(void) { 294 | return BUFFER_SIZE - (write_buffer.cnt_in - write_buffer.cnt_out); 295 | } 296 | 297 | int32_t uart_write_data (uint8_t *data, uint16_t size) { 298 | uint32_t cnt; 299 | int16_t len_in_buf; 300 | 301 | if (size == 0) { 302 | return 0; 303 | } 304 | 305 | cnt = 0; 306 | while (size--) { 307 | len_in_buf = write_buffer.cnt_in - write_buffer.cnt_out; 308 | if (len_in_buf < BUFFER_SIZE) { 309 | write_buffer.data[write_buffer.idx_in++] = *data++; 310 | write_buffer.idx_in &= (BUFFER_SIZE - 1); 311 | write_buffer.cnt_in++; 312 | cnt++; 313 | } 314 | } 315 | 316 | // enable THRE interrupt 317 | LPC_USART->IER |= (1 << 1); 318 | 319 | if (!tx_in_progress) { 320 | // force THRE interrupt to start 321 | NVIC_SetPendingIRQ(UART_IRQn); 322 | } 323 | 324 | return cnt; 325 | } 326 | 327 | 328 | int32_t uart_read_data (uint8_t *data, uint16_t size) { 329 | uint32_t cnt; 330 | 331 | if (size == 0) { 332 | return 0; 333 | } 334 | 335 | cnt = 0; 336 | while (size--) { 337 | if (read_buffer.cnt_in != read_buffer.cnt_out) { 338 | *data++ = read_buffer.data[read_buffer.idx_out++]; 339 | read_buffer.idx_out &= (BUFFER_SIZE - 1); 340 | read_buffer.cnt_out++; 341 | cnt++; 342 | } 343 | } 344 | 345 | return cnt; 346 | } 347 | 348 | 349 | void UART_IRQHandler (void) { 350 | uint32_t iir; 351 | int16_t len_in_buf; 352 | 353 | // read interrupt status 354 | iir = LPC_USART->IIR; 355 | 356 | // handle character to transmit 357 | if (write_buffer.cnt_in != write_buffer.cnt_out) { 358 | // if THR is empty 359 | if (LPC_USART->LSR & (1 << 5)) { 360 | LPC_USART->THR = write_buffer.data[write_buffer.idx_out++]; 361 | write_buffer.idx_out &= (BUFFER_SIZE - 1); 362 | write_buffer.cnt_out++; 363 | tx_in_progress = 1; 364 | } 365 | } else if (tx_in_progress) { 366 | tx_in_progress = 0; 367 | // disable THRE interrupt 368 | LPC_USART->IER &= ~(1 << 1); 369 | } 370 | 371 | // handle received character 372 | if (((iir & 0x0E) == 0x04) || // Rx interrupt (RDA) 373 | ((iir & 0x0E) == 0x0C)) { // Rx interrupt (CTI) 374 | while (LPC_USART->LSR & 0x01) { 375 | len_in_buf = read_buffer.cnt_in - read_buffer.cnt_out; 376 | read_buffer.data[read_buffer.idx_in++] = LPC_USART->RBR; 377 | read_buffer.idx_in &= (BUFFER_SIZE - 1); 378 | read_buffer.cnt_in++; 379 | // if buffer full: write by dropping oldest characters 380 | if (len_in_buf == BUFFER_SIZE) { 381 | read_buffer.idx_out++; 382 | read_buffer.idx_out &= (BUFFER_SIZE - 1); 383 | read_buffer.cnt_out++; 384 | } 385 | } 386 | } 387 | 388 | LPC_USART->LSR; 389 | } 390 | 391 | /*------------------------------------------------------------------------------ 392 | * End of file 393 | *----------------------------------------------------------------------------*/ 394 | 395 | -------------------------------------------------------------------------------- /interface/mdk/k20dx128/Abstract.txt: -------------------------------------------------------------------------------- 1 | CMSIS-DAP USB HID Firmware for Freescale MK20DX128VLH5 2 | Tested with these boards: 3 | Freescale Freedom K20D50M 4 | BOARD_FRDM_K20D50M (untested) 5 | -------------------------------------------------------------------------------- /interface/mdk/lpc11u35/Abstract.txt: -------------------------------------------------------------------------------- 1 | CMSIS-DAP USB HID Firmware for NXP LPC11U35 2 | Tested with these boards: 3 | Embedded Artists LPC11U35 QuickStart 4 | BOARD_EA_LPC11U35 5 | Micromint Bambino 210/210E 6 | BOARD_BAMBINO_210 7 | BOARD_BAMBINO_210E 8 | -------------------------------------------------------------------------------- /interface/mdk/lpc4320/Abstract.txt: -------------------------------------------------------------------------------- 1 | CMSIS-DAP USB HID Firmware for NXP LPC4320/LPC4330/LPC4370 2 | Tested with these boards: 3 | NXP LPC-Link 2 4 | BOARD_LPCLINK_2 5 | -------------------------------------------------------------------------------- /shared/USBStack/INC/rl_usb.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __RL_USB_H__ 17 | #define __RL_USB_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include "usb.h" 25 | 26 | /***************** Functions *************************************************/ 27 | 28 | /* USB Device functions exported from USB Device Core module */ 29 | extern void usbd_init (void); 30 | extern void usbd_connect (BOOL con); 31 | extern void usbd_reset_core (void); 32 | extern BOOL usbd_configured (void); 33 | 34 | /* USB Device user functions imported to USB HID Class module */ 35 | extern void usbd_hid_init (void); 36 | extern BOOL usbd_hid_get_report_trigger(U8 rid, U8 *buf, int len); 37 | extern int usbd_hid_get_report (U8 rtype, U8 rid, U8 *buf, U8 req); 38 | extern void usbd_hid_set_report (U8 rtype, U8 rid, U8 *buf, int len, U8 req); 39 | extern U8 usbd_hid_get_protocol (void); 40 | extern void usbd_hid_set_protocol (U8 protocol); 41 | 42 | /* USB Device user functions imported to USB Mass Storage Class module */ 43 | extern void usbd_msc_init (void); 44 | extern void usbd_msc_read_sect (U32 block, U8 *buf, U32 num_of_blocks); 45 | extern void usbd_msc_write_sect (U32 block, U8 *buf, U32 num_of_blocks); 46 | extern void usbd_msc_start_stop (BOOL start); 47 | 48 | /* USB Device user functions imported to USB Audio Class module */ 49 | extern void usbd_adc_init (void); 50 | 51 | /* USB Device CDC ACM class functions called automatically by USBD Core module*/ 52 | extern int32_t USBD_CDC_ACM_Initialize (void); 53 | extern int32_t USBD_CDC_ACM_Uninitialize (void); 54 | extern int32_t USBD_CDC_ACM_Reset (void); 55 | /* USB Device CDC ACM class user functions */ 56 | extern int32_t USBD_CDC_ACM_PortInitialize (void); 57 | extern int32_t USBD_CDC_ACM_PortUninitialize (void); 58 | extern int32_t USBD_CDC_ACM_PortReset (void); 59 | extern int32_t USBD_CDC_ACM_PortSetLineCoding (CDC_LINE_CODING *line_coding); 60 | extern int32_t USBD_CDC_ACM_PortGetLineCoding (CDC_LINE_CODING *line_coding); 61 | extern int32_t USBD_CDC_ACM_PortSetControlLineState (uint16_t ctrl_bmp); 62 | extern int32_t USBD_CDC_ACM_DataSend (const uint8_t *buf, int32_t len); 63 | extern int32_t USBD_CDC_ACM_DataFree (void); 64 | extern int32_t USBD_CDC_ACM_PutChar (const uint8_t ch); 65 | extern int32_t USBD_CDC_ACM_DataRead ( uint8_t *buf, int32_t len); 66 | extern int32_t USBD_CDC_ACM_GetChar (void); 67 | extern int32_t USBD_CDC_ACM_DataAvailable (void); 68 | extern int32_t USBD_CDC_ACM_Notify (uint16_t stat); 69 | /* USB Device CDC ACM class overridable functions */ 70 | extern int32_t USBD_CDC_ACM_SendEncapsulatedCommand (void); 71 | extern int32_t USBD_CDC_ACM_GetEncapsulatedResponse (void); 72 | extern int32_t USBD_CDC_ACM_SetCommFeature (uint16_t feat); 73 | extern int32_t USBD_CDC_ACM_GetCommFeature (uint16_t feat); 74 | extern int32_t USBD_CDC_ACM_ClearCommFeature (uint16_t feat); 75 | extern int32_t USBD_CDC_ACM_SetLineCoding (void); 76 | extern int32_t USBD_CDC_ACM_GetLineCoding (void); 77 | extern int32_t USBD_CDC_ACM_SetControlLineState (uint16_t ctrl_bmp); 78 | extern int32_t USBD_CDC_ACM_SendBreak (uint16_t dur); 79 | 80 | /* USB Device user functions imported to USB Custom Class module */ 81 | extern void usbd_cls_init (void); 82 | extern void usbd_cls_sof (void); 83 | extern BOOL usbd_cls_dev_req (BOOL setup); 84 | extern BOOL usbd_cls_if_req (BOOL setup); 85 | extern BOOL usbd_cls_ep_req (BOOL setup); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif /* __RL_USB_H__ */ 92 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usb.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USB_H__ 17 | #define __USB_H__ 18 | 19 | /* General USB header files */ 20 | #include "usb_def.h" 21 | #include "usb_cdc.h" 22 | #include "usb_hid.h" 23 | #include "usb_msc.h" 24 | 25 | /* USB Device header files */ 26 | #include "usbd_core.h" 27 | #include "usbd_core_cdc.h" 28 | #include "usbd_core_hid.h" 29 | #include "usbd_core_msc.h" 30 | 31 | #include "usbd_desc.h" 32 | #include "usbd_event.h" 33 | #include "usbd_cdc_acm.h" 34 | #include "usbd_hid.h" 35 | #include "usbd_msc.h" 36 | #include "usbd_hw.h" 37 | 38 | #endif /* __USB_H__ */ 39 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usb_cdc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USB_CDC_H 17 | #define __USB_CDC_H 18 | 19 | /*------------------------------------------------------------------------------ 20 | * Definitions based on usbcdc11.pdf (www.usb.org) 21 | *----------------------------------------------------------------------------*/ 22 | /* Communication device class specification version 1.10 */ 23 | #define CDC_V1_10 0x0110 24 | 25 | /* Communication interface class code */ 26 | /* (usbcdc11.pdf, 4.2, Table 15) */ 27 | #define CDC_COMMUNICATION_INTERFACE_CLASS 0x02 28 | 29 | /* Communication interface class subclass codes */ 30 | /* (usbcdc11.pdf, 4.3, Table 16) */ 31 | #define CDC_DIRECT_LINE_CONTROL_MODEL 0x01 32 | #define CDC_ABSTRACT_CONTROL_MODEL 0x02 33 | #define CDC_TELEPHONE_CONTROL_MODEL 0x03 34 | #define CDC_MULTI_CHANNEL_CONTROL_MODEL 0x04 35 | #define CDC_CAPI_CONTROL_MODEL 0x05 36 | #define CDC_ETHERNET_NETWORKING_CONTROL_MODEL 0x06 37 | #define CDC_ATM_NETWORKING_CONTROL_MODEL 0x07 38 | 39 | /* Communication interface class control protocol codes */ 40 | /* (usbcdc11.pdf, 4.4, Table 17) */ 41 | #define CDC_PROTOCOL_COMMON_AT_COMMANDS 0x01 42 | 43 | /* Data interface class code */ 44 | /* (usbcdc11.pdf, 4.5, Table 18) */ 45 | #define CDC_DATA_INTERFACE_CLASS 0x0A 46 | 47 | /* Data interface class protocol codes */ 48 | /* (usbcdc11.pdf, 4.7, Table 19) */ 49 | #define CDC_PROTOCOL_ISDN_BRI 0x30 50 | #define CDC_PROTOCOL_HDLC 0x31 51 | #define CDC_PROTOCOL_TRANSPARENT 0x32 52 | #define CDC_PROTOCOL_Q921_MANAGEMENT 0x50 53 | #define CDC_PROTOCOL_Q921_DATA_LINK 0x51 54 | #define CDC_PROTOCOL_Q921_MULTIPLEXOR 0x52 55 | #define CDC_PROTOCOL_V42 0x90 56 | #define CDC_PROTOCOL_EURO_ISDN 0x91 57 | #define CDC_PROTOCOL_V24_RATE_ADAPTATION 0x92 58 | #define CDC_PROTOCOL_CAPI 0x93 59 | #define CDC_PROTOCOL_HOST_BASED_DRIVER 0xFD 60 | #define CDC_PROTOCOL_DESCRIBED_IN_PUFD 0xFE 61 | 62 | /* Type values for bDescriptorType field of functional descriptors */ 63 | /* (usbcdc11.pdf, 5.2.3, Table 24) */ 64 | #define CDC_CS_INTERFACE 0x24 65 | #define CDC_CS_ENDPOINT 0x25 66 | 67 | /* Type values for bDescriptorSubtype field of functional descriptors */ 68 | /* (usbcdc11.pdf, 5.2.3, Table 25) */ 69 | #define CDC_HEADER 0x00 70 | #define CDC_CALL_MANAGEMENT 0x01 71 | #define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02 72 | #define CDC_DIRECT_LINE_MANAGEMENT 0x03 73 | #define CDC_TELEPHONE_RINGER 0x04 74 | #define CDC_REPORTING_CAPABILITIES 0x05 75 | #define CDC_UNION 0x06 76 | #define CDC_COUNTRY_SELECTION 0x07 77 | #define CDC_TELEPHONE_OPERATIONAL_MODES 0x08 78 | #define CDC_USB_TERMINAL 0x09 79 | #define CDC_NETWORK_CHANNEL 0x0A 80 | #define CDC_PROTOCOL_UNIT 0x0B 81 | #define CDC_EXTENSION_UNIT 0x0C 82 | #define CDC_MULTI_CHANNEL_MANAGEMENT 0x0D 83 | #define CDC_CAPI_CONTROL_MANAGEMENT 0x0E 84 | #define CDC_ETHERNET_NETWORKING 0x0F 85 | #define CDC_ATM_NETWORKING 0x10 86 | 87 | /* CDC class-specific request codes */ 88 | /* (usbcdc11.pdf, 6.2, Table 46) */ 89 | /* see Table 45 for info about the specific requests. */ 90 | #define CDC_SEND_ENCAPSULATED_COMMAND 0x00 91 | #define CDC_GET_ENCAPSULATED_RESPONSE 0x01 92 | #define CDC_SET_COMM_FEATURE 0x02 93 | #define CDC_GET_COMM_FEATURE 0x03 94 | #define CDC_CLEAR_COMM_FEATURE 0x04 95 | #define CDC_SET_AUX_LINE_STATE 0x10 96 | #define CDC_SET_HOOK_STATE 0x11 97 | #define CDC_PULSE_SETUP 0x12 98 | #define CDC_SEND_PULSE 0x13 99 | #define CDC_SET_PULSE_TIME 0x14 100 | #define CDC_RING_AUX_JACK 0x15 101 | #define CDC_SET_LINE_CODING 0x20 102 | #define CDC_GET_LINE_CODING 0x21 103 | #define CDC_SET_CONTROL_LINE_STATE 0x22 104 | #define CDC_SEND_BREAK 0x23 105 | #define CDC_SET_RINGER_PARMS 0x30 106 | #define CDC_GET_RINGER_PARMS 0x31 107 | #define CDC_SET_OPERATION_PARMS 0x32 108 | #define CDC_GET_OPERATION_PARMS 0x33 109 | #define CDC_SET_LINE_PARMS 0x34 110 | #define CDC_GET_LINE_PARMS 0x35 111 | #define CDC_DIAL_DIGITS 0x36 112 | #define CDC_SET_UNIT_PARAMETER 0x37 113 | #define CDC_GET_UNIT_PARAMETER 0x38 114 | #define CDC_CLEAR_UNIT_PARAMETER 0x39 115 | #define CDC_GET_PROFILE 0x3A 116 | #define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40 117 | #define CDC_SET_ETHERNET_PMP_FILTER 0x41 118 | #define CDC_GET_ETHERNET_PMP_FILTER 0x42 119 | #define CDC_SET_ETHERNET_PACKET_FILTER 0x43 120 | #define CDC_GET_ETHERNET_STATISTIC 0x44 121 | #define CDC_SET_ATM_DATA_FORMAT 0x50 122 | #define CDC_GET_ATM_DEVICE_STATISTICS 0x51 123 | #define CDC_SET_ATM_DEFAULT_VC 0x52 124 | #define CDC_GET_ATM_VC_STATISTICS 0x53 125 | 126 | /* Communication feature selector codes */ 127 | /* (usbcdc11.pdf, 6.2.2..6.2.4, Table 47) */ 128 | #define CDC_ABSTRACT_STATE 0x01 129 | #define CDC_COUNTRY_SETTING 0x02 130 | 131 | /* Feature Status returned for ABSTRACT_STATE Selector */ 132 | /* (usbcdc11.pdf, 6.2.3, Table 48) */ 133 | #define CDC_IDLE_SETTING (1 << 0) 134 | #define CDC_DATA_MULTPLEXED_STATE (1 << 1) 135 | 136 | 137 | /* Control signal bitmap values for the SetControlLineState request */ 138 | /* (usbcdc11.pdf, 6.2.14, Table 51) */ 139 | #define CDC_DTE_PRESENT (1 << 0) 140 | #define CDC_ACTIVATE_CARRIER (1 << 1) 141 | 142 | /* CDC class-specific notification codes */ 143 | /* (usbcdc11.pdf, 6.3, Table 68) */ 144 | /* see Table 67 for Info about class-specific notifications */ 145 | #define CDC_NOTIFICATION_NETWORK_CONNECTION 0x00 146 | #define CDC_RESPONSE_AVAILABLE 0x01 147 | #define CDC_AUX_JACK_HOOK_STATE 0x08 148 | #define CDC_RING_DETECT 0x09 149 | #define CDC_NOTIFICATION_SERIAL_STATE 0x20 150 | #define CDC_CALL_STATE_CHANGE 0x28 151 | #define CDC_LINE_STATE_CHANGE 0x29 152 | #define CDC_CONNECTION_SPEED_CHANGE 0x2A 153 | 154 | /* UART state bitmap values (Serial state notification). */ 155 | /* (usbcdc11.pdf, 6.3.5, Table 69) */ 156 | #define CDC_SERIAL_STATE_OVERRUN (1 << 6) /* receive data overrun error has occurred */ 157 | #define CDC_SERIAL_STATE_OVERRUN_Pos ( 6) 158 | #define CDC_SERIAL_STATE_OVERRUN_Msk (1 << CDC_SERIAL_STATE_OVERRUN_Pos) 159 | #define CDC_SERIAL_STATE_PARITY (1 << 5) /* parity error has occurred */ 160 | #define CDC_SERIAL_STATE_PARITY_Pos ( 5) 161 | #define CDC_SERIAL_STATE_PARITY_Msk (1 << CDC_SERIAL_STATE_PARITY_Pos) 162 | #define CDC_SERIAL_STATE_FRAMING (1 << 4) /* framing error has occurred */ 163 | #define CDC_SERIAL_STATE_FRAMING_Pos ( 4) 164 | #define CDC_SERIAL_STATE_FRAMING_Msk (1 << CDC_SERIAL_STATE_FRAMING_Pos) 165 | #define CDC_SERIAL_STATE_RING (1 << 3) /* state of ring signal detection */ 166 | #define CDC_SERIAL_STATE_RING_Pos ( 3) 167 | #define CDC_SERIAL_STATE_RING_Msk (1 << CDC_SERIAL_STATE_RING_Pos) 168 | #define CDC_SERIAL_STATE_BREAK (1 << 2) /* state of break detection */ 169 | #define CDC_SERIAL_STATE_BREAK_Pos ( 2) 170 | #define CDC_SERIAL_STATE_BREAK_Msk (1 << CDC_SERIAL_STATE_BREAK_Pos) 171 | #define CDC_SERIAL_STATE_TX_CARRIER (1 << 1) /* state of transmission carrier */ 172 | #define CDC_SERIAL_STATE_TX_CARRIER_Pos ( 1) 173 | #define CDC_SERIAL_STATE_TX_CARRIER_Msk (1 << CDC_SERIAL_STATE_TX_CARRIER_Pos) 174 | #define CDC_SERIAL_STATE_RX_CARRIER (1 << 0) /* state of receiver carrier */ 175 | #define CDC_SERIAL_STATE_RX_CARRIER_Pos ( 0) 176 | #define CDC_SERIAL_STATE_RX_CARRIER_Msk (1 << CDC_SERIAL_STATE_RX_CARRIER_Pos) 177 | 178 | 179 | /*------------------------------------------------------------------------------ 180 | * Structures based on usbcdc11.pdf (www.usb.org) 181 | *----------------------------------------------------------------------------*/ 182 | 183 | /* Header functional descriptor */ 184 | /* (usbcdc11.pdf, 5.2.3.1) */ 185 | /* This header must precede any list of class-specific descriptors. */ 186 | typedef __packed struct _CDC_HEADER_DESCRIPTOR{ 187 | U8 bFunctionLength; /* size of this descriptor in bytes */ 188 | U8 bDescriptorType; /* CS_INTERFACE descriptor type */ 189 | U8 bDescriptorSubtype; /* Header functional descriptor subtype */ 190 | U16 bcdCDC; /* USB CDC specification release version */ 191 | } CDC_HEADER_DESCRIPTOR; 192 | 193 | /* Call management functional descriptor */ 194 | /* (usbcdc11.pdf, 5.2.3.2) */ 195 | /* Describes the processing of calls for the communication class interface. */ 196 | typedef __packed struct _CDC_CALL_MANAGEMENT_DESCRIPTOR { 197 | U8 bFunctionLength; /* size of this descriptor in bytes */ 198 | U8 bDescriptorType; /* CS_INTERFACE descriptor type */ 199 | U8 bDescriptorSubtype; /* call management functional descriptor subtype */ 200 | U8 bmCapabilities; /* capabilities that this configuration supports */ 201 | U8 bDataInterface; /* interface number of the data class interface used for call management (optional) */ 202 | } CDC_CALL_MANAGEMENT_DESCRIPTOR; 203 | 204 | /* Abstract control management functional descriptor */ 205 | /* (usbcdc11.pdf, 5.2.3.3) */ 206 | /* Describes the command supported by the communication interface class with the Abstract Control Model subclass code. */ 207 | typedef __packed struct _CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR { 208 | U8 bFunctionLength; /* size of this descriptor in bytes */ 209 | U8 bDescriptorType; /* CS_INTERFACE descriptor type */ 210 | U8 bDescriptorSubtype; /* abstract control management functional descriptor subtype */ 211 | U8 bmCapabilities; /* capabilities supported by this configuration */ 212 | } CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR; 213 | 214 | /* Union functional descriptors */ 215 | /* (usbcdc11.pdf, 5.2.3.8) */ 216 | /* Describes the relationship between a group of interfaces that can be considered to form a functional unit. */ 217 | typedef __packed struct _CDC_UNION_DESCRIPTOR { 218 | U8 bFunctionLength; /* size of this descriptor in bytes */ 219 | U8 bDescriptorType; /* CS_INTERFACE descriptor type */ 220 | U8 bDescriptorSubtype; /* union functional descriptor subtype */ 221 | U8 bMasterInterface; /* interface number designated as master */ 222 | } CDC_UNION_DESCRIPTOR; 223 | 224 | /* Union functional descriptors with one slave interface */ 225 | /* (usbcdc11.pdf, 5.2.3.8) */ 226 | typedef __packed struct _CDC_UNION_1SLAVE_DESCRIPTOR { 227 | CDC_UNION_DESCRIPTOR sUnion; /* Union functional descriptor */ 228 | U8 bSlaveInterfaces[1]; /* Slave interface 0 */ 229 | } CDC_UNION_1SLAVE_DESCRIPTOR; 230 | 231 | /* Line coding structure */ 232 | /* Format of the data returned when a GetLineCoding request is received */ 233 | /* (usbcdc11.pdf, 6.2.13) */ 234 | typedef __packed struct _CDC_LINE_CODING { 235 | U32 dwDTERate; /* Data terminal rate in bits per second */ 236 | U8 bCharFormat; /* Number of stop bits */ 237 | U8 bParityType; /* Parity bit type */ 238 | U8 bDataBits; /* Number of data bits */ 239 | } CDC_LINE_CODING; 240 | 241 | /* Notification header */ 242 | /* Data sent on the notification endpoint must follow this header. */ 243 | /* see USB_SETUP_PACKET in file usb.h */ 244 | typedef USB_SETUP_PACKET CDC_NOTIFICATION_HEADER; 245 | 246 | #endif /* __USB_CDC_H */ 247 | 248 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usb_def.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USB_DEF_H__ 17 | #define __USB_DEF_H__ 18 | 19 | #pragma anon_unions 20 | 21 | 22 | /* bmRequestType.Dir */ 23 | #define REQUEST_HOST_TO_DEVICE 0 24 | #define REQUEST_DEVICE_TO_HOST 1 25 | 26 | /* bmRequestType.Type */ 27 | #define REQUEST_STANDARD 0 28 | #define REQUEST_CLASS 1 29 | #define REQUEST_VENDOR 2 30 | #define REQUEST_RESERVED 3 31 | 32 | /* bmRequestType.Recipient */ 33 | #define REQUEST_TO_DEVICE 0 34 | #define REQUEST_TO_INTERFACE 1 35 | #define REQUEST_TO_ENDPOINT 2 36 | #define REQUEST_TO_OTHER 3 37 | 38 | /* bmRequestType Definition */ 39 | typedef __packed struct _REQUEST_TYPE { 40 | U8 Recipient : 5; /* D4..0: Recipient */ 41 | U8 Type : 2; /* D6..5: Type */ 42 | U8 Dir : 1; /* D7: Data Phase Txsfer Direction */ 43 | } REQUEST_TYPE; 44 | 45 | /* USB Standard Request Codes */ 46 | #define USB_REQUEST_GET_STATUS 0 47 | #define USB_REQUEST_CLEAR_FEATURE 1 48 | #define USB_REQUEST_SET_FEATURE 3 49 | #define USB_REQUEST_SET_ADDRESS 5 50 | #define USB_REQUEST_GET_DESCRIPTOR 6 51 | #define USB_REQUEST_SET_DESCRIPTOR 7 52 | #define USB_REQUEST_GET_CONFIGURATION 8 53 | #define USB_REQUEST_SET_CONFIGURATION 9 54 | #define USB_REQUEST_GET_INTERFACE 10 55 | #define USB_REQUEST_SET_INTERFACE 11 56 | #define USB_REQUEST_SYNC_FRAME 12 57 | 58 | /* USB GET_STATUS Bit Values */ 59 | #define USB_GETSTATUS_SELF_POWERED 0x01 60 | #define USB_GETSTATUS_REMOTE_WAKEUP 0x02 61 | #define USB_GETSTATUS_ENDPOINT_STALL 0x01 62 | 63 | /* USB Standard Feature selectors */ 64 | #define USB_FEATURE_ENDPOINT_STALL 0 65 | #define USB_FEATURE_REMOTE_WAKEUP 1 66 | 67 | /* USB Default Control Pipe Setup Packet */ 68 | typedef __packed struct _USB_SETUP_PACKET { 69 | REQUEST_TYPE bmRequestType; /* bmRequestType */ 70 | U8 bRequest; /* bRequest */ 71 | __packed union { 72 | U16 wValue; /* wValue */ 73 | __packed struct { 74 | U8 wValueL; 75 | U8 wValueH; 76 | }; 77 | }; 78 | __packed union { 79 | U16 wIndex; /* wIndex */ 80 | __packed struct { 81 | U8 wIndexL; 82 | U8 wIndexH; 83 | }; 84 | }; 85 | U16 wLength; /* wLength */ 86 | } USB_SETUP_PACKET; 87 | 88 | 89 | /* USB Descriptor Types */ 90 | #define USB_DEVICE_DESCRIPTOR_TYPE 1 91 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 92 | #define USB_STRING_DESCRIPTOR_TYPE 3 93 | #define USB_INTERFACE_DESCRIPTOR_TYPE 4 94 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 5 95 | #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6 96 | #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7 97 | #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8 98 | #define USB_OTG_DESCRIPTOR_TYPE 9 99 | #define USB_DEBUG_DESCRIPTOR_TYPE 10 100 | #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11 101 | 102 | /* USB Device Classes */ 103 | #define USB_DEVICE_CLASS_RESERVED 0x00 104 | #define USB_DEVICE_CLASS_AUDIO 0x01 105 | #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 106 | #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 107 | #define USB_DEVICE_CLASS_MONITOR 0x04 108 | #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 109 | #define USB_DEVICE_CLASS_POWER 0x06 110 | #define USB_DEVICE_CLASS_PRINTER 0x07 111 | #define USB_DEVICE_CLASS_STORAGE 0x08 112 | #define USB_DEVICE_CLASS_HUB 0x09 113 | #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF 114 | #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF 115 | 116 | /* bmAttributes in Configuration Descriptor */ 117 | #define USB_CONFIG_POWERED_MASK 0x40 118 | #define USB_CONFIG_BUS_POWERED 0x80 119 | #define USB_CONFIG_SELF_POWERED 0xC0 120 | #define USB_CONFIG_REMOTE_WAKEUP 0x20 121 | 122 | /* bMaxPower in Configuration Descriptor */ 123 | #define USB_CONFIG_POWER_MA(mA) ((mA)/2) 124 | 125 | /* bEndpointAddress in Endpoint Descriptor */ 126 | #define USB_ENDPOINT_DIRECTION_MASK 0x80 127 | #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) 128 | #define USB_ENDPOINT_IN(addr) ((addr) | 0x80) 129 | 130 | /* bmAttributes in Endpoint Descriptor */ 131 | #define USB_ENDPOINT_TYPE_MASK 0x03 132 | #define USB_ENDPOINT_TYPE_CONTROL 0x00 133 | #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 134 | #define USB_ENDPOINT_TYPE_BULK 0x02 135 | #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 136 | #define USB_ENDPOINT_SYNC_MASK 0x0C 137 | #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 138 | #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 139 | #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 140 | #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C 141 | #define USB_ENDPOINT_USAGE_MASK 0x30 142 | #define USB_ENDPOINT_USAGE_DATA 0x00 143 | #define USB_ENDPOINT_USAGE_FEEDBACK 0x10 144 | #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 145 | #define USB_ENDPOINT_USAGE_RESERVED 0x30 146 | 147 | /* USB Standard Device Descriptor */ 148 | typedef __packed struct _USB_DEVICE_DESCRIPTOR { 149 | U8 bLength; 150 | U8 bDescriptorType; 151 | U16 bcdUSB; 152 | U8 bDeviceClass; 153 | U8 bDeviceSubClass; 154 | U8 bDeviceProtocol; 155 | U8 bMaxPacketSize0; 156 | U16 idVendor; 157 | U16 idProduct; 158 | U16 bcdDevice; 159 | U8 iManufacturer; 160 | U8 iProduct; 161 | U8 iSerialNumber; 162 | U8 bNumConfigurations; 163 | } USB_DEVICE_DESCRIPTOR; 164 | 165 | /* USB 2.0 Device Qualifier Descriptor */ 166 | typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR { 167 | U8 bLength; 168 | U8 bDescriptorType; 169 | U16 bcdUSB; 170 | U8 bDeviceClass; 171 | U8 bDeviceSubClass; 172 | U8 bDeviceProtocol; 173 | U8 bMaxPacketSize0; 174 | U8 bNumConfigurations; 175 | U8 bReserved; 176 | } USB_DEVICE_QUALIFIER_DESCRIPTOR; 177 | 178 | /* USB Standard Configuration Descriptor */ 179 | typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR { 180 | U8 bLength; 181 | U8 bDescriptorType; 182 | U16 wTotalLength; 183 | U8 bNumInterfaces; 184 | U8 bConfigurationValue; 185 | U8 iConfiguration; 186 | U8 bmAttributes; 187 | U8 bMaxPower; 188 | } USB_CONFIGURATION_DESCRIPTOR; 189 | 190 | /* USB Standard Interface Descriptor */ 191 | typedef __packed struct _USB_INTERFACE_DESCRIPTOR { 192 | U8 bLength; 193 | U8 bDescriptorType; 194 | U8 bInterfaceNumber; 195 | U8 bAlternateSetting; 196 | U8 bNumEndpoints; 197 | U8 bInterfaceClass; 198 | U8 bInterfaceSubClass; 199 | U8 bInterfaceProtocol; 200 | U8 iInterface; 201 | } USB_INTERFACE_DESCRIPTOR; 202 | 203 | /* USB Standard Endpoint Descriptor */ 204 | typedef __packed struct _USB_ENDPOINT_DESCRIPTOR { 205 | U8 bLength; 206 | U8 bDescriptorType; 207 | U8 bEndpointAddress; 208 | U8 bmAttributes; 209 | U16 wMaxPacketSize; 210 | U8 bInterval; 211 | } USB_ENDPOINT_DESCRIPTOR; 212 | 213 | /* USB String Descriptor */ 214 | typedef __packed struct _USB_STRING_DESCRIPTOR { 215 | U8 bLength; 216 | U8 bDescriptorType; 217 | U16 bString/*[]*/; 218 | } USB_STRING_DESCRIPTOR; 219 | 220 | /* USB Common Descriptor */ 221 | typedef __packed struct _USB_COMMON_DESCRIPTOR { 222 | U8 bLength; 223 | U8 bDescriptorType; 224 | } USB_COMMON_DESCRIPTOR; 225 | 226 | /* USB Interface Association Descriptor */ 227 | typedef __packed struct _USB_INTERFACE_ASSOCIATION_DESCRIPTOR { 228 | U8 bLength; 229 | U8 bDescriptorType; 230 | U8 bFirstInterface; 231 | U8 bInterfaceCount; 232 | U8 bFunctionClass; 233 | U8 bFunctionSubclass; 234 | U8 bFunctionProtocol; 235 | U8 iFunction; 236 | } USB_INTERFACE_ASSOCIATION_DESCRIPTOR; 237 | 238 | 239 | #endif /* __USB_DEF_H__ */ 240 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usb_for_lib.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USB_FOR_LIB_H__ 17 | #define __USB_FOR_LIB_H__ 18 | 19 | /* USB Device header files */ 20 | #include "usbd_lib_cdc.h" 21 | #include "usbd_lib_hid.h" 22 | #include "usbd_lib_msc.h" 23 | 24 | /* USB System Configuration header file */ 25 | #include "usb_lib.h" 26 | 27 | #endif /* __USB_FOR_LIB_H__ */ 28 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usb_hid.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USB_HID_H__ 17 | #define __USB_HID_H__ 18 | 19 | 20 | /* HID Subclass Codes */ 21 | #define HID_SUBCLASS_NONE 0x00 22 | #define HID_SUBCLASS_BOOT 0x01 23 | 24 | /* HID Protocol Codes */ 25 | #define HID_PROTOCOL_NONE 0x00 26 | #define HID_PROTOCOL_BOOT 0x00 27 | #define HID_PROTOCOL_KEYBOARD 0x01 28 | #define HID_PROTOCOL_REPORT 0x01 29 | #define HID_PROTOCOL_MOUSE 0x02 30 | 31 | 32 | /* HID Descriptor Types */ 33 | #define HID_HID_DESCRIPTOR_TYPE 0x21 34 | #define HID_REPORT_DESCRIPTOR_TYPE 0x22 35 | #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 36 | 37 | 38 | /* HID Descriptor */ 39 | typedef __packed struct _HID_DESCRIPTOR { 40 | U8 bLength; 41 | U8 bDescriptorType; 42 | U16 bcdHID; 43 | U8 bCountryCode; 44 | U8 bNumDescriptors; 45 | /* Array of one or more descriptors */ 46 | __packed struct _HID_DESCRIPTOR_LIST { 47 | U8 bDescriptorType; 48 | U16 wDescriptorLength; 49 | } DescriptorList[1]; 50 | } HID_DESCRIPTOR; 51 | 52 | 53 | /* HID Request Codes */ 54 | #define HID_REQUEST_GET_REPORT 0x01 55 | #define HID_REQUEST_GET_IDLE 0x02 56 | #define HID_REQUEST_GET_PROTOCOL 0x03 57 | #define HID_REQUEST_SET_REPORT 0x09 58 | #define HID_REQUEST_SET_IDLE 0x0A 59 | #define HID_REQUEST_SET_PROTOCOL 0x0B 60 | 61 | /* HID Report Types */ 62 | #define HID_REPORT_INPUT 0x01 63 | #define HID_REPORT_OUTPUT 0x02 64 | #define HID_REPORT_FEATURE 0x03 65 | 66 | 67 | /* Usage Pages */ 68 | #define HID_USAGE_PAGE_UNDEFINED 0x00 69 | #define HID_USAGE_PAGE_GENERIC 0x01 70 | #define HID_USAGE_PAGE_SIMULATION 0x02 71 | #define HID_USAGE_PAGE_VR 0x03 72 | #define HID_USAGE_PAGE_SPORT 0x04 73 | #define HID_USAGE_PAGE_GAME 0x05 74 | #define HID_USAGE_PAGE_DEV_CONTROLS 0x06 75 | #define HID_USAGE_PAGE_KEYBOARD 0x07 76 | #define HID_USAGE_PAGE_LED 0x08 77 | #define HID_USAGE_PAGE_BUTTON 0x09 78 | #define HID_USAGE_PAGE_ORDINAL 0x0A 79 | #define HID_USAGE_PAGE_TELEPHONY 0x0B 80 | #define HID_USAGE_PAGE_CONSUMER 0x0C 81 | #define HID_USAGE_PAGE_DIGITIZER 0x0D 82 | #define HID_USAGE_PAGE_UNICODE 0x10 83 | #define HID_USAGE_PAGE_ALPHANUMERIC 0x14 84 | /* ... */ 85 | 86 | 87 | /* Generic Desktop Page (0x01) */ 88 | #define HID_USAGE_GENERIC_POINTER 0x01 89 | #define HID_USAGE_GENERIC_MOUSE 0x02 90 | #define HID_USAGE_GENERIC_JOYSTICK 0x04 91 | #define HID_USAGE_GENERIC_GAMEPAD 0x05 92 | #define HID_USAGE_GENERIC_KEYBOARD 0x06 93 | #define HID_USAGE_GENERIC_KEYPAD 0x07 94 | #define HID_USAGE_GENERIC_X 0x30 95 | #define HID_USAGE_GENERIC_Y 0x31 96 | #define HID_USAGE_GENERIC_Z 0x32 97 | #define HID_USAGE_GENERIC_RX 0x33 98 | #define HID_USAGE_GENERIC_RY 0x34 99 | #define HID_USAGE_GENERIC_RZ 0x35 100 | #define HID_USAGE_GENERIC_SLIDER 0x36 101 | #define HID_USAGE_GENERIC_DIAL 0x37 102 | #define HID_USAGE_GENERIC_WHEEL 0x38 103 | #define HID_USAGE_GENERIC_HATSWITCH 0x39 104 | #define HID_USAGE_GENERIC_COUNTED_BUFFER 0x3A 105 | #define HID_USAGE_GENERIC_BYTE_COUNT 0x3B 106 | #define HID_USAGE_GENERIC_MOTION_WAKEUP 0x3C 107 | #define HID_USAGE_GENERIC_VX 0x40 108 | #define HID_USAGE_GENERIC_VY 0x41 109 | #define HID_USAGE_GENERIC_VZ 0x42 110 | #define HID_USAGE_GENERIC_VBRX 0x43 111 | #define HID_USAGE_GENERIC_VBRY 0x44 112 | #define HID_USAGE_GENERIC_VBRZ 0x45 113 | #define HID_USAGE_GENERIC_VNO 0x46 114 | #define HID_USAGE_GENERIC_SYSTEM_CTL 0x80 115 | #define HID_USAGE_GENERIC_SYSCTL_POWER 0x81 116 | #define HID_USAGE_GENERIC_SYSCTL_SLEEP 0x82 117 | #define HID_USAGE_GENERIC_SYSCTL_WAKE 0x83 118 | #define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU 0x84 119 | #define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU 0x85 120 | #define HID_USAGE_GENERIC_SYSCTL_APP_MENU 0x86 121 | #define HID_USAGE_GENERIC_SYSCTL_HELP_MENU 0x87 122 | #define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT 0x88 123 | #define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT 0x89 124 | #define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT 0x8A 125 | #define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT 0x8B 126 | #define HID_USAGE_GENERIC_SYSCTL_MENU_UP 0x8C 127 | #define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN 0x8D 128 | /* ... */ 129 | 130 | /* Simulation Controls Page (0x02) */ 131 | /* ... */ 132 | #define HID_USAGE_SIMULATION_RUDDER 0xBA 133 | #define HID_USAGE_SIMULATION_THROTTLE 0xBB 134 | /* ... */ 135 | 136 | /* Virtual Reality Controls Page (0x03) */ 137 | /* ... */ 138 | 139 | /* Sport Controls Page (0x04) */ 140 | /* ... */ 141 | 142 | /* Game Controls Page (0x05) */ 143 | /* ... */ 144 | 145 | /* Generic Device Controls Page (0x06) */ 146 | /* ... */ 147 | 148 | /* Keyboard/Keypad Page (0x07) */ 149 | 150 | /* Keyboard Usage Keys */ 151 | extern const unsigned char HID_KEYBOARD_ID_TO_ASCII[256]; 152 | extern const unsigned char HID_KEYBOARD_ALT_ID_TO_ASCII[57]; 153 | 154 | /* Error "Keys" */ 155 | #define HID_USAGE_KEYBOARD_NOEVENT 0x00 156 | #define HID_USAGE_KEYBOARD_ROLLOVER 0x01 157 | #define HID_USAGE_KEYBOARD_POSTFAIL 0x02 158 | #define HID_USAGE_KEYBOARD_UNDEFINED 0x03 159 | 160 | /* Letters */ 161 | #define HID_USAGE_KEYBOARD_aA 0x04 162 | #define HID_USAGE_KEYBOARD_zZ 0x1D 163 | 164 | /* Numbers */ 165 | #define HID_USAGE_KEYBOARD_ONE 0x1E 166 | #define HID_USAGE_KEYBOARD_ZERO 0x27 167 | 168 | #define HID_USAGE_KEYBOARD_RETURN 0x28 169 | #define HID_USAGE_KEYBOARD_ESCAPE 0x29 170 | #define HID_USAGE_KEYBOARD_DELETE 0x2A 171 | 172 | /* Funtion Keys */ 173 | #define HID_USAGE_KEYBOARD_F1 0x3A 174 | #define HID_USAGE_KEYBOARD_F12 0x45 175 | 176 | #define HID_USAGE_KEYBOARD_PRINT_SCREEN 0x46 177 | 178 | /* Modifier Keys */ 179 | #define HID_USAGE_KEYBOARD_LCTRL 0xE0 180 | #define HID_USAGE_KEYBOARD_LSHFT 0xE1 181 | #define HID_USAGE_KEYBOARD_LALT 0xE2 182 | #define HID_USAGE_KEYBOARD_LGUI 0xE3 183 | #define HID_USAGE_KEYBOARD_RCTRL 0xE4 184 | #define HID_USAGE_KEYBOARD_RSHFT 0xE5 185 | #define HID_USAGE_KEYBOARD_RALT 0xE6 186 | #define HID_USAGE_KEYBOARD_RGUI 0xE7 187 | #define HID_USAGE_KEYBOARD_SCROLL_LOCK 0x47 188 | #define HID_USAGE_KEYBOARD_NUM_LOCK 0x53 189 | #define HID_USAGE_KEYBOARD_CAPS_LOCK 0x39 190 | 191 | /* Modifier Keys (values) */ 192 | #define HID_USAGE_KEYBOARD_MOD_LCTRL 0x01 193 | #define HID_USAGE_KEYBOARD_MOD_LSHIFT 0x02 194 | #define HID_USAGE_KEYBOARD_MOD_LALTL 0x04 195 | #define HID_USAGE_KEYBOARD_MOD_LGUI 0x08 196 | #define HID_USAGE_KEYBOARD_MOD_RCTRL 0x10 197 | #define HID_USAGE_KEYBOARD_MOD_RSHIFT 0x20 198 | #define HID_USAGE_KEYBOARD_MOD_RALTL 0x40 199 | #define HID_USAGE_KEYBOARD_MOD_RGUI 0x80 200 | 201 | /* ... */ 202 | 203 | /* LED Page (0x08) */ 204 | #define HID_USAGE_LED_NUM_LOCK 0x01 205 | #define HID_USAGE_LED_CAPS_LOCK 0x02 206 | #define HID_USAGE_LED_SCROLL_LOCK 0x03 207 | #define HID_USAGE_LED_COMPOSE 0x04 208 | #define HID_USAGE_LED_KANA 0x05 209 | #define HID_USAGE_LED_POWER 0x06 210 | #define HID_USAGE_LED_SHIFT 0x07 211 | #define HID_USAGE_LED_DO_NOT_DISTURB 0x08 212 | #define HID_USAGE_LED_MUTE 0x09 213 | #define HID_USAGE_LED_TONE_ENABLE 0x0A 214 | #define HID_USAGE_LED_HIGH_CUT_FILTER 0x0B 215 | #define HID_USAGE_LED_LOW_CUT_FILTER 0x0C 216 | #define HID_USAGE_LED_EQUALIZER_ENABLE 0x0D 217 | #define HID_USAGE_LED_SOUND_FIELD_ON 0x0E 218 | #define HID_USAGE_LED_SURROUND_FIELD_ON 0x0F 219 | #define HID_USAGE_LED_REPEAT 0x10 220 | #define HID_USAGE_LED_STEREO 0x11 221 | #define HID_USAGE_LED_SAMPLING_RATE_DETECT 0x12 222 | #define HID_USAGE_LED_SPINNING 0x13 223 | #define HID_USAGE_LED_CAV 0x14 224 | #define HID_USAGE_LED_CLV 0x15 225 | #define HID_USAGE_LED_RECORDING_FORMAT_DET 0x16 226 | #define HID_USAGE_LED_OFF_HOOK 0x17 227 | #define HID_USAGE_LED_RING 0x18 228 | #define HID_USAGE_LED_MESSAGE_WAITING 0x19 229 | #define HID_USAGE_LED_DATA_MODE 0x1A 230 | #define HID_USAGE_LED_BATTERY_OPERATION 0x1B 231 | #define HID_USAGE_LED_BATTERY_OK 0x1C 232 | #define HID_USAGE_LED_BATTERY_LOW 0x1D 233 | #define HID_USAGE_LED_SPEAKER 0x1E 234 | #define HID_USAGE_LED_HEAD_SET 0x1F 235 | #define HID_USAGE_LED_HOLD 0x20 236 | #define HID_USAGE_LED_MICROPHONE 0x21 237 | #define HID_USAGE_LED_COVERAGE 0x22 238 | #define HID_USAGE_LED_NIGHT_MODE 0x23 239 | #define HID_USAGE_LED_SEND_CALLS 0x24 240 | #define HID_USAGE_LED_CALL_PICKUP 0x25 241 | #define HID_USAGE_LED_CONFERENCE 0x26 242 | #define HID_USAGE_LED_STAND_BY 0x27 243 | #define HID_USAGE_LED_CAMERA_ON 0x28 244 | #define HID_USAGE_LED_CAMERA_OFF 0x29 245 | #define HID_USAGE_LED_ON_LINE 0x2A 246 | #define HID_USAGE_LED_OFF_LINE 0x2B 247 | #define HID_USAGE_LED_BUSY 0x2C 248 | #define HID_USAGE_LED_READY 0x2D 249 | #define HID_USAGE_LED_PAPER_OUT 0x2E 250 | #define HID_USAGE_LED_PAPER_JAM 0x2F 251 | #define HID_USAGE_LED_REMOTE 0x30 252 | #define HID_USAGE_LED_FORWARD 0x31 253 | #define HID_USAGE_LED_REVERSE 0x32 254 | #define HID_USAGE_LED_STOP 0x33 255 | #define HID_USAGE_LED_REWIND 0x34 256 | #define HID_USAGE_LED_FAST_FORWARD 0x35 257 | #define HID_USAGE_LED_PLAY 0x36 258 | #define HID_USAGE_LED_PAUSE 0x37 259 | #define HID_USAGE_LED_RECORD 0x38 260 | #define HID_USAGE_LED_ERROR 0x39 261 | #define HID_USAGE_LED_SELECTED_INDICATOR 0x3A 262 | #define HID_USAGE_LED_IN_USE_INDICATOR 0x3B 263 | #define HID_USAGE_LED_MULTI_MODE_INDICATOR 0x3C 264 | #define HID_USAGE_LED_INDICATOR_ON 0x3D 265 | #define HID_USAGE_LED_INDICATOR_FLASH 0x3E 266 | #define HID_USAGE_LED_INDICATOR_SLOW_BLINK 0x3F 267 | #define HID_USAGE_LED_INDICATOR_FAST_BLINK 0x40 268 | #define HID_USAGE_LED_INDICATOR_OFF 0x41 269 | #define HID_USAGE_LED_FLASH_ON_TIME 0x42 270 | #define HID_USAGE_LED_SLOW_BLINK_ON_TIME 0x43 271 | #define HID_USAGE_LED_SLOW_BLINK_OFF_TIME 0x44 272 | #define HID_USAGE_LED_FAST_BLINK_ON_TIME 0x45 273 | #define HID_USAGE_LED_FAST_BLINK_OFF_TIME 0x46 274 | #define HID_USAGE_LED_INDICATOR_COLOR 0x47 275 | #define HID_USAGE_LED_RED 0x48 276 | #define HID_USAGE_LED_GREEN 0x49 277 | #define HID_USAGE_LED_AMBER 0x4A 278 | #define HID_USAGE_LED_GENERIC_INDICATOR 0x4B 279 | 280 | /* Button Page (0x09) */ 281 | /* There is no need to label these usages. */ 282 | 283 | /* Ordinal Page (0x0A) */ 284 | /* There is no need to label these usages. */ 285 | 286 | /* Telephony Device Page (0x0B) */ 287 | #define HID_USAGE_TELEPHONY_PHONE 0x01 288 | #define HID_USAGE_TELEPHONY_ANSWERING_MACHINE 0x02 289 | #define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS 0x03 290 | #define HID_USAGE_TELEPHONY_HANDSET 0x04 291 | #define HID_USAGE_TELEPHONY_HEADSET 0x05 292 | #define HID_USAGE_TELEPHONY_KEYPAD 0x06 293 | #define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON 0x07 294 | /* ... */ 295 | 296 | /* Consumer Page (0x0C) */ 297 | #define HID_USAGE_CONSUMER_CONTROL 0x01 298 | /* ... */ 299 | 300 | /* and others ... */ 301 | 302 | 303 | /* HID Report Item Macros */ 304 | 305 | /* Main Items */ 306 | #define HID_Input(x) 0x81,x 307 | #define HID_Output(x) 0x91,x 308 | #define HID_Feature(x) 0xB1,x 309 | #define HID_Collection(x) 0xA1,x 310 | #define HID_EndCollection 0xC0 311 | 312 | /* Data (Input, Output, Feature) */ 313 | #define HID_Data 0<<0 314 | #define HID_Constant 1<<0 315 | #define HID_Array 0<<1 316 | #define HID_Variable 1<<1 317 | #define HID_Absolute 0<<2 318 | #define HID_Relative 1<<2 319 | #define HID_NoWrap 0<<3 320 | #define HID_Wrap 1<<3 321 | #define HID_Linear 0<<4 322 | #define HID_NonLinear 1<<4 323 | #define HID_PreferredState 0<<5 324 | #define HID_NoPreferred 1<<5 325 | #define HID_NoNullPosition 0<<6 326 | #define HID_NullState 1<<6 327 | #define HID_NonVolatile 0<<7 328 | #define HID_Volatile 1<<7 329 | 330 | /* Collection Data */ 331 | #define HID_Physical 0x00 332 | #define HID_Application 0x01 333 | #define HID_Logical 0x02 334 | #define HID_Report 0x03 335 | #define HID_NamedArray 0x04 336 | #define HID_UsageSwitch 0x05 337 | #define HID_UsageModifier 0x06 338 | 339 | /* Global Items */ 340 | #define HID_UsagePage(x) 0x05,x 341 | #define HID_UsagePageVendor(x) 0x06,x,0xFF 342 | #define HID_LogicalMin(x) 0x15,x 343 | #define HID_LogicalMinS(x) 0x16,(x&0xFF),((x>>8)&0xFF) 344 | #define HID_LogicalMinL(x) 0x17,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) 345 | #define HID_LogicalMax(x) 0x25,x 346 | #define HID_LogicalMaxS(x) 0x26,(x&0xFF),((x>>8)&0xFF) 347 | #define HID_LogicalMaxL(x) 0x27,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) 348 | #define HID_PhysicalMin(x) 0x35,x 349 | #define HID_PhysicalMinS(x) 0x36,(x&0xFF),((x>>8)&0xFF) 350 | #define HID_PhysicalMinL(x) 0x37,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) 351 | #define HID_PhysicalMax(x) 0x45,x 352 | #define HID_PhysicalMaxS(x) 0x46,(x&0xFF),((x>>8)&0xFF) 353 | #define HID_PhysicalMaxL(x) 0x47,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) 354 | #define HID_UnitExponent(x) 0x55,x 355 | #define HID_Unit(x) 0x65,x 356 | #define HID_UnitS(x) 0x66,(x&0xFF),((x>>8)&0xFF) 357 | #define HID_UnitL(x) 0x67,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) 358 | #define HID_ReportSize(x) 0x75,x 359 | #define HID_ReportSizeS(x) 0x76,(x&0xFF),((x>>8)&0xFF) 360 | #define HID_ReportSizeL(x) 0x77,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) 361 | #define HID_ReportID(x) 0x85,x 362 | #define HID_ReportCount(x) 0x95,x 363 | #define HID_ReportCountS(x) 0x96,(x&0xFF),((x>>8)&0xFF) 364 | #define HID_ReportCountL(x) 0x97,(x&0xFF),((x>>8)&0xFF),((x>>16)&0xFF),((x>>24)&0xFF) 365 | #define HID_Push 0xA4 366 | #define HID_Pop 0xB4 367 | 368 | /* Local Items */ 369 | #define HID_Usage(x) 0x09,x 370 | #define HID_UsageMin(x) 0x19,x 371 | #define HID_UsageMax(x) 0x29,x 372 | 373 | 374 | #endif /* __USB_HID_H__ */ 375 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usb_lib.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USB_LIB_H__ 17 | #define __USB_LIB_H__ 18 | 19 | /*------------------------------------------------------------------------------ 20 | * USB Device Configuration 21 | *----------------------------------------------------------------------------*/ 22 | extern U8 USBD_AltSetting[]; 23 | extern U8 USBD_EP0Buf[]; 24 | extern const U8 usbd_power; 25 | extern const U8 usbd_hs_enable; 26 | extern const U16 usbd_if_num; 27 | extern const U8 usbd_ep_num; 28 | extern const U8 usbd_max_packet0; 29 | 30 | 31 | /*------------------------------------------------------------------------------ 32 | * USB Device Class Configuration 33 | *----------------------------------------------------------------------------*/ 34 | extern const U8 usbd_hid_enable; 35 | extern const U8 usbd_hid_if_num; 36 | extern const U8 usbd_hid_ep_intin; 37 | extern const U8 usbd_hid_ep_intout; 38 | extern const U16 usbd_hid_interval [2]; 39 | extern const U16 usbd_hid_maxpacketsize[2]; 40 | extern const U8 usbd_hid_inreport_num; 41 | extern const U8 usbd_hid_outreport_num; 42 | extern const U16 usbd_hid_inreport_max_sz; 43 | extern const U16 usbd_hid_outreport_max_sz; 44 | extern const U16 usbd_hid_featreport_max_sz; 45 | extern U16 USBD_HID_PollingCnt; 46 | extern U16 USBD_HID_PollingReload[]; 47 | extern U8 USBD_HID_IdleCnt []; 48 | extern U8 USBD_HID_IdleReload []; 49 | extern U8 USBD_HID_IdleSet []; 50 | extern U8 USBD_HID_InReport []; 51 | extern U8 USBD_HID_OutReport []; 52 | extern U8 USBD_HID_FeatReport []; 53 | 54 | extern const U8 usbd_msc_enable; 55 | extern const U8 usbd_msc_if_num; 56 | extern const U8 usbd_msc_ep_bulkin; 57 | extern const U8 usbd_msc_ep_bulkout; 58 | extern const U16 usbd_msc_maxpacketsize[2]; 59 | extern const U8 *usbd_msc_inquiry_data; 60 | extern U8 USBD_MSC_BulkBuf []; 61 | 62 | extern const U8 usbd_adc_enable; 63 | extern const U8 usbd_adc_cif_num; 64 | extern const U8 usbd_adc_sif1_num; 65 | extern const U8 usbd_adc_sif2_num; 66 | extern const U8 usbd_adc_ep_isoout; 67 | extern const U32 usbd_adc_cfg_datafreq; 68 | extern const U32 usbd_adc_cfg_p_s; 69 | extern const U32 usbd_adc_cfg_p_c; 70 | extern const U32 usbd_adc_cfg_b_s; 71 | extern S16 USBD_ADC_DataBuf []; 72 | 73 | extern const U8 usbd_cdc_acm_enable; 74 | extern const U8 usbd_cdc_acm_cif_num; 75 | extern const U8 usbd_cdc_acm_dif_num; 76 | extern const U8 usbd_cdc_acm_bufsize; 77 | extern const U8 usbd_cdc_acm_ep_intin; 78 | extern const U8 usbd_cdc_acm_ep_bulkin; 79 | extern const U8 usbd_cdc_acm_ep_bulkout; 80 | extern const U16 usbd_cdc_acm_sendbuf_sz; 81 | extern const U16 usbd_cdc_acm_receivebuf_sz; 82 | extern const U16 usbd_cdc_acm_maxpacketsize [2]; 83 | extern const U16 usbd_cdc_acm_maxpacketsize1[2]; 84 | extern U8 USBD_CDC_ACM_SendBuf []; 85 | extern U8 USBD_CDC_ACM_ReceiveBuf []; 86 | extern U8 USBD_CDC_ACM_NotifyBuf [10]; 87 | 88 | extern void usbd_os_evt_set (U16 event_flags, U32 task); 89 | extern U16 usbd_os_evt_get (void); 90 | extern U32 usbd_os_evt_wait_or (U16 wait_flags, U16 timeout); 91 | 92 | extern const BOOL __rtx; 93 | 94 | 95 | /*------------------------------------------------------------------------------ 96 | * USB Device Descriptors 97 | *----------------------------------------------------------------------------*/ 98 | extern const U8 USBD_HID_ReportDescriptor[]; 99 | extern const U16 USBD_HID_ReportDescriptorSize; 100 | extern const U16 USBD_HID_DescriptorOffset; 101 | extern const U8 USBD_DeviceDescriptor[]; 102 | extern const U8 USBD_DeviceQualifier[]; 103 | extern const U8 USBD_DeviceQualifier_HS[]; 104 | extern const U8 USBD_ConfigDescriptor[]; 105 | extern const U8 USBD_ConfigDescriptor_HS[]; 106 | extern const U8 USBD_OtherSpeedConfigDescriptor[]; 107 | extern const U8 USBD_OtherSpeedConfigDescriptor_HS[]; 108 | extern const U8 USBD_OtherSpeedConfigDescriptor[]; 109 | extern const U8 USBD_OtherSpeedConfigDescriptor_HS[]; 110 | extern const U8 USBD_StringDescriptor[]; 111 | 112 | #endif /* __USB_LIB_H__ */ 113 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usb_msc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USB_MSC_H__ 17 | #define __USB_MSC_H__ 18 | 19 | 20 | /* MSC Subclass Codes */ 21 | #define MSC_SUBCLASS_RBC 0x01 22 | #define MSC_SUBCLASS_SFF8020I_MMC2 0x02 23 | #define MSC_SUBCLASS_QIC157 0x03 24 | #define MSC_SUBCLASS_UFI 0x04 25 | #define MSC_SUBCLASS_SFF8070I 0x05 26 | #define MSC_SUBCLASS_SCSI 0x06 27 | 28 | /* MSC Protocol Codes */ 29 | #define MSC_PROTOCOL_CBI_INT 0x00 30 | #define MSC_PROTOCOL_CBI_NOINT 0x01 31 | #define MSC_PROTOCOL_BULK_ONLY 0x50 32 | 33 | 34 | /* MSC Request Codes */ 35 | #define MSC_REQUEST_RESET 0xFF 36 | #define MSC_REQUEST_GET_MAX_LUN 0xFE 37 | 38 | 39 | /* MSC Bulk-only Stage */ 40 | #define MSC_BS_CBW 0 /* Command Block Wrapper */ 41 | #define MSC_BS_DATA_OUT 1 /* Data Out Phase */ 42 | #define MSC_BS_DATA_IN 2 /* Data In Phase */ 43 | #define MSC_BS_DATA_IN_LAST 3 /* Data In Last Phase */ 44 | #define MSC_BS_DATA_IN_LAST_STALL 4 /* Data In Last Phase with Stall */ 45 | #define MSC_BS_CSW 5 /* Command Status Wrapper */ 46 | #define MSC_BS_ERROR 6 /* Error */ 47 | 48 | 49 | /* Bulk-only Command Block Wrapper */ 50 | typedef __packed struct _MSC_CBW { 51 | U32 dSignature; 52 | U32 dTag; 53 | U32 dDataLength; 54 | U8 bmFlags; 55 | U8 bLUN; 56 | U8 bCBLength; 57 | U8 CB[16]; 58 | } MSC_CBW; 59 | 60 | /* Bulk-only Command Status Wrapper */ 61 | typedef __packed struct _MSC_CSW { 62 | U32 dSignature; 63 | U32 dTag; 64 | U32 dDataResidue; 65 | U8 bStatus; 66 | } MSC_CSW; 67 | 68 | #define MSC_CBW_Signature 0x43425355 69 | #define MSC_CSW_Signature 0x53425355 70 | 71 | 72 | /* CSW Status Definitions */ 73 | #define CSW_CMD_PASSED 0x00 74 | #define CSW_CMD_FAILED 0x01 75 | #define CSW_PHASE_ERROR 0x02 76 | 77 | 78 | /* SCSI Commands */ 79 | #define SCSI_TEST_UNIT_READY 0x00 80 | #define SCSI_REQUEST_SENSE 0x03 81 | #define SCSI_FORMAT_UNIT 0x04 82 | #define SCSI_INQUIRY 0x12 83 | #define SCSI_MODE_SELECT6 0x15 84 | #define SCSI_MODE_SENSE6 0x1A 85 | #define SCSI_START_STOP_UNIT 0x1B 86 | #define SCSI_MEDIA_REMOVAL 0x1E 87 | #define SCSI_READ_FORMAT_CAPACITIES 0x23 88 | #define SCSI_READ_CAPACITY 0x25 89 | #define SCSI_READ10 0x28 90 | #define SCSI_WRITE10 0x2A 91 | #define SCSI_VERIFY10 0x2F 92 | #define SCSI_SYNC_CACHE10 0x35 93 | #define SCSI_READ12 0xA8 94 | #define SCSI_WRITE12 0xAA 95 | #define SCSI_MODE_SELECT10 0x55 96 | #define SCSI_MODE_SENSE10 0x5A 97 | #define SCSI_SYNC_CACHE16 0x91 98 | #define SCSI_ATA_COMMAND_PASS_THROUGH12 0xA1 99 | #define SCSI_ATA_COMMAND_PASS_THROUGH16 0x85 100 | #define SCSI_SERVICE_ACTION_IN12 0xAB 101 | #define SCSI_SERVICE_ACTION_IN16 0x9E 102 | #define SCSI_SERVICE_ACTION_OUT12 0xA9 103 | #define SCSI_SERVICE_ACTION_OUT16 0x9F 104 | 105 | 106 | #endif /* __USB_MSC_H__ */ 107 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_cdc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_CDC_H__ 17 | #define __USBD_CDC_H__ 18 | 19 | 20 | /*--------------------------- Event handling routines ------------------------*/ 21 | 22 | extern void usbd_vcom_serial2usb (void); 23 | extern void usbd_vcom_chkserstate (void); 24 | extern void usbd_vcom_usb2serial (void); 25 | extern void usbd_cdc_ser_flush (void); 26 | 27 | extern void USBD_CDC_SOF_Event (void); 28 | 29 | extern void USBD_CDC_EP_INTIN_Event (U32 event); 30 | extern void USBD_CDC_EP_BULKIN_Event (U32 event); 31 | extern void USBD_CDC_EP_BULKOUT_Event (U32 event); 32 | extern void USBD_CDC_EP_BULK_Event (U32 event); 33 | 34 | extern void USBD_RTX_CDC_EP_INTIN_Event (void); 35 | extern void USBD_RTX_CDC_EP_BULKIN_Event (void); 36 | extern void USBD_RTX_CDC_EP_BULKOUT_Event (void); 37 | extern void USBD_RTX_CDC_EP_BULK_Event (void); 38 | 39 | 40 | #endif /* __USBD_CDC_H__ */ 41 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_cdc_acm.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_CDC_ACM_H__ 17 | #define __USBD_CDC_ACM_H__ 18 | 19 | 20 | /*--------------------------- Event handling routines ------------------------*/ 21 | 22 | extern void USBD_CDC_ACM_Reset_Event (void); 23 | 24 | extern void USBD_CDC_ACM_SOF_Event (void); 25 | 26 | extern void USBD_CDC_ACM_EP_INTIN_Event (U32 event); 27 | extern void USBD_CDC_ACM_EP_BULKIN_Event (U32 event); 28 | extern void USBD_CDC_ACM_EP_BULKOUT_Event (U32 event); 29 | extern void USBD_CDC_ACM_EP_BULK_Event (U32 event); 30 | 31 | extern __task void USBD_RTX_CDC_ACM_EP_INTIN_Event (void); 32 | extern __task void USBD_RTX_CDC_ACM_EP_BULKIN_Event (void); 33 | extern __task void USBD_RTX_CDC_ACM_EP_BULKOUT_Event (void); 34 | extern __task void USBD_RTX_CDC_ACM_EP_BULK_Event (void); 35 | 36 | 37 | #endif /* __USBD_CDC_ACM_H__ */ 38 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_core.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_CORE_H__ 17 | #define __USBD_CORE_H__ 18 | 19 | 20 | /*--------------------------- Data structures --------------------------------*/ 21 | 22 | /* USB Device Core Endpoint Data Structure */ 23 | typedef struct _USBD_EP_DATA { 24 | U8 *pData; 25 | U16 Count; 26 | } USBD_EP_DATA; 27 | 28 | 29 | /*--------------------------- Global variables -------------------------------*/ 30 | 31 | /* USB Device Core Global Variables */ 32 | extern U16 USBD_DeviceStatus; 33 | extern U8 USBD_DeviceAddress; 34 | extern U8 USBD_Configuration; 35 | extern U32 USBD_EndPointMask; 36 | extern U32 USBD_EndPointHalt; 37 | extern U32 USBD_EndPointStall; 38 | extern U8 USBD_NumInterfaces; 39 | extern U8 USBD_HighSpeed; 40 | extern U8 USBD_ZLP; 41 | 42 | extern USBD_EP_DATA USBD_EP0Data; 43 | extern USB_SETUP_PACKET USBD_SetupPacket; 44 | 45 | extern OS_TID USBD_RTX_DevTask; 46 | extern OS_TID USBD_RTX_EPTask[]; 47 | extern OS_TID USBD_RTX_CoreTask; 48 | 49 | 50 | /*--------------------------- Functions exported to class specific files -----*/ 51 | 52 | extern void USBD_SetupStage (void); 53 | extern void USBD_DataInStage (void); 54 | extern void USBD_DataOutStage (void); 55 | extern void USBD_StatusInStage (void); 56 | extern void USBD_StatusOutStage (void); 57 | 58 | 59 | /*--------------------------- Event handling routines ------------------------*/ 60 | 61 | extern void usbd_class_init (void); 62 | 63 | extern void USBD_EndPoint0 (U32 event); 64 | 65 | extern __task void USBD_RTX_EndPoint0 (void); 66 | 67 | 68 | #endif /* __USBD_CORE_H__ */ 69 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_core_cdc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_CORE_CDC_H__ 17 | #define __USBD_CORE_CDC_H__ 18 | 19 | 20 | /*--------------------------- Core overridable class specific functions ------*/ 21 | 22 | extern BOOL USBD_EndPoint0_Setup_CDC_ReqToIF (void); 23 | extern BOOL USBD_EndPoint0_Out_CDC_ReqToIF (void); 24 | 25 | 26 | #endif /* __USBD_CORE_CDC_H__ */ 27 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_core_hid.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_CORE_HID_H__ 17 | #define __USBD_CORE_HID_H__ 18 | 19 | 20 | /*--------------------------- Core overridable class specific functions ------*/ 21 | 22 | extern BOOL USBD_ReqGetDescriptor_HID (U8 **pD, U32 *len); 23 | extern BOOL USBD_EndPoint0_Setup_HID_ReqToIF (void); 24 | extern BOOL USBD_EndPoint0_Out_HID_ReqToIF (void); 25 | 26 | 27 | #endif /* __USBD_CORE_HID_H__ */ 28 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_core_msc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_CORE_MSC_H__ 17 | #define __USBD_CORE_MSC_H__ 18 | 19 | 20 | /*--------------------------- Core overridable class specific functions ------*/ 21 | 22 | extern void USBD_ReqClrFeature_MSC (U32 EPNum); 23 | extern BOOL USBD_EndPoint0_Setup_MSC_ReqToIF (void); 24 | extern BOOL USBD_EndPoint0_Out_MSC_ReqToIF (void); 25 | 26 | 27 | #endif /* __USBD_CORE_MSC_H__ */ 28 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_DESC_H__ 17 | #define __USBD_DESC_H__ 18 | 19 | #define WBVAL(x) (x & 0xFF),((x >> 8) & 0xFF) 20 | #define B3VAL(x) (x & 0xFF),((x >> 8) & 0xFF),((x >> 16) & 0xFF) 21 | #define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR)) 22 | #define USB_DEVICE_QUALI_SIZE (sizeof(USB_DEVICE_QUALIFIER_DESCRIPTOR)) 23 | #define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR)) 24 | #define USB_INTERFACE_ASSOC_DESC_SIZE (sizeof(USB_INTERFACE_ASSOCIATION_DESCRIPTOR)) 25 | #define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR)) 26 | #define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR)) 27 | #define USB_HID_DESC_SIZE (sizeof(HID_DESCRIPTOR)) 28 | #define USB_HID_REPORT_DESC_SIZE (sizeof(USBD_HID_ReportDescriptor)) 29 | 30 | #endif /* __USBD_DESC_H__ */ 31 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_event.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_EVENT_H__ 17 | #define __USBD_EVENT_H__ 18 | 19 | 20 | /* USB Device - Device Events */ 21 | #define USBD_EVT_POWER_ON (1 << 0) /* USB Power On */ 22 | #define USBD_EVT_POWER_OFF (1 << 1) /* USB Power Off */ 23 | #define USBD_EVT_RESET (1 << 2) /* USB Bus Reset */ 24 | #define USBD_EVT_WAKEUP (1 << 3) /* USB Remote Wakeup */ 25 | #define USBD_EVT_SUSPEND (1 << 4) /* USB Suspend */ 26 | #define USBD_EVT_RESUME (1 << 5) /* USB Resume */ 27 | #define USBD_EVT_SOF (1 << 6) /* USB Start of Frame */ 28 | #define USBD_EVT_ERROR (1 << 7) /* USB Error */ 29 | 30 | /* USB Device - Endpoint Events */ 31 | #define USBD_EVT_SETUP (1 << 1) /* Setup Packet */ 32 | #define USBD_EVT_OUT (1 << 2) /* OUT Packet */ 33 | #define USBD_EVT_IN (1 << 3) /* IN Packet */ 34 | #define USBD_EVT_OUT_NAK (1 << 4) /* OUT Packet - Not Acknowledged */ 35 | #define USBD_EVT_IN_NAK (1 << 5) /* IN Packet - Not Acknowledged */ 36 | #define USBD_EVT_OUT_STALL (1 << 6) /* OUT Packet - Stalled */ 37 | #define USBD_EVT_IN_STALL (1 << 7) /* IN Packet - Stalled */ 38 | #define USBD_EVT_OUT_DMA_EOT (1 << 8) /* DMA OUT EP - End of Transfer */ 39 | #define USBD_EVT_IN_DMA_EOT (1 << 9) /* DMA IN EP - End of Transfer */ 40 | #define USBD_EVT_OUT_DMA_NDR (1 << 10) /* DMA OUT EP - New Descriptor Request*/ 41 | #define USBD_EVT_IN_DMA_NDR (1 << 11) /* DMA IN EP - New Descriptor Request*/ 42 | #define USBD_EVT_OUT_DMA_ERR (1 << 12) /* DMA OUT EP - Error */ 43 | #define USBD_EVT_IN_DMA_ERR (1 << 13) /* DMA IN EP - Error */ 44 | 45 | /* USB Device - Core Events */ 46 | #define USBD_EVT_SET_CFG (1 << 0) /* Set Configuration */ 47 | #define USBD_EVT_SET_IF (1 << 1) /* Set Interface */ 48 | #define USBD_EVT_SET_FEATURE (1 << 2) /* Set Feature */ 49 | #define USBD_EVT_CLR_FEATURE (1 << 3) /* Clear Feature */ 50 | 51 | /* USB Device - Device Events Callback Pointers */ 52 | extern void (* const USBD_P_Power_Event )(BOOL power); 53 | extern void (* const USBD_P_Reset_Event )(void); 54 | extern void (* const USBD_P_Suspend_Event )(void); 55 | extern void (* const USBD_P_Resume_Event )(void); 56 | extern void (* const USBD_P_WakeUp_Event )(void); 57 | extern void (* const USBD_P_SOF_Event )(void); 58 | extern void (* const USBD_P_Error_Event )(U32 error); 59 | 60 | /* USB Device - Endpoint Events Callback Pointers */ 61 | extern void (* const USBD_P_EP[16]) (U32 event); 62 | 63 | /* USB Device - Core Events Callback Pointers */ 64 | extern void (* const USBD_P_Configure_Event)(void); 65 | extern void (* const USBD_P_Interface_Event)(void); 66 | extern void (* const USBD_P_Feature_Event )(void); 67 | 68 | /* USB Device - RTX version RTX tasks initialization */ 69 | extern void USBD_RTX_TaskInit (void); 70 | 71 | #endif /* __USBD_EVENT_H__ */ 72 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_hid.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_HID_H__ 17 | #define __USBD_HID_H__ 18 | 19 | 20 | /*--------------------------- Global constants -------------------------------*/ 21 | 22 | /* USB HID Class API enumerated constants */ 23 | enum { 24 | USBD_HID_REQ_EP_CTRL = 0, /* Request from control endpoint */ 25 | USBD_HID_REQ_EP_INT, /* Request from interrupt endpoint */ 26 | USBD_HID_REQ_PERIOD_UPDATE /* Request from periodic update */ 27 | }; 28 | 29 | 30 | /*--------------------------- Event handling routines ------------------------*/ 31 | 32 | extern void USBD_HID_Configure_Event (void); 33 | extern void USBD_HID_SOF_Event (void); 34 | 35 | extern void USBD_HID_EP_INTIN_Event (U32 event); 36 | extern void USBD_HID_EP_INTOUT_Event (U32 event); 37 | extern void USBD_HID_EP_INT_Event (U32 event); 38 | 39 | extern __task void USBD_RTX_HID_EP_INTIN_Event (void); 40 | extern __task void USBD_RTX_HID_EP_INTOUT_Event(void); 41 | extern __task void USBD_RTX_HID_EP_INT_Event (void); 42 | 43 | 44 | #endif /* __USBD_HID_H__ */ 45 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_hw.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_HW_H__ 17 | #define __USBD_HW_H__ 18 | 19 | 20 | /* USB Hardware Functions */ 21 | extern void USBD_Init (void); 22 | extern void USBD_Connect (BOOL con); 23 | extern void USBD_Reset (void); 24 | extern void USBD_Suspend (void); 25 | extern void USBD_Resume (void); 26 | extern void USBD_WakeUp (void); 27 | extern void USBD_WakeUpCfg (BOOL cfg); 28 | extern void USBD_SetAddress (U32 adr, U32 setup); 29 | extern void USBD_Configure (BOOL cfg); 30 | extern void USBD_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD); 31 | extern void USBD_DirCtrlEP (U32 dir); 32 | extern void USBD_EnableEP (U32 EPNum); 33 | extern void USBD_DisableEP (U32 EPNum); 34 | extern void USBD_ResetEP (U32 EPNum); 35 | extern void USBD_SetStallEP (U32 EPNum); 36 | extern void USBD_ClrStallEP (U32 EPNum); 37 | extern void USBD_ClearEPBuf (U32 EPNum); 38 | extern U32 USBD_ReadEP (U32 EPNum, U8 *pData); 39 | extern U32 USBD_WriteEP (U32 EPNum, U8 *pData, U32 cnt); 40 | extern U32 USBD_GetFrame (void); 41 | extern U32 USBD_GetError (void); 42 | 43 | #endif /* __USBD_HW_H__ */ 44 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_lib_cdc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_LIB_CDC_H__ 17 | #define __USBD_LIB_CDC_H__ 18 | 19 | 20 | /*--------------------------- USB Requests -----------------------------------*/ 21 | 22 | extern int32_t USBD_CDC_ACM_SendEncapsulatedCommand (void); 23 | extern int32_t USBD_CDC_ACM_GetEncapsulatedResponse (void); 24 | extern int32_t USBD_CDC_ACM_SetCommFeature (uint16_t feat); 25 | extern int32_t USBD_CDC_ACM_GetCommFeature (uint16_t feat); 26 | extern int32_t USBD_CDC_ACM_ClearCommFeature (uint16_t feat); 27 | extern int32_t USBD_CDC_ACM_SetLineCoding (void); 28 | extern int32_t USBD_CDC_ACM_GetLineCoding (void); 29 | extern int32_t USBD_CDC_ACM_SetControlLineState (uint16_t ctrl_bmp); 30 | extern int32_t USBD_CDC_ACM_SendBreak (uint16_t dur); 31 | 32 | 33 | #endif /* __USBD_LIB_CDC_H__ */ 34 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_lib_hid.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_LIB_HID_H__ 17 | #define __USBD_LIB_HID_H__ 18 | 19 | 20 | /*--------------------------- USB Requests -----------------------------------*/ 21 | 22 | extern BOOL USBD_HID_GetReport (void); 23 | extern BOOL USBD_HID_SetReport (void); 24 | extern BOOL USBD_HID_GetIdle (void); 25 | extern BOOL USBD_HID_SetIdle (void); 26 | extern BOOL USBD_HID_GetProtocol (void); 27 | extern BOOL USBD_HID_SetProtocol (void); 28 | 29 | 30 | #endif /* __USBD_LIB_HID_H__ */ 31 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_lib_msc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_LIB_MSC_H__ 17 | #define __USBD_LIB_MSC_H__ 18 | 19 | 20 | /*--------------------------- USB Requests -----------------------------------*/ 21 | 22 | extern void USBD_MSC_ClrStallEP(U32 EPNum); 23 | extern BOOL USBD_MSC_Reset (void); 24 | extern BOOL USBD_MSC_GetMaxLUN (void); 25 | extern void USBD_MSC_GetCBW (void); 26 | extern void USBD_MSC_SetCSW (void); 27 | 28 | 29 | #endif /* __USBD_LIB_MSC_H__ */ 30 | -------------------------------------------------------------------------------- /shared/USBStack/INC/usbd_msc.h: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __USBD_MSC_H__ 17 | #define __USBD_MSC_H__ 18 | 19 | 20 | /*--------------------------- Global variables -------------------------------*/ 21 | 22 | /* USB Device Mass Storage Device Class Global Variables */ 23 | extern BOOL USBD_MSC_MediaReady; 24 | extern BOOL USBD_MSC_ReadOnly; 25 | extern U32 USBD_MSC_MemorySize; 26 | extern U32 USBD_MSC_BlockSize; 27 | extern U32 USBD_MSC_BlockGroup; 28 | extern U32 USBD_MSC_BlockCount; 29 | extern U8 *USBD_MSC_BlockBuf; 30 | 31 | 32 | /*--------------------------- Event handling routines ------------------------*/ 33 | 34 | extern void USBD_MSC_EP_BULKIN_Event (U32 event); 35 | extern void USBD_MSC_EP_BULKOUT_Event (U32 event); 36 | extern void USBD_MSC_EP_BULK_Event (U32 event); 37 | 38 | extern __task void USBD_RTX_MSC_EP_BULKIN_Event (void); 39 | extern __task void USBD_RTX_MSC_EP_BULKOUT_Event (void); 40 | extern __task void USBD_RTX_MSC_EP_BULK_Event (void); 41 | 42 | 43 | #endif /* __USBD_MSC_H__ */ 44 | -------------------------------------------------------------------------------- /shared/USBStack/SRC/usbd_core_cdc.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include "usb_for_lib.h" 20 | 21 | 22 | /* 23 | * USB Device Endpoint 0 Event Callback - CDC specific handling (Setup Request To Interface) 24 | * Parameters: none 25 | * Return Value: TRUE - Setup class request ok, FALSE - Setup class request not supported 26 | */ 27 | 28 | __weak BOOL USBD_EndPoint0_Setup_CDC_ReqToIF (void) { 29 | if ((USBD_SetupPacket.wIndexL == usbd_cdc_acm_cif_num) || /* IF number correct? */ 30 | (USBD_SetupPacket.wIndexL == usbd_cdc_acm_dif_num)) { 31 | switch (USBD_SetupPacket.bRequest) { 32 | case CDC_SEND_ENCAPSULATED_COMMAND: 33 | USBD_EP0Data.pData = USBD_EP0Buf; /* data to be received, see USBD_EVT_OUT */ 34 | return (__TRUE); 35 | case CDC_GET_ENCAPSULATED_RESPONSE: 36 | if (USBD_CDC_ACM_GetEncapsulatedResponse()) { 37 | USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */ 38 | USBD_DataInStage(); /* send requested data */ 39 | return (__TRUE); 40 | } 41 | break; 42 | case CDC_SET_COMM_FEATURE: 43 | USBD_EP0Data.pData = USBD_EP0Buf; /* data to be received, see USBD_EVT_OUT */ 44 | return (__TRUE); 45 | case CDC_GET_COMM_FEATURE: 46 | if (USBD_CDC_ACM_GetCommFeature(USBD_SetupPacket.wValue)) { 47 | USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */ 48 | USBD_DataInStage(); /* send requested data */ 49 | return (__TRUE); 50 | } 51 | break; 52 | case CDC_CLEAR_COMM_FEATURE: 53 | if (USBD_CDC_ACM_ClearCommFeature(USBD_SetupPacket.wValue)) { 54 | USBD_StatusInStage(); /* send Acknowledge */ 55 | return (__TRUE); 56 | } 57 | break; 58 | case CDC_SET_LINE_CODING: 59 | USBD_EP0Data.pData = USBD_EP0Buf; /* data to be received, see USBD_EVT_OUT */ 60 | return (__TRUE); 61 | case CDC_GET_LINE_CODING: 62 | if (USBD_CDC_ACM_GetLineCoding()) { 63 | USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */ 64 | USBD_DataInStage(); /* send requested data */ 65 | return (__TRUE); 66 | } 67 | break; 68 | case CDC_SET_CONTROL_LINE_STATE: 69 | if (USBD_CDC_ACM_SetControlLineState(USBD_SetupPacket.wValue)) { 70 | USBD_StatusInStage(); /* send Acknowledge */ 71 | return (__TRUE); 72 | } 73 | break; 74 | case CDC_SEND_BREAK: 75 | if (USBD_CDC_ACM_SendBreak(USBD_SetupPacket.wValue)) { 76 | USBD_StatusInStage(); /* send Acknowledge */ 77 | return (__TRUE); 78 | } 79 | break; 80 | } 81 | } 82 | return (__FALSE); 83 | } 84 | 85 | 86 | /* 87 | * USB Device Endpoint 0 Event Callback - CDC specific handling (Out Request To Interface) 88 | * Parameters: none 89 | * Return Value: TRUE - Out class request ok, FALSE - Out class request not supported 90 | */ 91 | 92 | __weak BOOL USBD_EndPoint0_Out_CDC_ReqToIF (void) { 93 | if ((USBD_SetupPacket.wIndexL == usbd_cdc_acm_cif_num) || /* IF number correct? */ 94 | (USBD_SetupPacket.wIndexL == usbd_cdc_acm_dif_num)) { 95 | switch (USBD_SetupPacket.bRequest) { 96 | case CDC_SEND_ENCAPSULATED_COMMAND: 97 | if (USBD_CDC_ACM_SendEncapsulatedCommand()) { 98 | USBD_StatusInStage(); /* send Acknowledge */ 99 | return (__TRUE); 100 | } 101 | break; 102 | case CDC_SET_COMM_FEATURE: 103 | if (USBD_CDC_ACM_SetCommFeature(USBD_SetupPacket.wValue)) { 104 | USBD_StatusInStage(); /* send Acknowledge */ 105 | return (__TRUE); 106 | } 107 | break; 108 | case CDC_SET_LINE_CODING: 109 | if (USBD_CDC_ACM_SetLineCoding()) { 110 | USBD_StatusInStage(); /* send Acknowledge */ 111 | return (__TRUE); 112 | } 113 | break; 114 | } 115 | } 116 | return (__FALSE); 117 | } 118 | -------------------------------------------------------------------------------- /shared/USBStack/SRC/usbd_core_hid.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include "usb_for_lib.h" 20 | 21 | 22 | /* 23 | * Get Descriptor USB Device Request - HID specific handling 24 | * Parameters: None 25 | * Return Value: TRUE - Success, FALSE - Error 26 | */ 27 | 28 | __weak BOOL USBD_ReqGetDescriptor_HID (U8 **pD, U32 *len) { 29 | switch (USBD_SetupPacket.wValueH) { 30 | case HID_HID_DESCRIPTOR_TYPE: 31 | if (USBD_SetupPacket.wIndexL != usbd_hid_if_num) { 32 | return (__FALSE); /* Only Single HID Interface is supported */ 33 | } 34 | if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) { 35 | return (__FALSE); /* High speed request but high-speed not enabled */ 36 | } 37 | if (USBD_HighSpeed == __FALSE) { 38 | *pD = (U8 *)USBD_ConfigDescriptor; 39 | } else { 40 | *pD = (U8 *)USBD_ConfigDescriptor_HS; 41 | } 42 | USBD_EP0Data.pData = *pD + USBD_HID_DescriptorOffset; 43 | *len = USB_HID_DESC_SIZE; 44 | break; 45 | case HID_REPORT_DESCRIPTOR_TYPE: 46 | if (USBD_SetupPacket.wIndexL != usbd_hid_if_num) { 47 | return (__FALSE); /* Only Single HID Interface is supported */ 48 | } 49 | USBD_EP0Data.pData = (U8 *)USBD_HID_ReportDescriptor; 50 | *len = USBD_HID_ReportDescriptorSize; 51 | break; 52 | case HID_PHYSICAL_DESCRIPTOR_TYPE: 53 | return (__FALSE); /* HID Physical Descriptor is not supported */ 54 | default: 55 | return (__FALSE); 56 | } 57 | return (__TRUE); 58 | } 59 | 60 | 61 | /* 62 | * USB Device Endpoint 0 Event Callback - HID specific handling (Setup Request To Interface) 63 | * Parameters: none 64 | * Return Value: TRUE - Setup class request ok, FALSE - Setup class request not supported 65 | */ 66 | 67 | __weak BOOL USBD_EndPoint0_Setup_HID_ReqToIF (void) { 68 | if (USBD_SetupPacket.wIndexL == usbd_hid_if_num) { /* IF number correct? */ 69 | switch (USBD_SetupPacket.bRequest) { 70 | case HID_REQUEST_GET_REPORT: 71 | if (USBD_HID_GetReport()) { 72 | if (USBD_SetupPacket.wValueH == HID_REPORT_INPUT) { 73 | USBD_EP0Data.pData = &USBD_HID_InReport[1]; /* point to data to be sent (skip ReportID) */ 74 | } 75 | else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) { 76 | USBD_EP0Data.pData = &USBD_HID_FeatReport[1]; /* point to data to be sent (skip ReportID) */ 77 | } 78 | USBD_DataInStage(); /* send requested data */ 79 | return (__TRUE); 80 | } 81 | break; 82 | case HID_REQUEST_SET_REPORT: 83 | if (USBD_SetupPacket.wValueH == HID_REPORT_OUTPUT) { 84 | USBD_EP0Data.pData = &USBD_HID_OutReport[1]; /* out data to be received (skip ReportID) */ 85 | } 86 | else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) { 87 | USBD_EP0Data.pData = &USBD_HID_FeatReport[1]; /* out data to be received (skip ReportID) */ 88 | } 89 | return (__TRUE); 90 | case HID_REQUEST_GET_IDLE: 91 | if (USBD_HID_GetIdle()) { 92 | USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */ 93 | USBD_DataInStage(); /* send requested data */ 94 | return (__TRUE); 95 | } 96 | break; 97 | case HID_REQUEST_SET_IDLE: 98 | if (USBD_HID_SetIdle()) { 99 | USBD_StatusInStage(); /* send Acknowledge */ 100 | return (__TRUE); 101 | } 102 | break; 103 | case HID_REQUEST_GET_PROTOCOL: 104 | if (USBD_HID_GetProtocol()) { 105 | USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */ 106 | USBD_DataInStage(); /* send requested data */ 107 | return (__TRUE); 108 | } 109 | break; 110 | case HID_REQUEST_SET_PROTOCOL: 111 | if (USBD_HID_SetProtocol()) { 112 | USBD_StatusInStage(); /* send Acknowledge */ 113 | return (__TRUE); 114 | } 115 | break; 116 | } 117 | } 118 | return (__FALSE); 119 | } 120 | 121 | 122 | /* 123 | * USB Device Endpoint 0 Event Callback - HID specific handling (Out Request To Interface) 124 | * Parameters: none 125 | * Return Value: TRUE - Out class request ok, FALSE - Out class request not supported 126 | */ 127 | 128 | __weak BOOL USBD_EndPoint0_Out_HID_ReqToIF (void) { 129 | if (USBD_SetupPacket.wIndexL == usbd_hid_if_num) { /* IF number correct? */ 130 | switch (USBD_SetupPacket.bRequest) { 131 | case HID_REQUEST_SET_REPORT: 132 | if (USBD_HID_SetReport()) { 133 | USBD_StatusInStage(); /* send Acknowledge */ 134 | return (__TRUE); 135 | } 136 | break; 137 | } 138 | } 139 | return (__FALSE); 140 | } 141 | -------------------------------------------------------------------------------- /shared/USBStack/SRC/usbd_core_msc.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include "usb_for_lib.h" 20 | 21 | 22 | /* 23 | * Clear Feature USB Device Request - MSC specific handling 24 | * Parameters: EPNum: Endpoint number 25 | * Return Value: None 26 | */ 27 | 28 | __weak void USBD_ReqClrFeature_MSC (U32 EPNum) { 29 | USBD_MSC_ClrStallEP (EPNum); 30 | } 31 | 32 | 33 | /* 34 | * USB Device Endpoint 0 Event Callback - MSC specific handling (Setup Request To Interface) 35 | * Parameters: none 36 | * Return Value: TRUE - Setup class request ok, FALSE - Setup class request not supported 37 | */ 38 | 39 | __weak BOOL USBD_EndPoint0_Setup_MSC_ReqToIF (void) { 40 | if (USBD_SetupPacket.wIndexL == usbd_msc_if_num) { /* IF number correct? */ 41 | switch (USBD_SetupPacket.bRequest) { 42 | case MSC_REQUEST_RESET: 43 | if ((USBD_SetupPacket.wValue == 0) && /* RESET with invalid parameters -> STALL */ 44 | (USBD_SetupPacket.wLength == 0)) { 45 | if (USBD_MSC_Reset()) { 46 | USBD_StatusInStage(); 47 | return (__TRUE); 48 | } 49 | } 50 | break; 51 | case MSC_REQUEST_GET_MAX_LUN: 52 | if ((USBD_SetupPacket.wValue == 0) && /* GET_MAX_LUN with invalid parameters -> STALL */ 53 | (USBD_SetupPacket.wLength == 1)) { 54 | if (USBD_MSC_GetMaxLUN()) { 55 | USBD_EP0Data.pData = USBD_EP0Buf; 56 | USBD_DataInStage(); 57 | return (__TRUE); 58 | } 59 | } 60 | break; 61 | } 62 | } 63 | return (__FALSE); 64 | } 65 | -------------------------------------------------------------------------------- /shared/USBStack/SRC/usbd_hid.c: -------------------------------------------------------------------------------- 1 | /* CMSIS-DAP Interface Firmware 2 | * Copyright (c) 2009-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include "usb_for_lib.h" 20 | 21 | 22 | U8 USBD_HID_Protocol; 23 | 24 | BOOL DataOutAsyncReq; 25 | U32 DataOutUpdateReqMask; 26 | U8 *ptrDataOut; 27 | volatile U16 DataOutToSendLen; 28 | U16 DataOutSentLen; 29 | BOOL DataOutEndWithShortPacket; 30 | 31 | U8 *ptrDataIn; 32 | U16 DataInReceLen; 33 | 34 | U8 *ptrDataFeat; 35 | U16 DataFeatReceLen; 36 | 37 | 38 | /* Dummy Weak Functions that need to be provided by user */ 39 | __weak void usbd_hid_init (void) {}; 40 | __weak int usbd_hid_get_report (U8 rtype, U8 rid, U8 *buf, U8 req) { return (0); }; 41 | __weak void usbd_hid_set_report (U8 rtype, U8 rid, U8 *buf, int len, U8 req) {}; 42 | __weak U8 usbd_hid_get_protocol (void) { return (0); }; 43 | __weak void usbd_hid_set_protocol (U8 protocol) {}; 44 | 45 | 46 | /* 47 | * USB Device HID Get Report Request Callback 48 | * Called automatically on USB Device HID Get Report Request 49 | * Parameters: None 50 | * Return Value: TRUE - Success, FALSE - Error 51 | */ 52 | 53 | BOOL USBD_HID_GetReport (void) { 54 | U8 *ptr_buf = 0; 55 | 56 | /* Report Type = USBD_SetupPacket.wValueH */ 57 | /* Report ID = USBD_SetupPacket.wValueL */ 58 | /* Report Length = USBD_SetupPacket.wLength */ 59 | switch (USBD_SetupPacket.wValueH) { 60 | case HID_REPORT_INPUT: 61 | ptr_buf = &USBD_HID_InReport[1]; 62 | break; 63 | case HID_REPORT_OUTPUT: 64 | return (__FALSE); /* Not Supported */ 65 | case HID_REPORT_FEATURE: 66 | ptr_buf = &USBD_HID_FeatReport[1]; 67 | break; 68 | } 69 | usbd_hid_get_report (USBD_SetupPacket.wValueH, USBD_SetupPacket.wValueL, ptr_buf, USBD_HID_REQ_EP_CTRL); 70 | return (__TRUE); 71 | } 72 | 73 | 74 | /* 75 | * USB Device HID Set Report Request Callback 76 | * Called automatically on USB Device HID Set Report Request 77 | * Parameters: None 78 | * Return Value: TRUE - Success, FALSE - Error 79 | */ 80 | 81 | BOOL USBD_HID_SetReport (void) { 82 | U8 *ptr_buf = 0; 83 | 84 | /* Report Type = USBD_SetupPacket.wValueH */ 85 | /* Report ID = USBD_SetupPacket.wValueL */ 86 | /* Report Length = USBD_SetupPacket.wLength */ 87 | switch (USBD_SetupPacket.wValueH) { 88 | case HID_REPORT_INPUT: 89 | return (__FALSE); /* Not Supported */ 90 | case HID_REPORT_OUTPUT: 91 | ptr_buf = &USBD_HID_OutReport[1]; 92 | break; 93 | case HID_REPORT_FEATURE: 94 | ptr_buf = &USBD_HID_FeatReport[1]; 95 | break; 96 | } 97 | usbd_hid_set_report (USBD_SetupPacket.wValueH, USBD_SetupPacket.wValueL, ptr_buf, USBD_SetupPacket.wLength, USBD_HID_REQ_EP_CTRL); 98 | return (__TRUE); 99 | } 100 | 101 | 102 | /* 103 | * USB Device HID Get Idle Request Callback 104 | * Called automatically on USB Device HID Get Idle Request 105 | * Parameters: None 106 | * Return Value: TRUE - Success, FALSE - Error 107 | */ 108 | 109 | BOOL USBD_HID_GetIdle (void) { 110 | 111 | USBD_EP0Buf[0] = USBD_HID_IdleSet[USBD_SetupPacket.wValueL]; 112 | return (__TRUE); 113 | } 114 | 115 | 116 | /* 117 | * USB Device HID Set Idle Request Callback 118 | * Called automatically on USB Device HID Set Idle Request 119 | * Parameters: None 120 | * Return Value: TRUE - Success, FALSE - Error 121 | */ 122 | 123 | BOOL USBD_HID_SetIdle (void) { 124 | U8 i; 125 | 126 | if (USBD_SetupPacket.wValueL) { /* If > 0 Report ID specified */ 127 | USBD_HID_IdleSet[USBD_SetupPacket.wValueL-1] = USBD_SetupPacket.wValueH; 128 | } else { /* If == 0 all reports */ 129 | for (i = 0; i < usbd_hid_inreport_num; i++) 130 | USBD_HID_IdleSet[i] = USBD_SetupPacket.wValueH; 131 | } 132 | return (__TRUE); 133 | } 134 | 135 | 136 | /* 137 | * USB Device HID Get Protocol Request Callback 138 | * Called automatically on USB Device HID Get Protocol Request 139 | * Parameters: None 140 | * Return Value: TRUE - Success, FALSE - Error 141 | */ 142 | 143 | BOOL USBD_HID_GetProtocol (void) { 144 | 145 | USBD_EP0Buf[0] = usbd_hid_get_protocol (); 146 | return (__TRUE); 147 | } 148 | 149 | 150 | /* 151 | * USB Device HID Set Protocol Request Callback 152 | * Called automatically on USB Device HID Set Protocol Request 153 | * Parameters: None 154 | * Return Value: TRUE - Success, FALSE - Error 155 | */ 156 | 157 | BOOL USBD_HID_SetProtocol (void) { 158 | 159 | usbd_hid_set_protocol (USBD_SetupPacket.wValueL); 160 | return (__TRUE); 161 | } 162 | 163 | 164 | /* 165 | * USB Device HID Interrupt In Endpoint Event Callback 166 | * Parameters: event: not used (just for compatibility) 167 | * Return Value: None 168 | */ 169 | 170 | void USBD_HID_EP_INTIN_Event (U32 event) { 171 | U8 i; 172 | U16 bytes_to_send; 173 | 174 | /* Check if sending is finished */ 175 | if ((DataOutSentLen >= DataOutToSendLen) && 176 | !DataOutEndWithShortPacket) { /* If all sent and short packet also */ 177 | ptrDataOut = NULL; 178 | DataOutSentLen = 0; 179 | DataOutToSendLen = usbd_hid_get_report (HID_REPORT_INPUT, USBD_HID_InReport[0], &USBD_HID_InReport[1], USBD_HID_REQ_EP_INT); 180 | if (DataOutToSendLen) { /* If new send should be started */ 181 | ptrDataOut = USBD_HID_InReport; 182 | if (usbd_hid_inreport_num <= 1) /* If only in 1 report skip ReportID */ 183 | ptrDataOut++; 184 | else /* If more in reports, send ReportID */ 185 | DataOutToSendLen++; 186 | } 187 | } 188 | /* Check if new data out sending should be started */ 189 | if(!DataOutToSendLen) { /* If send not in progress */ 190 | if (DataOutAsyncReq) { /* If asynchronous send requested */ 191 | DataOutAsyncReq = __FALSE; 192 | } 193 | else if (DataOutUpdateReqMask) { /* If update requested */ 194 | if (usbd_hid_inreport_num <= 1) { /* If only one in report in system */ 195 | if (DataOutUpdateReqMask) { 196 | USBD_HID_InReport[0] = 0; /* ReportID = 0 */ 197 | DataOutSentLen = 0; 198 | DataOutToSendLen = usbd_hid_get_report (HID_REPORT_INPUT, 0, &USBD_HID_InReport[1], USBD_HID_REQ_PERIOD_UPDATE); 199 | if (DataOutToSendLen) { 200 | ptrDataOut = &USBD_HID_InReport[1]; 201 | } 202 | DataOutUpdateReqMask = 0; 203 | } 204 | } else { /* If multiple reports in system */ 205 | for (i = USBD_HID_InReport[0]; ; i++) { 206 | if (i >= 32) i = 0; 207 | if (DataOutUpdateReqMask & (1 << i)) { 208 | USBD_HID_InReport[0]= i+1; /* ReportID */ 209 | DataOutSentLen = 0; 210 | DataOutToSendLen = usbd_hid_get_report (HID_REPORT_INPUT, i+1, &USBD_HID_InReport[1], USBD_HID_REQ_PERIOD_UPDATE); 211 | if (DataOutToSendLen) { 212 | ptrDataOut = USBD_HID_InReport; 213 | DataOutToSendLen++; 214 | } 215 | DataOutUpdateReqMask &= ~(1 << i); 216 | break; 217 | } 218 | } 219 | } 220 | } 221 | } 222 | /* Check if data needs to be sent */ 223 | if (DataOutToSendLen || 224 | DataOutEndWithShortPacket) { /* If sending is in progress */ 225 | bytes_to_send = DataOutToSendLen - DataOutSentLen; 226 | if (bytes_to_send > usbd_hid_maxpacketsize[USBD_HighSpeed]) 227 | bytes_to_send = usbd_hid_maxpacketsize[USBD_HighSpeed]; 228 | USBD_WriteEP(usbd_hid_ep_intin | 0x80, ptrDataOut, bytes_to_send); 229 | ptrDataOut += bytes_to_send; 230 | DataOutSentLen += bytes_to_send; 231 | if ((DataOutSentLen < usbd_hid_inreport_max_sz) && 232 | (bytes_to_send == usbd_hid_maxpacketsize[USBD_HighSpeed])) { 233 | /* If short packet should be sent also*/ 234 | DataOutEndWithShortPacket = __TRUE; 235 | } else { 236 | DataOutEndWithShortPacket = __FALSE; 237 | } 238 | } 239 | } 240 | 241 | 242 | /* 243 | * USB Device HID Interrupt Out Endpoint Event Callback 244 | * Parameters: event: not used (just for compatibility) 245 | * Return Value: None 246 | */ 247 | 248 | void USBD_HID_EP_INTOUT_Event (U32 event) { 249 | U16 bytes_rece; 250 | 251 | if (!DataInReceLen) { /* Check if new reception */ 252 | ptrDataIn = USBD_HID_OutReport; 253 | DataInReceLen = 0; 254 | } 255 | bytes_rece = USBD_ReadEP(usbd_hid_ep_intout, ptrDataIn); 256 | ptrDataIn += bytes_rece; 257 | DataInReceLen += bytes_rece; 258 | if (!bytes_rece || 259 | (DataInReceLen >= usbd_hid_outreport_max_sz) || 260 | (bytes_rece < usbd_hid_maxpacketsize[USBD_HighSpeed])) { 261 | if (usbd_hid_outreport_num <= 1) { /* If only one out report in system */ 262 | usbd_hid_set_report (HID_REPORT_OUTPUT, 0 , USBD_HID_OutReport , DataInReceLen, USBD_HID_REQ_EP_INT); 263 | } else { 264 | usbd_hid_set_report (HID_REPORT_OUTPUT, USBD_HID_OutReport[0], &USBD_HID_OutReport[1], DataInReceLen-1, USBD_HID_REQ_EP_INT); 265 | } 266 | DataInReceLen = 0; 267 | } 268 | } 269 | 270 | 271 | /* 272 | * USB Device HID Configure Callback 273 | * Parameters: None 274 | * Return Value: None 275 | */ 276 | 277 | void USBD_HID_Configure_Event (void) { 278 | 279 | /* Reset all variables after connect event */ 280 | USBD_HID_Protocol = 0; 281 | 282 | DataOutAsyncReq = __FALSE; 283 | DataOutUpdateReqMask = __FALSE; 284 | ptrDataOut = NULL; 285 | DataOutToSendLen = 0; 286 | DataOutSentLen = 0; 287 | DataOutEndWithShortPacket = __FALSE; 288 | 289 | ptrDataIn = NULL; 290 | DataInReceLen = 0; 291 | 292 | ptrDataFeat = NULL; 293 | DataFeatReceLen = 0; 294 | } 295 | 296 | 297 | /* 298 | * USB Device HID Interrupt In/Out Endpoint Event Callback 299 | * Parameters: event: USB Device Event 300 | * USBD_EVT_IN: Input Event 301 | * USBD_EVT_OUT: Output Event 302 | * Return Value: None 303 | */ 304 | 305 | void USBD_HID_EP_INT_Event (U32 event) { 306 | if (event & USBD_EVT_IN) { 307 | USBD_HID_EP_INTIN_Event (event); 308 | } 309 | if (event & USBD_EVT_OUT) { 310 | USBD_HID_EP_INTOUT_Event (event); 311 | } 312 | } 313 | 314 | 315 | /* 316 | * USB Device HID SOF Handler (handles report timings: polling and idle times) 317 | * Called automatically on USB Device Start of Frame 318 | * Parameters: None 319 | * Return Value: None 320 | */ 321 | 322 | void USBD_HID_SOF_Event (void) { 323 | static U8 cnt_for_4ms = 0; 324 | U8 i; 325 | BOOL tick_4ms, do_polling, polling_reload, idle_reload; 326 | 327 | if (USBD_Configuration) { 328 | tick_4ms = __FALSE; 329 | if (cnt_for_4ms++ >= ((4 << (3 * USBD_HighSpeed))) - 1) { 330 | cnt_for_4ms = 0; 331 | tick_4ms = __TRUE; 332 | } 333 | 334 | polling_reload = __FALSE; 335 | if (USBD_HID_PollingCnt < 255) USBD_HID_PollingCnt++; 336 | if (USBD_HID_PollingCnt == usbd_hid_interval[USBD_HighSpeed]) { 337 | polling_reload = __TRUE; /* If polling interval expired */ 338 | } 339 | for (i = 0; i < usbd_hid_inreport_num; i++) { 340 | idle_reload = __FALSE; 341 | if (tick_4ms) { 342 | if (USBD_HID_IdleCnt[i] < 255) USBD_HID_IdleCnt[i]++; 343 | if (USBD_HID_IdleReload[i]) { 344 | if (USBD_HID_IdleCnt[i] >= USBD_HID_IdleReload[i]) { 345 | idle_reload = __TRUE; /* If idle period expired */ 346 | } 347 | } 348 | } 349 | do_polling = (usbd_hid_interval[USBD_HighSpeed] > ((U16)(USBD_HID_IdleReload[i]) << (2 << (3 * USBD_HighSpeed)))) && (USBD_HID_IdleReload[i] != 0); 350 | if (polling_reload) { 351 | if (do_polling) { 352 | /* If polling is longer than idle */ 353 | DataOutUpdateReqMask |= (1 << i); 354 | } 355 | } 356 | if (USBD_HID_IdleReload[i] != USBD_HID_IdleSet[i]) { 357 | if (USBD_HID_IdleCnt[i] >= USBD_HID_IdleSet[i]) { 358 | DataOutUpdateReqMask |= (1 << i); 359 | cnt_for_4ms = 0; 360 | } 361 | USBD_HID_IdleReload[i] = USBD_HID_IdleSet[i]; 362 | } 363 | if (idle_reload) { 364 | if (!do_polling) { 365 | DataOutUpdateReqMask |= (1 << i); 366 | } 367 | USBD_HID_IdleCnt[i] = 0; 368 | } 369 | } 370 | if (polling_reload) { 371 | USBD_HID_PollingCnt = 0; 372 | } 373 | 374 | if (DataOutUpdateReqMask && !DataOutToSendLen) { /* If pending */ 375 | /* refresh request and no active data */ 376 | /* out then start data out */ 377 | USBD_HID_EP_INTIN_Event (0); 378 | } 379 | } 380 | } 381 | 382 | 383 | #ifdef __RTX /* RTX task for handling events */ 384 | 385 | /* 386 | * USB Device HID Interrupt In Endpoint Event Handler Task 387 | * Parameters: None 388 | * Return Value: None 389 | */ 390 | 391 | __task void USBD_RTX_HID_EP_INTIN_Event (void) { 392 | 393 | if (__rtx) { 394 | for (;;) { 395 | usbd_os_evt_wait_or (0xFFFF, 0xFFFF); 396 | if (usbd_os_evt_get() & USBD_EVT_IN) { 397 | USBD_HID_EP_INTIN_Event (0); 398 | } 399 | } 400 | } 401 | } 402 | 403 | 404 | /* 405 | * USB Device HID Interrupt Out Endpoint Event Handler Task 406 | * Parameters: None 407 | * Return Value: None 408 | */ 409 | 410 | __task void USBD_RTX_HID_EP_INTOUT_Event (void) { 411 | 412 | if (__rtx) { 413 | for (;;) { 414 | usbd_os_evt_wait_or (0xFFFF, 0xFFFF); 415 | if (usbd_os_evt_get() & USBD_EVT_OUT) { 416 | USBD_HID_EP_INTOUT_Event (0); 417 | } 418 | } 419 | } 420 | } 421 | 422 | 423 | /* 424 | * USB Device HID Interrupt In/Out Endpoint Event Handler Task 425 | * Parameters: None 426 | * Return Value: None 427 | */ 428 | 429 | __task void USBD_RTX_HID_EP_INT_Event (void) { 430 | 431 | if (__rtx) { 432 | for (;;) { 433 | usbd_os_evt_wait_or (0xFFFF, 0xFFFF); 434 | USBD_HID_EP_INT_Event (usbd_os_evt_get()); 435 | } 436 | } 437 | } 438 | #endif 439 | 440 | 441 | /* 442 | * USB Device HID Get Report Trigger (asynchronous Get_Report request) 443 | * Parameters: rid: Report ID 444 | * buf: Pointer to data buffer 445 | * len: Number of bytes to be sent 446 | * Return Value: TRUE - Success, FALSE - Error 447 | */ 448 | 449 | BOOL usbd_hid_get_report_trigger (U8 rid, U8 *buf, int len) { 450 | 451 | if (len > usbd_hid_inreport_max_sz) 452 | return (__FALSE); 453 | 454 | if (USBD_Configuration) { 455 | DataOutAsyncReq = __TRUE; /* Asynchronous data out request */ 456 | while (DataOutToSendLen) { 457 | if (!USBD_Configuration) { /* If device not configured reject rq */ 458 | DataOutAsyncReq = __FALSE; /* Asynchronous data out request */ 459 | ptrDataOut = NULL; 460 | DataOutSentLen = 0; 461 | DataOutToSendLen = 0; 462 | return (__FALSE); 463 | } 464 | } 465 | USBD_HID_InReport[0] = rid; 466 | memcpy (&USBD_HID_InReport[1], buf, len); 467 | ptrDataOut = USBD_HID_InReport; 468 | DataOutSentLen = 0; 469 | DataOutToSendLen = len; 470 | if (usbd_hid_inreport_num <= 1) /* If only 1 in report skip ReportID */ 471 | ptrDataOut ++; 472 | else /* If more in reports, send ReportID */ 473 | DataOutToSendLen ++; 474 | USBD_HID_EP_INTIN_Event (0); 475 | USBD_HID_IdleCnt[rid] = 0; 476 | return (__TRUE); 477 | } 478 | 479 | return (__FALSE); 480 | } 481 | -------------------------------------------------------------------------------- /shared/cmsis/TARGET_Freescale/TARGET_MK20DX/TOOLCHAIN_ARM_STD/MK20D5.sct: -------------------------------------------------------------------------------- 1 | LR_IROM1 0x00000000 0x00020000 { ; load region size_region 2 | 3 | ER_IROM1 0x00000000 0x00020000 { ; load address = execution address 4 | *.o (RESET, +First) 5 | *(InRoot$$Sections) 6 | .ANY (+RO) 7 | } 8 | 9 | RW_IRAM1 0x1FFFE000 0x00002000 { ; RW data 10 | .ANY (+RW +ZI) 11 | } 12 | 13 | RW_IRAM2 0x20000000 0x00002000 { 14 | .ANY (+RW +ZI) 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /shared/cmsis/TARGET_Freescale/TARGET_MK20DX/system_MK20D5.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** ################################################################### 3 | ** Compilers: ARM Compiler 4 | ** Freescale C/C++ for Embedded ARM 5 | ** GNU C Compiler 6 | ** IAR ANSI C/C++ Compiler for ARM 7 | ** 8 | ** Reference manuals: K20P64M50SF0RM Rev. 1, Oct 2011 9 | ** K20P32M50SF0RM Rev. 1, Oct 2011 10 | ** K20P48M50SF0RM Rev. 1, Oct 2011 11 | ** 12 | ** Version: rev. 1.0, 2011-12-15 13 | ** 14 | ** Abstract: 15 | ** Provides a system configuration function and a global variable that 16 | ** contains the system frequency. It configures the device and initializes 17 | ** the oscillator (PLL) that is part of the microcontroller device. 18 | ** 19 | ** Copyright: 2011 Freescale Semiconductor, Inc. All Rights Reserved. 20 | ** 21 | ** http: www.freescale.com 22 | ** mail: support@freescale.com 23 | ** 24 | ** Revisions: 25 | ** - rev. 1.0 (2011-12-15) 26 | ** Initial version 27 | ** 28 | ** ################################################################### 29 | */ 30 | 31 | /** 32 | * @file MK20D5 33 | * @version 1.0 34 | * @date 2011-12-15 35 | * @brief Device specific configuration file for MK20D5 (implementation file) 36 | * 37 | * Provides a system configuration function and a global variable that contains 38 | * the system frequency. It configures the device and initializes the oscillator 39 | * (PLL) that is part of the microcontroller device. 40 | */ 41 | 42 | #include 43 | #include "MK20D5.h" 44 | 45 | #define DISABLE_WDOG 1 46 | 47 | #define CLOCK_SETUP 1 48 | /* Predefined clock setups 49 | 0 ... Multipurpose Clock Generator (MCG) in FLL Engaged Internal (FEI) mode 50 | Reference clock source for MCG module is the slow internal clock source 32.768kHz 51 | Core clock = 41.94MHz, BusClock = 41.94MHz 52 | 1 ... Multipurpose Clock Generator (MCG) in PLL Engaged External (PEE) mode 53 | Reference clock source for MCG module is an external crystal 8MHz 54 | Core clock = 48MHz, BusClock = 48MHz 55 | 2 ... Multipurpose Clock Generator (MCG) in Bypassed Low Power External (BLPE) mode 56 | Core clock/Bus clock derived directly from an external crystal 8MHz with no multiplication 57 | Core clock = 8MHz, BusClock = 8MHz 58 | */ 59 | 60 | /*---------------------------------------------------------------------------- 61 | Define clock source values 62 | *----------------------------------------------------------------------------*/ 63 | #if (CLOCK_SETUP == 0) 64 | #define CPU_XTAL_CLK_HZ 8000000u /* Value of the external crystal or oscillator clock frequency in Hz */ 65 | #define CPU_XTAL32k_CLK_HZ 32768u /* Value of the external 32k crystal or oscillator clock frequency in Hz */ 66 | #define CPU_INT_SLOW_CLK_HZ 32768u /* Value of the slow internal oscillator clock frequency in Hz */ 67 | #define CPU_INT_FAST_CLK_HZ 4000000u /* Value of the fast internal oscillator clock frequency in Hz */ 68 | #define DEFAULT_SYSTEM_CLOCK 41943040u /* Default System clock value */ 69 | #elif (CLOCK_SETUP == 1) 70 | #define CPU_XTAL_CLK_HZ 8000000u /* Value of the external crystal or oscillator clock frequency in Hz */ 71 | #define CPU_XTAL32k_CLK_HZ 32768u /* Value of the external 32k crystal or oscillator clock frequency in Hz */ 72 | #define CPU_INT_SLOW_CLK_HZ 32768u /* Value of the slow internal oscillator clock frequency in Hz */ 73 | #define CPU_INT_FAST_CLK_HZ 4000000u /* Value of the fast internal oscillator clock frequency in Hz */ 74 | #define DEFAULT_SYSTEM_CLOCK 48000000u /* Default System clock value */ 75 | #elif (CLOCK_SETUP == 2) 76 | #define CPU_XTAL_CLK_HZ 8000000u /* Value of the external crystal or oscillator clock frequency in Hz */ 77 | #define CPU_XTAL32k_CLK_HZ 32768u /* Value of the external 32k crystal or oscillator clock frequency in Hz */ 78 | #define CPU_INT_SLOW_CLK_HZ 32768u /* Value of the slow internal oscillator clock frequency in Hz */ 79 | #define CPU_INT_FAST_CLK_HZ 4000000u /* Value of the fast internal oscillator clock frequency in Hz */ 80 | #define DEFAULT_SYSTEM_CLOCK 8000000u /* Default System clock value */ 81 | #endif /* (CLOCK_SETUP == 2) */ 82 | 83 | 84 | /* ---------------------------------------------------------------------------- 85 | -- Core clock 86 | ---------------------------------------------------------------------------- */ 87 | 88 | uint32_t SystemCoreClock = DEFAULT_SYSTEM_CLOCK; 89 | 90 | /* ---------------------------------------------------------------------------- 91 | -- SystemInit() 92 | ---------------------------------------------------------------------------- */ 93 | 94 | void SystemInit (void) { 95 | #if (DISABLE_WDOG) 96 | /* Disable the WDOG module */ 97 | /* WDOG_UNLOCK: WDOGUNLOCK=0xC520 */ 98 | WDOG->UNLOCK = (uint16_t)0xC520u; /* Key 1 */ 99 | /* WDOG_UNLOCK : WDOGUNLOCK=0xD928 */ 100 | WDOG->UNLOCK = (uint16_t)0xD928u; /* Key 2 */ 101 | /* WDOG_STCTRLH: ??=0,DISTESTWDOG=0,BYTESEL=0,TESTSEL=0,TESTWDOG=0,??=0,STNDBYEN=1,WAITEN=1,STOPEN=1,DBGEN=0,ALLOWUPDATE=1,WINEN=0,IRQRSTEN=0,CLKSRC=1,WDOGEN=0 */ 102 | WDOG->STCTRLH = (uint16_t)0x01D2u; 103 | #endif /* (DISABLE_WDOG) */ 104 | #if (CLOCK_SETUP == 0) 105 | /* SIM->CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=1,OUTDIV4=1,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */ 106 | SIM->CLKDIV1 = (uint32_t)0x00110000u; /* Update system prescalers */ 107 | /* Switch to FEI Mode */ 108 | /* MCG->C1: CLKS=0,FRDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */ 109 | MCG->C1 = (uint8_t)0x06u; 110 | /* MCG->C2: ??=0,??=0,RANGE0=0,HGO=0,EREFS=0,LP=0,IRCS=0 */ 111 | MCG->C2 = (uint8_t)0x00u; 112 | /* MCG_C4: DMX32=0,DRST_DRS=1 */ 113 | MCG->C4 = (uint8_t)((MCG->C4 & (uint8_t)~(uint8_t)0xC0u) | (uint8_t)0x20u); 114 | /* MCG->C5: ??=0,PLLCLKEN=0,PLLSTEN=0,PRDIV0=0 */ 115 | MCG->C5 = (uint8_t)0x00u; 116 | /* MCG->C6: LOLIE=0,PLLS=0,CME=0,VDIV0=0 */ 117 | MCG->C6 = (uint8_t)0x00u; 118 | while((MCG->S & MCG_S_IREFST_MASK) == 0u) { /* Check that the source of the FLL reference clock is the internal reference clock. */ 119 | } 120 | while((MCG->S & 0x0Cu) != 0x00u) { /* Wait until output of the FLL is selected */ 121 | } 122 | #elif (CLOCK_SETUP == 1) 123 | /* SIM->CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=1,OUTDIV4=1,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */ 124 | SIM->CLKDIV1 = (uint32_t)0x00110000u; /* Update system prescalers */ 125 | /* Switch to FBE Mode */ 126 | /* OSC0->CR: ERCLKEN=0,??=0,EREFSTEN=0,??=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */ 127 | OSC0->CR = (uint8_t)0x00u; 128 | /* MCG->C7: OSCSEL=0 */ 129 | MCG->C7 = (uint8_t)0x00u; 130 | /* MCG->C2: ??=0,??=0,RANGE0=2,HGO=0,EREFS=1,LP=0,IRCS=0 */ 131 | MCG->C2 = (uint8_t)0x24u; 132 | /* MCG->C1: CLKS=2,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */ 133 | MCG->C1 = (uint8_t)0x9Au; 134 | /* MCG->C4: DMX32=0,DRST_DRS=0 */ 135 | MCG->C4 &= (uint8_t)~(uint8_t)0xE0u; 136 | /* MCG->C5: ??=0,PLLCLKEN=0,PLLSTEN=0,PRDIV0=3 */ 137 | MCG->C5 = (uint8_t)0x03u; 138 | /* MCG->C6: LOLIE=0,PLLS=0,CME=0,VDIV0=0 */ 139 | MCG->C6 = (uint8_t)0x00u; 140 | while((MCG->S & MCG_S_OSCINIT0_MASK) == 0u) { /* Check that the oscillator is running */ 141 | } 142 | #if 0 /* ARM: THIS CHECK IS REMOVED DUE TO BUG WITH SLOW IRC IN REV. 1.0 */ 143 | while((MCG->S & MCG_S_IREFST_MASK) != 0u) { /* Check that the source of the FLL reference clock is the external reference clock. */ 144 | } 145 | #endif 146 | while((MCG->S & 0x0Cu) != 0x08u) { /* Wait until external reference clock is selected as MCG output */ 147 | } 148 | /* Switch to PBE Mode */ 149 | /* MCG_C5: ??=0,PLLCLKEN=0,PLLSTEN=0,PRDIV0=3 */ 150 | MCG->C5 = (uint8_t)0x03u; 151 | /* MCG->C6: LOLIE=0,PLLS=1,CME=0,VDIV0=0 */ 152 | MCG->C6 = (uint8_t)0x40u; 153 | while((MCG->S & MCG_S_PLLST_MASK) == 0u) { /* Wait until the source of the PLLS clock has switched to the PLL */ 154 | } 155 | while((MCG->S & MCG_S_LOCK0_MASK) == 0u) { /* Wait until locked */ 156 | } 157 | /* Switch to PEE Mode */ 158 | /* MCG->C1: CLKS=0,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */ 159 | MCG->C1 = (uint8_t)0x1Au; 160 | while((MCG->S & 0x0Cu) != 0x0Cu) { /* Wait until output of the PLL is selected */ 161 | } 162 | while((MCG->S & MCG_S_LOCK0_MASK) == 0u) { /* Wait until locked */ 163 | } 164 | #elif (CLOCK_SETUP == 2) 165 | /* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=1,OUTDIV4=1,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */ 166 | SIM->CLKDIV1 = (uint32_t)0x00110000u; /* Update system prescalers */ 167 | /* Switch to FBE Mode */ 168 | /* OSC0->CR: ERCLKEN=0,??=0,EREFSTEN=0,??=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */ 169 | OSC0->CR = (uint8_t)0x00u; 170 | /* MCG->C7: OSCSEL=0 */ 171 | MCG->C7 = (uint8_t)0x00u; 172 | /* MCG->C2: ??=0,??=0,RANGE0=2,HGO=0,EREFS=1,LP=0,IRCS=0 */ 173 | MCG->C2 = (uint8_t)0x24u; 174 | /* MCG->C1: CLKS=2,FRDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */ 175 | MCG->C1 = (uint8_t)0x9Au; 176 | /* MCG->C4: DMX32=0,DRST_DRS=0 */ 177 | MCG->C4 &= (uint8_t)~(uint8_t)0xE0u; 178 | /* MCG->C5: ??=0,PLLCLKEN=0,PLLSTEN=0,PRDIV0=0 */ 179 | MCG->C5 = (uint8_t)0x00u; 180 | /* MCG->C6: LOLIE=0,PLLS=0,CME=0,VDIV0=0 */ 181 | MCG->C6 = (uint8_t)0x00u; 182 | while((MCG->S & MCG_S_OSCINIT0_MASK) == 0u) { /* Check that the oscillator is running */ 183 | } 184 | #if 0 /* ARM: THIS CHECK IS REMOVED DUE TO BUG WITH SLOW IRC IN REV. 1.0 */ 185 | while((MCG->S & MCG_S_IREFST_MASK) != 0u) { /* Check that the source of the FLL reference clock is the external reference clock. */ 186 | } 187 | #endif 188 | while((MCG->S & 0x0CU) != 0x08u) { /* Wait until external reference clock is selected as MCG output */ 189 | } 190 | /* Switch to BLPE Mode */ 191 | /* MCG->C2: ??=0,??=0,RANGE0=2,HGO=0,EREFS=1,LP=0,IRCS=0 */ 192 | MCG->C2 = (uint8_t)0x24u; 193 | #endif /* (CLOCK_SETUP == 2) */ 194 | 195 | #if defined(OFFSET_VTABLE_32K) 196 | SCB->VTOR = 0x8000u; 197 | #elif defined(OFFSET_VTABLE_20K) 198 | SCB->VTOR = 0x5000u; 199 | #endif 200 | } 201 | 202 | /* ---------------------------------------------------------------------------- 203 | -- SystemCoreClockUpdate() 204 | ---------------------------------------------------------------------------- */ 205 | 206 | void SystemCoreClockUpdate (void) { 207 | uint32_t MCGOUTClock; /* Variable to store output clock frequency of the MCG module */ 208 | uint8_t Divider; 209 | 210 | if ((MCG->C1 & MCG_C1_CLKS_MASK) == 0x0u) { 211 | /* Output of FLL or PLL is selected */ 212 | if ((MCG->C6 & MCG_C6_PLLS_MASK) == 0x0u) { 213 | /* FLL is selected */ 214 | if ((MCG->C1 & MCG_C1_IREFS_MASK) == 0x0u) { 215 | /* External reference clock is selected */ 216 | if ((MCG->C7 & MCG_C7_OSCSEL_MASK) == 0x0u) { 217 | MCGOUTClock = CPU_XTAL_CLK_HZ; /* System oscillator drives MCG clock */ 218 | } else { /* (!((MCG->C7 & MCG_C7_OSCSEL_MASK) == 0x0u)) */ 219 | MCGOUTClock = CPU_XTAL32k_CLK_HZ; /* RTC 32 kHz oscillator drives MCG clock */ 220 | } /* (!((MCG->C7 & MCG_C7_OSCSEL_MASK) == 0x0u)) */ 221 | Divider = (uint8_t)(1u << ((MCG->C1 & MCG_C1_FRDIV_MASK) >> MCG_C1_FRDIV_SHIFT)); 222 | MCGOUTClock = (MCGOUTClock / Divider); /* Calculate the divided FLL reference clock */ 223 | if ((MCG->C2 & MCG_C2_RANGE0_MASK) != 0x0u) { 224 | MCGOUTClock /= 32u; /* If high range is enabled, additional 32 divider is active */ 225 | } /* ((MCG->C2 & MCG_C2_RANGE0_MASK) != 0x0u) */ 226 | } else { /* (!((MCG->C1 & MCG_C1_IREFS_MASK) == 0x0u)) */ 227 | MCGOUTClock = CPU_INT_SLOW_CLK_HZ; /* The slow internal reference clock is selected */ 228 | } /* (!((MCG->C1 & MCG_C1_IREFS_MASK) == 0x0u)) */ 229 | /* Select correct multiplier to calculate the MCG output clock */ 230 | switch (MCG->C4 & (MCG_C4_DMX32_MASK | MCG_C4_DRST_DRS_MASK)) { 231 | case 0x0u: 232 | MCGOUTClock *= 640u; 233 | break; 234 | case 0x20u: 235 | MCGOUTClock *= 1280u; 236 | break; 237 | case 0x40u: 238 | MCGOUTClock *= 1920u; 239 | break; 240 | case 0x60u: 241 | MCGOUTClock *= 2560u; 242 | break; 243 | case 0x80u: 244 | MCGOUTClock *= 732u; 245 | break; 246 | case 0xA0u: 247 | MCGOUTClock *= 1464u; 248 | break; 249 | case 0xC0u: 250 | MCGOUTClock *= 2197u; 251 | break; 252 | case 0xE0u: 253 | MCGOUTClock *= 2929u; 254 | break; 255 | default: 256 | break; 257 | } 258 | } else { /* (!((MCG->C6 & MCG_C6_PLLS_MASK) == 0x0u)) */ 259 | /* PLL is selected */ 260 | Divider = (1u + (MCG->C5 & MCG_C5_PRDIV0_MASK)); 261 | MCGOUTClock = (uint32_t)(CPU_XTAL_CLK_HZ / Divider); /* Calculate the PLL reference clock */ 262 | Divider = ((MCG->C6 & MCG_C6_VDIV0_MASK) + 24u); 263 | MCGOUTClock *= Divider; /* Calculate the MCG output clock */ 264 | } /* (!((MCG->C6 & MCG_C6_PLLS_MASK) == 0x0u)) */ 265 | } else if ((MCG->C1 & MCG_C1_CLKS_MASK) == 0x40u) { 266 | /* Internal reference clock is selected */ 267 | if ((MCG->C2 & MCG_C2_IRCS_MASK) == 0x0u) { 268 | MCGOUTClock = CPU_INT_SLOW_CLK_HZ; /* Slow internal reference clock selected */ 269 | } else { /* (!((MCG->C2 & MCG_C2_IRCS_MASK) == 0x0u)) */ 270 | MCGOUTClock = CPU_INT_FAST_CLK_HZ / (1 << ((MCG->SC & MCG_SC_FCRDIV_MASK) >> MCG_SC_FCRDIV_SHIFT)); /* Fast internal reference clock selected */ 271 | } /* (!((MCG->C2 & MCG_C2_IRCS_MASK) == 0x0u)) */ 272 | } else if ((MCG->C1 & MCG_C1_CLKS_MASK) == 0x80u) { 273 | /* External reference clock is selected */ 274 | if ((MCG->C7 & MCG_C7_OSCSEL_MASK) == 0x0u) { 275 | MCGOUTClock = CPU_XTAL_CLK_HZ; /* System oscillator drives MCG clock */ 276 | } else { /* (!((MCG->C7 & MCG_C7_OSCSEL_MASK) == 0x0u)) */ 277 | MCGOUTClock = CPU_XTAL32k_CLK_HZ; /* RTC 32 kHz oscillator drives MCG clock */ 278 | } /* (!((MCG->C7 & MCG_C7_OSCSEL_MASK) == 0x0u)) */ 279 | } else { /* (!((MCG->C1 & MCG_C1_CLKS_MASK) == 0x80u)) */ 280 | /* Reserved value */ 281 | return; 282 | } /* (!((MCG->C1 & MCG_C1_CLKS_MASK) == 0x80u)) */ 283 | SystemCoreClock = (MCGOUTClock / (1u + ((SIM->CLKDIV1 & SIM_CLKDIV1_OUTDIV1_MASK) >> SIM_CLKDIV1_OUTDIV1_SHIFT))); 284 | } 285 | -------------------------------------------------------------------------------- /shared/cmsis/TARGET_Freescale/TARGET_MK20DX/system_MK20D5.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ################################################################### 3 | ** Compilers: ARM Compiler 4 | ** Freescale C/C++ for Embedded ARM 5 | ** GNU C Compiler 6 | ** IAR ANSI C/C++ Compiler for ARM 7 | ** 8 | ** Reference manuals: K20P64M50SF0RM Rev. 1, Oct 2011 9 | ** K20P32M50SF0RM Rev. 1, Oct 2011 10 | ** K20P48M50SF0RM Rev. 1, Oct 2011 11 | ** 12 | ** Version: rev. 2.0, 2012-03-19 13 | ** 14 | ** Abstract: 15 | ** Provides a system configuration function and a global variable that 16 | ** contains the system frequency. It configures the device and initializes 17 | ** the oscillator (PLL) that is part of the microcontroller device. 18 | ** 19 | ** Copyright: 2012 Freescale Semiconductor, Inc. All Rights Reserved. 20 | ** 21 | ** http: www.freescale.com 22 | ** mail: support@freescale.com 23 | ** 24 | ** Revisions: 25 | ** - rev. 1.0 (2011-12-15) 26 | ** Initial version 27 | ** - rev. 2.0 (2012-03-19) 28 | ** PDB Peripheral register structure updated. 29 | ** DMA Registers and bits for unsupported DMA channels removed. 30 | ** 31 | ** ################################################################### 32 | */ 33 | 34 | /** 35 | * @file MK20D5 36 | * @version 2.0 37 | * @date 2012-03-19 38 | * @brief Device specific configuration file for MK20D5 (header file) 39 | * 40 | * Provides a system configuration function and a global variable that contains 41 | * the system frequency. It configures the device and initializes the oscillator 42 | * (PLL) that is part of the microcontroller device. 43 | */ 44 | 45 | #ifndef SYSTEM_MK20D5_H_ 46 | #define SYSTEM_MK20D5_H_ /**< Symbol preventing repeated inclusion */ 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | #include 53 | 54 | /** 55 | * @brief System clock frequency (core clock) 56 | * 57 | * The system clock frequency supplied to the SysTick timer and the processor 58 | * core clock. This variable can be used by the user application to setup the 59 | * SysTick timer or configure other parameters. It may also be used by debugger to 60 | * query the frequency of the debug timer or configure the trace clock speed 61 | * SystemCoreClock is initialized with a correct predefined value. 62 | */ 63 | extern uint32_t SystemCoreClock; 64 | 65 | /** 66 | * @brief Setup the microcontroller system. 67 | * 68 | * Typically this function configures the oscillator (PLL) that is part of the 69 | * microcontroller device. For systems with variable clock speed it also updates 70 | * the variable SystemCoreClock. SystemInit is called from startup_device file. 71 | */ 72 | void SystemInit (void); 73 | 74 | /** 75 | * @brief Updates the SystemCoreClock variable. 76 | * 77 | * It must be called whenever the core clock is changed during program 78 | * execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates 79 | * the current core clock. 80 | */ 81 | void SystemCoreClockUpdate (void); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* #if !defined(SYSTEM_MK20D5_H_) */ 88 | -------------------------------------------------------------------------------- /shared/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_ARM_STD/LPC11U35.sct: -------------------------------------------------------------------------------- 1 | 2 | LR_IROM1 0x00000000 0x10000 { ; load region size_region (64k) 3 | 4 | ER_IROM1 0x00000000 0x10000 { ; load address = execution address 5 | *.o (RESET, +First) 6 | *(InRoot$$Sections) 7 | .ANY (+RO) 8 | } 9 | 10 | RW_IRAM1 0x10000000 0x2000 { 11 | .ANY (+RW +ZI) 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /shared/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_ARM_STD/startup_LPC11Uxx.s: -------------------------------------------------------------------------------- 1 | ; * CMSIS-DAP Interface Firmware 2 | ; * Copyright (c) 2009-2013 ARM Limited 3 | ; * 4 | ; * Licensed under the Apache License, Version 2.0 (the "License"); 5 | ; * you may not use this file except in compliance with the License. 6 | ; * You may obtain a copy of the License at 7 | ; * 8 | ; * http://www.apache.org/licenses/LICENSE-2.0 9 | ; * 10 | ; * Unless required by applicable law or agreed to in writing, software 11 | ; * distributed under the License is distributed on an "AS IS" BASIS, 12 | ; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ; * See the License for the specific language governing permissions and 14 | ; * limitations under the License. 15 | 16 | ; Stack Configuration 17 | ; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> 18 | ; 19 | 20 | Stack_Size EQU 0x00000200 21 | 22 | AREA STACK, NOINIT, READWRITE, ALIGN=3 23 | Stack_Mem SPACE Stack_Size 24 | __initial_sp 25 | 26 | 27 | ; Heap Configuration 28 | ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> 29 | ; 30 | 31 | Heap_Size EQU 0x00000200 32 | 33 | AREA HEAP, NOINIT, READWRITE, ALIGN=3 34 | __heap_base 35 | Heap_Mem SPACE Heap_Size 36 | __heap_limit 37 | 38 | 39 | PRESERVE8 40 | THUMB 41 | 42 | 43 | ; Vector Table Mapped to Address 0 at Reset 44 | 45 | AREA RESET, DATA, READONLY 46 | EXPORT __Vectors 47 | 48 | __Vectors DCD __initial_sp ; Top of Stack 49 | DCD Reset_Handler ; Reset Handler 50 | DCD NMI_Handler ; NMI Handler 51 | DCD HardFault_Handler ; Hard Fault Handler 52 | DCD 0 ; Reserved 53 | DCD 0 ; Reserved 54 | DCD 0 ; Reserved 55 | DCD 0 ; Reserved 56 | DCD 0 ; Reserved 57 | DCD 0 ; Reserved 58 | DCD 0 ; Reserved 59 | DCD SVC_Handler ; SVCall Handler 60 | DCD 0 ; Reserved 61 | DCD 0 ; Reserved 62 | DCD PendSV_Handler ; PendSV Handler 63 | DCD SysTick_Handler ; SysTick Handler 64 | 65 | ; External Interrupts 66 | DCD FLEX_INT0_IRQHandler ; All GPIO pin can be routed to FLEX_INTx 67 | DCD FLEX_INT1_IRQHandler 68 | DCD FLEX_INT2_IRQHandler 69 | DCD FLEX_INT3_IRQHandler 70 | DCD FLEX_INT4_IRQHandler 71 | DCD FLEX_INT5_IRQHandler 72 | DCD FLEX_INT6_IRQHandler 73 | DCD FLEX_INT7_IRQHandler 74 | DCD GINT0_IRQHandler 75 | DCD GINT1_IRQHandler ; PIO0 (0:7) 76 | DCD Reserved_IRQHandler ; Reserved 77 | DCD Reserved_IRQHandler 78 | DCD Reserved_IRQHandler 79 | DCD Reserved_IRQHandler 80 | DCD SSP1_IRQHandler ; SSP1 81 | DCD I2C_IRQHandler ; I2C 82 | DCD TIMER16_0_IRQHandler ; 16-bit Timer0 83 | DCD TIMER16_1_IRQHandler ; 16-bit Timer1 84 | DCD TIMER32_0_IRQHandler ; 32-bit Timer0 85 | DCD TIMER32_1_IRQHandler ; 32-bit Timer1 86 | DCD SSP0_IRQHandler ; SSP0 87 | DCD UART_IRQHandler ; UART 88 | DCD USB_IRQHandler ; USB IRQ 89 | DCD USB_FIQHandler ; USB FIQ 90 | DCD ADC_IRQHandler ; A/D Converter 91 | DCD WDT_IRQHandler ; Watchdog timer 92 | DCD BOD_IRQHandler ; Brown Out Detect 93 | DCD FMC_IRQHandler ; IP2111 Flash Memory Controller 94 | DCD Reserved_IRQHandler ; Reserved 95 | DCD Reserved_IRQHandler ; Reserved 96 | DCD USBWakeup_IRQHandler ; USB wake up 97 | DCD Reserved_IRQHandler ; Reserved 98 | 99 | 100 | IF :LNOT::DEF:NO_CRP 101 | AREA |.ARM.__at_0x02FC|, CODE, READONLY 102 | CRP_Key DCD 0xFFFFFFFF 103 | ENDIF 104 | 105 | 106 | AREA |.text|, CODE, READONLY 107 | 108 | 109 | ; Reset Handler 110 | 111 | Reset_Handler PROC 112 | EXPORT Reset_Handler [WEAK] 113 | IMPORT SystemInit 114 | IMPORT __main 115 | LDR R0, =SystemInit 116 | BLX R0 117 | LDR R0, =__main 118 | BX R0 119 | ENDP 120 | 121 | 122 | ; Dummy Exception Handlers (infinite loops which can be modified) 123 | 124 | ; now, under COMMON NMI.c and NMI.h, a real NMI handler is created if NMI is enabled 125 | ; for particular peripheral. 126 | ;NMI_Handler PROC 127 | ; EXPORT NMI_Handler [WEAK] 128 | ; B . 129 | ; ENDP 130 | HardFault_Handler\ 131 | PROC 132 | EXPORT HardFault_Handler [WEAK] 133 | B . 134 | ENDP 135 | SVC_Handler PROC 136 | EXPORT SVC_Handler [WEAK] 137 | B . 138 | ENDP 139 | PendSV_Handler PROC 140 | EXPORT PendSV_Handler [WEAK] 141 | B . 142 | ENDP 143 | SysTick_Handler PROC 144 | EXPORT SysTick_Handler [WEAK] 145 | B . 146 | ENDP 147 | Reserved_IRQHandler PROC 148 | EXPORT Reserved_IRQHandler [WEAK] 149 | B . 150 | ENDP 151 | 152 | Default_Handler PROC 153 | EXPORT NMI_Handler [WEAK] 154 | EXPORT FLEX_INT0_IRQHandler [WEAK] 155 | EXPORT FLEX_INT1_IRQHandler [WEAK] 156 | EXPORT FLEX_INT2_IRQHandler [WEAK] 157 | EXPORT FLEX_INT3_IRQHandler [WEAK] 158 | EXPORT FLEX_INT4_IRQHandler [WEAK] 159 | EXPORT FLEX_INT5_IRQHandler [WEAK] 160 | EXPORT FLEX_INT6_IRQHandler [WEAK] 161 | EXPORT FLEX_INT7_IRQHandler [WEAK] 162 | EXPORT GINT0_IRQHandler [WEAK] 163 | EXPORT GINT1_IRQHandler [WEAK] 164 | EXPORT SSP1_IRQHandler [WEAK] 165 | EXPORT I2C_IRQHandler [WEAK] 166 | EXPORT TIMER16_0_IRQHandler [WEAK] 167 | EXPORT TIMER16_1_IRQHandler [WEAK] 168 | EXPORT TIMER32_0_IRQHandler [WEAK] 169 | EXPORT TIMER32_1_IRQHandler [WEAK] 170 | EXPORT SSP0_IRQHandler [WEAK] 171 | EXPORT UART_IRQHandler [WEAK] 172 | 173 | EXPORT USB_IRQHandler [WEAK] 174 | EXPORT USB_FIQHandler [WEAK] 175 | EXPORT ADC_IRQHandler [WEAK] 176 | EXPORT WDT_IRQHandler [WEAK] 177 | EXPORT BOD_IRQHandler [WEAK] 178 | EXPORT FMC_IRQHandler [WEAK] 179 | EXPORT USBWakeup_IRQHandler [WEAK] 180 | 181 | NMI_Handler 182 | FLEX_INT0_IRQHandler 183 | FLEX_INT1_IRQHandler 184 | FLEX_INT2_IRQHandler 185 | FLEX_INT3_IRQHandler 186 | FLEX_INT4_IRQHandler 187 | FLEX_INT5_IRQHandler 188 | FLEX_INT6_IRQHandler 189 | FLEX_INT7_IRQHandler 190 | GINT0_IRQHandler 191 | GINT1_IRQHandler 192 | SSP1_IRQHandler 193 | I2C_IRQHandler 194 | TIMER16_0_IRQHandler 195 | TIMER16_1_IRQHandler 196 | TIMER32_0_IRQHandler 197 | TIMER32_1_IRQHandler 198 | SSP0_IRQHandler 199 | UART_IRQHandler 200 | USB_IRQHandler 201 | USB_FIQHandler 202 | ADC_IRQHandler 203 | WDT_IRQHandler 204 | BOD_IRQHandler 205 | FMC_IRQHandler 206 | USBWakeup_IRQHandler 207 | 208 | B . 209 | 210 | ENDP 211 | 212 | 213 | ALIGN 214 | 215 | 216 | ; User Initial Stack & Heap 217 | 218 | IF :DEF:__MICROLIB 219 | 220 | EXPORT __initial_sp 221 | EXPORT __heap_base 222 | EXPORT __heap_limit 223 | 224 | ELSE 225 | 226 | IMPORT __use_two_region_memory 227 | EXPORT __user_initial_stackheap 228 | __user_initial_stackheap 229 | 230 | LDR R0, = Heap_Mem 231 | LDR R1, =(Stack_Mem + Stack_Size) 232 | LDR R2, = (Heap_Mem + Heap_Size) 233 | LDR R3, = Stack_Mem 234 | BX LR 235 | 236 | ALIGN 237 | 238 | ENDIF 239 | 240 | 241 | END 242 | -------------------------------------------------------------------------------- /shared/cmsis/TARGET_NXP/TARGET_LPC11UXX/system_LPC11Uxx.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micromint/Simple-DAP/7ea04ef30b1a972812e0f921611b7cbc3f64b186/shared/cmsis/TARGET_NXP/TARGET_LPC11UXX/system_LPC11Uxx.c -------------------------------------------------------------------------------- /shared/cmsis/TARGET_NXP/TARGET_LPC43XX/TOOLCHAIN_ARM_STD/LPC4320_SPIFI.sct: -------------------------------------------------------------------------------- 1 | ; ************************************************************* 2 | ; *** Scatter-Loading Description File generated by uVision *** 3 | ; ************************************************************* 4 | 5 | LR_ROM1 0x14000000 0x00400000 { ; load region size_region 6 | ER_ROM1 0x14000000 0x00400000 { ; load address = execution address 7 | *.o (RESET, +First) 8 | *(InRoot$$Sections) 9 | startup_LPC43xx.o (+RO) 10 | system_LPC43xx.o (+RO) 11 | } 12 | RW_IRAM2 0x20000000 0x00010000 { ; RW data 13 | .ANY (+RW +ZI) 14 | } 15 | VECT_RAM 0x10000000 EMPTY 0x00000200 { 16 | } 17 | RW_IRAM1 0x10000200 0x00018000 { 18 | .ANY (+RO) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /shared/cmsis/TARGET_NXP/TARGET_LPC43XX/TOOLCHAIN_ARM_STD/startup_LPC43xx.s: -------------------------------------------------------------------------------- 1 | ;/*********************************************************************** 2 | ; * $Id: startup_LPC43xx.s 6473 2011-02-16 17:40:54Z nxp27266 $ 3 | ; * 4 | ; * Project: LPC43xx CMSIS Package 5 | ; * 6 | ; * Description: Cortex-M3 Core Device Startup File for the NXP LPC43xx 7 | ; * Device Series. 8 | ; * 9 | ; * Copyright(C) 2011, NXP Semiconductor 10 | ; * All rights reserved. 11 | ; * 12 | ; * modified by KEIL 13 | ; *********************************************************************** 14 | ; * Software that is described herein is for illustrative purposes only 15 | ; * which provides customers with programming information regarding the 16 | ; * products. This software is supplied "AS IS" without any warranties. 17 | ; * NXP Semiconductors assumes no responsibility or liability for the 18 | ; * use of the software, conveys no license or title under any patent, 19 | ; * copyright, or mask work right to the product. NXP Semiconductors 20 | ; * reserves the right to make changes in the software without 21 | ; * notification. NXP Semiconductors also make no representation or 22 | ; * warranty that such application will be suitable for the specified 23 | ; * use without further testing or modification. 24 | ; **********************************************************************/ 25 | 26 | ; Stack Configuration 27 | ; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> 28 | ; 29 | 30 | Stack_Size EQU 0x00000200 31 | 32 | AREA STACK, NOINIT, READWRITE, ALIGN=3 33 | Stack_Mem SPACE Stack_Size 34 | __initial_sp 35 | 36 | 37 | ; Heap Configuration 38 | ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> 39 | ; 40 | 41 | Heap_Size EQU 0x00000000 42 | 43 | AREA HEAP, NOINIT, READWRITE, ALIGN=3 44 | __heap_base 45 | Heap_Mem SPACE Heap_Size 46 | __heap_limit 47 | 48 | PRESERVE8 49 | THUMB 50 | 51 | ; Vector Table Mapped to Address 0 at Reset 52 | 53 | AREA RESET, DATA, READONLY 54 | EXPORT __Vectors 55 | 56 | Sign_Value EQU 0x5A5A5A5A 57 | 58 | __Vectors DCD __initial_sp ; 0 Top of Stack 59 | DCD Reset_Handler ; 1 Reset Handler 60 | DCD NMI_Handler ; 2 NMI Handler 61 | DCD HardFault_Handler ; 3 Hard Fault Handler 62 | DCD MemManage_Handler ; 4 MPU Fault Handler 63 | DCD BusFault_Handler ; 5 Bus Fault Handler 64 | DCD UsageFault_Handler ; 6 Usage Fault Handler 65 | DCD Sign_Value ; 7 Reserved 66 | DCD 0 ; 8 Reserved 67 | DCD 0 ; 9 Reserved 68 | DCD 0 ; 10 Reserved 69 | DCD SVC_Handler ; 11 SVCall Handler 70 | DCD DebugMon_Handler ; 12 Debug Monitor Handler 71 | DCD 0 ; 13 Reserved 72 | DCD PendSV_Handler ; 14 PendSV Handler 73 | DCD SysTick_Handler ; 15 SysTick Handler 74 | 75 | ; External Interrupts 76 | DCD DAC_IRQHandler ; 16 D/A Converter 77 | DCD M0CORE_IRQHandler ; 17 M0 Core 78 | DCD DMA_IRQHandler ; 18 General Purpose DMA 79 | DCD EZH_IRQHandler ; 19 EZH/EDM 80 | DCD FLASH_EEPROM_IRQHandler ; 20 Reserved for Typhoon 81 | DCD ETH_IRQHandler ; 21 Ethernet 82 | DCD SDIO_IRQHandler ; 22 SD/MMC 83 | DCD LCD_IRQHandler ; 23 LCD 84 | DCD USB0_IRQHandler ; 24 USB0 85 | DCD USB1_IRQHandler ; 25 USB1 86 | DCD SCT_IRQHandler ; 26 State Configurable Timer 87 | DCD RIT_IRQHandler ; 27 Repetitive Interrupt Timer 88 | DCD TIMER0_IRQHandler ; 28 Timer0 89 | DCD TIMER1_IRQHandler ; 29 Timer1 90 | DCD TIMER2_IRQHandler ; 30 Timer2 91 | DCD TIMER3_IRQHandler ; 31 Timer3 92 | DCD MCPWM_IRQHandler ; 32 Motor Control PWM 93 | DCD ADC0_IRQHandler ; 33 A/D Converter 0 94 | DCD I2C0_IRQHandler ; 34 I2C0 95 | DCD I2C1_IRQHandler ; 35 I2C1 96 | DCD SPI_IRQHandler ; 36 SPI 97 | DCD ADC1_IRQHandler ; 37 A/D Converter 1 98 | DCD SSP0_IRQHandler ; 38 SSP0 99 | DCD SSP1_IRQHandler ; 39 SSP1 100 | DCD UART0_IRQHandler ; 40 UART0 101 | DCD UART1_IRQHandler ; 41 UART1 102 | DCD UART2_IRQHandler ; 42 UART2 103 | DCD UART3_IRQHandler ; 43 UART3 104 | DCD I2S0_IRQHandler ; 44 I2S0 105 | DCD I2S1_IRQHandler ; 45 I2S1 106 | DCD SPIFI_IRQHandler ; 46 SPI Flash Interface 107 | DCD SGPIO_IRQHandler ; 47 SGPIO 108 | DCD GPIO0_IRQHandler ; 48 GPIO0 109 | DCD GPIO1_IRQHandler ; 49 GPIO1 110 | DCD GPIO2_IRQHandler ; 50 GPIO2 111 | DCD GPIO3_IRQHandler ; 51 GPIO3 112 | DCD GPIO4_IRQHandler ; 52 GPIO4 113 | DCD GPIO5_IRQHandler ; 53 GPIO5 114 | DCD GPIO6_IRQHandler ; 54 GPIO6 115 | DCD GPIO7_IRQHandler ; 55 GPIO7 116 | DCD GINT0_IRQHandler ; 56 GINT0 117 | DCD GINT1_IRQHandler ; 57 GINT1 118 | DCD EVRT_IRQHandler ; 58 Event Router 119 | DCD CAN1_IRQHandler ; 59 C_CAN1 120 | DCD 0 ; 60 Reserved 121 | DCD VADC_IRQHandler ; 61 VADC 122 | DCD ATIMER_IRQHandler ; 62 ATIMER 123 | DCD RTC_IRQHandler ; 63 RTC 124 | DCD 0 ; 64 Reserved 125 | DCD WDT_IRQHandler ; 65 WDT 126 | DCD M0s_IRQHandler ; 66 M0s 127 | DCD CAN0_IRQHandler ; 67 C_CAN0 128 | DCD QEI_IRQHandler ; 68 QEI 129 | 130 | 131 | IF :LNOT::DEF:NO_CRP 132 | AREA |.ARM.__at_0x02FC|, CODE, READONLY 133 | CRP_Key DCD 0xFFFFFFFF 134 | ENDIF 135 | 136 | AREA |.text|, CODE, READONLY 137 | 138 | ; Reset Handler 139 | 140 | Reset_Handler PROC 141 | EXPORT Reset_Handler [WEAK] 142 | IMPORT SystemInit 143 | IMPORT __main 144 | LDR R0, =SystemInit 145 | BLX R0 146 | LDR R0, =__main 147 | BX R0 148 | ENDP 149 | 150 | ; Dummy Exception Handlers (infinite loops which can be modified) 151 | 152 | NMI_Handler PROC 153 | EXPORT NMI_Handler [WEAK] 154 | B . 155 | ENDP 156 | HardFault_Handler\ 157 | PROC 158 | EXPORT HardFault_Handler [WEAK] 159 | B . 160 | ENDP 161 | MemManage_Handler\ 162 | PROC 163 | EXPORT MemManage_Handler [WEAK] 164 | B . 165 | ENDP 166 | BusFault_Handler\ 167 | PROC 168 | EXPORT BusFault_Handler [WEAK] 169 | B . 170 | ENDP 171 | UsageFault_Handler\ 172 | PROC 173 | EXPORT UsageFault_Handler [WEAK] 174 | B . 175 | ENDP 176 | SVC_Handler PROC 177 | EXPORT SVC_Handler [WEAK] 178 | B . 179 | ENDP 180 | DebugMon_Handler\ 181 | PROC 182 | EXPORT DebugMon_Handler [WEAK] 183 | B . 184 | ENDP 185 | PendSV_Handler PROC 186 | EXPORT PendSV_Handler [WEAK] 187 | B . 188 | ENDP 189 | SysTick_Handler PROC 190 | EXPORT SysTick_Handler [WEAK] 191 | B . 192 | ENDP 193 | 194 | Default_Handler PROC 195 | 196 | EXPORT DAC_IRQHandler [WEAK] 197 | EXPORT M0CORE_IRQHandler [WEAK] 198 | EXPORT DMA_IRQHandler [WEAK] 199 | EXPORT EZH_IRQHandler [WEAK] 200 | EXPORT FLASH_EEPROM_IRQHandler [WEAK] 201 | EXPORT ETH_IRQHandler [WEAK] 202 | EXPORT SDIO_IRQHandler [WEAK] 203 | EXPORT LCD_IRQHandler [WEAK] 204 | EXPORT USB0_IRQHandler [WEAK] 205 | EXPORT USB1_IRQHandler [WEAK] 206 | EXPORT SCT_IRQHandler [WEAK] 207 | EXPORT RIT_IRQHandler [WEAK] 208 | EXPORT TIMER0_IRQHandler [WEAK] 209 | EXPORT TIMER1_IRQHandler [WEAK] 210 | EXPORT TIMER2_IRQHandler [WEAK] 211 | EXPORT TIMER3_IRQHandler [WEAK] 212 | EXPORT MCPWM_IRQHandler [WEAK] 213 | EXPORT ADC0_IRQHandler [WEAK] 214 | EXPORT I2C0_IRQHandler [WEAK] 215 | EXPORT I2C1_IRQHandler [WEAK] 216 | EXPORT SPI_IRQHandler [WEAK] 217 | EXPORT ADC1_IRQHandler [WEAK] 218 | EXPORT SSP0_IRQHandler [WEAK] 219 | EXPORT SSP1_IRQHandler [WEAK] 220 | EXPORT UART0_IRQHandler [WEAK] 221 | EXPORT UART1_IRQHandler [WEAK] 222 | EXPORT UART2_IRQHandler [WEAK] 223 | EXPORT UART3_IRQHandler [WEAK] 224 | EXPORT I2S0_IRQHandler [WEAK] 225 | EXPORT I2S1_IRQHandler [WEAK] 226 | EXPORT SPIFI_IRQHandler [WEAK] 227 | EXPORT SGPIO_IRQHandler [WEAK] 228 | EXPORT GPIO0_IRQHandler [WEAK] 229 | EXPORT GPIO1_IRQHandler [WEAK] 230 | EXPORT GPIO2_IRQHandler [WEAK] 231 | EXPORT GPIO3_IRQHandler [WEAK] 232 | EXPORT GPIO4_IRQHandler [WEAK] 233 | EXPORT GPIO5_IRQHandler [WEAK] 234 | EXPORT GPIO6_IRQHandler [WEAK] 235 | EXPORT GPIO7_IRQHandler [WEAK] 236 | EXPORT GINT0_IRQHandler [WEAK] 237 | EXPORT GINT1_IRQHandler [WEAK] 238 | EXPORT EVRT_IRQHandler [WEAK] 239 | EXPORT CAN1_IRQHandler [WEAK] 240 | EXPORT VADC_IRQHandler [WEAK] 241 | EXPORT ATIMER_IRQHandler [WEAK] 242 | EXPORT RTC_IRQHandler [WEAK] 243 | EXPORT WDT_IRQHandler [WEAK] 244 | EXPORT M0s_IRQHandler [WEAK] 245 | EXPORT CAN0_IRQHandler [WEAK] 246 | EXPORT QEI_IRQHandler [WEAK] 247 | 248 | DAC_IRQHandler 249 | M0CORE_IRQHandler 250 | DMA_IRQHandler 251 | EZH_IRQHandler 252 | FLASH_EEPROM_IRQHandler 253 | ETH_IRQHandler 254 | SDIO_IRQHandler 255 | LCD_IRQHandler 256 | USB0_IRQHandler 257 | USB1_IRQHandler 258 | SCT_IRQHandler 259 | RIT_IRQHandler 260 | TIMER0_IRQHandler 261 | TIMER1_IRQHandler 262 | TIMER2_IRQHandler 263 | TIMER3_IRQHandler 264 | MCPWM_IRQHandler 265 | ADC0_IRQHandler 266 | I2C0_IRQHandler 267 | I2C1_IRQHandler 268 | SPI_IRQHandler 269 | ADC1_IRQHandler 270 | SSP0_IRQHandler 271 | SSP1_IRQHandler 272 | UART0_IRQHandler 273 | UART1_IRQHandler 274 | UART2_IRQHandler 275 | UART3_IRQHandler 276 | I2S0_IRQHandler 277 | I2S1_IRQHandler 278 | SPIFI_IRQHandler 279 | SGPIO_IRQHandler 280 | GPIO0_IRQHandler 281 | GPIO1_IRQHandler 282 | GPIO2_IRQHandler 283 | GPIO3_IRQHandler 284 | GPIO4_IRQHandler 285 | GPIO5_IRQHandler 286 | GPIO6_IRQHandler 287 | GPIO7_IRQHandler 288 | GINT0_IRQHandler 289 | GINT1_IRQHandler 290 | EVRT_IRQHandler 291 | CAN1_IRQHandler 292 | VADC_IRQHandler 293 | ATIMER_IRQHandler 294 | RTC_IRQHandler 295 | WDT_IRQHandler 296 | M0s_IRQHandler 297 | CAN0_IRQHandler 298 | QEI_IRQHandler 299 | 300 | B . 301 | 302 | ENDP 303 | 304 | ALIGN 305 | 306 | ; User Initial Stack & Heap 307 | 308 | IF :DEF:__MICROLIB 309 | 310 | EXPORT __initial_sp 311 | EXPORT __heap_base 312 | EXPORT __heap_limit 313 | 314 | ELSE 315 | 316 | IMPORT __use_two_region_memory 317 | EXPORT __user_initial_stackheap 318 | __user_initial_stackheap 319 | 320 | LDR R0, = Heap_Mem 321 | LDR R1, =(Stack_Mem + Stack_Size) 322 | LDR R2, = (Heap_Mem + Heap_Size) 323 | LDR R3, = Stack_Mem 324 | BX LR 325 | 326 | ALIGN 327 | 328 | ENDIF 329 | 330 | AREA |.text|,CODE, READONLY 331 | getPC PROC 332 | EXPORT getPC 333 | 334 | MOV R0,LR 335 | BX LR 336 | 337 | ENDP 338 | 339 | END 340 | --------------------------------------------------------------------------------