1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 3 /*************************************************************************** 4 * 5 * Copyright(c) 2015,2016 Intel Corporation. 6 * Copyright(c) 2017 PHYTEC Messtechnik GmbH 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * * Neither the name of Intel Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 ***************************************************************************/ 35 36 /** 37 * @file 38 * @brief USB Device Firmware Upgrade (DFU) public header 39 * 40 * Header follows the Device Class Specification for 41 * Device Firmware Upgrade Version 1.1 42 */ 43 44 #ifndef ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_ 45 #define ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_ 46 47 #include <zephyr/sys_clock.h> 48 49 /** DFU Class Subclass */ 50 #define DFU_SUBCLASS 0x01 51 52 /** DFU Class runtime Protocol */ 53 #define DFU_RT_PROTOCOL 0x01 54 55 /** DFU Class DFU mode Protocol */ 56 #define DFU_MODE_PROTOCOL 0x02 57 58 /** 59 * @brief DFU Class Specific Requests 60 */ 61 #define DFU_DETACH 0x00 62 #define DFU_DNLOAD 0x01 63 #define DFU_UPLOAD 0x02 64 #define DFU_GETSTATUS 0x03 65 #define DFU_CLRSTATUS 0x04 66 #define DFU_GETSTATE 0x05 67 #define DFU_ABORT 0x06 68 69 /** DFU FUNCTIONAL descriptor type */ 70 #define DFU_FUNC_DESC 0x21 71 72 /** DFU attributes DFU Functional Descriptor */ 73 #define DFU_ATTR_WILL_DETACH 0x08 74 #define DFU_ATTR_MANIFESTATION_TOLERANT 0x04 75 #define DFU_ATTR_CAN_UPLOAD 0x02 76 #define DFU_ATTR_CAN_DNLOAD 0x01 77 78 /** DFU Specification release */ 79 #define DFU_VERSION 0x0110 80 81 /** Run-Time Functional Descriptor */ 82 struct dfu_runtime_descriptor { 83 uint8_t bLength; 84 uint8_t bDescriptorType; 85 uint8_t bmAttributes; 86 uint16_t wDetachTimeOut; 87 uint16_t wTransferSize; 88 uint16_t bcdDFUVersion; 89 } __packed; 90 91 /** bStatus values for the DFU_GETSTATUS response */ 92 enum dfu_status { 93 statusOK, 94 errTARGET, 95 errFILE, 96 errWRITE, 97 errERASE, 98 errCHECK_ERASED, 99 errPROG, 100 errVERIFY, 101 errADDRESS, 102 errNOTDONE, 103 errFIRMWARE, 104 errVENDOR, 105 errUSB, 106 errPOR, 107 errUNKNOWN, 108 errSTALLEDPKT 109 }; 110 111 /** bState values for the DFU_GETSTATUS response */ 112 enum dfu_state { 113 appIDLE, 114 appDETACH, 115 dfuIDLE, 116 dfuDNLOAD_SYNC, 117 dfuDNBUSY, 118 dfuDNLOAD_IDLE, 119 dfuMANIFEST_SYNC, 120 dfuMANIFEST, 121 dfuMANIFEST_WAIT_RST, 122 dfuUPLOAD_IDLE, 123 dfuERROR, 124 }; 125 126 void wait_for_usb_dfu(k_timeout_t delay); 127 128 #endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_DFU_H_ */ 129